11// SPDX-License-Identifier: UNLICENSED
2- pragma solidity ^ 0.8.0 ;
2+ pragma solidity ^ 0.8.20 ;
33
44import "forge-std/Test.sol " ;
5-
6- import "./test/utils/Caller.sol " ;
7-
8- import {OnlyAuthorized} from "./OnlyAuthorized.sol " ;
5+ import "./utils/Caller.sol " ;
6+ import {OnlyAuthorized} from "../src/OnlyAuthorized.sol " ;
97
108contract OnlyAuthorizedTest is Test {
119 OnlyAuthorized private oa;
@@ -14,22 +12,30 @@ contract OnlyAuthorizedTest is Test {
1412 oa = new OnlyAuthorized ();
1513 }
1614
17- function testCanChangeOwner () public {
18- oa.changeOwner (address (0x1 ));
19- assertEq (oa.owner (), address (0x1 ));
15+ function testOwnerCanChangeOwner () public {
16+ address newOwner = address (0x1 );
17+
18+ oa.changeOwner (newOwner);
19+
20+ assertEq (oa.owner (), newOwner);
2021 }
2122
22- function testOtherUsersCannotChangeOwner () public {
23+ function testNonOwnerCannotChangeOwner () public {
2324 Caller user = new Caller ();
2425
2526 (bool ok , ) = user.externalCall (
2627 address (oa),
2728 abi.encodeWithSelector (
28- oa .changeOwner.selector ,
29- ( address (0xdeadbeef ) )
29+ OnlyAuthorized .changeOwner.selector ,
30+ address (0xdeadbeef )
3031 )
3132 );
3233
33- assertTrue (! ok, "Only the owner can change owner " );
34+ assertFalse (ok);
35+ }
36+
37+ function testRevertOnZeroAddress () public {
38+ vm.expectRevert (OnlyAuthorized.ZeroAddress.selector );
39+ oa.changeOwner (address (0 ));
3440 }
3541}
0 commit comments