-
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 unit 'transferOwnership' tests
- Loading branch information
1 parent
5bb6c02
commit f11b6f5
Showing
5 changed files
with
81 additions
and
1 deletion.
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
55 changes: 55 additions & 0 deletions
55
test/unit/concrete/container/transfer-ownership/transferOwnership.t.sol
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,55 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.26; | ||
|
||
import { Container_Unit_Concrete_Test } from "../Container.t.sol"; | ||
import { MockModule } from "../../../../mocks/MockModule.sol"; | ||
import { Events } from "../../../../utils/Events.sol"; | ||
import { Errors } from "../../../../utils/Errors.sol"; | ||
|
||
contract TransferOwnership_Unit_Concrete_Test is Container_Unit_Concrete_Test { | ||
function setUp() public virtual override { | ||
Container_Unit_Concrete_Test.setUp(); | ||
} | ||
|
||
function test_RevertWhen_CallerNotOwner() external { | ||
// Make Bob the caller for this test suite who is not the owner of the container | ||
vm.startPrank({ msgSender: users.bob }); | ||
|
||
// Expect the next call to revert with the {Unauthorized} error | ||
vm.expectRevert(Errors.Unauthorized.selector); | ||
|
||
// Run the test | ||
container.transferOwnership({ newOwner: users.eve }); | ||
} | ||
|
||
modifier whenCallerOwner() { | ||
// Make Eve the caller for the next test suite as she's the owner of the container | ||
vm.startPrank({ msgSender: users.eve }); | ||
_; | ||
} | ||
|
||
function test_RevertWhen_InvalidOwnerZeroAddress() external whenCallerOwner { | ||
// Expect the next call to revert with the {InvalidOwnerZeroAddress} | ||
vm.expectRevert(Errors.InvalidOwnerZeroAddress.selector); | ||
|
||
// Run the test | ||
container.transferOwnership({ newOwner: address(0) }); | ||
} | ||
|
||
modifier whenNonZeroOwnerAddress() { | ||
_; | ||
} | ||
|
||
function test_TransferOwnership() external whenCallerOwner whenNonZeroOwnerAddress { | ||
// Expect the {OwnershipTransferred} to be emitted | ||
vm.expectEmit(); | ||
emit Events.OwnershipTransferred({ oldOwner: users.eve, newOwner: users.bob }); | ||
|
||
// Run the test | ||
container.transferOwnership({ newOwner: users.bob }); | ||
|
||
// Assert the actual and expected owner | ||
address actualOwner = container.owner(); | ||
assertEq(actualOwner, users.bob); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
test/unit/concrete/container/transfer-ownership/transferOwnership.tree
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,9 @@ | ||
transferOwnership.t.sol | ||
├── when the caller IS NOT the container owner | ||
│ └── it should revert with the {Unauthorized} error | ||
└── when the caller IS the container owner | ||
├── when the new owner address IS the zero address | ||
│ └── it should revert with the {InvalidOwnerZeroAddress} error | ||
└── when the new owner address IS NOT the zero address | ||
├── it should update the owner | ||
└── it should emit a {OwnershipTransferred} event |
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