-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add Ownable 'transferOwnership' fuzz tests
- Loading branch information
1 parent
58f39c9
commit 93f727e
Showing
4 changed files
with
56 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.26; | ||
|
||
import { Ownable_Shared_Test } from "../shared/Ownable.t.sol"; | ||
import { Errors } from "../../utils/Errors.sol"; | ||
import { Events } from "../../utils/Events.sol"; | ||
|
||
contract TransferOwnership_Unit_Fuzz_Test is Ownable_Shared_Test { | ||
function setUp() public virtual override { | ||
Ownable_Shared_Test.setUp(); | ||
} | ||
|
||
function testFuzz_RevertWhen_CallerNotCurrentOwner(address newOwner) external whenNewOwnerNotZeroAddress { | ||
// Make sure the new owner is not the current one or the zero address | ||
vm.assume(newOwner != users.admin && newOwner != address(0)); | ||
|
||
// Make Bob the caller for this test suite who is not the current owner | ||
vm.startPrank({ msgSender: newOwner }); | ||
|
||
// Expect the next call to revert with the {Unauthorized} error | ||
vm.expectRevert(Errors.Unauthorized.selector); | ||
|
||
// Run the test | ||
ownableMock.transferOwnership(newOwner); | ||
} | ||
|
||
function testFuzz_TransferOwnership(address newOwner) external whenCallerCurrentOwner whenNewOwnerNotZeroAddress { | ||
// Make sure the new owner is not the zero address | ||
vm.assume(newOwner != address(0)); | ||
|
||
// Expect the {OwnershipTransferred} event to be emitted | ||
vm.expectEmit(); | ||
emit Events.OwnershipTransferred({ oldOwner: users.admin, newOwner: newOwner }); | ||
|
||
// Run the test | ||
ownableMock.transferOwnership({ newOwner: newOwner }); | ||
|
||
// Assert the actual and expected owner | ||
address actualOwner = ownableMock.owner(); | ||
assertEq(actualOwner, newOwner); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters