From 3f7d99c947054372b3af0805f4465d50dea1f538 Mon Sep 17 00:00:00 2001 From: Eric Nordelo Date: Thu, 28 Dec 2023 13:22:32 +0100 Subject: [PATCH 01/15] feat: mocks improved --- CHANGELOG.md | 2 + Scarb.toml | 5 +- .../access/test_dual_accesscontrol.cairo | 24 ++--- src/tests/access/test_dual_ownable.cairo | 10 +- src/tests/account/test_dual_account.cairo | 16 +-- src/tests/introspection/test_dual_src5.cairo | 4 +- src/tests/mocks.cairo | 7 +- src/tests/mocks/accesscontrol_mocks.cairo | 39 +++++--- src/tests/mocks/account_mocks.cairo | 33 ++++--- src/tests/mocks/erc20_mocks.cairo | 25 ++--- src/tests/mocks/erc721_mocks.cairo | 66 ++++++------- src/tests/mocks/erc721_receiver_mocks.cairo | 28 +++--- src/tests/mocks/initializable_mock.cairo | 23 ----- src/tests/mocks/ownable_mocks.cairo | 12 +-- src/tests/mocks/pausable_mock.cairo | 23 ----- .../mocks/reentrancy_attacker_mock.cairo | 23 ----- src/tests/mocks/reentrancy_mock.cairo | 97 ------------------- src/tests/mocks/src5_mocks.cairo | 4 +- src/tests/security/test_initializable.cairo | 2 +- src/tests/security/test_pausable.cairo | 2 +- src/tests/security/test_reentrancyguard.cairo | 7 +- src/tests/token/test_dual20.cairo | 22 ++--- src/tests/token/test_dual721.cairo | 42 ++++---- src/tests/token/test_dual721_receiver.cairo | 4 +- 24 files changed, 187 insertions(+), 333 deletions(-) delete mode 100644 src/tests/mocks/initializable_mock.cairo delete mode 100644 src/tests/mocks/pausable_mock.cairo delete mode 100644 src/tests/mocks/reentrancy_attacker_mock.cairo delete mode 100644 src/tests/mocks/reentrancy_mock.cairo diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d657f5e8..6d5989360 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,3 +18,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Use ComponentState in tests (#836) - Docsite navbar (#838) +- Use panic macro in tests (#) +- Fix test mocks file naming (#) diff --git a/Scarb.toml b/Scarb.toml index d684990ec..ea1607368 100644 --- a/Scarb.toml +++ b/Scarb.toml @@ -1,7 +1,8 @@ [package] name = "openzeppelin" version = "0.8.0" -cairo-version = "2.3.1" +edition = "2023_01" +cairo-version = "2.4.1" authors = ["OpenZeppelin Community "] description = "OpenZeppelin Contracts written in Cairo for StarkNet, a decentralized ZK Rollup" documentation = "https://docs.openzeppelin.com/contracts-cairo" @@ -11,7 +12,7 @@ license-file = "LICENSE" keywords = ["openzeppelin", "starknet", "cairo", "contracts", "security", "standards"] [dependencies] -starknet = "2.3.1" +starknet = "2.4.1" [lib] diff --git a/src/tests/access/test_dual_accesscontrol.cairo b/src/tests/access/test_dual_accesscontrol.cairo index 5c61e4d36..b95bf9de0 100644 --- a/src/tests/access/test_dual_accesscontrol.cairo +++ b/src/tests/access/test_dual_accesscontrol.cairo @@ -77,7 +77,7 @@ fn test_dual_no_supports_interface() { #[test] #[available_gas(2000000)] -#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_supports_interface_exists_and_panics() { let (dispatcher, _) = setup_accesscontrol_panic(); dispatcher.supports_interface(IACCESSCONTROL_ID); @@ -100,7 +100,7 @@ fn test_dual_no_has_role() { #[test] #[available_gas(2000000)] -#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_has_role_exists_and_panics() { let (dispatcher, _) = setup_accesscontrol_panic(); dispatcher.has_role(DEFAULT_ADMIN_ROLE, ADMIN()); @@ -123,7 +123,7 @@ fn test_dual_no_get_role_admin() { #[test] #[available_gas(2000000)] -#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_get_role_admin_exists_and_panics() { let (dispatcher, _) = setup_accesscontrol_panic(); dispatcher.get_role_admin(ROLE); @@ -148,7 +148,7 @@ fn test_dual_no_grant_role() { #[test] #[available_gas(2000000)] -#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_grant_role_exists_and_panics() { let (dispatcher, _) = setup_accesscontrol_panic(); dispatcher.grant_role(ROLE, AUTHORIZED()); @@ -173,7 +173,7 @@ fn test_dual_no_revoke_role() { #[test] #[available_gas(2000000)] -#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_revoke_role_exists_and_panics() { let (dispatcher, _) = setup_accesscontrol_panic(); dispatcher.revoke_role(ROLE, AUTHORIZED()); @@ -198,7 +198,7 @@ fn test_dual_no_renounce_role() { #[test] #[available_gas(2000000)] -#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_renounce_role_exists_and_panics() { let (dispatcher, _) = setup_accesscontrol_panic(); dispatcher.renounce_role(DEFAULT_ADMIN_ROLE, ADMIN()); @@ -217,7 +217,7 @@ fn test_dual_supportsInterface() { #[test] #[available_gas(2000000)] -#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_supportsInterface_exists_and_panics() { let (_, dispatcher) = setup_accesscontrol_panic(); dispatcher.supports_interface(IACCESSCONTROL_ID); @@ -232,7 +232,7 @@ fn test_dual_hasRole() { #[test] #[available_gas(2000000)] -#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_hasRole_exists_and_panics() { let (_, dispatcher) = setup_accesscontrol_panic(); dispatcher.has_role(DEFAULT_ADMIN_ROLE, ADMIN()); @@ -247,7 +247,7 @@ fn test_dual_getRoleAdmin() { #[test] #[available_gas(2000000)] -#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_getRoleAdmin_exists_and_panics() { let (_, dispatcher) = setup_accesscontrol_panic(); dispatcher.get_role_admin(ROLE); @@ -264,7 +264,7 @@ fn test_dual_grantRole() { #[test] #[available_gas(2000000)] -#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_grantRole_exists_and_panics() { let (_, dispatcher) = setup_accesscontrol_panic(); dispatcher.grant_role(ROLE, AUTHORIZED()); @@ -282,7 +282,7 @@ fn test_dual_revokeRole() { #[test] #[available_gas(2000000)] -#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_revokeRole_exists_and_panics() { let (_, dispatcher) = setup_accesscontrol_panic(); dispatcher.revoke_role(ROLE, AUTHORIZED()); @@ -299,7 +299,7 @@ fn test_dual_renounceRole() { #[test] #[available_gas(2000000)] -#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_renounceRole_exists_and_panics() { let (_, dispatcher) = setup_accesscontrol_panic(); dispatcher.renounce_role(DEFAULT_ADMIN_ROLE, ADMIN()); diff --git a/src/tests/access/test_dual_ownable.cairo b/src/tests/access/test_dual_ownable.cairo index 16588be16..6eac0c9dc 100644 --- a/src/tests/access/test_dual_ownable.cairo +++ b/src/tests/access/test_dual_ownable.cairo @@ -71,7 +71,7 @@ fn test_dual_no_owner() { #[test] #[available_gas(2000000)] -#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_owner_exists_and_panics() { let (dispatcher, _) = setup_ownable_panic(); dispatcher.owner(); @@ -100,7 +100,7 @@ fn test_dual_no_transfer_ownership() { #[test] #[available_gas(2000000)] -#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_transfer_ownership_exists_and_panics() { let (dispatcher, _) = setup_ownable_panic(); dispatcher.transfer_ownership(NEW_OWNER()); @@ -125,7 +125,7 @@ fn test_dual_no_renounce_ownership() { #[test] #[available_gas(2000000)] -#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_renounce_ownership_exists_and_panics() { let (dispatcher, _) = setup_ownable_panic(); dispatcher.renounce_ownership(); @@ -146,7 +146,7 @@ fn test_dual_transferOwnership() { #[test] #[available_gas(2000000)] -#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_transferOwnership_exists_and_panics() { let (_, dispatcher) = setup_ownable_panic(); dispatcher.transfer_ownership(NEW_OWNER()); @@ -163,7 +163,7 @@ fn test_dual_renounceOwnership() { #[test] #[available_gas(2000000)] -#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_renounceOwnership_exists_and_panics() { let (_, dispatcher) = setup_ownable_panic(); dispatcher.renounce_ownership(); diff --git a/src/tests/account/test_dual_account.cairo b/src/tests/account/test_dual_account.cairo index ef7ee88c5..16d803e67 100644 --- a/src/tests/account/test_dual_account.cairo +++ b/src/tests/account/test_dual_account.cairo @@ -72,7 +72,7 @@ fn test_dual_no_set_public_key() { #[test] #[available_gas(2000000)] -#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_set_public_key_exists_and_panics() { let (dispatcher, _) = setup_account_panic(); dispatcher.set_public_key(NEW_PUBKEY); @@ -95,7 +95,7 @@ fn test_dual_no_get_public_key() { #[test] #[available_gas(2000000)] -#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_get_public_key_exists_and_panics() { let (dispatcher, _) = setup_account_panic(); dispatcher.get_public_key(); @@ -130,7 +130,7 @@ fn test_dual_no_is_valid_signature() { #[test] #[available_gas(2000000)] -#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_is_valid_signature_exists_and_panics() { let hash = 0x0; let signature = array![]; @@ -156,7 +156,7 @@ fn test_dual_no_supports_interface() { #[test] #[available_gas(2000000)] -#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_supports_interface_exists_and_panics() { let (dispatcher, _) = setup_account_panic(); dispatcher.supports_interface(ISRC5_ID); @@ -179,7 +179,7 @@ fn test_dual_setPublicKey() { #[test] #[available_gas(2000000)] -#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_setPublicKey_exists_and_panics() { let (_, dispatcher) = setup_account_panic(); dispatcher.set_public_key(NEW_PUBKEY); @@ -194,7 +194,7 @@ fn test_dual_getPublicKey() { #[test] #[available_gas(2000000)] -#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_getPublicKey_exists_and_panics() { let (_, dispatcher) = setup_account_panic(); dispatcher.get_public_key(); @@ -218,7 +218,7 @@ fn test_dual_isValidSignature() { #[test] #[available_gas(2000000)] -#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_isValidSignature_exists_and_panics() { let hash = 0x0; let signature = array![]; @@ -236,7 +236,7 @@ fn test_dual_supportsInterface() { #[test] #[available_gas(2000000)] -#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_supportsInterface_exists_and_panics() { let (_, dispatcher) = setup_account_panic(); dispatcher.supports_interface(ISRC5_ID); diff --git a/src/tests/introspection/test_dual_src5.cairo b/src/tests/introspection/test_dual_src5.cairo index 80c13e56a..68f537534 100644 --- a/src/tests/introspection/test_dual_src5.cairo +++ b/src/tests/introspection/test_dual_src5.cairo @@ -60,7 +60,7 @@ fn test_dual_no_supports_interface() { #[test] #[available_gas(2000000)] -#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_supports_interface_exists_and_panics() { let (dispatcher, _) = setup_src5_panic(); dispatcher.supports_interface(ISRC5_ID); @@ -79,7 +79,7 @@ fn test_dual_supportsInterface() { #[test] #[available_gas(2000000)] -#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_supportsInterface_exists_and_panics() { let (_, dispatcher) = setup_src5_panic(); dispatcher.supports_interface(ISRC5_ID); diff --git a/src/tests/mocks.cairo b/src/tests/mocks.cairo index 4bc03de22..7eeb6c8c8 100644 --- a/src/tests/mocks.cairo +++ b/src/tests/mocks.cairo @@ -3,11 +3,10 @@ mod account_mocks; mod erc20_mocks; mod erc721_mocks; mod erc721_receiver_mocks; -mod initializable_mock; +mod initializable_mocks; mod non_implementing_mock; mod ownable_mocks; -mod pausable_mock; -mod reentrancy_attacker_mock; -mod reentrancy_mock; +mod pausable_mocks; +mod reentrancy_mocks; mod src5_mocks; mod upgrades_mocks; diff --git a/src/tests/mocks/accesscontrol_mocks.cairo b/src/tests/mocks/accesscontrol_mocks.cairo index b037f2dfd..a2f4290d0 100644 --- a/src/tests/mocks/accesscontrol_mocks.cairo +++ b/src/tests/mocks/accesscontrol_mocks.cairo @@ -8,16 +8,19 @@ mod DualCaseAccessControlMock { component!(path: AccessControlComponent, storage: accesscontrol, event: AccessControlEvent); component!(path: SRC5Component, storage: src5, event: SRC5Event); + // AccessControl #[abi(embed_v0)] impl AccessControlImpl = AccessControlComponent::AccessControlImpl; #[abi(embed_v0)] impl AccessControlCamelImpl = AccessControlComponent::AccessControlCamelImpl; + impl AccessControlInternalImpl = AccessControlComponent::InternalImpl; + + // SRC5 #[abi(embed_v0)] impl SRC5Impl = SRC5Component::SRC5Impl; - impl AccessControlInternalImpl = AccessControlComponent::InternalImpl; #[storage] struct Storage { @@ -53,12 +56,15 @@ mod SnakeAccessControlMock { component!(path: AccessControlComponent, storage: accesscontrol, event: AccessControlEvent); component!(path: SRC5Component, storage: src5, event: SRC5Event); + // AccessControl #[abi(embed_v0)] impl AccessControlImpl = AccessControlComponent::AccessControlImpl; + impl AccessControlInternalImpl = AccessControlComponent::InternalImpl; + + // SCR5 #[abi(embed_v0)] impl SRC5Impl = SRC5Component::SRC5Impl; - impl AccessControlInternalImpl = AccessControlComponent::InternalImpl; #[storage] struct Storage { @@ -94,13 +100,16 @@ mod CamelAccessControlMock { component!(path: AccessControlComponent, storage: accesscontrol, event: AccessControlEvent); component!(path: SRC5Component, storage: src5, event: SRC5Event); + // AccessControl #[abi(embed_v0)] impl AccessControlCamelImpl = AccessControlComponent::AccessControlCamelImpl; + impl AccessControlInternalImpl = AccessControlComponent::InternalImpl; + + // SCR5 #[abi(embed_v0)] impl SRC5Impl = SRC5Component::SRC5Impl; - impl AccessControlInternalImpl = AccessControlComponent::InternalImpl; #[storage] struct Storage { @@ -141,34 +150,34 @@ mod SnakeAccessControlPanicMock { #[external(v0)] fn has_role(self: @ContractState, role: felt252, account: ContractAddress) -> bool { - panic_with_felt252('Some error'); + panic!("Some error"); false } #[external(v0)] fn get_role_admin(self: @ContractState, role: felt252) -> felt252 { - panic_with_felt252('Some error'); + panic!("Some error"); 3 } #[external(v0)] fn grant_role(ref self: ContractState, role: felt252, account: ContractAddress) { - panic_with_felt252('Some error'); + panic!("Some error"); } #[external(v0)] fn revoke_role(ref self: ContractState, role: felt252, account: ContractAddress) { - panic_with_felt252('Some error'); + panic!("Some error"); } #[external(v0)] fn renounce_role(ref self: ContractState, role: felt252, account: ContractAddress) { - panic_with_felt252('Some error'); + panic!("Some error"); } #[external(v0)] fn supports_interface(self: @ContractState, interface_id: felt252) -> bool { - panic_with_felt252('Some error'); + panic!("Some error"); false } } @@ -182,34 +191,34 @@ mod CamelAccessControlPanicMock { #[external(v0)] fn hasRole(self: @ContractState, role: felt252, account: ContractAddress) -> bool { - panic_with_felt252('Some error'); + panic!("Some error"); false } #[external(v0)] fn getRoleAdmin(self: @ContractState, role: felt252) -> felt252 { - panic_with_felt252('Some error'); + panic!("Some error"); 3 } #[external(v0)] fn grantRole(ref self: ContractState, role: felt252, account: ContractAddress) { - panic_with_felt252('Some error'); + panic!("Some error"); } #[external(v0)] fn revokeRole(ref self: ContractState, role: felt252, account: ContractAddress) { - panic_with_felt252('Some error'); + panic!("Some error"); } #[external(v0)] fn renounceRole(ref self: ContractState, role: felt252, account: ContractAddress) { - panic_with_felt252('Some error'); + panic!("Some error"); } #[external(v0)] fn supportsInterface(self: @ContractState, interfaceId: felt252) -> bool { - panic_with_felt252('Some error'); + panic!("Some error"); false } } diff --git a/src/tests/mocks/account_mocks.cairo b/src/tests/mocks/account_mocks.cairo index 926d4c686..03df45d92 100644 --- a/src/tests/mocks/account_mocks.cairo +++ b/src/tests/mocks/account_mocks.cairo @@ -6,6 +6,7 @@ mod DualCaseAccountMock { component!(path: AccountComponent, storage: account, event: AccountEvent); component!(path: SRC5Component, storage: src5, event: SRC5Event); + // Account #[abi(embed_v0)] impl SRC6Impl = AccountComponent::SRC6Impl; #[abi(embed_v0)] @@ -14,9 +15,11 @@ mod DualCaseAccountMock { impl DeclarerImpl = AccountComponent::DeclarerImpl; #[abi(embed_v0)] impl DeployableImpl = AccountComponent::DeployableImpl; + impl AccountInternalImpl = AccountComponent::InternalImpl; + + // SCR5 #[abi(embed_v0)] impl SRC5Impl = SRC5Component::SRC5Impl; - impl AccountInternalImpl = AccountComponent::InternalImpl; #[storage] @@ -50,13 +53,16 @@ mod SnakeAccountMock { component!(path: AccountComponent, storage: account, event: AccountEvent); component!(path: SRC5Component, storage: src5, event: SRC5Event); + // Account #[abi(embed_v0)] impl SRC6Impl = AccountComponent::SRC6Impl; #[abi(embed_v0)] impl PublicKeyImpl = AccountComponent::PublicKeyImpl; + impl AccountInternalImpl = AccountComponent::InternalImpl; + + // SCR5 #[abi(embed_v0)] impl SRC5Impl = SRC5Component::SRC5Impl; - impl AccountInternalImpl = AccountComponent::InternalImpl; #[storage] @@ -91,15 +97,18 @@ mod CamelAccountMock { component!(path: AccountComponent, storage: account, event: AccountEvent); component!(path: SRC5Component, storage: src5, event: SRC5Event); + // Account #[abi(embed_v0)] impl SRC6CamelOnlyImpl = AccountComponent::SRC6CamelOnlyImpl; #[abi(embed_v0)] impl PublicKeyCamelImpl = AccountComponent::PublicKeyCamelImpl; - #[abi(embed_v0)] - impl SRC5Impl = SRC5Component::SRC5Impl; impl SRC6Impl = AccountComponent::SRC6Impl; impl AccountInternalImpl = AccountComponent::InternalImpl; + // SCR5 + #[abi(embed_v0)] + impl SRC5Impl = SRC5Component::SRC5Impl; + #[storage] struct Storage { @@ -149,12 +158,12 @@ mod SnakeAccountPanicMock { #[external(v0)] fn set_public_key(ref self: ContractState, new_public_key: felt252) { - panic_with_felt252('Some error'); + panic!("Some error"); } #[external(v0)] fn get_public_key(self: @ContractState) -> felt252 { - panic_with_felt252('Some error'); + panic!("Some error"); 3 } @@ -162,13 +171,13 @@ mod SnakeAccountPanicMock { fn is_valid_signature( self: @ContractState, hash: felt252, signature: Array ) -> felt252 { - panic_with_felt252('Some error'); + panic!("Some error"); 3 } #[external(v0)] fn supports_interface(self: @ContractState, interface_id: felt252) -> bool { - panic_with_felt252('Some error'); + panic!("Some error"); false } } @@ -180,24 +189,24 @@ mod CamelAccountPanicMock { #[external(v0)] fn setPublicKey(ref self: ContractState, newPublicKey: felt252) { - panic_with_felt252('Some error'); + panic!("Some error"); } #[external(v0)] fn getPublicKey(self: @ContractState) -> felt252 { - panic_with_felt252('Some error'); + panic!("Some error"); 3 } #[external(v0)] fn isValidSignature(self: @ContractState, hash: felt252, signature: Array) -> felt252 { - panic_with_felt252('Some error'); + panic!("Some error"); 3 } #[external(v0)] fn supportsInterface(self: @ContractState, interfaceId: felt252) -> bool { - panic_with_felt252('Some error'); + panic!("Some error"); false } } diff --git a/src/tests/mocks/erc20_mocks.cairo b/src/tests/mocks/erc20_mocks.cairo index dbe4466d7..4e28bb889 100644 --- a/src/tests/mocks/erc20_mocks.cairo +++ b/src/tests/mocks/erc20_mocks.cairo @@ -99,6 +99,7 @@ mod CamelERC20Mock { #[abi(embed_v0)] impl SafeAllowanceCamelImpl = ERC20Component::SafeAllowanceCamelImpl; + // `ERC20Impl` is not embedded because it would defeat the purpose of the // mock. The `ERC20Impl` case-agnostic methods are manually exposed. impl ERC20Impl = ERC20Component::ERC20Impl; @@ -160,49 +161,49 @@ mod SnakeERC20Panic { #[external(v0)] fn name(self: @ContractState) -> felt252 { - panic_with_felt252('Some error'); + panic!("Some error"); 3 } #[external(v0)] fn symbol(self: @ContractState) -> felt252 { - panic_with_felt252('Some error'); + panic!("Some error"); 3 } #[external(v0)] fn decimals(self: @ContractState) -> u8 { - panic_with_felt252('Some error'); + panic!("Some error"); 3 } #[external(v0)] fn allowance(self: @ContractState, owner: ContractAddress, spender: ContractAddress) -> u256 { - panic_with_felt252('Some error'); + panic!("Some error"); 3 } #[external(v0)] fn transfer(ref self: ContractState, recipient: ContractAddress, amount: u256) -> bool { - panic_with_felt252('Some error'); + panic!("Some error"); false } #[external(v0)] fn approve(ref self: ContractState, to: ContractAddress, token_id: u256) -> bool { - panic_with_felt252('Some error'); + panic!("Some error"); false } #[external(v0)] fn total_supply(self: @ContractState) -> u256 { - panic_with_felt252('Some error'); + panic!("Some error"); 3 } #[external(v0)] fn balance_of(self: @ContractState, account: ContractAddress) -> u256 { - panic_with_felt252('Some error'); + panic!("Some error"); 3 } @@ -210,7 +211,7 @@ mod SnakeERC20Panic { fn transfer_from( ref self: ContractState, from: ContractAddress, to: ContractAddress, amount: u256 ) -> bool { - panic_with_felt252('Some error'); + panic!("Some error"); false } } @@ -224,13 +225,13 @@ mod CamelERC20Panic { #[external(v0)] fn totalSupply(self: @ContractState) -> u256 { - panic_with_felt252('Some error'); + panic!("Some error"); 3 } #[external(v0)] fn balanceOf(self: @ContractState, account: ContractAddress) -> u256 { - panic_with_felt252('Some error'); + panic!("Some error"); 3 } @@ -238,6 +239,6 @@ mod CamelERC20Panic { fn transferFrom( ref self: ContractState, sender: ContractAddress, recipient: ContractAddress, amount: u256 ) { - panic_with_felt252('Some error'); + panic!("Some error"); } } diff --git a/src/tests/mocks/erc721_mocks.cairo b/src/tests/mocks/erc721_mocks.cairo index f9604f568..340c3154a 100644 --- a/src/tests/mocks/erc721_mocks.cairo +++ b/src/tests/mocks/erc721_mocks.cairo @@ -7,10 +7,6 @@ mod DualCaseERC721Mock { component!(path: SRC5Component, storage: src5, event: SRC5Event); component!(path: ERC721Component, storage: erc721, event: ERC721Event); - // SRC5 - #[abi(embed_v0)] - impl SRC5Impl = SRC5Component::SRC5Impl; - // ERC721 #[abi(embed_v0)] impl ERC721Impl = ERC721Component::ERC721Impl; @@ -23,6 +19,10 @@ mod DualCaseERC721Mock { ERC721Component::ERC721MetadataCamelOnlyImpl; impl ERC721InternalImpl = ERC721Component::InternalImpl; + // SRC5 + #[abi(embed_v0)] + impl SRC5Impl = SRC5Component::SRC5Impl; + #[storage] struct Storage { #[substorage(v0)] @@ -64,10 +64,6 @@ mod SnakeERC721Mock { component!(path: SRC5Component, storage: src5, event: SRC5Event); component!(path: ERC721Component, storage: erc721, event: ERC721Event); - // SRC5 - #[abi(embed_v0)] - impl SRC5Impl = SRC5Component::SRC5Impl; - // ERC721 #[abi(embed_v0)] impl ERC721Impl = ERC721Component::ERC721Impl; @@ -75,6 +71,10 @@ mod SnakeERC721Mock { impl ERC721MetadataImpl = ERC721Component::ERC721MetadataImpl; impl ERC721InternalImpl = ERC721Component::InternalImpl; + // SRC5 + #[abi(embed_v0)] + impl SRC5Impl = SRC5Component::SRC5Impl; + #[storage] struct Storage { #[substorage(v0)] @@ -117,10 +117,6 @@ mod CamelERC721Mock { component!(path: SRC5Component, storage: src5, event: SRC5Event); component!(path: ERC721Component, storage: erc721, event: ERC721Event); - // SRC5 - #[abi(embed_v0)] - impl SRC5Impl = SRC5Component::SRC5Impl; - // ERC721 #[abi(embed_v0)] impl ERC721CamelOnly = ERC721Component::ERC721CamelOnlyImpl; @@ -129,6 +125,10 @@ mod CamelERC721Mock { ERC721Component::ERC721MetadataCamelOnlyImpl; impl ERC721InternalImpl = ERC721Component::InternalImpl; + // SRC5 + #[abi(embed_v0)] + impl SRC5Impl = SRC5Component::SRC5Impl; + #[storage] struct Storage { #[substorage(v0)] @@ -197,61 +197,61 @@ mod SnakeERC721PanicMock { #[external(v0)] impl ExternalImpl of ExternalTrait { fn name(self: @ContractState) -> felt252 { - panic_with_felt252('Some error'); + panic!("Some error"); 3 } fn symbol(self: @ContractState) -> felt252 { - panic_with_felt252('Some error'); + panic!("Some error"); 3 } fn approve(ref self: ContractState, to: ContractAddress, token_id: u256) { - panic_with_felt252('Some error'); + panic!("Some error"); } fn supports_interface(self: @ContractState, interface_id: felt252) -> bool { - panic_with_felt252('Some error'); + panic!("Some error"); false } fn token_uri(self: @ContractState, token_id: u256) -> felt252 { - panic_with_felt252('Some error'); + panic!("Some error"); 3 } fn balance_of(self: @ContractState, account: ContractAddress) -> u256 { - panic_with_felt252('Some error'); + panic!("Some error"); u256 { low: 3, high: 3 } } fn owner_of(self: @ContractState, token_id: u256) -> ContractAddress { - panic_with_felt252('Some error'); + panic!("Some error"); Zeroable::zero() } fn get_approved(self: @ContractState, token_id: u256) -> ContractAddress { - panic_with_felt252('Some error'); + panic!("Some error"); Zeroable::zero() } fn is_approved_for_all( self: @ContractState, owner: ContractAddress, operator: ContractAddress ) -> bool { - panic_with_felt252('Some error'); + panic!("Some error"); false } fn set_approval_for_all( ref self: ContractState, operator: ContractAddress, approved: bool ) { - panic_with_felt252('Some error'); + panic!("Some error"); } fn transfer_from( ref self: ContractState, from: ContractAddress, to: ContractAddress, token_id: u256 ) { - panic_with_felt252('Some error'); + panic!("Some error"); } fn safe_transfer_from( @@ -261,7 +261,7 @@ mod SnakeERC721PanicMock { token_id: u256, data: Span ) { - panic_with_felt252('Some error'); + panic!("Some error"); } } } @@ -278,45 +278,45 @@ mod CamelERC721PanicMock { #[external(v0)] impl ExternalImpl of ExternalTrait { fn supportsInterface(self: @ContractState, interfaceId: felt252) -> bool { - panic_with_felt252('Some error'); + panic!("Some error"); false } fn tokenURI(self: @ContractState, tokenId: u256) -> felt252 { - panic_with_felt252('Some error'); + panic!("Some error"); 3 } fn balanceOf(self: @ContractState, account: ContractAddress) -> u256 { - panic_with_felt252('Some error'); + panic!("Some error"); u256 { low: 3, high: 3 } } fn ownerOf(self: @ContractState, tokenId: u256) -> ContractAddress { - panic_with_felt252('Some error'); + panic!("Some error"); Zeroable::zero() } fn getApproved(self: @ContractState, tokenId: u256) -> ContractAddress { - panic_with_felt252('Some error'); + panic!("Some error"); Zeroable::zero() } fn isApprovedForAll( self: @ContractState, owner: ContractAddress, operator: ContractAddress ) -> bool { - panic_with_felt252('Some error'); + panic!("Some error"); false } fn setApprovalForAll(ref self: ContractState, operator: ContractAddress, approved: bool) { - panic_with_felt252('Some error'); + panic!("Some error"); } fn transferFrom( ref self: ContractState, from: ContractAddress, to: ContractAddress, tokenId: u256 ) { - panic_with_felt252('Some error'); + panic!("Some error"); } fn safeTransferFrom( @@ -326,7 +326,7 @@ mod CamelERC721PanicMock { tokenId: u256, data: Span ) { - panic_with_felt252('Some error'); + panic!("Some error"); } } } diff --git a/src/tests/mocks/erc721_receiver_mocks.cairo b/src/tests/mocks/erc721_receiver_mocks.cairo index 0732fc3e9..e47cc4325 100644 --- a/src/tests/mocks/erc721_receiver_mocks.cairo +++ b/src/tests/mocks/erc721_receiver_mocks.cairo @@ -9,14 +9,14 @@ mod DualCaseERC721ReceiverMock { component!(path: SRC5Component, storage: src5, event: SRC5Event); component!(path: ERC721ReceiverComponent, storage: erc721_receiver, event: ERC721ReceiverEvent); - // SRC5 - #[abi(embed_v0)] - impl SRC5Impl = SRC5Component::SRC5Impl; - // ERC721Receiver impl ERC721ReceiverImpl = ERC721ReceiverComponent::ERC721ReceiverImpl; impl ERC721ReceiverInternalImpl = ERC721ReceiverComponent::InternalImpl; + // SRC5 + #[abi(embed_v0)] + impl SRC5Impl = SRC5Component::SRC5Impl; + #[storage] struct Storage { #[substorage(v0)] @@ -75,14 +75,14 @@ mod SnakeERC721ReceiverMock { component!(path: SRC5Component, storage: src5, event: SRC5Event); component!(path: ERC721ReceiverComponent, storage: erc721_receiver, event: ERC721ReceiverEvent); - // SRC5 - #[abi(embed_v0)] - impl SRC5Impl = SRC5Component::SRC5Impl; - // ERC721Receiver impl ERC721ReceiverImpl = ERC721ReceiverComponent::ERC721ReceiverImpl; impl ERC721ReceiverInternalImpl = ERC721ReceiverComponent::InternalImpl; + // SRC5 + #[abi(embed_v0)] + impl SRC5Impl = SRC5Component::SRC5Impl; + #[storage] struct Storage { #[substorage(v0)] @@ -130,14 +130,14 @@ mod CamelERC721ReceiverMock { component!(path: SRC5Component, storage: src5, event: SRC5Event); component!(path: ERC721ReceiverComponent, storage: erc721_receiver, event: ERC721ReceiverEvent); - // SRC5 - #[abi(embed_v0)] - impl SRC5Impl = SRC5Component::SRC5Impl; - // ERC721Receiver impl ERC721ReceiverCamelImpl = ERC721ReceiverComponent::ERC721ReceiverCamelImpl; impl ERC721ReceiverInternalImpl = ERC721ReceiverComponent::InternalImpl; + // SRC5 + #[abi(embed_v0)] + impl SRC5Impl = SRC5Component::SRC5Impl; + #[storage] struct Storage { #[substorage(v0)] @@ -191,7 +191,7 @@ mod SnakeERC721ReceiverPanicMock { token_id: u256, data: Span ) -> felt252 { - panic_with_felt252('Some error'); + panic!("Some error"); 3 } } @@ -211,7 +211,7 @@ mod CamelERC721ReceiverPanicMock { tokenId: u256, data: Span ) -> felt252 { - panic_with_felt252('Some error'); + panic!("Some error"); 3 } } diff --git a/src/tests/mocks/initializable_mock.cairo b/src/tests/mocks/initializable_mock.cairo deleted file mode 100644 index 9b85fc5c8..000000000 --- a/src/tests/mocks/initializable_mock.cairo +++ /dev/null @@ -1,23 +0,0 @@ -#[starknet::contract] -mod InitializableMock { - use openzeppelin::security::initializable::InitializableComponent; - - component!(path: InitializableComponent, storage: initializable, event: InitializableEvent); - - #[abi(embed_v0)] - impl InitializableImpl = - InitializableComponent::InitializableImpl; - - #[storage] - struct Storage { - #[substorage(v0)] - initializable: InitializableComponent::Storage - } - - #[event] - #[derive(Drop, starknet::Event)] - enum Event { - #[flat] - InitializableEvent: InitializableComponent::Event - } -} diff --git a/src/tests/mocks/ownable_mocks.cairo b/src/tests/mocks/ownable_mocks.cairo index 5ed7e107c..e6a6a294d 100644 --- a/src/tests/mocks/ownable_mocks.cairo +++ b/src/tests/mocks/ownable_mocks.cairo @@ -107,18 +107,18 @@ mod SnakeOwnablePanicMock { #[external(v0)] fn owner(self: @ContractState) -> ContractAddress { - panic_with_felt252('Some error'); + panic!("Some error"); Zeroable::zero() } #[external(v0)] fn transfer_ownership(ref self: ContractState, new_owner: ContractAddress) { - panic_with_felt252('Some error'); + panic!("Some error"); } #[external(v0)] fn renounce_ownership(ref self: ContractState) { - panic_with_felt252('Some error'); + panic!("Some error"); } } @@ -131,17 +131,17 @@ mod CamelOwnablePanicMock { #[external(v0)] fn owner(self: @ContractState) -> ContractAddress { - panic_with_felt252('Some error'); + panic!("Some error"); Zeroable::zero() } #[external(v0)] fn transferOwnership(ref self: ContractState, newOwner: ContractAddress) { - panic_with_felt252('Some error'); + panic!("Some error"); } #[external(v0)] fn renounceOwnership(ref self: ContractState) { - panic_with_felt252('Some error'); + panic!("Some error"); } } diff --git a/src/tests/mocks/pausable_mock.cairo b/src/tests/mocks/pausable_mock.cairo deleted file mode 100644 index 2cb1e9317..000000000 --- a/src/tests/mocks/pausable_mock.cairo +++ /dev/null @@ -1,23 +0,0 @@ -#[starknet::contract] -mod PausableMock { - use openzeppelin::security::pausable::PausableComponent; - - component!(path: PausableComponent, storage: pausable, event: PausableEvent); - - #[abi(embed_v0)] - impl PausableImpl = PausableComponent::PausableImpl; - impl InternalImpl = PausableComponent::InternalImpl; - - #[storage] - struct Storage { - #[substorage(v0)] - pausable: PausableComponent::Storage - } - - #[event] - #[derive(Drop, starknet::Event)] - enum Event { - #[flat] - PausableEvent: PausableComponent::Event - } -} diff --git a/src/tests/mocks/reentrancy_attacker_mock.cairo b/src/tests/mocks/reentrancy_attacker_mock.cairo deleted file mode 100644 index 6657cc145..000000000 --- a/src/tests/mocks/reentrancy_attacker_mock.cairo +++ /dev/null @@ -1,23 +0,0 @@ -#[starknet::interface] -trait IAttacker { - fn call_sender(self: @TState); -} - -#[starknet::contract] -mod Attacker { - use openzeppelin::tests::mocks::reentrancy_mock::IReentrancyMockDispatcher; - use openzeppelin::tests::mocks::reentrancy_mock::IReentrancyMockDispatcherTrait; - use starknet::ContractAddress; - use starknet::get_caller_address; - - #[storage] - struct Storage {} - - #[external(v0)] - impl IAttackerImpl of super::IAttacker { - fn call_sender(self: @ContractState) { - let caller: ContractAddress = get_caller_address(); - IReentrancyMockDispatcher { contract_address: caller }.callback(); - } - } -} diff --git a/src/tests/mocks/reentrancy_mock.cairo b/src/tests/mocks/reentrancy_mock.cairo deleted file mode 100644 index 7107bb970..000000000 --- a/src/tests/mocks/reentrancy_mock.cairo +++ /dev/null @@ -1,97 +0,0 @@ -use starknet::ContractAddress; - -#[starknet::interface] -trait IReentrancyGuarded { - fn count_external_recursive(ref self: TState, n: felt252); -} - -#[starknet::interface] -trait IReentrancyMock { - fn count(ref self: TState); - fn current_count(self: @TState) -> felt252; - fn callback(ref self: TState); - fn count_local_recursive(ref self: TState, n: felt252); - fn count_external_recursive(ref self: TState, n: felt252); - fn count_and_call(ref self: TState, attacker: ContractAddress); -} - -#[starknet::contract] -mod ReentrancyMock { - use openzeppelin::security::reentrancyguard::ReentrancyGuardComponent; - use openzeppelin::tests::mocks::reentrancy_attacker_mock::IAttackerDispatcher; - use openzeppelin::tests::mocks::reentrancy_attacker_mock::IAttackerDispatcherTrait; - use starknet::ContractAddress; - use starknet::get_contract_address; - use super::IReentrancyGuardedDispatcher; - use super::IReentrancyGuardedDispatcherTrait; - - component!( - path: ReentrancyGuardComponent, storage: reentrancy_guard, event: ReentrancyGuardEvent - ); - - impl InternalImpl = ReentrancyGuardComponent::InternalImpl; - - #[storage] - struct Storage { - counter: felt252, - #[substorage(v0)] - reentrancy_guard: ReentrancyGuardComponent::Storage - } - - #[event] - #[derive(Drop, starknet::Event)] - enum Event { - #[flat] - ReentrancyGuardEvent: ReentrancyGuardComponent::Event - } - - #[external(v0)] - impl IReentrancyMockImpl of super::IReentrancyMock { - fn count(ref self: ContractState) { - self.counter.write(self.counter.read() + 1); - } - - fn current_count(self: @ContractState) -> felt252 { - self.counter.read() - } - - fn callback(ref self: ContractState) { - self.reentrancy_guard.start(); - self.count(); - self.reentrancy_guard.end(); - } - - fn count_local_recursive(ref self: ContractState, n: felt252) { - self.reentrancy_guard.start(); - - if n != 0 { - self.count(); - self.count_local_recursive(n - 1); - } - - self.reentrancy_guard.end(); - } - - fn count_external_recursive(ref self: ContractState, n: felt252) { - self.reentrancy_guard.start(); - - if n != 0 { - self.count(); - let this: ContractAddress = get_contract_address(); - IReentrancyGuardedDispatcher { contract_address: this } - .count_external_recursive(n - 1) - } - - self.reentrancy_guard.end(); - } - - fn count_and_call(ref self: ContractState, attacker: ContractAddress) { - self.reentrancy_guard.start(); - - self.count(); - IAttackerDispatcher { contract_address: attacker }.call_sender(); - - self.reentrancy_guard.end(); - } - } -} diff --git a/src/tests/mocks/src5_mocks.cairo b/src/tests/mocks/src5_mocks.cairo index f63776568..9264264b7 100644 --- a/src/tests/mocks/src5_mocks.cairo +++ b/src/tests/mocks/src5_mocks.cairo @@ -77,7 +77,7 @@ mod SnakeSRC5PanicMock { #[external(v0)] fn supports_interface(self: @ContractState, interface_id: felt252) -> bool { - panic_with_felt252('Some error'); + panic!("Some error"); false } } @@ -89,7 +89,7 @@ mod CamelSRC5PanicMock { #[external(v0)] fn supportsInterface(self: @ContractState, interfaceId: felt252) -> bool { - panic_with_felt252('Some error'); + panic!("Some error"); false } } diff --git a/src/tests/security/test_initializable.cairo b/src/tests/security/test_initializable.cairo index 5b70c5d7c..c07c0f91e 100644 --- a/src/tests/security/test_initializable.cairo +++ b/src/tests/security/test_initializable.cairo @@ -1,6 +1,6 @@ use openzeppelin::security::InitializableComponent::{InitializableImpl, InternalImpl}; use openzeppelin::security::InitializableComponent; -use openzeppelin::tests::mocks::initializable_mock::InitializableMock; +use openzeppelin::tests::mocks::initializable_mocks::InitializableMock; type ComponentState = InitializableComponent::ComponentState; diff --git a/src/tests/security/test_pausable.cairo b/src/tests/security/test_pausable.cairo index df0204160..bd69f24a6 100644 --- a/src/tests/security/test_pausable.cairo +++ b/src/tests/security/test_pausable.cairo @@ -1,7 +1,7 @@ use openzeppelin::security::PausableComponent::{InternalImpl, PausableImpl}; use openzeppelin::security::PausableComponent::{Paused, Unpaused}; use openzeppelin::security::PausableComponent; -use openzeppelin::tests::mocks::pausable_mock::PausableMock; +use openzeppelin::tests::mocks::pausable_mocks::PausableMock; use openzeppelin::tests::utils::constants::{CALLER, ZERO}; use openzeppelin::tests::utils; use starknet::ContractAddress; diff --git a/src/tests/security/test_reentrancyguard.cairo b/src/tests/security/test_reentrancyguard.cairo index 4824308c4..13f15b8b4 100644 --- a/src/tests/security/test_reentrancyguard.cairo +++ b/src/tests/security/test_reentrancyguard.cairo @@ -1,9 +1,8 @@ use openzeppelin::security::ReentrancyGuardComponent::InternalImpl; use openzeppelin::security::ReentrancyGuardComponent; -use openzeppelin::tests::mocks::reentrancy_attacker_mock::Attacker; -use openzeppelin::tests::mocks::reentrancy_mock::IReentrancyMockDispatcher; -use openzeppelin::tests::mocks::reentrancy_mock::IReentrancyMockDispatcherTrait; -use openzeppelin::tests::mocks::reentrancy_mock::ReentrancyMock; +use openzeppelin::tests::mocks::reentrancy_mocks::{ + Attacker, ReentrancyMock, IReentrancyMockDispatcher, IReentrancyMockDispatcherTrait +}; use openzeppelin::tests::utils; use starknet::storage::StorageMemberAccessTrait; diff --git a/src/tests/token/test_dual20.cairo b/src/tests/token/test_dual20.cairo index 48324ff9c..88e4558a8 100644 --- a/src/tests/token/test_dual20.cairo +++ b/src/tests/token/test_dual20.cairo @@ -73,7 +73,7 @@ fn test_dual_no_name() { #[test] #[available_gas(2000000)] -#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_name_exists_and_panics() { let (dispatcher, _) = setup_erc20_panic(); dispatcher.name(); @@ -98,7 +98,7 @@ fn test_dual_no_symbol() { #[test] #[available_gas(2000000)] -#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_symbol_exists_and_panics() { let (dispatcher, _) = setup_erc20_panic(); dispatcher.symbol(); @@ -123,7 +123,7 @@ fn test_dual_no_decimals() { #[test] #[available_gas(2000000)] -#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_decimals_exists_and_panics() { let (dispatcher, _) = setup_erc20_panic(); dispatcher.decimals(); @@ -153,7 +153,7 @@ fn test_dual_no_transfer() { #[test] #[available_gas(2000000)] -#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_transfer_exists_and_panics() { let (dispatcher, _) = setup_erc20_panic(); dispatcher.transfer(RECIPIENT(), VALUE); @@ -183,7 +183,7 @@ fn test_dual_no_approve() { #[test] #[available_gas(2000000)] -#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_approve_exists_and_panics() { let (dispatcher, _) = setup_erc20_panic(); dispatcher.approve(SPENDER(), VALUE); @@ -210,7 +210,7 @@ fn test_dual_no_total_supply() { #[test] #[available_gas(2000000)] -#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_total_supply_exists_and_panics() { let (dispatcher, _) = setup_erc20_panic(); dispatcher.total_supply(); @@ -233,7 +233,7 @@ fn test_dual_no_balance_of() { #[test] #[available_gas(2000000)] -#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_balance_of_exists_and_panics() { let (dispatcher, _) = setup_erc20_panic(); dispatcher.balance_of(OWNER()); @@ -261,7 +261,7 @@ fn test_dual_no_transfer_from() { #[test] #[available_gas(2000000)] -#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_transfer_from_exists_and_panics() { let (dispatcher, _) = setup_erc20_panic(); dispatcher.transfer_from(OWNER(), RECIPIENT(), VALUE); @@ -280,7 +280,7 @@ fn test_dual_totalSupply() { #[test] #[available_gas(2000000)] -#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_totalSupply_exists_and_panics() { let (_, dispatcher) = setup_erc20_panic(); dispatcher.total_supply(); @@ -295,7 +295,7 @@ fn test_dual_balanceOf() { #[test] #[available_gas(2000000)] -#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_balanceOf_exists_and_panics() { let (_, dispatcher) = setup_erc20_panic(); dispatcher.balance_of(OWNER()); @@ -315,7 +315,7 @@ fn test_dual_transferFrom() { #[test] #[available_gas(2000000)] -#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_transferFrom_exists_and_panics() { let (_, dispatcher) = setup_erc20_panic(); dispatcher.transfer_from(OWNER(), RECIPIENT(), VALUE); diff --git a/src/tests/token/test_dual721.cairo b/src/tests/token/test_dual721.cairo index 28e2c196b..5611ef2d5 100644 --- a/src/tests/token/test_dual721.cairo +++ b/src/tests/token/test_dual721.cairo @@ -90,7 +90,7 @@ fn test_dual_no_name() { #[test] #[available_gas(2000000)] -#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_name_exists_and_panics() { let (dispatcher, _) = setup_erc721_panic(); dispatcher.name(); @@ -115,7 +115,7 @@ fn test_dual_no_symbol() { #[test] #[available_gas(2000000)] -#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_symbol_exists_and_panics() { let (dispatcher, _) = setup_erc721_panic(); dispatcher.symbol(); @@ -145,7 +145,7 @@ fn test_dual_no_approve() { #[test] #[available_gas(2000000)] -#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_approve_exists_and_panics() { let (dispatcher, _) = setup_erc721_panic(); dispatcher.approve(SPENDER(), TOKEN_ID); @@ -172,7 +172,7 @@ fn test_dual_no_balance_of() { #[test] #[available_gas(2000000)] -#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_balance_of_exists_and_panics() { let (dispatcher, _) = setup_erc721_panic(); dispatcher.balance_of(OWNER()); @@ -195,7 +195,7 @@ fn test_dual_no_owner_of() { #[test] #[available_gas(2000000)] -#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_owner_of_exists_and_panics() { let (dispatcher, _) = setup_erc721_panic(); dispatcher.owner_of(TOKEN_ID); @@ -219,7 +219,7 @@ fn test_dual_no_transfer_from() { #[test] #[available_gas(2000000)] -#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_transfer_from_exists_and_panics() { let (dispatcher, _) = setup_erc721_panic(); dispatcher.transfer_from(OWNER(), RECIPIENT(), TOKEN_ID); @@ -244,7 +244,7 @@ fn test_dual_no_safe_transfer_from() { #[test] #[available_gas(2000000)] -#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_safe_transfer_from_exists_and_panics() { let (dispatcher, _) = setup_erc721_panic(); dispatcher.safe_transfer_from(OWNER(), RECIPIENT(), TOKEN_ID, DATA(true)); @@ -269,7 +269,7 @@ fn test_dual_no_get_approved() { #[test] #[available_gas(2000000)] -#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_get_approved_exists_and_panics() { let (dispatcher, _) = setup_erc721_panic(); dispatcher.get_approved(TOKEN_ID); @@ -294,7 +294,7 @@ fn test_dual_no_set_approval_for_all() { #[test] #[available_gas(2000000)] -#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_set_approval_for_all_exists_and_panics() { let (dispatcher, _) = setup_erc721_panic(); dispatcher.set_approval_for_all(OPERATOR(), true); @@ -319,7 +319,7 @@ fn test_dual_no_is_approved_for_all() { #[test] #[available_gas(2000000)] -#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_is_approved_for_all_exists_and_panics() { let (dispatcher, _) = setup_erc721_panic(); dispatcher.is_approved_for_all(OWNER(), OPERATOR()); @@ -342,7 +342,7 @@ fn test_dual_no_token_uri() { #[test] #[available_gas(2000000)] -#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_token_uri_exists_and_panics() { let (dispatcher, _) = setup_erc721_panic(); dispatcher.token_uri(TOKEN_ID); @@ -365,7 +365,7 @@ fn test_dual_no_supports_interface() { #[test] #[available_gas(2000000)] -#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_supports_interface_exists_and_panics() { let (dispatcher, _) = setup_erc721_panic(); dispatcher.supports_interface(IERC721_ID); @@ -384,7 +384,7 @@ fn test_dual_balanceOf() { #[test] #[available_gas(2000000)] -#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_balanceOf_exists_and_panics() { let (_, dispatcher) = setup_erc721_panic(); dispatcher.balance_of(OWNER()); @@ -399,7 +399,7 @@ fn test_dual_ownerOf() { #[test] #[available_gas(2000000)] -#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_ownerOf_exists_and_panics() { let (_, dispatcher) = setup_erc721_panic(); dispatcher.owner_of(TOKEN_ID); @@ -416,7 +416,7 @@ fn test_dual_transferFrom() { #[test] #[available_gas(2000000)] -#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_transferFrom_exists_and_panics() { let (_, dispatcher) = setup_erc721_panic(); dispatcher.transfer_from(OWNER(), RECIPIENT(), TOKEN_ID); @@ -433,7 +433,7 @@ fn test_dual_safeTransferFrom() { #[test] #[available_gas(2000000)] -#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_safeTransferFrom_exists_and_panics() { let (_, dispatcher) = setup_erc721_panic(); dispatcher.safe_transfer_from(OWNER(), RECIPIENT(), TOKEN_ID, DATA(true)); @@ -450,7 +450,7 @@ fn test_dual_getApproved() { #[test] #[available_gas(2000000)] -#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_getApproved_exists_and_panics() { let (_, dispatcher) = setup_erc721_panic(); dispatcher.get_approved(TOKEN_ID); @@ -467,7 +467,7 @@ fn test_dual_setApprovalForAll() { #[test] #[available_gas(2000000)] -#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_setApprovalForAll_exists_and_panics() { let (_, dispatcher) = setup_erc721_panic(); dispatcher.set_approval_for_all(OPERATOR(), true); @@ -484,7 +484,7 @@ fn test_dual_isApprovedForAll() { #[test] #[available_gas(2000000)] -#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_isApprovedForAll_exists_and_panics() { let (_, dispatcher) = setup_erc721_panic(); dispatcher.is_approved_for_all(OWNER(), OPERATOR()); @@ -499,7 +499,7 @@ fn test_dual_tokenURI() { #[test] #[available_gas(2000000)] -#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_tokenURI_exists_and_panics() { let (_, dispatcher) = setup_erc721_panic(); dispatcher.token_uri(TOKEN_ID); @@ -514,7 +514,7 @@ fn test_dual_supportsInterface() { #[test] #[available_gas(2000000)] -#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_supportsInterface_exists_and_panics() { let (_, dispatcher) = setup_erc721_panic(); dispatcher.supports_interface(IERC721_ID); diff --git a/src/tests/token/test_dual721_receiver.cairo b/src/tests/token/test_dual721_receiver.cairo index 0ef522c9e..922d235b4 100644 --- a/src/tests/token/test_dual721_receiver.cairo +++ b/src/tests/token/test_dual721_receiver.cairo @@ -84,7 +84,7 @@ fn test_dual_no_on_erc721_received() { #[test] #[available_gas(2000000)] -#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_on_erc721_received_exists_and_panics() { let (dispatcher, _) = setup_erc721_receiver_panic(); dispatcher.on_erc721_received(OPERATOR(), OWNER(), TOKEN_ID, DATA(true)); @@ -107,7 +107,7 @@ fn test_dual_onERC721Received() { #[test] #[available_gas(2000000)] -#[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_onERC721Received_exists_and_panics() { let (_, dispatcher) = setup_erc721_receiver_panic(); dispatcher.on_erc721_received(OPERATOR(), OWNER(), TOKEN_ID, DATA(true)); From b8c68d9126979b8e750abc4e48c4fab48aa3a4a4 Mon Sep 17 00:00:00 2001 From: Eric Nordelo Date: Thu, 28 Dec 2023 13:22:46 +0100 Subject: [PATCH 02/15] feat: add missing mocks --- src/tests/mocks/initializable_mocks.cairo | 23 ++++ src/tests/mocks/pausable_mocks.cairo | 23 ++++ src/tests/mocks/reentrancy_mocks.cairo | 125 ++++++++++++++++++++++ 3 files changed, 171 insertions(+) create mode 100644 src/tests/mocks/initializable_mocks.cairo create mode 100644 src/tests/mocks/pausable_mocks.cairo create mode 100644 src/tests/mocks/reentrancy_mocks.cairo diff --git a/src/tests/mocks/initializable_mocks.cairo b/src/tests/mocks/initializable_mocks.cairo new file mode 100644 index 000000000..9b85fc5c8 --- /dev/null +++ b/src/tests/mocks/initializable_mocks.cairo @@ -0,0 +1,23 @@ +#[starknet::contract] +mod InitializableMock { + use openzeppelin::security::initializable::InitializableComponent; + + component!(path: InitializableComponent, storage: initializable, event: InitializableEvent); + + #[abi(embed_v0)] + impl InitializableImpl = + InitializableComponent::InitializableImpl; + + #[storage] + struct Storage { + #[substorage(v0)] + initializable: InitializableComponent::Storage + } + + #[event] + #[derive(Drop, starknet::Event)] + enum Event { + #[flat] + InitializableEvent: InitializableComponent::Event + } +} diff --git a/src/tests/mocks/pausable_mocks.cairo b/src/tests/mocks/pausable_mocks.cairo new file mode 100644 index 000000000..2cb1e9317 --- /dev/null +++ b/src/tests/mocks/pausable_mocks.cairo @@ -0,0 +1,23 @@ +#[starknet::contract] +mod PausableMock { + use openzeppelin::security::pausable::PausableComponent; + + component!(path: PausableComponent, storage: pausable, event: PausableEvent); + + #[abi(embed_v0)] + impl PausableImpl = PausableComponent::PausableImpl; + impl InternalImpl = PausableComponent::InternalImpl; + + #[storage] + struct Storage { + #[substorage(v0)] + pausable: PausableComponent::Storage + } + + #[event] + #[derive(Drop, starknet::Event)] + enum Event { + #[flat] + PausableEvent: PausableComponent::Event + } +} diff --git a/src/tests/mocks/reentrancy_mocks.cairo b/src/tests/mocks/reentrancy_mocks.cairo new file mode 100644 index 000000000..3cdf87c24 --- /dev/null +++ b/src/tests/mocks/reentrancy_mocks.cairo @@ -0,0 +1,125 @@ +use starknet::ContractAddress; + +#[starknet::interface] +trait IReentrancyGuarded { + fn count_external_recursive(ref self: TState, n: felt252); +} + +#[starknet::interface] +trait IReentrancyMock { + fn count(ref self: TState); + fn current_count(self: @TState) -> felt252; + fn callback(ref self: TState); + fn count_local_recursive(ref self: TState, n: felt252); + fn count_external_recursive(ref self: TState, n: felt252); + fn count_and_call(ref self: TState, attacker: ContractAddress); +} + +#[starknet::contract] +mod ReentrancyMock { + use openzeppelin::security::reentrancyguard::ReentrancyGuardComponent; + use starknet::ContractAddress; + use starknet::get_contract_address; + use super::IAttackerDispatcher; + use super::IAttackerDispatcherTrait; + use super::IReentrancyGuardedDispatcher; + use super::IReentrancyGuardedDispatcherTrait; + + component!( + path: ReentrancyGuardComponent, storage: reentrancy_guard, event: ReentrancyGuardEvent + ); + + impl InternalImpl = ReentrancyGuardComponent::InternalImpl; + + #[storage] + struct Storage { + counter: felt252, + #[substorage(v0)] + reentrancy_guard: ReentrancyGuardComponent::Storage + } + + #[event] + #[derive(Drop, starknet::Event)] + enum Event { + #[flat] + ReentrancyGuardEvent: ReentrancyGuardComponent::Event + } + + #[external(v0)] + impl IReentrancyMockImpl of super::IReentrancyMock { + fn count(ref self: ContractState) { + self.counter.write(self.counter.read() + 1); + } + + fn current_count(self: @ContractState) -> felt252 { + self.counter.read() + } + + fn callback(ref self: ContractState) { + self.reentrancy_guard.start(); + self.count(); + self.reentrancy_guard.end(); + } + + fn count_local_recursive(ref self: ContractState, n: felt252) { + self.reentrancy_guard.start(); + + if n != 0 { + self.count(); + self.count_local_recursive(n - 1); + } + + self.reentrancy_guard.end(); + } + + fn count_external_recursive(ref self: ContractState, n: felt252) { + self.reentrancy_guard.start(); + + if n != 0 { + self.count(); + let this: ContractAddress = get_contract_address(); + IReentrancyGuardedDispatcher { contract_address: this } + .count_external_recursive(n - 1) + } + + self.reentrancy_guard.end(); + } + + fn count_and_call(ref self: ContractState, attacker: ContractAddress) { + self.reentrancy_guard.start(); + + self.count(); + IAttackerDispatcher { contract_address: attacker }.call_sender(); + + self.reentrancy_guard.end(); + } + } +} + +// +// Attacker +// + +#[starknet::interface] +trait IAttacker { + fn call_sender(self: @TState); +} + +#[starknet::contract] +mod Attacker { + use starknet::ContractAddress; + use starknet::get_caller_address; + use super::IReentrancyMockDispatcher; + use super::IReentrancyMockDispatcherTrait; + + #[storage] + struct Storage {} + + #[external(v0)] + impl IAttackerImpl of super::IAttacker { + fn call_sender(self: @ContractState) { + let caller: ContractAddress = get_caller_address(); + IReentrancyMockDispatcher { contract_address: caller }.callback(); + } + } +} From 638b37a9de53a0502b704b6feeb674ebf976083d Mon Sep 17 00:00:00 2001 From: Eric Nordelo Date: Wed, 3 Jan 2024 12:57:55 +0100 Subject: [PATCH 03/15] refactor: remove available gas --- .github/workflows/test.yml | 2 +- Scarb.toml | 4 +- src/tests/access/test_accesscontrol.cairo | 73 ++++----------- .../access/test_dual_accesscontrol.cairo | 30 ------- src/tests/access/test_dual_ownable.cairo | 13 --- src/tests/access/test_ownable.cairo | 19 ---- src/tests/account/test_account.cairo | 27 ------ src/tests/account/test_dual_account.cairo | 20 ----- src/tests/introspection/test_dual_src5.cairo | 5 -- src/tests/introspection/test_src5.cairo | 5 -- src/tests/presets/test_account.cairo | 26 ------ src/tests/presets/test_erc20.cairo | 33 ------- src/tests/presets/test_erc721.cairo | 66 -------------- src/tests/security/test_initializable.cairo | 2 - src/tests/security/test_pausable.cairo | 9 -- src/tests/security/test_reentrancyguard.cairo | 7 -- src/tests/token/test_dual20.cairo | 30 ------- src/tests/token/test_dual721.cairo | 54 ----------- src/tests/token/test_dual721_receiver.cairo | 5 -- src/tests/token/test_erc20.cairo | 48 ---------- src/tests/token/test_erc721.cairo | 89 ------------------- src/tests/token/test_erc721_receiver.cairo | 2 - src/tests/upgrades/test_upgradeable.cairo | 6 -- 23 files changed, 22 insertions(+), 553 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 117bdaedb..99a9e2fbf 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -16,7 +16,7 @@ jobs: - uses: actions/checkout@v3 - uses: software-mansion/setup-scarb@v1 with: - scarb-version: "2.3.1" + scarb-version: "2.4.2" - name: Markdown lint uses: DavidAnson/markdownlint-cli2-action@5b7c9f74fec47e6b15667b2cc23c63dff11e449e # v9 with: diff --git a/Scarb.toml b/Scarb.toml index ea1607368..5baba8b97 100644 --- a/Scarb.toml +++ b/Scarb.toml @@ -2,7 +2,7 @@ name = "openzeppelin" version = "0.8.0" edition = "2023_01" -cairo-version = "2.4.1" +cairo-version = "2.4.2" authors = ["OpenZeppelin Community "] description = "OpenZeppelin Contracts written in Cairo for StarkNet, a decentralized ZK Rollup" documentation = "https://docs.openzeppelin.com/contracts-cairo" @@ -12,7 +12,7 @@ license-file = "LICENSE" keywords = ["openzeppelin", "starknet", "cairo", "contracts", "security", "standards"] [dependencies] -starknet = "2.4.1" +starknet = "2.4.2" [lib] diff --git a/src/tests/access/test_accesscontrol.cairo b/src/tests/access/test_accesscontrol.cairo index 018ae499b..f1f6a459b 100644 --- a/src/tests/access/test_accesscontrol.cairo +++ b/src/tests/access/test_accesscontrol.cairo @@ -42,7 +42,6 @@ fn setup() -> ComponentState { // #[test] -#[available_gas(2000000)] fn test_initializer() { let mut state = COMPONENT_STATE(); state.initializer(); @@ -54,21 +53,19 @@ fn test_initializer() { // #[test] -#[available_gas(2000000)] fn test_has_role() { let mut state = setup(); - assert(!state.has_role(ROLE, AUTHORIZED()), 'should not have role'); + assert(!state.has_role(ROLE, AUTHORIZED()), 'Should not have role'); state._grant_role(ROLE, AUTHORIZED()); - assert(state.has_role(ROLE, AUTHORIZED()), 'should have role'); + assert(state.has_role(ROLE, AUTHORIZED()), 'Should have role'); } #[test] -#[available_gas(2000000)] fn test_hasRole() { let mut state = setup(); - assert(!state.hasRole(ROLE, AUTHORIZED()), 'should not have role'); + assert(!state.hasRole(ROLE, AUTHORIZED()), 'Should not have role'); state._grant_role(ROLE, AUTHORIZED()); - assert(state.hasRole(ROLE, AUTHORIZED()), 'should have role'); + assert(state.hasRole(ROLE, AUTHORIZED()), 'Should have role'); } // @@ -76,7 +73,6 @@ fn test_hasRole() { // #[test] -#[available_gas(2000000)] fn test_assert_only_role() { let mut state = setup(); testing::set_caller_address(ADMIN()); @@ -87,7 +83,6 @@ fn test_assert_only_role() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('Caller is missing role',))] fn test_assert_only_role_unauthorized() { let state = setup(); @@ -96,7 +91,6 @@ fn test_assert_only_role_unauthorized() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('Caller is missing role',))] fn test_assert_only_role_unauthorized_when_authorized_for_another_role() { let mut state = setup(); @@ -111,51 +105,46 @@ fn test_assert_only_role_unauthorized_when_authorized_for_another_role() { // #[test] -#[available_gas(2000000)] fn test_grant_role() { let mut state = setup(); testing::set_caller_address(ADMIN()); state.grant_role(ROLE, AUTHORIZED()); assert_event_role_granted(ROLE, AUTHORIZED(), ADMIN()); - assert(state.has_role(ROLE, AUTHORIZED()), 'Role should be granted'); + assert(state.has_role(ROLE, AUTHORIZED()), 'Should have role granted'); } #[test] -#[available_gas(2000000)] fn test_grantRole() { let mut state = setup(); testing::set_caller_address(ADMIN()); state.grantRole(ROLE, AUTHORIZED()); assert_event_role_granted(ROLE, AUTHORIZED(), ADMIN()); - assert(state.hasRole(ROLE, AUTHORIZED()), 'Role should be granted'); + assert(state.hasRole(ROLE, AUTHORIZED()), 'Should have role granted'); } #[test] -#[available_gas(2000000)] fn test_grant_role_multiple_times_for_granted_role() { let mut state = setup(); testing::set_caller_address(ADMIN()); state.grant_role(ROLE, AUTHORIZED()); state.grant_role(ROLE, AUTHORIZED()); - assert(state.has_role(ROLE, AUTHORIZED()), 'Role should still be granted'); + assert(state.has_role(ROLE, AUTHORIZED()), 'Should have role granted'); } #[test] -#[available_gas(2000000)] fn test_grantRole_multiple_times_for_granted_role() { let mut state = setup(); testing::set_caller_address(ADMIN()); state.grantRole(ROLE, AUTHORIZED()); state.grantRole(ROLE, AUTHORIZED()); - assert(state.hasRole(ROLE, AUTHORIZED()), 'Role should still be granted'); + assert(state.hasRole(ROLE, AUTHORIZED()), 'Should have role granted'); } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('Caller is missing role',))] fn test_grant_role_unauthorized() { let mut state = setup(); @@ -164,7 +153,6 @@ fn test_grant_role_unauthorized() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('Caller is missing role',))] fn test_grantRole_unauthorized() { let mut state = setup(); @@ -177,7 +165,6 @@ fn test_grantRole_unauthorized() { // #[test] -#[available_gas(2000000)] fn test_revoke_role_for_role_not_granted() { let mut state = setup(); testing::set_caller_address(ADMIN()); @@ -185,7 +172,6 @@ fn test_revoke_role_for_role_not_granted() { } #[test] -#[available_gas(2000000)] fn test_revokeRole_for_role_not_granted() { let mut state = setup(); testing::set_caller_address(ADMIN()); @@ -193,7 +179,6 @@ fn test_revokeRole_for_role_not_granted() { } #[test] -#[available_gas(2000000)] fn test_revoke_role_for_granted_role() { let mut state = setup(); testing::set_caller_address(ADMIN()); @@ -204,11 +189,10 @@ fn test_revoke_role_for_granted_role() { state.revoke_role(ROLE, AUTHORIZED()); assert_event_role_revoked(ROLE, AUTHORIZED(), ADMIN()); - assert(!state.has_role(ROLE, AUTHORIZED()), 'Role should be revoked'); + assert(!state.has_role(ROLE, AUTHORIZED()), 'Should have role revoked'); } #[test] -#[available_gas(2000000)] fn test_revokeRole_for_granted_role() { let mut state = setup(); testing::set_caller_address(ADMIN()); @@ -219,11 +203,10 @@ fn test_revokeRole_for_granted_role() { state.revokeRole(ROLE, AUTHORIZED()); assert_event_role_revoked(ROLE, AUTHORIZED(), ADMIN()); - assert(!state.hasRole(ROLE, AUTHORIZED()), 'Role should be revoked'); + assert(!state.hasRole(ROLE, AUTHORIZED()), 'Should have role revoked'); } #[test] -#[available_gas(2000000)] fn test_revoke_role_multiple_times_for_granted_role() { let mut state = setup(); testing::set_caller_address(ADMIN()); @@ -231,11 +214,10 @@ fn test_revoke_role_multiple_times_for_granted_role() { state.grant_role(ROLE, AUTHORIZED()); state.revoke_role(ROLE, AUTHORIZED()); state.revoke_role(ROLE, AUTHORIZED()); - assert(!state.has_role(ROLE, AUTHORIZED()), 'Role should still be revoked'); + assert(!state.has_role(ROLE, AUTHORIZED()), 'Should have role revoked'); } #[test] -#[available_gas(2000000)] fn test_revokeRole_multiple_times_for_granted_role() { let mut state = setup(); testing::set_caller_address(ADMIN()); @@ -243,11 +225,10 @@ fn test_revokeRole_multiple_times_for_granted_role() { state.grantRole(ROLE, AUTHORIZED()); state.revokeRole(ROLE, AUTHORIZED()); state.revokeRole(ROLE, AUTHORIZED()); - assert(!state.hasRole(ROLE, AUTHORIZED()), 'Role should still be revoked'); + assert(!state.hasRole(ROLE, AUTHORIZED()), 'Should have role revoked'); } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('Caller is missing role',))] fn test_revoke_role_unauthorized() { let mut state = setup(); @@ -256,7 +237,6 @@ fn test_revoke_role_unauthorized() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('Caller is missing role',))] fn test_revokeRole_unauthorized() { let mut state = setup(); @@ -269,7 +249,6 @@ fn test_revokeRole_unauthorized() { // #[test] -#[available_gas(2000000)] fn test_renounce_role_for_role_not_granted() { let mut state = setup(); testing::set_caller_address(AUTHORIZED()); @@ -277,7 +256,6 @@ fn test_renounce_role_for_role_not_granted() { } #[test] -#[available_gas(2000000)] fn test_renounceRole_for_role_not_granted() { let mut state = setup(); testing::set_caller_address(AUTHORIZED()); @@ -285,7 +263,6 @@ fn test_renounceRole_for_role_not_granted() { } #[test] -#[available_gas(2000000)] fn test_renounce_role_for_granted_role() { let mut state = setup(); testing::set_caller_address(ADMIN()); @@ -297,11 +274,10 @@ fn test_renounce_role_for_granted_role() { state.renounce_role(ROLE, AUTHORIZED()); assert_event_role_revoked(ROLE, AUTHORIZED(), AUTHORIZED()); - assert(!state.has_role(ROLE, AUTHORIZED()), 'Role should be renounced'); + assert(!state.has_role(ROLE, AUTHORIZED()), 'Should have role revoked'); } #[test] -#[available_gas(2000000)] fn test_renounceRole_for_granted_role() { let mut state = setup(); testing::set_caller_address(ADMIN()); @@ -313,11 +289,10 @@ fn test_renounceRole_for_granted_role() { state.renounceRole(ROLE, AUTHORIZED()); assert_event_role_revoked(ROLE, AUTHORIZED(), AUTHORIZED()); - assert(!state.hasRole(ROLE, AUTHORIZED()), 'Role should be renounced'); + assert(!state.hasRole(ROLE, AUTHORIZED()), 'Should have role revoked'); } #[test] -#[available_gas(2000000)] fn test_renounce_role_multiple_times_for_granted_role() { let mut state = setup(); testing::set_caller_address(ADMIN()); @@ -326,11 +301,10 @@ fn test_renounce_role_multiple_times_for_granted_role() { testing::set_caller_address(AUTHORIZED()); state.renounce_role(ROLE, AUTHORIZED()); state.renounce_role(ROLE, AUTHORIZED()); - assert(!state.has_role(ROLE, AUTHORIZED()), 'Role should still be renounced'); + assert(!state.has_role(ROLE, AUTHORIZED()), 'Should have role revoked'); } #[test] -#[available_gas(2000000)] fn test_renounceRole_multiple_times_for_granted_role() { let mut state = setup(); testing::set_caller_address(ADMIN()); @@ -339,11 +313,10 @@ fn test_renounceRole_multiple_times_for_granted_role() { testing::set_caller_address(AUTHORIZED()); state.renounceRole(ROLE, AUTHORIZED()); state.renounceRole(ROLE, AUTHORIZED()); - assert(!state.hasRole(ROLE, AUTHORIZED()), 'Role should still be renounced'); + assert(!state.hasRole(ROLE, AUTHORIZED()), 'Should have role revoked'); } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('Can only renounce role for self',))] fn test_renounce_role_unauthorized() { let mut state = setup(); @@ -355,7 +328,6 @@ fn test_renounce_role_unauthorized() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('Can only renounce role for self',))] fn test_renounceRole_unauthorized() { let mut state = setup(); @@ -371,18 +343,16 @@ fn test_renounceRole_unauthorized() { // #[test] -#[available_gas(2000000)] fn test__set_role_admin() { let mut state = setup(); - assert(state.get_role_admin(ROLE) == DEFAULT_ADMIN_ROLE, 'ROLE admin default should be 0'); + assert(state.get_role_admin(ROLE) == DEFAULT_ADMIN_ROLE, 'Default admin should be zero'); state._set_role_admin(ROLE, OTHER_ROLE); assert_event_role_admin_changed(ROLE, DEFAULT_ADMIN_ROLE, OTHER_ROLE); - assert(state.get_role_admin(ROLE) == OTHER_ROLE, 'ROLE admin should be OTHER_ROLE'); + assert(state.get_role_admin(ROLE) == OTHER_ROLE, 'Admin should be OTHER_ROLE'); } #[test] -#[available_gas(2000000)] fn test_new_admin_can_grant_roles() { let mut state = setup(); state._set_role_admin(ROLE, OTHER_ROLE); @@ -392,11 +362,10 @@ fn test_new_admin_can_grant_roles() { testing::set_caller_address(OTHER_ADMIN()); state.grant_role(ROLE, AUTHORIZED()); - assert(state.has_role(ROLE, AUTHORIZED()), 'AUTHORIZED should have ROLE'); + assert(state.has_role(ROLE, AUTHORIZED()), 'Should have role granted'); } #[test] -#[available_gas(2000000)] fn test_new_admin_can_revoke_roles() { let mut state = setup(); state._set_role_admin(ROLE, OTHER_ROLE); @@ -411,7 +380,6 @@ fn test_new_admin_can_revoke_roles() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('Caller is missing role',))] fn test_previous_admin_cannot_grant_roles() { let mut state = setup(); @@ -421,7 +389,6 @@ fn test_previous_admin_cannot_grant_roles() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('Caller is missing role',))] fn test_previous_admin_cannot_revoke_roles() { let mut state = setup(); @@ -435,14 +402,12 @@ fn test_previous_admin_cannot_revoke_roles() { // #[test] -#[available_gas(2000000)] fn test_other_role_admin_is_the_default_admin_role() { let state = setup(); assert(state.get_role_admin(OTHER_ROLE) == DEFAULT_ADMIN_ROLE, 'Should be DEFAULT_ADMIN_ROLE'); } #[test] -#[available_gas(2000000)] fn test_default_admin_role_is_its_own_admin() { let state = setup(); assert( diff --git a/src/tests/access/test_dual_accesscontrol.cairo b/src/tests/access/test_dual_accesscontrol.cairo index b95bf9de0..2a8054cb0 100644 --- a/src/tests/access/test_dual_accesscontrol.cairo +++ b/src/tests/access/test_dual_accesscontrol.cairo @@ -61,14 +61,12 @@ fn setup_accesscontrol_panic() -> (DualCaseAccessControl, DualCaseAccessControl) // #[test] -#[available_gas(2000000)] fn test_dual_supports_interface() { let (dispatcher, _) = setup_snake(); assert(dispatcher.supports_interface(IACCESSCONTROL_ID), 'Should support own interface'); } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] fn test_dual_no_supports_interface() { let dispatcher = setup_non_accesscontrol(); @@ -76,7 +74,6 @@ fn test_dual_no_supports_interface() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_supports_interface_exists_and_panics() { let (dispatcher, _) = setup_accesscontrol_panic(); @@ -84,14 +81,12 @@ fn test_dual_supports_interface_exists_and_panics() { } #[test] -#[available_gas(2000000)] fn test_dual_has_role() { let (dispatcher, _) = setup_snake(); assert(dispatcher.has_role(DEFAULT_ADMIN_ROLE, ADMIN()), 'Should have role'); } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] fn test_dual_no_has_role() { let dispatcher = setup_non_accesscontrol(); @@ -99,7 +94,6 @@ fn test_dual_no_has_role() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_has_role_exists_and_panics() { let (dispatcher, _) = setup_accesscontrol_panic(); @@ -107,14 +101,12 @@ fn test_dual_has_role_exists_and_panics() { } #[test] -#[available_gas(2000000)] fn test_dual_get_role_admin() { let (dispatcher, _) = setup_snake(); assert(dispatcher.get_role_admin(ROLE) == DEFAULT_ADMIN_ROLE, 'Should get admin'); } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] fn test_dual_no_get_role_admin() { let dispatcher = setup_non_accesscontrol(); @@ -122,7 +114,6 @@ fn test_dual_no_get_role_admin() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_get_role_admin_exists_and_panics() { let (dispatcher, _) = setup_accesscontrol_panic(); @@ -130,7 +121,6 @@ fn test_dual_get_role_admin_exists_and_panics() { } #[test] -#[available_gas(2000000)] fn test_dual_grant_role() { let (dispatcher, target) = setup_snake(); set_contract_address(ADMIN()); @@ -139,7 +129,6 @@ fn test_dual_grant_role() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] fn test_dual_no_grant_role() { let dispatcher = setup_non_accesscontrol(); @@ -147,7 +136,6 @@ fn test_dual_no_grant_role() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_grant_role_exists_and_panics() { let (dispatcher, _) = setup_accesscontrol_panic(); @@ -155,7 +143,6 @@ fn test_dual_grant_role_exists_and_panics() { } #[test] -#[available_gas(2000000)] fn test_dual_revoke_role() { let (dispatcher, target) = setup_snake(); set_contract_address(ADMIN()); @@ -164,7 +151,6 @@ fn test_dual_revoke_role() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] fn test_dual_no_revoke_role() { let dispatcher = setup_non_accesscontrol(); @@ -172,7 +158,6 @@ fn test_dual_no_revoke_role() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_revoke_role_exists_and_panics() { let (dispatcher, _) = setup_accesscontrol_panic(); @@ -180,7 +165,6 @@ fn test_dual_revoke_role_exists_and_panics() { } #[test] -#[available_gas(2000000)] fn test_dual_renounce_role() { let (dispatcher, target) = setup_snake(); set_contract_address(ADMIN()); @@ -189,7 +173,6 @@ fn test_dual_renounce_role() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] fn test_dual_no_renounce_role() { let dispatcher = setup_non_accesscontrol(); @@ -197,7 +180,6 @@ fn test_dual_no_renounce_role() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_renounce_role_exists_and_panics() { let (dispatcher, _) = setup_accesscontrol_panic(); @@ -209,14 +191,12 @@ fn test_dual_renounce_role_exists_and_panics() { // #[test] -#[available_gas(2000000)] fn test_dual_supportsInterface() { let (dispatcher, _) = setup_camel(); assert(dispatcher.supports_interface(IACCESSCONTROL_ID), 'Should support own interface'); } #[test] -#[available_gas(2000000)] #[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_supportsInterface_exists_and_panics() { let (_, dispatcher) = setup_accesscontrol_panic(); @@ -224,14 +204,12 @@ fn test_dual_supportsInterface_exists_and_panics() { } #[test] -#[available_gas(2000000)] fn test_dual_hasRole() { let (dispatcher, _) = setup_camel(); assert(dispatcher.has_role(DEFAULT_ADMIN_ROLE, ADMIN()), 'Should have role'); } #[test] -#[available_gas(2000000)] #[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_hasRole_exists_and_panics() { let (_, dispatcher) = setup_accesscontrol_panic(); @@ -239,14 +217,12 @@ fn test_dual_hasRole_exists_and_panics() { } #[test] -#[available_gas(2000000)] fn test_dual_getRoleAdmin() { let (dispatcher, _) = setup_camel(); assert(dispatcher.get_role_admin(ROLE) == DEFAULT_ADMIN_ROLE, 'Should get admin'); } #[test] -#[available_gas(2000000)] #[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_getRoleAdmin_exists_and_panics() { let (_, dispatcher) = setup_accesscontrol_panic(); @@ -254,7 +230,6 @@ fn test_dual_getRoleAdmin_exists_and_panics() { } #[test] -#[available_gas(2000000)] fn test_dual_grantRole() { let (dispatcher, target) = setup_camel(); set_contract_address(ADMIN()); @@ -263,7 +238,6 @@ fn test_dual_grantRole() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_grantRole_exists_and_panics() { let (_, dispatcher) = setup_accesscontrol_panic(); @@ -271,7 +245,6 @@ fn test_dual_grantRole_exists_and_panics() { } #[test] -#[available_gas(2000000)] fn test_dual_revokeRole() { let (dispatcher, target) = setup_camel(); set_contract_address(ADMIN()); @@ -281,7 +254,6 @@ fn test_dual_revokeRole() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_revokeRole_exists_and_panics() { let (_, dispatcher) = setup_accesscontrol_panic(); @@ -289,7 +261,6 @@ fn test_dual_revokeRole_exists_and_panics() { } #[test] -#[available_gas(2000000)] fn test_dual_renounceRole() { let (dispatcher, target) = setup_camel(); set_contract_address(ADMIN()); @@ -298,7 +269,6 @@ fn test_dual_renounceRole() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_renounceRole_exists_and_panics() { let (_, dispatcher) = setup_accesscontrol_panic(); diff --git a/src/tests/access/test_dual_ownable.cairo b/src/tests/access/test_dual_ownable.cairo index 6eac0c9dc..bacd2ce7a 100644 --- a/src/tests/access/test_dual_ownable.cairo +++ b/src/tests/access/test_dual_ownable.cairo @@ -53,7 +53,6 @@ fn setup_ownable_panic() -> (DualCaseOwnable, DualCaseOwnable) { // #[test] -#[available_gas(2000000)] fn test_dual_owner() { let (snake_dispatcher, _) = setup_snake(); let (camel_dispatcher, _) = setup_camel(); @@ -62,7 +61,6 @@ fn test_dual_owner() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] fn test_dual_no_owner() { let dispatcher = setup_non_ownable(); @@ -70,7 +68,6 @@ fn test_dual_no_owner() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_owner_exists_and_panics() { let (dispatcher, _) = setup_ownable_panic(); @@ -82,7 +79,6 @@ fn test_dual_owner_exists_and_panics() { // #[test] -#[available_gas(2000000)] fn test_dual_transfer_ownership() { let (dispatcher, target) = setup_snake(); set_contract_address(OWNER()); @@ -91,7 +87,6 @@ fn test_dual_transfer_ownership() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] fn test_dual_no_transfer_ownership() { let dispatcher = setup_non_ownable(); @@ -99,7 +94,6 @@ fn test_dual_no_transfer_ownership() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_transfer_ownership_exists_and_panics() { let (dispatcher, _) = setup_ownable_panic(); @@ -107,7 +101,6 @@ fn test_dual_transfer_ownership_exists_and_panics() { } #[test] -#[available_gas(2000000)] fn test_dual_renounce_ownership() { let (dispatcher, target) = setup_snake(); set_contract_address(OWNER()); @@ -116,7 +109,6 @@ fn test_dual_renounce_ownership() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] fn test_dual_no_renounce_ownership() { let dispatcher = setup_non_ownable(); @@ -124,7 +116,6 @@ fn test_dual_no_renounce_ownership() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_renounce_ownership_exists_and_panics() { let (dispatcher, _) = setup_ownable_panic(); @@ -136,7 +127,6 @@ fn test_dual_renounce_ownership_exists_and_panics() { // #[test] -#[available_gas(2000000)] fn test_dual_transferOwnership() { let (dispatcher, _) = setup_camel(); set_contract_address(OWNER()); @@ -145,7 +135,6 @@ fn test_dual_transferOwnership() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_transferOwnership_exists_and_panics() { let (_, dispatcher) = setup_ownable_panic(); @@ -153,7 +142,6 @@ fn test_dual_transferOwnership_exists_and_panics() { } #[test] -#[available_gas(2000000)] fn test_dual_renounceOwnership() { let (dispatcher, _) = setup_camel(); set_contract_address(OWNER()); @@ -162,7 +150,6 @@ fn test_dual_renounceOwnership() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_renounceOwnership_exists_and_panics() { let (_, dispatcher) = setup_ownable_panic(); diff --git a/src/tests/access/test_ownable.cairo b/src/tests/access/test_ownable.cairo index 29dca9fe7..0a1bebf28 100644 --- a/src/tests/access/test_ownable.cairo +++ b/src/tests/access/test_ownable.cairo @@ -31,7 +31,6 @@ fn setup() -> ComponentState { // #[test] -#[available_gas(2000000)] fn test_initializer_owner() { let mut state = COMPONENT_STATE(); assert(state.Ownable_owner.read().is_zero(), 'Should be zero'); @@ -47,7 +46,6 @@ fn test_initializer_owner() { // #[test] -#[available_gas(2000000)] fn test_assert_only_owner() { let state = setup(); testing::set_caller_address(OWNER()); @@ -55,7 +53,6 @@ fn test_assert_only_owner() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('Caller is not the owner',))] fn test_assert_only_owner_when_not_owner() { let state = setup(); @@ -64,7 +61,6 @@ fn test_assert_only_owner_when_not_owner() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('Caller is the zero address',))] fn test_assert_only_owner_when_caller_zero() { let state = setup(); @@ -76,7 +72,6 @@ fn test_assert_only_owner_when_caller_zero() { // #[test] -#[available_gas(2000000)] fn test__transfer_ownership() { let mut state = setup(); state._transfer_ownership(OTHER()); @@ -91,7 +86,6 @@ fn test__transfer_ownership() { // #[test] -#[available_gas(2000000)] fn test_transfer_ownership() { let mut state = setup(); testing::set_caller_address(OWNER()); @@ -103,7 +97,6 @@ fn test_transfer_ownership() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('New owner is the zero address',))] fn test_transfer_ownership_to_zero() { let mut state = setup(); @@ -112,7 +105,6 @@ fn test_transfer_ownership_to_zero() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('Caller is the zero address',))] fn test_transfer_ownership_from_zero() { let mut state = setup(); @@ -120,7 +112,6 @@ fn test_transfer_ownership_from_zero() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('Caller is not the owner',))] fn test_transfer_ownership_from_nonowner() { let mut state = setup(); @@ -129,7 +120,6 @@ fn test_transfer_ownership_from_nonowner() { } #[test] -#[available_gas(2000000)] fn test_transferOwnership() { let mut state = setup(); testing::set_caller_address(OWNER()); @@ -141,7 +131,6 @@ fn test_transferOwnership() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('New owner is the zero address',))] fn test_transferOwnership_to_zero() { let mut state = setup(); @@ -150,7 +139,6 @@ fn test_transferOwnership_to_zero() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('Caller is the zero address',))] fn test_transferOwnership_from_zero() { let mut state = setup(); @@ -158,7 +146,6 @@ fn test_transferOwnership_from_zero() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('Caller is not the owner',))] fn test_transferOwnership_from_nonowner() { let mut state = setup(); @@ -171,7 +158,6 @@ fn test_transferOwnership_from_nonowner() { // #[test] -#[available_gas(2000000)] fn test_renounce_ownership() { let mut state = setup(); testing::set_caller_address(OWNER()); @@ -183,7 +169,6 @@ fn test_renounce_ownership() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('Caller is the zero address',))] fn test_renounce_ownership_from_zero_address() { let mut state = setup(); @@ -191,7 +176,6 @@ fn test_renounce_ownership_from_zero_address() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('Caller is not the owner',))] fn test_renounce_ownership_from_nonowner() { let mut state = setup(); @@ -200,7 +184,6 @@ fn test_renounce_ownership_from_nonowner() { } #[test] -#[available_gas(2000000)] fn test_renounceOwnership() { let mut state = setup(); testing::set_caller_address(OWNER()); @@ -212,7 +195,6 @@ fn test_renounceOwnership() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('Caller is the zero address',))] fn test_renounceOwnership_from_zero_address() { let mut state = setup(); @@ -220,7 +202,6 @@ fn test_renounceOwnership_from_zero_address() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('Caller is not the owner',))] fn test_renounceOwnership_from_nonowner() { let mut state = setup(); diff --git a/src/tests/account/test_account.cairo b/src/tests/account/test_account.cairo index 3ad1018ab..a04cf9d14 100644 --- a/src/tests/account/test_account.cairo +++ b/src/tests/account/test_account.cairo @@ -106,7 +106,6 @@ fn deploy_erc20(recipient: ContractAddress, initial_supply: u256) -> IERC20Dispa // #[test] -#[available_gas(2000000)] fn test_is_valid_signature() { let mut state = COMPONENT_STATE(); let data = SIGNED_TX_DATA(); @@ -125,7 +124,6 @@ fn test_is_valid_signature() { } #[test] -#[available_gas(2000000)] fn test_isValidSignature() { let mut state = COMPONENT_STATE(); let data = SIGNED_TX_DATA(); @@ -148,7 +146,6 @@ fn test_isValidSignature() { // #[test] -#[available_gas(2000000)] fn test_validate_deploy() { let account = setup_dispatcher(Option::Some(@SIGNED_TX_DATA())); @@ -162,7 +159,6 @@ fn test_validate_deploy() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('Account: invalid signature', 'ENTRYPOINT_FAILED'))] fn test_validate_deploy_invalid_signature_data() { let mut data = SIGNED_TX_DATA(); @@ -173,7 +169,6 @@ fn test_validate_deploy_invalid_signature_data() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('Account: invalid signature', 'ENTRYPOINT_FAILED'))] fn test_validate_deploy_invalid_signature_length() { let account = setup_dispatcher(Option::Some(@SIGNED_TX_DATA())); @@ -186,7 +181,6 @@ fn test_validate_deploy_invalid_signature_length() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('Account: invalid signature', 'ENTRYPOINT_FAILED'))] fn test_validate_deploy_empty_signature() { let account = setup_dispatcher(Option::Some(@SIGNED_TX_DATA())); @@ -197,7 +191,6 @@ fn test_validate_deploy_empty_signature() { } #[test] -#[available_gas(2000000)] fn test_validate_declare() { let account = setup_dispatcher(Option::Some(@SIGNED_TX_DATA())); @@ -211,7 +204,6 @@ fn test_validate_declare() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('Account: invalid signature', 'ENTRYPOINT_FAILED'))] fn test_validate_declare_invalid_signature_data() { let mut data = SIGNED_TX_DATA(); @@ -222,7 +214,6 @@ fn test_validate_declare_invalid_signature_data() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('Account: invalid signature', 'ENTRYPOINT_FAILED'))] fn test_validate_declare_invalid_signature_length() { let account = setup_dispatcher(Option::Some(@SIGNED_TX_DATA())); @@ -235,7 +226,6 @@ fn test_validate_declare_invalid_signature_length() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('Account: invalid signature', 'ENTRYPOINT_FAILED'))] fn test_validate_declare_empty_signature() { let account = setup_dispatcher(Option::Some(@SIGNED_TX_DATA())); @@ -282,26 +272,22 @@ fn test_execute_with_version(version: Option) { } #[test] -#[available_gas(2000000)] fn test_execute() { test_execute_with_version(Option::None(())); } #[test] -#[available_gas(2000000)] fn test_execute_query_version() { test_execute_with_version(Option::Some(QUERY_VERSION)); } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('Account: invalid tx version', 'ENTRYPOINT_FAILED'))] fn test_execute_invalid_version() { test_execute_with_version(Option::Some(TRANSACTION_VERSION - 1)); } #[test] -#[available_gas(2000000)] fn test_validate() { let calls = array![]; let account = setup_dispatcher(Option::Some(@SIGNED_TX_DATA())); @@ -310,7 +296,6 @@ fn test_validate() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('Account: invalid signature', 'ENTRYPOINT_FAILED'))] fn test_validate_invalid() { let calls = array![]; @@ -322,7 +307,6 @@ fn test_validate_invalid() { } #[test] -#[available_gas(20000000)] fn test_multicall() { let account = setup_dispatcher(Option::Some(@SIGNED_TX_DATA())); let erc20 = deploy_erc20(account.contract_address, 1000); @@ -368,7 +352,6 @@ fn test_multicall() { } #[test] -#[available_gas(2000000)] fn test_multicall_zero_calls() { let account = setup_dispatcher(Option::Some(@SIGNED_TX_DATA())); let mut calls = array![]; @@ -380,7 +363,6 @@ fn test_multicall_zero_calls() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('Account: invalid caller',))] fn test_account_called_from_contract() { let state = setup(); @@ -398,7 +380,6 @@ fn test_account_called_from_contract() { // #[test] -#[available_gas(2000000)] fn test_public_key_setter_and_getter() { let mut state = COMPONENT_STATE(); testing::set_contract_address(ACCOUNT_ADDRESS()); @@ -423,7 +404,6 @@ fn test_public_key_setter_and_getter() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('Account: unauthorized',))] fn test_public_key_setter_different_account() { let mut state = COMPONENT_STATE(); @@ -439,7 +419,6 @@ fn test_public_key_setter_different_account() { // #[test] -#[available_gas(2000000)] fn test_public_key_setter_and_getter_camel() { let mut state = COMPONENT_STATE(); testing::set_contract_address(ACCOUNT_ADDRESS()); @@ -464,7 +443,6 @@ fn test_public_key_setter_and_getter_camel() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('Account: unauthorized',))] fn test_public_key_setter_different_account_camel() { let mut state = COMPONENT_STATE(); @@ -480,7 +458,6 @@ fn test_public_key_setter_different_account_camel() { // #[test] -#[available_gas(2000000)] fn test_initializer() { let mut state = COMPONENT_STATE(); let mock_state = CONTRACT_STATE(); @@ -500,7 +477,6 @@ fn test_initializer() { } #[test] -#[available_gas(2000000)] fn test_assert_only_self_true() { let mut state = COMPONENT_STATE(); @@ -510,7 +486,6 @@ fn test_assert_only_self_true() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('Account: unauthorized',))] fn test_assert_only_self_false() { let mut state = COMPONENT_STATE(); @@ -522,7 +497,6 @@ fn test_assert_only_self_false() { } #[test] -#[available_gas(2000000)] fn test__is_valid_signature() { let mut state = COMPONENT_STATE(); let data = SIGNED_TX_DATA(); @@ -545,7 +519,6 @@ fn test__is_valid_signature() { } #[test] -#[available_gas(2000000)] fn test__set_public_key() { let mut state = COMPONENT_STATE(); state._set_public_key(PUBKEY); diff --git a/src/tests/account/test_dual_account.cairo b/src/tests/account/test_dual_account.cairo index 16d803e67..50336091d 100644 --- a/src/tests/account/test_dual_account.cairo +++ b/src/tests/account/test_dual_account.cairo @@ -52,7 +52,6 @@ fn setup_account_panic() -> (DualCaseAccount, DualCaseAccount) { // #[test] -#[available_gas(2000000)] fn test_dual_set_public_key() { let (snake_dispatcher, target) = setup_snake(); @@ -63,7 +62,6 @@ fn test_dual_set_public_key() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] fn test_dual_no_set_public_key() { let dispatcher = setup_non_account(); @@ -71,7 +69,6 @@ fn test_dual_no_set_public_key() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_set_public_key_exists_and_panics() { let (dispatcher, _) = setup_account_panic(); @@ -79,14 +76,12 @@ fn test_dual_set_public_key_exists_and_panics() { } #[test] -#[available_gas(2000000)] fn test_dual_get_public_key() { let (snake_dispatcher, _) = setup_snake(); assert(snake_dispatcher.get_public_key() == PUBKEY, 'Should return PUBKEY'); } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] fn test_dual_no_get_public_key() { let dispatcher = setup_non_account(); @@ -94,7 +89,6 @@ fn test_dual_no_get_public_key() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_get_public_key_exists_and_panics() { let (dispatcher, _) = setup_account_panic(); @@ -102,7 +96,6 @@ fn test_dual_get_public_key_exists_and_panics() { } #[test] -#[available_gas(2000000)] fn test_dual_is_valid_signature() { let (snake_dispatcher, target) = setup_snake(); @@ -118,7 +111,6 @@ fn test_dual_is_valid_signature() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] fn test_dual_no_is_valid_signature() { let hash = 0x0; @@ -129,7 +121,6 @@ fn test_dual_no_is_valid_signature() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_is_valid_signature_exists_and_panics() { let hash = 0x0; @@ -140,14 +131,12 @@ fn test_dual_is_valid_signature_exists_and_panics() { } #[test] -#[available_gas(2000000)] fn test_dual_supports_interface() { let (snake_dispatcher, target) = setup_snake(); assert(snake_dispatcher.supports_interface(ISRC5_ID), 'Should implement ISRC5'); } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] fn test_dual_no_supports_interface() { let dispatcher = setup_non_account(); @@ -155,7 +144,6 @@ fn test_dual_no_supports_interface() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_supports_interface_exists_and_panics() { let (dispatcher, _) = setup_account_panic(); @@ -167,7 +155,6 @@ fn test_dual_supports_interface_exists_and_panics() { // #[test] -#[available_gas(2000000)] fn test_dual_setPublicKey() { let (camel_dispatcher, target) = setup_camel(); @@ -178,7 +165,6 @@ fn test_dual_setPublicKey() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_setPublicKey_exists_and_panics() { let (_, dispatcher) = setup_account_panic(); @@ -186,14 +172,12 @@ fn test_dual_setPublicKey_exists_and_panics() { } #[test] -#[available_gas(2000000)] fn test_dual_getPublicKey() { let (camel_dispatcher, _) = setup_camel(); assert(camel_dispatcher.get_public_key() == PUBKEY, 'Should return PUBKEY'); } #[test] -#[available_gas(2000000)] #[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_getPublicKey_exists_and_panics() { let (_, dispatcher) = setup_account_panic(); @@ -201,7 +185,6 @@ fn test_dual_getPublicKey_exists_and_panics() { } #[test] -#[available_gas(2000000)] fn test_dual_isValidSignature() { let (camel_dispatcher, target) = setup_camel(); @@ -217,7 +200,6 @@ fn test_dual_isValidSignature() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_isValidSignature_exists_and_panics() { let hash = 0x0; @@ -228,14 +210,12 @@ fn test_dual_isValidSignature_exists_and_panics() { } #[test] -#[available_gas(2000000)] fn test_dual_supportsInterface() { let (camel_dispatcher, _) = setup_camel(); assert(camel_dispatcher.supports_interface(ISRC5_ID), 'Should implement ISRC5'); } #[test] -#[available_gas(2000000)] #[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_supportsInterface_exists_and_panics() { let (_, dispatcher) = setup_account_panic(); diff --git a/src/tests/introspection/test_dual_src5.cairo b/src/tests/introspection/test_dual_src5.cairo index 68f537534..2f1d300fa 100644 --- a/src/tests/introspection/test_dual_src5.cairo +++ b/src/tests/introspection/test_dual_src5.cairo @@ -44,14 +44,12 @@ fn setup_src5_panic() -> (DualCaseSRC5, DualCaseSRC5) { // #[test] -#[available_gas(2000000)] fn test_dual_supports_interface() { let dispatcher = setup_snake(); assert(dispatcher.supports_interface(ISRC5_ID), 'Should support base interface'); } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] fn test_dual_no_supports_interface() { let dispatcher = setup_non_src5(); @@ -59,7 +57,6 @@ fn test_dual_no_supports_interface() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_supports_interface_exists_and_panics() { let (dispatcher, _) = setup_src5_panic(); @@ -71,14 +68,12 @@ fn test_dual_supports_interface_exists_and_panics() { // #[test] -#[available_gas(2000000)] fn test_dual_supportsInterface() { let dispatcher = setup_camel(); assert(dispatcher.supports_interface(ISRC5_ID), 'Should support base interface'); } #[test] -#[available_gas(2000000)] #[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_supportsInterface_exists_and_panics() { let (_, dispatcher) = setup_src5_panic(); diff --git a/src/tests/introspection/test_src5.cairo b/src/tests/introspection/test_src5.cairo index f58f8a977..001b7b5a7 100644 --- a/src/tests/introspection/test_src5.cairo +++ b/src/tests/introspection/test_src5.cairo @@ -12,7 +12,6 @@ fn COMPONENT_STATE() -> ComponentState { } #[test] -#[available_gas(2000000)] fn test_default_behavior() { let state = COMPONENT_STATE(); let supports_default_interface = state.supports_interface(ISRC5_ID); @@ -20,7 +19,6 @@ fn test_default_behavior() { } #[test] -#[available_gas(2000000)] fn test_not_registered_interface() { let state = COMPONENT_STATE(); let supports_unregistered_interface = state.supports_interface(OTHER_ID); @@ -28,7 +26,6 @@ fn test_not_registered_interface() { } #[test] -#[available_gas(2000000)] fn test_register_interface() { let mut state = COMPONENT_STATE(); state.register_interface(OTHER_ID); @@ -37,7 +34,6 @@ fn test_register_interface() { } #[test] -#[available_gas(2000000)] fn test_deregister_interface() { let mut state = COMPONENT_STATE(); state.register_interface(OTHER_ID); @@ -47,7 +43,6 @@ fn test_deregister_interface() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('SRC5: invalid id',))] fn test_deregister_default_interface() { let mut state = COMPONENT_STATE(); diff --git a/src/tests/presets/test_account.cairo b/src/tests/presets/test_account.cairo index 080b48d41..7a396c8e0 100644 --- a/src/tests/presets/test_account.cairo +++ b/src/tests/presets/test_account.cairo @@ -55,7 +55,6 @@ fn setup_dispatcher_with_data(data: Option<@SignedTransactionData>) -> AccountAB // #[test] -#[available_gas(2000000)] fn test_constructor() { let mut state = Account::contract_state_for_testing(); Account::constructor(ref state, PUBKEY); @@ -72,7 +71,6 @@ fn test_constructor() { // #[test] -#[available_gas(2000000)] fn test_public_key_setter_and_getter() { let dispatcher = setup_dispatcher(); @@ -86,7 +84,6 @@ fn test_public_key_setter_and_getter() { } #[test] -#[available_gas(2000000)] fn test_public_key_setter_and_getter_camel() { let dispatcher = setup_dispatcher(); @@ -100,7 +97,6 @@ fn test_public_key_setter_and_getter_camel() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('Account: unauthorized', 'ENTRYPOINT_FAILED'))] fn test_set_public_key_different_account() { let dispatcher = setup_dispatcher(); @@ -108,7 +104,6 @@ fn test_set_public_key_different_account() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('Account: unauthorized', 'ENTRYPOINT_FAILED'))] fn test_setPublicKey_different_account() { let dispatcher = setup_dispatcher(); @@ -133,7 +128,6 @@ fn is_valid_sig_dispatcher() -> (AccountABIDispatcher, felt252, Array) } #[test] -#[available_gas(2000000)] fn test_is_valid_signature() { let (dispatcher, hash, signature) = is_valid_sig_dispatcher(); @@ -142,7 +136,6 @@ fn test_is_valid_signature() { } #[test] -#[available_gas(2000000)] fn test_is_valid_signature_bad_sig() { let (dispatcher, hash, _) = is_valid_sig_dispatcher(); @@ -153,7 +146,6 @@ fn test_is_valid_signature_bad_sig() { } #[test] -#[available_gas(2000000)] fn test_isValidSignature() { let (dispatcher, hash, signature) = is_valid_sig_dispatcher(); @@ -162,7 +154,6 @@ fn test_isValidSignature() { } #[test] -#[available_gas(2000000)] fn test_isValidSignature_bad_sig() { let (dispatcher, hash, _) = is_valid_sig_dispatcher(); @@ -177,7 +168,6 @@ fn test_isValidSignature_bad_sig() { // #[test] -#[available_gas(2000000)] fn test_supports_interface() { let dispatcher = setup_dispatcher(); assert(dispatcher.supports_interface(ISRC5_ID), 'Should implement ISRC5'); @@ -190,7 +180,6 @@ fn test_supports_interface() { // #[test] -#[available_gas(2000000)] fn test_validate_deploy() { let account = setup_dispatcher_with_data(Option::Some(@SIGNED_TX_DATA())); @@ -204,7 +193,6 @@ fn test_validate_deploy() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('Account: invalid signature', 'ENTRYPOINT_FAILED'))] fn test_validate_deploy_invalid_signature_data() { let mut data = SIGNED_TX_DATA(); @@ -215,7 +203,6 @@ fn test_validate_deploy_invalid_signature_data() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('Account: invalid signature', 'ENTRYPOINT_FAILED'))] fn test_validate_deploy_invalid_signature_length() { let account = setup_dispatcher_with_data(Option::Some(@SIGNED_TX_DATA())); @@ -227,7 +214,6 @@ fn test_validate_deploy_invalid_signature_length() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('Account: invalid signature', 'ENTRYPOINT_FAILED'))] fn test_validate_deploy_empty_signature() { let account = setup_dispatcher_with_data(Option::Some(@SIGNED_TX_DATA())); @@ -238,7 +224,6 @@ fn test_validate_deploy_empty_signature() { } #[test] -#[available_gas(2000000)] fn test_validate_declare() { let account = setup_dispatcher_with_data(Option::Some(@SIGNED_TX_DATA())); @@ -252,7 +237,6 @@ fn test_validate_declare() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('Account: invalid signature', 'ENTRYPOINT_FAILED'))] fn test_validate_declare_invalid_signature_data() { let mut data = SIGNED_TX_DATA(); @@ -263,7 +247,6 @@ fn test_validate_declare_invalid_signature_data() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('Account: invalid signature', 'ENTRYPOINT_FAILED'))] fn test_validate_declare_invalid_signature_length() { let account = setup_dispatcher_with_data(Option::Some(@SIGNED_TX_DATA())); @@ -275,7 +258,6 @@ fn test_validate_declare_invalid_signature_length() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('Account: invalid signature', 'ENTRYPOINT_FAILED'))] fn test_validate_declare_empty_signature() { let account = setup_dispatcher_with_data(Option::Some(@SIGNED_TX_DATA())); @@ -323,26 +305,22 @@ fn test_execute_with_version(version: Option) { } #[test] -#[available_gas(2000000)] fn test_execute() { test_execute_with_version(Option::None(())); } #[test] -#[available_gas(2000000)] fn test_execute_query_version() { test_execute_with_version(Option::Some(QUERY_VERSION)); } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('Account: invalid tx version', 'ENTRYPOINT_FAILED'))] fn test_execute_invalid_version() { test_execute_with_version(Option::Some(TRANSACTION_VERSION - 1)); } #[test] -#[available_gas(2000000)] fn test_validate() { let calls = array![]; let account = setup_dispatcher_with_data(Option::Some(@SIGNED_TX_DATA())); @@ -351,7 +329,6 @@ fn test_validate() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('Account: invalid signature', 'ENTRYPOINT_FAILED'))] fn test_validate_invalid() { let calls = array![]; @@ -363,7 +340,6 @@ fn test_validate_invalid() { } #[test] -#[available_gas(20000000)] fn test_multicall() { let account = setup_dispatcher_with_data(Option::Some(@SIGNED_TX_DATA())); let erc20 = deploy_erc20(account.contract_address, 1000); @@ -409,7 +385,6 @@ fn test_multicall() { } #[test] -#[available_gas(2000000)] fn test_multicall_zero_calls() { let account = setup_dispatcher_with_data(Option::Some(@SIGNED_TX_DATA())); let mut calls = array![]; @@ -421,7 +396,6 @@ fn test_multicall_zero_calls() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('Account: invalid caller', 'ENTRYPOINT_FAILED'))] fn test_account_called_from_contract() { let account = setup_dispatcher(); diff --git a/src/tests/presets/test_erc20.cairo b/src/tests/presets/test_erc20.cairo index aa8174cc1..566e52e93 100644 --- a/src/tests/presets/test_erc20.cairo +++ b/src/tests/presets/test_erc20.cairo @@ -41,7 +41,6 @@ fn setup_dispatcher() -> ERC20ABIDispatcher { // #[test] -#[available_gas(2000000)] fn test_constructor() { let mut dispatcher = setup_dispatcher_with_event(); @@ -58,7 +57,6 @@ fn test_constructor() { // #[test] -#[available_gas(2000000)] fn test_total_supply() { let mut dispatcher = setup_dispatcher(); @@ -67,7 +65,6 @@ fn test_total_supply() { } #[test] -#[available_gas(2000000)] fn test_balance_of() { let mut dispatcher = setup_dispatcher(); @@ -76,7 +73,6 @@ fn test_balance_of() { } #[test] -#[available_gas(2000000)] fn test_allowance() { let mut dispatcher = setup_dispatcher(); @@ -90,7 +86,6 @@ fn test_allowance() { // #[test] -#[available_gas(2000000)] fn test_approve() { let mut dispatcher = setup_dispatcher(); assert(dispatcher.allowance(OWNER(), SPENDER()) == 0, 'Should equal ZERO'); @@ -103,7 +98,6 @@ fn test_approve() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('ERC20: approve from 0', 'ENTRYPOINT_FAILED'))] fn test_approve_from_zero() { let mut dispatcher = setup_dispatcher(); @@ -111,7 +105,6 @@ fn test_approve_from_zero() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('ERC20: approve to 0', 'ENTRYPOINT_FAILED'))] fn test_approve_to_zero() { let mut dispatcher = setup_dispatcher(); @@ -124,7 +117,6 @@ fn test_approve_to_zero() { // #[test] -#[available_gas(2000000)] fn test_transfer() { let mut dispatcher = setup_dispatcher(); @@ -138,7 +130,6 @@ fn test_transfer() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('u256_sub Overflow', 'ENTRYPOINT_FAILED'))] fn test_transfer_not_enough_balance() { let mut dispatcher = setup_dispatcher(); @@ -149,7 +140,6 @@ fn test_transfer_not_enough_balance() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('ERC20: transfer from 0', 'ENTRYPOINT_FAILED'))] fn test_transfer_from_zero() { let mut dispatcher = setup_dispatcher(); @@ -157,7 +147,6 @@ fn test_transfer_from_zero() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('ERC20: transfer to 0', 'ENTRYPOINT_FAILED'))] fn test_transfer_to_zero() { let mut dispatcher = setup_dispatcher(); @@ -170,7 +159,6 @@ fn test_transfer_to_zero() { // #[test] -#[available_gas(2000000)] fn test_transfer_from() { let mut dispatcher = setup_dispatcher(); @@ -191,7 +179,6 @@ fn test_transfer_from() { } #[test] -#[available_gas(2000000)] fn test_transfer_from_doesnt_consume_infinite_allowance() { let mut dispatcher = setup_dispatcher(); @@ -207,7 +194,6 @@ fn test_transfer_from_doesnt_consume_infinite_allowance() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('u256_sub Overflow', 'ENTRYPOINT_FAILED'))] fn test_transfer_from_greater_than_allowance() { let mut dispatcher = setup_dispatcher(); @@ -220,7 +206,6 @@ fn test_transfer_from_greater_than_allowance() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('ERC20: transfer to 0', 'ENTRYPOINT_FAILED'))] fn test_transfer_from_to_zero_address() { let mut dispatcher = setup_dispatcher(); @@ -232,7 +217,6 @@ fn test_transfer_from_to_zero_address() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('u256_sub Overflow', 'ENTRYPOINT_FAILED'))] fn test_transfer_from_from_zero_address() { let mut dispatcher = setup_dispatcher(); @@ -240,7 +224,6 @@ fn test_transfer_from_from_zero_address() { } #[test] -#[available_gas(2000000)] fn test_transferFrom() { let mut dispatcher = setup_dispatcher(); @@ -261,7 +244,6 @@ fn test_transferFrom() { } #[test] -#[available_gas(2000000)] fn test_transferFrom_doesnt_consume_infinite_allowance() { let mut dispatcher = setup_dispatcher(); testing::set_contract_address(OWNER()); @@ -276,7 +258,6 @@ fn test_transferFrom_doesnt_consume_infinite_allowance() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('u256_sub Overflow', 'ENTRYPOINT_FAILED'))] fn test_transferFrom_greater_than_allowance() { let mut dispatcher = setup_dispatcher(); @@ -289,7 +270,6 @@ fn test_transferFrom_greater_than_allowance() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('ERC20: transfer to 0', 'ENTRYPOINT_FAILED'))] fn test_transferFrom_to_zero_address() { let mut dispatcher = setup_dispatcher(); @@ -301,7 +281,6 @@ fn test_transferFrom_to_zero_address() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('u256_sub Overflow', 'ENTRYPOINT_FAILED'))] fn test_transferFrom_from_zero_address() { let mut dispatcher = setup_dispatcher(); @@ -313,7 +292,6 @@ fn test_transferFrom_from_zero_address() { // #[test] -#[available_gas(2000000)] fn test_increase_allowance() { let mut dispatcher = setup_dispatcher(); testing::set_contract_address(OWNER()); @@ -327,7 +305,6 @@ fn test_increase_allowance() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('ERC20: approve to 0', 'ENTRYPOINT_FAILED'))] fn test_increase_allowance_to_zero_address() { let mut dispatcher = setup_dispatcher(); @@ -336,7 +313,6 @@ fn test_increase_allowance_to_zero_address() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('ERC20: approve from 0', 'ENTRYPOINT_FAILED'))] fn test_increase_allowance_from_zero_address() { let mut dispatcher = setup_dispatcher(); @@ -344,7 +320,6 @@ fn test_increase_allowance_from_zero_address() { } #[test] -#[available_gas(2000000)] fn test_increaseAllowance() { let mut dispatcher = setup_dispatcher(); testing::set_contract_address(OWNER()); @@ -358,7 +333,6 @@ fn test_increaseAllowance() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('ERC20: approve to 0', 'ENTRYPOINT_FAILED'))] fn test_increaseAllowance_to_zero_address() { let mut dispatcher = setup_dispatcher(); @@ -367,7 +341,6 @@ fn test_increaseAllowance_to_zero_address() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('ERC20: approve from 0', 'ENTRYPOINT_FAILED'))] fn test_increaseAllowance_from_zero_address() { let mut dispatcher = setup_dispatcher(); @@ -379,7 +352,6 @@ fn test_increaseAllowance_from_zero_address() { // #[test] -#[available_gas(2000000)] fn test_decrease_allowance() { let mut dispatcher = setup_dispatcher(); testing::set_contract_address(OWNER()); @@ -393,7 +365,6 @@ fn test_decrease_allowance() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('u256_sub Overflow', 'ENTRYPOINT_FAILED'))] fn test_decrease_allowance_to_zero_address() { let mut dispatcher = setup_dispatcher(); @@ -402,7 +373,6 @@ fn test_decrease_allowance_to_zero_address() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('u256_sub Overflow', 'ENTRYPOINT_FAILED'))] fn test_decrease_allowance_from_zero_address() { let mut dispatcher = setup_dispatcher(); @@ -410,7 +380,6 @@ fn test_decrease_allowance_from_zero_address() { } #[test] -#[available_gas(2000000)] fn test_decreaseAllowance() { let mut dispatcher = setup_dispatcher(); testing::set_contract_address(OWNER()); @@ -424,7 +393,6 @@ fn test_decreaseAllowance() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('u256_sub Overflow', 'ENTRYPOINT_FAILED'))] fn test_decreaseAllowance_to_zero_address() { let mut dispatcher = setup_dispatcher(); @@ -433,7 +401,6 @@ fn test_decreaseAllowance_to_zero_address() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('u256_sub Overflow', 'ENTRYPOINT_FAILED'))] fn test_decreaseAllowance_from_zero_address() { let mut dispatcher = setup_dispatcher(); diff --git a/src/tests/presets/test_erc721.cairo b/src/tests/presets/test_erc721.cairo index 2f2c42e74..a0d7fedfc 100644 --- a/src/tests/presets/test_erc721.cairo +++ b/src/tests/presets/test_erc721.cairo @@ -88,7 +88,6 @@ fn setup_camel_account() -> ContractAddress { // #[test] -#[available_gas(2000000000)] fn test__mint_assets() { let mut state = ERC721::contract_state_for_testing(); let mut token_ids = array![TOKEN_1, TOKEN_2, TOKEN_3].span(); @@ -112,7 +111,6 @@ fn test__mint_assets() { } #[test] -#[available_gas(2000000000)] #[should_panic(expected: ('Array lengths do not match',))] fn test__mint_assets_mismatched_arrays_1() { let mut state = ERC721::contract_state_for_testing(); @@ -123,7 +121,6 @@ fn test__mint_assets_mismatched_arrays_1() { } #[test] -#[available_gas(2000000000)] #[should_panic(expected: ('Array lengths do not match',))] fn test__mint_assets_mismatched_arrays_2() { let mut state = ERC721::contract_state_for_testing(); @@ -138,7 +135,6 @@ fn test__mint_assets_mismatched_arrays_2() { // #[test] -#[available_gas(2000000000)] fn test_constructor() { let dispatcher = setup_dispatcher_with_event(); @@ -165,7 +161,6 @@ fn test_constructor() { } #[test] -#[available_gas(2000000000)] fn test_constructor_events() { let dispatcher = setup_dispatcher_with_event(); let mut tokens = array![TOKEN_1, TOKEN_2, TOKEN_3]; @@ -186,14 +181,12 @@ fn test_constructor_events() { // #[test] -#[available_gas(20000000)] fn test_balance_of() { let dispatcher = setup_dispatcher(); assert(dispatcher.balance_of(OWNER()) == TOKENS_LEN, 'Should return balance'); } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ERC721: invalid account', 'ENTRYPOINT_FAILED'))] fn test_balance_of_zero() { let dispatcher = setup_dispatcher(); @@ -201,14 +194,12 @@ fn test_balance_of_zero() { } #[test] -#[available_gas(20000000)] fn test_owner_of() { let dispatcher = setup_dispatcher(); assert(dispatcher.owner_of(TOKEN_1) == OWNER(), 'Should return owner'); } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ERC721: invalid token ID', 'ENTRYPOINT_FAILED'))] fn test_owner_of_non_minted() { let dispatcher = setup_dispatcher(); @@ -216,7 +207,6 @@ fn test_owner_of_non_minted() { } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ERC721: invalid token ID', 'ENTRYPOINT_FAILED'))] fn test_token_uri_non_minted() { let dispatcher = setup_dispatcher(); @@ -224,7 +214,6 @@ fn test_token_uri_non_minted() { } #[test] -#[available_gas(20000000)] fn test_get_approved() { let dispatcher = setup_dispatcher(); let spender = SPENDER(); @@ -237,7 +226,6 @@ fn test_get_approved() { } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ERC721: invalid token ID', 'ENTRYPOINT_FAILED'))] fn test_get_approved_nonexistent() { let dispatcher = setup_dispatcher(); @@ -249,7 +237,6 @@ fn test_get_approved_nonexistent() { // #[test] -#[available_gas(20000000)] fn test_approve_from_owner() { let dispatcher = setup_dispatcher(); @@ -260,7 +247,6 @@ fn test_approve_from_owner() { } #[test] -#[available_gas(20000000)] fn test_approve_from_operator() { let dispatcher = setup_dispatcher(); @@ -275,7 +261,6 @@ fn test_approve_from_operator() { } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ERC721: unauthorized caller', 'ENTRYPOINT_FAILED'))] fn test_approve_from_unauthorized() { let dispatcher = setup_dispatcher(); @@ -285,7 +270,6 @@ fn test_approve_from_unauthorized() { } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ERC721: approval to owner', 'ENTRYPOINT_FAILED'))] fn test_approve_to_owner() { let dispatcher = setup_dispatcher(); @@ -294,7 +278,6 @@ fn test_approve_to_owner() { } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ERC721: invalid token ID', 'ENTRYPOINT_FAILED'))] fn test_approve_nonexistent() { let dispatcher = setup_dispatcher(); @@ -306,7 +289,6 @@ fn test_approve_nonexistent() { // #[test] -#[available_gas(20000000)] fn test_set_approval_for_all() { let dispatcher = setup_dispatcher(); @@ -324,7 +306,6 @@ fn test_set_approval_for_all() { } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ERC721: self approval', 'ENTRYPOINT_FAILED'))] fn test_set_approval_for_all_owner_equal_operator_true() { let dispatcher = setup_dispatcher(); @@ -332,7 +313,6 @@ fn test_set_approval_for_all_owner_equal_operator_true() { } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ERC721: self approval', 'ENTRYPOINT_FAILED'))] fn test_set_approval_for_all_owner_equal_operator_false() { let dispatcher = setup_dispatcher(); @@ -344,7 +324,6 @@ fn test_set_approval_for_all_owner_equal_operator_false() { // #[test] -#[available_gas(20000000)] fn test_transfer_from_owner() { let dispatcher = setup_dispatcher(); let token_id = TOKEN_1; @@ -365,7 +344,6 @@ fn test_transfer_from_owner() { } #[test] -#[available_gas(20000000)] fn test_transferFrom_owner() { let dispatcher = setup_dispatcher(); let token_id = TOKEN_1; @@ -386,7 +364,6 @@ fn test_transferFrom_owner() { } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ERC721: invalid token ID', 'ENTRYPOINT_FAILED'))] fn test_transfer_from_nonexistent() { let dispatcher = setup_dispatcher(); @@ -394,7 +371,6 @@ fn test_transfer_from_nonexistent() { } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ERC721: invalid token ID', 'ENTRYPOINT_FAILED'))] fn test_transferFrom_nonexistent() { let dispatcher = setup_dispatcher(); @@ -402,7 +378,6 @@ fn test_transferFrom_nonexistent() { } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ERC721: invalid receiver', 'ENTRYPOINT_FAILED'))] fn test_transfer_from_to_zero() { let dispatcher = setup_dispatcher(); @@ -410,7 +385,6 @@ fn test_transfer_from_to_zero() { } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ERC721: invalid receiver', 'ENTRYPOINT_FAILED'))] fn test_transferFrom_to_zero() { let dispatcher = setup_dispatcher(); @@ -418,7 +392,6 @@ fn test_transferFrom_to_zero() { } #[test] -#[available_gas(20000000)] fn test_transfer_from_to_owner() { let dispatcher = setup_dispatcher(); @@ -430,7 +403,6 @@ fn test_transfer_from_to_owner() { } #[test] -#[available_gas(20000000)] fn test_transferFrom_to_owner() { let dispatcher = setup_dispatcher(); @@ -442,7 +414,6 @@ fn test_transferFrom_to_owner() { } #[test] -#[available_gas(20000000)] fn test_transfer_from_approved() { let dispatcher = setup_dispatcher(); let token_id = TOKEN_1; @@ -461,7 +432,6 @@ fn test_transfer_from_approved() { } #[test] -#[available_gas(20000000)] fn test_transferFrom_approved() { let dispatcher = setup_dispatcher(); let token_id = TOKEN_1; @@ -480,7 +450,6 @@ fn test_transferFrom_approved() { } #[test] -#[available_gas(20000000)] fn test_transfer_from_approved_for_all() { let dispatcher = setup_dispatcher(); let token_id = TOKEN_1; @@ -500,7 +469,6 @@ fn test_transfer_from_approved_for_all() { } #[test] -#[available_gas(20000000)] fn test_transferFrom_approved_for_all() { let dispatcher = setup_dispatcher(); let token_id = TOKEN_1; @@ -520,7 +488,6 @@ fn test_transferFrom_approved_for_all() { } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ERC721: unauthorized caller', 'ENTRYPOINT_FAILED'))] fn test_transfer_from_unauthorized() { let dispatcher = setup_dispatcher(); @@ -529,7 +496,6 @@ fn test_transfer_from_unauthorized() { } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ERC721: unauthorized caller', 'ENTRYPOINT_FAILED'))] fn test_transferFrom_unauthorized() { let dispatcher = setup_dispatcher(); @@ -542,7 +508,6 @@ fn test_transferFrom_unauthorized() { // #[test] -#[available_gas(20000000)] fn test_safe_transfer_from_to_account() { let dispatcher = setup_dispatcher(); let account = setup_account(); @@ -558,7 +523,6 @@ fn test_safe_transfer_from_to_account() { } #[test] -#[available_gas(20000000)] fn test_safeTransferFrom_to_account() { let dispatcher = setup_dispatcher(); let account = setup_account(); @@ -574,7 +538,6 @@ fn test_safeTransferFrom_to_account() { } #[test] -#[available_gas(20000000)] fn test_safe_transfer_from_to_account_camel() { let dispatcher = setup_dispatcher(); let account = setup_camel_account(); @@ -590,7 +553,6 @@ fn test_safe_transfer_from_to_account_camel() { } #[test] -#[available_gas(20000000)] fn test_safeTransferFrom_to_account_camel() { let dispatcher = setup_dispatcher(); let account = setup_camel_account(); @@ -606,7 +568,6 @@ fn test_safeTransferFrom_to_account_camel() { } #[test] -#[available_gas(20000000)] fn test_safe_transfer_from_to_receiver() { let dispatcher = setup_dispatcher(); let receiver = setup_receiver(); @@ -622,7 +583,6 @@ fn test_safe_transfer_from_to_receiver() { } #[test] -#[available_gas(20000000)] fn test_safeTransferFrom_to_receiver() { let dispatcher = setup_dispatcher(); let receiver = setup_receiver(); @@ -638,7 +598,6 @@ fn test_safeTransferFrom_to_receiver() { } #[test] -#[available_gas(20000000)] fn test_safe_transfer_from_to_receiver_camel() { let dispatcher = setup_dispatcher(); let receiver = setup_camel_receiver(); @@ -654,7 +613,6 @@ fn test_safe_transfer_from_to_receiver_camel() { } #[test] -#[available_gas(20000000)] fn test_safeTransferFrom_to_receiver_camel() { let dispatcher = setup_dispatcher(); let receiver = setup_camel_receiver(); @@ -670,7 +628,6 @@ fn test_safeTransferFrom_to_receiver_camel() { } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ERC721: safe transfer failed', 'ENTRYPOINT_FAILED'))] fn test_safe_transfer_from_to_receiver_failure() { let dispatcher = setup_dispatcher(); @@ -682,7 +639,6 @@ fn test_safe_transfer_from_to_receiver_failure() { } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ERC721: safe transfer failed', 'ENTRYPOINT_FAILED'))] fn test_safeTransferFrom_to_receiver_failure() { let dispatcher = setup_dispatcher(); @@ -694,7 +650,6 @@ fn test_safeTransferFrom_to_receiver_failure() { } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ERC721: safe transfer failed', 'ENTRYPOINT_FAILED'))] fn test_safe_transfer_from_to_receiver_failure_camel() { let dispatcher = setup_dispatcher(); @@ -706,7 +661,6 @@ fn test_safe_transfer_from_to_receiver_failure_camel() { } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ERC721: safe transfer failed', 'ENTRYPOINT_FAILED'))] fn test_safeTransferFrom_to_receiver_failure_camel() { let dispatcher = setup_dispatcher(); @@ -718,7 +672,6 @@ fn test_safeTransferFrom_to_receiver_failure_camel() { } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ENTRYPOINT_NOT_FOUND', 'ENTRYPOINT_FAILED'))] fn test_safe_transfer_from_to_non_receiver() { let dispatcher = setup_dispatcher(); @@ -730,7 +683,6 @@ fn test_safe_transfer_from_to_non_receiver() { } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ENTRYPOINT_NOT_FOUND', 'ENTRYPOINT_FAILED'))] fn test_safeTransferFrom_to_non_receiver() { let dispatcher = setup_dispatcher(); @@ -742,7 +694,6 @@ fn test_safeTransferFrom_to_non_receiver() { } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ERC721: invalid token ID', 'ENTRYPOINT_FAILED'))] fn test_safe_transfer_from_nonexistent() { let dispatcher = setup_dispatcher(); @@ -750,7 +701,6 @@ fn test_safe_transfer_from_nonexistent() { } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ERC721: invalid token ID', 'ENTRYPOINT_FAILED'))] fn test_safeTransferFrom_nonexistent() { let dispatcher = setup_dispatcher(); @@ -758,7 +708,6 @@ fn test_safeTransferFrom_nonexistent() { } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ERC721: invalid receiver', 'ENTRYPOINT_FAILED'))] fn test_safe_transfer_from_to_zero() { let dispatcher = setup_dispatcher(); @@ -766,7 +715,6 @@ fn test_safe_transfer_from_to_zero() { } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ERC721: invalid receiver', 'ENTRYPOINT_FAILED'))] fn test_safeTransferFrom_to_zero() { let dispatcher = setup_dispatcher(); @@ -774,7 +722,6 @@ fn test_safeTransferFrom_to_zero() { } #[test] -#[available_gas(20000000)] fn test_safe_transfer_from_to_owner() { let dispatcher = setup_dispatcher(); let token_id = TOKEN_1; @@ -793,7 +740,6 @@ fn test_safe_transfer_from_to_owner() { } #[test] -#[available_gas(20000000)] fn test_safeTransferFrom_to_owner() { let dispatcher = setup_dispatcher(); let token_id = TOKEN_1; @@ -812,7 +758,6 @@ fn test_safeTransferFrom_to_owner() { } #[test] -#[available_gas(20000000)] fn test_safe_transfer_from_to_owner_camel() { let dispatcher = setup_dispatcher(); let token_id = TOKEN_1; @@ -831,7 +776,6 @@ fn test_safe_transfer_from_to_owner_camel() { } #[test] -#[available_gas(20000000)] fn test_safeTransferFrom_to_owner_camel() { let dispatcher = setup_dispatcher(); let token_id = TOKEN_1; @@ -850,7 +794,6 @@ fn test_safeTransferFrom_to_owner_camel() { } #[test] -#[available_gas(20000000)] fn test_safe_transfer_from_approved() { let dispatcher = setup_dispatcher(); let receiver = setup_receiver(); @@ -870,7 +813,6 @@ fn test_safe_transfer_from_approved() { } #[test] -#[available_gas(20000000)] fn test_safeTransferFrom_approved() { let dispatcher = setup_dispatcher(); let receiver = setup_receiver(); @@ -890,7 +832,6 @@ fn test_safeTransferFrom_approved() { } #[test] -#[available_gas(20000000)] fn test_safe_transfer_from_approved_camel() { let dispatcher = setup_dispatcher(); let receiver = setup_camel_receiver(); @@ -910,7 +851,6 @@ fn test_safe_transfer_from_approved_camel() { } #[test] -#[available_gas(20000000)] fn test_safeTransferFrom_approved_camel() { let dispatcher = setup_dispatcher(); let receiver = setup_camel_receiver(); @@ -930,7 +870,6 @@ fn test_safeTransferFrom_approved_camel() { } #[test] -#[available_gas(20000000)] fn test_safe_transfer_from_approved_for_all() { let dispatcher = setup_dispatcher(); let receiver = setup_receiver(); @@ -950,7 +889,6 @@ fn test_safe_transfer_from_approved_for_all() { } #[test] -#[available_gas(20000000)] fn test_safeTransferFrom_approved_for_all() { let dispatcher = setup_dispatcher(); let receiver = setup_receiver(); @@ -970,7 +908,6 @@ fn test_safeTransferFrom_approved_for_all() { } #[test] -#[available_gas(20000000)] fn test_safe_transfer_from_approved_for_all_camel() { let dispatcher = setup_dispatcher(); let receiver = setup_camel_receiver(); @@ -990,7 +927,6 @@ fn test_safe_transfer_from_approved_for_all_camel() { } #[test] -#[available_gas(20000000)] fn test_safeTransferFrom_approved_for_all_camel() { let dispatcher = setup_dispatcher(); let receiver = setup_camel_receiver(); @@ -1010,7 +946,6 @@ fn test_safeTransferFrom_approved_for_all_camel() { } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ERC721: unauthorized caller', 'ENTRYPOINT_FAILED'))] fn test_safe_transfer_from_unauthorized() { let dispatcher = setup_dispatcher(); @@ -1019,7 +954,6 @@ fn test_safe_transfer_from_unauthorized() { } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ERC721: unauthorized caller', 'ENTRYPOINT_FAILED'))] fn test_safeTransferFrom_unauthorized() { let dispatcher = setup_dispatcher(); diff --git a/src/tests/security/test_initializable.cairo b/src/tests/security/test_initializable.cairo index c07c0f91e..eed0a01cc 100644 --- a/src/tests/security/test_initializable.cairo +++ b/src/tests/security/test_initializable.cairo @@ -9,7 +9,6 @@ fn COMPONENT_STATE() -> ComponentState { } #[test] -#[available_gas(2000000)] fn test_initialize() { let mut state = COMPONENT_STATE(); assert(!state.is_initialized(), 'Should not be initialized'); @@ -18,7 +17,6 @@ fn test_initialize() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('Initializable: is initialized',))] fn test_initialize_when_initialized() { let mut state = COMPONENT_STATE(); diff --git a/src/tests/security/test_pausable.cairo b/src/tests/security/test_pausable.cairo index bd69f24a6..53b88f3f6 100644 --- a/src/tests/security/test_pausable.cairo +++ b/src/tests/security/test_pausable.cairo @@ -19,7 +19,6 @@ fn COMPONENT_STATE() -> ComponentState { // #[test] -#[available_gas(2000000)] fn test_is_paused() { let mut state = COMPONENT_STATE(); assert(!state.is_paused(), 'Should not be paused'); @@ -36,7 +35,6 @@ fn test_is_paused() { // #[test] -#[available_gas(2000000)] fn test_assert_paused_when_paused() { let mut state = COMPONENT_STATE(); state._pause(); @@ -44,7 +42,6 @@ fn test_assert_paused_when_paused() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('Pausable: not paused',))] fn test_assert_paused_when_not_paused() { let state = COMPONENT_STATE(); @@ -56,7 +53,6 @@ fn test_assert_paused_when_not_paused() { // #[test] -#[available_gas(2000000)] #[should_panic(expected: ('Pausable: paused',))] fn test_assert_not_paused_when_paused() { let mut state = COMPONENT_STATE(); @@ -65,7 +61,6 @@ fn test_assert_not_paused_when_paused() { } #[test] -#[available_gas(2000000)] fn test_assert_not_paused_when_not_paused() { let state = COMPONENT_STATE(); state.assert_not_paused(); @@ -76,7 +71,6 @@ fn test_assert_not_paused_when_not_paused() { // #[test] -#[available_gas(2000000)] fn test_pause_when_unpaused() { let mut state = COMPONENT_STATE(); testing::set_caller_address(CALLER()); @@ -88,7 +82,6 @@ fn test_pause_when_unpaused() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('Pausable: paused',))] fn test_pause_when_paused() { let mut state = COMPONENT_STATE(); @@ -101,7 +94,6 @@ fn test_pause_when_paused() { // #[test] -#[available_gas(2000000)] fn test_unpause_when_paused() { let mut state = COMPONENT_STATE(); testing::set_caller_address(CALLER()); @@ -116,7 +108,6 @@ fn test_unpause_when_paused() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('Pausable: not paused',))] fn test_unpause_when_unpaused() { let mut state = COMPONENT_STATE(); diff --git a/src/tests/security/test_reentrancyguard.cairo b/src/tests/security/test_reentrancyguard.cairo index 13f15b8b4..a38c21432 100644 --- a/src/tests/security/test_reentrancyguard.cairo +++ b/src/tests/security/test_reentrancyguard.cairo @@ -23,7 +23,6 @@ fn deploy_mock() -> IReentrancyMockDispatcher { // #[test] -#[available_gas(2000000)] fn test_reentrancy_guard_start() { let mut state = COMPONENT_STATE(); @@ -33,7 +32,6 @@ fn test_reentrancy_guard_start() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('ReentrancyGuard: reentrant call',))] fn test_reentrancy_guard_start_when_started() { let mut state = COMPONENT_STATE(); @@ -43,7 +41,6 @@ fn test_reentrancy_guard_start_when_started() { } #[test] -#[available_gas(2000000)] fn test_reentrancy_guard_end() { let mut state = COMPONENT_STATE(); @@ -58,7 +55,6 @@ fn test_reentrancy_guard_end() { // #[test] -#[available_gas(2000000)] #[should_panic( expected: ( 'ReentrancyGuard: reentrant call', @@ -78,7 +74,6 @@ fn test_remote_callback() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('ReentrancyGuard: reentrant call', 'ENTRYPOINT_FAILED'))] fn test_local_recursion() { let contract = deploy_mock(); @@ -86,7 +81,6 @@ fn test_local_recursion() { } #[test] -#[available_gas(2000000)] #[should_panic( expected: ('ReentrancyGuard: reentrant call', 'ENTRYPOINT_FAILED', 'ENTRYPOINT_FAILED') )] @@ -96,7 +90,6 @@ fn test_external_recursion() { } #[test] -#[available_gas(2000000)] fn test_nonreentrant_function_call() { let contract = deploy_mock(); contract.callback(); diff --git a/src/tests/token/test_dual20.cairo b/src/tests/token/test_dual20.cairo index 88e4558a8..df69154ca 100644 --- a/src/tests/token/test_dual20.cairo +++ b/src/tests/token/test_dual20.cairo @@ -55,7 +55,6 @@ fn setup_erc20_panic() -> (DualCaseERC20, DualCaseERC20) { // #[test] -#[available_gas(2000000)] fn test_dual_name() { let (snake_dispatcher, _) = setup_snake(); let (camel_dispatcher, _) = setup_camel(); @@ -64,7 +63,6 @@ fn test_dual_name() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] fn test_dual_no_name() { let dispatcher = setup_non_erc20(); @@ -72,7 +70,6 @@ fn test_dual_no_name() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_name_exists_and_panics() { let (dispatcher, _) = setup_erc20_panic(); @@ -80,7 +77,6 @@ fn test_dual_name_exists_and_panics() { } #[test] -#[available_gas(2000000)] fn test_dual_symbol() { let (snake_dispatcher, _) = setup_snake(); let (camel_dispatcher, _) = setup_camel(); @@ -89,7 +85,6 @@ fn test_dual_symbol() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] fn test_dual_no_symbol() { let dispatcher = setup_non_erc20(); @@ -97,7 +92,6 @@ fn test_dual_no_symbol() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_symbol_exists_and_panics() { let (dispatcher, _) = setup_erc20_panic(); @@ -105,7 +99,6 @@ fn test_dual_symbol_exists_and_panics() { } #[test] -#[available_gas(2000000)] fn test_dual_decimals() { let (snake_dispatcher, _) = setup_snake(); let (camel_dispatcher, _) = setup_camel(); @@ -114,7 +107,6 @@ fn test_dual_decimals() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] fn test_dual_no_decimals() { let dispatcher = setup_non_erc20(); @@ -122,7 +114,6 @@ fn test_dual_no_decimals() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_decimals_exists_and_panics() { let (dispatcher, _) = setup_erc20_panic(); @@ -130,7 +121,6 @@ fn test_dual_decimals_exists_and_panics() { } #[test] -#[available_gas(2000000)] fn test_dual_transfer() { let (snake_dispatcher, snake_target) = setup_snake(); set_contract_address(OWNER()); @@ -144,7 +134,6 @@ fn test_dual_transfer() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] fn test_dual_no_transfer() { let dispatcher = setup_non_erc20(); @@ -152,7 +141,6 @@ fn test_dual_no_transfer() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_transfer_exists_and_panics() { let (dispatcher, _) = setup_erc20_panic(); @@ -160,7 +148,6 @@ fn test_dual_transfer_exists_and_panics() { } #[test] -#[available_gas(2000000)] fn test_dual_approve() { let (snake_dispatcher, snake_target) = setup_snake(); set_contract_address(OWNER()); @@ -174,7 +161,6 @@ fn test_dual_approve() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] fn test_dual_no_approve() { let dispatcher = setup_non_erc20(); @@ -182,7 +168,6 @@ fn test_dual_no_approve() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_approve_exists_and_panics() { let (dispatcher, _) = setup_erc20_panic(); @@ -194,14 +179,12 @@ fn test_dual_approve_exists_and_panics() { // #[test] -#[available_gas(2000000)] fn test_dual_total_supply() { let (dispatcher, _) = setup_snake(); assert(dispatcher.total_supply() == SUPPLY, 'Should return balance'); } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] fn test_dual_no_total_supply() { let dispatcher = setup_non_erc20(); @@ -209,7 +192,6 @@ fn test_dual_no_total_supply() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_total_supply_exists_and_panics() { let (dispatcher, _) = setup_erc20_panic(); @@ -217,14 +199,12 @@ fn test_dual_total_supply_exists_and_panics() { } #[test] -#[available_gas(2000000)] fn test_dual_balance_of() { let (dispatcher, _) = setup_snake(); assert(dispatcher.balance_of(OWNER()) == SUPPLY, 'Should return balance'); } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] fn test_dual_no_balance_of() { let dispatcher = setup_non_erc20(); @@ -232,7 +212,6 @@ fn test_dual_no_balance_of() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_balance_of_exists_and_panics() { let (dispatcher, _) = setup_erc20_panic(); @@ -240,7 +219,6 @@ fn test_dual_balance_of_exists_and_panics() { } #[test] -#[available_gas(2000000)] fn test_dual_transfer_from() { let (dispatcher, target) = setup_snake(); set_contract_address(OWNER()); @@ -252,7 +230,6 @@ fn test_dual_transfer_from() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] fn test_dual_no_transfer_from() { let dispatcher = setup_non_erc20(); @@ -260,7 +237,6 @@ fn test_dual_no_transfer_from() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_transfer_from_exists_and_panics() { let (dispatcher, _) = setup_erc20_panic(); @@ -272,14 +248,12 @@ fn test_dual_transfer_from_exists_and_panics() { // #[test] -#[available_gas(2000000)] fn test_dual_totalSupply() { let (dispatcher, _) = setup_camel(); assert(dispatcher.total_supply() == SUPPLY, 'Should return supply'); } #[test] -#[available_gas(2000000)] #[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_totalSupply_exists_and_panics() { let (_, dispatcher) = setup_erc20_panic(); @@ -287,14 +261,12 @@ fn test_dual_totalSupply_exists_and_panics() { } #[test] -#[available_gas(2000000)] fn test_dual_balanceOf() { let (dispatcher, _) = setup_camel(); assert(dispatcher.balance_of(OWNER()) == SUPPLY, 'Should return balance'); } #[test] -#[available_gas(2000000)] #[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_balanceOf_exists_and_panics() { let (_, dispatcher) = setup_erc20_panic(); @@ -302,7 +274,6 @@ fn test_dual_balanceOf_exists_and_panics() { } #[test] -#[available_gas(2000000)] fn test_dual_transferFrom() { let (dispatcher, target) = setup_camel(); set_contract_address(OWNER()); @@ -314,7 +285,6 @@ fn test_dual_transferFrom() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_transferFrom_exists_and_panics() { let (_, dispatcher) = setup_erc20_panic(); diff --git a/src/tests/token/test_dual721.cairo b/src/tests/token/test_dual721.cairo index 5611ef2d5..229ecffbb 100644 --- a/src/tests/token/test_dual721.cairo +++ b/src/tests/token/test_dual721.cairo @@ -72,7 +72,6 @@ fn setup_receiver() -> ContractAddress { // #[test] -#[available_gas(2000000)] fn test_dual_name() { let (snake_dispatcher, _) = setup_snake(); let (camel_dispatcher, _) = setup_camel(); @@ -81,7 +80,6 @@ fn test_dual_name() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] fn test_dual_no_name() { let dispatcher = setup_non_erc721(); @@ -89,7 +87,6 @@ fn test_dual_no_name() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_name_exists_and_panics() { let (dispatcher, _) = setup_erc721_panic(); @@ -97,7 +94,6 @@ fn test_dual_name_exists_and_panics() { } #[test] -#[available_gas(2000000)] fn test_dual_symbol() { let (snake_dispatcher, _) = setup_snake(); let (camel_dispatcher, _) = setup_camel(); @@ -106,7 +102,6 @@ fn test_dual_symbol() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] fn test_dual_no_symbol() { let dispatcher = setup_non_erc721(); @@ -114,7 +109,6 @@ fn test_dual_no_symbol() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_symbol_exists_and_panics() { let (dispatcher, _) = setup_erc721_panic(); @@ -122,7 +116,6 @@ fn test_dual_symbol_exists_and_panics() { } #[test] -#[available_gas(20000000)] fn test_dual_approve() { let (snake_dispatcher, snake_target) = setup_snake(); set_contract_address(OWNER()); @@ -136,7 +129,6 @@ fn test_dual_approve() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] fn test_dual_no_approve() { let dispatcher = setup_non_erc721(); @@ -144,7 +136,6 @@ fn test_dual_no_approve() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_approve_exists_and_panics() { let (dispatcher, _) = setup_erc721_panic(); @@ -156,14 +147,12 @@ fn test_dual_approve_exists_and_panics() { // #[test] -#[available_gas(2000000)] fn test_dual_balance_of() { let (dispatcher, _) = setup_snake(); assert(dispatcher.balance_of(OWNER()) == 1, 'Should return balance'); } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] fn test_dual_no_balance_of() { let dispatcher = setup_non_erc721(); @@ -171,7 +160,6 @@ fn test_dual_no_balance_of() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_balance_of_exists_and_panics() { let (dispatcher, _) = setup_erc721_panic(); @@ -179,14 +167,12 @@ fn test_dual_balance_of_exists_and_panics() { } #[test] -#[available_gas(2000000)] fn test_dual_owner_of() { let (dispatcher, target) = setup_snake(); assert(dispatcher.owner_of(TOKEN_ID) == OWNER(), 'Should return owner'); } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] fn test_dual_no_owner_of() { let dispatcher = setup_non_erc721(); @@ -194,7 +180,6 @@ fn test_dual_no_owner_of() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_owner_of_exists_and_panics() { let (dispatcher, _) = setup_erc721_panic(); @@ -202,7 +187,6 @@ fn test_dual_owner_of_exists_and_panics() { } #[test] -#[available_gas(2000000)] fn test_dual_transfer_from() { let (dispatcher, target) = setup_snake(); dispatcher.transfer_from(OWNER(), RECIPIENT(), TOKEN_ID); @@ -210,7 +194,6 @@ fn test_dual_transfer_from() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] fn test_dual_no_transfer_from() { let dispatcher = setup_non_erc721(); @@ -218,7 +201,6 @@ fn test_dual_no_transfer_from() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_transfer_from_exists_and_panics() { let (dispatcher, _) = setup_erc721_panic(); @@ -226,7 +208,6 @@ fn test_dual_transfer_from_exists_and_panics() { } #[test] -#[available_gas(2000000)] fn test_dual_safe_transfer_from() { let (dispatcher, target) = setup_snake(); let receiver = setup_receiver(); @@ -235,7 +216,6 @@ fn test_dual_safe_transfer_from() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] fn test_dual_no_safe_transfer_from() { let dispatcher = setup_non_erc721(); @@ -243,7 +223,6 @@ fn test_dual_no_safe_transfer_from() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_safe_transfer_from_exists_and_panics() { let (dispatcher, _) = setup_erc721_panic(); @@ -251,7 +230,6 @@ fn test_dual_safe_transfer_from_exists_and_panics() { } #[test] -#[available_gas(2000000)] fn test_dual_get_approved() { let (dispatcher, target) = setup_snake(); set_contract_address(OWNER()); @@ -260,7 +238,6 @@ fn test_dual_get_approved() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] fn test_dual_no_get_approved() { let dispatcher = setup_non_erc721(); @@ -268,7 +245,6 @@ fn test_dual_no_get_approved() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_get_approved_exists_and_panics() { let (dispatcher, _) = setup_erc721_panic(); @@ -276,7 +252,6 @@ fn test_dual_get_approved_exists_and_panics() { } #[test] -#[available_gas(2000000)] fn test_dual_set_approval_for_all() { let (dispatcher, target) = setup_snake(); set_contract_address(OWNER()); @@ -285,7 +260,6 @@ fn test_dual_set_approval_for_all() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] fn test_dual_no_set_approval_for_all() { let dispatcher = setup_non_erc721(); @@ -293,7 +267,6 @@ fn test_dual_no_set_approval_for_all() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_set_approval_for_all_exists_and_panics() { let (dispatcher, _) = setup_erc721_panic(); @@ -301,7 +274,6 @@ fn test_dual_set_approval_for_all_exists_and_panics() { } #[test] -#[available_gas(2000000)] fn test_dual_is_approved_for_all() { let (dispatcher, target) = setup_snake(); set_contract_address(OWNER()); @@ -310,7 +282,6 @@ fn test_dual_is_approved_for_all() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] fn test_dual_no_is_approved_for_all() { let dispatcher = setup_non_erc721(); @@ -318,7 +289,6 @@ fn test_dual_no_is_approved_for_all() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_is_approved_for_all_exists_and_panics() { let (dispatcher, _) = setup_erc721_panic(); @@ -326,14 +296,12 @@ fn test_dual_is_approved_for_all_exists_and_panics() { } #[test] -#[available_gas(2000000)] fn test_dual_token_uri() { let (dispatcher, target) = setup_snake(); assert(dispatcher.token_uri(TOKEN_ID) == URI, 'Should return URI'); } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] fn test_dual_no_token_uri() { let dispatcher = setup_non_erc721(); @@ -341,7 +309,6 @@ fn test_dual_no_token_uri() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_token_uri_exists_and_panics() { let (dispatcher, _) = setup_erc721_panic(); @@ -349,14 +316,12 @@ fn test_dual_token_uri_exists_and_panics() { } #[test] -#[available_gas(2000000)] fn test_dual_supports_interface() { let (dispatcher, _) = setup_snake(); assert(dispatcher.supports_interface(IERC721_ID), 'Should support own interface'); } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] fn test_dual_no_supports_interface() { let dispatcher = setup_non_erc721(); @@ -364,7 +329,6 @@ fn test_dual_no_supports_interface() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_supports_interface_exists_and_panics() { let (dispatcher, _) = setup_erc721_panic(); @@ -376,14 +340,12 @@ fn test_dual_supports_interface_exists_and_panics() { // #[test] -#[available_gas(2000000)] fn test_dual_balanceOf() { let (dispatcher, _) = setup_camel(); assert(dispatcher.balance_of(OWNER()) == 1, 'Should return balance'); } #[test] -#[available_gas(2000000)] #[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_balanceOf_exists_and_panics() { let (_, dispatcher) = setup_erc721_panic(); @@ -391,14 +353,12 @@ fn test_dual_balanceOf_exists_and_panics() { } #[test] -#[available_gas(2000000)] fn test_dual_ownerOf() { let (dispatcher, target) = setup_camel(); assert(dispatcher.owner_of(TOKEN_ID) == OWNER(), 'Should return owner'); } #[test] -#[available_gas(2000000)] #[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_ownerOf_exists_and_panics() { let (_, dispatcher) = setup_erc721_panic(); @@ -406,7 +366,6 @@ fn test_dual_ownerOf_exists_and_panics() { } #[test] -#[available_gas(2000000)] fn test_dual_transferFrom() { let (dispatcher, target) = setup_camel(); set_contract_address(OWNER()); @@ -415,7 +374,6 @@ fn test_dual_transferFrom() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_transferFrom_exists_and_panics() { let (_, dispatcher) = setup_erc721_panic(); @@ -423,7 +381,6 @@ fn test_dual_transferFrom_exists_and_panics() { } #[test] -#[available_gas(2000000)] fn test_dual_safeTransferFrom() { let (dispatcher, target) = setup_camel(); let receiver = setup_receiver(); @@ -432,7 +389,6 @@ fn test_dual_safeTransferFrom() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_safeTransferFrom_exists_and_panics() { let (_, dispatcher) = setup_erc721_panic(); @@ -440,7 +396,6 @@ fn test_dual_safeTransferFrom_exists_and_panics() { } #[test] -#[available_gas(2000000)] fn test_dual_getApproved() { let (dispatcher, _) = setup_camel(); set_contract_address(OWNER()); @@ -449,7 +404,6 @@ fn test_dual_getApproved() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_getApproved_exists_and_panics() { let (_, dispatcher) = setup_erc721_panic(); @@ -457,7 +411,6 @@ fn test_dual_getApproved_exists_and_panics() { } #[test] -#[available_gas(2000000)] fn test_dual_setApprovalForAll() { let (dispatcher, target) = setup_camel(); set_contract_address(OWNER()); @@ -466,7 +419,6 @@ fn test_dual_setApprovalForAll() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_setApprovalForAll_exists_and_panics() { let (_, dispatcher) = setup_erc721_panic(); @@ -474,7 +426,6 @@ fn test_dual_setApprovalForAll_exists_and_panics() { } #[test] -#[available_gas(2000000)] fn test_dual_isApprovedForAll() { let (dispatcher, target) = setup_camel(); set_contract_address(OWNER()); @@ -483,7 +434,6 @@ fn test_dual_isApprovedForAll() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_isApprovedForAll_exists_and_panics() { let (_, dispatcher) = setup_erc721_panic(); @@ -491,14 +441,12 @@ fn test_dual_isApprovedForAll_exists_and_panics() { } #[test] -#[available_gas(2000000)] fn test_dual_tokenURI() { let (dispatcher, target) = setup_camel(); assert(dispatcher.token_uri(TOKEN_ID) == URI, 'Should return URI'); } #[test] -#[available_gas(2000000)] #[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_tokenURI_exists_and_panics() { let (_, dispatcher) = setup_erc721_panic(); @@ -506,14 +454,12 @@ fn test_dual_tokenURI_exists_and_panics() { } #[test] -#[available_gas(2000000)] fn test_dual_supportsInterface() { let (dispatcher, _) = setup_camel(); assert(dispatcher.supports_interface(IERC721_ID), 'Should support own interface'); } #[test] -#[available_gas(2000000)] #[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_supportsInterface_exists_and_panics() { let (_, dispatcher) = setup_erc721_panic(); diff --git a/src/tests/token/test_dual721_receiver.cairo b/src/tests/token/test_dual721_receiver.cairo index 922d235b4..746ef1046 100644 --- a/src/tests/token/test_dual721_receiver.cairo +++ b/src/tests/token/test_dual721_receiver.cairo @@ -64,7 +64,6 @@ fn setup_erc721_receiver_panic() -> (DualCaseERC721Receiver, DualCaseERC721Recei // #[test] -#[available_gas(2000000)] fn test_dual_on_erc721_received() { let (dispatcher, _) = setup_snake(); assert( @@ -75,7 +74,6 @@ fn test_dual_on_erc721_received() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] fn test_dual_no_on_erc721_received() { let dispatcher = setup_non_erc721_receiver(); @@ -83,7 +81,6 @@ fn test_dual_no_on_erc721_received() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_on_erc721_received_exists_and_panics() { let (dispatcher, _) = setup_erc721_receiver_panic(); @@ -95,7 +92,6 @@ fn test_dual_on_erc721_received_exists_and_panics() { // #[test] -#[available_gas(2000000)] fn test_dual_onERC721Received() { let (dispatcher, _) = setup_camel(); assert( @@ -106,7 +102,6 @@ fn test_dual_onERC721Received() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ("Some error", 'ENTRYPOINT_FAILED',))] fn test_dual_onERC721Received_exists_and_panics() { let (_, dispatcher) = setup_erc721_receiver_panic(); diff --git a/src/tests/token/test_erc20.cairo b/src/tests/token/test_erc20.cairo index ed321612a..9c654eb07 100644 --- a/src/tests/token/test_erc20.cairo +++ b/src/tests/token/test_erc20.cairo @@ -36,7 +36,6 @@ fn setup() -> ComponentState { // #[test] -#[available_gas(2000000)] fn test_initializer() { let mut state = COMPONENT_STATE(); state.initializer(NAME, SYMBOL); @@ -52,7 +51,6 @@ fn test_initializer() { // #[test] -#[available_gas(2000000)] fn test_total_supply() { let mut state = COMPONENT_STATE(); state._mint(OWNER(), SUPPLY); @@ -60,7 +58,6 @@ fn test_total_supply() { } #[test] -#[available_gas(2000000)] fn test_totalSupply() { let mut state = COMPONENT_STATE(); state._mint(OWNER(), SUPPLY); @@ -68,7 +65,6 @@ fn test_totalSupply() { } #[test] -#[available_gas(2000000)] fn test_balance_of() { let mut state = COMPONENT_STATE(); state._mint(OWNER(), SUPPLY); @@ -76,7 +72,6 @@ fn test_balance_of() { } #[test] -#[available_gas(2000000)] fn test_balanceOf() { let mut state = COMPONENT_STATE(); state._mint(OWNER(), SUPPLY); @@ -84,7 +79,6 @@ fn test_balanceOf() { } #[test] -#[available_gas(2000000)] fn test_allowance() { let mut state = setup(); testing::set_caller_address(OWNER()); @@ -98,7 +92,6 @@ fn test_allowance() { // #[test] -#[available_gas(2000000)] fn test_approve() { let mut state = setup(); testing::set_caller_address(OWNER()); @@ -109,7 +102,6 @@ fn test_approve() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('ERC20: approve from 0',))] fn test_approve_from_zero() { let mut state = setup(); @@ -117,7 +109,6 @@ fn test_approve_from_zero() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('ERC20: approve to 0',))] fn test_approve_to_zero() { let mut state = setup(); @@ -126,7 +117,6 @@ fn test_approve_to_zero() { } #[test] -#[available_gas(2000000)] fn test__approve() { let mut state = setup(); testing::set_caller_address(OWNER()); @@ -137,7 +127,6 @@ fn test__approve() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('ERC20: approve from 0',))] fn test__approve_from_zero() { let mut state = setup(); @@ -145,7 +134,6 @@ fn test__approve_from_zero() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('ERC20: approve to 0',))] fn test__approve_to_zero() { let mut state = setup(); @@ -158,7 +146,6 @@ fn test__approve_to_zero() { // #[test] -#[available_gas(2000000)] fn test_transfer() { let mut state = setup(); testing::set_caller_address(OWNER()); @@ -171,7 +158,6 @@ fn test_transfer() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('u256_sub Overflow',))] fn test_transfer_not_enough_balance() { let mut state = setup(); @@ -182,7 +168,6 @@ fn test_transfer_not_enough_balance() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('ERC20: transfer from 0',))] fn test_transfer_from_zero() { let mut state = setup(); @@ -190,7 +175,6 @@ fn test_transfer_from_zero() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('ERC20: transfer to 0',))] fn test_transfer_to_zero() { let mut state = setup(); @@ -199,7 +183,6 @@ fn test_transfer_to_zero() { } #[test] -#[available_gas(2000000)] fn test__transfer() { let mut state = setup(); @@ -212,7 +195,6 @@ fn test__transfer() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('u256_sub Overflow',))] fn test__transfer_not_enough_balance() { let mut state = setup(); @@ -223,7 +205,6 @@ fn test__transfer_not_enough_balance() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('ERC20: transfer from 0',))] fn test__transfer_from_zero() { let mut state = setup(); @@ -231,7 +212,6 @@ fn test__transfer_from_zero() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('ERC20: transfer to 0',))] fn test__transfer_to_zero() { let mut state = setup(); @@ -243,7 +223,6 @@ fn test__transfer_to_zero() { // #[test] -#[available_gas(2000000)] fn test_transfer_from() { let mut state = setup(); testing::set_caller_address(OWNER()); @@ -263,7 +242,6 @@ fn test_transfer_from() { } #[test] -#[available_gas(2000000)] fn test_transfer_from_doesnt_consume_infinite_allowance() { let mut state = setup(); testing::set_caller_address(OWNER()); @@ -276,7 +254,6 @@ fn test_transfer_from_doesnt_consume_infinite_allowance() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('u256_sub Overflow',))] fn test_transfer_from_greater_than_allowance() { let mut state = setup(); @@ -289,7 +266,6 @@ fn test_transfer_from_greater_than_allowance() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('ERC20: transfer to 0',))] fn test_transfer_from_to_zero_address() { let mut state = setup(); @@ -301,7 +277,6 @@ fn test_transfer_from_to_zero_address() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('u256_sub Overflow',))] fn test_transfer_from_from_zero_address() { let mut state = setup(); @@ -309,7 +284,6 @@ fn test_transfer_from_from_zero_address() { } #[test] -#[available_gas(2000000)] fn test_transferFrom() { let mut state = setup(); testing::set_caller_address(OWNER()); @@ -329,7 +303,6 @@ fn test_transferFrom() { } #[test] -#[available_gas(2000000)] fn test_transferFrom_doesnt_consume_infinite_allowance() { let mut state = setup(); testing::set_caller_address(OWNER()); @@ -342,7 +315,6 @@ fn test_transferFrom_doesnt_consume_infinite_allowance() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('u256_sub Overflow',))] fn test_transferFrom_greater_than_allowance() { let mut state = setup(); @@ -355,7 +327,6 @@ fn test_transferFrom_greater_than_allowance() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('ERC20: transfer to 0',))] fn test_transferFrom_to_zero_address() { let mut state = setup(); @@ -367,7 +338,6 @@ fn test_transferFrom_to_zero_address() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('u256_sub Overflow',))] fn test_transferFrom_from_zero_address() { let mut state = setup(); @@ -379,7 +349,6 @@ fn test_transferFrom_from_zero_address() { // #[test] -#[available_gas(2000000)] fn test_increase_allowance() { let mut state = setup(); testing::set_caller_address(OWNER()); @@ -393,7 +362,6 @@ fn test_increase_allowance() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('ERC20: approve to 0',))] fn test_increase_allowance_to_zero_address() { let mut state = setup(); @@ -402,7 +370,6 @@ fn test_increase_allowance_to_zero_address() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('ERC20: approve from 0',))] fn test_increase_allowance_from_zero_address() { let mut state = setup(); @@ -410,7 +377,6 @@ fn test_increase_allowance_from_zero_address() { } #[test] -#[available_gas(2000000)] fn test_increaseAllowance() { let mut state = setup(); testing::set_caller_address(OWNER()); @@ -424,7 +390,6 @@ fn test_increaseAllowance() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('ERC20: approve to 0',))] fn test_increaseAllowance_to_zero_address() { let mut state = setup(); @@ -433,7 +398,6 @@ fn test_increaseAllowance_to_zero_address() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('ERC20: approve from 0',))] fn test_increaseAllowance_from_zero_address() { let mut state = setup(); @@ -445,7 +409,6 @@ fn test_increaseAllowance_from_zero_address() { // #[test] -#[available_gas(2000000)] fn test_decrease_allowance() { let mut state = setup(); testing::set_caller_address(OWNER()); @@ -459,7 +422,6 @@ fn test_decrease_allowance() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('u256_sub Overflow',))] fn test_decrease_allowance_to_zero_address() { let mut state = setup(); @@ -468,7 +430,6 @@ fn test_decrease_allowance_to_zero_address() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('u256_sub Overflow',))] fn test_decrease_allowance_from_zero_address() { let mut state = setup(); @@ -476,7 +437,6 @@ fn test_decrease_allowance_from_zero_address() { } #[test] -#[available_gas(2000000)] fn test_decreaseAllowance() { let mut state = setup(); testing::set_caller_address(OWNER()); @@ -490,7 +450,6 @@ fn test_decreaseAllowance() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('u256_sub Overflow',))] fn test_decreaseAllowance_to_zero_address() { let mut state = setup(); @@ -499,7 +458,6 @@ fn test_decreaseAllowance_to_zero_address() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('u256_sub Overflow',))] fn test_decreaseAllowance_from_zero_address() { let mut state = setup(); @@ -511,7 +469,6 @@ fn test_decreaseAllowance_from_zero_address() { // #[test] -#[available_gas(2000000)] fn test__spend_allowance_not_unlimited() { let mut state = setup(); @@ -525,7 +482,6 @@ fn test__spend_allowance_not_unlimited() { } #[test] -#[available_gas(2000000)] fn test__spend_allowance_unlimited() { let mut state = setup(); state._approve(OWNER(), SPENDER(), BoundedInt::max()); @@ -541,7 +497,6 @@ fn test__spend_allowance_unlimited() { // #[test] -#[available_gas(2000000)] fn test__mint() { let mut state = COMPONENT_STATE(); state._mint(OWNER(), VALUE); @@ -552,7 +507,6 @@ fn test__mint() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('ERC20: mint to 0',))] fn test__mint_to_zero() { let mut state = COMPONENT_STATE(); @@ -564,7 +518,6 @@ fn test__mint_to_zero() { // #[test] -#[available_gas(2000000)] fn test__burn() { let mut state = setup(); state._burn(OWNER(), VALUE); @@ -575,7 +528,6 @@ fn test__burn() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('ERC20: burn from 0',))] fn test__burn_from_zero() { let mut state = setup(); diff --git a/src/tests/token/test_erc721.cairo b/src/tests/token/test_erc721.cairo index 8a1a3376b..48e18643d 100644 --- a/src/tests/token/test_erc721.cairo +++ b/src/tests/token/test_erc721.cairo @@ -70,7 +70,6 @@ fn setup_camel_account() -> ContractAddress { // #[test] -#[available_gas(20000000)] fn test_initialize() { let mut state = COMPONENT_STATE(); let mock_state = CONTRACT_STATE(); @@ -96,14 +95,12 @@ fn test_initialize() { // #[test] -#[available_gas(20000000)] fn test_balance_of() { let state = setup(); assert(state.balance_of(OWNER()) == 1, 'Should return balance'); } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ERC721: invalid account',))] fn test_balance_of_zero() { let state = setup(); @@ -111,14 +108,12 @@ fn test_balance_of_zero() { } #[test] -#[available_gas(20000000)] fn test_owner_of() { let state = setup(); assert(state.owner_of(TOKEN_ID) == OWNER(), 'Should return owner'); } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ERC721: invalid token ID',))] fn test_owner_of_non_minted() { let state = setup(); @@ -126,7 +121,6 @@ fn test_owner_of_non_minted() { } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ERC721: invalid token ID',))] fn test_token_uri_non_minted() { let state = setup(); @@ -134,7 +128,6 @@ fn test_token_uri_non_minted() { } #[test] -#[available_gas(20000000)] fn test_get_approved() { let mut state = setup(); let spender = SPENDER(); @@ -146,7 +139,6 @@ fn test_get_approved() { } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ERC721: invalid token ID',))] fn test_get_approved_nonexistent() { let state = setup(); @@ -154,7 +146,6 @@ fn test_get_approved_nonexistent() { } #[test] -#[available_gas(20000000)] fn test__exists() { let mut state = COMPONENT_STATE(); let zero = ZERO(); @@ -182,7 +173,6 @@ fn test__exists() { // #[test] -#[available_gas(20000000)] fn test_approve_from_owner() { let mut state = setup(); @@ -194,7 +184,6 @@ fn test_approve_from_owner() { } #[test] -#[available_gas(20000000)] fn test_approve_from_operator() { let mut state = setup(); @@ -210,7 +199,6 @@ fn test_approve_from_operator() { } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ERC721: unauthorized caller',))] fn test_approve_from_unauthorized() { let mut state = setup(); @@ -220,7 +208,6 @@ fn test_approve_from_unauthorized() { } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ERC721: approval to owner',))] fn test_approve_to_owner() { let mut state = setup(); @@ -230,7 +217,6 @@ fn test_approve_to_owner() { } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ERC721: invalid token ID',))] fn test_approve_nonexistent() { let mut state = COMPONENT_STATE(); @@ -238,7 +224,6 @@ fn test_approve_nonexistent() { } #[test] -#[available_gas(20000000)] fn test__approve() { let mut state = setup(); state._approve(SPENDER(), TOKEN_ID); @@ -248,7 +233,6 @@ fn test__approve() { } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ERC721: approval to owner',))] fn test__approve_to_owner() { let mut state = setup(); @@ -256,7 +240,6 @@ fn test__approve_to_owner() { } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ERC721: invalid token ID',))] fn test__approve_nonexistent() { let mut state = COMPONENT_STATE(); @@ -268,7 +251,6 @@ fn test__approve_nonexistent() { // #[test] -#[available_gas(20000000)] fn test_set_approval_for_all() { let mut state = COMPONENT_STATE(); testing::set_caller_address(OWNER()); @@ -287,7 +269,6 @@ fn test_set_approval_for_all() { } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ERC721: self approval',))] fn test_set_approval_for_all_owner_equal_operator_true() { let mut state = COMPONENT_STATE(); @@ -296,7 +277,6 @@ fn test_set_approval_for_all_owner_equal_operator_true() { } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ERC721: self approval',))] fn test_set_approval_for_all_owner_equal_operator_false() { let mut state = COMPONENT_STATE(); @@ -305,7 +285,6 @@ fn test_set_approval_for_all_owner_equal_operator_false() { } #[test] -#[available_gas(20000000)] fn test__set_approval_for_all() { let mut state = COMPONENT_STATE(); assert(!state.is_approved_for_all(OWNER(), OPERATOR()), 'Invalid default value'); @@ -322,7 +301,6 @@ fn test__set_approval_for_all() { } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ERC721: self approval',))] fn test__set_approval_for_all_owner_equal_operator_true() { let mut state = COMPONENT_STATE(); @@ -330,7 +308,6 @@ fn test__set_approval_for_all_owner_equal_operator_true() { } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ERC721: self approval',))] fn test__set_approval_for_all_owner_equal_operator_false() { let mut state = COMPONENT_STATE(); @@ -342,7 +319,6 @@ fn test__set_approval_for_all_owner_equal_operator_false() { // #[test] -#[available_gas(20000000)] fn test_transfer_from_owner() { let mut state = setup(); let token_id = TOKEN_ID; @@ -363,7 +339,6 @@ fn test_transfer_from_owner() { } #[test] -#[available_gas(20000000)] fn test_transferFrom_owner() { let mut state = setup(); let token_id = TOKEN_ID; @@ -384,7 +359,6 @@ fn test_transferFrom_owner() { } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ERC721: invalid token ID',))] fn test_transfer_from_nonexistent() { let mut state = COMPONENT_STATE(); @@ -392,7 +366,6 @@ fn test_transfer_from_nonexistent() { } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ERC721: invalid token ID',))] fn test_transferFrom_nonexistent() { let mut state = COMPONENT_STATE(); @@ -400,7 +373,6 @@ fn test_transferFrom_nonexistent() { } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ERC721: invalid receiver',))] fn test_transfer_from_to_zero() { let mut state = setup(); @@ -409,7 +381,6 @@ fn test_transfer_from_to_zero() { } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ERC721: invalid receiver',))] fn test_transferFrom_to_zero() { let mut state = setup(); @@ -419,7 +390,6 @@ fn test_transferFrom_to_zero() { } #[test] -#[available_gas(20000000)] fn test_transfer_from_to_owner() { let mut state = setup(); @@ -435,7 +405,6 @@ fn test_transfer_from_to_owner() { } #[test] -#[available_gas(20000000)] fn test_transferFrom_to_owner() { let mut state = setup(); @@ -451,7 +420,6 @@ fn test_transferFrom_to_owner() { } #[test] -#[available_gas(20000000)] fn test_transfer_from_approved() { let mut state = setup(); let token_id = TOKEN_ID; @@ -471,7 +439,6 @@ fn test_transfer_from_approved() { } #[test] -#[available_gas(20000000)] fn test_transferFrom_approved() { let mut state = setup(); let token_id = TOKEN_ID; @@ -491,7 +458,6 @@ fn test_transferFrom_approved() { } #[test] -#[available_gas(20000000)] fn test_transfer_from_approved_for_all() { let mut state = setup(); let token_id = TOKEN_ID; @@ -512,7 +478,6 @@ fn test_transfer_from_approved_for_all() { } #[test] -#[available_gas(20000000)] fn test_transferFrom_approved_for_all() { let mut state = setup(); let token_id = TOKEN_ID; @@ -533,7 +498,6 @@ fn test_transferFrom_approved_for_all() { } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ERC721: unauthorized caller',))] fn test_transfer_from_unauthorized() { let mut state = setup(); @@ -542,7 +506,6 @@ fn test_transfer_from_unauthorized() { } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ERC721: unauthorized caller',))] fn test_transferFrom_unauthorized() { let mut state = setup(); @@ -555,7 +518,6 @@ fn test_transferFrom_unauthorized() { // #[test] -#[available_gas(20000000)] fn test_safe_transfer_from_to_account() { let mut state = setup(); let account = setup_account(); @@ -572,7 +534,6 @@ fn test_safe_transfer_from_to_account() { } #[test] -#[available_gas(20000000)] fn test_safeTransferFrom_to_account() { let mut state = setup(); let account = setup_account(); @@ -589,7 +550,6 @@ fn test_safeTransferFrom_to_account() { } #[test] -#[available_gas(20000000)] fn test_safe_transfer_from_to_account_camel() { let mut state = setup(); let account = setup_camel_account(); @@ -606,7 +566,6 @@ fn test_safe_transfer_from_to_account_camel() { } #[test] -#[available_gas(20000000)] fn test_safeTransferFrom_to_account_camel() { let mut state = setup(); let account = setup_camel_account(); @@ -623,7 +582,6 @@ fn test_safeTransferFrom_to_account_camel() { } #[test] -#[available_gas(20000000)] fn test_safe_transfer_from_to_receiver() { let mut state = setup(); let receiver = setup_receiver(); @@ -640,7 +598,6 @@ fn test_safe_transfer_from_to_receiver() { } #[test] -#[available_gas(20000000)] fn test_safeTransferFrom_to_receiver() { let mut state = setup(); let receiver = setup_receiver(); @@ -657,7 +614,6 @@ fn test_safeTransferFrom_to_receiver() { } #[test] -#[available_gas(20000000)] fn test_safe_transfer_from_to_receiver_camel() { let mut state = setup(); let receiver = setup_camel_receiver(); @@ -674,7 +630,6 @@ fn test_safe_transfer_from_to_receiver_camel() { } #[test] -#[available_gas(20000000)] fn test_safeTransferFrom_to_receiver_camel() { let mut state = setup(); let receiver = setup_camel_receiver(); @@ -691,7 +646,6 @@ fn test_safeTransferFrom_to_receiver_camel() { } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ERC721: safe transfer failed',))] fn test_safe_transfer_from_to_receiver_failure() { let mut state = setup(); @@ -704,7 +658,6 @@ fn test_safe_transfer_from_to_receiver_failure() { } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ERC721: safe transfer failed',))] fn test_safeTransferFrom_to_receiver_failure() { let mut state = setup(); @@ -717,7 +670,6 @@ fn test_safeTransferFrom_to_receiver_failure() { } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ERC721: safe transfer failed',))] fn test_safe_transfer_from_to_receiver_failure_camel() { let mut state = setup(); @@ -730,7 +682,6 @@ fn test_safe_transfer_from_to_receiver_failure_camel() { } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ERC721: safe transfer failed',))] fn test_safeTransferFrom_to_receiver_failure_camel() { let mut state = setup(); @@ -743,7 +694,6 @@ fn test_safeTransferFrom_to_receiver_failure_camel() { } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] fn test_safe_transfer_from_to_non_receiver() { let mut state = setup(); @@ -756,7 +706,6 @@ fn test_safe_transfer_from_to_non_receiver() { } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] fn test_safeTransferFrom_to_non_receiver() { let mut state = setup(); @@ -769,7 +718,6 @@ fn test_safeTransferFrom_to_non_receiver() { } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ERC721: invalid token ID',))] fn test_safe_transfer_from_nonexistent() { let mut state = COMPONENT_STATE(); @@ -777,7 +725,6 @@ fn test_safe_transfer_from_nonexistent() { } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ERC721: invalid token ID',))] fn test_safeTransferFrom_nonexistent() { let mut state = COMPONENT_STATE(); @@ -785,7 +732,6 @@ fn test_safeTransferFrom_nonexistent() { } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ERC721: invalid receiver',))] fn test_safe_transfer_from_to_zero() { let mut state = setup(); @@ -794,7 +740,6 @@ fn test_safe_transfer_from_to_zero() { } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ERC721: invalid receiver',))] fn test_safeTransferFrom_to_zero() { let mut state = setup(); @@ -803,7 +748,6 @@ fn test_safeTransferFrom_to_zero() { } #[test] -#[available_gas(20000000)] fn test_safe_transfer_from_to_owner() { let mut state = COMPONENT_STATE(); let token_id = TOKEN_ID; @@ -824,7 +768,6 @@ fn test_safe_transfer_from_to_owner() { } #[test] -#[available_gas(20000000)] fn test_safeTransferFrom_to_owner() { let mut state = COMPONENT_STATE(); let token_id = TOKEN_ID; @@ -845,7 +788,6 @@ fn test_safeTransferFrom_to_owner() { } #[test] -#[available_gas(20000000)] fn test_safe_transfer_from_to_owner_camel() { let mut state = COMPONENT_STATE(); let token_id = TOKEN_ID; @@ -866,7 +808,6 @@ fn test_safe_transfer_from_to_owner_camel() { } #[test] -#[available_gas(20000000)] fn test_safeTransferFrom_to_owner_camel() { let mut state = COMPONENT_STATE(); let token_id = TOKEN_ID; @@ -887,7 +828,6 @@ fn test_safeTransferFrom_to_owner_camel() { } #[test] -#[available_gas(20000000)] fn test_safe_transfer_from_approved() { let mut state = setup(); let receiver = setup_receiver(); @@ -908,7 +848,6 @@ fn test_safe_transfer_from_approved() { } #[test] -#[available_gas(20000000)] fn test_safeTransferFrom_approved() { let mut state = setup(); let receiver = setup_receiver(); @@ -929,7 +868,6 @@ fn test_safeTransferFrom_approved() { } #[test] -#[available_gas(20000000)] fn test_safe_transfer_from_approved_camel() { let mut state = setup(); let receiver = setup_camel_receiver(); @@ -950,7 +888,6 @@ fn test_safe_transfer_from_approved_camel() { } #[test] -#[available_gas(20000000)] fn test_safeTransferFrom_approved_camel() { let mut state = setup(); let receiver = setup_camel_receiver(); @@ -971,7 +908,6 @@ fn test_safeTransferFrom_approved_camel() { } #[test] -#[available_gas(20000000)] fn test_safe_transfer_from_approved_for_all() { let mut state = setup(); let receiver = setup_receiver(); @@ -992,7 +928,6 @@ fn test_safe_transfer_from_approved_for_all() { } #[test] -#[available_gas(20000000)] fn test_safeTransferFrom_approved_for_all() { let mut state = setup(); let receiver = setup_receiver(); @@ -1013,7 +948,6 @@ fn test_safeTransferFrom_approved_for_all() { } #[test] -#[available_gas(20000000)] fn test_safe_transfer_from_approved_for_all_camel() { let mut state = setup(); let receiver = setup_camel_receiver(); @@ -1034,7 +968,6 @@ fn test_safe_transfer_from_approved_for_all_camel() { } #[test] -#[available_gas(20000000)] fn test_safeTransferFrom_approved_for_all_camel() { let mut state = setup(); let receiver = setup_camel_receiver(); @@ -1055,7 +988,6 @@ fn test_safeTransferFrom_approved_for_all_camel() { } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ERC721: unauthorized caller',))] fn test_safe_transfer_from_unauthorized() { let mut state = setup(); @@ -1064,7 +996,6 @@ fn test_safe_transfer_from_unauthorized() { } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ERC721: unauthorized caller',))] fn test_safeTransferFrom_unauthorized() { let mut state = setup(); @@ -1077,7 +1008,6 @@ fn test_safeTransferFrom_unauthorized() { // #[test] -#[available_gas(20000000)] fn test__transfer() { let mut state = setup(); let token_id = TOKEN_ID; @@ -1093,7 +1023,6 @@ fn test__transfer() { } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ERC721: invalid token ID',))] fn test__transfer_nonexistent() { let mut state = COMPONENT_STATE(); @@ -1101,7 +1030,6 @@ fn test__transfer_nonexistent() { } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ERC721: invalid receiver',))] fn test__transfer_to_zero() { let mut state = setup(); @@ -1109,7 +1037,6 @@ fn test__transfer_to_zero() { } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ERC721: wrong sender',))] fn test__transfer_from_invalid_owner() { let mut state = setup(); @@ -1121,7 +1048,6 @@ fn test__transfer_from_invalid_owner() { // #[test] -#[available_gas(20000000)] fn test__mint() { let mut state = COMPONENT_STATE(); let recipient = RECIPIENT(); @@ -1135,7 +1061,6 @@ fn test__mint() { } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ERC721: invalid receiver',))] fn test__mint_to_zero() { let mut state = COMPONENT_STATE(); @@ -1143,7 +1068,6 @@ fn test__mint_to_zero() { } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ERC721: token already minted',))] fn test__mint_already_exist() { let mut state = setup(); @@ -1155,7 +1079,6 @@ fn test__mint_already_exist() { // #[test] -#[available_gas(20000000)] fn test__safe_mint_to_receiver() { let mut state = COMPONENT_STATE(); let recipient = setup_receiver(); @@ -1169,7 +1092,6 @@ fn test__safe_mint_to_receiver() { } #[test] -#[available_gas(20000000)] fn test__safe_mint_to_receiver_camel() { let mut state = COMPONENT_STATE(); let recipient = setup_camel_receiver(); @@ -1183,7 +1105,6 @@ fn test__safe_mint_to_receiver_camel() { } #[test] -#[available_gas(20000000)] fn test__safe_mint_to_account() { let mut state = COMPONENT_STATE(); let account = setup_account(); @@ -1197,7 +1118,6 @@ fn test__safe_mint_to_account() { } #[test] -#[available_gas(20000000)] fn test__safe_mint_to_account_camel() { let mut state = COMPONENT_STATE(); let account = setup_camel_account(); @@ -1211,7 +1131,6 @@ fn test__safe_mint_to_account_camel() { } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] fn test__safe_mint_to_non_receiver() { let mut state = COMPONENT_STATE(); @@ -1224,7 +1143,6 @@ fn test__safe_mint_to_non_receiver() { } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ERC721: safe mint failed',))] fn test__safe_mint_to_receiver_failure() { let mut state = COMPONENT_STATE(); @@ -1237,7 +1155,6 @@ fn test__safe_mint_to_receiver_failure() { } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ERC721: safe mint failed',))] fn test__safe_mint_to_receiver_failure_camel() { let mut state = COMPONENT_STATE(); @@ -1250,7 +1167,6 @@ fn test__safe_mint_to_receiver_failure_camel() { } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ERC721: invalid receiver',))] fn test__safe_mint_to_zero() { let mut state = COMPONENT_STATE(); @@ -1258,7 +1174,6 @@ fn test__safe_mint_to_zero() { } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ERC721: token already minted',))] fn test__safe_mint_already_exist() { let mut state = setup(); @@ -1270,7 +1185,6 @@ fn test__safe_mint_already_exist() { // #[test] -#[available_gas(20000000)] fn test__burn() { let mut state = setup(); @@ -1290,7 +1204,6 @@ fn test__burn() { } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ERC721: invalid token ID',))] fn test__burn_nonexistent() { let mut state = COMPONENT_STATE(); @@ -1302,7 +1215,6 @@ fn test__burn_nonexistent() { // #[test] -#[available_gas(20000000)] fn test__set_token_uri() { let mut state = setup(); @@ -1312,7 +1224,6 @@ fn test__set_token_uri() { } #[test] -#[available_gas(20000000)] #[should_panic(expected: ('ERC721: invalid token ID',))] fn test__set_token_uri_nonexistent() { let mut state = COMPONENT_STATE(); diff --git a/src/tests/token/test_erc721_receiver.cairo b/src/tests/token/test_erc721_receiver.cairo index 529d9b2fe..52af8bcc7 100644 --- a/src/tests/token/test_erc721_receiver.cairo +++ b/src/tests/token/test_erc721_receiver.cairo @@ -12,7 +12,6 @@ fn STATE() -> DualCaseERC721ReceiverMock::ContractState { } #[test] -#[available_gas(20000000)] fn test_initializer() { let mut state = STATE(); state.erc721_receiver.initializer(); @@ -21,7 +20,6 @@ fn test_initializer() { } #[test] -#[available_gas(20000000)] fn test_on_erc721_received() { let mut state = STATE(); let data = array![]; diff --git a/src/tests/upgrades/test_upgradeable.cairo b/src/tests/upgrades/test_upgradeable.cairo index 26b191f3c..932d33c63 100644 --- a/src/tests/upgrades/test_upgradeable.cairo +++ b/src/tests/upgrades/test_upgradeable.cairo @@ -31,7 +31,6 @@ fn deploy_v1() -> IUpgradesV1Dispatcher { // #[test] -#[available_gas(2000000)] #[should_panic(expected: ('Class hash cannot be zero', 'ENTRYPOINT_FAILED',))] fn test_upgrade_with_class_hash_zero() { let v1 = deploy_v1(); @@ -39,7 +38,6 @@ fn test_upgrade_with_class_hash_zero() { } #[test] -#[available_gas(2000000)] fn test_upgraded_event() { let v1 = deploy_v1(); v1.upgrade(V2_CLASS_HASH()); @@ -51,7 +49,6 @@ fn test_upgraded_event() { } #[test] -#[available_gas(2000000)] fn test_new_selector_after_upgrade() { let v1 = deploy_v1(); @@ -63,7 +60,6 @@ fn test_new_selector_after_upgrade() { } #[test] -#[available_gas(2000000)] fn test_state_persists_after_upgrade() { let v1 = deploy_v1(); v1.set_value(VALUE); @@ -75,14 +71,12 @@ fn test_state_persists_after_upgrade() { } #[test] -#[available_gas(2000000)] fn test_remove_selector_passes_in_v1() { let v1 = deploy_v1(); v1.remove_selector(); } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] fn test_remove_selector_fails_in_v2() { let v1 = deploy_v1(); From 2eabea6b3829bfca5c9fa57d6601f7f43eb0ac33 Mon Sep 17 00:00:00 2001 From: Eric Nordelo Date: Fri, 5 Jan 2024 12:22:52 +0100 Subject: [PATCH 04/15] feat: refactor access assertions --- CHANGELOG.md | 3 +- src/tests/access/test_accesscontrol.cairo | 96 ++++++++++++------- .../access/test_dual_accesscontrol.cairo | 46 ++++++--- src/tests/access/test_dual_ownable.cairo | 24 +++-- src/tests/access/test_ownable.cairo | 28 +++--- src/tests/utils.cairo | 1 + src/tests/utils/debug.cairo | 9 ++ 7 files changed, 141 insertions(+), 66 deletions(-) create mode 100644 src/tests/utils/debug.cairo diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d5989360..35d3e8439 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,4 +19,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Use ComponentState in tests (#836) - Docsite navbar (#838) - Use panic macro in tests (#) -- Fix test mocks file naming (#) +- Normalize test mocks file naming (#) +- Normalize assertions in tests (#) diff --git a/src/tests/access/test_accesscontrol.cairo b/src/tests/access/test_accesscontrol.cairo index f1f6a459b..93386cfef 100644 --- a/src/tests/access/test_accesscontrol.cairo +++ b/src/tests/access/test_accesscontrol.cairo @@ -11,6 +11,7 @@ use openzeppelin::tests::mocks::accesscontrol_mocks::DualCaseAccessControlMock; use openzeppelin::tests::utils::constants::{ ADMIN, AUTHORIZED, OTHER, OTHER_ADMIN, ROLE, OTHER_ROLE, ZERO }; +use openzeppelin::tests::utils::debug::DebugContractAddress; use openzeppelin::tests::utils; use starknet::ContractAddress; use starknet::testing; @@ -45,7 +46,8 @@ fn setup() -> ComponentState { fn test_initializer() { let mut state = COMPONENT_STATE(); state.initializer(); - assert(CONTRACT_STATE().supports_interface(IACCESSCONTROL_ID), 'Should support own interface'); + let supported = CONTRACT_STATE().supports_interface(IACCESSCONTROL_ID); + assert!(supported, "Should implement IACCESSCONTROL"); } // @@ -55,17 +57,17 @@ fn test_initializer() { #[test] fn test_has_role() { let mut state = setup(); - assert(!state.has_role(ROLE, AUTHORIZED()), 'Should not have role'); + assert!(!state.has_role(ROLE, AUTHORIZED())); state._grant_role(ROLE, AUTHORIZED()); - assert(state.has_role(ROLE, AUTHORIZED()), 'Should have role'); + assert!(state.has_role(ROLE, AUTHORIZED())); } #[test] fn test_hasRole() { let mut state = setup(); - assert(!state.hasRole(ROLE, AUTHORIZED()), 'Should not have role'); + assert!(!state.hasRole(ROLE, AUTHORIZED())); state._grant_role(ROLE, AUTHORIZED()); - assert(state.hasRole(ROLE, AUTHORIZED()), 'Should have role'); + assert!(state.hasRole(ROLE, AUTHORIZED())); } // @@ -111,7 +113,9 @@ fn test_grant_role() { state.grant_role(ROLE, AUTHORIZED()); assert_event_role_granted(ROLE, AUTHORIZED(), ADMIN()); - assert(state.has_role(ROLE, AUTHORIZED()), 'Should have role granted'); + + let has_role = state.has_role(ROLE, AUTHORIZED()); + assert!(has_role); } #[test] @@ -121,7 +125,9 @@ fn test_grantRole() { state.grantRole(ROLE, AUTHORIZED()); assert_event_role_granted(ROLE, AUTHORIZED(), ADMIN()); - assert(state.hasRole(ROLE, AUTHORIZED()), 'Should have role granted'); + + let has_role = state.hasRole(ROLE, AUTHORIZED()); + assert!(has_role); } #[test] @@ -131,7 +137,7 @@ fn test_grant_role_multiple_times_for_granted_role() { state.grant_role(ROLE, AUTHORIZED()); state.grant_role(ROLE, AUTHORIZED()); - assert(state.has_role(ROLE, AUTHORIZED()), 'Should have role granted'); + assert!(state.has_role(ROLE, AUTHORIZED())); } #[test] @@ -141,7 +147,7 @@ fn test_grantRole_multiple_times_for_granted_role() { state.grantRole(ROLE, AUTHORIZED()); state.grantRole(ROLE, AUTHORIZED()); - assert(state.hasRole(ROLE, AUTHORIZED()), 'Should have role granted'); + assert!(state.hasRole(ROLE, AUTHORIZED())); } #[test] @@ -189,7 +195,9 @@ fn test_revoke_role_for_granted_role() { state.revoke_role(ROLE, AUTHORIZED()); assert_event_role_revoked(ROLE, AUTHORIZED(), ADMIN()); - assert(!state.has_role(ROLE, AUTHORIZED()), 'Should have role revoked'); + + let has_not_role = !state.has_role(ROLE, AUTHORIZED()); + assert!(has_not_role); } #[test] @@ -203,7 +211,9 @@ fn test_revokeRole_for_granted_role() { state.revokeRole(ROLE, AUTHORIZED()); assert_event_role_revoked(ROLE, AUTHORIZED(), ADMIN()); - assert(!state.hasRole(ROLE, AUTHORIZED()), 'Should have role revoked'); + + let has_not_role = !state.hasRole(ROLE, AUTHORIZED()); + assert!(has_not_role); } #[test] @@ -214,7 +224,9 @@ fn test_revoke_role_multiple_times_for_granted_role() { state.grant_role(ROLE, AUTHORIZED()); state.revoke_role(ROLE, AUTHORIZED()); state.revoke_role(ROLE, AUTHORIZED()); - assert(!state.has_role(ROLE, AUTHORIZED()), 'Should have role revoked'); + + let has_not_role = !state.has_role(ROLE, AUTHORIZED()); + assert!(has_not_role); } #[test] @@ -225,7 +237,9 @@ fn test_revokeRole_multiple_times_for_granted_role() { state.grantRole(ROLE, AUTHORIZED()); state.revokeRole(ROLE, AUTHORIZED()); state.revokeRole(ROLE, AUTHORIZED()); - assert(!state.hasRole(ROLE, AUTHORIZED()), 'Should have role revoked'); + + let has_not_role = !state.hasRole(ROLE, AUTHORIZED()); + assert!(has_not_role); } #[test] @@ -274,7 +288,9 @@ fn test_renounce_role_for_granted_role() { state.renounce_role(ROLE, AUTHORIZED()); assert_event_role_revoked(ROLE, AUTHORIZED(), AUTHORIZED()); - assert(!state.has_role(ROLE, AUTHORIZED()), 'Should have role revoked'); + + let has_not_role = !state.has_role(ROLE, AUTHORIZED()); + assert!(has_not_role); } #[test] @@ -289,7 +305,9 @@ fn test_renounceRole_for_granted_role() { state.renounceRole(ROLE, AUTHORIZED()); assert_event_role_revoked(ROLE, AUTHORIZED(), AUTHORIZED()); - assert(!state.hasRole(ROLE, AUTHORIZED()), 'Should have role revoked'); + + let has_not_role = !state.hasRole(ROLE, AUTHORIZED()); + assert!(has_not_role); } #[test] @@ -301,7 +319,9 @@ fn test_renounce_role_multiple_times_for_granted_role() { testing::set_caller_address(AUTHORIZED()); state.renounce_role(ROLE, AUTHORIZED()); state.renounce_role(ROLE, AUTHORIZED()); - assert(!state.has_role(ROLE, AUTHORIZED()), 'Should have role revoked'); + + let has_not_role = !state.has_role(ROLE, AUTHORIZED()); + assert!(has_not_role); } #[test] @@ -313,7 +333,9 @@ fn test_renounceRole_multiple_times_for_granted_role() { testing::set_caller_address(AUTHORIZED()); state.renounceRole(ROLE, AUTHORIZED()); state.renounceRole(ROLE, AUTHORIZED()); - assert(!state.hasRole(ROLE, AUTHORIZED()), 'Should have role revoked'); + + let has_not_role = !state.hasRole(ROLE, AUTHORIZED()); + assert!(has_not_role); } #[test] @@ -349,7 +371,9 @@ fn test__set_role_admin() { state._set_role_admin(ROLE, OTHER_ROLE); assert_event_role_admin_changed(ROLE, DEFAULT_ADMIN_ROLE, OTHER_ROLE); - assert(state.get_role_admin(ROLE) == OTHER_ROLE, 'Admin should be OTHER_ROLE'); + + let current_admin_role = state.get_role_admin(ROLE); + assert_eq!(current_admin_role, OTHER_ROLE); } #[test] @@ -362,7 +386,9 @@ fn test_new_admin_can_grant_roles() { testing::set_caller_address(OTHER_ADMIN()); state.grant_role(ROLE, AUTHORIZED()); - assert(state.has_role(ROLE, AUTHORIZED()), 'Should have role granted'); + + let has_role = state.has_role(ROLE, AUTHORIZED()); + assert!(has_role); } #[test] @@ -376,7 +402,9 @@ fn test_new_admin_can_revoke_roles() { testing::set_caller_address(OTHER_ADMIN()); state.grant_role(ROLE, AUTHORIZED()); state.revoke_role(ROLE, AUTHORIZED()); - assert(!state.has_role(ROLE, AUTHORIZED()), 'AUTHORIZED should not have ROLE'); + + let has_not_role = !state.has_role(ROLE, AUTHORIZED()); + assert!(has_not_role); } #[test] @@ -404,16 +432,16 @@ fn test_previous_admin_cannot_revoke_roles() { #[test] fn test_other_role_admin_is_the_default_admin_role() { let state = setup(); - assert(state.get_role_admin(OTHER_ROLE) == DEFAULT_ADMIN_ROLE, 'Should be DEFAULT_ADMIN_ROLE'); + + let current_admin_role = state.get_role_admin(OTHER_ROLE); + assert_eq!(current_admin_role, DEFAULT_ADMIN_ROLE); } #[test] fn test_default_admin_role_is_its_own_admin() { let state = setup(); - assert( - state.get_role_admin(DEFAULT_ADMIN_ROLE) == DEFAULT_ADMIN_ROLE, - 'Should be DEFAULT_ADMIN_ROLE' - ); + let current_admin_role = state.get_role_admin(DEFAULT_ADMIN_ROLE); + assert_eq!(current_admin_role, DEFAULT_ADMIN_ROLE); } // @@ -422,17 +450,17 @@ fn test_default_admin_role_is_its_own_admin() { fn assert_event_role_revoked(role: felt252, account: ContractAddress, sender: ContractAddress) { let event = utils::pop_log::(ZERO()).unwrap(); - assert(event.role == role, 'Invalid `role`'); - assert(event.account == account, 'Invalid `account`'); - assert(event.sender == sender, 'Invalid `sender`'); + assert_eq!(event.role, role); + assert_eq!(event.account, account); + assert_eq!(event.sender, sender); utils::assert_no_events_left(ZERO()); } fn assert_event_role_granted(role: felt252, account: ContractAddress, sender: ContractAddress) { let event = utils::pop_log::(ZERO()).unwrap(); - assert(event.role == role, 'Invalid `role`'); - assert(event.account == account, 'Invalid `account`'); - assert(event.sender == sender, 'Invalid `sender`'); + assert_eq!(event.role, role); + assert_eq!(event.account, account); + assert_eq!(event.sender, sender); utils::assert_no_events_left(ZERO()); } @@ -440,8 +468,8 @@ fn assert_event_role_admin_changed( role: felt252, previous_admin_role: felt252, new_admin_role: felt252 ) { let event = utils::pop_log::(ZERO()).unwrap(); - assert(event.role == role, 'Invalid `role`'); - assert(event.previous_admin_role == previous_admin_role, 'Invalid `previous_admin_role`'); - assert(event.new_admin_role == new_admin_role, 'Invalid `new_admin_role`'); + assert_eq!(event.role, role); + assert_eq!(event.previous_admin_role, previous_admin_role); + assert_eq!(event.new_admin_role, new_admin_role); utils::assert_no_events_left(ZERO()); } diff --git a/src/tests/access/test_dual_accesscontrol.cairo b/src/tests/access/test_dual_accesscontrol.cairo index 2a8054cb0..a823c9f16 100644 --- a/src/tests/access/test_dual_accesscontrol.cairo +++ b/src/tests/access/test_dual_accesscontrol.cairo @@ -63,7 +63,8 @@ fn setup_accesscontrol_panic() -> (DualCaseAccessControl, DualCaseAccessControl) #[test] fn test_dual_supports_interface() { let (dispatcher, _) = setup_snake(); - assert(dispatcher.supports_interface(IACCESSCONTROL_ID), 'Should support own interface'); + let supported = dispatcher.supports_interface(IACCESSCONTROL_ID); + assert!(supported, "Should implement IACCESSCONTROL"); } #[test] @@ -83,7 +84,8 @@ fn test_dual_supports_interface_exists_and_panics() { #[test] fn test_dual_has_role() { let (dispatcher, _) = setup_snake(); - assert(dispatcher.has_role(DEFAULT_ADMIN_ROLE, ADMIN()), 'Should have role'); + let has_role = dispatcher.has_role(DEFAULT_ADMIN_ROLE, ADMIN()); + assert!(has_role); } #[test] @@ -103,7 +105,9 @@ fn test_dual_has_role_exists_and_panics() { #[test] fn test_dual_get_role_admin() { let (dispatcher, _) = setup_snake(); - assert(dispatcher.get_role_admin(ROLE) == DEFAULT_ADMIN_ROLE, 'Should get admin'); + + let current_admin_role = dispatcher.get_role_admin(ROLE); + assert_eq!(current_admin_role, DEFAULT_ADMIN_ROLE); } #[test] @@ -125,7 +129,9 @@ fn test_dual_grant_role() { let (dispatcher, target) = setup_snake(); set_contract_address(ADMIN()); dispatcher.grant_role(ROLE, AUTHORIZED()); - assert(target.has_role(ROLE, AUTHORIZED()), 'Should grant role'); + + let has_role = target.has_role(ROLE, AUTHORIZED()); + assert!(has_role); } #[test] @@ -147,7 +153,9 @@ fn test_dual_revoke_role() { let (dispatcher, target) = setup_snake(); set_contract_address(ADMIN()); dispatcher.revoke_role(ROLE, AUTHORIZED()); - assert(!target.has_role(ROLE, AUTHORIZED()), 'Should revoke role'); + + let has_not_role = !target.has_role(ROLE, AUTHORIZED()); + assert!(has_not_role); } #[test] @@ -169,7 +177,9 @@ fn test_dual_renounce_role() { let (dispatcher, target) = setup_snake(); set_contract_address(ADMIN()); dispatcher.renounce_role(DEFAULT_ADMIN_ROLE, ADMIN()); - assert(!target.has_role(DEFAULT_ADMIN_ROLE, ADMIN()), 'Should renounce role'); + + let has_not_role = !target.has_role(DEFAULT_ADMIN_ROLE, ADMIN()); + assert!(has_not_role); } #[test] @@ -193,7 +203,9 @@ fn test_dual_renounce_role_exists_and_panics() { #[test] fn test_dual_supportsInterface() { let (dispatcher, _) = setup_camel(); - assert(dispatcher.supports_interface(IACCESSCONTROL_ID), 'Should support own interface'); + + let supported = dispatcher.supports_interface(IACCESSCONTROL_ID); + assert!(supported, "Should support IACCESSCONTROL"); } #[test] @@ -206,7 +218,9 @@ fn test_dual_supportsInterface_exists_and_panics() { #[test] fn test_dual_hasRole() { let (dispatcher, _) = setup_camel(); - assert(dispatcher.has_role(DEFAULT_ADMIN_ROLE, ADMIN()), 'Should have role'); + + let has_role = dispatcher.has_role(DEFAULT_ADMIN_ROLE, ADMIN()); + assert!(has_role); } #[test] @@ -219,7 +233,9 @@ fn test_dual_hasRole_exists_and_panics() { #[test] fn test_dual_getRoleAdmin() { let (dispatcher, _) = setup_camel(); - assert(dispatcher.get_role_admin(ROLE) == DEFAULT_ADMIN_ROLE, 'Should get admin'); + + let current_admin_role = dispatcher.get_role_admin(ROLE); + assert_eq!(current_admin_role, DEFAULT_ADMIN_ROLE); } #[test] @@ -234,7 +250,9 @@ fn test_dual_grantRole() { let (dispatcher, target) = setup_camel(); set_contract_address(ADMIN()); dispatcher.grant_role(ROLE, AUTHORIZED()); - assert(target.hasRole(ROLE, AUTHORIZED()), 'Should grant role'); + + let has_role = target.hasRole(ROLE, AUTHORIZED()); + assert!(has_role); } #[test] @@ -250,7 +268,9 @@ fn test_dual_revokeRole() { set_contract_address(ADMIN()); dispatcher.grant_role(ROLE, AUTHORIZED()); dispatcher.revoke_role(ROLE, AUTHORIZED()); - assert(!target.hasRole(ROLE, AUTHORIZED()), 'Should revoke role'); + + let has_not_role = !target.hasRole(ROLE, AUTHORIZED()); + assert!(has_not_role); } #[test] @@ -265,7 +285,9 @@ fn test_dual_renounceRole() { let (dispatcher, target) = setup_camel(); set_contract_address(ADMIN()); dispatcher.renounce_role(DEFAULT_ADMIN_ROLE, ADMIN()); - assert(!target.hasRole(DEFAULT_ADMIN_ROLE, ADMIN()), 'Should renounce role'); + + let has_not_role = !target.hasRole(DEFAULT_ADMIN_ROLE, ADMIN()); + assert!(has_not_role); } #[test] diff --git a/src/tests/access/test_dual_ownable.cairo b/src/tests/access/test_dual_ownable.cairo index bacd2ce7a..3266ab197 100644 --- a/src/tests/access/test_dual_ownable.cairo +++ b/src/tests/access/test_dual_ownable.cairo @@ -8,6 +8,7 @@ use openzeppelin::tests::mocks::ownable_mocks::{ CamelOwnableMock, CamelOwnablePanicMock, SnakeOwnableMock, SnakeOwnablePanicMock }; use openzeppelin::tests::utils::constants::{OWNER, NEW_OWNER}; +use openzeppelin::tests::utils::debug::DebugContractAddress; use openzeppelin::tests::utils; use openzeppelin::utils::serde::SerializedAppend; use starknet::testing::set_contract_address; @@ -56,8 +57,11 @@ fn setup_ownable_panic() -> (DualCaseOwnable, DualCaseOwnable) { fn test_dual_owner() { let (snake_dispatcher, _) = setup_snake(); let (camel_dispatcher, _) = setup_camel(); - assert(snake_dispatcher.owner() == OWNER(), 'Should return OWNER'); - assert(camel_dispatcher.owner() == OWNER(), 'Should return OWNER'); + + let snake_owner = snake_dispatcher.owner(); + let camel_owner = camel_dispatcher.owner(); + assert_eq!(snake_owner, OWNER()); + assert_eq!(camel_owner, OWNER()); } #[test] @@ -83,7 +87,9 @@ fn test_dual_transfer_ownership() { let (dispatcher, target) = setup_snake(); set_contract_address(OWNER()); dispatcher.transfer_ownership(NEW_OWNER()); - assert(target.owner() == NEW_OWNER(), 'Should be new owner'); + + let current_owner = target.owner(); + assert_eq!(current_owner, NEW_OWNER()); } #[test] @@ -105,7 +111,9 @@ fn test_dual_renounce_ownership() { let (dispatcher, target) = setup_snake(); set_contract_address(OWNER()); dispatcher.renounce_ownership(); - assert(target.owner().is_zero(), 'Should be zero'); + + let current_owner = target.owner(); + assert!(current_owner.is_zero()); } #[test] @@ -131,7 +139,9 @@ fn test_dual_transferOwnership() { let (dispatcher, _) = setup_camel(); set_contract_address(OWNER()); dispatcher.transfer_ownership(NEW_OWNER()); - assert(dispatcher.owner() == NEW_OWNER(), 'Should be new owner'); + + let current_owner = dispatcher.owner(); + assert_eq!(current_owner, NEW_OWNER()); } #[test] @@ -146,7 +156,9 @@ fn test_dual_renounceOwnership() { let (dispatcher, _) = setup_camel(); set_contract_address(OWNER()); dispatcher.renounce_ownership(); - assert(dispatcher.owner().is_zero(), 'Should be zero'); + + let current_owner = dispatcher.owner(); + assert!(current_owner.is_zero()); } #[test] diff --git a/src/tests/access/test_ownable.cairo b/src/tests/access/test_ownable.cairo index 0a1bebf28..c7d47e063 100644 --- a/src/tests/access/test_ownable.cairo +++ b/src/tests/access/test_ownable.cairo @@ -4,6 +4,7 @@ use openzeppelin::access::ownable::OwnableComponent; use openzeppelin::access::ownable::interface::{IOwnable, IOwnableCamelOnly}; use openzeppelin::tests::mocks::ownable_mocks::DualCaseOwnableMock; use openzeppelin::tests::utils::constants::{ZERO, OTHER, OWNER}; +use openzeppelin::tests::utils::debug::DebugContractAddress; use openzeppelin::tests::utils; use starknet::ContractAddress; use starknet::storage::StorageMemberAccessTrait; @@ -33,12 +34,16 @@ fn setup() -> ComponentState { #[test] fn test_initializer_owner() { let mut state = COMPONENT_STATE(); - assert(state.Ownable_owner.read().is_zero(), 'Should be zero'); + + let current_owner = state.Ownable_owner.read(); + assert!(current_owner.is_zero()); + state.initializer(OWNER()); assert_event_ownership_transferred(ZERO(), OWNER()); - assert(state.Ownable_owner.read() == OWNER(), 'Owner should be set'); + let new_owner = state.Ownable_owner.read(); + assert_eq!(new_owner, OWNER()); } // @@ -78,7 +83,8 @@ fn test__transfer_ownership() { assert_event_ownership_transferred(OWNER(), OTHER()); - assert(state.Ownable_owner.read() == OTHER(), 'Owner should be OTHER'); + let current_owner = state.Ownable_owner.read(); + assert_eq!(current_owner, OTHER()); } // @@ -92,8 +98,7 @@ fn test_transfer_ownership() { state.transfer_ownership(OTHER()); assert_event_ownership_transferred(OWNER(), OTHER()); - - assert(state.owner() == OTHER(), 'Should transfer ownership'); + assert_eq!(state.owner(), OTHER()); } #[test] @@ -126,8 +131,7 @@ fn test_transferOwnership() { state.transferOwnership(OTHER()); assert_event_ownership_transferred(OWNER(), OTHER()); - - assert(state.owner() == OTHER(), 'Should transfer ownership'); + assert_eq!(state.owner(), OTHER()); } #[test] @@ -164,8 +168,7 @@ fn test_renounce_ownership() { state.renounce_ownership(); assert_event_ownership_transferred(OWNER(), ZERO()); - - assert(state.owner() == ZERO(), 'Should renounce ownership'); + assert!(state.owner().is_zero()); } #[test] @@ -190,8 +193,7 @@ fn test_renounceOwnership() { state.renounceOwnership(); assert_event_ownership_transferred(OWNER(), ZERO()); - - assert(state.owner() == ZERO(), 'Should renounce ownership'); + assert!(state.owner().is_zero()); } #[test] @@ -215,7 +217,7 @@ fn test_renounceOwnership_from_nonowner() { fn assert_event_ownership_transferred(previous_owner: ContractAddress, new_owner: ContractAddress) { let event = utils::pop_log::(ZERO()).unwrap(); - assert(event.previous_owner == previous_owner, 'Invalid `previous_owner`'); - assert(event.new_owner == new_owner, 'Invalid `new_owner`'); + assert_eq!(event.previous_owner, previous_owner); + assert_eq!(event.new_owner, new_owner); utils::assert_no_events_left(ZERO()); } diff --git a/src/tests/utils.cairo b/src/tests/utils.cairo index 24409ccad..028b8b24c 100644 --- a/src/tests/utils.cairo +++ b/src/tests/utils.cairo @@ -1,4 +1,5 @@ mod constants; +mod debug; use starknet::ContractAddress; use starknet::testing; diff --git a/src/tests/utils/debug.cairo b/src/tests/utils/debug.cairo new file mode 100644 index 000000000..0d71ba069 --- /dev/null +++ b/src/tests/utils/debug.cairo @@ -0,0 +1,9 @@ +use core::fmt::{Debug, Formatter, Error}; +use starknet::ContractAddress; + +impl DebugContractAddress of core::fmt::Debug { + fn fmt(self: @ContractAddress, ref f: Formatter) -> Result<(), Error> { + let address: felt252 = (*self).into(); + write!(f, "{address:?}") + } +} From c050b1f814e11680dde45a11ba2fe36cad6391e8 Mon Sep 17 00:00:00 2001 From: Eric Nordelo Date: Fri, 5 Jan 2024 12:44:20 +0100 Subject: [PATCH 05/15] refactor: account assertions --- src/tests/account/test_account.cairo | 126 ++++++++++++---------- src/tests/account/test_dual_account.cairo | 24 +++-- 2 files changed, 85 insertions(+), 65 deletions(-) diff --git a/src/tests/account/test_account.cairo b/src/tests/account/test_account.cairo index a04cf9d14..83256a939 100644 --- a/src/tests/account/test_account.cairo +++ b/src/tests/account/test_account.cairo @@ -1,3 +1,4 @@ +use core::array::ArrayTrait; use openzeppelin::account::AccountComponent::{InternalTrait, SRC6CamelOnlyImpl}; use openzeppelin::account::AccountComponent::{OwnerAdded, OwnerRemoved}; use openzeppelin::account::AccountComponent::{PublicKeyCamelImpl, PublicKeyImpl}; @@ -117,10 +118,10 @@ fn test_is_valid_signature() { state.set_public_key(data.public_key); let is_valid = state.is_valid_signature(hash, good_signature); - assert(is_valid == starknet::VALIDATED, 'Should accept valid signature'); + assert_eq!(is_valid, starknet::VALIDATED); let is_valid = state.is_valid_signature(hash, bad_signature); - assert(is_valid == 0, 'Should reject invalid signature'); + assert!(is_valid.is_zero(), "Should reject invalid signature"); } #[test] @@ -135,10 +136,10 @@ fn test_isValidSignature() { state.set_public_key(data.public_key); let is_valid = state.isValidSignature(hash, good_signature); - assert(is_valid == starknet::VALIDATED, 'Should accept valid signature'); + assert_eq!(is_valid, starknet::VALIDATED); let is_valid = state.isValidSignature(hash, bad_signature); - assert(is_valid == 0, 'Should reject invalid signature'); + assert!(is_valid.is_zero(), "Should reject invalid signature"); } // @@ -152,10 +153,8 @@ fn test_validate_deploy() { // `__validate_deploy__` does not directly use the passed arguments. Their // values are already integrated in the tx hash. The passed arguments in this // testing context are decoupled from the signature and have no effect on the test. - assert( - account.__validate_deploy__(CLASS_HASH(), SALT, PUBKEY) == starknet::VALIDATED, - 'Should validate correctly' - ); + let is_valid = account.__validate_deploy__(CLASS_HASH(), SALT, PUBKEY); + assert_eq!(is_valid, starknet::VALIDATED); } #[test] @@ -197,10 +196,8 @@ fn test_validate_declare() { // `__validate_declare__` does not directly use the class_hash argument. Its // value is already integrated in the tx hash. The class_hash argument in this // testing context is decoupled from the signature and has no effect on the test. - assert( - account.__validate_declare__(CLASS_HASH()) == starknet::VALIDATED, - 'Should validate correctly' - ); + let is_valid = account.__validate_declare__(CLASS_HASH()); + assert_eq!(is_valid, starknet::VALIDATED); } #[test] @@ -262,13 +259,13 @@ fn test_execute_with_version(version: Option) { let ret = account.__execute__(calls); // Assert that the transfer was successful - assert(erc20.balance_of(account.contract_address) == 800, 'Should have remainder'); - assert(erc20.balance_of(recipient) == amount, 'Should have transferred'); + assert_eq!(erc20.balance_of(account.contract_address), 800, "Should have remainder"); + assert_eq!(erc20.balance_of(recipient), amount, "Should have transferred"); // Test return value let mut call_serialized_retval = *ret.at(0); let call_retval = Serde::::deserialize(ref call_serialized_retval); - assert(call_retval.unwrap(), 'Should have succeeded'); + assert!(call_retval.unwrap()); } #[test] @@ -292,7 +289,8 @@ fn test_validate() { let calls = array![]; let account = setup_dispatcher(Option::Some(@SIGNED_TX_DATA())); - assert(account.__validate__(calls) == starknet::VALIDATED, 'Should validate correctly'); + let is_valid = account.__validate__(calls); + assert_eq!(is_valid, starknet::VALIDATED); } #[test] @@ -338,17 +336,17 @@ fn test_multicall() { let ret = account.__execute__(calls); // Assert that the transfers were successful - assert(erc20.balance_of(account.contract_address) == 200, 'Should have remainder'); - assert(erc20.balance_of(recipient1) == 300, 'Should have transferred'); - assert(erc20.balance_of(recipient2) == 500, 'Should have transferred'); + assert_eq!(erc20.balance_of(account.contract_address), 200, "Should have remainder"); + assert_eq!(erc20.balance_of(recipient1), 300, "Should have transferred from call1"); + assert_eq!(erc20.balance_of(recipient2), 500, "Should have transferred from call2"); - // Test return value + // Test return values let mut call1_serialized_retval = *ret.at(0); let mut call2_serialized_retval = *ret.at(1); let call1_retval = Serde::::deserialize(ref call1_serialized_retval); let call2_retval = Serde::::deserialize(ref call2_serialized_retval); - assert(call1_retval.unwrap(), 'Should have succeeded'); - assert(call2_retval.unwrap(), 'Should have succeeded'); + assert!(call1_retval.unwrap()); + assert!(call2_retval.unwrap()); } #[test] @@ -356,10 +354,8 @@ fn test_multicall_zero_calls() { let account = setup_dispatcher(Option::Some(@SIGNED_TX_DATA())); let mut calls = array![]; - let ret = account.__execute__(calls); - - // Test return value - assert(ret.len() == 0, 'Should have an empty response'); + let response = account.__execute__(calls); + assert!(response.is_empty()); } #[test] @@ -387,20 +383,16 @@ fn test_public_key_setter_and_getter() { // Check default let public_key = state.get_public_key(); - assert(public_key == 0, 'Should be zero'); + assert!(public_key.is_zero()); // Set key state.set_public_key(NEW_PUBKEY); - let event = utils::pop_log::(ACCOUNT_ADDRESS()).unwrap(); - assert(event.removed_owner_guid == 0, 'Invalid old owner key'); - - let event = utils::pop_log::(ACCOUNT_ADDRESS()).unwrap(); - assert(event.new_owner_guid == NEW_PUBKEY, 'Invalid new owner key'); - utils::assert_no_events_left(ACCOUNT_ADDRESS()); + assert_event_owner_removed(ACCOUNT_ADDRESS(), 0); + assert_only_event_owner_added(ACCOUNT_ADDRESS(), NEW_PUBKEY); let public_key = state.get_public_key(); - assert(public_key == NEW_PUBKEY, 'Should update key'); + assert_eq!(public_key, NEW_PUBKEY); } #[test] @@ -426,20 +418,16 @@ fn test_public_key_setter_and_getter_camel() { // Check default let public_key = state.getPublicKey(); - assert(public_key == 0, 'Should be zero'); + assert!(public_key.is_zero()); // Set key state.setPublicKey(NEW_PUBKEY); - let event = utils::pop_log::(ACCOUNT_ADDRESS()).unwrap(); - assert(event.removed_owner_guid == 0, 'Invalid old owner key'); - - let event = utils::pop_log::(ACCOUNT_ADDRESS()).unwrap(); - assert(event.new_owner_guid == NEW_PUBKEY, 'Invalid new owner key'); - utils::assert_no_events_left(ACCOUNT_ADDRESS()); + assert_event_owner_removed(ACCOUNT_ADDRESS(), 0); + assert_only_event_owner_added(ACCOUNT_ADDRESS(), NEW_PUBKEY); let public_key = state.getPublicKey(); - assert(public_key == NEW_PUBKEY, 'Should update key'); + assert_eq!(public_key, NEW_PUBKEY); } #[test] @@ -463,17 +451,16 @@ fn test_initializer() { let mock_state = CONTRACT_STATE(); state.initializer(PUBKEY); - let event = utils::pop_log::(ZERO()).unwrap(); - assert(event.new_owner_guid == PUBKEY, 'Invalid owner key'); - utils::assert_no_events_left(ZERO()); + assert_only_event_owner_added(ZERO(), PUBKEY); - assert(state.get_public_key() == PUBKEY, 'Should return PUBKEY'); + let public_key = state.get_public_key(); + assert_eq!(public_key, PUBKEY); let supports_default_interface = mock_state.supports_interface(ISRC5_ID); - assert(supports_default_interface, 'Should support base interface'); + assert!(supports_default_interface, "Should implement ISRC5"); let supports_account_interface = mock_state.supports_interface(ISRC6_ID); - assert(supports_account_interface, 'Should support account id'); + assert!(supports_account_interface, "Should implement ISRC6"); } #[test] @@ -509,13 +496,13 @@ fn test__is_valid_signature() { state.set_public_key(data.public_key); let is_valid = state._is_valid_signature(hash, good_signature.span()); - assert(is_valid, 'Should accept valid signature'); + assert!(is_valid); - let is_valid = state._is_valid_signature(hash, bad_signature.span()); - assert(!is_valid, 'Should reject invalid signature'); + let is_not_valid = state._is_valid_signature(hash, bad_signature.span()); + assert!(is_not_valid); - let is_valid = state._is_valid_signature(hash, invalid_length_signature.span()); - assert(!is_valid, 'Should reject invalid length'); + let is_not_valid = state._is_valid_signature(hash, invalid_length_signature.span()); + assert!(is_not_valid); } #[test] @@ -523,10 +510,35 @@ fn test__set_public_key() { let mut state = COMPONENT_STATE(); state._set_public_key(PUBKEY); - let event = utils::pop_log::(ZERO()).unwrap(); - assert(event.new_owner_guid == PUBKEY, 'Invalid owner key'); - utils::assert_no_events_left(ZERO()); + assert_only_event_owner_added(ZERO(), PUBKEY); let public_key = state.get_public_key(); - assert(public_key == PUBKEY, 'Should update key'); + assert_eq!(public_key, PUBKEY); +} + +// +// Helpers +// + +fn assert_event_owner_removed(contract: ContractAddress, removed_owner_guid: felt252) { + let event = utils::pop_log::(contract).unwrap(); + assert_eq!(event.removed_owner_guid, removed_owner_guid); + + // Check indexed keys + let indexed_keys = array![removed_owner_guid]; + utils::assert_indexed_keys(event, indexed_keys.span()); +} + +fn assert_event_owner_added(contract: ContractAddress, new_owner_guid: felt252) { + let event = utils::pop_log::(contract).unwrap(); + assert_eq!(event.new_owner_guid, new_owner_guid); + + // Check indexed keys + let indexed_keys = array![new_owner_guid]; + utils::assert_indexed_keys(event, indexed_keys.span()); +} + +fn assert_only_event_owner_added(contract: ContractAddress, new_owner_guid: felt252) { + assert_event_owner_added(contract, new_owner_guid); + utils::assert_no_events_left(contract); } diff --git a/src/tests/account/test_dual_account.cairo b/src/tests/account/test_dual_account.cairo index 50336091d..42152fe02 100644 --- a/src/tests/account/test_dual_account.cairo +++ b/src/tests/account/test_dual_account.cairo @@ -58,7 +58,9 @@ fn test_dual_set_public_key() { testing::set_contract_address(snake_dispatcher.contract_address); snake_dispatcher.set_public_key(NEW_PUBKEY); - assert(target.get_public_key() == NEW_PUBKEY, 'Should return NEW_PUBKEY'); + + let public_key = target.get_public_key(); + assert_eq!(public_key, NEW_PUBKEY); } #[test] @@ -78,7 +80,8 @@ fn test_dual_set_public_key_exists_and_panics() { #[test] fn test_dual_get_public_key() { let (snake_dispatcher, _) = setup_snake(); - assert(snake_dispatcher.get_public_key() == PUBKEY, 'Should return PUBKEY'); + let public_key = snake_dispatcher.get_public_key(); + assert_eq!(public_key, PUBKEY); } #[test] @@ -107,7 +110,7 @@ fn test_dual_is_valid_signature() { target.set_public_key(data.public_key); let is_valid = snake_dispatcher.is_valid_signature(hash, signature); - assert(is_valid == 'VALID', 'Should accept valid signature'); + assert_eq!(is_valid, starknet::VALIDATED); } #[test] @@ -133,7 +136,8 @@ fn test_dual_is_valid_signature_exists_and_panics() { #[test] fn test_dual_supports_interface() { let (snake_dispatcher, target) = setup_snake(); - assert(snake_dispatcher.supports_interface(ISRC5_ID), 'Should implement ISRC5'); + let supported = snake_dispatcher.supports_interface(ISRC5_ID); + assert!(supported, "Should implement ISRC5"); } #[test] @@ -161,7 +165,9 @@ fn test_dual_setPublicKey() { testing::set_contract_address(camel_dispatcher.contract_address); camel_dispatcher.set_public_key(NEW_PUBKEY); - assert(target.getPublicKey() == NEW_PUBKEY, 'Should return NEW_PUBKEY'); + + let public_key = target.getPublicKey(); + assert_eq!(public_key, NEW_PUBKEY); } #[test] @@ -174,7 +180,8 @@ fn test_dual_setPublicKey_exists_and_panics() { #[test] fn test_dual_getPublicKey() { let (camel_dispatcher, _) = setup_camel(); - assert(camel_dispatcher.get_public_key() == PUBKEY, 'Should return PUBKEY'); + let public_key = camel_dispatcher.get_public_key(); + assert_eq!(public_key, PUBKEY); } #[test] @@ -196,7 +203,7 @@ fn test_dual_isValidSignature() { target.setPublicKey(data.public_key); let is_valid = camel_dispatcher.is_valid_signature(hash, signature); - assert(is_valid == 'VALID', 'Should accept valid signature'); + assert_eq!(is_valid, starknet::VALIDATED); } #[test] @@ -212,7 +219,8 @@ fn test_dual_isValidSignature_exists_and_panics() { #[test] fn test_dual_supportsInterface() { let (camel_dispatcher, _) = setup_camel(); - assert(camel_dispatcher.supports_interface(ISRC5_ID), 'Should implement ISRC5'); + let supported = camel_dispatcher.supports_interface(ISRC5_ID); + assert!(supported, "Should implement ISRC5"); } #[test] From a36a84498af2fc821845fb21497e17f3f48367d6 Mon Sep 17 00:00:00 2001 From: Eric Nordelo Date: Fri, 5 Jan 2024 12:46:57 +0100 Subject: [PATCH 06/15] refactor: src5 test assertions --- src/tests/introspection/test_dual_src5.cairo | 6 ++++-- src/tests/introspection/test_src5.cairo | 12 ++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/tests/introspection/test_dual_src5.cairo b/src/tests/introspection/test_dual_src5.cairo index 2f1d300fa..c3e233f1b 100644 --- a/src/tests/introspection/test_dual_src5.cairo +++ b/src/tests/introspection/test_dual_src5.cairo @@ -46,7 +46,8 @@ fn setup_src5_panic() -> (DualCaseSRC5, DualCaseSRC5) { #[test] fn test_dual_supports_interface() { let dispatcher = setup_snake(); - assert(dispatcher.supports_interface(ISRC5_ID), 'Should support base interface'); + let supported = dispatcher.supports_interface(ISRC5_ID); + assert!(supported, "Should implement ISRC5"); } #[test] @@ -70,7 +71,8 @@ fn test_dual_supports_interface_exists_and_panics() { #[test] fn test_dual_supportsInterface() { let dispatcher = setup_camel(); - assert(dispatcher.supports_interface(ISRC5_ID), 'Should support base interface'); + let supported = dispatcher.supports_interface(ISRC5_ID); + assert!(supported, "Should implement ISRC5"); } #[test] diff --git a/src/tests/introspection/test_src5.cairo b/src/tests/introspection/test_src5.cairo index 001b7b5a7..f95a1954c 100644 --- a/src/tests/introspection/test_src5.cairo +++ b/src/tests/introspection/test_src5.cairo @@ -15,14 +15,14 @@ fn COMPONENT_STATE() -> ComponentState { fn test_default_behavior() { let state = COMPONENT_STATE(); let supports_default_interface = state.supports_interface(ISRC5_ID); - assert(supports_default_interface, 'Should support base interface'); + assert!(supports_default_interface, "Should implement ISRC5"); } #[test] fn test_not_registered_interface() { let state = COMPONENT_STATE(); - let supports_unregistered_interface = state.supports_interface(OTHER_ID); - assert(!supports_unregistered_interface, 'Should not support unregistered'); + let does_not_support_unregistered_interface = state.supports_interface(OTHER_ID); + assert!(does_not_support_unregistered_interface); } #[test] @@ -30,7 +30,7 @@ fn test_register_interface() { let mut state = COMPONENT_STATE(); state.register_interface(OTHER_ID); let supports_new_interface = state.supports_interface(OTHER_ID); - assert(supports_new_interface, 'Should support new interface'); + assert!(supports_new_interface); } #[test] @@ -38,8 +38,8 @@ fn test_deregister_interface() { let mut state = COMPONENT_STATE(); state.register_interface(OTHER_ID); state.deregister_interface(OTHER_ID); - let supports_old_interface = state.supports_interface(OTHER_ID); - assert(!supports_old_interface, 'Should not support interface'); + let does_not_support_old_interface = state.supports_interface(OTHER_ID); + assert!(does_not_support_old_interface); } #[test] From 1ecb8a0cf148a730beb5608e324645c857573cd0 Mon Sep 17 00:00:00 2001 From: Eric Nordelo Date: Fri, 5 Jan 2024 13:27:47 +0100 Subject: [PATCH 07/15] refactor: presets and security tests assertions --- src/tests/account/test_account.cairo | 10 +- src/tests/introspection/test_src5.cairo | 4 +- src/tests/presets/test_account.cairo | 72 ++++++------ src/tests/presets/test_erc20.cairo | 107 ++++++++++-------- src/tests/presets/test_erc721.cairo | 88 ++++++++------ src/tests/security/test_initializable.cairo | 4 +- src/tests/security/test_pausable.cairo | 17 +-- src/tests/security/test_reentrancyguard.cairo | 19 +++- 8 files changed, 178 insertions(+), 143 deletions(-) diff --git a/src/tests/account/test_account.cairo b/src/tests/account/test_account.cairo index 83256a939..0c44ca2b4 100644 --- a/src/tests/account/test_account.cairo +++ b/src/tests/account/test_account.cairo @@ -501,7 +501,7 @@ fn test__is_valid_signature() { let is_not_valid = state._is_valid_signature(hash, bad_signature.span()); assert!(is_not_valid); - let is_not_valid = state._is_valid_signature(hash, invalid_length_signature.span()); + let is_not_valid = !state._is_valid_signature(hash, invalid_length_signature.span()); assert!(is_not_valid); } @@ -523,19 +523,11 @@ fn test__set_public_key() { fn assert_event_owner_removed(contract: ContractAddress, removed_owner_guid: felt252) { let event = utils::pop_log::(contract).unwrap(); assert_eq!(event.removed_owner_guid, removed_owner_guid); - - // Check indexed keys - let indexed_keys = array![removed_owner_guid]; - utils::assert_indexed_keys(event, indexed_keys.span()); } fn assert_event_owner_added(contract: ContractAddress, new_owner_guid: felt252) { let event = utils::pop_log::(contract).unwrap(); assert_eq!(event.new_owner_guid, new_owner_guid); - - // Check indexed keys - let indexed_keys = array![new_owner_guid]; - utils::assert_indexed_keys(event, indexed_keys.span()); } fn assert_only_event_owner_added(contract: ContractAddress, new_owner_guid: felt252) { diff --git a/src/tests/introspection/test_src5.cairo b/src/tests/introspection/test_src5.cairo index f95a1954c..7dd681033 100644 --- a/src/tests/introspection/test_src5.cairo +++ b/src/tests/introspection/test_src5.cairo @@ -21,7 +21,7 @@ fn test_default_behavior() { #[test] fn test_not_registered_interface() { let state = COMPONENT_STATE(); - let does_not_support_unregistered_interface = state.supports_interface(OTHER_ID); + let does_not_support_unregistered_interface = !state.supports_interface(OTHER_ID); assert!(does_not_support_unregistered_interface); } @@ -38,7 +38,7 @@ fn test_deregister_interface() { let mut state = COMPONENT_STATE(); state.register_interface(OTHER_ID); state.deregister_interface(OTHER_ID); - let does_not_support_old_interface = state.supports_interface(OTHER_ID); + let does_not_support_old_interface = !state.supports_interface(OTHER_ID); assert!(does_not_support_old_interface); } diff --git a/src/tests/presets/test_account.cairo b/src/tests/presets/test_account.cairo index 7a396c8e0..b4f8937e8 100644 --- a/src/tests/presets/test_account.cairo +++ b/src/tests/presets/test_account.cairo @@ -1,3 +1,4 @@ +use core::array::ArrayTrait; use openzeppelin::account::AccountComponent::{OwnerAdded, OwnerRemoved}; use openzeppelin::account::AccountComponent::{TRANSACTION_VERSION, QUERY_VERSION}; use openzeppelin::account::interface::ISRC6_ID; @@ -61,9 +62,13 @@ fn test_constructor() { assert_only_event_owner_added(PUBKEY, ZERO()); - assert(Account::PublicKeyImpl::get_public_key(@state) == PUBKEY, 'Should return PUBKEY'); - assert(Account::SRC5Impl::supports_interface(@state, ISRC5_ID), 'Should implement ISRC5'); - assert(Account::SRC5Impl::supports_interface(@state, ISRC6_ID), 'Should implement ISRC6'); + let public_key = Account::PublicKeyImpl::get_public_key(@state); + assert_eq!(public_key, PUBKEY); + + let supports_isrc5 = Account::SRC5Impl::supports_interface(@state, ISRC5_ID); + let supports_isrc6 = Account::SRC5Impl::supports_interface(@state, ISRC6_ID); + assert!(supports_isrc5, "Should implement ISRC5"); + assert!(supports_isrc6, "Should implement ISRC6"); } // @@ -77,7 +82,8 @@ fn test_public_key_setter_and_getter() { testing::set_contract_address(dispatcher.contract_address); dispatcher.set_public_key(NEW_PUBKEY); - assert(dispatcher.get_public_key() == NEW_PUBKEY, 'Should return NEW_PUBKEY'); + let public_key = dispatcher.get_public_key(); + assert_eq!(public_key, NEW_PUBKEY); assert_event_owner_removed(PUBKEY, dispatcher.contract_address); assert_only_event_owner_added(NEW_PUBKEY, dispatcher.contract_address); @@ -90,7 +96,8 @@ fn test_public_key_setter_and_getter_camel() { testing::set_contract_address(dispatcher.contract_address); dispatcher.setPublicKey(NEW_PUBKEY); - assert(dispatcher.getPublicKey() == NEW_PUBKEY, 'Should return NEW_PUBKEY'); + let public_key = dispatcher.getPublicKey(); + assert_eq!(public_key, NEW_PUBKEY); assert_event_owner_removed(PUBKEY, dispatcher.contract_address); assert_only_event_owner_added(NEW_PUBKEY, dispatcher.contract_address); @@ -132,7 +139,7 @@ fn test_is_valid_signature() { let (dispatcher, hash, signature) = is_valid_sig_dispatcher(); let is_valid = dispatcher.is_valid_signature(hash, signature); - assert(is_valid == starknet::VALIDATED, 'Should accept valid signature'); + assert_eq!(is_valid, starknet::VALIDATED); } #[test] @@ -142,7 +149,7 @@ fn test_is_valid_signature_bad_sig() { let bad_signature = array![0x987, 0x564]; let is_valid = dispatcher.is_valid_signature(hash, bad_signature.clone()); - assert(is_valid == 0, 'Should reject invalid signature'); + assert!(is_valid.is_zero(), "Should reject invalid signature"); } #[test] @@ -150,7 +157,7 @@ fn test_isValidSignature() { let (dispatcher, hash, signature) = is_valid_sig_dispatcher(); let is_valid = dispatcher.isValidSignature(hash, signature); - assert(is_valid == starknet::VALIDATED, 'Should accept valid signature'); + assert_eq!(is_valid, starknet::VALIDATED); } #[test] @@ -160,7 +167,7 @@ fn test_isValidSignature_bad_sig() { let bad_signature = array![0x987, 0x564]; let is_valid = dispatcher.isValidSignature(hash, bad_signature); - assert(is_valid == 0, 'Should reject invalid signature'); + assert!(is_valid.is_zero(), "Should reject invalid signature"); } // @@ -170,9 +177,9 @@ fn test_isValidSignature_bad_sig() { #[test] fn test_supports_interface() { let dispatcher = setup_dispatcher(); - assert(dispatcher.supports_interface(ISRC5_ID), 'Should implement ISRC5'); - assert(dispatcher.supports_interface(ISRC6_ID), 'Should implement ISRC6'); - assert(!dispatcher.supports_interface(0x123), 'Should not implement 0x123'); + assert!(dispatcher.supports_interface(ISRC5_ID), "Should implement ISRC5"); + assert!(dispatcher.supports_interface(ISRC6_ID), "Should implement ISRC6"); + assert!(!dispatcher.supports_interface(0x123), "Should not implement 0x123"); } // @@ -186,10 +193,8 @@ fn test_validate_deploy() { // `__validate_deploy__` does not directly use the passed arguments. Their // values are already integrated in the tx hash. The passed arguments in this // testing context are decoupled from the signature and have no effect on the test. - assert( - account.__validate_deploy__(CLASS_HASH(), SALT, PUBKEY) == starknet::VALIDATED, - 'Should validate correctly' - ); + let is_valid = account.__validate_deploy__(CLASS_HASH(), SALT, PUBKEY); + assert_eq!(is_valid, starknet::VALIDATED); } #[test] @@ -230,10 +235,8 @@ fn test_validate_declare() { // `__validate_declare__` does not directly use the class_hash argument. Its // value is already integrated in the tx hash. The class_hash argument in this // testing context is decoupled from the signature and has no effect on the test. - assert( - account.__validate_declare__(CLASS_HASH()) == starknet::VALIDATED, - 'Should validate correctly' - ); + let is_valid = account.__validate_declare__(CLASS_HASH()); + assert_eq!(is_valid, starknet::VALIDATED); } #[test] @@ -295,13 +298,13 @@ fn test_execute_with_version(version: Option) { let ret = account.__execute__(calls); // Assert that the transfer was successful - assert(erc20.balance_of(account.contract_address) == 800, 'Should have remainder'); - assert(erc20.balance_of(RECIPIENT()) == amount, 'Should have transferred'); + assert_eq!(erc20.balance_of(account.contract_address), 800, "Should have remainder"); + assert_eq!(erc20.balance_of(RECIPIENT()), amount, "Should have transferred"); // Test return value let mut call_serialized_retval = *ret.at(0); let call_retval = Serde::::deserialize(ref call_serialized_retval); - assert(call_retval.unwrap(), 'Should have succeeded'); + assert!(call_retval.unwrap()); } #[test] @@ -325,7 +328,8 @@ fn test_validate() { let calls = array![]; let account = setup_dispatcher_with_data(Option::Some(@SIGNED_TX_DATA())); - assert(account.__validate__(calls) == starknet::VALIDATED, 'Should validate correctly'); + let is_valid = account.__validate__(calls); + assert_eq!(is_valid, starknet::VALIDATED); } #[test] @@ -371,17 +375,17 @@ fn test_multicall() { let ret = account.__execute__(calls); // Assert that the transfers were successful - assert(erc20.balance_of(account.contract_address) == 200, 'Should have remainder'); - assert(erc20.balance_of(recipient1) == 300, 'Should have transferred'); - assert(erc20.balance_of(recipient2) == 500, 'Should have transferred'); + assert_eq!(erc20.balance_of(account.contract_address), 200, "Should have remainder"); + assert_eq!(erc20.balance_of(recipient1), 300, "Should have transferred"); + assert_eq!(erc20.balance_of(recipient2), 500, "Should have transferred"); // Test return value let mut call1_serialized_retval = *ret.at(0); let mut call2_serialized_retval = *ret.at(1); let call1_retval = Serde::::deserialize(ref call1_serialized_retval); let call2_retval = Serde::::deserialize(ref call2_serialized_retval); - assert(call1_retval.unwrap(), 'Should have succeeded'); - assert(call2_retval.unwrap(), 'Should have succeeded'); + assert!(call1_retval.unwrap()); + assert!(call2_retval.unwrap()); } #[test] @@ -389,10 +393,8 @@ fn test_multicall_zero_calls() { let account = setup_dispatcher_with_data(Option::Some(@SIGNED_TX_DATA())); let mut calls = array![]; - let ret = account.__execute__(calls); - - // Test return value - assert(ret.len() == 0, 'Should have an empty response'); + let response = account.__execute__(calls); + assert!(response.is_empty()); } #[test] @@ -414,12 +416,12 @@ fn test_account_called_from_contract() { fn assert_event_owner_removed(removed_owner_guid: felt252, contract: ContractAddress) { let event = utils::pop_log::(contract).unwrap(); - assert(event.removed_owner_guid == removed_owner_guid, 'Invalid `removed_owner_guid`'); + assert_eq!(event.removed_owner_guid, removed_owner_guid); } fn assert_event_owner_added(new_owner_guid: felt252, contract: ContractAddress) { let event = utils::pop_log::(contract).unwrap(); - assert(event.new_owner_guid == new_owner_guid, 'Invalid `new_owner_guid`'); + assert_eq!(event.new_owner_guid, new_owner_guid); } fn assert_only_event_owner_added(new_owner_guid: felt252, contract: ContractAddress) { diff --git a/src/tests/presets/test_erc20.cairo b/src/tests/presets/test_erc20.cairo index 566e52e93..86b4ab4c9 100644 --- a/src/tests/presets/test_erc20.cairo +++ b/src/tests/presets/test_erc20.cairo @@ -3,6 +3,7 @@ use openzeppelin::presets::ERC20; use openzeppelin::tests::utils::constants::{ ZERO, OWNER, SPENDER, RECIPIENT, NAME, SYMBOL, DECIMALS, SUPPLY, VALUE }; +use openzeppelin::tests::utils::debug::DebugContractAddress; use openzeppelin::tests::utils; use openzeppelin::token::erc20::ERC20Component::{Approval, Transfer}; use openzeppelin::token::erc20::ERC20Component::{ERC20CamelOnlyImpl, ERC20Impl}; @@ -44,11 +45,11 @@ fn setup_dispatcher() -> ERC20ABIDispatcher { fn test_constructor() { let mut dispatcher = setup_dispatcher_with_event(); - assert(dispatcher.name() == NAME, 'Should be NAME'); - assert(dispatcher.symbol() == SYMBOL, 'Should be SYMBOL'); - assert(dispatcher.decimals() == DECIMALS, 'Should be DECIMALS'); - assert(dispatcher.total_supply() == SUPPLY, 'Should equal SUPPLY'); - assert(dispatcher.balance_of(OWNER()) == SUPPLY, 'Should equal SUPPLY'); + assert_eq!(dispatcher.name(), NAME); + assert_eq!(dispatcher.symbol(), SYMBOL); + assert_eq!(dispatcher.decimals(), DECIMALS); + assert_eq!(dispatcher.total_supply(), SUPPLY); + assert_eq!(dispatcher.balance_of(OWNER()), SUPPLY); assert_only_event_transfer(dispatcher.contract_address, ZERO(), OWNER(), SUPPLY); } @@ -60,16 +61,16 @@ fn test_constructor() { fn test_total_supply() { let mut dispatcher = setup_dispatcher(); - assert(dispatcher.total_supply() == SUPPLY, 'Should equal SUPPLY'); - assert(dispatcher.totalSupply() == SUPPLY, 'Should equal SUPPLY'); + assert_eq!(dispatcher.total_supply(), SUPPLY); + assert_eq!(dispatcher.totalSupply(), SUPPLY); } #[test] fn test_balance_of() { let mut dispatcher = setup_dispatcher(); - assert(dispatcher.balance_of(OWNER()) == SUPPLY, 'Should equal SUPPLY'); - assert(dispatcher.balanceOf(OWNER()) == SUPPLY, 'Should equal SUPPLY'); + assert_eq!(dispatcher.balance_of(OWNER()), SUPPLY); + assert_eq!(dispatcher.balanceOf(OWNER()), SUPPLY); } #[test] @@ -78,7 +79,9 @@ fn test_allowance() { testing::set_contract_address(OWNER()); dispatcher.approve(SPENDER(), VALUE); - assert(dispatcher.allowance(OWNER(), SPENDER()) == VALUE, 'Should equal VALUE'); + + let allowance = dispatcher.allowance(OWNER(), SPENDER()); + assert_eq!(allowance, VALUE); } // @@ -88,12 +91,15 @@ fn test_allowance() { #[test] fn test_approve() { let mut dispatcher = setup_dispatcher(); - assert(dispatcher.allowance(OWNER(), SPENDER()) == 0, 'Should equal ZERO'); + let allowance = dispatcher.allowance(OWNER(), SPENDER()); + assert!(allowance.is_zero()); testing::set_contract_address(OWNER()); - assert(dispatcher.approve(SPENDER(), VALUE), 'Should return true'); + assert!(dispatcher.approve(SPENDER(), VALUE)); + + let allowance = dispatcher.allowance(OWNER(), SPENDER()); + assert_eq!(allowance, VALUE); - assert(dispatcher.allowance(OWNER(), SPENDER()) == VALUE, 'Should equal VALUE'); assert_only_event_approval(dispatcher.contract_address, OWNER(), SPENDER(), VALUE); } @@ -121,11 +127,12 @@ fn test_transfer() { let mut dispatcher = setup_dispatcher(); testing::set_contract_address(OWNER()); - assert(dispatcher.transfer(RECIPIENT(), VALUE), 'Should return true'); + assert!(dispatcher.transfer(RECIPIENT(), VALUE)); + + assert_eq!(dispatcher.balance_of(OWNER()), SUPPLY - VALUE); + assert_eq!(dispatcher.balance_of(RECIPIENT()), VALUE); + assert_eq!(dispatcher.total_supply(), SUPPLY); - assert(dispatcher.balance_of(OWNER()) == SUPPLY - VALUE, 'Should equal SUPPLY - VALUE'); - assert(dispatcher.balance_of(RECIPIENT()) == VALUE, 'Should equal VALUE'); - assert(dispatcher.total_supply() == SUPPLY, 'Should equal SUPPLY'); assert_only_event_transfer(dispatcher.contract_address, OWNER(), RECIPIENT(), VALUE); } @@ -167,15 +174,15 @@ fn test_transfer_from() { utils::drop_event(dispatcher.contract_address); testing::set_contract_address(SPENDER()); - assert(dispatcher.transfer_from(OWNER(), RECIPIENT(), VALUE), 'Should return true'); + assert!(dispatcher.transfer_from(OWNER(), RECIPIENT(), VALUE)); assert_event_approval(dispatcher.contract_address, OWNER(), SPENDER(), 0); assert_only_event_transfer(dispatcher.contract_address, OWNER(), RECIPIENT(), VALUE); - assert(dispatcher.balance_of(RECIPIENT()) == VALUE, 'Should equal amount'); - assert(dispatcher.balance_of(OWNER()) == SUPPLY - VALUE, 'Should equal supply - amount'); - assert(dispatcher.allowance(OWNER(), SPENDER()) == 0, 'Should equal 0'); - assert(dispatcher.total_supply() == SUPPLY, 'Total supply should not change'); + assert_eq!(dispatcher.balance_of(RECIPIENT()), VALUE); + assert_eq!(dispatcher.balance_of(OWNER()), SUPPLY - VALUE); + assert_eq!(dispatcher.allowance(OWNER(), SPENDER()), 0); + assert_eq!(dispatcher.total_supply(), SUPPLY); } #[test] @@ -188,9 +195,8 @@ fn test_transfer_from_doesnt_consume_infinite_allowance() { testing::set_contract_address(SPENDER()); dispatcher.transfer_from(OWNER(), RECIPIENT(), VALUE); - assert( - dispatcher.allowance(OWNER(), SPENDER()) == BoundedInt::max(), 'Allowance should not change' - ); + let allowance = dispatcher.allowance(OWNER(), SPENDER()); + assert_eq!(allowance, BoundedInt::max(), "Should not decrease"); } #[test] @@ -232,15 +238,15 @@ fn test_transferFrom() { utils::drop_event(dispatcher.contract_address); testing::set_contract_address(SPENDER()); - assert(dispatcher.transferFrom(OWNER(), RECIPIENT(), VALUE), 'Should return true'); + assert!(dispatcher.transferFrom(OWNER(), RECIPIENT(), VALUE)); assert_event_approval(dispatcher.contract_address, OWNER(), SPENDER(), 0); assert_only_event_transfer(dispatcher.contract_address, OWNER(), RECIPIENT(), VALUE); - assert(dispatcher.balance_of(RECIPIENT()) == VALUE, 'Should equal amount'); - assert(dispatcher.balance_of(OWNER()) == SUPPLY - VALUE, 'Should equal supply - amount'); - assert(dispatcher.allowance(OWNER(), SPENDER()) == 0, 'Should equal 0'); - assert(dispatcher.total_supply() == SUPPLY, 'Total supply should not change'); + assert_eq!(dispatcher.balance_of(RECIPIENT()), VALUE); + assert_eq!(dispatcher.balance_of(OWNER()), SUPPLY - VALUE); + assert_eq!(dispatcher.allowance(OWNER(), SPENDER()), 0); + assert_eq!(dispatcher.total_supply(), SUPPLY); } #[test] @@ -252,9 +258,8 @@ fn test_transferFrom_doesnt_consume_infinite_allowance() { testing::set_contract_address(SPENDER()); dispatcher.transferFrom(OWNER(), RECIPIENT(), VALUE); - assert( - dispatcher.allowance(OWNER(), SPENDER()) == BoundedInt::max(), 'Allowance should not change' - ); + let allowance = dispatcher.allowance(OWNER(), SPENDER()); + assert_eq!(allowance, BoundedInt::max(), "Should not decrease"); } #[test] @@ -298,10 +303,12 @@ fn test_increase_allowance() { dispatcher.approve(SPENDER(), VALUE); utils::drop_event(dispatcher.contract_address); - assert(dispatcher.increase_allowance(SPENDER(), VALUE), 'Should return true'); + assert!(dispatcher.increase_allowance(SPENDER(), VALUE)); assert_only_event_approval(dispatcher.contract_address, OWNER(), SPENDER(), VALUE * 2); - assert(dispatcher.allowance(OWNER(), SPENDER()) == VALUE * 2, 'Should be amount * 2'); + + let allowance = dispatcher.allowance(OWNER(), SPENDER()); + assert_eq!(allowance, VALUE * 2); } #[test] @@ -326,10 +333,12 @@ fn test_increaseAllowance() { dispatcher.approve(SPENDER(), VALUE); utils::drop_event(dispatcher.contract_address); - assert(dispatcher.increaseAllowance(SPENDER(), VALUE), 'Should return true'); + assert!(dispatcher.increaseAllowance(SPENDER(), VALUE)); assert_only_event_approval(dispatcher.contract_address, OWNER(), SPENDER(), 2 * VALUE); - assert(dispatcher.allowance(OWNER(), SPENDER()) == VALUE * 2, 'Should be amount * 2'); + + let allowance = dispatcher.allowance(OWNER(), SPENDER()); + assert_eq!(allowance, VALUE * 2); } #[test] @@ -358,10 +367,12 @@ fn test_decrease_allowance() { dispatcher.approve(SPENDER(), VALUE); utils::drop_event(dispatcher.contract_address); - assert(dispatcher.decrease_allowance(SPENDER(), VALUE), 'Should return true'); + assert!(dispatcher.decrease_allowance(SPENDER(), VALUE)); assert_only_event_approval(dispatcher.contract_address, OWNER(), SPENDER(), 0); - assert(dispatcher.allowance(OWNER(), SPENDER()) == VALUE - VALUE, 'Should be 0'); + + let allowance = dispatcher.allowance(OWNER(), SPENDER()); + assert!(allowance.is_zero()); } #[test] @@ -386,10 +397,12 @@ fn test_decreaseAllowance() { dispatcher.approve(SPENDER(), VALUE); utils::drop_event(dispatcher.contract_address); - assert(dispatcher.decreaseAllowance(SPENDER(), VALUE), 'Should return true'); + assert!(dispatcher.decreaseAllowance(SPENDER(), VALUE)); assert_only_event_approval(dispatcher.contract_address, OWNER(), SPENDER(), 0); - assert(dispatcher.allowance(OWNER(), SPENDER()) == VALUE - VALUE, 'Should be 0'); + + let allowance = dispatcher.allowance(OWNER(), SPENDER()); + assert!(allowance.is_zero()); } #[test] @@ -415,9 +428,9 @@ fn assert_event_approval( contract: ContractAddress, owner: ContractAddress, spender: ContractAddress, value: u256 ) { let event = utils::pop_log::(contract).unwrap(); - assert(event.owner == owner, 'Invalid `owner`'); - assert(event.spender == spender, 'Invalid `spender`'); - assert(event.value == value, 'Invalid `value`'); + assert_eq!(event.owner, owner); + assert_eq!(event.spender, spender); + assert_eq!(event.value, value); // Check indexed keys let mut indexed_keys = array![]; @@ -437,9 +450,9 @@ fn assert_event_transfer( contract: ContractAddress, from: ContractAddress, to: ContractAddress, value: u256 ) { let event = utils::pop_log::(contract).unwrap(); - assert(event.from == from, 'Invalid `from`'); - assert(event.to == to, 'Invalid `to`'); - assert(event.value == value, 'Invalid `value`'); + assert_eq!(event.from, from); + assert_eq!(event.to, to); + assert_eq!(event.value, value); // Check indexed keys let mut indexed_keys = array![]; diff --git a/src/tests/presets/test_erc721.cairo b/src/tests/presets/test_erc721.cairo index a0d7fedfc..b466e09e4 100644 --- a/src/tests/presets/test_erc721.cairo +++ b/src/tests/presets/test_erc721.cairo @@ -11,6 +11,7 @@ use openzeppelin::tests::mocks::non_implementing_mock::NonImplementingMock; use openzeppelin::tests::utils::constants::{ ZERO, DATA, OWNER, SPENDER, RECIPIENT, OTHER, OPERATOR, PUBKEY, NAME, SYMBOL }; +use openzeppelin::tests::utils::debug::DebugContractAddress; use openzeppelin::tests::utils; use openzeppelin::token::erc721::ERC721Component::InternalImpl as ERC721ComponentInternalTrait; use openzeppelin::token::erc721::ERC721Component::{Approval, ApprovalForAll, Transfer}; @@ -95,7 +96,7 @@ fn test__mint_assets() { state._mint_assets(OWNER(), token_ids, token_uris); - assert(state.erc721.balance_of(OWNER()) == TOKENS_LEN, 'Should equal IDs length'); + assert_eq!(state.erc721.balance_of(OWNER()), TOKENS_LEN); loop { if token_ids.len() == 0 { @@ -105,8 +106,8 @@ fn test__mint_assets() { let id = *token_ids.pop_front().unwrap(); let uri = *token_uris.pop_front().unwrap(); - assert(state.erc721.owner_of(id) == OWNER(), 'Should be owned by OWNER'); - assert(state.erc721.token_uri(id) == uri, 'Should equal correct URI'); + assert_eq!(state.erc721.owner_of(id), OWNER()); + assert_eq!(state.erc721.token_uri(id), uri); }; } @@ -145,18 +146,21 @@ fn test_constructor() { if interface_ids.len() == 0 { break; } - assert(dispatcher.supports_interface(id), 'Should support interface'); + let supported = dispatcher.supports_interface(id); + assert!(supported, "Should implement interface"); }; // Check token balance and owner let mut tokens = array![TOKEN_1, TOKEN_2, TOKEN_3]; - assert(dispatcher.balance_of(OWNER()) == TOKENS_LEN, 'Should equal TOKENS_LEN'); + assert_eq!(dispatcher.balance_of(OWNER()), TOKENS_LEN); + loop { let token = tokens.pop_front().unwrap(); if tokens.len() == 0 { break; } - assert(dispatcher.owner_of(token) == OWNER(), 'Should be owned by OWNER'); + let current_owner = dispatcher.owner_of(token); + assert_eq!(current_owner, OWNER()); }; } @@ -183,7 +187,7 @@ fn test_constructor_events() { #[test] fn test_balance_of() { let dispatcher = setup_dispatcher(); - assert(dispatcher.balance_of(OWNER()) == TOKENS_LEN, 'Should return balance'); + assert_eq!(dispatcher.balance_of(OWNER()), TOKENS_LEN); } #[test] @@ -196,7 +200,7 @@ fn test_balance_of_zero() { #[test] fn test_owner_of() { let dispatcher = setup_dispatcher(); - assert(dispatcher.owner_of(TOKEN_1) == OWNER(), 'Should return owner'); + assert_eq!(dispatcher.owner_of(TOKEN_1), OWNER()); } #[test] @@ -219,10 +223,12 @@ fn test_get_approved() { let spender = SPENDER(); let token_id = TOKEN_1; - assert(dispatcher.get_approved(token_id) == ZERO(), 'Should return non-approval'); + let approved = dispatcher.get_approved(token_id); + assert!(approved.is_zero()); dispatcher.approve(spender, token_id); - assert(dispatcher.get_approved(token_id) == spender, 'Should return approval'); + let approved = dispatcher.get_approved(token_id); + assert_eq!(approved, spender); } #[test] @@ -243,7 +249,8 @@ fn test_approve_from_owner() { dispatcher.approve(SPENDER(), TOKEN_1); assert_event_approval(dispatcher.contract_address, OWNER(), SPENDER(), TOKEN_1); - assert(dispatcher.get_approved(TOKEN_1) == SPENDER(), 'Spender not approved correctly'); + let approved = dispatcher.get_approved(TOKEN_1); + assert_eq!(approved, SPENDER()); } #[test] @@ -257,7 +264,8 @@ fn test_approve_from_operator() { dispatcher.approve(SPENDER(), TOKEN_1); assert_event_approval(dispatcher.contract_address, OWNER(), SPENDER(), TOKEN_1); - assert(dispatcher.get_approved(TOKEN_1) == SPENDER(), 'Spender not approved correctly'); + let approved = dispatcher.get_approved(TOKEN_1); + assert_eq!(approved, SPENDER()); } #[test] @@ -292,17 +300,20 @@ fn test_approve_nonexistent() { fn test_set_approval_for_all() { let dispatcher = setup_dispatcher(); - assert(!dispatcher.is_approved_for_all(OWNER(), OPERATOR()), 'Invalid default value'); + let is_not_approved_for_all = !dispatcher.is_approved_for_all(OWNER(), OPERATOR()); + assert!(is_not_approved_for_all); dispatcher.set_approval_for_all(OPERATOR(), true); assert_event_approval_for_all(dispatcher.contract_address, OWNER(), OPERATOR(), true); - assert(dispatcher.is_approved_for_all(OWNER(), OPERATOR()), 'Operator not approved correctly'); + let is_approved_for_all = dispatcher.is_approved_for_all(OWNER(), OPERATOR()); + assert!(is_approved_for_all); dispatcher.set_approval_for_all(OPERATOR(), false); assert_event_approval_for_all(dispatcher.contract_address, OWNER(), OPERATOR(), false); - assert(!dispatcher.is_approved_for_all(OWNER(), OPERATOR()), 'Approval not revoked correctly'); + let is_not_approved_for_all = !dispatcher.is_approved_for_all(OWNER(), OPERATOR()); + assert!(is_not_approved_for_all); } #[test] @@ -335,7 +346,9 @@ fn test_transfer_from_owner() { utils::drop_event(dispatcher.contract_address); assert_state_before_transfer(dispatcher, owner, recipient, token_id); - assert(dispatcher.get_approved(token_id) == OTHER(), 'Approval not implicitly reset'); + + let approved = dispatcher.get_approved(token_id); + assert_eq!(approved, OTHER()); dispatcher.transfer_from(owner, recipient, token_id); assert_only_event_transfer(dispatcher.contract_address, owner, recipient, token_id); @@ -355,7 +368,9 @@ fn test_transferFrom_owner() { utils::drop_event(dispatcher.contract_address); assert_state_before_transfer(dispatcher, owner, recipient, token_id); - assert(dispatcher.get_approved(token_id) == OTHER(), 'Approval not implicitly reset'); + + let approved = dispatcher.get_approved(token_id); + assert_eq!(approved, OTHER()); dispatcher.transferFrom(owner, recipient, token_id); assert_only_event_transfer(dispatcher.contract_address, owner, recipient, token_id); @@ -971,9 +986,9 @@ fn assert_state_before_transfer( recipient: ContractAddress, token_id: u256 ) { - assert(dispatcher.owner_of(token_id) == owner, 'Ownership before'); - assert(dispatcher.balance_of(owner) == TOKENS_LEN, 'Balance of owner before'); - assert(dispatcher.balance_of(recipient) == 0, 'Balance of recipient before'); + assert_eq!(dispatcher.owner_of(token_id), owner); + assert_eq!(dispatcher.balance_of(owner), TOKENS_LEN); + assert!(dispatcher.balance_of(recipient).is_zero()); } fn assert_state_after_transfer( @@ -982,26 +997,29 @@ fn assert_state_after_transfer( recipient: ContractAddress, token_id: u256 ) { - assert(dispatcher.owner_of(token_id) == recipient, 'Ownership after'); - assert(dispatcher.balance_of(owner) == TOKENS_LEN - 1, 'Balance of owner after'); - assert(dispatcher.balance_of(recipient) == 1, 'Balance of recipient after'); - assert(dispatcher.get_approved(token_id) == ZERO(), 'Approval not implicitly reset'); + let current_owner = dispatcher.owner_of(token_id); + assert_eq!(current_owner, recipient); + assert_eq!(dispatcher.balance_of(owner), TOKENS_LEN - 1); + assert_eq!(dispatcher.balance_of(recipient), 1); + + let approved = dispatcher.get_approved(token_id); + assert!(approved.is_zero()); } fn assert_state_transfer_to_self( dispatcher: ERC721ABIDispatcher, target: ContractAddress, token_id: u256, token_balance: u256 ) { - assert(dispatcher.owner_of(token_id) == target, 'Ownership before'); - assert(dispatcher.balance_of(target) == token_balance, 'Balance of owner before'); + assert_eq!(dispatcher.owner_of(token_id), target); + assert_eq!(dispatcher.balance_of(target), token_balance); } fn assert_event_approval_for_all( contract: ContractAddress, owner: ContractAddress, operator: ContractAddress, approved: bool ) { let event = utils::pop_log::(contract).unwrap(); - assert(event.owner == owner, 'Invalid `owner`'); - assert(event.operator == operator, 'Invalid `operator`'); - assert(event.approved == approved, 'Invalid `approved`'); + assert_eq!(event.owner, owner); + assert_eq!(event.operator, operator); + assert_eq!(event.approved, approved); utils::assert_no_events_left(contract); // Check indexed keys @@ -1015,9 +1033,9 @@ fn assert_event_approval( contract: ContractAddress, owner: ContractAddress, approved: ContractAddress, token_id: u256 ) { let event = utils::pop_log::(contract).unwrap(); - assert(event.owner == owner, 'Invalid `owner`'); - assert(event.approved == approved, 'Invalid `approved`'); - assert(event.token_id == token_id, 'Invalid `token_id`'); + assert_eq!(event.owner, owner); + assert_eq!(event.approved, approved); + assert_eq!(event.token_id, token_id); utils::assert_no_events_left(contract); // Check indexed keys @@ -1032,9 +1050,9 @@ fn assert_event_transfer( contract: ContractAddress, from: ContractAddress, to: ContractAddress, token_id: u256 ) { let event = utils::pop_log::(contract).unwrap(); - assert(event.from == from, 'Invalid `from`'); - assert(event.to == to, 'Invalid `to`'); - assert(event.token_id == token_id, 'Invalid `token_id`'); + assert_eq!(event.from, from); + assert_eq!(event.to, to); + assert_eq!(event.token_id, token_id); // Check indexed keys let mut indexed_keys = array![]; diff --git a/src/tests/security/test_initializable.cairo b/src/tests/security/test_initializable.cairo index eed0a01cc..745b34518 100644 --- a/src/tests/security/test_initializable.cairo +++ b/src/tests/security/test_initializable.cairo @@ -11,9 +11,9 @@ fn COMPONENT_STATE() -> ComponentState { #[test] fn test_initialize() { let mut state = COMPONENT_STATE(); - assert(!state.is_initialized(), 'Should not be initialized'); + assert!(!state.is_initialized()); state.initialize(); - assert(state.is_initialized(), 'Should be initialized'); + assert!(state.is_initialized()); } #[test] diff --git a/src/tests/security/test_pausable.cairo b/src/tests/security/test_pausable.cairo index 53b88f3f6..fb675e55b 100644 --- a/src/tests/security/test_pausable.cairo +++ b/src/tests/security/test_pausable.cairo @@ -3,6 +3,7 @@ use openzeppelin::security::PausableComponent::{Paused, Unpaused}; use openzeppelin::security::PausableComponent; use openzeppelin::tests::mocks::pausable_mocks::PausableMock; use openzeppelin::tests::utils::constants::{CALLER, ZERO}; +use openzeppelin::tests::utils::debug::DebugContractAddress; use openzeppelin::tests::utils; use starknet::ContractAddress; use starknet::contract_address_const; @@ -21,13 +22,13 @@ fn COMPONENT_STATE() -> ComponentState { #[test] fn test_is_paused() { let mut state = COMPONENT_STATE(); - assert(!state.is_paused(), 'Should not be paused'); + assert!(!state.is_paused()); state._pause(); - assert(state.is_paused(), 'Should be paused'); + assert!(state.is_paused()); state._unpause(); - assert(!state.is_paused(), 'Should not be paused'); + assert!(!state.is_paused()); } // @@ -78,7 +79,7 @@ fn test_pause_when_unpaused() { state._pause(); assert_event_paused(CALLER()); - assert(state.is_paused(), 'Should be paused'); + assert!(state.is_paused()); } #[test] @@ -104,14 +105,14 @@ fn test_unpause_when_paused() { state._unpause(); assert_event_unpaused(CALLER()); - assert(!state.is_paused(), 'Should not be paused'); + assert!(!state.is_paused()); } #[test] #[should_panic(expected: ('Pausable: not paused',))] fn test_unpause_when_unpaused() { let mut state = COMPONENT_STATE(); - assert(!state.is_paused(), 'Should be paused'); + assert!(!state.is_paused()); state._unpause(); } @@ -121,12 +122,12 @@ fn test_unpause_when_unpaused() { fn assert_event_paused(account: ContractAddress) { let event = utils::pop_log::(ZERO()).unwrap(); - assert(event.account == account, 'Invalid `account`'); + assert_eq!(event.account, account); utils::assert_no_events_left(ZERO()); } fn assert_event_unpaused(account: ContractAddress) { let event = utils::pop_log::(ZERO()).unwrap(); - assert(event.account == account, 'Invalid `account`'); + assert_eq!(event.account, account); utils::assert_no_events_left(ZERO()); } diff --git a/src/tests/security/test_reentrancyguard.cairo b/src/tests/security/test_reentrancyguard.cairo index a38c21432..327f72fa4 100644 --- a/src/tests/security/test_reentrancyguard.cairo +++ b/src/tests/security/test_reentrancyguard.cairo @@ -26,9 +26,13 @@ fn deploy_mock() -> IReentrancyMockDispatcher { fn test_reentrancy_guard_start() { let mut state = COMPONENT_STATE(); - assert(!state.ReentrancyGuard_entered.read(), 'Should not be entered'); + let not_entered = !state.ReentrancyGuard_entered.read(); + assert!(not_entered); + state.start(); - assert(state.ReentrancyGuard_entered.read(), 'Should be entered'); + + let entered = state.ReentrancyGuard_entered.read(); + assert!(entered); } #[test] @@ -45,9 +49,14 @@ fn test_reentrancy_guard_end() { let mut state = COMPONENT_STATE(); state.start(); - assert(state.ReentrancyGuard_entered.read(), 'Should be entered'); + + let entered = state.ReentrancyGuard_entered.read(); + assert!(entered); + state.end(); - assert(!state.ReentrancyGuard_entered.read(), 'Should no longer be entered'); + + let not_entered = !state.ReentrancyGuard_entered.read(); + assert!(not_entered); } // @@ -93,5 +102,5 @@ fn test_external_recursion() { fn test_nonreentrant_function_call() { let contract = deploy_mock(); contract.callback(); - assert(contract.current_count() == 1, 'Call should execute'); + assert_eq!(contract.current_count(), 1, "Call should execute"); } From 61c3f80673a3f3dc2ef6680293f9ae88082b8893 Mon Sep 17 00:00:00 2001 From: Eric Nordelo Date: Fri, 5 Jan 2024 13:43:55 +0100 Subject: [PATCH 08/15] refactor: more tests --- src/tests/account/test_account.cairo | 2 +- src/tests/token/test_dual20.cairo | 44 ++++++++------ src/tests/token/test_dual721.cairo | 67 +++++++++++++-------- src/tests/token/test_dual721_receiver.cairo | 18 +++--- src/tests/upgrades/test_upgradeable.cairo | 7 ++- src/tests/utils/debug.cairo | 9 ++- 6 files changed, 88 insertions(+), 59 deletions(-) diff --git a/src/tests/account/test_account.cairo b/src/tests/account/test_account.cairo index 0c44ca2b4..0d24feb7f 100644 --- a/src/tests/account/test_account.cairo +++ b/src/tests/account/test_account.cairo @@ -498,7 +498,7 @@ fn test__is_valid_signature() { let is_valid = state._is_valid_signature(hash, good_signature.span()); assert!(is_valid); - let is_not_valid = state._is_valid_signature(hash, bad_signature.span()); + let is_not_valid = !state._is_valid_signature(hash, bad_signature.span()); assert!(is_not_valid); let is_not_valid = !state._is_valid_signature(hash, invalid_length_signature.span()); diff --git a/src/tests/token/test_dual20.cairo b/src/tests/token/test_dual20.cairo index df69154ca..aab4b05a2 100644 --- a/src/tests/token/test_dual20.cairo +++ b/src/tests/token/test_dual20.cairo @@ -58,8 +58,8 @@ fn setup_erc20_panic() -> (DualCaseERC20, DualCaseERC20) { fn test_dual_name() { let (snake_dispatcher, _) = setup_snake(); let (camel_dispatcher, _) = setup_camel(); - assert(snake_dispatcher.name() == NAME, 'Should return name'); - assert(camel_dispatcher.name() == NAME, 'Should return name'); + assert_eq!(snake_dispatcher.name(), NAME); + assert_eq!(camel_dispatcher.name(), NAME); } #[test] @@ -80,8 +80,8 @@ fn test_dual_name_exists_and_panics() { fn test_dual_symbol() { let (snake_dispatcher, _) = setup_snake(); let (camel_dispatcher, _) = setup_camel(); - assert(snake_dispatcher.symbol() == SYMBOL, 'Should return symbol'); - assert(camel_dispatcher.symbol() == SYMBOL, 'Should return symbol'); + assert_eq!(snake_dispatcher.symbol(), SYMBOL); + assert_eq!(camel_dispatcher.symbol(), SYMBOL); } #[test] @@ -102,8 +102,8 @@ fn test_dual_symbol_exists_and_panics() { fn test_dual_decimals() { let (snake_dispatcher, _) = setup_snake(); let (camel_dispatcher, _) = setup_camel(); - assert(snake_dispatcher.decimals() == DECIMALS, 'Should return symbol'); - assert(camel_dispatcher.decimals() == DECIMALS, 'Should return symbol'); + assert_eq!(snake_dispatcher.decimals(), DECIMALS); + assert_eq!(camel_dispatcher.decimals(), DECIMALS); } #[test] @@ -124,13 +124,13 @@ fn test_dual_decimals_exists_and_panics() { fn test_dual_transfer() { let (snake_dispatcher, snake_target) = setup_snake(); set_contract_address(OWNER()); - assert(snake_dispatcher.transfer(RECIPIENT(), VALUE), 'Should return true'); - assert(snake_target.balance_of(RECIPIENT()) == VALUE, 'Should equal VALUE'); + assert!(snake_dispatcher.transfer(RECIPIENT(), VALUE)); + assert_eq!(snake_target.balance_of(RECIPIENT()), VALUE); let (camel_dispatcher, camel_target) = setup_camel(); set_contract_address(OWNER()); - assert(camel_dispatcher.transfer(RECIPIENT(), VALUE), 'Should return true'); - assert(camel_target.balanceOf(RECIPIENT()) == VALUE, 'Should equal VALUE'); + assert!(camel_dispatcher.transfer(RECIPIENT(), VALUE)); + assert_eq!(camel_target.balanceOf(RECIPIENT()), VALUE); } #[test] @@ -151,13 +151,17 @@ fn test_dual_transfer_exists_and_panics() { fn test_dual_approve() { let (snake_dispatcher, snake_target) = setup_snake(); set_contract_address(OWNER()); - assert(snake_dispatcher.approve(SPENDER(), VALUE), 'Should return true'); - assert(snake_target.allowance(OWNER(), SPENDER()) == VALUE, 'Allowance should equal VALUE'); + assert!(snake_dispatcher.approve(SPENDER(), VALUE)); + + let snake_allowance = snake_target.allowance(OWNER(), SPENDER()); + assert_eq!(snake_allowance, VALUE); let (camel_dispatcher, camel_target) = setup_camel(); set_contract_address(OWNER()); - assert(camel_dispatcher.approve(SPENDER(), VALUE), 'Should return true'); - assert(camel_target.allowance(OWNER(), SPENDER()) == VALUE, 'Allowance should equal VALUE'); + assert!(camel_dispatcher.approve(SPENDER(), VALUE)); + + let camel_allowance = camel_target.allowance(OWNER(), SPENDER()); + assert_eq!(camel_allowance, VALUE); } #[test] @@ -181,7 +185,7 @@ fn test_dual_approve_exists_and_panics() { #[test] fn test_dual_total_supply() { let (dispatcher, _) = setup_snake(); - assert(dispatcher.total_supply() == SUPPLY, 'Should return balance'); + assert_eq!(dispatcher.total_supply(), SUPPLY); } #[test] @@ -201,7 +205,7 @@ fn test_dual_total_supply_exists_and_panics() { #[test] fn test_dual_balance_of() { let (dispatcher, _) = setup_snake(); - assert(dispatcher.balance_of(OWNER()) == SUPPLY, 'Should return balance'); + assert_eq!(dispatcher.balance_of(OWNER()), SUPPLY); } #[test] @@ -226,7 +230,7 @@ fn test_dual_transfer_from() { set_contract_address(OPERATOR()); dispatcher.transfer_from(OWNER(), RECIPIENT(), VALUE); - assert(target.balance_of(RECIPIENT()) == VALUE, 'Should transfer VALUE'); + assert_eq!(target.balance_of(RECIPIENT()), VALUE); } #[test] @@ -250,7 +254,7 @@ fn test_dual_transfer_from_exists_and_panics() { #[test] fn test_dual_totalSupply() { let (dispatcher, _) = setup_camel(); - assert(dispatcher.total_supply() == SUPPLY, 'Should return supply'); + assert_eq!(dispatcher.total_supply(), SUPPLY); } #[test] @@ -263,7 +267,7 @@ fn test_dual_totalSupply_exists_and_panics() { #[test] fn test_dual_balanceOf() { let (dispatcher, _) = setup_camel(); - assert(dispatcher.balance_of(OWNER()) == SUPPLY, 'Should return balance'); + assert_eq!(dispatcher.balance_of(OWNER()), SUPPLY); } #[test] @@ -281,7 +285,7 @@ fn test_dual_transferFrom() { set_contract_address(OPERATOR()); dispatcher.transfer_from(OWNER(), RECIPIENT(), VALUE); - assert(target.balanceOf(RECIPIENT()) == VALUE, 'Should transfer VALUE'); + assert_eq!(target.balanceOf(RECIPIENT()), VALUE); } #[test] diff --git a/src/tests/token/test_dual721.cairo b/src/tests/token/test_dual721.cairo index 229ecffbb..9026ffd55 100644 --- a/src/tests/token/test_dual721.cairo +++ b/src/tests/token/test_dual721.cairo @@ -5,6 +5,7 @@ use openzeppelin::tests::mocks::non_implementing_mock::NonImplementingMock; use openzeppelin::tests::utils::constants::{ DATA, OWNER, RECIPIENT, SPENDER, OPERATOR, OTHER, NAME, SYMBOL, URI, TOKEN_ID }; +use openzeppelin::tests::utils::debug::DebugContractAddress; use openzeppelin::tests::utils; use openzeppelin::token::erc721::dual721::{DualCaseERC721, DualCaseERC721Trait}; use openzeppelin::token::erc721::interface::IERC721_ID; @@ -75,8 +76,8 @@ fn setup_receiver() -> ContractAddress { fn test_dual_name() { let (snake_dispatcher, _) = setup_snake(); let (camel_dispatcher, _) = setup_camel(); - assert(snake_dispatcher.name() == NAME, 'Should return name'); - assert(camel_dispatcher.name() == NAME, 'Should return name'); + assert_eq!(snake_dispatcher.name(), NAME); + assert_eq!(camel_dispatcher.name(), NAME); } #[test] @@ -97,8 +98,8 @@ fn test_dual_name_exists_and_panics() { fn test_dual_symbol() { let (snake_dispatcher, _) = setup_snake(); let (camel_dispatcher, _) = setup_camel(); - assert(snake_dispatcher.symbol() == SYMBOL, 'Should return symbol'); - assert(camel_dispatcher.symbol() == SYMBOL, 'Should return symbol'); + assert_eq!(snake_dispatcher.symbol(), SYMBOL); + assert_eq!(camel_dispatcher.symbol(), SYMBOL); } #[test] @@ -120,12 +121,12 @@ fn test_dual_approve() { let (snake_dispatcher, snake_target) = setup_snake(); set_contract_address(OWNER()); snake_dispatcher.approve(SPENDER(), TOKEN_ID); - assert(snake_target.get_approved(TOKEN_ID) == SPENDER(), 'Spender not approved correctly'); + assert_eq!(snake_target.get_approved(TOKEN_ID), SPENDER()); let (camel_dispatcher, camel_target) = setup_camel(); set_contract_address(OWNER()); camel_dispatcher.approve(SPENDER(), TOKEN_ID); - assert(camel_target.getApproved(TOKEN_ID) == SPENDER(), 'Spender not approved correctly'); + assert_eq!(camel_target.getApproved(TOKEN_ID), SPENDER()); } #[test] @@ -149,7 +150,7 @@ fn test_dual_approve_exists_and_panics() { #[test] fn test_dual_balance_of() { let (dispatcher, _) = setup_snake(); - assert(dispatcher.balance_of(OWNER()) == 1, 'Should return balance'); + assert_eq!(dispatcher.balance_of(OWNER()), 1); } #[test] @@ -169,7 +170,7 @@ fn test_dual_balance_of_exists_and_panics() { #[test] fn test_dual_owner_of() { let (dispatcher, target) = setup_snake(); - assert(dispatcher.owner_of(TOKEN_ID) == OWNER(), 'Should return owner'); + assert_eq!(dispatcher.owner_of(TOKEN_ID), OWNER()); } #[test] @@ -190,7 +191,7 @@ fn test_dual_owner_of_exists_and_panics() { fn test_dual_transfer_from() { let (dispatcher, target) = setup_snake(); dispatcher.transfer_from(OWNER(), RECIPIENT(), TOKEN_ID); - assert(target.owner_of(TOKEN_ID) == RECIPIENT(), 'Should transfer token'); + assert_eq!(target.owner_of(TOKEN_ID), RECIPIENT()); } #[test] @@ -212,7 +213,7 @@ fn test_dual_safe_transfer_from() { let (dispatcher, target) = setup_snake(); let receiver = setup_receiver(); dispatcher.safe_transfer_from(OWNER(), receiver, TOKEN_ID, DATA(true)); - assert(target.owner_of(TOKEN_ID) == receiver, 'Should transfer token'); + assert_eq!(target.owner_of(TOKEN_ID), receiver); } #[test] @@ -234,7 +235,7 @@ fn test_dual_get_approved() { let (dispatcher, target) = setup_snake(); set_contract_address(OWNER()); target.approve(SPENDER(), TOKEN_ID); - assert(dispatcher.get_approved(TOKEN_ID) == SPENDER(), 'Should return approval'); + assert_eq!(dispatcher.get_approved(TOKEN_ID), SPENDER()); } #[test] @@ -256,7 +257,9 @@ fn test_dual_set_approval_for_all() { let (dispatcher, target) = setup_snake(); set_contract_address(OWNER()); dispatcher.set_approval_for_all(OPERATOR(), true); - assert(target.is_approved_for_all(OWNER(), OPERATOR()), 'Operator not approved correctly'); + + let is_approved_for_all = target.is_approved_for_all(OWNER(), OPERATOR()); + assert!(is_approved_for_all); } #[test] @@ -278,7 +281,9 @@ fn test_dual_is_approved_for_all() { let (dispatcher, target) = setup_snake(); set_contract_address(OWNER()); target.set_approval_for_all(OPERATOR(), true); - assert(dispatcher.is_approved_for_all(OWNER(), OPERATOR()), 'Operator not approved correctly'); + + let is_approved_for_all = dispatcher.is_approved_for_all(OWNER(), OPERATOR()); + assert!(is_approved_for_all); } #[test] @@ -298,7 +303,7 @@ fn test_dual_is_approved_for_all_exists_and_panics() { #[test] fn test_dual_token_uri() { let (dispatcher, target) = setup_snake(); - assert(dispatcher.token_uri(TOKEN_ID) == URI, 'Should return URI'); + assert_eq!(dispatcher.token_uri(TOKEN_ID), URI); } #[test] @@ -318,7 +323,8 @@ fn test_dual_token_uri_exists_and_panics() { #[test] fn test_dual_supports_interface() { let (dispatcher, _) = setup_snake(); - assert(dispatcher.supports_interface(IERC721_ID), 'Should support own interface'); + let supported = dispatcher.supports_interface(IERC721_ID); + assert!(supported, "Should implement IERC721"); } #[test] @@ -342,7 +348,7 @@ fn test_dual_supports_interface_exists_and_panics() { #[test] fn test_dual_balanceOf() { let (dispatcher, _) = setup_camel(); - assert(dispatcher.balance_of(OWNER()) == 1, 'Should return balance'); + assert_eq!(dispatcher.balance_of(OWNER()), 1); } #[test] @@ -355,7 +361,8 @@ fn test_dual_balanceOf_exists_and_panics() { #[test] fn test_dual_ownerOf() { let (dispatcher, target) = setup_camel(); - assert(dispatcher.owner_of(TOKEN_ID) == OWNER(), 'Should return owner'); + let current_owner = dispatcher.owner_of(TOKEN_ID); + assert_eq!(current_owner, OWNER()); } #[test] @@ -370,7 +377,9 @@ fn test_dual_transferFrom() { let (dispatcher, target) = setup_camel(); set_contract_address(OWNER()); dispatcher.transfer_from(OWNER(), RECIPIENT(), TOKEN_ID); - assert(target.ownerOf(TOKEN_ID) == RECIPIENT(), 'Should transfer token'); + + let current_owner = target.ownerOf(TOKEN_ID); + assert_eq!(current_owner, RECIPIENT()); } #[test] @@ -385,7 +394,9 @@ fn test_dual_safeTransferFrom() { let (dispatcher, target) = setup_camel(); let receiver = setup_receiver(); dispatcher.safe_transfer_from(OWNER(), receiver, TOKEN_ID, DATA(true)); - assert(target.ownerOf(TOKEN_ID) == receiver, 'Should transfer token'); + + let current_owner = target.ownerOf(TOKEN_ID); + assert_eq!(current_owner, receiver); } #[test] @@ -400,7 +411,9 @@ fn test_dual_getApproved() { let (dispatcher, _) = setup_camel(); set_contract_address(OWNER()); dispatcher.approve(SPENDER(), TOKEN_ID); - assert(dispatcher.get_approved(TOKEN_ID) == SPENDER(), 'Should return approval'); + + let approved = dispatcher.get_approved(TOKEN_ID); + assert_eq!(approved, SPENDER()); } #[test] @@ -415,7 +428,9 @@ fn test_dual_setApprovalForAll() { let (dispatcher, target) = setup_camel(); set_contract_address(OWNER()); dispatcher.set_approval_for_all(OPERATOR(), true); - assert(target.isApprovedForAll(OWNER(), OPERATOR()), 'Operator not approved correctly'); + + let is_approved_for_all = target.isApprovedForAll(OWNER(), OPERATOR()); + assert!(is_approved_for_all); } #[test] @@ -430,7 +445,9 @@ fn test_dual_isApprovedForAll() { let (dispatcher, target) = setup_camel(); set_contract_address(OWNER()); target.setApprovalForAll(OPERATOR(), true); - assert(dispatcher.is_approved_for_all(OWNER(), OPERATOR()), 'Operator not approved correctly'); + + let is_approved_for_all = dispatcher.is_approved_for_all(OWNER(), OPERATOR()); + assert!(is_approved_for_all); } #[test] @@ -443,7 +460,8 @@ fn test_dual_isApprovedForAll_exists_and_panics() { #[test] fn test_dual_tokenURI() { let (dispatcher, target) = setup_camel(); - assert(dispatcher.token_uri(TOKEN_ID) == URI, 'Should return URI'); + let token_uri = dispatcher.token_uri(TOKEN_ID); + assert_eq!(token_uri, URI); } #[test] @@ -456,7 +474,8 @@ fn test_dual_tokenURI_exists_and_panics() { #[test] fn test_dual_supportsInterface() { let (dispatcher, _) = setup_camel(); - assert(dispatcher.supports_interface(IERC721_ID), 'Should support own interface'); + let supported = dispatcher.supports_interface(IERC721_ID); + assert!(supported, "Should implement IERC721"); } #[test] diff --git a/src/tests/token/test_dual721_receiver.cairo b/src/tests/token/test_dual721_receiver.cairo index 746ef1046..b201b14d3 100644 --- a/src/tests/token/test_dual721_receiver.cairo +++ b/src/tests/token/test_dual721_receiver.cairo @@ -66,11 +66,10 @@ fn setup_erc721_receiver_panic() -> (DualCaseERC721Receiver, DualCaseERC721Recei #[test] fn test_dual_on_erc721_received() { let (dispatcher, _) = setup_snake(); - assert( - dispatcher - .on_erc721_received(OPERATOR(), OWNER(), TOKEN_ID, DATA(true)) == IERC721_RECEIVER_ID, - 'Should return interface id' - ); + + let on_erc721_received = dispatcher + .on_erc721_received(OPERATOR(), OWNER(), TOKEN_ID, DATA(true)); + assert_eq!(on_erc721_received, IERC721_RECEIVER_ID); } #[test] @@ -94,11 +93,10 @@ fn test_dual_on_erc721_received_exists_and_panics() { #[test] fn test_dual_onERC721Received() { let (dispatcher, _) = setup_camel(); - assert( - dispatcher - .on_erc721_received(OPERATOR(), OWNER(), TOKEN_ID, DATA(true)) == IERC721_RECEIVER_ID, - 'Should return interface id' - ); + + let on_erc721_received = dispatcher + .on_erc721_received(OPERATOR(), OWNER(), TOKEN_ID, DATA(true)); + assert_eq!(on_erc721_received, IERC721_RECEIVER_ID); } #[test] diff --git a/src/tests/upgrades/test_upgradeable.cairo b/src/tests/upgrades/test_upgradeable.cairo index 932d33c63..280b309d7 100644 --- a/src/tests/upgrades/test_upgradeable.cairo +++ b/src/tests/upgrades/test_upgradeable.cairo @@ -5,6 +5,7 @@ use openzeppelin::tests::mocks::upgrades_mocks::{ IUpgradesV2Dispatcher, IUpgradesV2DispatcherTrait, UpgradesV2 }; use openzeppelin::tests::utils::constants::{CLASS_HASH_ZERO, ZERO}; +use openzeppelin::tests::utils::debug::DebugClassHash; use openzeppelin::tests::utils; use openzeppelin::upgrades::UpgradeableComponent::Upgraded; use starknet::ClassHash; @@ -43,7 +44,7 @@ fn test_upgraded_event() { v1.upgrade(V2_CLASS_HASH()); let event = utils::pop_log::(v1.contract_address).unwrap(); - assert(event.class_hash == V2_CLASS_HASH(), 'Invalid class hash'); + assert_eq!(event.class_hash, V2_CLASS_HASH()); utils::assert_no_events_left(v1.contract_address); } @@ -56,7 +57,7 @@ fn test_new_selector_after_upgrade() { let v2 = IUpgradesV2Dispatcher { contract_address: v1.contract_address }; v2.set_value2(VALUE); - assert(v2.get_value2() == VALUE, 'New selector should be callable'); + assert_eq!(v2.get_value2(), VALUE); } #[test] @@ -67,7 +68,7 @@ fn test_state_persists_after_upgrade() { v1.upgrade(V2_CLASS_HASH()); let v2 = IUpgradesV2Dispatcher { contract_address: v1.contract_address }; - assert(v2.get_value() == VALUE, 'Should keep state after upgrade'); + assert_eq!(v2.get_value(), VALUE); } #[test] diff --git a/src/tests/utils/debug.cairo b/src/tests/utils/debug.cairo index 0d71ba069..f2a859e95 100644 --- a/src/tests/utils/debug.cairo +++ b/src/tests/utils/debug.cairo @@ -1,5 +1,5 @@ use core::fmt::{Debug, Formatter, Error}; -use starknet::ContractAddress; +use starknet::{ContractAddress, ClassHash}; impl DebugContractAddress of core::fmt::Debug { fn fmt(self: @ContractAddress, ref f: Formatter) -> Result<(), Error> { @@ -7,3 +7,10 @@ impl DebugContractAddress of core::fmt::Debug { write!(f, "{address:?}") } } + +impl DebugClassHash of core::fmt::Debug { + fn fmt(self: @ClassHash, ref f: Formatter) -> Result<(), Error> { + let hash: felt252 = (*self).into(); + write!(f, "{hash:?}") + } +} From bc5560f7cc179b3fe8602f2959503243a5f9568e Mon Sep 17 00:00:00 2001 From: Eric Nordelo Date: Mon, 8 Jan 2024 11:57:03 +0100 Subject: [PATCH 09/15] refactor: token assertions --- src/tests/access/test_accesscontrol.cairo | 2 +- src/tests/token/test_erc20.cairo | 126 ++++++++------ src/tests/token/test_erc721.cairo | 189 ++++++++++++--------- src/tests/token/test_erc721_receiver.cairo | 30 ++-- src/tests/utils.cairo | 8 +- 5 files changed, 201 insertions(+), 154 deletions(-) diff --git a/src/tests/access/test_accesscontrol.cairo b/src/tests/access/test_accesscontrol.cairo index 93386cfef..81fd7f650 100644 --- a/src/tests/access/test_accesscontrol.cairo +++ b/src/tests/access/test_accesscontrol.cairo @@ -367,7 +367,7 @@ fn test_renounceRole_unauthorized() { #[test] fn test__set_role_admin() { let mut state = setup(); - assert(state.get_role_admin(ROLE) == DEFAULT_ADMIN_ROLE, 'Default admin should be zero'); + assert_eq!(state.get_role_admin(ROLE), DEFAULT_ADMIN_ROLE); state._set_role_admin(ROLE, OTHER_ROLE); assert_event_role_admin_changed(ROLE, DEFAULT_ADMIN_ROLE, OTHER_ROLE); diff --git a/src/tests/token/test_erc20.cairo b/src/tests/token/test_erc20.cairo index 9c654eb07..72be7189f 100644 --- a/src/tests/token/test_erc20.cairo +++ b/src/tests/token/test_erc20.cairo @@ -1,8 +1,10 @@ +use core::num::traits::zero::Zero; use integer::BoundedInt; use openzeppelin::tests::mocks::erc20_mocks::DualCaseERC20Mock; use openzeppelin::tests::utils::constants::{ ZERO, OWNER, SPENDER, RECIPIENT, NAME, SYMBOL, DECIMALS, SUPPLY, VALUE }; +use openzeppelin::tests::utils::debug::DebugContractAddress; use openzeppelin::tests::utils; use openzeppelin::token::erc20::ERC20Component::{Approval, Transfer}; use openzeppelin::token::erc20::ERC20Component::{ERC20CamelOnlyImpl, ERC20Impl}; @@ -40,10 +42,10 @@ fn test_initializer() { let mut state = COMPONENT_STATE(); state.initializer(NAME, SYMBOL); - assert(state.name() == NAME, 'Should be NAME'); - assert(state.symbol() == SYMBOL, 'Should be SYMBOL'); - assert(state.decimals() == DECIMALS, 'Should be DECIMALS'); - assert(state.total_supply() == 0, 'Should equal 0'); + assert_eq!(state.name(), NAME); + assert_eq!(state.symbol(), SYMBOL); + assert_eq!(state.decimals(), DECIMALS); + assert_eq!(state.total_supply(), 0); } // @@ -54,28 +56,28 @@ fn test_initializer() { fn test_total_supply() { let mut state = COMPONENT_STATE(); state._mint(OWNER(), SUPPLY); - assert(state.total_supply() == SUPPLY, 'Should equal SUPPLY'); + assert_eq!(state.total_supply(), SUPPLY); } #[test] fn test_totalSupply() { let mut state = COMPONENT_STATE(); state._mint(OWNER(), SUPPLY); - assert(state.totalSupply() == SUPPLY, 'Should equal SUPPLY'); + assert_eq!(state.totalSupply(), SUPPLY); } #[test] fn test_balance_of() { let mut state = COMPONENT_STATE(); state._mint(OWNER(), SUPPLY); - assert(state.balance_of(OWNER()) == SUPPLY, 'Should equal SUPPLY'); + assert_eq!(state.balance_of(OWNER()), SUPPLY); } #[test] fn test_balanceOf() { let mut state = COMPONENT_STATE(); state._mint(OWNER(), SUPPLY); - assert(state.balanceOf(OWNER()) == SUPPLY, 'Should equal SUPPLY'); + assert_eq!(state.balanceOf(OWNER()), SUPPLY); } #[test] @@ -84,7 +86,8 @@ fn test_allowance() { testing::set_caller_address(OWNER()); state.approve(SPENDER(), VALUE); - assert(state.allowance(OWNER(), SPENDER()) == VALUE, 'Should equal VALUE'); + let allowance = state.allowance(OWNER(), SPENDER()); + assert_eq!(allowance, VALUE); } // @@ -95,10 +98,12 @@ fn test_allowance() { fn test_approve() { let mut state = setup(); testing::set_caller_address(OWNER()); - assert(state.approve(SPENDER(), VALUE), 'Should return true'); + assert!(state.approve(SPENDER(), VALUE)); assert_only_event_approval(OWNER(), SPENDER(), VALUE); - assert(state.allowance(OWNER(), SPENDER()) == VALUE, 'Spender not approved correctly'); + + let allowance = state.allowance(OWNER(), SPENDER()); + assert_eq!(allowance, VALUE); } #[test] @@ -123,7 +128,9 @@ fn test__approve() { state._approve(OWNER(), SPENDER(), VALUE); assert_only_event_approval(OWNER(), SPENDER(), VALUE); - assert(state.allowance(OWNER(), SPENDER()) == VALUE, 'Spender not approved correctly'); + + let allowance = state.allowance(OWNER(), SPENDER()); + assert_eq!(allowance, VALUE); } #[test] @@ -149,12 +156,12 @@ fn test__approve_to_zero() { fn test_transfer() { let mut state = setup(); testing::set_caller_address(OWNER()); - assert(state.transfer(RECIPIENT(), VALUE), 'Should return true'); + assert!(state.transfer(RECIPIENT(), VALUE)); assert_only_event_transfer(OWNER(), RECIPIENT(), VALUE); - assert(state.balance_of(RECIPIENT()) == VALUE, 'Should equal VALUE'); - assert(state.balance_of(OWNER()) == SUPPLY - VALUE, 'Should equal SUPPLY - VALUE'); - assert(state.total_supply() == SUPPLY, 'Total supply should not change'); + assert_eq!(state.balance_of(RECIPIENT()), VALUE); + assert_eq!(state.balance_of(OWNER()), SUPPLY - VALUE); + assert_eq!(state.total_supply(), SUPPLY); } #[test] @@ -189,9 +196,9 @@ fn test__transfer() { state._transfer(OWNER(), RECIPIENT(), VALUE); assert_only_event_transfer(OWNER(), RECIPIENT(), VALUE); - assert(state.balance_of(RECIPIENT()) == VALUE, 'Should equal amount'); - assert(state.balance_of(OWNER()) == SUPPLY - VALUE, 'Should equal SUPPLY - VALUE'); - assert(state.total_supply() == SUPPLY, 'Total supply should not change'); + assert_eq!(state.balance_of(RECIPIENT()), VALUE); + assert_eq!(state.balance_of(OWNER()), SUPPLY - VALUE); + assert_eq!(state.total_supply(), SUPPLY); } #[test] @@ -230,15 +237,17 @@ fn test_transfer_from() { utils::drop_event(ZERO()); testing::set_caller_address(SPENDER()); - assert(state.transfer_from(OWNER(), RECIPIENT(), VALUE), 'Should return true'); + assert!(state.transfer_from(OWNER(), RECIPIENT(), VALUE)); assert_event_approval(OWNER(), SPENDER(), 0); assert_only_event_transfer(OWNER(), RECIPIENT(), VALUE); - assert(state.balance_of(RECIPIENT()) == VALUE, 'Should equal VALUE'); - assert(state.balance_of(OWNER()) == SUPPLY - VALUE, 'Should equal SUPPLY - VALUE'); - assert(state.allowance(OWNER(), SPENDER()) == 0, 'Should equal 0'); - assert(state.total_supply() == SUPPLY, 'Total supply should not change'); + let allowance = state.allowance(OWNER(), SPENDER()); + + assert_eq!(state.balance_of(RECIPIENT()), VALUE); + assert_eq!(state.balance_of(OWNER()), SUPPLY - VALUE); + assert_eq!(state.total_supply(), SUPPLY); + assert_eq!(allowance, 0); } #[test] @@ -250,7 +259,8 @@ fn test_transfer_from_doesnt_consume_infinite_allowance() { testing::set_caller_address(SPENDER()); state.transfer_from(OWNER(), RECIPIENT(), VALUE); - assert(state.allowance(OWNER(), SPENDER()) == BoundedInt::max(), 'Allowance should not change'); + let allowance = state.allowance(OWNER(), SPENDER()); + assert_eq!(allowance, BoundedInt::max()); } #[test] @@ -291,15 +301,17 @@ fn test_transferFrom() { utils::drop_event(ZERO()); testing::set_caller_address(SPENDER()); - assert(state.transferFrom(OWNER(), RECIPIENT(), VALUE), 'Should return true'); + assert!(state.transferFrom(OWNER(), RECIPIENT(), VALUE)); assert_event_approval(OWNER(), SPENDER(), 0); assert_only_event_transfer(OWNER(), RECIPIENT(), VALUE); - assert(state.balanceOf(RECIPIENT()) == VALUE, 'Should equal VALUE'); - assert(state.balanceOf(OWNER()) == SUPPLY - VALUE, 'Should equal SUPPLY - VALUE'); - assert(state.allowance(OWNER(), SPENDER()) == 0, 'Should equal 0'); - assert(state.totalSupply() == SUPPLY, 'Total supply should not change'); + let allowance = state.allowance(OWNER(), SPENDER()); + + assert_eq!(state.balanceOf(RECIPIENT()), VALUE); + assert_eq!(state.balanceOf(OWNER()), SUPPLY - VALUE); + assert_eq!(state.totalSupply(), SUPPLY); + assert_eq!(allowance, 0); } #[test] @@ -311,7 +323,8 @@ fn test_transferFrom_doesnt_consume_infinite_allowance() { testing::set_caller_address(SPENDER()); state.transferFrom(OWNER(), RECIPIENT(), VALUE); - assert(state.allowance(OWNER(), SPENDER()) == BoundedInt::max(), 'Allowance should not change'); + let allowance = state.allowance(OWNER(), SPENDER()); + assert_eq!(allowance, BoundedInt::max()); } #[test] @@ -355,10 +368,12 @@ fn test_increase_allowance() { state.approve(SPENDER(), VALUE); utils::drop_event(ZERO()); - assert(state.increase_allowance(SPENDER(), VALUE), 'Should return true'); + assert!(state.increase_allowance(SPENDER(), VALUE)); assert_only_event_approval(OWNER(), SPENDER(), VALUE * 2); - assert(state.allowance(OWNER(), SPENDER()) == VALUE * 2, 'Should equal VALUE * 2'); + + let allowance = state.allowance(OWNER(), SPENDER()); + assert_eq!(allowance, VALUE * 2); } #[test] @@ -383,10 +398,12 @@ fn test_increaseAllowance() { state.approve(SPENDER(), VALUE); utils::drop_event(ZERO()); - assert(state.increaseAllowance(SPENDER(), VALUE), 'Should return true'); + assert!(state.increaseAllowance(SPENDER(), VALUE)); assert_only_event_approval(OWNER(), SPENDER(), 2 * VALUE); - assert(state.allowance(OWNER(), SPENDER()) == VALUE * 2, 'Should equal VALUE * 2'); + + let allowance = state.allowance(OWNER(), SPENDER()); + assert_eq!(allowance, VALUE * 2); } #[test] @@ -415,10 +432,12 @@ fn test_decrease_allowance() { state.approve(SPENDER(), VALUE); utils::drop_event(ZERO()); - assert(state.decrease_allowance(SPENDER(), VALUE), 'Should return true'); + assert!(state.decrease_allowance(SPENDER(), VALUE)); assert_only_event_approval(OWNER(), SPENDER(), 0); - assert(state.allowance(OWNER(), SPENDER()) == VALUE - VALUE, 'Should be 0'); + + let allowance = state.allowance(OWNER(), SPENDER()); + assert_eq!(allowance, 0); } #[test] @@ -443,10 +462,12 @@ fn test_decreaseAllowance() { state.approve(SPENDER(), VALUE); utils::drop_event(ZERO()); - assert(state.decreaseAllowance(SPENDER(), VALUE), 'Should return true'); + assert!(state.decreaseAllowance(SPENDER(), VALUE)); assert_only_event_approval(OWNER(), SPENDER(), 0); - assert(state.allowance(OWNER(), SPENDER()) == VALUE - VALUE, 'Should be 0'); + + let allowance = state.allowance(OWNER(), SPENDER()); + assert_eq!(allowance, 0); } #[test] @@ -478,7 +499,9 @@ fn test__spend_allowance_not_unlimited() { state._spend_allowance(OWNER(), SPENDER(), VALUE); assert_only_event_approval(OWNER(), SPENDER(), SUPPLY - VALUE); - assert(state.allowance(OWNER(), SPENDER()) == SUPPLY - VALUE, 'Should equal SUPPLY - VALUE'); + + let allowance = state.allowance(OWNER(), SPENDER()); + assert_eq!(allowance, SUPPLY - VALUE); } #[test] @@ -489,7 +512,8 @@ fn test__spend_allowance_unlimited() { let max_minus_one: u256 = BoundedInt::max() - 1; state._spend_allowance(OWNER(), SPENDER(), max_minus_one); - assert(state.allowance(OWNER(), SPENDER()) == BoundedInt::max(), 'Allowance should not change'); + let allowance = state.allowance(OWNER(), SPENDER()); + assert_eq!(state.allowance(OWNER(), SPENDER()), BoundedInt::max()); } // @@ -502,8 +526,8 @@ fn test__mint() { state._mint(OWNER(), VALUE); assert_only_event_transfer(ZERO(), OWNER(), VALUE); - assert(state.balance_of(OWNER()) == VALUE, 'Should equal VALUE'); - assert(state.total_supply() == VALUE, 'Should equal VALUE'); + assert_eq!(state.balance_of(OWNER()), VALUE); + assert_eq!(state.total_supply(), VALUE); } #[test] @@ -523,8 +547,8 @@ fn test__burn() { state._burn(OWNER(), VALUE); assert_only_event_transfer(OWNER(), ZERO(), VALUE); - assert(state.total_supply() == SUPPLY - VALUE, 'Should equal SUPPLY - VALUE'); - assert(state.balance_of(OWNER()) == SUPPLY - VALUE, 'Should equal SUPPLY - VALUE'); + assert_eq!(state.total_supply(), SUPPLY - VALUE); + assert_eq!(state.balance_of(OWNER()), SUPPLY - VALUE); } #[test] @@ -540,9 +564,9 @@ fn test__burn_from_zero() { fn assert_event_approval(owner: ContractAddress, spender: ContractAddress, value: u256) { let event = utils::pop_log::(ZERO()).unwrap(); - assert(event.owner == owner, 'Invalid `owner`'); - assert(event.spender == spender, 'Invalid `spender`'); - assert(event.value == value, 'Invalid `value`'); + assert_eq!(event.owner, owner); + assert_eq!(event.spender, spender); + assert_eq!(event.value, value); // Check indexed keys let mut indexed_keys = array![]; @@ -558,9 +582,9 @@ fn assert_only_event_approval(owner: ContractAddress, spender: ContractAddress, fn assert_event_transfer(from: ContractAddress, to: ContractAddress, value: u256) { let event = utils::pop_log::(ZERO()).unwrap(); - assert(event.from == from, 'Invalid `from`'); - assert(event.to == to, 'Invalid `to`'); - assert(event.value == value, 'Invalid `value`'); + assert_eq!(event.from, from); + assert_eq!(event.to, to); + assert_eq!(event.value, value); // Check indexed keys let mut indexed_keys = array![]; diff --git a/src/tests/token/test_erc721.cairo b/src/tests/token/test_erc721.cairo index 48e18643d..6c751a934 100644 --- a/src/tests/token/test_erc721.cairo +++ b/src/tests/token/test_erc721.cairo @@ -12,6 +12,7 @@ use openzeppelin::tests::mocks::non_implementing_mock::NonImplementingMock; use openzeppelin::tests::utils::constants::{ DATA, ZERO, OWNER, RECIPIENT, SPENDER, OPERATOR, OTHER, NAME, SYMBOL, URI, TOKEN_ID, PUBKEY, }; +use openzeppelin::tests::utils::debug::DebugContractAddress; use openzeppelin::tests::utils; use openzeppelin::token::erc721::ERC721Component::{ ERC721CamelOnlyImpl, ERC721MetadataCamelOnlyImpl @@ -76,18 +77,18 @@ fn test_initialize() { state.initializer(NAME, SYMBOL); - assert(state.name() == NAME, 'Name should be NAME'); - assert(state.symbol() == SYMBOL, 'Symbol should be SYMBOL'); - assert(state.balance_of(OWNER()) == 0, 'Balance should be zero'); + assert_eq!(state.name(), NAME); + assert_eq!(state.symbol(), SYMBOL); + assert!(state.balance_of(OWNER()).is_zero()); - assert(mock_state.supports_interface(erc721::interface::IERC721_ID), 'Missing interface ID'); - assert( - mock_state.supports_interface(erc721::interface::IERC721_METADATA_ID), - 'Missing interface ID' - ); - assert( - mock_state.supports_interface(introspection::interface::ISRC5_ID), 'Missing interface ID' - ); + let supports_erc721 = mock_state.supports_interface(erc721::interface::IERC721_ID); + let supports_erc721_metadata = mock_state + .supports_interface(erc721::interface::IERC721_METADATA_ID); + let supports_src5 = mock_state.supports_interface(introspection::interface::ISRC5_ID); + + assert!(supports_erc721, "Should implement IERC721"); + assert!(supports_erc721_metadata, "Should implement IERC721Metadata"); + assert!(supports_src5, "Should implement ISRC5"); } // @@ -97,7 +98,7 @@ fn test_initialize() { #[test] fn test_balance_of() { let state = setup(); - assert(state.balance_of(OWNER()) == 1, 'Should return balance'); + assert_eq!(state.balance_of(OWNER()), 1); } #[test] @@ -110,7 +111,7 @@ fn test_balance_of_zero() { #[test] fn test_owner_of() { let state = setup(); - assert(state.owner_of(TOKEN_ID) == OWNER(), 'Should return owner'); + assert_eq!(state.owner_of(TOKEN_ID), OWNER()); } #[test] @@ -133,9 +134,9 @@ fn test_get_approved() { let spender = SPENDER(); let token_id = TOKEN_ID; - assert(state.get_approved(token_id) == ZERO(), 'Should return non-approval'); + assert_eq!(state.get_approved(token_id), ZERO()); state._approve(spender, token_id); - assert(state.get_approved(token_id) == spender, 'Should return approval'); + assert_eq!(state.get_approved(token_id), spender); } #[test] @@ -151,21 +152,27 @@ fn test__exists() { let zero = ZERO(); let token_id = TOKEN_ID; - assert(!state._exists(token_id), 'Token should not exist'); + let not_exists = !state._exists(token_id); + assert!(not_exists); + let mut owner = state.ERC721_owners.read(token_id); - assert(owner == zero, ''); + assert!(owner.is_zero()); state._mint(RECIPIENT(), token_id); - assert(state._exists(token_id), 'Token should exist'); + let exists = state._exists(token_id); + assert!(exists); + owner = state.ERC721_owners.read(token_id); - assert(owner == RECIPIENT(), 'Invalid owner'); + assert_eq!(owner, RECIPIENT()); state._burn(token_id); - assert(!state._exists(token_id), 'Token should not exist'); + let not_exists = !state._exists(token_id); + assert!(not_exists); + owner = state.ERC721_owners.read(token_id); - assert(owner == zero, 'Invalid owner'); + assert!(owner.is_zero()); } // @@ -180,7 +187,8 @@ fn test_approve_from_owner() { state.approve(SPENDER(), TOKEN_ID); assert_event_approval(OWNER(), SPENDER(), TOKEN_ID); - assert(state.get_approved(TOKEN_ID) == SPENDER(), 'Spender not approved correctly'); + let approved = state.get_approved(TOKEN_ID); + assert_eq!(approved, SPENDER()); } #[test] @@ -195,7 +203,8 @@ fn test_approve_from_operator() { state.approve(SPENDER(), TOKEN_ID); assert_event_approval(OWNER(), SPENDER(), TOKEN_ID); - assert(state.get_approved(TOKEN_ID) == SPENDER(), 'Spender not approved correctly'); + let approved = state.get_approved(TOKEN_ID); + assert_eq!(approved, SPENDER()); } #[test] @@ -229,7 +238,8 @@ fn test__approve() { state._approve(SPENDER(), TOKEN_ID); assert_event_approval(OWNER(), SPENDER(), TOKEN_ID); - assert(state.get_approved(TOKEN_ID) == SPENDER(), 'Spender not approved correctly'); + let approved = state.get_approved(TOKEN_ID); + assert_eq!(approved, SPENDER()); } #[test] @@ -255,17 +265,20 @@ fn test_set_approval_for_all() { let mut state = COMPONENT_STATE(); testing::set_caller_address(OWNER()); - assert(!state.is_approved_for_all(OWNER(), OPERATOR()), 'Invalid default value'); + let not_approved_for_all = !state.is_approved_for_all(OWNER(), OPERATOR()); + assert!(not_approved_for_all); state.set_approval_for_all(OPERATOR(), true); assert_event_approval_for_all(OWNER(), OPERATOR(), true); - assert(state.is_approved_for_all(OWNER(), OPERATOR()), 'Operator not approved correctly'); + let is_approved_for_all = state.is_approved_for_all(OWNER(), OPERATOR()); + assert!(is_approved_for_all); state.set_approval_for_all(OPERATOR(), false); assert_event_approval_for_all(OWNER(), OPERATOR(), false); - assert(!state.is_approved_for_all(OWNER(), OPERATOR()), 'Approval not revoked correctly'); + let not_approved_for_all = !state.is_approved_for_all(OWNER(), OPERATOR()); + assert!(not_approved_for_all); } #[test] @@ -287,17 +300,21 @@ fn test_set_approval_for_all_owner_equal_operator_false() { #[test] fn test__set_approval_for_all() { let mut state = COMPONENT_STATE(); - assert(!state.is_approved_for_all(OWNER(), OPERATOR()), 'Invalid default value'); + + let not_approved_for_all = !state.is_approved_for_all(OWNER(), OPERATOR()); + assert!(not_approved_for_all); state._set_approval_for_all(OWNER(), OPERATOR(), true); assert_event_approval_for_all(OWNER(), OPERATOR(), true); - assert(state.is_approved_for_all(OWNER(), OPERATOR()), 'Operator not approved correctly'); + let is_approved_for_all = state.is_approved_for_all(OWNER(), OPERATOR()); + assert!(is_approved_for_all); state._set_approval_for_all(OWNER(), OPERATOR(), false); assert_event_approval_for_all(OWNER(), OPERATOR(), false); - assert(!state.is_approved_for_all(OWNER(), OPERATOR()), 'Operator not approved correctly'); + let not_approved_for_all = !state.is_approved_for_all(OWNER(), OPERATOR()); + assert!(not_approved_for_all); } #[test] @@ -329,7 +346,9 @@ fn test_transfer_from_owner() { utils::drop_event(ZERO()); assert_state_before_transfer(owner, recipient, token_id); - assert(state.get_approved(token_id) == OTHER(), 'Approval not implicitly reset'); + + let approved = state.get_approved(token_id); + assert_eq!(approved, OTHER()); testing::set_caller_address(owner); state.transfer_from(owner, recipient, token_id); @@ -349,7 +368,9 @@ fn test_transferFrom_owner() { utils::drop_event(ZERO()); assert_state_before_transfer(owner, recipient, token_id); - assert(state.get_approved(token_id) == OTHER(), 'Approval not implicitly reset'); + + let approved = state.get_approved(token_id); + assert_eq!(approved, OTHER()); testing::set_caller_address(owner); state.transferFrom(owner, recipient, token_id); @@ -393,30 +414,30 @@ fn test_transferFrom_to_zero() { fn test_transfer_from_to_owner() { let mut state = setup(); - assert(state.owner_of(TOKEN_ID) == OWNER(), 'Ownership before'); - assert(state.balance_of(OWNER()) == 1, 'Balance of owner before'); + assert_eq!(state.owner_of(TOKEN_ID), OWNER()); + assert_eq!(state.balance_of(OWNER()), 1); testing::set_caller_address(OWNER()); state.transfer_from(OWNER(), OWNER(), TOKEN_ID); assert_event_transfer(OWNER(), OWNER(), TOKEN_ID); - assert(state.owner_of(TOKEN_ID) == OWNER(), 'Ownership after'); - assert(state.balance_of(OWNER()) == 1, 'Balance of owner after'); + assert_eq!(state.owner_of(TOKEN_ID), OWNER()); + assert_eq!(state.balance_of(OWNER()), 1); } #[test] fn test_transferFrom_to_owner() { let mut state = setup(); - assert(state.owner_of(TOKEN_ID) == OWNER(), 'Ownership before'); - assert(state.balance_of(OWNER()) == 1, 'Balance of owner before'); + assert_eq!(state.owner_of(TOKEN_ID), OWNER()); + assert_eq!(state.balance_of(OWNER()), 1); testing::set_caller_address(OWNER()); state.transferFrom(OWNER(), OWNER(), TOKEN_ID); assert_event_transfer(OWNER(), OWNER(), TOKEN_ID); - assert(state.owner_of(TOKEN_ID) == OWNER(), 'Ownership after'); - assert(state.balance_of(OWNER()) == 1, 'Balance of owner after'); + assert_eq!(state.owner_of(TOKEN_ID), OWNER()); + assert_eq!(state.balance_of(OWNER()), 1); } #[test] @@ -756,15 +777,15 @@ fn test_safe_transfer_from_to_owner() { state._mint(owner, token_id); utils::drop_event(ZERO()); - assert(state.owner_of(token_id) == owner, 'Ownership before'); - assert(state.balance_of(owner) == 1, 'Balance of owner before'); + assert_eq!(state.owner_of(token_id), owner); + assert_eq!(state.balance_of(owner), 1); testing::set_caller_address(owner); state.safe_transfer_from(owner, owner, token_id, DATA(true)); assert_event_transfer(owner, owner, token_id); - assert(state.owner_of(token_id) == owner, 'Ownership after'); - assert(state.balance_of(owner) == 1, 'Balance of owner after'); + assert_eq!(state.owner_of(token_id), owner); + assert_eq!(state.balance_of(owner), 1); } #[test] @@ -776,15 +797,15 @@ fn test_safeTransferFrom_to_owner() { state._mint(owner, token_id); utils::drop_event(ZERO()); - assert(state.owner_of(token_id) == owner, 'Ownership before'); - assert(state.balance_of(owner) == 1, 'Balance of owner before'); + assert_eq!(state.owner_of(token_id), owner); + assert_eq!(state.balance_of(owner), 1); testing::set_caller_address(owner); state.safeTransferFrom(owner, owner, token_id, DATA(true)); assert_event_transfer(owner, owner, token_id); - assert(state.owner_of(token_id) == owner, 'Ownership after'); - assert(state.balance_of(owner) == 1, 'Balance of owner after'); + assert_eq!(state.owner_of(token_id), owner); + assert_eq!(state.balance_of(owner), 1); } #[test] @@ -796,15 +817,15 @@ fn test_safe_transfer_from_to_owner_camel() { state._mint(owner, token_id); utils::drop_event(ZERO()); - assert(state.owner_of(token_id) == owner, 'Ownership before'); - assert(state.balance_of(owner) == 1, 'Balance of owner before'); + assert_eq!(state.owner_of(token_id), owner); + assert_eq!(state.balance_of(owner), 1); testing::set_caller_address(owner); state.safe_transfer_from(owner, owner, token_id, DATA(true)); assert_event_transfer(owner, owner, token_id); - assert(state.owner_of(token_id) == owner, 'Ownership after'); - assert(state.balance_of(owner) == 1, 'Balance of owner after'); + assert_eq!(state.owner_of(token_id), owner); + assert_eq!(state.balance_of(owner), 1); } #[test] @@ -816,15 +837,15 @@ fn test_safeTransferFrom_to_owner_camel() { state._mint(owner, token_id); utils::drop_event(ZERO()); - assert(state.owner_of(token_id) == owner, 'Ownership before'); - assert(state.balance_of(owner) == 1, 'Balance of owner before'); + assert_eq!(state.owner_of(token_id), owner); + assert_eq!(state.balance_of(owner), 1); testing::set_caller_address(owner); state.safeTransferFrom(owner, owner, token_id, DATA(true)); assert_event_transfer(owner, owner, token_id); - assert(state.owner_of(token_id) == owner, 'Ownership after'); - assert(state.balance_of(owner) == 1, 'Balance of owner after'); + assert_eq!(state.owner_of(token_id), owner); + assert_eq!(state.balance_of(owner), 1); } #[test] @@ -1191,16 +1212,16 @@ fn test__burn() { state._approve(OTHER(), TOKEN_ID); utils::drop_event(ZERO()); - assert(state.owner_of(TOKEN_ID) == OWNER(), 'Ownership before'); - assert(state.balance_of(OWNER()) == 1, 'Balance of owner before'); - assert(state.get_approved(TOKEN_ID) == OTHER(), 'Approval before'); + assert_eq!(state.owner_of(TOKEN_ID), OWNER()); + assert_eq!(state.balance_of(OWNER()), 1); + assert_eq!(state.get_approved(TOKEN_ID), OTHER()); state._burn(TOKEN_ID); assert_event_transfer(OWNER(), ZERO(), TOKEN_ID); - assert(state.ERC721_owners.read(TOKEN_ID) == ZERO(), 'Ownership after'); - assert(state.balance_of(OWNER()) == 0, 'Balance of owner after'); - assert(state.ERC721_token_approvals.read(TOKEN_ID) == ZERO(), 'Approval after'); + assert_eq!(state.ERC721_owners.read(TOKEN_ID), ZERO()); + assert_eq!(state.balance_of(OWNER()), 0); + assert_eq!(state.ERC721_token_approvals.read(TOKEN_ID), ZERO()); } #[test] @@ -1218,9 +1239,9 @@ fn test__burn_nonexistent() { fn test__set_token_uri() { let mut state = setup(); - assert(state.token_uri(TOKEN_ID) == 0, 'URI should be 0'); + assert!(state.token_uri(TOKEN_ID).is_zero()); state._set_token_uri(TOKEN_ID, URI); - assert(state.token_uri(TOKEN_ID) == URI, 'URI should be set'); + assert_eq!(state.token_uri(TOKEN_ID), URI); } #[test] @@ -1238,38 +1259,38 @@ fn assert_state_before_transfer( owner: ContractAddress, recipient: ContractAddress, token_id: u256 ) { let state = COMPONENT_STATE(); - assert(state.owner_of(token_id) == owner, 'Ownership before'); - assert(state.balance_of(owner) == 1, 'Balance of owner before'); - assert(state.balance_of(recipient) == 0, 'Balance of recipient before'); + assert_eq!(state.owner_of(token_id), owner); + assert_eq!(state.balance_of(owner), 1); + assert!(state.balance_of(recipient).is_zero()); } fn assert_state_after_transfer(owner: ContractAddress, recipient: ContractAddress, token_id: u256) { let state = COMPONENT_STATE(); - assert(state.owner_of(token_id) == recipient, 'Ownership after'); - assert(state.balance_of(owner) == 0, 'Balance of owner after'); - assert(state.balance_of(recipient) == 1, 'Balance of recipient after'); - assert(state.get_approved(token_id) == ZERO(), 'Approval not implicitly reset'); + assert_eq!(state.owner_of(token_id), recipient); + assert_eq!(state.balance_of(owner), 0); + assert_eq!(state.balance_of(recipient), 1); + assert!(state.get_approved(token_id).is_zero()); } fn assert_state_before_mint(recipient: ContractAddress) { let state = COMPONENT_STATE(); - assert(state.balance_of(recipient) == 0, 'Balance of recipient before'); + assert!(state.balance_of(recipient).is_zero()); } fn assert_state_after_mint(recipient: ContractAddress, token_id: u256) { let state = COMPONENT_STATE(); - assert(state.owner_of(token_id) == recipient, 'Ownership after'); - assert(state.balance_of(recipient) == 1, 'Balance of recipient after'); - assert(state.get_approved(token_id) == ZERO(), 'Approval implicitly set'); + assert_eq!(state.owner_of(token_id), recipient); + assert_eq!(state.balance_of(recipient), 1); + assert!(state.get_approved(token_id).is_zero()); } fn assert_event_approval_for_all( owner: ContractAddress, operator: ContractAddress, approved: bool ) { let event = utils::pop_log::(ZERO()).unwrap(); - assert(event.owner == owner, 'Invalid `owner`'); - assert(event.operator == operator, 'Invalid `operator`'); - assert(event.approved == approved, 'Invalid `approved`'); + assert_eq!(event.owner, owner); + assert_eq!(event.operator, operator); + assert_eq!(event.approved, approved); utils::assert_no_events_left(ZERO()); // Check indexed keys @@ -1281,9 +1302,9 @@ fn assert_event_approval_for_all( fn assert_event_approval(owner: ContractAddress, approved: ContractAddress, token_id: u256) { let event = utils::pop_log::(ZERO()).unwrap(); - assert(event.owner == owner, 'Invalid `owner`'); - assert(event.approved == approved, 'Invalid `approved`'); - assert(event.token_id == token_id, 'Invalid `token_id`'); + assert_eq!(event.owner, owner); + assert_eq!(event.approved, approved); + assert_eq!(event.token_id, token_id); utils::assert_no_events_left(ZERO()); // Check indexed keys @@ -1296,9 +1317,9 @@ fn assert_event_approval(owner: ContractAddress, approved: ContractAddress, toke fn assert_event_transfer(from: ContractAddress, to: ContractAddress, token_id: u256) { let event = utils::pop_log::(ZERO()).unwrap(); - assert(event.from == from, 'Invalid `from`'); - assert(event.to == to, 'Invalid `to`'); - assert(event.token_id == token_id, 'Invalid `token_id`'); + assert_eq!(event.from, from); + assert_eq!(event.to, to); + assert_eq!(event.token_id, token_id); utils::assert_no_events_left(ZERO()); // Check indexed keys diff --git a/src/tests/token/test_erc721_receiver.cairo b/src/tests/token/test_erc721_receiver.cairo index 52af8bcc7..d1750cffd 100644 --- a/src/tests/token/test_erc721_receiver.cairo +++ b/src/tests/token/test_erc721_receiver.cairo @@ -15,24 +15,26 @@ fn STATE() -> DualCaseERC721ReceiverMock::ContractState { fn test_initializer() { let mut state = STATE(); state.erc721_receiver.initializer(); - assert(state.src5.supports_interface(IERC721_RECEIVER_ID), 'Missing interface ID'); - assert(state.src5.supports_interface(ISRC5_ID), 'Missing interface ID'); + + let supports_erc721_receiver = state.src5.supports_interface(IERC721_RECEIVER_ID); + let supports_src5 = state.src5.supports_interface(ISRC5_ID); + + assert!(supports_erc721_receiver, "Should implement IERC721Receiver"); + assert!(supports_src5, "Should implement ISRC5"); } #[test] fn test_on_erc721_received() { let mut state = STATE(); let data = array![]; - assert( - state - .erc721_receiver - .on_erc721_received(OPERATOR(), OWNER(), TOKEN_ID, data.span()) == IERC721_RECEIVER_ID, - 'Should return receiver ID' - ); - assert( - state - .erc721_receiver - .onERC721Received(OPERATOR(), OWNER(), TOKEN_ID, data.span()) == IERC721_RECEIVER_ID, - 'Should return receiver ID' - ); + + let on_erc721_received = state + .erc721_receiver + .on_erc721_received(OPERATOR(), OWNER(), TOKEN_ID, data.span()); + assert_eq!(on_erc721_received, IERC721_RECEIVER_ID, "Should return receiver ID"); + + let onERC721Received = state + .erc721_receiver + .onERC721Received(OPERATOR(), OWNER(), TOKEN_ID, data.span()); + assert_eq!(onERC721Received, IERC721_RECEIVER_ID, "Should return receiver ID"); } diff --git a/src/tests/utils.cairo b/src/tests/utils.cairo index 028b8b24c..adadd304a 100644 --- a/src/tests/utils.cairo +++ b/src/tests/utils.cairo @@ -27,8 +27,8 @@ fn pop_log, +starknet::Event>(address: ContractAddress) -> Option keys.pop_front(); let ret = starknet::Event::deserialize(ref keys, ref data); - assert(data.is_empty(), 'Event has extra data'); - assert(keys.is_empty(), 'Event has extra keys'); + assert!(data.is_empty(), "Event has extra data"); + assert!(keys.is_empty(), "Event has extra keys"); ret } @@ -41,11 +41,11 @@ fn assert_indexed_keys, +starknet::Event>(event: T, expected_keys let mut data = array![]; event.append_keys_and_data(ref keys, ref data); - assert(expected_keys == keys.span(), 'Invalid keys'); + assert!(expected_keys == keys.span()); } fn assert_no_events_left(address: ContractAddress) { - assert(testing::pop_log_raw(address).is_none(), 'Events remaining on queue'); + assert!(testing::pop_log_raw(address).is_none(), "Events remaining on queue"); } fn drop_event(address: ContractAddress) { From 4c2a002ba6176e56dbcce1819421b1fbfc3e3ee3 Mon Sep 17 00:00:00 2001 From: Eric Nordelo Date: Wed, 10 Jan 2024 10:54:21 +0100 Subject: [PATCH 10/15] Update src/tests/token/test_erc20.cairo Co-authored-by: Andrew Fleming --- src/tests/token/test_erc20.cairo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tests/token/test_erc20.cairo b/src/tests/token/test_erc20.cairo index 72be7189f..1f1e76e71 100644 --- a/src/tests/token/test_erc20.cairo +++ b/src/tests/token/test_erc20.cairo @@ -243,11 +243,11 @@ fn test_transfer_from() { assert_only_event_transfer(OWNER(), RECIPIENT(), VALUE); let allowance = state.allowance(OWNER(), SPENDER()); + assert_eq!(allowance, 0); assert_eq!(state.balance_of(RECIPIENT()), VALUE); assert_eq!(state.balance_of(OWNER()), SUPPLY - VALUE); assert_eq!(state.total_supply(), SUPPLY); - assert_eq!(allowance, 0); } #[test] From d8af8bee18f4d7c3b63b98bbf17da85fb50932ec Mon Sep 17 00:00:00 2001 From: Eric Nordelo Date: Wed, 10 Jan 2024 10:54:44 +0100 Subject: [PATCH 11/15] Update src/tests/token/test_erc20.cairo Co-authored-by: Andrew Fleming --- src/tests/token/test_erc20.cairo | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/tests/token/test_erc20.cairo b/src/tests/token/test_erc20.cairo index 1f1e76e71..6d68d233c 100644 --- a/src/tests/token/test_erc20.cairo +++ b/src/tests/token/test_erc20.cairo @@ -307,10 +307,11 @@ fn test_transferFrom() { assert_only_event_transfer(OWNER(), RECIPIENT(), VALUE); let allowance = state.allowance(OWNER(), SPENDER()); + assert_eq!(allowance, 0); - assert_eq!(state.balanceOf(RECIPIENT()), VALUE); - assert_eq!(state.balanceOf(OWNER()), SUPPLY - VALUE); - assert_eq!(state.totalSupply(), SUPPLY); + assert_eq!(state.balance_of(RECIPIENT()), VALUE); + assert_eq!(state.balance_of(OWNER()), SUPPLY - VALUE); + assert_eq!(state.total_supply(), SUPPLY); assert_eq!(allowance, 0); } From 94968ff199c446a2ab1c154d8c395b509362bb10 Mon Sep 17 00:00:00 2001 From: Eric Nordelo Date: Wed, 10 Jan 2024 11:01:47 +0100 Subject: [PATCH 12/15] feat: apply review updates --- src/tests/access/test_accesscontrol.cairo | 4 ++-- src/tests/access/test_dual_accesscontrol.cairo | 4 ++-- src/tests/account/test_account.cairo | 9 ++++----- src/tests/account/test_dual_account.cairo | 8 ++++---- src/tests/introspection/test_dual_src5.cairo | 8 ++++---- src/tests/introspection/test_src5.cairo | 4 ++-- src/tests/mocks/erc721_mocks.cairo | 6 +++--- src/tests/mocks/erc721_receiver_mocks.cairo | 6 +++--- src/tests/presets/test_account.cairo | 14 ++++++++------ src/tests/presets/test_erc721.cairo | 4 ++-- src/tests/token/test_dual721.cairo | 8 ++++---- src/tests/token/test_erc20.cairo | 1 - src/tests/token/test_erc721.cairo | 12 ++++++------ src/tests/token/test_erc721_receiver.cairo | 8 ++++---- 14 files changed, 48 insertions(+), 48 deletions(-) diff --git a/src/tests/access/test_accesscontrol.cairo b/src/tests/access/test_accesscontrol.cairo index 81fd7f650..ac97f0d52 100644 --- a/src/tests/access/test_accesscontrol.cairo +++ b/src/tests/access/test_accesscontrol.cairo @@ -46,8 +46,8 @@ fn setup() -> ComponentState { fn test_initializer() { let mut state = COMPONENT_STATE(); state.initializer(); - let supported = CONTRACT_STATE().supports_interface(IACCESSCONTROL_ID); - assert!(supported, "Should implement IACCESSCONTROL"); + let supports_iaccesscontrol = CONTRACT_STATE().supports_interface(IACCESSCONTROL_ID); + assert!(supports_iaccesscontrol); } // diff --git a/src/tests/access/test_dual_accesscontrol.cairo b/src/tests/access/test_dual_accesscontrol.cairo index a823c9f16..efd444210 100644 --- a/src/tests/access/test_dual_accesscontrol.cairo +++ b/src/tests/access/test_dual_accesscontrol.cairo @@ -63,8 +63,8 @@ fn setup_accesscontrol_panic() -> (DualCaseAccessControl, DualCaseAccessControl) #[test] fn test_dual_supports_interface() { let (dispatcher, _) = setup_snake(); - let supported = dispatcher.supports_interface(IACCESSCONTROL_ID); - assert!(supported, "Should implement IACCESSCONTROL"); + let supports_iaccesscontrol = dispatcher.supports_interface(IACCESSCONTROL_ID); + assert!(supports_iaccesscontrol); } #[test] diff --git a/src/tests/account/test_account.cairo b/src/tests/account/test_account.cairo index 0d24feb7f..1b849571f 100644 --- a/src/tests/account/test_account.cairo +++ b/src/tests/account/test_account.cairo @@ -1,4 +1,3 @@ -use core::array::ArrayTrait; use openzeppelin::account::AccountComponent::{InternalTrait, SRC6CamelOnlyImpl}; use openzeppelin::account::AccountComponent::{OwnerAdded, OwnerRemoved}; use openzeppelin::account::AccountComponent::{PublicKeyCamelImpl, PublicKeyImpl}; @@ -456,11 +455,11 @@ fn test_initializer() { let public_key = state.get_public_key(); assert_eq!(public_key, PUBKEY); - let supports_default_interface = mock_state.supports_interface(ISRC5_ID); - assert!(supports_default_interface, "Should implement ISRC5"); + let supports_isrc5 = mock_state.supports_interface(ISRC5_ID); + assert!(supports_isrc5); - let supports_account_interface = mock_state.supports_interface(ISRC6_ID); - assert!(supports_account_interface, "Should implement ISRC6"); + let supports_isrc6 = mock_state.supports_interface(ISRC6_ID); + assert!(supports_isrc6); } #[test] diff --git a/src/tests/account/test_dual_account.cairo b/src/tests/account/test_dual_account.cairo index 42152fe02..08e711c24 100644 --- a/src/tests/account/test_dual_account.cairo +++ b/src/tests/account/test_dual_account.cairo @@ -136,8 +136,8 @@ fn test_dual_is_valid_signature_exists_and_panics() { #[test] fn test_dual_supports_interface() { let (snake_dispatcher, target) = setup_snake(); - let supported = snake_dispatcher.supports_interface(ISRC5_ID); - assert!(supported, "Should implement ISRC5"); + let supports_isrc5 = snake_dispatcher.supports_interface(ISRC5_ID); + assert!(supports_isrc5); } #[test] @@ -219,8 +219,8 @@ fn test_dual_isValidSignature_exists_and_panics() { #[test] fn test_dual_supportsInterface() { let (camel_dispatcher, _) = setup_camel(); - let supported = camel_dispatcher.supports_interface(ISRC5_ID); - assert!(supported, "Should implement ISRC5"); + let supports_isrc5 = camel_dispatcher.supports_interface(ISRC5_ID); + assert!(supports_isrc5); } #[test] diff --git a/src/tests/introspection/test_dual_src5.cairo b/src/tests/introspection/test_dual_src5.cairo index c3e233f1b..2240bd617 100644 --- a/src/tests/introspection/test_dual_src5.cairo +++ b/src/tests/introspection/test_dual_src5.cairo @@ -46,8 +46,8 @@ fn setup_src5_panic() -> (DualCaseSRC5, DualCaseSRC5) { #[test] fn test_dual_supports_interface() { let dispatcher = setup_snake(); - let supported = dispatcher.supports_interface(ISRC5_ID); - assert!(supported, "Should implement ISRC5"); + let supports_isrc5 = dispatcher.supports_interface(ISRC5_ID); + assert!(supports_isrc5); } #[test] @@ -71,8 +71,8 @@ fn test_dual_supports_interface_exists_and_panics() { #[test] fn test_dual_supportsInterface() { let dispatcher = setup_camel(); - let supported = dispatcher.supports_interface(ISRC5_ID); - assert!(supported, "Should implement ISRC5"); + let supports_isrc5 = dispatcher.supports_interface(ISRC5_ID); + assert!(supports_isrc5); } #[test] diff --git a/src/tests/introspection/test_src5.cairo b/src/tests/introspection/test_src5.cairo index 7dd681033..d7726b7ff 100644 --- a/src/tests/introspection/test_src5.cairo +++ b/src/tests/introspection/test_src5.cairo @@ -14,8 +14,8 @@ fn COMPONENT_STATE() -> ComponentState { #[test] fn test_default_behavior() { let state = COMPONENT_STATE(); - let supports_default_interface = state.supports_interface(ISRC5_ID); - assert!(supports_default_interface, "Should implement ISRC5"); + let supports_isrc5 = state.supports_interface(ISRC5_ID); + assert!(supports_isrc5); } #[test] diff --git a/src/tests/mocks/erc721_mocks.cairo b/src/tests/mocks/erc721_mocks.cairo index 340c3154a..54f9fd8db 100644 --- a/src/tests/mocks/erc721_mocks.cairo +++ b/src/tests/mocks/erc721_mocks.cairo @@ -4,8 +4,8 @@ mod DualCaseERC721Mock { use openzeppelin::token::erc721::ERC721Component; use starknet::ContractAddress; - component!(path: SRC5Component, storage: src5, event: SRC5Event); component!(path: ERC721Component, storage: erc721, event: ERC721Event); + component!(path: SRC5Component, storage: src5, event: SRC5Event); // ERC721 #[abi(embed_v0)] @@ -61,8 +61,8 @@ mod SnakeERC721Mock { use openzeppelin::token::erc721::ERC721Component; use starknet::ContractAddress; - component!(path: SRC5Component, storage: src5, event: SRC5Event); component!(path: ERC721Component, storage: erc721, event: ERC721Event); + component!(path: SRC5Component, storage: src5, event: SRC5Event); // ERC721 #[abi(embed_v0)] @@ -114,8 +114,8 @@ mod CamelERC721Mock { use openzeppelin::token::erc721::ERC721Component; use starknet::ContractAddress; - component!(path: SRC5Component, storage: src5, event: SRC5Event); component!(path: ERC721Component, storage: erc721, event: ERC721Event); + component!(path: SRC5Component, storage: src5, event: SRC5Event); // ERC721 #[abi(embed_v0)] diff --git a/src/tests/mocks/erc721_receiver_mocks.cairo b/src/tests/mocks/erc721_receiver_mocks.cairo index e47cc4325..ed54696e1 100644 --- a/src/tests/mocks/erc721_receiver_mocks.cairo +++ b/src/tests/mocks/erc721_receiver_mocks.cairo @@ -6,8 +6,8 @@ mod DualCaseERC721ReceiverMock { use openzeppelin::token::erc721::ERC721ReceiverComponent; use starknet::ContractAddress; - component!(path: SRC5Component, storage: src5, event: SRC5Event); component!(path: ERC721ReceiverComponent, storage: erc721_receiver, event: ERC721ReceiverEvent); + component!(path: SRC5Component, storage: src5, event: SRC5Event); // ERC721Receiver impl ERC721ReceiverImpl = ERC721ReceiverComponent::ERC721ReceiverImpl; @@ -72,8 +72,8 @@ mod SnakeERC721ReceiverMock { use openzeppelin::token::erc721::ERC721ReceiverComponent; use starknet::ContractAddress; - component!(path: SRC5Component, storage: src5, event: SRC5Event); component!(path: ERC721ReceiverComponent, storage: erc721_receiver, event: ERC721ReceiverEvent); + component!(path: SRC5Component, storage: src5, event: SRC5Event); // ERC721Receiver impl ERC721ReceiverImpl = ERC721ReceiverComponent::ERC721ReceiverImpl; @@ -127,8 +127,8 @@ mod CamelERC721ReceiverMock { use openzeppelin::token::erc721::ERC721ReceiverComponent; use starknet::ContractAddress; - component!(path: SRC5Component, storage: src5, event: SRC5Event); component!(path: ERC721ReceiverComponent, storage: erc721_receiver, event: ERC721ReceiverEvent); + component!(path: SRC5Component, storage: src5, event: SRC5Event); // ERC721Receiver impl ERC721ReceiverCamelImpl = ERC721ReceiverComponent::ERC721ReceiverCamelImpl; diff --git a/src/tests/presets/test_account.cairo b/src/tests/presets/test_account.cairo index b4f8937e8..669adcdce 100644 --- a/src/tests/presets/test_account.cairo +++ b/src/tests/presets/test_account.cairo @@ -1,4 +1,3 @@ -use core::array::ArrayTrait; use openzeppelin::account::AccountComponent::{OwnerAdded, OwnerRemoved}; use openzeppelin::account::AccountComponent::{TRANSACTION_VERSION, QUERY_VERSION}; use openzeppelin::account::interface::ISRC6_ID; @@ -67,8 +66,8 @@ fn test_constructor() { let supports_isrc5 = Account::SRC5Impl::supports_interface(@state, ISRC5_ID); let supports_isrc6 = Account::SRC5Impl::supports_interface(@state, ISRC6_ID); - assert!(supports_isrc5, "Should implement ISRC5"); - assert!(supports_isrc6, "Should implement ISRC6"); + assert!(supports_isrc5); + assert!(supports_isrc6); } // @@ -177,9 +176,12 @@ fn test_isValidSignature_bad_sig() { #[test] fn test_supports_interface() { let dispatcher = setup_dispatcher(); - assert!(dispatcher.supports_interface(ISRC5_ID), "Should implement ISRC5"); - assert!(dispatcher.supports_interface(ISRC6_ID), "Should implement ISRC6"); - assert!(!dispatcher.supports_interface(0x123), "Should not implement 0x123"); + let supports_isrc5 = dispatcher.supports_interface(ISRC5_ID); + let supports_isrc6 = dispatcher.supports_interface(ISRC6_ID); + let doesnt_support_0x123 = !dispatcher.supports_interface(0x123); + assert!(supports_isrc5); + assert!(supports_isrc6); + assert!(doesnt_support_0x123); } // diff --git a/src/tests/presets/test_erc721.cairo b/src/tests/presets/test_erc721.cairo index b466e09e4..6d2bf3346 100644 --- a/src/tests/presets/test_erc721.cairo +++ b/src/tests/presets/test_erc721.cairo @@ -146,8 +146,8 @@ fn test_constructor() { if interface_ids.len() == 0 { break; } - let supported = dispatcher.supports_interface(id); - assert!(supported, "Should implement interface"); + let supports_isrc5 = dispatcher.supports_interface(id); + assert!(supports_isrc5); }; // Check token balance and owner diff --git a/src/tests/token/test_dual721.cairo b/src/tests/token/test_dual721.cairo index 9026ffd55..d398b2b75 100644 --- a/src/tests/token/test_dual721.cairo +++ b/src/tests/token/test_dual721.cairo @@ -323,8 +323,8 @@ fn test_dual_token_uri_exists_and_panics() { #[test] fn test_dual_supports_interface() { let (dispatcher, _) = setup_snake(); - let supported = dispatcher.supports_interface(IERC721_ID); - assert!(supported, "Should implement IERC721"); + let supports_ierc721 = dispatcher.supports_interface(IERC721_ID); + assert!(supports_ierc721); } #[test] @@ -474,8 +474,8 @@ fn test_dual_tokenURI_exists_and_panics() { #[test] fn test_dual_supportsInterface() { let (dispatcher, _) = setup_camel(); - let supported = dispatcher.supports_interface(IERC721_ID); - assert!(supported, "Should implement IERC721"); + let supports_ierc721 = dispatcher.supports_interface(IERC721_ID); + assert!(supports_ierc721); } #[test] diff --git a/src/tests/token/test_erc20.cairo b/src/tests/token/test_erc20.cairo index 72be7189f..1f55bc238 100644 --- a/src/tests/token/test_erc20.cairo +++ b/src/tests/token/test_erc20.cairo @@ -1,4 +1,3 @@ -use core::num::traits::zero::Zero; use integer::BoundedInt; use openzeppelin::tests::mocks::erc20_mocks::DualCaseERC20Mock; use openzeppelin::tests::utils::constants::{ diff --git a/src/tests/token/test_erc721.cairo b/src/tests/token/test_erc721.cairo index 6c751a934..bb74ea952 100644 --- a/src/tests/token/test_erc721.cairo +++ b/src/tests/token/test_erc721.cairo @@ -81,14 +81,14 @@ fn test_initialize() { assert_eq!(state.symbol(), SYMBOL); assert!(state.balance_of(OWNER()).is_zero()); - let supports_erc721 = mock_state.supports_interface(erc721::interface::IERC721_ID); - let supports_erc721_metadata = mock_state + let supports_ierc721 = mock_state.supports_interface(erc721::interface::IERC721_ID); + let supports_ierc721_metadata = mock_state .supports_interface(erc721::interface::IERC721_METADATA_ID); - let supports_src5 = mock_state.supports_interface(introspection::interface::ISRC5_ID); + let supports_isrc5 = mock_state.supports_interface(introspection::interface::ISRC5_ID); - assert!(supports_erc721, "Should implement IERC721"); - assert!(supports_erc721_metadata, "Should implement IERC721Metadata"); - assert!(supports_src5, "Should implement ISRC5"); + assert!(supports_ierc721); + assert!(supports_ierc721_metadata); + assert!(supports_isrc5); } // diff --git a/src/tests/token/test_erc721_receiver.cairo b/src/tests/token/test_erc721_receiver.cairo index d1750cffd..c7c8c4f14 100644 --- a/src/tests/token/test_erc721_receiver.cairo +++ b/src/tests/token/test_erc721_receiver.cairo @@ -16,11 +16,11 @@ fn test_initializer() { let mut state = STATE(); state.erc721_receiver.initializer(); - let supports_erc721_receiver = state.src5.supports_interface(IERC721_RECEIVER_ID); - let supports_src5 = state.src5.supports_interface(ISRC5_ID); + let supports_ierc721_receiver = state.src5.supports_interface(IERC721_RECEIVER_ID); + let supports_isrc5 = state.src5.supports_interface(ISRC5_ID); - assert!(supports_erc721_receiver, "Should implement IERC721Receiver"); - assert!(supports_src5, "Should implement ISRC5"); + assert!(supports_ierc721_receiver); + assert!(supports_isrc5); } #[test] From aa1f4a5573ae17ca4dadde3103b3802080bfdd5f Mon Sep 17 00:00:00 2001 From: Eric Nordelo Date: Tue, 16 Jan 2024 11:38:15 +0100 Subject: [PATCH 13/15] Update src/tests/access/test_dual_accesscontrol.cairo Co-authored-by: Andrew Fleming --- src/tests/access/test_dual_accesscontrol.cairo | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tests/access/test_dual_accesscontrol.cairo b/src/tests/access/test_dual_accesscontrol.cairo index efd444210..aaafe9f71 100644 --- a/src/tests/access/test_dual_accesscontrol.cairo +++ b/src/tests/access/test_dual_accesscontrol.cairo @@ -204,8 +204,8 @@ fn test_dual_renounce_role_exists_and_panics() { fn test_dual_supportsInterface() { let (dispatcher, _) = setup_camel(); - let supported = dispatcher.supports_interface(IACCESSCONTROL_ID); - assert!(supported, "Should support IACCESSCONTROL"); + let supports_iaccesscontrol = dispatcher.supports_interface(IACCESSCONTROL_ID); + assert!(supports_iaccesscontrol); } #[test] From e2b498e13961ef1d9314ba2fdb23a72c3752e190 Mon Sep 17 00:00:00 2001 From: Eric Nordelo Date: Sat, 27 Jan 2024 12:54:46 +0100 Subject: [PATCH 14/15] feat: apply review updates --- src/tests/access/test_dual_ownable.cairo | 3 ++- src/tests/account/test_account.cairo | 4 +++- src/tests/presets/test_account.cairo | 7 +++++-- src/tests/token/test_dual20.cairo | 3 ++- src/tests/token/test_erc721.cairo | 7 ++++--- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/tests/access/test_dual_ownable.cairo b/src/tests/access/test_dual_ownable.cairo index 3266ab197..5e13b0057 100644 --- a/src/tests/access/test_dual_ownable.cairo +++ b/src/tests/access/test_dual_ownable.cairo @@ -59,8 +59,9 @@ fn test_dual_owner() { let (camel_dispatcher, _) = setup_camel(); let snake_owner = snake_dispatcher.owner(); - let camel_owner = camel_dispatcher.owner(); assert_eq!(snake_owner, OWNER()); + + let camel_owner = camel_dispatcher.owner(); assert_eq!(camel_owner, OWNER()); } diff --git a/src/tests/account/test_account.cairo b/src/tests/account/test_account.cairo index 8bb2f4713..309c777a8 100644 --- a/src/tests/account/test_account.cairo +++ b/src/tests/account/test_account.cairo @@ -359,9 +359,11 @@ fn test_multicall() { // Test return values let mut call1_serialized_retval = *ret.at(0); let mut call2_serialized_retval = *ret.at(1); + let call1_retval = Serde::::deserialize(ref call1_serialized_retval); - let call2_retval = Serde::::deserialize(ref call2_serialized_retval); assert!(call1_retval.unwrap()); + + let call2_retval = Serde::::deserialize(ref call2_serialized_retval); assert!(call2_retval.unwrap()); } diff --git a/src/tests/presets/test_account.cairo b/src/tests/presets/test_account.cairo index e0b4bb355..4ee96aaf2 100644 --- a/src/tests/presets/test_account.cairo +++ b/src/tests/presets/test_account.cairo @@ -66,8 +66,9 @@ fn test_constructor() { assert_eq!(public_key, PUBKEY); let supports_isrc5 = Account::SRC5Impl::supports_interface(@state, ISRC5_ID); - let supports_isrc6 = Account::SRC5Impl::supports_interface(@state, ISRC6_ID); assert!(supports_isrc5); + + let supports_isrc6 = Account::SRC5Impl::supports_interface(@state, ISRC6_ID); assert!(supports_isrc6); } @@ -401,9 +402,11 @@ fn test_multicall() { // Test return value let mut call1_serialized_retval = *ret.at(0); let mut call2_serialized_retval = *ret.at(1); + let call1_retval = Serde::::deserialize(ref call1_serialized_retval); - let call2_retval = Serde::::deserialize(ref call2_serialized_retval); assert!(call1_retval.unwrap()); + + let call2_retval = Serde::::deserialize(ref call2_serialized_retval); assert!(call2_retval.unwrap()); } diff --git a/src/tests/token/test_dual20.cairo b/src/tests/token/test_dual20.cairo index aab4b05a2..5e85fa1f2 100644 --- a/src/tests/token/test_dual20.cairo +++ b/src/tests/token/test_dual20.cairo @@ -57,8 +57,9 @@ fn setup_erc20_panic() -> (DualCaseERC20, DualCaseERC20) { #[test] fn test_dual_name() { let (snake_dispatcher, _) = setup_snake(); - let (camel_dispatcher, _) = setup_camel(); assert_eq!(snake_dispatcher.name(), NAME); + + let (camel_dispatcher, _) = setup_camel(); assert_eq!(camel_dispatcher.name(), NAME); } diff --git a/src/tests/token/test_erc721.cairo b/src/tests/token/test_erc721.cairo index bb74ea952..a96a33b6b 100644 --- a/src/tests/token/test_erc721.cairo +++ b/src/tests/token/test_erc721.cairo @@ -82,12 +82,13 @@ fn test_initialize() { assert!(state.balance_of(OWNER()).is_zero()); let supports_ierc721 = mock_state.supports_interface(erc721::interface::IERC721_ID); + assert!(supports_ierc721); + let supports_ierc721_metadata = mock_state .supports_interface(erc721::interface::IERC721_METADATA_ID); - let supports_isrc5 = mock_state.supports_interface(introspection::interface::ISRC5_ID); - - assert!(supports_ierc721); assert!(supports_ierc721_metadata); + + let supports_isrc5 = mock_state.supports_interface(introspection::interface::ISRC5_ID); assert!(supports_isrc5); } From 49abadf509a20e58536e1ca3fedb559055e4b581 Mon Sep 17 00:00:00 2001 From: Eric Nordelo Date: Sat, 27 Jan 2024 22:54:46 +0100 Subject: [PATCH 15/15] fix: markdown linter --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5cd235bd8..44796a95b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,4 @@ + # Changelog All notable changes to this project will be documented in this file.