File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -37,6 +37,8 @@ abstract contract Ownable2Step is Ownable {
37
37
/**
38
38
* @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.
39
39
* Can only be called by the current owner.
40
+ *
41
+ * Setting `newOwner` to the zero address is allowed; this can be used to cancel an initiated ownership transfer.
40
42
*/
41
43
function transferOwnership (address newOwner ) public virtual override onlyOwner {
42
44
_pendingOwner = newOwner;
Original file line number Diff line number Diff line change @@ -81,5 +81,22 @@ describe('Ownable2Step', function () {
81
81
82
82
expect ( await this . ownable2Step . owner ( ) ) . to . equal ( this . accountA ) ;
83
83
} ) ;
84
+
85
+ it ( 'allows the owner to cancel an initiated ownership transfer by setting newOwner to zero address' , async function ( ) {
86
+ // initiate ownership transfer to accountA
87
+ await this . ownable2Step . connect ( this . owner ) . transferOwnership ( this . accountA ) ;
88
+ expect ( await this . ownable2Step . pendingOwner ( ) ) . to . equal ( this . accountA ) ;
89
+
90
+ // cancel the ownership transfer by setting newOwner to zero address
91
+ await expect ( this . ownable2Step . connect ( this . owner ) . transferOwnership ( ethers . ZeroAddress ) )
92
+ . to . emit ( this . ownable2Step , 'OwnershipTransferStarted' )
93
+ . withArgs ( this . owner , ethers . ZeroAddress ) ;
94
+ expect ( await this . ownable2Step . pendingOwner ( ) ) . to . equal ( ethers . ZeroAddress ) ;
95
+
96
+ // verify that accountA cannot accept ownership anymore
97
+ await expect ( this . ownable2Step . connect ( this . accountA ) . acceptOwnership ( ) )
98
+ . to . be . revertedWithCustomError ( this . ownable2Step , 'OwnableUnauthorizedAccount' )
99
+ . withArgs ( this . accountA ) ;
100
+ } ) ;
84
101
} ) ;
85
102
} ) ;
You can’t perform that action at this time.
0 commit comments