Skip to content

Commit

Permalink
Merge pull request #50 from casweeney/develop
Browse files Browse the repository at this point in the history
implement is_locked function
  • Loading branch information
mubarak23 authored Dec 18, 2024
2 parents a1af6c1 + 484c8ec commit 04b23f0
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 119 deletions.
115 changes: 0 additions & 115 deletions Scarb.lock

This file was deleted.

7 changes: 4 additions & 3 deletions Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ keywords = ["SocialFi", "tokenbound", "cairo", "contracts", "starknet"]
# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html

[dependencies]
openzeppelin = "0.17.0"
starknet = "2.8.2"
openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", tag = "v0.15.0" }
token_bound_accounts= { git = "https://github.com/Starknet-Africa-Edu/TBA", tag = "v0.3.0" }
token_bound_accounts = "0.3.0"


[dev-dependencies]
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v0.31.0" }
Expand All @@ -35,4 +36,4 @@ block_id.tag = "latest"
[[tool.snforge.fork]]
name = "Mainnet"
url = "https://starknet-mainnet.g.alchemy.com/starknet/version/rpc/v0_7/4PHlmV2x26oj0up8xY3ZuqjhHb7mSvfQ"
block_id.number = "631894"
block_id.number = "631894"
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 04b23f0

Please sign in to comment.