Skip to content

Commit b209c09

Browse files
committed
feat: enhance pausable functionality with custom error handling and bridge role assignment
1 parent 960f42c commit b209c09

File tree

1 file changed

+23
-14
lines changed

1 file changed

+23
-14
lines changed

test/RLCOFT.t.sol

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ contract RLCOFTTest is Test {
1010
RLCOFT public rlcOft;
1111

1212
address public owner;
13+
address public bridge;
1314
address public pauser;
1415
address public user1;
1516
address public user2;
@@ -19,11 +20,16 @@ contract RLCOFTTest is Test {
1920
event Unpaused(address account);
2021
event Transfer(address indexed from, address indexed to, uint256 value);
2122

23+
// Custom errors from OpenZeppelin
24+
error EnforcedPause();
25+
error AccessControlUnauthorizedAccount(address account, bytes32 neededRole);
26+
2227
function setUp() public {
2328
vm.createSelectFork(vm.envString("ARBITRUM_SEPOLIA_RPC_URL"));
2429

2530
// Create addresses using makeAddr
2631
owner = makeAddr("owner");
32+
bridge = makeAddr("bridge");
2733
pauser = makeAddr("pauser");
2834
user1 = makeAddr("user1");
2935
user2 = makeAddr("user2");
@@ -40,11 +46,15 @@ contract RLCOFTTest is Test {
4046
rlcOft = RLCOFT(new RLCOFTDeploy().run());
4147

4248

43-
vm.startPrank(owner);
44-
rlcOft.grantRole(rlcOft.BRIDGE_ROLE(), owner);
49+
vm.startPrank(owner);// We can't use vm.prank here as the first call will be rlcOft.BRIDGE_ROLE() before doing the grantRole
50+
rlcOft.grantRole(rlcOft.BRIDGE_ROLE(), bridge);
51+
vm.stopPrank();
52+
53+
vm.startPrank(bridge);
4554
rlcOft.mint(user1, 1000 * 10**9);
4655
rlcOft.mint(user2, 500 * 10**9);
4756
vm.stopPrank();
57+
4858
}
4959

5060
// ============ Deployment Tests ============
@@ -67,7 +77,7 @@ contract RLCOFTTest is Test {
6777
}
6878

6979
function testPauseUnauthorized() public {
70-
vm.expectRevert();
80+
vm.expectRevert(abi.encodeWithSelector(AccessControlUnauthorizedAccount.selector, user1, rlcOft.PAUSER_ROLE()));
7181
vm.prank(user1);
7282
rlcOft.pause();
7383
}
@@ -92,7 +102,7 @@ contract RLCOFTTest is Test {
92102
vm.prank(pauser);
93103
rlcOft.pause();
94104

95-
vm.expectRevert();
105+
vm.expectRevert(abi.encodeWithSelector(AccessControlUnauthorizedAccount.selector, user1, rlcOft.PAUSER_ROLE()));
96106
vm.prank(user1);
97107
rlcOft.unpause();
98108
}
@@ -102,8 +112,7 @@ contract RLCOFTTest is Test {
102112
vm.prank(pauser);
103113
rlcOft.pause();
104114

105-
// Try to transfer - should fail
106-
vm.expectRevert("Pausable: paused");
115+
vm.expectRevert(EnforcedPause.selector);
107116
vm.prank(user1);
108117
rlcOft.transfer(user2, 100 * 10**9);
109118
}
@@ -117,8 +126,8 @@ contract RLCOFTTest is Test {
117126
vm.prank(pauser);
118127
rlcOft.pause();
119128

120-
// Try to transferFrom - should fail
121-
vm.expectRevert("Pausable: paused");
129+
// Try to transferFrom - should fail with EnforcedPause() custom error
130+
vm.expectRevert(EnforcedPause.selector);
122131
vm.prank(user2);
123132
rlcOft.transferFrom(user1, user2, 100 * 10**9);
124133
}
@@ -128,9 +137,9 @@ contract RLCOFTTest is Test {
128137
vm.prank(pauser);
129138
rlcOft.pause();
130139

131-
// Try to mint - should fail
132-
vm.expectRevert("Pausable: paused");
133-
vm.prank(owner);
140+
// Try to mint - should fail with EnforcedPause() custom error
141+
vm.expectRevert(EnforcedPause.selector);
142+
vm.prank(bridge);
134143
rlcOft.mint(user1, 100 * 10**9);
135144
}
136145

@@ -139,9 +148,9 @@ contract RLCOFTTest is Test {
139148
vm.prank(pauser);
140149
rlcOft.pause();
141150

142-
// Try to burn - should fail
143-
vm.expectRevert("Pausable: paused");
144-
vm.prank(user1);
151+
// Try to burn - should fail with EnforcedPause() custom error
152+
vm.expectRevert(EnforcedPause.selector);
153+
vm.prank(bridge);
145154
rlcOft.burn(100 * 10**9);
146155
}
147156

0 commit comments

Comments
 (0)