Skip to content

Commit

Permalink
check owner is not zero on initializer and improve comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ggonzalez94 committed Nov 18, 2024
1 parent 014a180 commit e423bef
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/access/src/ownable/ownable.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ pub mod OwnableComponent {

/// Starts the two-step ownership transfer process by setting the pending owner.
///
/// Setting `newOwner` to the zero address is allowed; this can be used to cancel an
/// initiated ownership transfer.
/// Requirements:
///
/// - The caller is the contract owner.
Expand Down Expand Up @@ -278,8 +280,13 @@ pub mod OwnableComponent {
> of InternalTrait<TContractState> {
/// 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<TContractState>, owner: ContractAddress) {
assert(!owner.is_zero(), Errors::ZERO_ADDRESS_OWNER);
self._transfer_ownership(owner);
}

Expand Down
7 changes: 7 additions & 0 deletions packages/access/src/tests/test_ownable.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand Down

0 comments on commit e423bef

Please sign in to comment.