From c6ee00e96d36e1e6c1508ef11623552d21a32fc5 Mon Sep 17 00:00:00 2001 From: mohiiit Date: Fri, 22 Dec 2023 09:41:57 +0530 Subject: [PATCH] test removed, u256 to usize, owner and transfer_ownership removed --- .../src/marketplace/currency_manager.cairo | 24 +- .../tests/test_currency_manager.cairo | 205 ------------------ 2 files changed, 7 insertions(+), 222 deletions(-) delete mode 100644 flex_marketplace/tests/test_currency_manager.cairo diff --git a/flex_marketplace/src/marketplace/currency_manager.cairo b/flex_marketplace/src/marketplace/currency_manager.cairo index b254acf..065f06f 100644 --- a/flex_marketplace/src/marketplace/currency_manager.cairo +++ b/flex_marketplace/src/marketplace/currency_manager.cairo @@ -5,11 +5,9 @@ trait ICurrencyManager { fn initializer(ref self: TState, owner: ContractAddress, proxy_admin: ContractAddress); fn add_currency(ref self: TState, currency: ContractAddress); fn remove_currency(ref self: TState, currency: ContractAddress); - fn transfer_contract_ownership(ref self: TState, new_owner: ContractAddress); - fn contract_owner(self: @TState) -> ContractAddress; fn is_currency_whitelisted(self: @TState, currency: ContractAddress) -> bool; - fn whitelisted_currency_count(self: @TState) -> u256; - fn whitelisted_currency(self: @TState, index: u256) -> ContractAddress; + fn whitelisted_currency_count(self: @TState) -> usize; + fn whitelisted_currency(self: @TState, index: usize) -> ContractAddress; } #[starknet::contract] @@ -29,9 +27,9 @@ mod CurrencyManager { #[storage] struct Storage { - whitelisted_currency_count: u256, - whitelisted_currencies: LegacyMap::, - whitelisted_currency_index: LegacyMap::, + whitelisted_currency_count: usize, + whitelisted_currencies: LegacyMap::, + whitelisted_currency_index: LegacyMap::, #[substorage(v0)] ownable: OwnableComponent::Storage } @@ -95,14 +93,6 @@ mod CurrencyManager { self.emit(CurrencyRemoved { currency, timestamp }); } - fn transfer_contract_ownership(ref self: ContractState, new_owner: ContractAddress) { - self.ownable.assert_only_owner(); - self.ownable.transfer_ownership(new_owner); - } - fn contract_owner(self: @ContractState) -> ContractAddress { - self.ownable.owner() - } - fn is_currency_whitelisted(self: @ContractState, currency: ContractAddress) -> bool { let index = self.whitelisted_currency_index.read(currency); if (index == 0) { @@ -111,11 +101,11 @@ mod CurrencyManager { true } - fn whitelisted_currency_count(self: @ContractState) -> u256 { + fn whitelisted_currency_count(self: @ContractState) -> usize { self.whitelisted_currency_count.read() } - fn whitelisted_currency(self: @ContractState, index: u256) -> ContractAddress { + fn whitelisted_currency(self: @ContractState, index: usize) -> ContractAddress { self.whitelisted_currencies.read(index) } } diff --git a/flex_marketplace/tests/test_currency_manager.cairo b/flex_marketplace/tests/test_currency_manager.cairo deleted file mode 100644 index e5cd7b9..0000000 --- a/flex_marketplace/tests/test_currency_manager.cairo +++ /dev/null @@ -1,205 +0,0 @@ -use flex::marketplace::currency_manager::{ - ICurrencyManagerDispatcher, ICurrencyManagerDispatcherTrait -}; -use snforge_std::{ - declare, ContractClassTrait, start_prank, stop_prank, RevertedTransaction, start_spoof, - CheatTarget, stop_spoof, cheatcodes -}; -use starknet::{ContractAddress, contract_address_const,}; - -fn CURRENCY0() -> ContractAddress { - return contract_address_const::<'CURRENCY0'>(); -} - -fn CURRENCY1() -> ContractAddress { - return contract_address_const::<'CURRENCY1'>(); -} - -fn OWNER() -> ContractAddress { - return contract_address_const::<'OWNER'>(); -} - -fn SECOND_OWNER() -> ContractAddress { - return contract_address_const::<'SECOND_OWNER'>(); -} - -fn deploy_contract() -> Result { - let contract = declare('CurrencyManager'); - let constructor_calldata = array![]; - contract.deploy(@constructor_calldata) -} - -#[test] -fn test_ownership() { - let contract_address = match deploy_contract() { - Result::Ok(address) => address, - Result::Err(msg) => panic(msg.panic_data), - }; - let currency_manager = ICurrencyManagerDispatcher { contract_address }; - currency_manager.initializer(OWNER(), OWNER()); - assert(currency_manager.contract_owner() == OWNER(), 'owner mismatch'); -} - -#[test] -fn test_add_currency() { - let contract_address = match deploy_contract() { - Result::Ok(address) => address, - Result::Err(msg) => panic(msg.panic_data), - }; - let currency_manager = ICurrencyManagerDispatcher { contract_address }; - currency_manager.initializer(OWNER(), OWNER()); - start_prank(CheatTarget::All, OWNER()); - currency_manager.add_currency(CURRENCY0()); - assert(currency_manager.is_currency_whitelisted(CURRENCY0()) == true, 'should be whitelisted'); - assert(currency_manager.whitelisted_currency_count() == 1, 'should be one'); - assert(currency_manager.whitelisted_currency(1) == CURRENCY0(), 'should be currency0'); -// assert(currency_manager.contract_owner()==OWNER(), 'owner mismatch'); -} - -#[test] -fn test_remove_currency() { - let contract_address = match deploy_contract() { - Result::Ok(address) => address, - Result::Err(msg) => panic(msg.panic_data), - }; - let currency_manager = ICurrencyManagerDispatcher { contract_address }; - currency_manager.initializer(OWNER(), OWNER()); - start_prank(CheatTarget::All, OWNER()); - currency_manager.add_currency(CURRENCY0()); - currency_manager.add_currency(CURRENCY1()); - currency_manager.remove_currency(CURRENCY0()); - assert( - currency_manager.is_currency_whitelisted(CURRENCY0()) == false, 'should not be whitelisted' - ); - assert(currency_manager.is_currency_whitelisted(CURRENCY1()) == true, 'should be whitelisted'); - assert(currency_manager.whitelisted_currency_count() == 1, 'should be one'); - assert(currency_manager.whitelisted_currency(1) == CURRENCY1(), 'should be currency1') -} - -#[test] -#[should_panic(expected: ('Caller is not the owner',))] -fn test_add_currency_not_owner() { - let contract_address = match deploy_contract() { - Result::Ok(address) => address, - Result::Err(msg) => panic(msg.panic_data), - }; - let currency_manager = ICurrencyManagerDispatcher { contract_address }; - currency_manager.initializer(OWNER(), OWNER()); - currency_manager.add_currency(CURRENCY0()); -} - -#[test] -#[should_panic(expected: ('Caller is not the owner',))] -fn test_remove_currency_not_owner() { - let contract_address = match deploy_contract() { - Result::Ok(address) => address, - Result::Err(msg) => panic(msg.panic_data), - }; - let currency_manager = ICurrencyManagerDispatcher { contract_address }; - currency_manager.initializer(OWNER(), OWNER()); - start_prank(CheatTarget::All, OWNER()); - currency_manager.add_currency(CURRENCY0()); - stop_prank(CheatTarget::All); - currency_manager.remove_currency(CURRENCY0()); -} - -#[test] -fn test_transfer_contract_ownership() { - let contract_address = match deploy_contract() { - Result::Ok(address) => address, - Result::Err(msg) => panic(msg.panic_data), - }; - let currency_manager = ICurrencyManagerDispatcher { contract_address }; - currency_manager.initializer(OWNER(), OWNER()); - start_prank(CheatTarget::All, OWNER()); - currency_manager.transfer_contract_ownership(SECOND_OWNER()); - assert(currency_manager.contract_owner() == SECOND_OWNER(), 'second owner should be owner'); -} - -#[test] -#[should_panic(expected: ('Caller is not the owner',))] -fn test_transfer_contract_ownership_not_owner() { - let contract_address = match deploy_contract() { - Result::Ok(address) => address, - Result::Err(msg) => panic(msg.panic_data), - }; - let currency_manager = ICurrencyManagerDispatcher { contract_address }; - currency_manager.initializer(OWNER(), OWNER()); - currency_manager.transfer_contract_ownership(SECOND_OWNER()); -} - -#[test] -fn test_whitelisted_currency_count() { - let contract_address = match deploy_contract() { - Result::Ok(address) => address, - Result::Err(msg) => panic(msg.panic_data), - }; - let currency_manager = ICurrencyManagerDispatcher { contract_address }; - currency_manager.initializer(OWNER(), OWNER()); - start_prank(CheatTarget::All, OWNER()); - currency_manager.add_currency(CURRENCY0()); - assert(currency_manager.whitelisted_currency_count() == 1, 'should be one'); - currency_manager.add_currency(CURRENCY1()); - assert(currency_manager.whitelisted_currency_count() == 2, 'should be two'); -} - - -#[test] -fn test_whitelisted_currency() { - let contract_address = match deploy_contract() { - Result::Ok(address) => address, - Result::Err(msg) => panic(msg.panic_data), - }; - let currency_manager = ICurrencyManagerDispatcher { contract_address }; - currency_manager.initializer(OWNER(), OWNER()); - start_prank(CheatTarget::All, OWNER()); - currency_manager.add_currency(CURRENCY0()); - currency_manager.add_currency(CURRENCY1()); - assert(currency_manager.whitelisted_currency(1) == CURRENCY0(), 'should be currency0'); - assert(currency_manager.whitelisted_currency(2) == CURRENCY1(), 'should be currency1'); - currency_manager.remove_currency(CURRENCY0()); - assert(currency_manager.whitelisted_currency(1) == CURRENCY1(), 'should be currency0'); -} - - -#[test] -fn test_is_currency_whitelisted() { - let contract_address = match deploy_contract() { - Result::Ok(address) => address, - Result::Err(msg) => panic(msg.panic_data), - }; - let currency_manager = ICurrencyManagerDispatcher { contract_address }; - currency_manager.initializer(OWNER(), OWNER()); - start_prank(CheatTarget::All, OWNER()); - - assert( - currency_manager.is_currency_whitelisted(CURRENCY0()) == false, 'should not be whitelisted' - ); - assert( - currency_manager.is_currency_whitelisted(CURRENCY1()) == false, 'should not whitelisted' - ); - - currency_manager.add_currency(CURRENCY0()); - assert(currency_manager.is_currency_whitelisted(CURRENCY0()) == true, 'should be whitelisted'); - assert( - currency_manager.is_currency_whitelisted(CURRENCY1()) == false, 'should not be whitelisted' - ); - - currency_manager.add_currency(CURRENCY1()); - assert(currency_manager.is_currency_whitelisted(CURRENCY0()) == true, 'should be whitelisted'); - assert(currency_manager.is_currency_whitelisted(CURRENCY1()) == true, 'should be whitelisted'); - - currency_manager.remove_currency(CURRENCY0()); - assert( - currency_manager.is_currency_whitelisted(CURRENCY0()) == false, 'should not be whitelisted' - ); - assert(currency_manager.is_currency_whitelisted(CURRENCY1()) == true, 'should be whitelisted'); - - currency_manager.remove_currency(CURRENCY1()); - assert( - currency_manager.is_currency_whitelisted(CURRENCY0()) == false, 'should not be whitelisted' - ); - assert( - currency_manager.is_currency_whitelisted(CURRENCY1()) == false, 'should not whitelisted' - ); -}