diff --git a/CHANGELOG.md b/CHANGELOG.md index 8789aba12..538523cba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,3 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Utilities documentation (#825) + +### Changed + +- Use ComponentState in tests (#836) diff --git a/src/tests/access/test_accesscontrol.cairo b/src/tests/access/test_accesscontrol.cairo index 1e060a1f1..018ae499b 100644 --- a/src/tests/access/test_accesscontrol.cairo +++ b/src/tests/access/test_accesscontrol.cairo @@ -2,6 +2,7 @@ use openzeppelin::access::accesscontrol::AccessControlComponent::InternalImpl; use openzeppelin::access::accesscontrol::AccessControlComponent::RoleAdminChanged; use openzeppelin::access::accesscontrol::AccessControlComponent::RoleGranted; use openzeppelin::access::accesscontrol::AccessControlComponent::RoleRevoked; +use openzeppelin::access::accesscontrol::AccessControlComponent; use openzeppelin::access::accesscontrol::DEFAULT_ADMIN_ROLE; use openzeppelin::access::accesscontrol::interface::IACCESSCONTROL_ID; use openzeppelin::access::accesscontrol::interface::{IAccessControl, IAccessControlCamel}; @@ -18,13 +19,20 @@ use starknet::testing; // Setup // -fn STATE() -> DualCaseAccessControlMock::ContractState { +type ComponentState = + AccessControlComponent::ComponentState; + +fn CONTRACT_STATE() -> DualCaseAccessControlMock::ContractState { DualCaseAccessControlMock::contract_state_for_testing() } -fn setup() -> DualCaseAccessControlMock::ContractState { - let mut state = STATE(); - state.accesscontrol._grant_role(DEFAULT_ADMIN_ROLE, ADMIN()); +fn COMPONENT_STATE() -> ComponentState { + AccessControlComponent::component_state_for_testing() +} + +fn setup() -> ComponentState { + let mut state = COMPONENT_STATE(); + state._grant_role(DEFAULT_ADMIN_ROLE, ADMIN()); utils::drop_event(ZERO()); state } @@ -36,28 +44,9 @@ fn setup() -> DualCaseAccessControlMock::ContractState { #[test] #[available_gas(2000000)] fn test_initializer() { - let mut state = STATE(); - state.accesscontrol.initializer(); - assert(state.src5.supports_interface(IACCESSCONTROL_ID), 'Should support own interface'); -} -// -// supports_interface & supportsInterface -// - -#[test] -#[available_gas(2000000)] -fn test_supports_interface() { - let mut state = STATE(); - state.accesscontrol.initializer(); - assert(state.src5.supports_interface(IACCESSCONTROL_ID), 'Should support own interface'); -} - -#[test] -#[available_gas(2000000)] -fn test_supportsInterface() { - let mut state = STATE(); - state.accesscontrol.initializer(); - assert(state.src5.supportsInterface(IACCESSCONTROL_ID), 'Should support own interface'); + let mut state = COMPONENT_STATE(); + state.initializer(); + assert(CONTRACT_STATE().supports_interface(IACCESSCONTROL_ID), 'Should support own interface'); } // @@ -68,21 +57,20 @@ fn test_supportsInterface() { #[available_gas(2000000)] fn test_has_role() { let mut state = setup(); - assert(!state.accesscontrol.has_role(ROLE, AUTHORIZED()), 'should not have role'); - state.accesscontrol._grant_role(ROLE, AUTHORIZED()); - assert(state.accesscontrol.has_role(ROLE, AUTHORIZED()), 'should 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'); } #[test] #[available_gas(2000000)] fn test_hasRole() { let mut state = setup(); - assert(!state.accesscontrol.hasRole(ROLE, AUTHORIZED()), 'should not have role'); - state.accesscontrol._grant_role(ROLE, AUTHORIZED()); - assert(state.accesscontrol.hasRole(ROLE, AUTHORIZED()), 'should 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_only_role // @@ -92,10 +80,10 @@ fn test_hasRole() { fn test_assert_only_role() { let mut state = setup(); testing::set_caller_address(ADMIN()); - state.accesscontrol.grant_role(ROLE, AUTHORIZED()); + state.grant_role(ROLE, AUTHORIZED()); testing::set_caller_address(AUTHORIZED()); - state.accesscontrol.assert_only_role(ROLE); + state.assert_only_role(ROLE); } #[test] @@ -104,7 +92,7 @@ fn test_assert_only_role() { fn test_assert_only_role_unauthorized() { let state = setup(); testing::set_caller_address(OTHER()); - state.accesscontrol.assert_only_role(ROLE); + state.assert_only_role(ROLE); } #[test] @@ -112,10 +100,10 @@ fn test_assert_only_role_unauthorized() { #[should_panic(expected: ('Caller is missing role',))] fn test_assert_only_role_unauthorized_when_authorized_for_another_role() { let mut state = setup(); - state.accesscontrol.grant_role(ROLE, AUTHORIZED()); + state.grant_role(ROLE, AUTHORIZED()); testing::set_caller_address(AUTHORIZED()); - state.accesscontrol.assert_only_role(OTHER_ROLE); + state.assert_only_role(OTHER_ROLE); } // @@ -127,10 +115,10 @@ fn test_assert_only_role_unauthorized_when_authorized_for_another_role() { fn test_grant_role() { let mut state = setup(); testing::set_caller_address(ADMIN()); - state.accesscontrol.grant_role(ROLE, AUTHORIZED()); + state.grant_role(ROLE, AUTHORIZED()); assert_event_role_granted(ROLE, AUTHORIZED(), ADMIN()); - assert(state.accesscontrol.has_role(ROLE, AUTHORIZED()), 'Role should be granted'); + assert(state.has_role(ROLE, AUTHORIZED()), 'Role should be granted'); } #[test] @@ -138,10 +126,10 @@ fn test_grant_role() { fn test_grantRole() { let mut state = setup(); testing::set_caller_address(ADMIN()); - state.accesscontrol.grantRole(ROLE, AUTHORIZED()); + state.grantRole(ROLE, AUTHORIZED()); assert_event_role_granted(ROLE, AUTHORIZED(), ADMIN()); - assert(state.accesscontrol.hasRole(ROLE, AUTHORIZED()), 'Role should be granted'); + assert(state.hasRole(ROLE, AUTHORIZED()), 'Role should be granted'); } #[test] @@ -150,9 +138,9 @@ fn test_grant_role_multiple_times_for_granted_role() { let mut state = setup(); testing::set_caller_address(ADMIN()); - state.accesscontrol.grant_role(ROLE, AUTHORIZED()); - state.accesscontrol.grant_role(ROLE, AUTHORIZED()); - assert(state.accesscontrol.has_role(ROLE, AUTHORIZED()), 'Role should still be granted'); + state.grant_role(ROLE, AUTHORIZED()); + state.grant_role(ROLE, AUTHORIZED()); + assert(state.has_role(ROLE, AUTHORIZED()), 'Role should still be granted'); } #[test] @@ -161,9 +149,9 @@ fn test_grantRole_multiple_times_for_granted_role() { let mut state = setup(); testing::set_caller_address(ADMIN()); - state.accesscontrol.grantRole(ROLE, AUTHORIZED()); - state.accesscontrol.grantRole(ROLE, AUTHORIZED()); - assert(state.accesscontrol.hasRole(ROLE, AUTHORIZED()), 'Role should still be granted'); + state.grantRole(ROLE, AUTHORIZED()); + state.grantRole(ROLE, AUTHORIZED()); + assert(state.hasRole(ROLE, AUTHORIZED()), 'Role should still be granted'); } #[test] @@ -172,7 +160,7 @@ fn test_grantRole_multiple_times_for_granted_role() { fn test_grant_role_unauthorized() { let mut state = setup(); testing::set_caller_address(AUTHORIZED()); - state.accesscontrol.grant_role(ROLE, AUTHORIZED()); + state.grant_role(ROLE, AUTHORIZED()); } #[test] @@ -181,7 +169,7 @@ fn test_grant_role_unauthorized() { fn test_grantRole_unauthorized() { let mut state = setup(); testing::set_caller_address(AUTHORIZED()); - state.accesscontrol.grantRole(ROLE, AUTHORIZED()); + state.grantRole(ROLE, AUTHORIZED()); } // @@ -193,7 +181,7 @@ fn test_grantRole_unauthorized() { fn test_revoke_role_for_role_not_granted() { let mut state = setup(); testing::set_caller_address(ADMIN()); - state.accesscontrol.revoke_role(ROLE, AUTHORIZED()); + state.revoke_role(ROLE, AUTHORIZED()); } #[test] @@ -201,7 +189,7 @@ fn test_revoke_role_for_role_not_granted() { fn test_revokeRole_for_role_not_granted() { let mut state = setup(); testing::set_caller_address(ADMIN()); - state.accesscontrol.revokeRole(ROLE, AUTHORIZED()); + state.revokeRole(ROLE, AUTHORIZED()); } #[test] @@ -210,13 +198,13 @@ fn test_revoke_role_for_granted_role() { let mut state = setup(); testing::set_caller_address(ADMIN()); - state.accesscontrol.grant_role(ROLE, AUTHORIZED()); + state.grant_role(ROLE, AUTHORIZED()); utils::drop_event(ZERO()); - state.accesscontrol.revoke_role(ROLE, AUTHORIZED()); + state.revoke_role(ROLE, AUTHORIZED()); assert_event_role_revoked(ROLE, AUTHORIZED(), ADMIN()); - assert(!state.accesscontrol.has_role(ROLE, AUTHORIZED()), 'Role should be revoked'); + assert(!state.has_role(ROLE, AUTHORIZED()), 'Role should be revoked'); } #[test] @@ -225,13 +213,13 @@ fn test_revokeRole_for_granted_role() { let mut state = setup(); testing::set_caller_address(ADMIN()); - state.accesscontrol.grantRole(ROLE, AUTHORIZED()); + state.grantRole(ROLE, AUTHORIZED()); utils::drop_event(ZERO()); - state.accesscontrol.revokeRole(ROLE, AUTHORIZED()); + state.revokeRole(ROLE, AUTHORIZED()); assert_event_role_revoked(ROLE, AUTHORIZED(), ADMIN()); - assert(!state.accesscontrol.hasRole(ROLE, AUTHORIZED()), 'Role should be revoked'); + assert(!state.hasRole(ROLE, AUTHORIZED()), 'Role should be revoked'); } #[test] @@ -240,10 +228,10 @@ fn test_revoke_role_multiple_times_for_granted_role() { let mut state = setup(); testing::set_caller_address(ADMIN()); - state.accesscontrol.grant_role(ROLE, AUTHORIZED()); - state.accesscontrol.revoke_role(ROLE, AUTHORIZED()); - state.accesscontrol.revoke_role(ROLE, AUTHORIZED()); - assert(!state.accesscontrol.has_role(ROLE, AUTHORIZED()), 'Role should still be revoked'); + 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'); } #[test] @@ -252,10 +240,10 @@ fn test_revokeRole_multiple_times_for_granted_role() { let mut state = setup(); testing::set_caller_address(ADMIN()); - state.accesscontrol.grantRole(ROLE, AUTHORIZED()); - state.accesscontrol.revokeRole(ROLE, AUTHORIZED()); - state.accesscontrol.revokeRole(ROLE, AUTHORIZED()); - assert(!state.accesscontrol.hasRole(ROLE, AUTHORIZED()), 'Role should still be revoked'); + state.grantRole(ROLE, AUTHORIZED()); + state.revokeRole(ROLE, AUTHORIZED()); + state.revokeRole(ROLE, AUTHORIZED()); + assert(!state.hasRole(ROLE, AUTHORIZED()), 'Role should still be revoked'); } #[test] @@ -264,7 +252,7 @@ fn test_revokeRole_multiple_times_for_granted_role() { fn test_revoke_role_unauthorized() { let mut state = setup(); testing::set_caller_address(OTHER()); - state.accesscontrol.revoke_role(ROLE, AUTHORIZED()); + state.revoke_role(ROLE, AUTHORIZED()); } #[test] @@ -273,7 +261,7 @@ fn test_revoke_role_unauthorized() { fn test_revokeRole_unauthorized() { let mut state = setup(); testing::set_caller_address(OTHER()); - state.accesscontrol.revokeRole(ROLE, AUTHORIZED()); + state.revokeRole(ROLE, AUTHORIZED()); } // @@ -285,7 +273,7 @@ fn test_revokeRole_unauthorized() { fn test_renounce_role_for_role_not_granted() { let mut state = setup(); testing::set_caller_address(AUTHORIZED()); - state.accesscontrol.renounce_role(ROLE, AUTHORIZED()); + state.renounce_role(ROLE, AUTHORIZED()); } #[test] @@ -293,7 +281,7 @@ fn test_renounce_role_for_role_not_granted() { fn test_renounceRole_for_role_not_granted() { let mut state = setup(); testing::set_caller_address(AUTHORIZED()); - state.accesscontrol.renounceRole(ROLE, AUTHORIZED()); + state.renounceRole(ROLE, AUTHORIZED()); } #[test] @@ -302,14 +290,14 @@ fn test_renounce_role_for_granted_role() { let mut state = setup(); testing::set_caller_address(ADMIN()); - state.accesscontrol.grant_role(ROLE, AUTHORIZED()); + state.grant_role(ROLE, AUTHORIZED()); utils::drop_event(ZERO()); testing::set_caller_address(AUTHORIZED()); - state.accesscontrol.renounce_role(ROLE, AUTHORIZED()); + state.renounce_role(ROLE, AUTHORIZED()); assert_event_role_revoked(ROLE, AUTHORIZED(), AUTHORIZED()); - assert(!state.accesscontrol.has_role(ROLE, AUTHORIZED()), 'Role should be renounced'); + assert(!state.has_role(ROLE, AUTHORIZED()), 'Role should be renounced'); } #[test] @@ -318,14 +306,14 @@ fn test_renounceRole_for_granted_role() { let mut state = setup(); testing::set_caller_address(ADMIN()); - state.accesscontrol.grantRole(ROLE, AUTHORIZED()); + state.grantRole(ROLE, AUTHORIZED()); utils::drop_event(ZERO()); testing::set_caller_address(AUTHORIZED()); - state.accesscontrol.renounceRole(ROLE, AUTHORIZED()); + state.renounceRole(ROLE, AUTHORIZED()); assert_event_role_revoked(ROLE, AUTHORIZED(), AUTHORIZED()); - assert(!state.accesscontrol.hasRole(ROLE, AUTHORIZED()), 'Role should be renounced'); + assert(!state.hasRole(ROLE, AUTHORIZED()), 'Role should be renounced'); } #[test] @@ -333,12 +321,12 @@ fn test_renounceRole_for_granted_role() { fn test_renounce_role_multiple_times_for_granted_role() { let mut state = setup(); testing::set_caller_address(ADMIN()); - state.accesscontrol.grant_role(ROLE, AUTHORIZED()); + state.grant_role(ROLE, AUTHORIZED()); testing::set_caller_address(AUTHORIZED()); - state.accesscontrol.renounce_role(ROLE, AUTHORIZED()); - state.accesscontrol.renounce_role(ROLE, AUTHORIZED()); - assert(!state.accesscontrol.has_role(ROLE, AUTHORIZED()), 'Role should still be renounced'); + state.renounce_role(ROLE, AUTHORIZED()); + state.renounce_role(ROLE, AUTHORIZED()); + assert(!state.has_role(ROLE, AUTHORIZED()), 'Role should still be renounced'); } #[test] @@ -346,12 +334,12 @@ fn test_renounce_role_multiple_times_for_granted_role() { fn test_renounceRole_multiple_times_for_granted_role() { let mut state = setup(); testing::set_caller_address(ADMIN()); - state.accesscontrol.grantRole(ROLE, AUTHORIZED()); + state.grantRole(ROLE, AUTHORIZED()); testing::set_caller_address(AUTHORIZED()); - state.accesscontrol.renounceRole(ROLE, AUTHORIZED()); - state.accesscontrol.renounceRole(ROLE, AUTHORIZED()); - assert(!state.accesscontrol.hasRole(ROLE, AUTHORIZED()), 'Role should still be renounced'); + state.renounceRole(ROLE, AUTHORIZED()); + state.renounceRole(ROLE, AUTHORIZED()); + assert(!state.hasRole(ROLE, AUTHORIZED()), 'Role should still be renounced'); } #[test] @@ -360,10 +348,10 @@ fn test_renounceRole_multiple_times_for_granted_role() { fn test_renounce_role_unauthorized() { let mut state = setup(); testing::set_caller_address(ADMIN()); - state.accesscontrol.grant_role(ROLE, AUTHORIZED()); + state.grant_role(ROLE, AUTHORIZED()); testing::set_caller_address(ZERO()); - state.accesscontrol.renounce_role(ROLE, AUTHORIZED()); + state.renounce_role(ROLE, AUTHORIZED()); } #[test] @@ -372,10 +360,10 @@ fn test_renounce_role_unauthorized() { fn test_renounceRole_unauthorized() { let mut state = setup(); testing::set_caller_address(ADMIN()); - state.accesscontrol.grantRole(ROLE, AUTHORIZED()); + state.grantRole(ROLE, AUTHORIZED()); // Admin is unauthorized caller - state.accesscontrol.renounceRole(ROLE, AUTHORIZED()); + state.renounceRole(ROLE, AUTHORIZED()); } // @@ -386,45 +374,40 @@ fn test_renounceRole_unauthorized() { #[available_gas(2000000)] fn test__set_role_admin() { let mut state = setup(); - assert( - state.accesscontrol.get_role_admin(ROLE) == DEFAULT_ADMIN_ROLE, - 'ROLE admin default should be 0' - ); - state.accesscontrol._set_role_admin(ROLE, OTHER_ROLE); + assert(state.get_role_admin(ROLE) == DEFAULT_ADMIN_ROLE, 'ROLE admin default should be 0'); + state._set_role_admin(ROLE, OTHER_ROLE); assert_event_role_admin_changed(ROLE, DEFAULT_ADMIN_ROLE, OTHER_ROLE); - assert( - state.accesscontrol.get_role_admin(ROLE) == OTHER_ROLE, 'ROLE admin should be OTHER_ROLE' - ); + assert(state.get_role_admin(ROLE) == OTHER_ROLE, 'ROLE admin should be OTHER_ROLE'); } #[test] #[available_gas(2000000)] fn test_new_admin_can_grant_roles() { let mut state = setup(); - state.accesscontrol._set_role_admin(ROLE, OTHER_ROLE); + state._set_role_admin(ROLE, OTHER_ROLE); testing::set_caller_address(ADMIN()); - state.accesscontrol.grant_role(OTHER_ROLE, OTHER_ADMIN()); + state.grant_role(OTHER_ROLE, OTHER_ADMIN()); testing::set_caller_address(OTHER_ADMIN()); - state.accesscontrol.grant_role(ROLE, AUTHORIZED()); - assert(state.accesscontrol.has_role(ROLE, AUTHORIZED()), 'AUTHORIZED should have ROLE'); + state.grant_role(ROLE, AUTHORIZED()); + assert(state.has_role(ROLE, AUTHORIZED()), 'AUTHORIZED should have ROLE'); } #[test] #[available_gas(2000000)] fn test_new_admin_can_revoke_roles() { let mut state = setup(); - state.accesscontrol._set_role_admin(ROLE, OTHER_ROLE); + state._set_role_admin(ROLE, OTHER_ROLE); testing::set_caller_address(ADMIN()); - state.accesscontrol.grant_role(OTHER_ROLE, OTHER_ADMIN()); + state.grant_role(OTHER_ROLE, OTHER_ADMIN()); testing::set_caller_address(OTHER_ADMIN()); - state.accesscontrol.grant_role(ROLE, AUTHORIZED()); - state.accesscontrol.revoke_role(ROLE, AUTHORIZED()); - assert(!state.accesscontrol.has_role(ROLE, AUTHORIZED()), 'AUTHORIZED should not have ROLE'); + state.grant_role(ROLE, AUTHORIZED()); + state.revoke_role(ROLE, AUTHORIZED()); + assert(!state.has_role(ROLE, AUTHORIZED()), 'AUTHORIZED should not have ROLE'); } #[test] @@ -432,9 +415,9 @@ fn test_new_admin_can_revoke_roles() { #[should_panic(expected: ('Caller is missing role',))] fn test_previous_admin_cannot_grant_roles() { let mut state = setup(); - state.accesscontrol._set_role_admin(ROLE, OTHER_ROLE); + state._set_role_admin(ROLE, OTHER_ROLE); testing::set_caller_address(ADMIN()); - state.accesscontrol.grant_role(ROLE, AUTHORIZED()); + state.grant_role(ROLE, AUTHORIZED()); } #[test] @@ -442,9 +425,9 @@ fn test_previous_admin_cannot_grant_roles() { #[should_panic(expected: ('Caller is missing role',))] fn test_previous_admin_cannot_revoke_roles() { let mut state = setup(); - state.accesscontrol._set_role_admin(ROLE, OTHER_ROLE); + state._set_role_admin(ROLE, OTHER_ROLE); testing::set_caller_address(ADMIN()); - state.accesscontrol.revoke_role(ROLE, AUTHORIZED()); + state.revoke_role(ROLE, AUTHORIZED()); } // @@ -455,10 +438,7 @@ fn test_previous_admin_cannot_revoke_roles() { #[available_gas(2000000)] fn test_other_role_admin_is_the_default_admin_role() { let state = setup(); - assert( - state.accesscontrol.get_role_admin(OTHER_ROLE) == DEFAULT_ADMIN_ROLE, - 'Should be DEFAULT_ADMIN_ROLE' - ); + assert(state.get_role_admin(OTHER_ROLE) == DEFAULT_ADMIN_ROLE, 'Should be DEFAULT_ADMIN_ROLE'); } #[test] @@ -466,7 +446,7 @@ fn test_other_role_admin_is_the_default_admin_role() { fn test_default_admin_role_is_its_own_admin() { let state = setup(); assert( - state.accesscontrol.get_role_admin(DEFAULT_ADMIN_ROLE) == DEFAULT_ADMIN_ROLE, + state.get_role_admin(DEFAULT_ADMIN_ROLE) == DEFAULT_ADMIN_ROLE, 'Should be DEFAULT_ADMIN_ROLE' ); } diff --git a/src/tests/access/test_ownable.cairo b/src/tests/access/test_ownable.cairo index c88448916..29dca9fe7 100644 --- a/src/tests/access/test_ownable.cairo +++ b/src/tests/access/test_ownable.cairo @@ -1,5 +1,6 @@ use openzeppelin::access::ownable::OwnableComponent::InternalTrait; use openzeppelin::access::ownable::OwnableComponent::OwnershipTransferred; +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}; @@ -12,13 +13,15 @@ use starknet::testing; // Setup // -fn STATE() -> DualCaseOwnableMock::ContractState { - DualCaseOwnableMock::contract_state_for_testing() +type ComponentState = OwnableComponent::ComponentState; + +fn COMPONENT_STATE() -> ComponentState { + OwnableComponent::component_state_for_testing() } -fn setup() -> DualCaseOwnableMock::ContractState { - let mut state = STATE(); - state.ownable.initializer(OWNER()); +fn setup() -> ComponentState { + let mut state = COMPONENT_STATE(); + state.initializer(OWNER()); utils::drop_event(ZERO()); state } @@ -30,13 +33,13 @@ fn setup() -> DualCaseOwnableMock::ContractState { #[test] #[available_gas(2000000)] fn test_initializer_owner() { - let mut state = STATE(); - assert(state.ownable.Ownable_owner.read().is_zero(), 'Should be zero'); - state.ownable.initializer(OWNER()); + let mut state = COMPONENT_STATE(); + assert(state.Ownable_owner.read().is_zero(), 'Should be zero'); + state.initializer(OWNER()); assert_event_ownership_transferred(ZERO(), OWNER()); - assert(state.ownable.Ownable_owner.read() == OWNER(), 'Owner should be set'); + assert(state.Ownable_owner.read() == OWNER(), 'Owner should be set'); } // @@ -48,7 +51,7 @@ fn test_initializer_owner() { fn test_assert_only_owner() { let state = setup(); testing::set_caller_address(OWNER()); - state.ownable.assert_only_owner(); + state.assert_only_owner(); } #[test] @@ -57,7 +60,7 @@ fn test_assert_only_owner() { fn test_assert_only_owner_when_not_owner() { let state = setup(); testing::set_caller_address(OTHER()); - state.ownable.assert_only_owner(); + state.assert_only_owner(); } #[test] @@ -65,7 +68,7 @@ fn test_assert_only_owner_when_not_owner() { #[should_panic(expected: ('Caller is the zero address',))] fn test_assert_only_owner_when_caller_zero() { let state = setup(); - state.ownable.assert_only_owner(); + state.assert_only_owner(); } // @@ -76,11 +79,11 @@ fn test_assert_only_owner_when_caller_zero() { #[available_gas(2000000)] fn test__transfer_ownership() { let mut state = setup(); - state.ownable._transfer_ownership(OTHER()); + state._transfer_ownership(OTHER()); assert_event_ownership_transferred(OWNER(), OTHER()); - assert(state.ownable.Ownable_owner.read() == OTHER(), 'Owner should be OTHER'); + assert(state.Ownable_owner.read() == OTHER(), 'Owner should be OTHER'); } // @@ -92,11 +95,11 @@ fn test__transfer_ownership() { fn test_transfer_ownership() { let mut state = setup(); testing::set_caller_address(OWNER()); - state.ownable.transfer_ownership(OTHER()); + state.transfer_ownership(OTHER()); assert_event_ownership_transferred(OWNER(), OTHER()); - assert(state.ownable.owner() == OTHER(), 'Should transfer ownership'); + assert(state.owner() == OTHER(), 'Should transfer ownership'); } #[test] @@ -105,7 +108,7 @@ fn test_transfer_ownership() { fn test_transfer_ownership_to_zero() { let mut state = setup(); testing::set_caller_address(OWNER()); - state.ownable.transfer_ownership(ZERO()); + state.transfer_ownership(ZERO()); } #[test] @@ -113,7 +116,7 @@ fn test_transfer_ownership_to_zero() { #[should_panic(expected: ('Caller is the zero address',))] fn test_transfer_ownership_from_zero() { let mut state = setup(); - state.ownable.transfer_ownership(OTHER()); + state.transfer_ownership(OTHER()); } #[test] @@ -122,7 +125,7 @@ fn test_transfer_ownership_from_zero() { fn test_transfer_ownership_from_nonowner() { let mut state = setup(); testing::set_caller_address(OTHER()); - state.ownable.transfer_ownership(OTHER()); + state.transfer_ownership(OTHER()); } #[test] @@ -130,11 +133,11 @@ fn test_transfer_ownership_from_nonowner() { fn test_transferOwnership() { let mut state = setup(); testing::set_caller_address(OWNER()); - state.ownable.transferOwnership(OTHER()); + state.transferOwnership(OTHER()); assert_event_ownership_transferred(OWNER(), OTHER()); - assert(state.ownable.owner() == OTHER(), 'Should transfer ownership'); + assert(state.owner() == OTHER(), 'Should transfer ownership'); } #[test] @@ -143,7 +146,7 @@ fn test_transferOwnership() { fn test_transferOwnership_to_zero() { let mut state = setup(); testing::set_caller_address(OWNER()); - state.ownable.transferOwnership(ZERO()); + state.transferOwnership(ZERO()); } #[test] @@ -151,7 +154,7 @@ fn test_transferOwnership_to_zero() { #[should_panic(expected: ('Caller is the zero address',))] fn test_transferOwnership_from_zero() { let mut state = setup(); - state.ownable.transferOwnership(OTHER()); + state.transferOwnership(OTHER()); } #[test] @@ -160,7 +163,7 @@ fn test_transferOwnership_from_zero() { fn test_transferOwnership_from_nonowner() { let mut state = setup(); testing::set_caller_address(OTHER()); - state.ownable.transferOwnership(OTHER()); + state.transferOwnership(OTHER()); } // @@ -172,11 +175,11 @@ fn test_transferOwnership_from_nonowner() { fn test_renounce_ownership() { let mut state = setup(); testing::set_caller_address(OWNER()); - state.ownable.renounce_ownership(); + state.renounce_ownership(); assert_event_ownership_transferred(OWNER(), ZERO()); - assert(state.ownable.owner() == ZERO(), 'Should renounce ownership'); + assert(state.owner() == ZERO(), 'Should renounce ownership'); } #[test] @@ -184,7 +187,7 @@ fn test_renounce_ownership() { #[should_panic(expected: ('Caller is the zero address',))] fn test_renounce_ownership_from_zero_address() { let mut state = setup(); - state.ownable.renounce_ownership(); + state.renounce_ownership(); } #[test] @@ -193,7 +196,7 @@ fn test_renounce_ownership_from_zero_address() { fn test_renounce_ownership_from_nonowner() { let mut state = setup(); testing::set_caller_address(OTHER()); - state.ownable.renounce_ownership(); + state.renounce_ownership(); } #[test] @@ -201,11 +204,11 @@ fn test_renounce_ownership_from_nonowner() { fn test_renounceOwnership() { let mut state = setup(); testing::set_caller_address(OWNER()); - state.ownable.renounceOwnership(); + state.renounceOwnership(); assert_event_ownership_transferred(OWNER(), ZERO()); - assert(state.ownable.owner() == ZERO(), 'Should renounce ownership'); + assert(state.owner() == ZERO(), 'Should renounce ownership'); } #[test] @@ -213,7 +216,7 @@ fn test_renounceOwnership() { #[should_panic(expected: ('Caller is the zero address',))] fn test_renounceOwnership_from_zero_address() { let mut state = setup(); - state.ownable.renounceOwnership(); + state.renounceOwnership(); } #[test] @@ -222,7 +225,7 @@ fn test_renounceOwnership_from_zero_address() { fn test_renounceOwnership_from_nonowner() { let mut state = setup(); testing::set_caller_address(OTHER()); - state.ownable.renounceOwnership(); + state.renounceOwnership(); } // diff --git a/src/tests/account/test_account.cairo b/src/tests/account/test_account.cairo index a5b1f0a40..3ad1018ab 100644 --- a/src/tests/account/test_account.cairo +++ b/src/tests/account/test_account.cairo @@ -2,11 +2,12 @@ use openzeppelin::account::AccountComponent::{InternalTrait, SRC6CamelOnlyImpl}; use openzeppelin::account::AccountComponent::{OwnerAdded, OwnerRemoved}; use openzeppelin::account::AccountComponent::{PublicKeyCamelImpl, PublicKeyImpl}; use openzeppelin::account::AccountComponent::{TRANSACTION_VERSION, QUERY_VERSION}; +use openzeppelin::account::AccountComponent; use openzeppelin::account::interface::{ISRC6, ISRC6_ID}; use openzeppelin::account::{AccountABIDispatcherTrait, AccountABIDispatcher}; use openzeppelin::introspection::interface::{ISRC5, ISRC5_ID}; use openzeppelin::tests::mocks::account_mocks::DualCaseAccountMock; -use openzeppelin::tests::mocks::erc20_mocks::DualCaseERC20; +use openzeppelin::tests::mocks::erc20_mocks::DualCaseERC20Mock; use openzeppelin::tests::utils::constants::{PUBKEY, NEW_PUBKEY, SALT, ZERO}; use openzeppelin::tests::utils; use openzeppelin::token::erc20::interface::{IERC20DispatcherTrait, IERC20Dispatcher}; @@ -26,16 +27,9 @@ struct SignedTransactionData { s: felt252 } -fn STATE() -> DualCaseAccountMock::ContractState { - DualCaseAccountMock::contract_state_for_testing() -} - -fn setup() -> DualCaseAccountMock::ContractState { - let mut state = STATE(); - state.account.initializer(PUBKEY); - utils::drop_event(ZERO()); - state -} +// +// Constants +// fn CLASS_HASH() -> felt252 { DualCaseAccountMock::TEST_CLASS_HASH @@ -55,6 +49,27 @@ fn SIGNED_TX_DATA() -> SignedTransactionData { } } +// +// Setup +// + +type ComponentState = AccountComponent::ComponentState; + +fn CONTRACT_STATE() -> DualCaseAccountMock::ContractState { + DualCaseAccountMock::contract_state_for_testing() +} + +fn COMPONENT_STATE() -> ComponentState { + AccountComponent::component_state_for_testing() +} + +fn setup() -> ComponentState { + let mut state = COMPONENT_STATE(); + state.initializer(PUBKEY); + utils::drop_event(ZERO()); + state +} + fn setup_dispatcher(data: Option<@SignedTransactionData>) -> AccountABIDispatcher { testing::set_version(TRANSACTION_VERSION); @@ -82,26 +97,10 @@ fn deploy_erc20(recipient: ContractAddress, initial_supply: u256) -> IERC20Dispa calldata.append_serde(initial_supply); calldata.append_serde(recipient); - let address = utils::deploy(DualCaseERC20::TEST_CLASS_HASH, calldata); + let address = utils::deploy(DualCaseERC20Mock::TEST_CLASS_HASH, calldata); IERC20Dispatcher { contract_address: address } } -// -// supports_interface -// - -#[test] -#[available_gas(2000000)] -fn test_supports_interface() { - let state = setup(); - - let supports_default_interface = state.src5.supports_interface(ISRC5_ID); - assert(supports_default_interface, 'Should support base interface'); - - let supports_account_interface = state.src5.supports_interface(ISRC6_ID); - assert(supports_account_interface, 'Should support account id'); -} - // // is_valid_signature & isValidSignature // @@ -109,7 +108,7 @@ fn test_supports_interface() { #[test] #[available_gas(2000000)] fn test_is_valid_signature() { - let mut state = STATE(); + let mut state = COMPONENT_STATE(); let data = SIGNED_TX_DATA(); let hash = data.transaction_hash; @@ -118,29 +117,29 @@ fn test_is_valid_signature() { state.set_public_key(data.public_key); - let is_valid = state.account.is_valid_signature(hash, good_signature); + let is_valid = state.is_valid_signature(hash, good_signature); assert(is_valid == starknet::VALIDATED, 'Should accept valid signature'); - let is_valid = state.account.is_valid_signature(hash, bad_signature); + let is_valid = state.is_valid_signature(hash, bad_signature); assert(is_valid == 0, 'Should reject invalid signature'); } #[test] #[available_gas(2000000)] fn test_isValidSignature() { - let mut state = STATE(); + let mut state = COMPONENT_STATE(); let data = SIGNED_TX_DATA(); let hash = data.transaction_hash; let mut good_signature = array![data.r, data.s]; let mut bad_signature = array![0x987, 0x564]; - state.account.set_public_key(data.public_key); + state.set_public_key(data.public_key); - let is_valid = state.account.isValidSignature(hash, good_signature); + let is_valid = state.isValidSignature(hash, good_signature); assert(is_valid == starknet::VALIDATED, 'Should accept valid signature'); - let is_valid = state.account.isValidSignature(hash, bad_signature); + let is_valid = state.isValidSignature(hash, bad_signature); assert(is_valid == 0, 'Should reject invalid signature'); } @@ -391,7 +390,7 @@ fn test_account_called_from_contract() { testing::set_contract_address(ACCOUNT_ADDRESS()); testing::set_caller_address(caller); - state.account.__execute__(calls); + state.__execute__(calls); } // @@ -401,16 +400,16 @@ fn test_account_called_from_contract() { #[test] #[available_gas(2000000)] fn test_public_key_setter_and_getter() { - let mut state = STATE(); + let mut state = COMPONENT_STATE(); testing::set_contract_address(ACCOUNT_ADDRESS()); testing::set_caller_address(ACCOUNT_ADDRESS()); // Check default - let public_key = state.account.get_public_key(); + let public_key = state.get_public_key(); assert(public_key == 0, 'Should be zero'); // Set key - state.account.set_public_key(NEW_PUBKEY); + state.set_public_key(NEW_PUBKEY); let event = utils::pop_log::(ACCOUNT_ADDRESS()).unwrap(); assert(event.removed_owner_guid == 0, 'Invalid old owner key'); @@ -419,7 +418,7 @@ fn test_public_key_setter_and_getter() { assert(event.new_owner_guid == NEW_PUBKEY, 'Invalid new owner key'); utils::assert_no_events_left(ACCOUNT_ADDRESS()); - let public_key = state.account.get_public_key(); + let public_key = state.get_public_key(); assert(public_key == NEW_PUBKEY, 'Should update key'); } @@ -427,12 +426,12 @@ fn test_public_key_setter_and_getter() { #[available_gas(2000000)] #[should_panic(expected: ('Account: unauthorized',))] fn test_public_key_setter_different_account() { - let mut state = STATE(); + let mut state = COMPONENT_STATE(); let caller = contract_address_const::<0x123>(); testing::set_contract_address(ACCOUNT_ADDRESS()); testing::set_caller_address(caller); - state.account.set_public_key(NEW_PUBKEY); + state.set_public_key(NEW_PUBKEY); } // @@ -442,7 +441,7 @@ fn test_public_key_setter_different_account() { #[test] #[available_gas(2000000)] fn test_public_key_setter_and_getter_camel() { - let mut state = STATE(); + let mut state = COMPONENT_STATE(); testing::set_contract_address(ACCOUNT_ADDRESS()); testing::set_caller_address(ACCOUNT_ADDRESS()); @@ -468,7 +467,7 @@ fn test_public_key_setter_and_getter_camel() { #[available_gas(2000000)] #[should_panic(expected: ('Account: unauthorized',))] fn test_public_key_setter_different_account_camel() { - let mut state = STATE(); + let mut state = COMPONENT_STATE(); let caller = contract_address_const::<0x123>(); testing::set_contract_address(ACCOUNT_ADDRESS()); testing::set_caller_address(caller); @@ -483,42 +482,49 @@ fn test_public_key_setter_different_account_camel() { #[test] #[available_gas(2000000)] fn test_initializer() { - let mut state = STATE(); + let mut state = COMPONENT_STATE(); + let mock_state = CONTRACT_STATE(); - state.account.initializer(PUBKEY); + 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(state.account.get_public_key() == PUBKEY, 'Should return PUBKEY'); + assert(state.get_public_key() == PUBKEY, 'Should return PUBKEY'); + + let supports_default_interface = mock_state.supports_interface(ISRC5_ID); + assert(supports_default_interface, 'Should support base interface'); + + let supports_account_interface = mock_state.supports_interface(ISRC6_ID); + assert(supports_account_interface, 'Should support account id'); } #[test] #[available_gas(2000000)] fn test_assert_only_self_true() { - let mut state = STATE(); + let mut state = COMPONENT_STATE(); testing::set_contract_address(ACCOUNT_ADDRESS()); testing::set_caller_address(ACCOUNT_ADDRESS()); - state.account.assert_only_self(); + state.assert_only_self(); } #[test] #[available_gas(2000000)] #[should_panic(expected: ('Account: unauthorized',))] fn test_assert_only_self_false() { - let mut state = STATE(); + let mut state = COMPONENT_STATE(); testing::set_contract_address(ACCOUNT_ADDRESS()); let other = contract_address_const::<0x4567>(); testing::set_caller_address(other); - state.account.assert_only_self(); + state.assert_only_self(); } #[test] #[available_gas(2000000)] fn test__is_valid_signature() { - let mut state = STATE(); + let mut state = COMPONENT_STATE(); let data = SIGNED_TX_DATA(); let hash = data.transaction_hash; @@ -526,28 +532,28 @@ fn test__is_valid_signature() { let mut bad_signature = array![0x987, 0x564]; let mut invalid_length_signature = array![0x987]; - state.account.set_public_key(data.public_key); + state.set_public_key(data.public_key); - let is_valid = state.account._is_valid_signature(hash, good_signature.span()); + let is_valid = state._is_valid_signature(hash, good_signature.span()); assert(is_valid, 'Should accept valid signature'); - let is_valid = state.account._is_valid_signature(hash, bad_signature.span()); + let is_valid = state._is_valid_signature(hash, bad_signature.span()); assert(!is_valid, 'Should reject invalid signature'); - let is_valid = state.account._is_valid_signature(hash, invalid_length_signature.span()); + let is_valid = state._is_valid_signature(hash, invalid_length_signature.span()); assert(!is_valid, 'Should reject invalid length'); } #[test] #[available_gas(2000000)] fn test__set_public_key() { - let mut state = STATE(); - state.account._set_public_key(PUBKEY); + 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()); - let public_key = state.account.get_public_key(); + let public_key = state.get_public_key(); assert(public_key == PUBKEY, 'Should update key'); } diff --git a/src/tests/introspection/test_src5.cairo b/src/tests/introspection/test_src5.cairo index db8b53ce3..f58f8a977 100644 --- a/src/tests/introspection/test_src5.cairo +++ b/src/tests/introspection/test_src5.cairo @@ -1,45 +1,48 @@ use openzeppelin::introspection::interface::{ISRC5_ID, ISRC5}; use openzeppelin::introspection::src5::SRC5Component::InternalTrait; +use openzeppelin::introspection::src5::SRC5Component; use openzeppelin::tests::mocks::src5_mocks::DualCaseSRC5Mock; const OTHER_ID: felt252 = 0x12345678; -fn STATE() -> DualCaseSRC5Mock::ContractState { - DualCaseSRC5Mock::contract_state_for_testing() +type ComponentState = SRC5Component::ComponentState; + +fn COMPONENT_STATE() -> ComponentState { + SRC5Component::component_state_for_testing() } #[test] #[available_gas(2000000)] fn test_default_behavior() { - let state = @STATE(); - let supports_default_interface = state.src5.supports_interface(ISRC5_ID); + let state = COMPONENT_STATE(); + let supports_default_interface = state.supports_interface(ISRC5_ID); assert(supports_default_interface, 'Should support base interface'); } #[test] #[available_gas(2000000)] fn test_not_registered_interface() { - let state = @STATE(); - let supports_unregistered_interface = state.src5.supports_interface(OTHER_ID); + let state = COMPONENT_STATE(); + let supports_unregistered_interface = state.supports_interface(OTHER_ID); assert(!supports_unregistered_interface, 'Should not support unregistered'); } #[test] #[available_gas(2000000)] fn test_register_interface() { - let mut state = STATE(); - state.src5.register_interface(OTHER_ID); - let supports_new_interface = state.src5.supports_interface(OTHER_ID); + 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'); } #[test] #[available_gas(2000000)] fn test_deregister_interface() { - let mut state = STATE(); - state.src5.register_interface(OTHER_ID); - state.src5.deregister_interface(OTHER_ID); - let supports_old_interface = state.src5.supports_interface(OTHER_ID); + 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'); } @@ -47,6 +50,6 @@ fn test_deregister_interface() { #[available_gas(2000000)] #[should_panic(expected: ('SRC5: invalid id',))] fn test_deregister_default_interface() { - let mut state = STATE(); - state.src5.deregister_interface(ISRC5_ID); + let mut state = COMPONENT_STATE(); + state.deregister_interface(ISRC5_ID); } diff --git a/src/tests/mocks/erc20_mocks.cairo b/src/tests/mocks/erc20_mocks.cairo index 5b775eb6e..dbe4466d7 100644 --- a/src/tests/mocks/erc20_mocks.cairo +++ b/src/tests/mocks/erc20_mocks.cairo @@ -1,5 +1,5 @@ #[starknet::contract] -mod DualCaseERC20 { +mod DualCaseERC20Mock { use openzeppelin::token::erc20::ERC20Component; use starknet::ContractAddress; diff --git a/src/tests/security/test_initializable.cairo b/src/tests/security/test_initializable.cairo index 9b1c71e96..5b70c5d7c 100644 --- a/src/tests/security/test_initializable.cairo +++ b/src/tests/security/test_initializable.cairo @@ -1,24 +1,27 @@ use openzeppelin::security::InitializableComponent::{InitializableImpl, InternalImpl}; +use openzeppelin::security::InitializableComponent; use openzeppelin::tests::mocks::initializable_mock::InitializableMock; -fn STATE() -> InitializableMock::ContractState { - InitializableMock::contract_state_for_testing() +type ComponentState = InitializableComponent::ComponentState; + +fn COMPONENT_STATE() -> ComponentState { + InitializableComponent::component_state_for_testing() } #[test] #[available_gas(2000000)] fn test_initialize() { - let mut state = STATE(); - assert(!state.initializable.is_initialized(), 'Should not be initialized'); - state.initializable.initialize(); - assert(state.initializable.is_initialized(), 'Should be initialized'); + let mut state = COMPONENT_STATE(); + assert(!state.is_initialized(), 'Should not be initialized'); + state.initialize(); + assert(state.is_initialized(), 'Should be initialized'); } #[test] #[available_gas(2000000)] #[should_panic(expected: ('Initializable: is initialized',))] fn test_initialize_when_initialized() { - let mut state = STATE(); - state.initializable.initialize(); - state.initializable.initialize(); + let mut state = COMPONENT_STATE(); + state.initialize(); + state.initialize(); } diff --git a/src/tests/security/test_pausable.cairo b/src/tests/security/test_pausable.cairo index f42bff2d2..df0204160 100644 --- a/src/tests/security/test_pausable.cairo +++ b/src/tests/security/test_pausable.cairo @@ -1,5 +1,6 @@ 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::utils::constants::{CALLER, ZERO}; use openzeppelin::tests::utils; @@ -7,12 +8,10 @@ use starknet::ContractAddress; use starknet::contract_address_const; use starknet::testing; -// -// Setup -// +type ComponentState = PausableComponent::ComponentState; -fn STATE() -> PausableMock::ContractState { - PausableMock::contract_state_for_testing() +fn COMPONENT_STATE() -> ComponentState { + PausableComponent::component_state_for_testing() } // @@ -22,14 +21,14 @@ fn STATE() -> PausableMock::ContractState { #[test] #[available_gas(2000000)] fn test_is_paused() { - let mut state = STATE(); - assert(!state.pausable.is_paused(), 'Should not be paused'); + let mut state = COMPONENT_STATE(); + assert(!state.is_paused(), 'Should not be paused'); - state.pausable._pause(); - assert(state.pausable.is_paused(), 'Should be paused'); + state._pause(); + assert(state.is_paused(), 'Should be paused'); - state.pausable._unpause(); - assert(!state.pausable.is_paused(), 'Should not be paused'); + state._unpause(); + assert(!state.is_paused(), 'Should not be paused'); } // @@ -39,17 +38,17 @@ fn test_is_paused() { #[test] #[available_gas(2000000)] fn test_assert_paused_when_paused() { - let mut state = STATE(); - state.pausable._pause(); - state.pausable.assert_paused(); + let mut state = COMPONENT_STATE(); + state._pause(); + state.assert_paused(); } #[test] #[available_gas(2000000)] #[should_panic(expected: ('Pausable: not paused',))] fn test_assert_paused_when_not_paused() { - let state = STATE(); - state.pausable.assert_paused(); + let state = COMPONENT_STATE(); + state.assert_paused(); } // @@ -60,16 +59,16 @@ fn test_assert_paused_when_not_paused() { #[available_gas(2000000)] #[should_panic(expected: ('Pausable: paused',))] fn test_assert_not_paused_when_paused() { - let mut state = STATE(); - state.pausable._pause(); - state.pausable.assert_not_paused(); + let mut state = COMPONENT_STATE(); + state._pause(); + state.assert_not_paused(); } #[test] #[available_gas(2000000)] fn test_assert_not_paused_when_not_paused() { - let state = STATE(); - state.pausable.assert_not_paused(); + let state = COMPONENT_STATE(); + state.assert_not_paused(); } // @@ -79,22 +78,22 @@ fn test_assert_not_paused_when_not_paused() { #[test] #[available_gas(2000000)] fn test_pause_when_unpaused() { - let mut state = STATE(); + let mut state = COMPONENT_STATE(); testing::set_caller_address(CALLER()); - state.pausable._pause(); + state._pause(); assert_event_paused(CALLER()); - assert(state.pausable.is_paused(), 'Should be paused'); + assert(state.is_paused(), 'Should be paused'); } #[test] #[available_gas(2000000)] #[should_panic(expected: ('Pausable: paused',))] fn test_pause_when_paused() { - let mut state = STATE(); - state.pausable._pause(); - state.pausable._pause(); + let mut state = COMPONENT_STATE(); + state._pause(); + state._pause(); } // @@ -104,25 +103,25 @@ fn test_pause_when_paused() { #[test] #[available_gas(2000000)] fn test_unpause_when_paused() { - let mut state = STATE(); + let mut state = COMPONENT_STATE(); testing::set_caller_address(CALLER()); - state.pausable._pause(); + state._pause(); utils::drop_event(ZERO()); - state.pausable._unpause(); + state._unpause(); assert_event_unpaused(CALLER()); - assert(!state.pausable.is_paused(), 'Should not be paused'); + assert(!state.is_paused(), 'Should not be paused'); } #[test] #[available_gas(2000000)] #[should_panic(expected: ('Pausable: not paused',))] fn test_unpause_when_unpaused() { - let mut state = STATE(); - assert(!state.pausable.is_paused(), 'Should be paused'); - state.pausable._unpause(); + let mut state = COMPONENT_STATE(); + assert(!state.is_paused(), 'Should be paused'); + state._unpause(); } // diff --git a/src/tests/security/test_reentrancyguard.cairo b/src/tests/security/test_reentrancyguard.cairo index 5d20c73e1..4824308c4 100644 --- a/src/tests/security/test_reentrancyguard.cairo +++ b/src/tests/security/test_reentrancyguard.cairo @@ -7,8 +7,10 @@ use openzeppelin::tests::mocks::reentrancy_mock::ReentrancyMock; use openzeppelin::tests::utils; use starknet::storage::StorageMemberAccessTrait; -fn STATE() -> ReentrancyMock::ContractState { - ReentrancyMock::contract_state_for_testing() +type ComponentState = ReentrancyGuardComponent::ComponentState; + +fn COMPONENT_STATE() -> ComponentState { + ReentrancyGuardComponent::component_state_for_testing() } fn deploy_mock() -> IReentrancyMockDispatcher { @@ -24,32 +26,32 @@ fn deploy_mock() -> IReentrancyMockDispatcher { #[test] #[available_gas(2000000)] fn test_reentrancy_guard_start() { - let mut state = STATE(); + let mut state = COMPONENT_STATE(); - assert(!state.reentrancy_guard.ReentrancyGuard_entered.read(), 'Should not be entered'); - state.reentrancy_guard.start(); - assert(state.reentrancy_guard.ReentrancyGuard_entered.read(), 'Should be entered'); + assert(!state.ReentrancyGuard_entered.read(), 'Should not be entered'); + state.start(); + assert(state.ReentrancyGuard_entered.read(), 'Should be entered'); } #[test] #[available_gas(2000000)] #[should_panic(expected: ('ReentrancyGuard: reentrant call',))] fn test_reentrancy_guard_start_when_started() { - let mut state = STATE(); + let mut state = COMPONENT_STATE(); - state.reentrancy_guard.start(); - state.reentrancy_guard.start(); + state.start(); + state.start(); } #[test] #[available_gas(2000000)] fn test_reentrancy_guard_end() { - let mut state = STATE(); + let mut state = COMPONENT_STATE(); - state.reentrancy_guard.start(); - assert(state.reentrancy_guard.ReentrancyGuard_entered.read(), 'Should be entered'); - state.reentrancy_guard.end(); - assert(!state.reentrancy_guard.ReentrancyGuard_entered.read(), 'Should no longer be entered'); + state.start(); + assert(state.ReentrancyGuard_entered.read(), 'Should be entered'); + state.end(); + assert(!state.ReentrancyGuard_entered.read(), 'Should no longer be entered'); } // diff --git a/src/tests/token/test_erc20.cairo b/src/tests/token/test_erc20.cairo index be0eb72db..ed321612a 100644 --- a/src/tests/token/test_erc20.cairo +++ b/src/tests/token/test_erc20.cairo @@ -1,5 +1,5 @@ use integer::BoundedInt; -use openzeppelin::tests::mocks::erc20_mocks::DualCaseERC20; +use openzeppelin::tests::mocks::erc20_mocks::DualCaseERC20Mock; use openzeppelin::tests::utils::constants::{ ZERO, OWNER, SPENDER, RECIPIENT, NAME, SYMBOL, DECIMALS, SUPPLY, VALUE }; @@ -8,6 +8,7 @@ use openzeppelin::token::erc20::ERC20Component::{Approval, Transfer}; use openzeppelin::token::erc20::ERC20Component::{ERC20CamelOnlyImpl, ERC20Impl}; use openzeppelin::token::erc20::ERC20Component::{ERC20MetadataImpl, InternalImpl}; use openzeppelin::token::erc20::ERC20Component::{SafeAllowanceImpl, SafeAllowanceCamelImpl}; +use openzeppelin::token::erc20::ERC20Component; use openzeppelin::utils::serde::SerializedAppend; use starknet::ContractAddress; use starknet::testing; @@ -16,14 +17,16 @@ use starknet::testing; // Setup // -fn STATE() -> DualCaseERC20::ContractState { - DualCaseERC20::contract_state_for_testing() +type ComponentState = ERC20Component::ComponentState; + +fn COMPONENT_STATE() -> ComponentState { + ERC20Component::component_state_for_testing() } -fn setup() -> DualCaseERC20::ContractState { - let mut state = STATE(); - state.erc20.initializer(NAME, SYMBOL); - state.erc20._mint(OWNER(), SUPPLY); +fn setup() -> ComponentState { + let mut state = COMPONENT_STATE(); + state.initializer(NAME, SYMBOL); + state._mint(OWNER(), SUPPLY); utils::drop_event(ZERO()); state } @@ -35,13 +38,13 @@ fn setup() -> DualCaseERC20::ContractState { #[test] #[available_gas(2000000)] fn test_initializer() { - let mut state = STATE(); - state.erc20.initializer(NAME, SYMBOL); + let mut state = COMPONENT_STATE(); + state.initializer(NAME, SYMBOL); - assert(state.erc20.name() == NAME, 'Should be NAME'); - assert(state.erc20.symbol() == SYMBOL, 'Should be SYMBOL'); - assert(state.erc20.decimals() == DECIMALS, 'Should be DECIMALS'); - assert(state.erc20.total_supply() == 0, 'Should equal 0'); + 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'); } // @@ -51,33 +54,33 @@ fn test_initializer() { #[test] #[available_gas(2000000)] fn test_total_supply() { - let mut state = STATE(); - state.erc20._mint(OWNER(), SUPPLY); - assert(state.erc20.total_supply() == SUPPLY, 'Should equal SUPPLY'); + let mut state = COMPONENT_STATE(); + state._mint(OWNER(), SUPPLY); + assert(state.total_supply() == SUPPLY, 'Should equal SUPPLY'); } #[test] #[available_gas(2000000)] fn test_totalSupply() { - let mut state = STATE(); - state.erc20._mint(OWNER(), SUPPLY); - assert(state.erc20.totalSupply() == SUPPLY, 'Should equal SUPPLY'); + let mut state = COMPONENT_STATE(); + state._mint(OWNER(), SUPPLY); + assert(state.totalSupply() == SUPPLY, 'Should equal SUPPLY'); } #[test] #[available_gas(2000000)] fn test_balance_of() { - let mut state = STATE(); - state.erc20._mint(OWNER(), SUPPLY); - assert(state.erc20.balance_of(OWNER()) == SUPPLY, 'Should equal SUPPLY'); + let mut state = COMPONENT_STATE(); + state._mint(OWNER(), SUPPLY); + assert(state.balance_of(OWNER()) == SUPPLY, 'Should equal SUPPLY'); } #[test] #[available_gas(2000000)] fn test_balanceOf() { - let mut state = STATE(); - state.erc20._mint(OWNER(), SUPPLY); - assert(state.erc20.balanceOf(OWNER()) == SUPPLY, 'Should equal SUPPLY'); + let mut state = COMPONENT_STATE(); + state._mint(OWNER(), SUPPLY); + assert(state.balanceOf(OWNER()) == SUPPLY, 'Should equal SUPPLY'); } #[test] @@ -85,9 +88,9 @@ fn test_balanceOf() { fn test_allowance() { let mut state = setup(); testing::set_caller_address(OWNER()); - state.erc20.approve(SPENDER(), VALUE); + state.approve(SPENDER(), VALUE); - assert(state.erc20.allowance(OWNER(), SPENDER()) == VALUE, 'Should equal VALUE'); + assert(state.allowance(OWNER(), SPENDER()) == VALUE, 'Should equal VALUE'); } // @@ -99,10 +102,10 @@ fn test_allowance() { fn test_approve() { let mut state = setup(); testing::set_caller_address(OWNER()); - assert(state.erc20.approve(SPENDER(), VALUE), 'Should return true'); + assert(state.approve(SPENDER(), VALUE), 'Should return true'); assert_only_event_approval(OWNER(), SPENDER(), VALUE); - assert(state.erc20.allowance(OWNER(), SPENDER()) == VALUE, 'Spender not approved correctly'); + assert(state.allowance(OWNER(), SPENDER()) == VALUE, 'Spender not approved correctly'); } #[test] @@ -110,7 +113,7 @@ fn test_approve() { #[should_panic(expected: ('ERC20: approve from 0',))] fn test_approve_from_zero() { let mut state = setup(); - state.erc20.approve(SPENDER(), VALUE); + state.approve(SPENDER(), VALUE); } #[test] @@ -119,7 +122,7 @@ fn test_approve_from_zero() { fn test_approve_to_zero() { let mut state = setup(); testing::set_caller_address(OWNER()); - state.erc20.approve(ZERO(), VALUE); + state.approve(ZERO(), VALUE); } #[test] @@ -127,10 +130,10 @@ fn test_approve_to_zero() { fn test__approve() { let mut state = setup(); testing::set_caller_address(OWNER()); - state.erc20._approve(OWNER(), SPENDER(), VALUE); + state._approve(OWNER(), SPENDER(), VALUE); assert_only_event_approval(OWNER(), SPENDER(), VALUE); - assert(state.erc20.allowance(OWNER(), SPENDER()) == VALUE, 'Spender not approved correctly'); + assert(state.allowance(OWNER(), SPENDER()) == VALUE, 'Spender not approved correctly'); } #[test] @@ -138,7 +141,7 @@ fn test__approve() { #[should_panic(expected: ('ERC20: approve from 0',))] fn test__approve_from_zero() { let mut state = setup(); - state.erc20._approve(ZERO(), SPENDER(), VALUE); + state._approve(ZERO(), SPENDER(), VALUE); } #[test] @@ -147,7 +150,7 @@ fn test__approve_from_zero() { fn test__approve_to_zero() { let mut state = setup(); testing::set_caller_address(OWNER()); - state.erc20._approve(OWNER(), ZERO(), VALUE); + state._approve(OWNER(), ZERO(), VALUE); } // @@ -159,12 +162,12 @@ fn test__approve_to_zero() { fn test_transfer() { let mut state = setup(); testing::set_caller_address(OWNER()); - assert(state.erc20.transfer(RECIPIENT(), VALUE), 'Should return true'); + assert(state.transfer(RECIPIENT(), VALUE), 'Should return true'); assert_only_event_transfer(OWNER(), RECIPIENT(), VALUE); - assert(state.erc20.balance_of(RECIPIENT()) == VALUE, 'Should equal VALUE'); - assert(state.erc20.balance_of(OWNER()) == SUPPLY - VALUE, 'Should equal SUPPLY - VALUE'); - assert(state.erc20.total_supply() == SUPPLY, 'Total supply should not change'); + 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'); } #[test] @@ -175,7 +178,7 @@ fn test_transfer_not_enough_balance() { testing::set_caller_address(OWNER()); let balance_plus_one = SUPPLY + 1; - state.erc20.transfer(RECIPIENT(), balance_plus_one); + state.transfer(RECIPIENT(), balance_plus_one); } #[test] @@ -183,7 +186,7 @@ fn test_transfer_not_enough_balance() { #[should_panic(expected: ('ERC20: transfer from 0',))] fn test_transfer_from_zero() { let mut state = setup(); - state.erc20.transfer(RECIPIENT(), VALUE); + state.transfer(RECIPIENT(), VALUE); } #[test] @@ -192,7 +195,7 @@ fn test_transfer_from_zero() { fn test_transfer_to_zero() { let mut state = setup(); testing::set_caller_address(OWNER()); - state.erc20.transfer(ZERO(), VALUE); + state.transfer(ZERO(), VALUE); } #[test] @@ -200,12 +203,12 @@ fn test_transfer_to_zero() { fn test__transfer() { let mut state = setup(); - state.erc20._transfer(OWNER(), RECIPIENT(), VALUE); + state._transfer(OWNER(), RECIPIENT(), VALUE); assert_only_event_transfer(OWNER(), RECIPIENT(), VALUE); - assert(state.erc20.balance_of(RECIPIENT()) == VALUE, 'Should equal amount'); - assert(state.erc20.balance_of(OWNER()) == SUPPLY - VALUE, 'Should equal SUPPLY - VALUE'); - assert(state.erc20.total_supply() == SUPPLY, 'Total supply should not change'); + 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'); } #[test] @@ -216,7 +219,7 @@ fn test__transfer_not_enough_balance() { testing::set_caller_address(OWNER()); let balance_plus_one = SUPPLY + 1; - state.erc20._transfer(OWNER(), RECIPIENT(), balance_plus_one); + state._transfer(OWNER(), RECIPIENT(), balance_plus_one); } #[test] @@ -224,7 +227,7 @@ fn test__transfer_not_enough_balance() { #[should_panic(expected: ('ERC20: transfer from 0',))] fn test__transfer_from_zero() { let mut state = setup(); - state.erc20._transfer(ZERO(), RECIPIENT(), VALUE); + state._transfer(ZERO(), RECIPIENT(), VALUE); } #[test] @@ -232,7 +235,7 @@ fn test__transfer_from_zero() { #[should_panic(expected: ('ERC20: transfer to 0',))] fn test__transfer_to_zero() { let mut state = setup(); - state.erc20._transfer(OWNER(), ZERO(), VALUE); + state._transfer(OWNER(), ZERO(), VALUE); } // @@ -244,19 +247,19 @@ fn test__transfer_to_zero() { fn test_transfer_from() { let mut state = setup(); testing::set_caller_address(OWNER()); - state.erc20.approve(SPENDER(), VALUE); + state.approve(SPENDER(), VALUE); utils::drop_event(ZERO()); testing::set_caller_address(SPENDER()); - assert(state.erc20.transfer_from(OWNER(), RECIPIENT(), VALUE), 'Should return true'); + assert(state.transfer_from(OWNER(), RECIPIENT(), VALUE), 'Should return true'); assert_event_approval(OWNER(), SPENDER(), 0); assert_only_event_transfer(OWNER(), RECIPIENT(), VALUE); - assert(state.erc20.balance_of(RECIPIENT()) == VALUE, 'Should equal VALUE'); - assert(state.erc20.balance_of(OWNER()) == SUPPLY - VALUE, 'Should equal SUPPLY - VALUE'); - assert(state.erc20.allowance(OWNER(), SPENDER()) == 0, 'Should equal 0'); - assert(state.erc20.total_supply() == SUPPLY, 'Total supply should not change'); + 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'); } #[test] @@ -264,15 +267,12 @@ fn test_transfer_from() { fn test_transfer_from_doesnt_consume_infinite_allowance() { let mut state = setup(); testing::set_caller_address(OWNER()); - state.erc20.approve(SPENDER(), BoundedInt::max()); + state.approve(SPENDER(), BoundedInt::max()); testing::set_caller_address(SPENDER()); - state.erc20.transfer_from(OWNER(), RECIPIENT(), VALUE); + state.transfer_from(OWNER(), RECIPIENT(), VALUE); - assert( - state.erc20.allowance(OWNER(), SPENDER()) == BoundedInt::max(), - 'Allowance should not change' - ); + assert(state.allowance(OWNER(), SPENDER()) == BoundedInt::max(), 'Allowance should not change'); } #[test] @@ -281,11 +281,11 @@ fn test_transfer_from_doesnt_consume_infinite_allowance() { fn test_transfer_from_greater_than_allowance() { let mut state = setup(); testing::set_caller_address(OWNER()); - state.erc20.approve(SPENDER(), VALUE); + state.approve(SPENDER(), VALUE); testing::set_caller_address(SPENDER()); let allowance_plus_one = VALUE + 1; - state.erc20.transfer_from(OWNER(), RECIPIENT(), allowance_plus_one); + state.transfer_from(OWNER(), RECIPIENT(), allowance_plus_one); } #[test] @@ -294,10 +294,10 @@ fn test_transfer_from_greater_than_allowance() { fn test_transfer_from_to_zero_address() { let mut state = setup(); testing::set_caller_address(OWNER()); - state.erc20.approve(SPENDER(), VALUE); + state.approve(SPENDER(), VALUE); testing::set_caller_address(SPENDER()); - state.erc20.transfer_from(OWNER(), ZERO(), VALUE); + state.transfer_from(OWNER(), ZERO(), VALUE); } #[test] @@ -305,7 +305,7 @@ fn test_transfer_from_to_zero_address() { #[should_panic(expected: ('u256_sub Overflow',))] fn test_transfer_from_from_zero_address() { let mut state = setup(); - state.erc20.transfer_from(ZERO(), RECIPIENT(), VALUE); + state.transfer_from(ZERO(), RECIPIENT(), VALUE); } #[test] @@ -313,19 +313,19 @@ fn test_transfer_from_from_zero_address() { fn test_transferFrom() { let mut state = setup(); testing::set_caller_address(OWNER()); - state.erc20.approve(SPENDER(), VALUE); + state.approve(SPENDER(), VALUE); utils::drop_event(ZERO()); testing::set_caller_address(SPENDER()); - assert(state.erc20.transferFrom(OWNER(), RECIPIENT(), VALUE), 'Should return true'); + assert(state.transferFrom(OWNER(), RECIPIENT(), VALUE), 'Should return true'); assert_event_approval(OWNER(), SPENDER(), 0); assert_only_event_transfer(OWNER(), RECIPIENT(), VALUE); - assert(state.erc20.balanceOf(RECIPIENT()) == VALUE, 'Should equal VALUE'); - assert(state.erc20.balanceOf(OWNER()) == SUPPLY - VALUE, 'Should equal SUPPLY - VALUE'); - assert(state.erc20.allowance(OWNER(), SPENDER()) == 0, 'Should equal 0'); - assert(state.erc20.totalSupply() == SUPPLY, 'Total supply should not change'); + 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'); } #[test] @@ -333,15 +333,12 @@ fn test_transferFrom() { fn test_transferFrom_doesnt_consume_infinite_allowance() { let mut state = setup(); testing::set_caller_address(OWNER()); - state.erc20.approve(SPENDER(), BoundedInt::max()); + state.approve(SPENDER(), BoundedInt::max()); testing::set_caller_address(SPENDER()); - state.erc20.transferFrom(OWNER(), RECIPIENT(), VALUE); + state.transferFrom(OWNER(), RECIPIENT(), VALUE); - assert( - state.erc20.allowance(OWNER(), SPENDER()) == BoundedInt::max(), - 'Allowance should not change' - ); + assert(state.allowance(OWNER(), SPENDER()) == BoundedInt::max(), 'Allowance should not change'); } #[test] @@ -350,11 +347,11 @@ fn test_transferFrom_doesnt_consume_infinite_allowance() { fn test_transferFrom_greater_than_allowance() { let mut state = setup(); testing::set_caller_address(OWNER()); - state.erc20.approve(SPENDER(), VALUE); + state.approve(SPENDER(), VALUE); testing::set_caller_address(SPENDER()); let allowance_plus_one = VALUE + 1; - state.erc20.transferFrom(OWNER(), RECIPIENT(), allowance_plus_one); + state.transferFrom(OWNER(), RECIPIENT(), allowance_plus_one); } #[test] @@ -363,10 +360,10 @@ fn test_transferFrom_greater_than_allowance() { fn test_transferFrom_to_zero_address() { let mut state = setup(); testing::set_caller_address(OWNER()); - state.erc20.approve(SPENDER(), VALUE); + state.approve(SPENDER(), VALUE); testing::set_caller_address(SPENDER()); - state.erc20.transferFrom(OWNER(), ZERO(), VALUE); + state.transferFrom(OWNER(), ZERO(), VALUE); } #[test] @@ -374,7 +371,7 @@ fn test_transferFrom_to_zero_address() { #[should_panic(expected: ('u256_sub Overflow',))] fn test_transferFrom_from_zero_address() { let mut state = setup(); - state.erc20.transferFrom(ZERO(), RECIPIENT(), VALUE); + state.transferFrom(ZERO(), RECIPIENT(), VALUE); } // @@ -386,13 +383,13 @@ fn test_transferFrom_from_zero_address() { fn test_increase_allowance() { let mut state = setup(); testing::set_caller_address(OWNER()); - state.erc20.approve(SPENDER(), VALUE); + state.approve(SPENDER(), VALUE); utils::drop_event(ZERO()); - assert(state.erc20.increase_allowance(SPENDER(), VALUE), 'Should return true'); + assert(state.increase_allowance(SPENDER(), VALUE), 'Should return true'); assert_only_event_approval(OWNER(), SPENDER(), VALUE * 2); - assert(state.erc20.allowance(OWNER(), SPENDER()) == VALUE * 2, 'Should equal VALUE * 2'); + assert(state.allowance(OWNER(), SPENDER()) == VALUE * 2, 'Should equal VALUE * 2'); } #[test] @@ -401,7 +398,7 @@ fn test_increase_allowance() { fn test_increase_allowance_to_zero_address() { let mut state = setup(); testing::set_caller_address(OWNER()); - state.erc20.increase_allowance(ZERO(), VALUE); + state.increase_allowance(ZERO(), VALUE); } #[test] @@ -409,7 +406,7 @@ fn test_increase_allowance_to_zero_address() { #[should_panic(expected: ('ERC20: approve from 0',))] fn test_increase_allowance_from_zero_address() { let mut state = setup(); - state.erc20.increase_allowance(SPENDER(), VALUE); + state.increase_allowance(SPENDER(), VALUE); } #[test] @@ -417,13 +414,13 @@ fn test_increase_allowance_from_zero_address() { fn test_increaseAllowance() { let mut state = setup(); testing::set_caller_address(OWNER()); - state.erc20.approve(SPENDER(), VALUE); + state.approve(SPENDER(), VALUE); utils::drop_event(ZERO()); - assert(state.erc20.increaseAllowance(SPENDER(), VALUE), 'Should return true'); + assert(state.increaseAllowance(SPENDER(), VALUE), 'Should return true'); assert_only_event_approval(OWNER(), SPENDER(), 2 * VALUE); - assert(state.erc20.allowance(OWNER(), SPENDER()) == VALUE * 2, 'Should equal VALUE * 2'); + assert(state.allowance(OWNER(), SPENDER()) == VALUE * 2, 'Should equal VALUE * 2'); } #[test] @@ -432,7 +429,7 @@ fn test_increaseAllowance() { fn test_increaseAllowance_to_zero_address() { let mut state = setup(); testing::set_caller_address(OWNER()); - state.erc20.increaseAllowance(ZERO(), VALUE); + state.increaseAllowance(ZERO(), VALUE); } #[test] @@ -440,7 +437,7 @@ fn test_increaseAllowance_to_zero_address() { #[should_panic(expected: ('ERC20: approve from 0',))] fn test_increaseAllowance_from_zero_address() { let mut state = setup(); - state.erc20.increaseAllowance(SPENDER(), VALUE); + state.increaseAllowance(SPENDER(), VALUE); } // @@ -452,13 +449,13 @@ fn test_increaseAllowance_from_zero_address() { fn test_decrease_allowance() { let mut state = setup(); testing::set_caller_address(OWNER()); - state.erc20.approve(SPENDER(), VALUE); + state.approve(SPENDER(), VALUE); utils::drop_event(ZERO()); - assert(state.erc20.decrease_allowance(SPENDER(), VALUE), 'Should return true'); + assert(state.decrease_allowance(SPENDER(), VALUE), 'Should return true'); assert_only_event_approval(OWNER(), SPENDER(), 0); - assert(state.erc20.allowance(OWNER(), SPENDER()) == VALUE - VALUE, 'Should be 0'); + assert(state.allowance(OWNER(), SPENDER()) == VALUE - VALUE, 'Should be 0'); } #[test] @@ -467,7 +464,7 @@ fn test_decrease_allowance() { fn test_decrease_allowance_to_zero_address() { let mut state = setup(); testing::set_caller_address(OWNER()); - state.erc20.decrease_allowance(ZERO(), VALUE); + state.decrease_allowance(ZERO(), VALUE); } #[test] @@ -475,7 +472,7 @@ fn test_decrease_allowance_to_zero_address() { #[should_panic(expected: ('u256_sub Overflow',))] fn test_decrease_allowance_from_zero_address() { let mut state = setup(); - state.erc20.decrease_allowance(SPENDER(), VALUE); + state.decrease_allowance(SPENDER(), VALUE); } #[test] @@ -483,13 +480,13 @@ fn test_decrease_allowance_from_zero_address() { fn test_decreaseAllowance() { let mut state = setup(); testing::set_caller_address(OWNER()); - state.erc20.approve(SPENDER(), VALUE); + state.approve(SPENDER(), VALUE); utils::drop_event(ZERO()); - assert(state.erc20.decreaseAllowance(SPENDER(), VALUE), 'Should return true'); + assert(state.decreaseAllowance(SPENDER(), VALUE), 'Should return true'); assert_only_event_approval(OWNER(), SPENDER(), 0); - assert(state.erc20.allowance(OWNER(), SPENDER()) == VALUE - VALUE, 'Should be 0'); + assert(state.allowance(OWNER(), SPENDER()) == VALUE - VALUE, 'Should be 0'); } #[test] @@ -498,7 +495,7 @@ fn test_decreaseAllowance() { fn test_decreaseAllowance_to_zero_address() { let mut state = setup(); testing::set_caller_address(OWNER()); - state.erc20.decreaseAllowance(ZERO(), VALUE); + state.decreaseAllowance(ZERO(), VALUE); } #[test] @@ -506,7 +503,7 @@ fn test_decreaseAllowance_to_zero_address() { #[should_panic(expected: ('u256_sub Overflow',))] fn test_decreaseAllowance_from_zero_address() { let mut state = setup(); - state.erc20.decreaseAllowance(SPENDER(), VALUE); + state.decreaseAllowance(SPENDER(), VALUE); } // @@ -518,30 +515,25 @@ fn test_decreaseAllowance_from_zero_address() { fn test__spend_allowance_not_unlimited() { let mut state = setup(); - state.erc20._approve(OWNER(), SPENDER(), SUPPLY); + state._approve(OWNER(), SPENDER(), SUPPLY); utils::drop_event(ZERO()); - state.erc20._spend_allowance(OWNER(), SPENDER(), VALUE); + state._spend_allowance(OWNER(), SPENDER(), VALUE); assert_only_event_approval(OWNER(), SPENDER(), SUPPLY - VALUE); - assert( - state.erc20.allowance(OWNER(), SPENDER()) == SUPPLY - VALUE, 'Should equal SUPPLY - VALUE' - ); + assert(state.allowance(OWNER(), SPENDER()) == SUPPLY - VALUE, 'Should equal SUPPLY - VALUE'); } #[test] #[available_gas(2000000)] fn test__spend_allowance_unlimited() { let mut state = setup(); - state.erc20._approve(OWNER(), SPENDER(), BoundedInt::max()); + state._approve(OWNER(), SPENDER(), BoundedInt::max()); let max_minus_one: u256 = BoundedInt::max() - 1; - state.erc20._spend_allowance(OWNER(), SPENDER(), max_minus_one); + state._spend_allowance(OWNER(), SPENDER(), max_minus_one); - assert( - state.erc20.allowance(OWNER(), SPENDER()) == BoundedInt::max(), - 'Allowance should not change' - ); + assert(state.allowance(OWNER(), SPENDER()) == BoundedInt::max(), 'Allowance should not change'); } // @@ -551,20 +543,20 @@ fn test__spend_allowance_unlimited() { #[test] #[available_gas(2000000)] fn test__mint() { - let mut state = STATE(); - state.erc20._mint(OWNER(), VALUE); + let mut state = COMPONENT_STATE(); + state._mint(OWNER(), VALUE); assert_only_event_transfer(ZERO(), OWNER(), VALUE); - assert(state.erc20.balance_of(OWNER()) == VALUE, 'Should equal VALUE'); - assert(state.erc20.total_supply() == VALUE, 'Should equal VALUE'); + assert(state.balance_of(OWNER()) == VALUE, 'Should equal VALUE'); + assert(state.total_supply() == VALUE, 'Should equal VALUE'); } #[test] #[available_gas(2000000)] #[should_panic(expected: ('ERC20: mint to 0',))] fn test__mint_to_zero() { - let mut state = STATE(); - state.erc20._mint(ZERO(), VALUE); + let mut state = COMPONENT_STATE(); + state._mint(ZERO(), VALUE); } // @@ -575,11 +567,11 @@ fn test__mint_to_zero() { #[available_gas(2000000)] fn test__burn() { let mut state = setup(); - state.erc20._burn(OWNER(), VALUE); + state._burn(OWNER(), VALUE); assert_only_event_transfer(OWNER(), ZERO(), VALUE); - assert(state.erc20.total_supply() == SUPPLY - VALUE, 'Should equal SUPPLY - VALUE'); - assert(state.erc20.balance_of(OWNER()) == SUPPLY - VALUE, 'Should equal SUPPLY - VALUE'); + assert(state.total_supply() == SUPPLY - VALUE, 'Should equal SUPPLY - VALUE'); + assert(state.balance_of(OWNER()) == SUPPLY - VALUE, 'Should equal SUPPLY - VALUE'); } #[test] @@ -587,7 +579,7 @@ fn test__burn() { #[should_panic(expected: ('ERC20: burn from 0',))] fn test__burn_from_zero() { let mut state = setup(); - state.erc20._burn(ZERO(), VALUE); + state._burn(ZERO(), VALUE); } // diff --git a/src/tests/token/test_erc721.cairo b/src/tests/token/test_erc721.cairo index ce82ac01b..8a1a3376b 100644 --- a/src/tests/token/test_erc721.cairo +++ b/src/tests/token/test_erc721.cairo @@ -30,14 +30,19 @@ use starknet::testing; // Setup // -fn STATE() -> DualCaseERC721Mock::ContractState { +type ComponentState = ERC721Component::ComponentState; + +fn CONTRACT_STATE() -> DualCaseERC721Mock::ContractState { DualCaseERC721Mock::contract_state_for_testing() } +fn COMPONENT_STATE() -> ComponentState { + ERC721Component::component_state_for_testing() +} -fn setup() -> DualCaseERC721Mock::ContractState { - let mut state = STATE(); - state.erc721.initializer(NAME, SYMBOL); - state.erc721._mint(OWNER(), TOKEN_ID); +fn setup() -> ComponentState { + let mut state = COMPONENT_STATE(); + state.initializer(NAME, SYMBOL); + state._mint(OWNER(), TOKEN_ID); utils::drop_event(ZERO()); state } @@ -67,20 +72,22 @@ fn setup_camel_account() -> ContractAddress { #[test] #[available_gas(20000000)] fn test_initialize() { - let mut state = STATE(); - state.erc721.initializer(NAME, SYMBOL); + let mut state = COMPONENT_STATE(); + let mock_state = CONTRACT_STATE(); + + state.initializer(NAME, SYMBOL); - assert(state.erc721.name() == NAME, 'Name should be NAME'); - assert(state.erc721.symbol() == SYMBOL, 'Symbol should be SYMBOL'); - assert(state.erc721.balance_of(OWNER()) == 0, 'Balance should be zero'); + 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(state.src5.supports_interface(erc721::interface::IERC721_ID), 'Missing interface ID'); + assert(mock_state.supports_interface(erc721::interface::IERC721_ID), 'Missing interface ID'); assert( - state.src5.supports_interface(erc721::interface::IERC721_METADATA_ID), + mock_state.supports_interface(erc721::interface::IERC721_METADATA_ID), 'Missing interface ID' ); assert( - state.src5.supports_interface(introspection::interface::ISRC5_ID), 'Missing interface ID' + mock_state.supports_interface(introspection::interface::ISRC5_ID), 'Missing interface ID' ); } @@ -92,7 +99,7 @@ fn test_initialize() { #[available_gas(20000000)] fn test_balance_of() { let state = setup(); - assert(state.erc721.balance_of(OWNER()) == 1, 'Should return balance'); + assert(state.balance_of(OWNER()) == 1, 'Should return balance'); } #[test] @@ -100,14 +107,14 @@ fn test_balance_of() { #[should_panic(expected: ('ERC721: invalid account',))] fn test_balance_of_zero() { let state = setup(); - state.erc721.balance_of(ZERO()); + state.balance_of(ZERO()); } #[test] #[available_gas(20000000)] fn test_owner_of() { let state = setup(); - assert(state.erc721.owner_of(TOKEN_ID) == OWNER(), 'Should return owner'); + assert(state.owner_of(TOKEN_ID) == OWNER(), 'Should return owner'); } #[test] @@ -115,7 +122,7 @@ fn test_owner_of() { #[should_panic(expected: ('ERC721: invalid token ID',))] fn test_owner_of_non_minted() { let state = setup(); - state.erc721.owner_of(u256_from_felt252(7)); + state.owner_of(u256_from_felt252(7)); } #[test] @@ -123,7 +130,7 @@ fn test_owner_of_non_minted() { #[should_panic(expected: ('ERC721: invalid token ID',))] fn test_token_uri_non_minted() { let state = setup(); - state.erc721.token_uri(u256_from_felt252(7)); + state.token_uri(u256_from_felt252(7)); } #[test] @@ -133,9 +140,9 @@ fn test_get_approved() { let spender = SPENDER(); let token_id = TOKEN_ID; - assert(state.erc721.get_approved(token_id) == ZERO(), 'Should return non-approval'); - state.erc721._approve(spender, token_id); - assert(state.erc721.get_approved(token_id) == spender, 'Should return approval'); + assert(state.get_approved(token_id) == ZERO(), 'Should return non-approval'); + state._approve(spender, token_id); + assert(state.get_approved(token_id) == spender, 'Should return approval'); } #[test] @@ -143,30 +150,30 @@ fn test_get_approved() { #[should_panic(expected: ('ERC721: invalid token ID',))] fn test_get_approved_nonexistent() { let state = setup(); - state.erc721.get_approved(u256_from_felt252(7)); + state.get_approved(u256_from_felt252(7)); } #[test] #[available_gas(20000000)] fn test__exists() { - let mut state = STATE(); + let mut state = COMPONENT_STATE(); let zero = ZERO(); let token_id = TOKEN_ID; - assert(!state.erc721._exists(token_id), 'Token should not exist'); - let mut owner = state.erc721.ERC721_owners.read(token_id); + assert(!state._exists(token_id), 'Token should not exist'); + let mut owner = state.ERC721_owners.read(token_id); assert(owner == zero, ''); - state.erc721._mint(RECIPIENT(), token_id); + state._mint(RECIPIENT(), token_id); - assert(state.erc721._exists(token_id), 'Token should exist'); - owner = state.erc721.ERC721_owners.read(token_id); + assert(state._exists(token_id), 'Token should exist'); + owner = state.ERC721_owners.read(token_id); assert(owner == RECIPIENT(), 'Invalid owner'); - state.erc721._burn(token_id); + state._burn(token_id); - assert(!state.erc721._exists(token_id), 'Token should not exist'); - owner = state.erc721.ERC721_owners.read(token_id); + assert(!state._exists(token_id), 'Token should not exist'); + owner = state.ERC721_owners.read(token_id); assert(owner == zero, 'Invalid owner'); } @@ -180,10 +187,10 @@ fn test_approve_from_owner() { let mut state = setup(); testing::set_caller_address(OWNER()); - state.erc721.approve(SPENDER(), TOKEN_ID); + state.approve(SPENDER(), TOKEN_ID); assert_event_approval(OWNER(), SPENDER(), TOKEN_ID); - assert(state.erc721.get_approved(TOKEN_ID) == SPENDER(), 'Spender not approved correctly'); + assert(state.get_approved(TOKEN_ID) == SPENDER(), 'Spender not approved correctly'); } #[test] @@ -192,14 +199,14 @@ fn test_approve_from_operator() { let mut state = setup(); testing::set_caller_address(OWNER()); - state.erc721.set_approval_for_all(OPERATOR(), true); + state.set_approval_for_all(OPERATOR(), true); utils::drop_event(ZERO()); testing::set_caller_address(OPERATOR()); - state.erc721.approve(SPENDER(), TOKEN_ID); + state.approve(SPENDER(), TOKEN_ID); assert_event_approval(OWNER(), SPENDER(), TOKEN_ID); - assert(state.erc721.get_approved(TOKEN_ID) == SPENDER(), 'Spender not approved correctly'); + assert(state.get_approved(TOKEN_ID) == SPENDER(), 'Spender not approved correctly'); } #[test] @@ -209,7 +216,7 @@ fn test_approve_from_unauthorized() { let mut state = setup(); testing::set_caller_address(OTHER()); - state.erc721.approve(SPENDER(), TOKEN_ID); + state.approve(SPENDER(), TOKEN_ID); } #[test] @@ -219,25 +226,25 @@ fn test_approve_to_owner() { let mut state = setup(); testing::set_caller_address(OWNER()); - state.erc721.approve(OWNER(), TOKEN_ID); + state.approve(OWNER(), TOKEN_ID); } #[test] #[available_gas(20000000)] #[should_panic(expected: ('ERC721: invalid token ID',))] fn test_approve_nonexistent() { - let mut state = STATE(); - state.erc721.approve(SPENDER(), TOKEN_ID); + let mut state = COMPONENT_STATE(); + state.approve(SPENDER(), TOKEN_ID); } #[test] #[available_gas(20000000)] fn test__approve() { let mut state = setup(); - state.erc721._approve(SPENDER(), TOKEN_ID); + state._approve(SPENDER(), TOKEN_ID); assert_event_approval(OWNER(), SPENDER(), TOKEN_ID); - assert(state.erc721.get_approved(TOKEN_ID) == SPENDER(), 'Spender not approved correctly'); + assert(state.get_approved(TOKEN_ID) == SPENDER(), 'Spender not approved correctly'); } #[test] @@ -245,15 +252,15 @@ fn test__approve() { #[should_panic(expected: ('ERC721: approval to owner',))] fn test__approve_to_owner() { let mut state = setup(); - state.erc721._approve(OWNER(), TOKEN_ID); + state._approve(OWNER(), TOKEN_ID); } #[test] #[available_gas(20000000)] #[should_panic(expected: ('ERC721: invalid token ID',))] fn test__approve_nonexistent() { - let mut state = STATE(); - state.erc721._approve(SPENDER(), TOKEN_ID); + let mut state = COMPONENT_STATE(); + state._approve(SPENDER(), TOKEN_ID); } // @@ -263,79 +270,71 @@ fn test__approve_nonexistent() { #[test] #[available_gas(20000000)] fn test_set_approval_for_all() { - let mut state = STATE(); + let mut state = COMPONENT_STATE(); testing::set_caller_address(OWNER()); - assert(!state.erc721.is_approved_for_all(OWNER(), OPERATOR()), 'Invalid default value'); + assert(!state.is_approved_for_all(OWNER(), OPERATOR()), 'Invalid default value'); - state.erc721.set_approval_for_all(OPERATOR(), true); + state.set_approval_for_all(OPERATOR(), true); assert_event_approval_for_all(OWNER(), OPERATOR(), true); - assert( - state.erc721.is_approved_for_all(OWNER(), OPERATOR()), 'Operator not approved correctly' - ); + assert(state.is_approved_for_all(OWNER(), OPERATOR()), 'Operator not approved correctly'); - state.erc721.set_approval_for_all(OPERATOR(), false); + state.set_approval_for_all(OPERATOR(), false); assert_event_approval_for_all(OWNER(), OPERATOR(), false); - assert( - !state.erc721.is_approved_for_all(OWNER(), OPERATOR()), 'Approval not revoked correctly' - ); + assert(!state.is_approved_for_all(OWNER(), OPERATOR()), 'Approval not revoked correctly'); } #[test] #[available_gas(20000000)] #[should_panic(expected: ('ERC721: self approval',))] fn test_set_approval_for_all_owner_equal_operator_true() { - let mut state = STATE(); + let mut state = COMPONENT_STATE(); testing::set_caller_address(OWNER()); - state.erc721.set_approval_for_all(OWNER(), true); + state.set_approval_for_all(OWNER(), true); } #[test] #[available_gas(20000000)] #[should_panic(expected: ('ERC721: self approval',))] fn test_set_approval_for_all_owner_equal_operator_false() { - let mut state = STATE(); + let mut state = COMPONENT_STATE(); testing::set_caller_address(OWNER()); - state.erc721.set_approval_for_all(OWNER(), false); + state.set_approval_for_all(OWNER(), false); } #[test] #[available_gas(20000000)] fn test__set_approval_for_all() { - let mut state = STATE(); - assert(!state.erc721.is_approved_for_all(OWNER(), OPERATOR()), 'Invalid default value'); + let mut state = COMPONENT_STATE(); + assert(!state.is_approved_for_all(OWNER(), OPERATOR()), 'Invalid default value'); - state.erc721._set_approval_for_all(OWNER(), OPERATOR(), true); + state._set_approval_for_all(OWNER(), OPERATOR(), true); assert_event_approval_for_all(OWNER(), OPERATOR(), true); - assert( - state.erc721.is_approved_for_all(OWNER(), OPERATOR()), 'Operator not approved correctly' - ); + assert(state.is_approved_for_all(OWNER(), OPERATOR()), 'Operator not approved correctly'); - state.erc721._set_approval_for_all(OWNER(), OPERATOR(), false); + state._set_approval_for_all(OWNER(), OPERATOR(), false); assert_event_approval_for_all(OWNER(), OPERATOR(), false); - assert( - !state.erc721.is_approved_for_all(OWNER(), OPERATOR()), 'Operator not approved correctly' - ); + assert(!state.is_approved_for_all(OWNER(), OPERATOR()), 'Operator not approved correctly'); } #[test] #[available_gas(20000000)] #[should_panic(expected: ('ERC721: self approval',))] fn test__set_approval_for_all_owner_equal_operator_true() { - let mut state = STATE(); - state.erc721._set_approval_for_all(OWNER(), OWNER(), true); + let mut state = COMPONENT_STATE(); + state._set_approval_for_all(OWNER(), OWNER(), true); } #[test] #[available_gas(20000000)] #[should_panic(expected: ('ERC721: self approval',))] fn test__set_approval_for_all_owner_equal_operator_false() { - let mut state = STATE(); - state.erc721._set_approval_for_all(OWNER(), OWNER(), false); + let mut state = COMPONENT_STATE(); + state._set_approval_for_all(OWNER(), OWNER(), false); } // @@ -350,14 +349,14 @@ fn test_transfer_from_owner() { let owner = OWNER(); let recipient = RECIPIENT(); // set approval to check reset - state.erc721._approve(OTHER(), token_id); + state._approve(OTHER(), token_id); utils::drop_event(ZERO()); assert_state_before_transfer(owner, recipient, token_id); - assert(state.erc721.get_approved(token_id) == OTHER(), 'Approval not implicitly reset'); + assert(state.get_approved(token_id) == OTHER(), 'Approval not implicitly reset'); testing::set_caller_address(owner); - state.erc721.transfer_from(owner, recipient, token_id); + state.transfer_from(owner, recipient, token_id); assert_event_transfer(owner, recipient, token_id); assert_state_after_transfer(owner, recipient, token_id); @@ -371,14 +370,14 @@ fn test_transferFrom_owner() { let owner = OWNER(); let recipient = RECIPIENT(); // set approval to check reset - state.erc721._approve(OTHER(), token_id); + state._approve(OTHER(), token_id); utils::drop_event(ZERO()); assert_state_before_transfer(owner, recipient, token_id); - assert(state.erc721.get_approved(token_id) == OTHER(), 'Approval not implicitly reset'); + assert(state.get_approved(token_id) == OTHER(), 'Approval not implicitly reset'); testing::set_caller_address(owner); - state.erc721.transferFrom(owner, recipient, token_id); + state.transferFrom(owner, recipient, token_id); assert_event_transfer(owner, recipient, token_id); assert_state_after_transfer(owner, recipient, token_id); @@ -388,16 +387,16 @@ fn test_transferFrom_owner() { #[available_gas(20000000)] #[should_panic(expected: ('ERC721: invalid token ID',))] fn test_transfer_from_nonexistent() { - let mut state = STATE(); - state.erc721.transfer_from(ZERO(), RECIPIENT(), TOKEN_ID); + let mut state = COMPONENT_STATE(); + state.transfer_from(ZERO(), RECIPIENT(), TOKEN_ID); } #[test] #[available_gas(20000000)] #[should_panic(expected: ('ERC721: invalid token ID',))] fn test_transferFrom_nonexistent() { - let mut state = STATE(); - state.erc721.transferFrom(ZERO(), RECIPIENT(), TOKEN_ID); + let mut state = COMPONENT_STATE(); + state.transferFrom(ZERO(), RECIPIENT(), TOKEN_ID); } #[test] @@ -406,7 +405,7 @@ fn test_transferFrom_nonexistent() { fn test_transfer_from_to_zero() { let mut state = setup(); testing::set_caller_address(OWNER()); - state.erc721.transfer_from(OWNER(), ZERO(), TOKEN_ID); + state.transfer_from(OWNER(), ZERO(), TOKEN_ID); } #[test] @@ -416,7 +415,7 @@ fn test_transferFrom_to_zero() { let mut state = setup(); testing::set_caller_address(OWNER()); - state.erc721.transferFrom(OWNER(), ZERO(), TOKEN_ID); + state.transferFrom(OWNER(), ZERO(), TOKEN_ID); } #[test] @@ -424,15 +423,15 @@ fn test_transferFrom_to_zero() { fn test_transfer_from_to_owner() { let mut state = setup(); - assert(state.erc721.owner_of(TOKEN_ID) == OWNER(), 'Ownership before'); - assert(state.erc721.balance_of(OWNER()) == 1, 'Balance of owner before'); + assert(state.owner_of(TOKEN_ID) == OWNER(), 'Ownership before'); + assert(state.balance_of(OWNER()) == 1, 'Balance of owner before'); testing::set_caller_address(OWNER()); - state.erc721.transfer_from(OWNER(), OWNER(), TOKEN_ID); + state.transfer_from(OWNER(), OWNER(), TOKEN_ID); assert_event_transfer(OWNER(), OWNER(), TOKEN_ID); - assert(state.erc721.owner_of(TOKEN_ID) == OWNER(), 'Ownership after'); - assert(state.erc721.balance_of(OWNER()) == 1, 'Balance of owner after'); + assert(state.owner_of(TOKEN_ID) == OWNER(), 'Ownership after'); + assert(state.balance_of(OWNER()) == 1, 'Balance of owner after'); } #[test] @@ -440,15 +439,15 @@ fn test_transfer_from_to_owner() { fn test_transferFrom_to_owner() { let mut state = setup(); - assert(state.erc721.owner_of(TOKEN_ID) == OWNER(), 'Ownership before'); - assert(state.erc721.balance_of(OWNER()) == 1, 'Balance of owner before'); + assert(state.owner_of(TOKEN_ID) == OWNER(), 'Ownership before'); + assert(state.balance_of(OWNER()) == 1, 'Balance of owner before'); testing::set_caller_address(OWNER()); - state.erc721.transferFrom(OWNER(), OWNER(), TOKEN_ID); + state.transferFrom(OWNER(), OWNER(), TOKEN_ID); assert_event_transfer(OWNER(), OWNER(), TOKEN_ID); - assert(state.erc721.owner_of(TOKEN_ID) == OWNER(), 'Ownership after'); - assert(state.erc721.balance_of(OWNER()) == 1, 'Balance of owner after'); + assert(state.owner_of(TOKEN_ID) == OWNER(), 'Ownership after'); + assert(state.balance_of(OWNER()) == 1, 'Balance of owner after'); } #[test] @@ -461,11 +460,11 @@ fn test_transfer_from_approved() { assert_state_before_transfer(owner, recipient, token_id); testing::set_caller_address(owner); - state.erc721.approve(OPERATOR(), token_id); + state.approve(OPERATOR(), token_id); utils::drop_event(ZERO()); testing::set_caller_address(OPERATOR()); - state.erc721.transfer_from(owner, recipient, token_id); + state.transfer_from(owner, recipient, token_id); assert_event_transfer(owner, recipient, token_id); assert_state_after_transfer(owner, recipient, token_id); @@ -481,11 +480,11 @@ fn test_transferFrom_approved() { assert_state_before_transfer(owner, recipient, token_id); testing::set_caller_address(owner); - state.erc721.approve(OPERATOR(), token_id); + state.approve(OPERATOR(), token_id); utils::drop_event(ZERO()); testing::set_caller_address(OPERATOR()); - state.erc721.transferFrom(owner, recipient, token_id); + state.transferFrom(owner, recipient, token_id); assert_event_transfer(owner, recipient, token_id); assert_state_after_transfer(owner, recipient, token_id); @@ -502,11 +501,11 @@ fn test_transfer_from_approved_for_all() { assert_state_before_transfer(owner, recipient, token_id); testing::set_caller_address(owner); - state.erc721.set_approval_for_all(OPERATOR(), true); + state.set_approval_for_all(OPERATOR(), true); utils::drop_event(ZERO()); testing::set_caller_address(OPERATOR()); - state.erc721.transfer_from(owner, recipient, token_id); + state.transfer_from(owner, recipient, token_id); assert_event_transfer(owner, recipient, token_id); assert_state_after_transfer(owner, recipient, token_id); @@ -523,11 +522,11 @@ fn test_transferFrom_approved_for_all() { assert_state_before_transfer(owner, recipient, token_id); testing::set_caller_address(owner); - state.erc721.set_approval_for_all(OPERATOR(), true); + state.set_approval_for_all(OPERATOR(), true); utils::drop_event(ZERO()); testing::set_caller_address(OPERATOR()); - state.erc721.transferFrom(owner, recipient, token_id); + state.transferFrom(owner, recipient, token_id); assert_event_transfer(owner, recipient, token_id); assert_state_after_transfer(owner, recipient, token_id); @@ -539,7 +538,7 @@ fn test_transferFrom_approved_for_all() { fn test_transfer_from_unauthorized() { let mut state = setup(); testing::set_caller_address(OTHER()); - state.erc721.transfer_from(OWNER(), RECIPIENT(), TOKEN_ID); + state.transfer_from(OWNER(), RECIPIENT(), TOKEN_ID); } #[test] @@ -548,7 +547,7 @@ fn test_transfer_from_unauthorized() { fn test_transferFrom_unauthorized() { let mut state = setup(); testing::set_caller_address(OTHER()); - state.erc721.transferFrom(OWNER(), RECIPIENT(), TOKEN_ID); + state.transferFrom(OWNER(), RECIPIENT(), TOKEN_ID); } // @@ -566,7 +565,7 @@ fn test_safe_transfer_from_to_account() { assert_state_before_transfer(owner, account, token_id); testing::set_caller_address(owner); - state.erc721.safe_transfer_from(owner, account, token_id, DATA(true)); + state.safe_transfer_from(owner, account, token_id, DATA(true)); assert_event_transfer(owner, account, token_id); assert_state_after_transfer(owner, account, token_id); @@ -583,7 +582,7 @@ fn test_safeTransferFrom_to_account() { assert_state_before_transfer(owner, account, token_id); testing::set_caller_address(owner); - state.erc721.safeTransferFrom(owner, account, token_id, DATA(true)); + state.safeTransferFrom(owner, account, token_id, DATA(true)); assert_event_transfer(owner, account, token_id); assert_state_after_transfer(owner, account, token_id); @@ -600,7 +599,7 @@ fn test_safe_transfer_from_to_account_camel() { assert_state_before_transfer(owner, account, token_id); testing::set_caller_address(owner); - state.erc721.safe_transfer_from(owner, account, token_id, DATA(true)); + state.safe_transfer_from(owner, account, token_id, DATA(true)); assert_event_transfer(owner, account, token_id); assert_state_after_transfer(owner, account, token_id); @@ -617,7 +616,7 @@ fn test_safeTransferFrom_to_account_camel() { assert_state_before_transfer(owner, account, token_id); testing::set_caller_address(owner); - state.erc721.safeTransferFrom(owner, account, token_id, DATA(true)); + state.safeTransferFrom(owner, account, token_id, DATA(true)); assert_event_transfer(owner, account, token_id); assert_state_after_transfer(owner, account, token_id); @@ -634,7 +633,7 @@ fn test_safe_transfer_from_to_receiver() { assert_state_before_transfer(owner, receiver, token_id); testing::set_caller_address(owner); - state.erc721.safe_transfer_from(owner, receiver, token_id, DATA(true)); + state.safe_transfer_from(owner, receiver, token_id, DATA(true)); assert_event_transfer(owner, receiver, token_id); assert_state_after_transfer(owner, receiver, token_id); @@ -651,7 +650,7 @@ fn test_safeTransferFrom_to_receiver() { assert_state_before_transfer(owner, receiver, token_id); testing::set_caller_address(owner); - state.erc721.safeTransferFrom(owner, receiver, token_id, DATA(true)); + state.safeTransferFrom(owner, receiver, token_id, DATA(true)); assert_event_transfer(owner, receiver, token_id); assert_state_after_transfer(owner, receiver, token_id); @@ -668,7 +667,7 @@ fn test_safe_transfer_from_to_receiver_camel() { assert_state_before_transfer(owner, receiver, token_id); testing::set_caller_address(owner); - state.erc721.safe_transfer_from(owner, receiver, token_id, DATA(true)); + state.safe_transfer_from(owner, receiver, token_id, DATA(true)); assert_event_transfer(owner, receiver, token_id); assert_state_after_transfer(owner, receiver, token_id); @@ -685,7 +684,7 @@ fn test_safeTransferFrom_to_receiver_camel() { assert_state_before_transfer(owner, receiver, token_id); testing::set_caller_address(owner); - state.erc721.safeTransferFrom(owner, receiver, token_id, DATA(true)); + state.safeTransferFrom(owner, receiver, token_id, DATA(true)); assert_event_transfer(owner, receiver, token_id); assert_state_after_transfer(owner, receiver, token_id); @@ -701,7 +700,7 @@ fn test_safe_transfer_from_to_receiver_failure() { let owner = OWNER(); testing::set_caller_address(owner); - state.erc721.safe_transfer_from(owner, receiver, token_id, DATA(false)); + state.safe_transfer_from(owner, receiver, token_id, DATA(false)); } #[test] @@ -714,7 +713,7 @@ fn test_safeTransferFrom_to_receiver_failure() { let owner = OWNER(); testing::set_caller_address(owner); - state.erc721.safeTransferFrom(owner, receiver, token_id, DATA(false)); + state.safeTransferFrom(owner, receiver, token_id, DATA(false)); } #[test] @@ -727,7 +726,7 @@ fn test_safe_transfer_from_to_receiver_failure_camel() { let owner = OWNER(); testing::set_caller_address(owner); - state.erc721.safe_transfer_from(owner, receiver, token_id, DATA(false)); + state.safe_transfer_from(owner, receiver, token_id, DATA(false)); } #[test] @@ -740,7 +739,7 @@ fn test_safeTransferFrom_to_receiver_failure_camel() { let owner = OWNER(); testing::set_caller_address(owner); - state.erc721.safeTransferFrom(owner, receiver, token_id, DATA(false)); + state.safeTransferFrom(owner, receiver, token_id, DATA(false)); } #[test] @@ -753,7 +752,7 @@ fn test_safe_transfer_from_to_non_receiver() { let owner = OWNER(); testing::set_caller_address(owner); - state.erc721.safe_transfer_from(owner, recipient, token_id, DATA(true)); + state.safe_transfer_from(owner, recipient, token_id, DATA(true)); } #[test] @@ -766,23 +765,23 @@ fn test_safeTransferFrom_to_non_receiver() { let owner = OWNER(); testing::set_caller_address(owner); - state.erc721.safeTransferFrom(owner, recipient, token_id, DATA(true)); + state.safeTransferFrom(owner, recipient, token_id, DATA(true)); } #[test] #[available_gas(20000000)] #[should_panic(expected: ('ERC721: invalid token ID',))] fn test_safe_transfer_from_nonexistent() { - let mut state = STATE(); - state.erc721.safe_transfer_from(ZERO(), RECIPIENT(), TOKEN_ID, DATA(true)); + let mut state = COMPONENT_STATE(); + state.safe_transfer_from(ZERO(), RECIPIENT(), TOKEN_ID, DATA(true)); } #[test] #[available_gas(20000000)] #[should_panic(expected: ('ERC721: invalid token ID',))] fn test_safeTransferFrom_nonexistent() { - let mut state = STATE(); - state.erc721.safeTransferFrom(ZERO(), RECIPIENT(), TOKEN_ID, DATA(true)); + let mut state = COMPONENT_STATE(); + state.safeTransferFrom(ZERO(), RECIPIENT(), TOKEN_ID, DATA(true)); } #[test] @@ -791,7 +790,7 @@ fn test_safeTransferFrom_nonexistent() { fn test_safe_transfer_from_to_zero() { let mut state = setup(); testing::set_caller_address(OWNER()); - state.erc721.safe_transfer_from(OWNER(), ZERO(), TOKEN_ID, DATA(true)); + state.safe_transfer_from(OWNER(), ZERO(), TOKEN_ID, DATA(true)); } #[test] @@ -800,91 +799,91 @@ fn test_safe_transfer_from_to_zero() { fn test_safeTransferFrom_to_zero() { let mut state = setup(); testing::set_caller_address(OWNER()); - state.erc721.safeTransferFrom(OWNER(), ZERO(), TOKEN_ID, DATA(true)); + state.safeTransferFrom(OWNER(), ZERO(), TOKEN_ID, DATA(true)); } #[test] #[available_gas(20000000)] fn test_safe_transfer_from_to_owner() { - let mut state = STATE(); + let mut state = COMPONENT_STATE(); let token_id = TOKEN_ID; let owner = setup_receiver(); - state.erc721.initializer(NAME, SYMBOL); - state.erc721._mint(owner, token_id); + state.initializer(NAME, SYMBOL); + state._mint(owner, token_id); utils::drop_event(ZERO()); - assert(state.erc721.owner_of(token_id) == owner, 'Ownership before'); - assert(state.erc721.balance_of(owner) == 1, 'Balance of owner before'); + assert(state.owner_of(token_id) == owner, 'Ownership before'); + assert(state.balance_of(owner) == 1, 'Balance of owner before'); testing::set_caller_address(owner); - state.erc721.safe_transfer_from(owner, owner, token_id, DATA(true)); + state.safe_transfer_from(owner, owner, token_id, DATA(true)); assert_event_transfer(owner, owner, token_id); - assert(state.erc721.owner_of(token_id) == owner, 'Ownership after'); - assert(state.erc721.balance_of(owner) == 1, 'Balance of owner after'); + assert(state.owner_of(token_id) == owner, 'Ownership after'); + assert(state.balance_of(owner) == 1, 'Balance of owner after'); } #[test] #[available_gas(20000000)] fn test_safeTransferFrom_to_owner() { - let mut state = STATE(); + let mut state = COMPONENT_STATE(); let token_id = TOKEN_ID; let owner = setup_receiver(); - state.erc721.initializer(NAME, SYMBOL); - state.erc721._mint(owner, token_id); + state.initializer(NAME, SYMBOL); + state._mint(owner, token_id); utils::drop_event(ZERO()); - assert(state.erc721.owner_of(token_id) == owner, 'Ownership before'); - assert(state.erc721.balance_of(owner) == 1, 'Balance of owner before'); + assert(state.owner_of(token_id) == owner, 'Ownership before'); + assert(state.balance_of(owner) == 1, 'Balance of owner before'); testing::set_caller_address(owner); - state.erc721.safeTransferFrom(owner, owner, token_id, DATA(true)); + state.safeTransferFrom(owner, owner, token_id, DATA(true)); assert_event_transfer(owner, owner, token_id); - assert(state.erc721.owner_of(token_id) == owner, 'Ownership after'); - assert(state.erc721.balance_of(owner) == 1, 'Balance of owner after'); + assert(state.owner_of(token_id) == owner, 'Ownership after'); + assert(state.balance_of(owner) == 1, 'Balance of owner after'); } #[test] #[available_gas(20000000)] fn test_safe_transfer_from_to_owner_camel() { - let mut state = STATE(); + let mut state = COMPONENT_STATE(); let token_id = TOKEN_ID; let owner = setup_camel_receiver(); - state.erc721.initializer(NAME, SYMBOL); - state.erc721._mint(owner, token_id); + state.initializer(NAME, SYMBOL); + state._mint(owner, token_id); utils::drop_event(ZERO()); - assert(state.erc721.owner_of(token_id) == owner, 'Ownership before'); - assert(state.erc721.balance_of(owner) == 1, 'Balance of owner before'); + assert(state.owner_of(token_id) == owner, 'Ownership before'); + assert(state.balance_of(owner) == 1, 'Balance of owner before'); testing::set_caller_address(owner); - state.erc721.safe_transfer_from(owner, owner, token_id, DATA(true)); + state.safe_transfer_from(owner, owner, token_id, DATA(true)); assert_event_transfer(owner, owner, token_id); - assert(state.erc721.owner_of(token_id) == owner, 'Ownership after'); - assert(state.erc721.balance_of(owner) == 1, 'Balance of owner after'); + assert(state.owner_of(token_id) == owner, 'Ownership after'); + assert(state.balance_of(owner) == 1, 'Balance of owner after'); } #[test] #[available_gas(20000000)] fn test_safeTransferFrom_to_owner_camel() { - let mut state = STATE(); + let mut state = COMPONENT_STATE(); let token_id = TOKEN_ID; let owner = setup_camel_receiver(); - state.erc721.initializer(NAME, SYMBOL); - state.erc721._mint(owner, token_id); + state.initializer(NAME, SYMBOL); + state._mint(owner, token_id); utils::drop_event(ZERO()); - assert(state.erc721.owner_of(token_id) == owner, 'Ownership before'); - assert(state.erc721.balance_of(owner) == 1, 'Balance of owner before'); + assert(state.owner_of(token_id) == owner, 'Ownership before'); + assert(state.balance_of(owner) == 1, 'Balance of owner before'); testing::set_caller_address(owner); - state.erc721.safeTransferFrom(owner, owner, token_id, DATA(true)); + state.safeTransferFrom(owner, owner, token_id, DATA(true)); assert_event_transfer(owner, owner, token_id); - assert(state.erc721.owner_of(token_id) == owner, 'Ownership after'); - assert(state.erc721.balance_of(owner) == 1, 'Balance of owner after'); + assert(state.owner_of(token_id) == owner, 'Ownership after'); + assert(state.balance_of(owner) == 1, 'Balance of owner after'); } #[test] @@ -898,11 +897,11 @@ fn test_safe_transfer_from_approved() { assert_state_before_transfer(owner, receiver, token_id); testing::set_caller_address(owner); - state.erc721.approve(OPERATOR(), token_id); + state.approve(OPERATOR(), token_id); utils::drop_event(ZERO()); testing::set_caller_address(OPERATOR()); - state.erc721.safe_transfer_from(owner, receiver, token_id, DATA(true)); + state.safe_transfer_from(owner, receiver, token_id, DATA(true)); assert_event_transfer(owner, receiver, token_id); assert_state_after_transfer(owner, receiver, token_id); @@ -919,11 +918,11 @@ fn test_safeTransferFrom_approved() { assert_state_before_transfer(owner, receiver, token_id); testing::set_caller_address(owner); - state.erc721.approve(OPERATOR(), token_id); + state.approve(OPERATOR(), token_id); utils::drop_event(ZERO()); testing::set_caller_address(OPERATOR()); - state.erc721.safeTransferFrom(owner, receiver, token_id, DATA(true)); + state.safeTransferFrom(owner, receiver, token_id, DATA(true)); assert_event_transfer(owner, receiver, token_id); assert_state_after_transfer(owner, receiver, token_id); @@ -940,11 +939,11 @@ fn test_safe_transfer_from_approved_camel() { assert_state_before_transfer(owner, receiver, token_id); testing::set_caller_address(owner); - state.erc721.approve(OPERATOR(), token_id); + state.approve(OPERATOR(), token_id); utils::drop_event(ZERO()); testing::set_caller_address(OPERATOR()); - state.erc721.safe_transfer_from(owner, receiver, token_id, DATA(true)); + state.safe_transfer_from(owner, receiver, token_id, DATA(true)); assert_event_transfer(owner, receiver, token_id); assert_state_after_transfer(owner, receiver, token_id); @@ -961,11 +960,11 @@ fn test_safeTransferFrom_approved_camel() { assert_state_before_transfer(owner, receiver, token_id); testing::set_caller_address(owner); - state.erc721.approve(OPERATOR(), token_id); + state.approve(OPERATOR(), token_id); utils::drop_event(ZERO()); testing::set_caller_address(OPERATOR()); - state.erc721.safeTransferFrom(owner, receiver, token_id, DATA(true)); + state.safeTransferFrom(owner, receiver, token_id, DATA(true)); assert_event_transfer(owner, receiver, token_id); assert_state_after_transfer(owner, receiver, token_id); @@ -982,11 +981,11 @@ fn test_safe_transfer_from_approved_for_all() { assert_state_before_transfer(owner, receiver, token_id); testing::set_caller_address(owner); - state.erc721.set_approval_for_all(OPERATOR(), true); + state.set_approval_for_all(OPERATOR(), true); utils::drop_event(ZERO()); testing::set_caller_address(OPERATOR()); - state.erc721.safe_transfer_from(owner, receiver, token_id, DATA(true)); + state.safe_transfer_from(owner, receiver, token_id, DATA(true)); assert_event_transfer(owner, receiver, token_id); assert_state_after_transfer(owner, receiver, token_id); @@ -1003,11 +1002,11 @@ fn test_safeTransferFrom_approved_for_all() { assert_state_before_transfer(owner, receiver, token_id); testing::set_caller_address(owner); - state.erc721.set_approval_for_all(OPERATOR(), true); + state.set_approval_for_all(OPERATOR(), true); utils::drop_event(ZERO()); testing::set_caller_address(OPERATOR()); - state.erc721.safeTransferFrom(owner, receiver, token_id, DATA(true)); + state.safeTransferFrom(owner, receiver, token_id, DATA(true)); assert_event_transfer(owner, receiver, token_id); assert_state_after_transfer(owner, receiver, token_id); @@ -1024,11 +1023,11 @@ fn test_safe_transfer_from_approved_for_all_camel() { assert_state_before_transfer(owner, receiver, token_id); testing::set_caller_address(owner); - state.erc721.set_approval_for_all(OPERATOR(), true); + state.set_approval_for_all(OPERATOR(), true); utils::drop_event(ZERO()); testing::set_caller_address(OPERATOR()); - state.erc721.safe_transfer_from(owner, receiver, token_id, DATA(true)); + state.safe_transfer_from(owner, receiver, token_id, DATA(true)); assert_event_transfer(owner, receiver, token_id); assert_state_after_transfer(owner, receiver, token_id); @@ -1045,11 +1044,11 @@ fn test_safeTransferFrom_approved_for_all_camel() { assert_state_before_transfer(owner, receiver, token_id); testing::set_caller_address(owner); - state.erc721.set_approval_for_all(OPERATOR(), true); + state.set_approval_for_all(OPERATOR(), true); utils::drop_event(ZERO()); testing::set_caller_address(OPERATOR()); - state.erc721.safeTransferFrom(owner, receiver, token_id, DATA(true)); + state.safeTransferFrom(owner, receiver, token_id, DATA(true)); assert_event_transfer(owner, receiver, token_id); assert_state_after_transfer(owner, receiver, token_id); @@ -1061,7 +1060,7 @@ fn test_safeTransferFrom_approved_for_all_camel() { fn test_safe_transfer_from_unauthorized() { let mut state = setup(); testing::set_caller_address(OTHER()); - state.erc721.safe_transfer_from(OWNER(), RECIPIENT(), TOKEN_ID, DATA(true)); + state.safe_transfer_from(OWNER(), RECIPIENT(), TOKEN_ID, DATA(true)); } #[test] @@ -1070,7 +1069,7 @@ fn test_safe_transfer_from_unauthorized() { fn test_safeTransferFrom_unauthorized() { let mut state = setup(); testing::set_caller_address(OTHER()); - state.erc721.safeTransferFrom(OWNER(), RECIPIENT(), TOKEN_ID, DATA(true)); + state.safeTransferFrom(OWNER(), RECIPIENT(), TOKEN_ID, DATA(true)); } // @@ -1087,7 +1086,7 @@ fn test__transfer() { assert_state_before_transfer(owner, recipient, token_id); - state.erc721._transfer(owner, recipient, token_id); + state._transfer(owner, recipient, token_id); assert_event_transfer(owner, recipient, token_id); assert_state_after_transfer(owner, recipient, token_id); @@ -1097,8 +1096,8 @@ fn test__transfer() { #[available_gas(20000000)] #[should_panic(expected: ('ERC721: invalid token ID',))] fn test__transfer_nonexistent() { - let mut state = STATE(); - state.erc721._transfer(ZERO(), RECIPIENT(), TOKEN_ID); + let mut state = COMPONENT_STATE(); + state._transfer(ZERO(), RECIPIENT(), TOKEN_ID); } #[test] @@ -1106,7 +1105,7 @@ fn test__transfer_nonexistent() { #[should_panic(expected: ('ERC721: invalid receiver',))] fn test__transfer_to_zero() { let mut state = setup(); - state.erc721._transfer(OWNER(), ZERO(), TOKEN_ID); + state._transfer(OWNER(), ZERO(), TOKEN_ID); } #[test] @@ -1114,7 +1113,7 @@ fn test__transfer_to_zero() { #[should_panic(expected: ('ERC721: wrong sender',))] fn test__transfer_from_invalid_owner() { let mut state = setup(); - state.erc721._transfer(RECIPIENT(), OWNER(), TOKEN_ID); + state._transfer(RECIPIENT(), OWNER(), TOKEN_ID); } // @@ -1124,12 +1123,12 @@ fn test__transfer_from_invalid_owner() { #[test] #[available_gas(20000000)] fn test__mint() { - let mut state = STATE(); + let mut state = COMPONENT_STATE(); let recipient = RECIPIENT(); let token_id = TOKEN_ID; assert_state_before_mint(recipient); - state.erc721._mint(recipient, TOKEN_ID); + state._mint(recipient, TOKEN_ID); assert_event_transfer(ZERO(), recipient, token_id); assert_state_after_mint(recipient, token_id); @@ -1139,8 +1138,8 @@ fn test__mint() { #[available_gas(20000000)] #[should_panic(expected: ('ERC721: invalid receiver',))] fn test__mint_to_zero() { - let mut state = STATE(); - state.erc721._mint(ZERO(), TOKEN_ID); + let mut state = COMPONENT_STATE(); + state._mint(ZERO(), TOKEN_ID); } #[test] @@ -1148,7 +1147,7 @@ fn test__mint_to_zero() { #[should_panic(expected: ('ERC721: token already minted',))] fn test__mint_already_exist() { let mut state = setup(); - state.erc721._mint(RECIPIENT(), TOKEN_ID); + state._mint(RECIPIENT(), TOKEN_ID); } // @@ -1158,12 +1157,12 @@ fn test__mint_already_exist() { #[test] #[available_gas(20000000)] fn test__safe_mint_to_receiver() { - let mut state = STATE(); + let mut state = COMPONENT_STATE(); let recipient = setup_receiver(); let token_id = TOKEN_ID; assert_state_before_mint(recipient); - state.erc721._safe_mint(recipient, token_id, DATA(true)); + state._safe_mint(recipient, token_id, DATA(true)); assert_event_transfer(ZERO(), recipient, token_id); assert_state_after_mint(recipient, token_id); @@ -1172,12 +1171,12 @@ fn test__safe_mint_to_receiver() { #[test] #[available_gas(20000000)] fn test__safe_mint_to_receiver_camel() { - let mut state = STATE(); + let mut state = COMPONENT_STATE(); let recipient = setup_camel_receiver(); let token_id = TOKEN_ID; assert_state_before_mint(recipient); - state.erc721._safe_mint(recipient, token_id, DATA(true)); + state._safe_mint(recipient, token_id, DATA(true)); assert_event_transfer(ZERO(), recipient, token_id); assert_state_after_mint(recipient, token_id); @@ -1186,12 +1185,12 @@ fn test__safe_mint_to_receiver_camel() { #[test] #[available_gas(20000000)] fn test__safe_mint_to_account() { - let mut state = STATE(); + let mut state = COMPONENT_STATE(); let account = setup_account(); let token_id = TOKEN_ID; assert_state_before_mint(account); - state.erc721._safe_mint(account, token_id, DATA(true)); + state._safe_mint(account, token_id, DATA(true)); assert_event_transfer(ZERO(), account, token_id); assert_state_after_mint(account, token_id); @@ -1200,12 +1199,12 @@ fn test__safe_mint_to_account() { #[test] #[available_gas(20000000)] fn test__safe_mint_to_account_camel() { - let mut state = STATE(); + let mut state = COMPONENT_STATE(); let account = setup_camel_account(); let token_id = TOKEN_ID; assert_state_before_mint(account); - state.erc721._safe_mint(account, token_id, DATA(true)); + state._safe_mint(account, token_id, DATA(true)); assert_event_transfer(ZERO(), account, token_id); assert_state_after_mint(account, token_id); @@ -1215,12 +1214,12 @@ fn test__safe_mint_to_account_camel() { #[available_gas(20000000)] #[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))] fn test__safe_mint_to_non_receiver() { - let mut state = STATE(); + let mut state = COMPONENT_STATE(); let recipient = utils::deploy(NonImplementingMock::TEST_CLASS_HASH, array![]); let token_id = TOKEN_ID; assert_state_before_mint(recipient); - state.erc721._safe_mint(recipient, token_id, DATA(true)); + state._safe_mint(recipient, token_id, DATA(true)); assert_state_after_mint(recipient, token_id); } @@ -1228,12 +1227,12 @@ fn test__safe_mint_to_non_receiver() { #[available_gas(20000000)] #[should_panic(expected: ('ERC721: safe mint failed',))] fn test__safe_mint_to_receiver_failure() { - let mut state = STATE(); + let mut state = COMPONENT_STATE(); let recipient = setup_receiver(); let token_id = TOKEN_ID; assert_state_before_mint(recipient); - state.erc721._safe_mint(recipient, token_id, DATA(false)); + state._safe_mint(recipient, token_id, DATA(false)); assert_state_after_mint(recipient, token_id); } @@ -1241,12 +1240,12 @@ fn test__safe_mint_to_receiver_failure() { #[available_gas(20000000)] #[should_panic(expected: ('ERC721: safe mint failed',))] fn test__safe_mint_to_receiver_failure_camel() { - let mut state = STATE(); + let mut state = COMPONENT_STATE(); let recipient = setup_camel_receiver(); let token_id = TOKEN_ID; assert_state_before_mint(recipient); - state.erc721._safe_mint(recipient, token_id, DATA(false)); + state._safe_mint(recipient, token_id, DATA(false)); assert_state_after_mint(recipient, token_id); } @@ -1254,8 +1253,8 @@ fn test__safe_mint_to_receiver_failure_camel() { #[available_gas(20000000)] #[should_panic(expected: ('ERC721: invalid receiver',))] fn test__safe_mint_to_zero() { - let mut state = STATE(); - state.erc721._safe_mint(ZERO(), TOKEN_ID, DATA(true)); + let mut state = COMPONENT_STATE(); + state._safe_mint(ZERO(), TOKEN_ID, DATA(true)); } #[test] @@ -1263,7 +1262,7 @@ fn test__safe_mint_to_zero() { #[should_panic(expected: ('ERC721: token already minted',))] fn test__safe_mint_already_exist() { let mut state = setup(); - state.erc721._safe_mint(RECIPIENT(), TOKEN_ID, DATA(true)); + state._safe_mint(RECIPIENT(), TOKEN_ID, DATA(true)); } // @@ -1275,27 +1274,27 @@ fn test__safe_mint_already_exist() { fn test__burn() { let mut state = setup(); - state.erc721._approve(OTHER(), TOKEN_ID); + state._approve(OTHER(), TOKEN_ID); utils::drop_event(ZERO()); - assert(state.erc721.owner_of(TOKEN_ID) == OWNER(), 'Ownership before'); - assert(state.erc721.balance_of(OWNER()) == 1, 'Balance of owner before'); - assert(state.erc721.get_approved(TOKEN_ID) == OTHER(), 'Approval before'); + 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'); - state.erc721._burn(TOKEN_ID); + state._burn(TOKEN_ID); assert_event_transfer(OWNER(), ZERO(), TOKEN_ID); - assert(state.erc721.ERC721_owners.read(TOKEN_ID) == ZERO(), 'Ownership after'); - assert(state.erc721.balance_of(OWNER()) == 0, 'Balance of owner after'); - assert(state.erc721.ERC721_token_approvals.read(TOKEN_ID) == ZERO(), 'Approval after'); + 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'); } #[test] #[available_gas(20000000)] #[should_panic(expected: ('ERC721: invalid token ID',))] fn test__burn_nonexistent() { - let mut state = STATE(); - state.erc721._burn(TOKEN_ID); + let mut state = COMPONENT_STATE(); + state._burn(TOKEN_ID); } // @@ -1307,17 +1306,17 @@ fn test__burn_nonexistent() { fn test__set_token_uri() { let mut state = setup(); - assert(state.erc721.token_uri(TOKEN_ID) == 0, 'URI should be 0'); - state.erc721._set_token_uri(TOKEN_ID, URI); - assert(state.erc721.token_uri(TOKEN_ID) == URI, 'URI should be set'); + assert(state.token_uri(TOKEN_ID) == 0, 'URI should be 0'); + state._set_token_uri(TOKEN_ID, URI); + assert(state.token_uri(TOKEN_ID) == URI, 'URI should be set'); } #[test] #[available_gas(20000000)] #[should_panic(expected: ('ERC721: invalid token ID',))] fn test__set_token_uri_nonexistent() { - let mut state = STATE(); - state.erc721._set_token_uri(TOKEN_ID, URI); + let mut state = COMPONENT_STATE(); + state._set_token_uri(TOKEN_ID, URI); } // @@ -1327,30 +1326,30 @@ fn test__set_token_uri_nonexistent() { fn assert_state_before_transfer( owner: ContractAddress, recipient: ContractAddress, token_id: u256 ) { - let state = STATE(); - assert(state.erc721.owner_of(token_id) == owner, 'Ownership before'); - assert(state.erc721.balance_of(owner) == 1, 'Balance of owner before'); - assert(state.erc721.balance_of(recipient) == 0, 'Balance of recipient before'); + 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'); } fn assert_state_after_transfer(owner: ContractAddress, recipient: ContractAddress, token_id: u256) { - let state = STATE(); - assert(state.erc721.owner_of(token_id) == recipient, 'Ownership after'); - assert(state.erc721.balance_of(owner) == 0, 'Balance of owner after'); - assert(state.erc721.balance_of(recipient) == 1, 'Balance of recipient after'); - assert(state.erc721.get_approved(token_id) == ZERO(), 'Approval not implicitly reset'); + 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'); } fn assert_state_before_mint(recipient: ContractAddress) { - let state = STATE(); - assert(state.erc721.balance_of(recipient) == 0, 'Balance of recipient before'); + let state = COMPONENT_STATE(); + assert(state.balance_of(recipient) == 0, 'Balance of recipient before'); } fn assert_state_after_mint(recipient: ContractAddress, token_id: u256) { - let state = STATE(); - assert(state.erc721.owner_of(token_id) == recipient, 'Ownership after'); - assert(state.erc721.balance_of(recipient) == 1, 'Balance of recipient after'); - assert(state.erc721.get_approved(token_id) == ZERO(), 'Approval implicitly set'); + 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'); } fn assert_event_approval_for_all(