diff --git a/Scarb.lock b/Scarb.lock deleted file mode 100644 index 0bbc0d0..0000000 --- a/Scarb.lock +++ /dev/null @@ -1,115 +0,0 @@ -# Code generated by scarb DO NOT EDIT. -version = 1 - -[[package]] -name = "openzeppelin" -version = "0.15.0" -source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.15.0#f57642960f1c8cffafefb88bfff418eca8510634" -dependencies = [ - "openzeppelin_access", - "openzeppelin_account", - "openzeppelin_governance", - "openzeppelin_introspection", - "openzeppelin_presets", - "openzeppelin_security", - "openzeppelin_token", - "openzeppelin_upgrades", - "openzeppelin_utils", -] - -[[package]] -name = "openzeppelin_access" -version = "0.15.0" -source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.15.0#f57642960f1c8cffafefb88bfff418eca8510634" -dependencies = [ - "openzeppelin_introspection", - "openzeppelin_utils", -] - -[[package]] -name = "openzeppelin_account" -version = "0.15.0" -source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.15.0#f57642960f1c8cffafefb88bfff418eca8510634" -dependencies = [ - "openzeppelin_introspection", - "openzeppelin_token", - "openzeppelin_utils", -] - -[[package]] -name = "openzeppelin_governance" -version = "0.15.0" -source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.15.0#f57642960f1c8cffafefb88bfff418eca8510634" -dependencies = [ - "openzeppelin_access", - "openzeppelin_introspection", -] - -[[package]] -name = "openzeppelin_introspection" -version = "0.15.0" -source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.15.0#f57642960f1c8cffafefb88bfff418eca8510634" - -[[package]] -name = "openzeppelin_presets" -version = "0.15.0" -source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.15.0#f57642960f1c8cffafefb88bfff418eca8510634" -dependencies = [ - "openzeppelin_access", - "openzeppelin_account", - "openzeppelin_introspection", - "openzeppelin_token", - "openzeppelin_upgrades", -] - -[[package]] -name = "openzeppelin_security" -version = "0.15.0" -source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.15.0#f57642960f1c8cffafefb88bfff418eca8510634" - -[[package]] -name = "openzeppelin_token" -version = "0.15.0" -source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.15.0#f57642960f1c8cffafefb88bfff418eca8510634" -dependencies = [ - "openzeppelin_account", - "openzeppelin_governance", - "openzeppelin_introspection", -] - -[[package]] -name = "openzeppelin_upgrades" -version = "0.15.0" -source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.15.0#f57642960f1c8cffafefb88bfff418eca8510634" - -[[package]] -name = "openzeppelin_utils" -version = "0.15.0" -source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.15.0#f57642960f1c8cffafefb88bfff418eca8510634" - -[[package]] -name = "snforge_scarb_plugin" -version = "0.31.0" -source = "git+https://github.com/foundry-rs/starknet-foundry?tag=v0.31.0#72ea785ca354e9e506de3e5d687da9fb2c1b3c67" - -[[package]] -name = "snforge_std" -version = "0.31.0" -source = "git+https://github.com/foundry-rs/starknet-foundry?tag=v0.31.0#72ea785ca354e9e506de3e5d687da9fb2c1b3c67" -dependencies = [ - "snforge_scarb_plugin", -] - -[[package]] -name = "token_bound_accounts" -version = "0.3.0" -source = "git+https://github.com/Starknet-Africa-Edu/TBA?tag=v0.3.0#1f8b5e3c45422fb188ef2cf874b46d02f642973b" - -[[package]] -name = "tokengiver" -version = "0.1.0" -dependencies = [ - "openzeppelin", - "snforge_std", - "token_bound_accounts", -] diff --git a/Scarb.toml b/Scarb.toml index 00521c4..3bcd26a 100644 --- a/Scarb.toml +++ b/Scarb.toml @@ -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" } @@ -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" \ No newline at end of file +block_id.number = "631894" 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'); +}