Skip to content

Commit

Permalink
test: implement test_is_locked()
Browse files Browse the repository at this point in the history
  • Loading branch information
casweeney committed Dec 17, 2024
1 parent 3b91989 commit adcabec
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/campaign.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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()
}
}
}
1 change: 1 addition & 0 deletions src/interfaces/ICampaign.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ pub trait ICampaign<TState> {
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);
}
19 changes: 18 additions & 1 deletion tests/test_campaign.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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');
}

0 comments on commit adcabec

Please sign in to comment.