diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f3b159a1..b182243de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed (Breaking) +- The initializer in `OwnableComponent` now checks that `owner` is not the zero address (#1221) - Add `verifying_contract` member to the `Delegation` struct used in Votes `delegate_by_sig` (#1214) use crate::votes::VotesComponent::VotingUnitsTrait; - VotingUnitsTrait moved from `openzeppelin_governance::votes::votes` to `openzeppelin_governance::votes::VotesComponent` (#1214) diff --git a/docs/modules/ROOT/pages/api/access.adoc b/docs/modules/ROOT/pages/api/access.adoc index 2b47dd86d..d3547d22c 100644 --- a/docs/modules/ROOT/pages/api/access.adoc +++ b/docs/modules/ROOT/pages/api/access.adoc @@ -156,7 +156,8 @@ Emits an xref:OwnableComponent-OwnershipTransferred[OwnershipTransferred] event. [[OwnableComponent-two-step-transfer_ownership]] ==== `[.contract-item-name]#++transfer_ownership++#++(ref self: ContractState, new_owner: ContractAddress)++` [.item-kind]#external# -Starts the two step ownership transfer process, by setting the pending owner. +Starts the two step ownership transfer process, by setting the pending owner. Setting `new_owner` to the zero address is allowed, this can be used to cancel an initiated ownership transfer. + Can only be called by the current owner. Emits an xref:OwnableComponent-OwnershipTransferStarted[OwnershipTransferStarted] event. @@ -211,6 +212,10 @@ See xref:OwnableComponent-two-step-renounce_ownership[renounce_ownership]. Initializes the contract and sets `owner` as the initial owner. +Requirements: + +- `owner` cannot be the zero address. + Emits an xref:OwnableComponent-OwnershipTransferred[OwnershipTransferred] event. [.contract-item] diff --git a/packages/access/src/accesscontrol/accesscontrol.cairo b/packages/access/src/accesscontrol/accesscontrol.cairo index 239306afe..c9d0eb906 100644 --- a/packages/access/src/accesscontrol/accesscontrol.cairo +++ b/packages/access/src/accesscontrol/accesscontrol.cairo @@ -3,8 +3,19 @@ /// # AccessControl Component /// -/// The AccessControl component allows contracts to implement role-based access control mechanisms. -/// Roles are referred to by their `felt252` identifier. +/// The AccessControl component enables role-based access control mechanisms. This is a lightweight +/// implementation that doesn't support on-chain enumeration of role members, though role membership +/// can be tracked off-chain through contract events. +/// +/// Roles can be granted and revoked dynamically via `grant_role` and `revoke_role`. Each role +/// has an associated admin role that controls who can grant and revoke it. By default, all roles +/// use `DEFAULT_ADMIN_ROLE` as their admin role. +/// Accounts can also renounce roles they have been granted by using `renounce_role`. +/// +/// More complex role hierarchies can be created using `set_role_admin`. +/// +/// WARNING: The `DEFAULT_ADMIN_ROLE` is its own admin, meaning it can grant and revoke itself. +/// Extra precautions should be taken to secure accounts with this role. #[starknet::component] pub mod AccessControlComponent { use crate::accesscontrol::interface; @@ -31,8 +42,8 @@ pub mod AccessControlComponent { /// Emitted when `account` is granted `role`. /// - /// `sender` is the account that originated the contract call, an admin role - /// bearer (except if `_grant_role` is called during initialization from the constructor). + /// `sender` is the account that originated the contract call, an account with the admin role + /// or the deployer address if `grant_role` is called from the constructor. #[derive(Drop, PartialEq, starknet::Event)] pub struct RoleGranted { pub role: felt252, @@ -40,7 +51,7 @@ pub mod AccessControlComponent { pub sender: ContractAddress } - /// Emitted when `account` is revoked `role`. + /// Emitted when `role` is revoked for `account`. /// /// `sender` is the account that originated the contract call: /// - If using `revoke_role`, it is the admin role bearer. @@ -55,7 +66,7 @@ pub mod AccessControlComponent { /// Emitted when `new_admin_role` is set as `role`'s admin role, replacing `previous_admin_role` /// /// `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite - /// {RoleAdminChanged} not being emitted signaling this. + /// `RoleAdminChanged` not being emitted signaling this. #[derive(Drop, PartialEq, starknet::Event)] pub struct RoleAdminChanged { pub role: felt252, @@ -89,7 +100,7 @@ pub mod AccessControlComponent { /// Grants `role` to `account`. /// - /// If `account` had not been already granted `role`, emits a `RoleGranted` event. + /// If `account` has not been already granted `role`, emits a `RoleGranted` event. /// /// Requirements: /// @@ -104,7 +115,7 @@ pub mod AccessControlComponent { /// Revokes `role` from `account`. /// - /// If `account` had been granted `role`, emits a `RoleRevoked` event. + /// If `account` has been granted `role`, emits a `RoleRevoked` event. /// /// Requirements: /// @@ -132,7 +143,7 @@ pub mod AccessControlComponent { fn renounce_role( ref self: ComponentState, role: felt252, account: ContractAddress ) { - let caller: ContractAddress = get_caller_address(); + let caller = get_caller_address(); assert(caller == account, Errors::INVALID_CALLER); self._revoke_role(role, account); } diff --git a/packages/access/src/ownable/ownable.cairo b/packages/access/src/ownable/ownable.cairo index b001e8dbd..321114793 100644 --- a/packages/access/src/ownable/ownable.cairo +++ b/packages/access/src/ownable/ownable.cairo @@ -35,6 +35,8 @@ pub mod OwnableComponent { OwnershipTransferStarted: OwnershipTransferStarted } + /// Emitted when `new_owner` is set as owner of the contract. + /// `new_owner` can be set to zero only if the ownership is renounced. #[derive(Drop, PartialEq, starknet::Event)] pub struct OwnershipTransferred { #[key] @@ -43,6 +45,9 @@ pub mod OwnableComponent { pub new_owner: ContractAddress, } + /// Emitted when `transfer_ownership` is called on a contract that implements `IOwnableTwoStep`. + /// `previous_owner` is the address of the current owner. + /// `new_owner` is the address of the pending owner. #[derive(Drop, PartialEq, starknet::Event)] pub struct OwnershipTransferStarted { #[key] @@ -54,7 +59,6 @@ pub mod OwnableComponent { pub mod Errors { pub const NOT_OWNER: felt252 = 'Caller is not the owner'; pub const NOT_PENDING_OWNER: felt252 = 'Caller is not the pending owner'; - pub const ZERO_ADDRESS_CALLER: felt252 = 'Caller is the zero address'; pub const ZERO_ADDRESS_OWNER: felt252 = 'New owner is the zero address'; } @@ -83,8 +87,8 @@ pub mod OwnableComponent { self._transfer_ownership(new_owner); } - /// Leaves the contract without owner. It will not be possible to call `assert_only_owner` - /// functions anymore. Can only be called by the current owner. + /// Leaves the contract without an owner. It will not be possible to call + /// `assert_only_owner` functions anymore. Can only be called by the current owner. /// /// Requirements: /// @@ -129,6 +133,8 @@ pub mod OwnableComponent { /// Starts the two-step ownership transfer process by setting the pending owner. /// + /// Setting `new_owner` to the zero address is allowed; this can be used to cancel an + /// initiated ownership transfer. /// Requirements: /// /// - The caller is the contract owner. @@ -150,7 +156,8 @@ pub mod OwnableComponent { /// /// Emits an `OwnershipTransferred` event. fn renounce_ownership(ref self: ComponentState) { - Ownable::renounce_ownership(ref self); + self.assert_only_owner(); + self._transfer_ownership(Zero::zero()); } } @@ -270,8 +277,13 @@ pub mod OwnableComponent { > of InternalTrait { /// Sets the contract's initial owner. /// + /// Requirements: + /// + /// - `owner` is not the zero address. + /// /// This function should be called at construction time. fn initializer(ref self: ComponentState, owner: ContractAddress) { + assert(!owner.is_zero(), Errors::ZERO_ADDRESS_OWNER); self._transfer_ownership(owner); } @@ -280,7 +292,6 @@ pub mod OwnableComponent { fn assert_only_owner(self: @ComponentState) { let owner = self.Ownable_owner.read(); let caller = get_caller_address(); - assert(!caller.is_zero(), Errors::ZERO_ADDRESS_CALLER); assert(caller == owner, Errors::NOT_OWNER); } @@ -297,10 +308,7 @@ pub mod OwnableComponent { let previous_owner: ContractAddress = self.Ownable_owner.read(); self.Ownable_owner.write(new_owner); - self - .emit( - OwnershipTransferred { previous_owner: previous_owner, new_owner: new_owner } - ); + self.emit(OwnershipTransferred { previous_owner, new_owner }); } /// Sets a new pending owner. @@ -311,12 +319,7 @@ pub mod OwnableComponent { fn _propose_owner(ref self: ComponentState, new_owner: ContractAddress) { let previous_owner = self.Ownable_owner.read(); self.Ownable_pending_owner.write(new_owner); - self - .emit( - OwnershipTransferStarted { - previous_owner: previous_owner, new_owner: new_owner - } - ); + self.emit(OwnershipTransferStarted { previous_owner, new_owner }); } } } diff --git a/packages/access/src/tests/test_accesscontrol.cairo b/packages/access/src/tests/test_accesscontrol.cairo index 81adcddfb..3b09a01f7 100644 --- a/packages/access/src/tests/test_accesscontrol.cairo +++ b/packages/access/src/tests/test_accesscontrol.cairo @@ -81,7 +81,7 @@ fn test_assert_only_role() { } #[test] -#[should_panic(expected: ('Caller is missing role',))] +#[should_panic(expected: 'Caller is missing role')] fn test_assert_only_role_unauthorized() { let state = setup(); start_cheat_caller_address(test_address(), OTHER()); @@ -89,7 +89,7 @@ fn test_assert_only_role_unauthorized() { } #[test] -#[should_panic(expected: ('Caller is missing role',))] +#[should_panic(expected: 'Caller is missing role')] fn test_assert_only_role_unauthorized_when_authorized_for_another_role() { let mut state = setup(); state.grant_role(ROLE, AUTHORIZED()); @@ -151,7 +151,7 @@ fn test_grantRole_multiple_times_for_granted_role() { } #[test] -#[should_panic(expected: ('Caller is missing role',))] +#[should_panic(expected: 'Caller is missing role')] fn test_grant_role_unauthorized() { let mut state = setup(); start_cheat_caller_address(test_address(), AUTHORIZED()); @@ -159,7 +159,7 @@ fn test_grant_role_unauthorized() { } #[test] -#[should_panic(expected: ('Caller is missing role',))] +#[should_panic(expected: 'Caller is missing role')] fn test_grantRole_unauthorized() { let mut state = setup(); start_cheat_caller_address(test_address(), AUTHORIZED()); @@ -245,7 +245,7 @@ fn test_revokeRole_multiple_times_for_granted_role() { } #[test] -#[should_panic(expected: ('Caller is missing role',))] +#[should_panic(expected: 'Caller is missing role')] fn test_revoke_role_unauthorized() { let mut state = setup(); start_cheat_caller_address(test_address(), OTHER()); @@ -253,7 +253,7 @@ fn test_revoke_role_unauthorized() { } #[test] -#[should_panic(expected: ('Caller is missing role',))] +#[should_panic(expected: 'Caller is missing role')] fn test_revokeRole_unauthorized() { let mut state = setup(); start_cheat_caller_address(test_address(), OTHER()); @@ -345,7 +345,7 @@ fn test_renounceRole_multiple_times_for_granted_role() { } #[test] -#[should_panic(expected: ('Can only renounce role for self',))] +#[should_panic(expected: 'Can only renounce role for self')] fn test_renounce_role_unauthorized() { let mut state = setup(); let contract_address = test_address(); @@ -357,7 +357,7 @@ fn test_renounce_role_unauthorized() { } #[test] -#[should_panic(expected: ('Can only renounce role for self',))] +#[should_panic(expected: 'Can only renounce role for self')] fn test_renounceRole_unauthorized() { let mut state = setup(); start_cheat_caller_address(test_address(), ADMIN()); @@ -423,7 +423,7 @@ fn test_new_admin_can_revoke_roles() { } #[test] -#[should_panic(expected: ('Caller is missing role',))] +#[should_panic(expected: 'Caller is missing role')] fn test_previous_admin_cannot_grant_roles() { let mut state = setup(); state.set_role_admin(ROLE, OTHER_ROLE); @@ -432,7 +432,7 @@ fn test_previous_admin_cannot_grant_roles() { } #[test] -#[should_panic(expected: ('Caller is missing role',))] +#[should_panic(expected: 'Caller is missing role')] fn test_previous_admin_cannot_revoke_roles() { let mut state = setup(); state.set_role_admin(ROLE, OTHER_ROLE); diff --git a/packages/access/src/tests/test_ownable.cairo b/packages/access/src/tests/test_ownable.cairo index 46c9d56da..329823c81 100644 --- a/packages/access/src/tests/test_ownable.cairo +++ b/packages/access/src/tests/test_ownable.cairo @@ -44,6 +44,13 @@ fn test_initializer_owner() { assert_eq!(new_owner, OWNER()); } +#[test] +#[should_panic(expected: 'New owner is the zero address')] +fn test_initializer_zero_owner() { + let mut state = COMPONENT_STATE(); + state.initializer(ZERO()); +} + // // assert_only_owner // @@ -56,20 +63,13 @@ fn test_assert_only_owner() { } #[test] -#[should_panic(expected: ('Caller is not the owner',))] +#[should_panic(expected: 'Caller is not the owner')] fn test_assert_only_owner_when_not_owner() { let state = setup(); start_cheat_caller_address(test_address(), OTHER()); state.assert_only_owner(); } -#[test] -#[should_panic(expected: ('Caller is the zero address',))] -fn test_assert_only_owner_when_caller_zero() { - let state = setup(); - state.assert_only_owner(); -} - // // _transfer_ownership // @@ -117,7 +117,7 @@ fn test_transfer_ownership() { } #[test] -#[should_panic(expected: ('New owner is the zero address',))] +#[should_panic(expected: 'New owner is the zero address')] fn test_transfer_ownership_to_zero() { let mut state = setup(); start_cheat_caller_address(test_address(), OWNER()); @@ -125,14 +125,7 @@ fn test_transfer_ownership_to_zero() { } #[test] -#[should_panic(expected: ('Caller is the zero address',))] -fn test_transfer_ownership_from_zero() { - let mut state = setup(); - state.transfer_ownership(OTHER()); -} - -#[test] -#[should_panic(expected: ('Caller is not the owner',))] +#[should_panic(expected: 'Caller is not the owner')] fn test_transfer_ownership_from_nonowner() { let mut state = setup(); start_cheat_caller_address(test_address(), OTHER()); @@ -152,7 +145,7 @@ fn test_transferOwnership() { } #[test] -#[should_panic(expected: ('New owner is the zero address',))] +#[should_panic(expected: 'New owner is the zero address')] fn test_transferOwnership_to_zero() { let mut state = setup(); start_cheat_caller_address(test_address(), OWNER()); @@ -160,14 +153,7 @@ fn test_transferOwnership_to_zero() { } #[test] -#[should_panic(expected: ('Caller is the zero address',))] -fn test_transferOwnership_from_zero() { - let mut state = setup(); - state.transferOwnership(OTHER()); -} - -#[test] -#[should_panic(expected: ('Caller is not the owner',))] +#[should_panic(expected: 'Caller is not the owner')] fn test_transferOwnership_from_nonowner() { let mut state = setup(); start_cheat_caller_address(test_address(), OTHER()); @@ -191,14 +177,7 @@ fn test_renounce_ownership() { } #[test] -#[should_panic(expected: ('Caller is the zero address',))] -fn test_renounce_ownership_from_zero_address() { - let mut state = setup(); - state.renounce_ownership(); -} - -#[test] -#[should_panic(expected: ('Caller is not the owner',))] +#[should_panic(expected: 'Caller is not the owner')] fn test_renounce_ownership_from_nonowner() { let mut state = setup(); start_cheat_caller_address(test_address(), OTHER()); @@ -218,14 +197,7 @@ fn test_renounceOwnership() { } #[test] -#[should_panic(expected: ('Caller is the zero address',))] -fn test_renounceOwnership_from_zero_address() { - let mut state = setup(); - state.renounceOwnership(); -} - -#[test] -#[should_panic(expected: ('Caller is not the owner',))] +#[should_panic(expected: 'Caller is not the owner')] fn test_renounceOwnership_from_nonowner() { let mut state = setup(); start_cheat_caller_address(test_address(), OTHER()); diff --git a/packages/access/src/tests/test_ownable_twostep.cairo b/packages/access/src/tests/test_ownable_twostep.cairo index ec6d6242b..b8ef090cd 100644 --- a/packages/access/src/tests/test_ownable_twostep.cairo +++ b/packages/access/src/tests/test_ownable_twostep.cairo @@ -97,14 +97,7 @@ fn test_transfer_ownership_to_zero() { } #[test] -#[should_panic(expected: ('Caller is the zero address',))] -fn test_transfer_ownership_from_zero() { - let mut state = setup(); - state.transfer_ownership(OTHER()); -} - -#[test] -#[should_panic(expected: ('Caller is not the owner',))] +#[should_panic(expected: 'Caller is not the owner')] fn test_transfer_ownership_from_nonowner() { let mut state = setup(); start_cheat_caller_address(test_address(), OTHER()); @@ -145,14 +138,7 @@ fn test_transferOwnership_to_zero() { } #[test] -#[should_panic(expected: ('Caller is the zero address',))] -fn test_transferOwnership_from_zero() { - let mut state = setup(); - state.transferOwnership(OTHER()); -} - -#[test] -#[should_panic(expected: ('Caller is not the owner',))] +#[should_panic(expected: 'Caller is not the owner')] fn test_transferOwnership_from_nonowner() { let mut state = setup(); start_cheat_caller_address(test_address(), OTHER()); @@ -179,7 +165,7 @@ fn test_accept_ownership() { } #[test] -#[should_panic(expected: ('Caller is not the pending owner',))] +#[should_panic(expected: 'Caller is not the pending owner')] fn test_accept_ownership_from_nonpending() { let mut state = setup(); state.Ownable_pending_owner.write(NEW_OWNER()); @@ -203,7 +189,7 @@ fn test_acceptOwnership() { } #[test] -#[should_panic(expected: ('Caller is not the pending owner',))] +#[should_panic(expected: 'Caller is not the pending owner')] fn test_acceptOwnership_from_nonpending() { let mut state = setup(); state.Ownable_pending_owner.write(NEW_OWNER()); @@ -245,14 +231,7 @@ fn test_renounce_ownership_resets_pending_owner() { } #[test] -#[should_panic(expected: ('Caller is the zero address',))] -fn test_renounce_ownership_from_zero_address() { - let mut state = setup(); - state.renounce_ownership(); -} - -#[test] -#[should_panic(expected: ('Caller is not the owner',))] +#[should_panic(expected: 'Caller is not the owner')] fn test_renounce_ownership_from_nonowner() { let mut state = setup(); start_cheat_caller_address(test_address(), OTHER()); @@ -273,14 +252,7 @@ fn test_renounceOwnership() { } #[test] -#[should_panic(expected: ('Caller is the zero address',))] -fn test_renounceOwnership_from_zero_address() { - let mut state = setup(); - state.renounceOwnership(); -} - -#[test] -#[should_panic(expected: ('Caller is not the owner',))] +#[should_panic(expected: 'Caller is not the owner')] fn test_renounceOwnership_from_nonowner() { let mut state = setup(); start_cheat_caller_address(test_address(), OTHER()); diff --git a/packages/presets/src/tests/test_erc1155.cairo b/packages/presets/src/tests/test_erc1155.cairo index 7cfb30f97..0e83b0640 100644 --- a/packages/presets/src/tests/test_erc1155.cairo +++ b/packages/presets/src/tests/test_erc1155.cairo @@ -656,14 +656,6 @@ fn test_transfer_ownership_to_zero() { dispatcher.transfer_ownership(ZERO()); } -#[test] -#[should_panic(expected: ('Caller is the zero address',))] -fn test_transfer_ownership_from_zero() { - let (_, dispatcher, _) = setup_dispatcher(); - start_cheat_caller_address(dispatcher.contract_address, ZERO()); - dispatcher.transfer_ownership(OTHER()); -} - #[test] #[should_panic(expected: ('Caller is not the owner',))] fn test_transfer_ownership_from_nonowner() { @@ -690,14 +682,6 @@ fn test_transferOwnership_to_zero() { dispatcher.transferOwnership(ZERO()); } -#[test] -#[should_panic(expected: ('Caller is the zero address',))] -fn test_transferOwnership_from_zero() { - let (_, dispatcher, _) = setup_dispatcher(); - start_cheat_caller_address(dispatcher.contract_address, ZERO()); - dispatcher.transferOwnership(OTHER()); -} - #[test] #[should_panic(expected: ('Caller is not the owner',))] fn test_transferOwnership_from_nonowner() { @@ -720,14 +704,6 @@ fn test_renounce_ownership() { assert!(dispatcher.owner().is_zero()); } -#[test] -#[should_panic(expected: ('Caller is the zero address',))] -fn test_renounce_ownership_from_zero_address() { - let (_, dispatcher, _) = setup_dispatcher(); - start_cheat_caller_address(dispatcher.contract_address, ZERO()); - dispatcher.renounce_ownership(); -} - #[test] #[should_panic(expected: ('Caller is not the owner',))] fn test_renounce_ownership_from_nonowner() { @@ -746,14 +722,6 @@ fn test_renounceOwnership() { assert!(dispatcher.owner().is_zero()); } -#[test] -#[should_panic(expected: ('Caller is the zero address',))] -fn test_renounceOwnership_from_zero_address() { - let (_, dispatcher, _) = setup_dispatcher(); - start_cheat_caller_address(dispatcher.contract_address, ZERO()); - dispatcher.renounceOwnership(); -} - #[test] #[should_panic(expected: ('Caller is not the owner',))] fn test_renounceOwnership_from_nonowner() { diff --git a/packages/presets/src/tests/test_erc20.cairo b/packages/presets/src/tests/test_erc20.cairo index cd41e83b1..be41473d9 100644 --- a/packages/presets/src/tests/test_erc20.cairo +++ b/packages/presets/src/tests/test_erc20.cairo @@ -328,14 +328,6 @@ fn test_transfer_ownership_to_zero() { dispatcher.transfer_ownership(ZERO()); } -#[test] -#[should_panic(expected: ('Caller is the zero address',))] -fn test_transfer_ownership_from_zero() { - let (_, mut dispatcher) = setup_dispatcher(); - start_cheat_caller_address(dispatcher.contract_address, ZERO()); - dispatcher.transfer_ownership(OTHER()); -} - #[test] #[should_panic(expected: ('Caller is not the owner',))] fn test_transfer_ownership_from_nonowner() { @@ -362,14 +354,6 @@ fn test_transferOwnership_to_zero() { dispatcher.transferOwnership(ZERO()); } -#[test] -#[should_panic(expected: ('Caller is the zero address',))] -fn test_transferOwnership_from_zero() { - let (_, mut dispatcher) = setup_dispatcher(); - start_cheat_caller_address(dispatcher.contract_address, ZERO()); - dispatcher.transferOwnership(OTHER()); -} - #[test] #[should_panic(expected: ('Caller is not the owner',))] fn test_transferOwnership_from_nonowner() { @@ -392,14 +376,6 @@ fn test_renounce_ownership() { assert!(dispatcher.owner().is_zero()); } -#[test] -#[should_panic(expected: ('Caller is the zero address',))] -fn test_renounce_ownership_from_zero_address() { - let (_, mut dispatcher) = setup_dispatcher(); - start_cheat_caller_address(dispatcher.contract_address, ZERO()); - dispatcher.renounce_ownership(); -} - #[test] #[should_panic(expected: ('Caller is not the owner',))] fn test_renounce_ownership_from_nonowner() { @@ -418,14 +394,6 @@ fn test_renounceOwnership() { assert!(dispatcher.owner().is_zero()); } -#[test] -#[should_panic(expected: ('Caller is the zero address',))] -fn test_renounceOwnership_from_zero_address() { - let (_, mut dispatcher) = setup_dispatcher(); - start_cheat_caller_address(dispatcher.contract_address, ZERO()); - dispatcher.renounceOwnership(); -} - #[test] #[should_panic(expected: ('Caller is not the owner',))] fn test_renounceOwnership_from_nonowner() { diff --git a/packages/presets/src/tests/test_erc721.cairo b/packages/presets/src/tests/test_erc721.cairo index 63a1844f9..c6b02aa65 100644 --- a/packages/presets/src/tests/test_erc721.cairo +++ b/packages/presets/src/tests/test_erc721.cairo @@ -756,14 +756,6 @@ fn test_transfer_ownership_to_zero() { dispatcher.transfer_ownership(ZERO()); } -#[test] -#[should_panic(expected: ('Caller is the zero address',))] -fn test_transfer_ownership_from_zero() { - let (_, mut dispatcher) = setup_dispatcher(); - start_cheat_caller_address(dispatcher.contract_address, ZERO()); - dispatcher.transfer_ownership(OTHER()); -} - #[test] #[should_panic(expected: ('Caller is not the owner',))] fn test_transfer_ownership_from_nonowner() { @@ -790,14 +782,6 @@ fn test_transferOwnership_to_zero() { dispatcher.transferOwnership(ZERO()); } -#[test] -#[should_panic(expected: ('Caller is the zero address',))] -fn test_transferOwnership_from_zero() { - let (_, mut dispatcher) = setup_dispatcher(); - start_cheat_caller_address(dispatcher.contract_address, ZERO()); - dispatcher.transferOwnership(OTHER()); -} - #[test] #[should_panic(expected: ('Caller is not the owner',))] fn test_transferOwnership_from_nonowner() { @@ -820,14 +804,6 @@ fn test_renounce_ownership() { assert!(dispatcher.owner().is_zero()); } -#[test] -#[should_panic(expected: ('Caller is the zero address',))] -fn test_renounce_ownership_from_zero_address() { - let (_, mut dispatcher) = setup_dispatcher(); - start_cheat_caller_address(dispatcher.contract_address, ZERO()); - dispatcher.renounce_ownership(); -} - #[test] #[should_panic(expected: ('Caller is not the owner',))] fn test_renounce_ownership_from_nonowner() { @@ -846,14 +822,6 @@ fn test_renounceOwnership() { assert!(dispatcher.owner().is_zero()); } -#[test] -#[should_panic(expected: ('Caller is the zero address',))] -fn test_renounceOwnership_from_zero_address() { - let (_, mut dispatcher) = setup_dispatcher(); - start_cheat_caller_address(dispatcher.contract_address, ZERO()); - dispatcher.renounceOwnership(); -} - #[test] #[should_panic(expected: ('Caller is not the owner',))] fn test_renounceOwnership_from_nonowner() { diff --git a/packages/presets/src/tests/test_vesting.cairo b/packages/presets/src/tests/test_vesting.cairo index 0cbc9763a..ccaa0758f 100644 --- a/packages/presets/src/tests/test_vesting.cairo +++ b/packages/presets/src/tests/test_vesting.cairo @@ -246,14 +246,6 @@ fn test_transfer_ownership_to_zero() { vesting.transfer_ownership(ZERO()); } -#[test] -#[should_panic(expected: 'Caller is the zero address')] -fn test_transfer_ownership_from_zero() { - let (vesting, _) = setup(TEST_DATA()); - start_cheat_caller_address(vesting.contract_address, ZERO()); - vesting.transfer_ownership(OTHER()); -} - #[test] #[should_panic(expected: 'Caller is not the owner')] fn test_transfer_ownership_from_nonowner() { @@ -281,14 +273,6 @@ fn test_transferOwnership_to_zero() { vesting.transferOwnership(ZERO()); } -#[test] -#[should_panic(expected: 'Caller is the zero address')] -fn test_transferOwnership_from_zero() { - let (vesting, _) = setup(TEST_DATA()); - start_cheat_caller_address(vesting.contract_address, ZERO()); - vesting.transferOwnership(OTHER()); -} - #[test] #[should_panic(expected: 'Caller is not the owner')] fn test_transferOwnership_from_nonowner() { @@ -312,14 +296,6 @@ fn test_renounce_ownership() { assert!(vesting.owner().is_zero()); } -#[test] -#[should_panic(expected: 'Caller is the zero address')] -fn test_renounce_ownership_from_zero_address() { - let (vesting, _) = setup(TEST_DATA()); - start_cheat_caller_address(vesting.contract_address, ZERO()); - vesting.renounce_ownership(); -} - #[test] #[should_panic(expected: 'Caller is not the owner')] fn test_renounce_ownership_from_nonowner() { @@ -339,14 +315,6 @@ fn test_renounceOwnership() { assert!(vesting.owner().is_zero()); } -#[test] -#[should_panic(expected: 'Caller is the zero address')] -fn test_renounceOwnership_from_zero_address() { - let (vesting, _) = setup(TEST_DATA()); - start_cheat_caller_address(vesting.contract_address, ZERO()); - vesting.renounceOwnership(); -} - #[test] #[should_panic(expected: 'Caller is not the owner')] fn test_renounceOwnership_from_nonowner() { diff --git a/packages/security/src/initializable.cairo b/packages/security/src/initializable.cairo index 9b09e91d8..4c7b348ba 100644 --- a/packages/security/src/initializable.cairo +++ b/packages/security/src/initializable.cairo @@ -24,7 +24,7 @@ pub mod InitializableComponent { impl Initializable< TContractState, +HasComponent > of IInitializable> { - /// Returns true if the using contract executed `initialize`. + /// Returns whether the contract has been initialized. fn is_initialized(self: @ComponentState) -> bool { self.Initializable_initialized.read() } diff --git a/packages/security/src/tests/test_initializable.cairo b/packages/security/src/tests/test_initializable.cairo index 0b7ac8fc7..6fbfada0a 100644 --- a/packages/security/src/tests/test_initializable.cairo +++ b/packages/security/src/tests/test_initializable.cairo @@ -17,7 +17,7 @@ fn test_initialize() { } #[test] -#[should_panic(expected: ('Initializable: is initialized',))] +#[should_panic(expected: 'Initializable: is initialized')] fn test_initialize_when_initialized() { let mut state = COMPONENT_STATE(); state.initialize(); diff --git a/packages/security/src/tests/test_pausable.cairo b/packages/security/src/tests/test_pausable.cairo index 486819c0e..6ccbc921a 100644 --- a/packages/security/src/tests/test_pausable.cairo +++ b/packages/security/src/tests/test_pausable.cairo @@ -42,7 +42,7 @@ fn test_assert_paused_when_paused() { } #[test] -#[should_panic(expected: ('Pausable: not paused',))] +#[should_panic(expected: 'Pausable: not paused')] fn test_assert_paused_when_not_paused() { let state = COMPONENT_STATE(); state.assert_paused(); @@ -53,7 +53,7 @@ fn test_assert_paused_when_not_paused() { // #[test] -#[should_panic(expected: ('Pausable: paused',))] +#[should_panic(expected: 'Pausable: paused')] fn test_assert_not_paused_when_paused() { let mut state = COMPONENT_STATE(); state.pause(); @@ -84,7 +84,7 @@ fn test_pause_when_unpaused() { } #[test] -#[should_panic(expected: ('Pausable: paused',))] +#[should_panic(expected: 'Pausable: paused')] fn test_pause_when_paused() { let mut state = COMPONENT_STATE(); state.pause(); @@ -111,7 +111,7 @@ fn test_unpause_when_paused() { } #[test] -#[should_panic(expected: ('Pausable: not paused',))] +#[should_panic(expected: 'Pausable: not paused')] fn test_unpause_when_unpaused() { let mut state = COMPONENT_STATE(); assert!(!state.is_paused()); diff --git a/packages/security/src/tests/test_reentrancyguard.cairo b/packages/security/src/tests/test_reentrancyguard.cairo index 8647c9e9e..3263e77a4 100644 --- a/packages/security/src/tests/test_reentrancyguard.cairo +++ b/packages/security/src/tests/test_reentrancyguard.cairo @@ -36,7 +36,7 @@ fn test_reentrancy_guard_start() { } #[test] -#[should_panic(expected: ('ReentrancyGuard: reentrant call',))] +#[should_panic(expected: 'ReentrancyGuard: reentrant call')] fn test_reentrancy_guard_start_when_started() { let mut state = COMPONENT_STATE(); @@ -64,7 +64,7 @@ fn test_reentrancy_guard_end() { // #[test] -#[should_panic(expected: ('ReentrancyGuard: reentrant call',))] +#[should_panic(expected: 'ReentrancyGuard: reentrant call')] fn test_remote_callback() { let contract = deploy_mock(); @@ -76,14 +76,14 @@ fn test_remote_callback() { } #[test] -#[should_panic(expected: ('ReentrancyGuard: reentrant call',))] +#[should_panic(expected: 'ReentrancyGuard: reentrant call')] fn test_local_recursion() { let contract = deploy_mock(); contract.count_local_recursive(10); } #[test] -#[should_panic(expected: ('ReentrancyGuard: reentrant call',))] +#[should_panic(expected: 'ReentrancyGuard: reentrant call')] fn test_external_recursion() { let contract = deploy_mock(); contract.count_external_recursive(10);