From adcabec2a5a2f8ea3c044b2f850f2609749e8a5b Mon Sep 17 00:00:00 2001 From: casweeney Date: Tue, 17 Dec 2024 22:58:30 +0100 Subject: [PATCH] test: implement test_is_locked() --- src/campaign.cairo | 7 +++++++ src/interfaces/ICampaign.cairo | 1 + tests/test_campaign.cairo | 19 ++++++++++++++++++- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/campaign.cairo b/src/campaign.cairo index f7db7bf..9a28d8b 100644 --- a/src/campaign.cairo +++ b/src/campaign.cairo @@ -27,6 +27,9 @@ mod TokengiverCampaign { use openzeppelin::access::ownable::OwnableComponent; use openzeppelin::upgrades::UpgradeableComponent; use openzeppelin::upgrades::interface::IUpgradeable; + use token_bound_accounts::interfaces::ILockable::{ + ILockableDispatcher, ILockableDispatcherTrait + }; component!(path: OwnableComponent, storage: ownable, event: OwnableEvent); component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent); @@ -338,5 +341,9 @@ mod TokengiverCampaign { fn get_donation_count(self: @ContractState, campaign_address: ContractAddress) -> u16 { self.donation_count.read(campaign_address) } + + fn is_locked(self: @ContractState, campaign_address: ContractAddress) -> (bool, u64) { + ILockableDispatcher { contract_address: campaign_address }.is_locked() + } } } diff --git a/src/interfaces/ICampaign.cairo b/src/interfaces/ICampaign.cairo index 42647a8..a6610f8 100644 --- a/src/interfaces/ICampaign.cairo +++ b/src/interfaces/ICampaign.cairo @@ -27,4 +27,5 @@ pub trait ICampaign { fn get_donation_count(self: @TState, campaign_address: ContractAddress) -> u16; fn get_available_withdrawal(self: @TState, campaign_address: ContractAddress) -> u256; fn get_donations(self: @TState, campaign_address: ContractAddress) -> u256; + fn is_locked(self: @TState, campaign_address: ContractAddress) -> (bool, u64); } diff --git a/tests/test_campaign.cairo b/tests/test_campaign.cairo index 3e159ea..b58e1a9 100644 --- a/tests/test_campaign.cairo +++ b/tests/test_campaign.cairo @@ -9,6 +9,7 @@ use starknet::{ContractAddress, ClassHash, get_block_timestamp}; use tokengiver::interfaces::ICampaign::{ICampaign, ICampaignDispatcher, ICampaignDispatcherTrait}; use tokengiver::campaign::TokengiverCampaign::{Event, DonationMade, WithdrawalMade, CreateCampaign}; +use token_bound_accounts::interfaces::ILockable::{ILockableDispatcher, ILockableDispatcherTrait}; fn REGISTRY_HASH() -> felt252 { 0x046163525551f5a50ed027548e86e1ad023c44e0eeb0733f0dab2fb1fdc31ed0.try_into().unwrap() @@ -80,7 +81,6 @@ fn test_donate() { let token_giver = ICampaignDispatcher { contract_address: token_giver_address }; let strk_dispatcher = IERC20Dispatcher { contract_address: strk_address }; let random_id = 1; - let mut spy = spy_events(); //create campaign start_cheat_caller_address(token_giver_address, RECIPIENT()); @@ -353,3 +353,20 @@ fn test_upgradability_should_fail_if_not_owner_tries_to_update() { start_cheat_caller_address(contract_address, starknet::contract_address_const::<0x123>()); campaign_dispatcher.upgrade(*new_class_hash); } + +#[test] +#[fork("Mainnet")] +fn test_is_locked() { + let (token_giver_address, _, _) = __setup__(); + let token_giver = ICampaignDispatcher { contract_address: token_giver_address }; + + //create campaign + start_cheat_caller_address(token_giver_address, RECIPIENT()); + let campaign_address = token_giver + .create_campaign(REGISTRY_HASH(), IMPLEMENTATION_HASH(), SALT()); + stop_cheat_caller_address(token_giver_address); + + let campaign_contract = ILockableDispatcher { contract_address: campaign_address }; + let (is_locked, _) = campaign_contract.is_locked(); + assert(is_locked == false, 'wrong lock value'); +}