@layerzerolabs/utils-upgradeable-evm-contracts 1.2.8 → 1.2.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-lint.log +232 -228
- package/.turbo/turbo-test.log +745 -768
- package/package.json +4 -4
- package/test/AccessControl2StepUpgradeable.t.sol +115 -111
- package/test/AllowlistBaseUpgradeable.t.sol +10 -15
- package/test/AllowlistRBACUpgradeable.t.sol +20 -16
- package/test/FeeConfigBaseUpgradeable.t.sol +68 -70
- package/test/FeeConfigRBACUpgradeable.t.sol +13 -10
- package/test/FeeHandlerBaseUpgradeable.t.sol +22 -28
- package/test/FeeHandlerRBACUpgradeable.t.sol +12 -9
- package/test/PauseBaseUpgradeable.t.sol +72 -85
- package/test/PauseByIDBaseUpgradeable.t.sol +84 -94
- package/test/PauseByIDRBACUpgradeable.t.sol +101 -115
- package/test/PauseRBACUpgradeable.t.sol +74 -106
- package/test/RateLimiterBaseUpgradeable.t.sol +28 -24
- package/test/RateLimiterRBACUpgradeable.t.sol +22 -12
- package/test/RateLimiterRBACUpgradeableInvariant.t.sol +10 -10
|
@@ -7,9 +7,9 @@ import { IAccessControl } from "@openzeppelin/contracts/access/IAccessControl.so
|
|
|
7
7
|
import { ERC1967Utils } from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.sol";
|
|
8
8
|
import { TransparentUpgradeableProxy } from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
|
|
9
9
|
import { PauseByIDRBACUpgradeable } from "./../contracts/pause-by-id/PauseByIDRBACUpgradeable.sol";
|
|
10
|
-
import { PauseByIDBaseUpgradeableTest,
|
|
10
|
+
import { PauseByIDBaseUpgradeableTest, PauseByIDBaseUpgradeableHarness } from "./PauseByIDBaseUpgradeable.t.sol";
|
|
11
11
|
|
|
12
|
-
contract
|
|
12
|
+
contract PauseByIDRBACUpgradeableHarness is PauseByIDRBACUpgradeable {
|
|
13
13
|
uint256 public callCount;
|
|
14
14
|
|
|
15
15
|
constructor() {
|
|
@@ -38,9 +38,10 @@ contract PauseByIDRBACUpgradeableMock is PauseByIDRBACUpgradeable {
|
|
|
38
38
|
contract PauseByIDRBACUpgradeableTest is PauseByIDBaseUpgradeableTest {
|
|
39
39
|
address alice = makeAddr("alice");
|
|
40
40
|
address proxyAdmin;
|
|
41
|
+
PauseByIDRBACUpgradeableHarness pauseRbac;
|
|
41
42
|
|
|
42
|
-
function
|
|
43
|
-
|
|
43
|
+
function _deployPause() internal virtual override returns (PauseByIDBaseUpgradeableHarness) {
|
|
44
|
+
PauseByIDRBACUpgradeableHarness impl = new PauseByIDRBACUpgradeableHarness();
|
|
44
45
|
|
|
45
46
|
uint256 currentNonce = vm.getNonce(address(this));
|
|
46
47
|
proxyAdmin = vm.computeCreateAddress(vm.computeCreateAddress(address(this), currentNonce), 1);
|
|
@@ -48,92 +49,88 @@ contract PauseByIDRBACUpgradeableTest is PauseByIDBaseUpgradeableTest {
|
|
|
48
49
|
TransparentUpgradeableProxy proxy = new TransparentUpgradeableProxy(
|
|
49
50
|
address(impl),
|
|
50
51
|
address(this),
|
|
51
|
-
abi.encodeWithSelector(
|
|
52
|
+
abi.encodeWithSelector(PauseByIDRBACUpgradeableHarness.initialize.selector, address(this))
|
|
52
53
|
);
|
|
53
54
|
|
|
54
55
|
bytes32 adminSlot = vm.load(address(proxy), ERC1967Utils.ADMIN_SLOT);
|
|
55
56
|
proxyAdmin = address(uint160(uint256(adminSlot)));
|
|
56
57
|
|
|
57
|
-
|
|
58
|
+
pauseRbac = PauseByIDRBACUpgradeableHarness(address(proxy));
|
|
59
|
+
return PauseByIDBaseUpgradeableHarness(address(proxy));
|
|
58
60
|
}
|
|
59
61
|
|
|
60
|
-
|
|
61
|
-
pauseHelper = _createPause();
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/// @dev `PauseByIDRBACUpgradeableMock.initialize(address)` has a different signature.
|
|
62
|
+
/// @dev `PauseByIDRBACUpgradeableHarness.initialize(address)` has a different signature.
|
|
65
63
|
function test_initialize_Revert_AlreadyInitialized() public virtual override {
|
|
66
64
|
vm.expectRevert(Initializable.InvalidInitialization.selector);
|
|
67
|
-
|
|
65
|
+
pauseRbac.initialize(alice);
|
|
68
66
|
}
|
|
69
67
|
|
|
70
68
|
function test_setDefaultPaused_Success() public {
|
|
71
|
-
|
|
72
|
-
assertTrue(
|
|
69
|
+
pause.setDefaultPaused(true);
|
|
70
|
+
assertTrue(pause.defaultPaused());
|
|
73
71
|
}
|
|
74
72
|
|
|
75
73
|
function test_setDefaultPaused_Revert_Unauthorized() public {
|
|
76
|
-
bytes32 pauserRole =
|
|
74
|
+
bytes32 pauserRole = pauseRbac.PAUSER_ROLE();
|
|
77
75
|
vm.expectRevert(
|
|
78
76
|
abi.encodeWithSelector(IAccessControl.AccessControlUnauthorizedAccount.selector, alice, pauserRole)
|
|
79
77
|
);
|
|
80
78
|
vm.prank(alice);
|
|
81
|
-
|
|
79
|
+
pause.setDefaultPaused(true);
|
|
82
80
|
}
|
|
83
81
|
|
|
84
82
|
function test_setPaused_Success() public {
|
|
85
83
|
IPauseByID.SetPausedParam[] memory params = new IPauseByID.SetPausedParam[](1);
|
|
86
84
|
params[0] = IPauseByID.SetPausedParam(1, true, true);
|
|
87
|
-
|
|
88
|
-
assertTrue(
|
|
85
|
+
pause.setPaused(params);
|
|
86
|
+
assertTrue(pause.isPaused(1));
|
|
89
87
|
}
|
|
90
88
|
|
|
91
89
|
function test_setPaused_Revert_Unauthorized() public {
|
|
92
90
|
IPauseByID.SetPausedParam[] memory params = new IPauseByID.SetPausedParam[](1);
|
|
93
91
|
params[0] = IPauseByID.SetPausedParam(1, true, true);
|
|
94
92
|
|
|
95
|
-
bytes32 pauserRole =
|
|
93
|
+
bytes32 pauserRole = pauseRbac.PAUSER_ROLE();
|
|
96
94
|
vm.expectRevert(
|
|
97
95
|
abi.encodeWithSelector(IAccessControl.AccessControlUnauthorizedAccount.selector, alice, pauserRole)
|
|
98
96
|
);
|
|
99
97
|
vm.prank(alice);
|
|
100
|
-
|
|
98
|
+
pause.setPaused(params);
|
|
101
99
|
}
|
|
102
100
|
|
|
103
101
|
function test_setPaused_Success_Batch() public {
|
|
104
|
-
|
|
105
|
-
assertTrue(
|
|
102
|
+
pause.setDefaultPaused(true);
|
|
103
|
+
assertTrue(pause.defaultPaused());
|
|
106
104
|
|
|
107
105
|
IPauseByID.SetPausedParam[] memory params = new IPauseByID.SetPausedParam[](1);
|
|
108
106
|
params[0] = IPauseByID.SetPausedParam(1, false, true);
|
|
109
|
-
|
|
110
|
-
assertFalse(
|
|
107
|
+
pause.setPaused(params);
|
|
108
|
+
assertFalse(pause.isPaused(1));
|
|
111
109
|
|
|
112
110
|
params[0] = IPauseByID.SetPausedParam(2, true, true);
|
|
113
|
-
|
|
114
|
-
assertTrue(
|
|
111
|
+
pause.setPaused(params);
|
|
112
|
+
assertTrue(pause.isPaused(2));
|
|
115
113
|
|
|
116
|
-
|
|
117
|
-
assertFalse(
|
|
114
|
+
pause.setDefaultPaused(false);
|
|
115
|
+
assertFalse(pause.defaultPaused());
|
|
118
116
|
|
|
119
117
|
IPauseByID.SetPausedParam[] memory batchParams = new IPauseByID.SetPausedParam[](10);
|
|
120
118
|
for (uint32 i = 0; i < 10; i++) {
|
|
121
119
|
batchParams[i] = IPauseByID.SetPausedParam(i + 10, (i + 10) % 2 == 0, true);
|
|
122
120
|
}
|
|
123
|
-
|
|
121
|
+
pause.setPaused(batchParams);
|
|
124
122
|
}
|
|
125
123
|
|
|
126
124
|
function test_setPaused_Revert_UnpauserCannotCauseEffectivePause() public {
|
|
127
125
|
// `defaultPaused=true` and `enabled=false`.
|
|
128
|
-
|
|
129
|
-
bytes32
|
|
130
|
-
bytes32 unpauserRole = mock.UNPAUSER_ROLE();
|
|
126
|
+
bytes32 pauserRole = pauseRbac.PAUSER_ROLE();
|
|
127
|
+
bytes32 unpauserRole = pauseRbac.UNPAUSER_ROLE();
|
|
131
128
|
|
|
132
129
|
// Set default to paused.
|
|
133
|
-
|
|
130
|
+
pause.setDefaultPaused(true);
|
|
134
131
|
|
|
135
132
|
// Grant only `UNPAUSER_ROLE` to `alice`.
|
|
136
|
-
|
|
133
|
+
pauseRbac.grantRole(unpauserRole, alice);
|
|
137
134
|
|
|
138
135
|
// `alice` tries to set `enabled=false` with `paused=false` — effective state is paused.
|
|
139
136
|
IPauseByID.SetPausedParam[] memory params = new IPauseByID.SetPausedParam[](1);
|
|
@@ -143,20 +140,19 @@ contract PauseByIDRBACUpgradeableTest is PauseByIDBaseUpgradeableTest {
|
|
|
143
140
|
abi.encodeWithSelector(IAccessControl.AccessControlUnauthorizedAccount.selector, alice, pauserRole)
|
|
144
141
|
);
|
|
145
142
|
vm.prank(alice);
|
|
146
|
-
|
|
143
|
+
pause.setPaused(params);
|
|
147
144
|
}
|
|
148
145
|
|
|
149
146
|
function test_setPaused_Revert_PauserCannotCauseEffectiveUnpause() public {
|
|
150
147
|
// `defaultPaused=false` and `enabled=false`.
|
|
151
|
-
|
|
152
|
-
bytes32
|
|
153
|
-
bytes32 unpauserRole = mock.UNPAUSER_ROLE();
|
|
148
|
+
bytes32 pauserRole = pauseRbac.PAUSER_ROLE();
|
|
149
|
+
bytes32 unpauserRole = pauseRbac.UNPAUSER_ROLE();
|
|
154
150
|
|
|
155
151
|
// Default is already false (unpaused).
|
|
156
|
-
assertFalse(
|
|
152
|
+
assertFalse(pause.defaultPaused());
|
|
157
153
|
|
|
158
154
|
// Grant only `PAUSER_ROLE` to `alice`.
|
|
159
|
-
|
|
155
|
+
pauseRbac.grantRole(pauserRole, alice);
|
|
160
156
|
|
|
161
157
|
// `alice` tries to set `enabled=false` with `paused=true` — effective state is unpaused.
|
|
162
158
|
IPauseByID.SetPausedParam[] memory params = new IPauseByID.SetPausedParam[](1);
|
|
@@ -166,60 +162,57 @@ contract PauseByIDRBACUpgradeableTest is PauseByIDBaseUpgradeableTest {
|
|
|
166
162
|
abi.encodeWithSelector(IAccessControl.AccessControlUnauthorizedAccount.selector, alice, unpauserRole)
|
|
167
163
|
);
|
|
168
164
|
vm.prank(alice);
|
|
169
|
-
|
|
165
|
+
pause.setPaused(params);
|
|
170
166
|
}
|
|
171
167
|
|
|
172
168
|
function test_setPaused_Success_PauserCanSetDisabledWhenDefaultPaused() public {
|
|
173
169
|
// `defaultPaused=true` and `enabled=false`.
|
|
174
|
-
|
|
175
|
-
bytes32 pauserRole = mock.PAUSER_ROLE();
|
|
170
|
+
bytes32 pauserRole = pauseRbac.PAUSER_ROLE();
|
|
176
171
|
|
|
177
172
|
// Set default to paused.
|
|
178
|
-
|
|
173
|
+
pause.setDefaultPaused(true);
|
|
179
174
|
|
|
180
175
|
// Grant only `PAUSER_ROLE` to `alice`.
|
|
181
|
-
|
|
176
|
+
pauseRbac.grantRole(pauserRole, alice);
|
|
182
177
|
|
|
183
178
|
// `alice` sets `enabled=false` — effective state is paused, so `PAUSER_ROLE` suffices.
|
|
184
179
|
IPauseByID.SetPausedParam[] memory params = new IPauseByID.SetPausedParam[](1);
|
|
185
180
|
params[0] = IPauseByID.SetPausedParam(1, false, false);
|
|
186
181
|
|
|
187
182
|
vm.prank(alice);
|
|
188
|
-
|
|
183
|
+
pause.setPaused(params);
|
|
189
184
|
|
|
190
|
-
assertTrue(
|
|
185
|
+
assertTrue(pause.isPaused(1));
|
|
191
186
|
}
|
|
192
187
|
|
|
193
188
|
function test_setPaused_Success_UnpauserCanSetDisabledWhenDefaultUnpaused() public {
|
|
194
|
-
|
|
195
|
-
bytes32 unpauserRole = mock.UNPAUSER_ROLE();
|
|
189
|
+
bytes32 unpauserRole = pauseRbac.UNPAUSER_ROLE();
|
|
196
190
|
|
|
197
191
|
// Default is already false (unpaused).
|
|
198
|
-
assertFalse(
|
|
192
|
+
assertFalse(pause.defaultPaused());
|
|
199
193
|
|
|
200
194
|
// Grant only `UNPAUSER_ROLE` to `alice`.
|
|
201
|
-
|
|
195
|
+
pauseRbac.grantRole(unpauserRole, alice);
|
|
202
196
|
|
|
203
197
|
// `alice` sets `enabled=false` — effective state is unpaused (from default), so `UNPAUSER_ROLE` suffices.
|
|
204
198
|
IPauseByID.SetPausedParam[] memory params = new IPauseByID.SetPausedParam[](1);
|
|
205
199
|
params[0] = IPauseByID.SetPausedParam(1, true, false);
|
|
206
200
|
|
|
207
201
|
vm.prank(alice);
|
|
208
|
-
|
|
202
|
+
pause.setPaused(params);
|
|
209
203
|
|
|
210
|
-
assertFalse(
|
|
204
|
+
assertFalse(pause.isPaused(1));
|
|
211
205
|
}
|
|
212
206
|
|
|
213
207
|
function test_setPaused_Revert_MixedBatchWithDisabledConfigs_NeedsBothRoles() public {
|
|
214
|
-
|
|
215
|
-
bytes32
|
|
216
|
-
bytes32 unpauserRole = mock.UNPAUSER_ROLE();
|
|
208
|
+
bytes32 pauserRole = pauseRbac.PAUSER_ROLE();
|
|
209
|
+
bytes32 unpauserRole = pauseRbac.UNPAUSER_ROLE();
|
|
217
210
|
|
|
218
211
|
// Set default to paused.
|
|
219
|
-
|
|
212
|
+
pause.setDefaultPaused(true);
|
|
220
213
|
|
|
221
214
|
// Grant only `PAUSER_ROLE` to `alice`.
|
|
222
|
-
|
|
215
|
+
pauseRbac.grantRole(pauserRole, alice);
|
|
223
216
|
|
|
224
217
|
// Batch: one explicitly unpauses (`enabled=true`, `paused=false`), one falls back to default paused (`enabled=false`).
|
|
225
218
|
IPauseByID.SetPausedParam[] memory params = new IPauseByID.SetPausedParam[](2);
|
|
@@ -230,20 +223,19 @@ contract PauseByIDRBACUpgradeableTest is PauseByIDBaseUpgradeableTest {
|
|
|
230
223
|
abi.encodeWithSelector(IAccessControl.AccessControlUnauthorizedAccount.selector, alice, unpauserRole)
|
|
231
224
|
);
|
|
232
225
|
vm.prank(alice);
|
|
233
|
-
|
|
226
|
+
pause.setPaused(params);
|
|
234
227
|
}
|
|
235
228
|
|
|
236
229
|
function test_setPaused_Success_MixedBatchWithDisabledConfigs_BothRoles() public {
|
|
237
|
-
|
|
238
|
-
bytes32
|
|
239
|
-
bytes32 unpauserRole = mock.UNPAUSER_ROLE();
|
|
230
|
+
bytes32 pauserRole = pauseRbac.PAUSER_ROLE();
|
|
231
|
+
bytes32 unpauserRole = pauseRbac.UNPAUSER_ROLE();
|
|
240
232
|
|
|
241
233
|
// Set default to paused.
|
|
242
|
-
|
|
234
|
+
pause.setDefaultPaused(true);
|
|
243
235
|
|
|
244
236
|
// Grant both roles to `alice`.
|
|
245
|
-
|
|
246
|
-
|
|
237
|
+
pauseRbac.grantRole(pauserRole, alice);
|
|
238
|
+
pauseRbac.grantRole(unpauserRole, alice);
|
|
247
239
|
|
|
248
240
|
// Batch: one explicitly unpauses, one falls back to default paused.
|
|
249
241
|
IPauseByID.SetPausedParam[] memory params = new IPauseByID.SetPausedParam[](2);
|
|
@@ -251,29 +243,28 @@ contract PauseByIDRBACUpgradeableTest is PauseByIDBaseUpgradeableTest {
|
|
|
251
243
|
params[1] = IPauseByID.SetPausedParam(2, false, false); // effective: paused (default)
|
|
252
244
|
|
|
253
245
|
vm.prank(alice);
|
|
254
|
-
|
|
246
|
+
pause.setPaused(params);
|
|
255
247
|
|
|
256
|
-
assertFalse(
|
|
257
|
-
assertTrue(
|
|
248
|
+
assertFalse(pause.isPaused(1));
|
|
249
|
+
assertTrue(pause.isPaused(2));
|
|
258
250
|
}
|
|
259
251
|
|
|
260
252
|
/// @dev Dormant data planted by one role cannot be activated without the other role.
|
|
261
253
|
function test_setPaused_DormantData() public {
|
|
262
|
-
|
|
263
|
-
bytes32
|
|
264
|
-
bytes32 unpauserRole = mock.UNPAUSER_ROLE();
|
|
254
|
+
bytes32 pauserRole = pauseRbac.PAUSER_ROLE();
|
|
255
|
+
bytes32 unpauserRole = pauseRbac.UNPAUSER_ROLE();
|
|
265
256
|
|
|
266
257
|
address frank = address(0x456);
|
|
267
|
-
|
|
268
|
-
|
|
258
|
+
pauseRbac.grantRole(unpauserRole, alice);
|
|
259
|
+
pauseRbac.grantRole(pauserRole, frank);
|
|
269
260
|
|
|
270
261
|
// `defaultPaused=false`. `UNPAUSER_ROLE` stores dormant `paused=true` (`enabled=false`).
|
|
271
262
|
IPauseByID.SetPausedParam[] memory params = new IPauseByID.SetPausedParam[](1);
|
|
272
263
|
params[0] = IPauseByID.SetPausedParam(1, true, false);
|
|
273
264
|
vm.prank(alice);
|
|
274
|
-
|
|
275
|
-
assertFalse(
|
|
276
|
-
assertTrue(
|
|
265
|
+
pause.setPaused(params);
|
|
266
|
+
assertFalse(pause.isPaused(1));
|
|
267
|
+
assertTrue(pause.pauseConfig(1).paused);
|
|
277
268
|
|
|
278
269
|
// `UNPAUSER_ROLE` cannot activate dormant `paused=true`.
|
|
279
270
|
params[0] = IPauseByID.SetPausedParam(1, true, true);
|
|
@@ -281,19 +272,19 @@ contract PauseByIDRBACUpgradeableTest is PauseByIDBaseUpgradeableTest {
|
|
|
281
272
|
abi.encodeWithSelector(IAccessControl.AccessControlUnauthorizedAccount.selector, alice, pauserRole)
|
|
282
273
|
);
|
|
283
274
|
vm.prank(alice);
|
|
284
|
-
|
|
275
|
+
pause.setPaused(params);
|
|
285
276
|
|
|
286
277
|
// `PAUSER_ROLE` can activate it.
|
|
287
278
|
vm.prank(frank);
|
|
288
|
-
|
|
289
|
-
assertTrue(
|
|
279
|
+
pause.setPaused(params);
|
|
280
|
+
assertTrue(pause.isPaused(1));
|
|
290
281
|
|
|
291
282
|
// Symmetric: `defaultPaused=true`. `PAUSER_ROLE` stores dormant `paused=false` (`enabled=false`).
|
|
292
|
-
|
|
283
|
+
pause.setDefaultPaused(true);
|
|
293
284
|
params[0] = IPauseByID.SetPausedParam(2, false, false);
|
|
294
285
|
vm.prank(frank);
|
|
295
|
-
|
|
296
|
-
assertTrue(
|
|
286
|
+
pause.setPaused(params);
|
|
287
|
+
assertTrue(pause.isPaused(2));
|
|
297
288
|
|
|
298
289
|
// `PAUSER_ROLE` cannot activate dormant `paused=false`.
|
|
299
290
|
params[0] = IPauseByID.SetPausedParam(2, false, true);
|
|
@@ -301,28 +292,25 @@ contract PauseByIDRBACUpgradeableTest is PauseByIDBaseUpgradeableTest {
|
|
|
301
292
|
abi.encodeWithSelector(IAccessControl.AccessControlUnauthorizedAccount.selector, frank, unpauserRole)
|
|
302
293
|
);
|
|
303
294
|
vm.prank(frank);
|
|
304
|
-
|
|
295
|
+
pause.setPaused(params);
|
|
305
296
|
|
|
306
297
|
// `UNPAUSER_ROLE` can activate it.
|
|
307
298
|
vm.prank(alice);
|
|
308
|
-
|
|
309
|
-
assertFalse(
|
|
299
|
+
pause.setPaused(params);
|
|
300
|
+
assertFalse(pause.isPaused(2));
|
|
310
301
|
}
|
|
311
302
|
|
|
312
303
|
function test_setPaused_EmptyArrayWithUnpauserRole() public {
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
mock.grantRole(mock.UNPAUSER_ROLE(), alice);
|
|
304
|
+
pauseRbac.grantRole(pauseRbac.UNPAUSER_ROLE(), alice);
|
|
316
305
|
|
|
317
306
|
IPauseByID.SetPausedParam[] memory params = new IPauseByID.SetPausedParam[](0);
|
|
318
307
|
|
|
319
308
|
vm.prank(alice);
|
|
320
|
-
|
|
309
|
+
pause.setPaused(params);
|
|
321
310
|
}
|
|
322
311
|
|
|
323
312
|
function test_setPaused_Revert_EmptyArrayUnauthorized() public {
|
|
324
|
-
|
|
325
|
-
bytes32 unpauserRole = mock.UNPAUSER_ROLE();
|
|
313
|
+
bytes32 unpauserRole = pauseRbac.UNPAUSER_ROLE();
|
|
326
314
|
|
|
327
315
|
IPauseByID.SetPausedParam[] memory params = new IPauseByID.SetPausedParam[](0);
|
|
328
316
|
|
|
@@ -330,17 +318,16 @@ contract PauseByIDRBACUpgradeableTest is PauseByIDBaseUpgradeableTest {
|
|
|
330
318
|
abi.encodeWithSelector(IAccessControl.AccessControlUnauthorizedAccount.selector, alice, unpauserRole)
|
|
331
319
|
);
|
|
332
320
|
vm.prank(alice);
|
|
333
|
-
|
|
321
|
+
pause.setPaused(params);
|
|
334
322
|
}
|
|
335
323
|
|
|
336
324
|
/// @dev Correct role succeeds, wrong role reverts, for all effective-state combinations.
|
|
337
325
|
function test_setPaused_Fuzz_EffectiveStateRoleCheck(bool _defaultPaused, bool _paused, bool _enabled) public {
|
|
338
|
-
|
|
339
|
-
bytes32
|
|
340
|
-
bytes32 unpauserRole = mock.UNPAUSER_ROLE();
|
|
326
|
+
bytes32 pauserRole = pauseRbac.PAUSER_ROLE();
|
|
327
|
+
bytes32 unpauserRole = pauseRbac.UNPAUSER_ROLE();
|
|
341
328
|
|
|
342
329
|
if (_defaultPaused) {
|
|
343
|
-
|
|
330
|
+
pause.setDefaultPaused(true);
|
|
344
331
|
}
|
|
345
332
|
|
|
346
333
|
bool effectivePaused = _enabled ? _paused : _defaultPaused;
|
|
@@ -351,64 +338,63 @@ contract PauseByIDRBACUpgradeableTest is PauseByIDBaseUpgradeableTest {
|
|
|
351
338
|
// Wrong role reverts.
|
|
352
339
|
address wrongCaller = address(0xBAD);
|
|
353
340
|
if (effectivePaused) {
|
|
354
|
-
|
|
341
|
+
pauseRbac.grantRole(unpauserRole, wrongCaller);
|
|
355
342
|
} else {
|
|
356
|
-
|
|
343
|
+
pauseRbac.grantRole(pauserRole, wrongCaller);
|
|
357
344
|
}
|
|
358
345
|
bytes32 missingRole = effectivePaused ? pauserRole : unpauserRole;
|
|
359
346
|
vm.expectRevert(
|
|
360
347
|
abi.encodeWithSelector(IAccessControl.AccessControlUnauthorizedAccount.selector, wrongCaller, missingRole)
|
|
361
348
|
);
|
|
362
349
|
vm.prank(wrongCaller);
|
|
363
|
-
|
|
350
|
+
pause.setPaused(params);
|
|
364
351
|
|
|
365
352
|
// Correct role succeeds.
|
|
366
353
|
if (effectivePaused) {
|
|
367
|
-
|
|
354
|
+
pauseRbac.grantRole(pauserRole, alice);
|
|
368
355
|
} else {
|
|
369
|
-
|
|
356
|
+
pauseRbac.grantRole(unpauserRole, alice);
|
|
370
357
|
}
|
|
371
358
|
vm.prank(alice);
|
|
372
|
-
|
|
373
|
-
assertEq(
|
|
359
|
+
pause.setPaused(params);
|
|
360
|
+
assertEq(pause.isPaused(1), effectivePaused);
|
|
374
361
|
}
|
|
375
362
|
|
|
376
363
|
function test_roleManagement_grantAndRevoke() public {
|
|
377
364
|
address newPauser = address(0x123);
|
|
378
|
-
|
|
379
|
-
bytes32
|
|
380
|
-
bytes32 unpauserRole = mock.UNPAUSER_ROLE();
|
|
365
|
+
bytes32 pauserRole = pauseRbac.PAUSER_ROLE();
|
|
366
|
+
bytes32 unpauserRole = pauseRbac.UNPAUSER_ROLE();
|
|
381
367
|
|
|
382
|
-
|
|
368
|
+
pauseRbac.grantRole(pauserRole, newPauser);
|
|
383
369
|
|
|
384
370
|
// `newPauser` can now pause.
|
|
385
371
|
vm.prank(newPauser);
|
|
386
|
-
|
|
387
|
-
assertTrue(
|
|
372
|
+
pause.setDefaultPaused(true);
|
|
373
|
+
assertTrue(pause.defaultPaused());
|
|
388
374
|
|
|
389
375
|
// But `newPauser` cannot unpause (needs `UNPAUSER_ROLE`).
|
|
390
376
|
vm.expectRevert(
|
|
391
377
|
abi.encodeWithSelector(IAccessControl.AccessControlUnauthorizedAccount.selector, newPauser, unpauserRole)
|
|
392
378
|
);
|
|
393
379
|
vm.prank(newPauser);
|
|
394
|
-
|
|
380
|
+
pause.setDefaultPaused(false);
|
|
395
381
|
|
|
396
382
|
// Grant `UNPAUSER_ROLE` to `newPauser`.
|
|
397
|
-
|
|
383
|
+
pauseRbac.grantRole(unpauserRole, newPauser);
|
|
398
384
|
|
|
399
385
|
// Now `newPauser` can unpause.
|
|
400
386
|
vm.prank(newPauser);
|
|
401
|
-
|
|
402
|
-
assertFalse(
|
|
387
|
+
pause.setDefaultPaused(false);
|
|
388
|
+
assertFalse(pause.defaultPaused());
|
|
403
389
|
|
|
404
390
|
// Revoke `PAUSER_ROLE`.
|
|
405
|
-
|
|
391
|
+
pauseRbac.revokeRole(pauserRole, newPauser);
|
|
406
392
|
|
|
407
393
|
// `newPauser` can no longer pause.
|
|
408
394
|
vm.expectRevert(
|
|
409
395
|
abi.encodeWithSelector(IAccessControl.AccessControlUnauthorizedAccount.selector, newPauser, pauserRole)
|
|
410
396
|
);
|
|
411
397
|
vm.prank(newPauser);
|
|
412
|
-
|
|
398
|
+
pause.setDefaultPaused(true);
|
|
413
399
|
}
|
|
414
400
|
}
|