@layerzerolabs/utils-upgradeable-evm-contracts 1.2.9 → 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 +730 -769
- 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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@layerzerolabs/utils-upgradeable-evm-contracts",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.10",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "LayerZero Labs reference EVM upgradeable utility implementations",
|
|
6
6
|
"license": "MIT",
|
|
@@ -10,9 +10,9 @@
|
|
|
10
10
|
"@openzeppelin/contracts": "^5.0.2",
|
|
11
11
|
"@openzeppelin/contracts-upgradeable": "^5.0.2",
|
|
12
12
|
"solhint": "^6.0.1",
|
|
13
|
-
"@layerzerolabs/utils-evm-contracts": "1.2.
|
|
14
|
-
"@layerzerolabs/
|
|
15
|
-
"@layerzerolabs/
|
|
13
|
+
"@layerzerolabs/utils-evm-contracts": "1.2.10",
|
|
14
|
+
"@layerzerolabs/solhint-configuration": "1.2.10",
|
|
15
|
+
"@layerzerolabs/vm-tooling-evm": "1.2.10"
|
|
16
16
|
},
|
|
17
17
|
"publishConfig": {
|
|
18
18
|
"access": "public",
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
IAccessControl2Step
|
|
11
11
|
} from "./../contracts/access/AccessControl2StepUpgradeable.sol";
|
|
12
12
|
|
|
13
|
-
contract
|
|
13
|
+
contract AccessControl2StepUpgradeableHarness is AccessControl2StepUpgradeable {
|
|
14
14
|
bytes32 public constant TEST_ROLE = keccak256("TEST_ROLE");
|
|
15
15
|
bytes32 public constant OTHER_ROLE = keccak256("OTHER_ROLE");
|
|
16
16
|
|
|
@@ -28,7 +28,7 @@ contract AccessControl2StepUpgradeableMock is AccessControl2StepUpgradeable {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
contract AccessControl2StepUpgradeableTest is Test {
|
|
31
|
-
|
|
31
|
+
AccessControl2StepUpgradeableHarness accessControl;
|
|
32
32
|
|
|
33
33
|
address initialAdmin = address(this);
|
|
34
34
|
address alice = makeAddr("alice");
|
|
@@ -39,8 +39,8 @@ contract AccessControl2StepUpgradeableTest is Test {
|
|
|
39
39
|
bytes32 defaultAdminRole;
|
|
40
40
|
bytes32 testRole;
|
|
41
41
|
|
|
42
|
-
function
|
|
43
|
-
|
|
42
|
+
function _deployAccessControl() internal returns (AccessControl2StepUpgradeableHarness) {
|
|
43
|
+
AccessControl2StepUpgradeableHarness impl = new AccessControl2StepUpgradeableHarness();
|
|
44
44
|
|
|
45
45
|
uint256 currentNonce = vm.getNonce(address(this));
|
|
46
46
|
proxyAdmin = vm.computeCreateAddress(vm.computeCreateAddress(address(this), currentNonce), 1);
|
|
@@ -48,78 +48,82 @@ contract AccessControl2StepUpgradeableTest is Test {
|
|
|
48
48
|
TransparentUpgradeableProxy proxy = new TransparentUpgradeableProxy(
|
|
49
49
|
address(impl),
|
|
50
50
|
address(this),
|
|
51
|
-
abi.encodeWithSelector(
|
|
51
|
+
abi.encodeWithSelector(AccessControl2StepUpgradeableHarness.initialize.selector, address(this))
|
|
52
52
|
);
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
return AccessControl2StepUpgradeableHarness(address(proxy));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function setUp() public {
|
|
57
|
+
accessControl = _deployAccessControl();
|
|
58
|
+
defaultAdminRole = accessControl.DEFAULT_ADMIN_ROLE();
|
|
59
|
+
testRole = accessControl.TEST_ROLE();
|
|
56
60
|
}
|
|
57
61
|
|
|
58
62
|
// ============ Initialization ============
|
|
59
63
|
|
|
60
64
|
function test_initialize_Success_AdminHasRole() public view {
|
|
61
|
-
assertTrue(
|
|
62
|
-
assertEq(
|
|
63
|
-
assertEq(
|
|
64
|
-
assertEq(
|
|
65
|
+
assertTrue(accessControl.hasRole(defaultAdminRole, initialAdmin));
|
|
66
|
+
assertEq(accessControl.getRoleMemberCount(defaultAdminRole), 1);
|
|
67
|
+
assertEq(accessControl.getRoleMember(defaultAdminRole, 0), initialAdmin);
|
|
68
|
+
assertEq(accessControl.defaultAdmin(), initialAdmin);
|
|
65
69
|
}
|
|
66
70
|
|
|
67
71
|
function test_initialize_Revert_AlreadyInitialized() public {
|
|
68
72
|
vm.expectRevert(Initializable.InvalidInitialization.selector);
|
|
69
|
-
|
|
73
|
+
accessControl.initialize(address(0x999));
|
|
70
74
|
}
|
|
71
75
|
|
|
72
76
|
function test_initialize_Revert_InvalidDefaultAdmin() public {
|
|
73
|
-
|
|
77
|
+
AccessControl2StepUpgradeableHarness impl = new AccessControl2StepUpgradeableHarness();
|
|
74
78
|
vm.expectRevert(abi.encodeWithSelector(IAccessControl2Step.InvalidDefaultAdmin.selector, address(0)));
|
|
75
79
|
new TransparentUpgradeableProxy(
|
|
76
80
|
address(impl),
|
|
77
81
|
address(this),
|
|
78
|
-
abi.encodeWithSelector(
|
|
82
|
+
abi.encodeWithSelector(AccessControl2StepUpgradeableHarness.initialize.selector, address(0))
|
|
79
83
|
);
|
|
80
84
|
}
|
|
81
85
|
|
|
82
86
|
// ============ defaultAdmin ============
|
|
83
87
|
|
|
84
88
|
function test_defaultAdmin_ReturnsInitialAdmin() public view {
|
|
85
|
-
assertEq(
|
|
89
|
+
assertEq(accessControl.defaultAdmin(), initialAdmin);
|
|
86
90
|
}
|
|
87
91
|
|
|
88
92
|
// ============ pendingDefaultAdmin ============
|
|
89
93
|
|
|
90
94
|
function test_pendingDefaultAdmin_InitiallyZero() public view {
|
|
91
|
-
assertEq(
|
|
95
|
+
assertEq(accessControl.pendingDefaultAdmin(), address(0));
|
|
92
96
|
}
|
|
93
97
|
|
|
94
98
|
// ============ beginDefaultAdminTransfer ============
|
|
95
99
|
|
|
96
100
|
function test_beginDefaultAdminTransfer_Success() public {
|
|
97
|
-
vm.expectEmit(true, true, true, true, address(
|
|
101
|
+
vm.expectEmit(true, true, true, true, address(accessControl));
|
|
98
102
|
emit IAccessControl2Step.DefaultAdminTransferStarted(alice);
|
|
99
103
|
|
|
100
|
-
|
|
104
|
+
accessControl.beginDefaultAdminTransfer(alice);
|
|
101
105
|
|
|
102
|
-
assertEq(
|
|
103
|
-
assertEq(
|
|
106
|
+
assertEq(accessControl.pendingDefaultAdmin(), alice);
|
|
107
|
+
assertEq(accessControl.defaultAdmin(), initialAdmin);
|
|
104
108
|
}
|
|
105
109
|
|
|
106
110
|
function test_beginDefaultAdminTransfer_Success_OverwritesPending() public {
|
|
107
|
-
|
|
108
|
-
assertEq(
|
|
111
|
+
accessControl.beginDefaultAdminTransfer(alice);
|
|
112
|
+
assertEq(accessControl.pendingDefaultAdmin(), alice);
|
|
109
113
|
|
|
110
|
-
|
|
111
|
-
assertEq(
|
|
114
|
+
accessControl.beginDefaultAdminTransfer(bob);
|
|
115
|
+
assertEq(accessControl.pendingDefaultAdmin(), bob);
|
|
112
116
|
}
|
|
113
117
|
|
|
114
118
|
function test_beginDefaultAdminTransfer_Success_CancelsBySettingZero() public {
|
|
115
|
-
|
|
116
|
-
assertEq(
|
|
119
|
+
accessControl.beginDefaultAdminTransfer(alice);
|
|
120
|
+
assertEq(accessControl.pendingDefaultAdmin(), alice);
|
|
117
121
|
|
|
118
|
-
vm.expectEmit(true, true, true, true, address(
|
|
122
|
+
vm.expectEmit(true, true, true, true, address(accessControl));
|
|
119
123
|
emit IAccessControl2Step.DefaultAdminTransferStarted(address(0));
|
|
120
124
|
|
|
121
|
-
|
|
122
|
-
assertEq(
|
|
125
|
+
accessControl.beginDefaultAdminTransfer(address(0));
|
|
126
|
+
assertEq(accessControl.pendingDefaultAdmin(), address(0));
|
|
123
127
|
}
|
|
124
128
|
|
|
125
129
|
function test_beginDefaultAdminTransfer_Revert_Unauthorized() public {
|
|
@@ -127,49 +131,49 @@ contract AccessControl2StepUpgradeableTest is Test {
|
|
|
127
131
|
abi.encodeWithSelector(IAccessControl.AccessControlUnauthorizedAccount.selector, alice, defaultAdminRole)
|
|
128
132
|
);
|
|
129
133
|
vm.prank(alice);
|
|
130
|
-
|
|
134
|
+
accessControl.beginDefaultAdminTransfer(bob);
|
|
131
135
|
}
|
|
132
136
|
|
|
133
137
|
// ============ acceptDefaultAdminTransfer ============
|
|
134
138
|
|
|
135
139
|
function test_acceptDefaultAdminTransfer_Success() public {
|
|
136
|
-
|
|
140
|
+
accessControl.beginDefaultAdminTransfer(alice);
|
|
137
141
|
|
|
138
142
|
vm.prank(alice);
|
|
139
|
-
|
|
143
|
+
accessControl.acceptDefaultAdminTransfer();
|
|
140
144
|
|
|
141
|
-
assertTrue(
|
|
142
|
-
assertFalse(
|
|
143
|
-
assertEq(
|
|
144
|
-
assertEq(
|
|
145
|
-
assertEq(
|
|
146
|
-
assertEq(
|
|
145
|
+
assertTrue(accessControl.hasRole(defaultAdminRole, alice));
|
|
146
|
+
assertFalse(accessControl.hasRole(defaultAdminRole, initialAdmin));
|
|
147
|
+
assertEq(accessControl.getRoleMemberCount(defaultAdminRole), 1);
|
|
148
|
+
assertEq(accessControl.getRoleMember(defaultAdminRole, 0), alice);
|
|
149
|
+
assertEq(accessControl.defaultAdmin(), alice);
|
|
150
|
+
assertEq(accessControl.pendingDefaultAdmin(), address(0));
|
|
147
151
|
}
|
|
148
152
|
|
|
149
153
|
function test_acceptDefaultAdminTransfer_Revert_NotPendingAdmin() public {
|
|
150
|
-
|
|
154
|
+
accessControl.beginDefaultAdminTransfer(alice);
|
|
151
155
|
|
|
152
156
|
vm.expectRevert(abi.encodeWithSelector(IAccessControl2Step.CallerNotPendingAdmin.selector, alice));
|
|
153
157
|
vm.prank(bob);
|
|
154
|
-
|
|
158
|
+
accessControl.acceptDefaultAdminTransfer();
|
|
155
159
|
}
|
|
156
160
|
|
|
157
161
|
function test_acceptDefaultAdminTransfer_Revert_NoPendingTransfer() public {
|
|
158
162
|
vm.expectRevert(abi.encodeWithSelector(IAccessControl2Step.CallerNotPendingAdmin.selector, address(0)));
|
|
159
163
|
vm.prank(alice);
|
|
160
|
-
|
|
164
|
+
accessControl.acceptDefaultAdminTransfer();
|
|
161
165
|
}
|
|
162
166
|
|
|
163
167
|
// ============ grantRole ============
|
|
164
168
|
|
|
165
169
|
function test_grantRole_Revert_DefaultAdminRole() public {
|
|
166
170
|
vm.expectRevert(abi.encodeWithSelector(IAccessControl2Step.AccessControlEnforcedDefaultAdminRules.selector));
|
|
167
|
-
|
|
171
|
+
accessControl.grantRole(defaultAdminRole, alice);
|
|
168
172
|
}
|
|
169
173
|
|
|
170
174
|
function test_grantRole_Success_NonAdminRole() public {
|
|
171
|
-
|
|
172
|
-
assertTrue(
|
|
175
|
+
accessControl.grantRole(testRole, alice);
|
|
176
|
+
assertTrue(accessControl.hasRole(testRole, alice));
|
|
173
177
|
}
|
|
174
178
|
|
|
175
179
|
// ============ revokeRole ============
|
|
@@ -179,80 +183,80 @@ contract AccessControl2StepUpgradeableTest is Test {
|
|
|
179
183
|
abi.encodeWithSelector(IAccessControl.AccessControlUnauthorizedAccount.selector, alice, defaultAdminRole)
|
|
180
184
|
);
|
|
181
185
|
vm.prank(alice);
|
|
182
|
-
|
|
186
|
+
accessControl.revokeRole(defaultAdminRole, initialAdmin);
|
|
183
187
|
}
|
|
184
188
|
|
|
185
189
|
function test_revokeRole_Revert_DefaultAdminRole_Admin() public {
|
|
186
190
|
vm.expectRevert(abi.encodeWithSelector(IAccessControl2Step.AccessControlEnforcedDefaultAdminRules.selector));
|
|
187
|
-
|
|
191
|
+
accessControl.revokeRole(defaultAdminRole, initialAdmin);
|
|
188
192
|
}
|
|
189
193
|
|
|
190
194
|
function test_revokeRole_Success_NonAdminRole_Admin() public {
|
|
191
|
-
|
|
192
|
-
assertTrue(
|
|
195
|
+
accessControl.grantRole(testRole, alice);
|
|
196
|
+
assertTrue(accessControl.hasRole(testRole, alice));
|
|
193
197
|
|
|
194
|
-
|
|
195
|
-
assertFalse(
|
|
198
|
+
accessControl.revokeRole(testRole, alice);
|
|
199
|
+
assertFalse(accessControl.hasRole(testRole, alice));
|
|
196
200
|
}
|
|
197
201
|
|
|
198
202
|
function test_revokeRole_Revert_NonAdminRole_NonAdmin() public {
|
|
199
|
-
|
|
200
|
-
assertTrue(
|
|
203
|
+
accessControl.grantRole(testRole, alice);
|
|
204
|
+
assertTrue(accessControl.hasRole(testRole, alice));
|
|
201
205
|
|
|
202
206
|
vm.expectRevert(
|
|
203
207
|
abi.encodeWithSelector(IAccessControl.AccessControlUnauthorizedAccount.selector, alice, defaultAdminRole)
|
|
204
208
|
);
|
|
205
209
|
vm.prank(alice);
|
|
206
|
-
|
|
210
|
+
accessControl.revokeRole(testRole, alice);
|
|
207
211
|
}
|
|
208
212
|
|
|
209
213
|
// ============ renounceRole ============
|
|
210
214
|
|
|
211
215
|
function test_renounceRole_Revert_DefaultAdminRole() public {
|
|
212
216
|
vm.expectRevert(abi.encodeWithSelector(IAccessControl2Step.AccessControlEnforcedDefaultAdminRules.selector));
|
|
213
|
-
|
|
217
|
+
accessControl.renounceRole(defaultAdminRole, initialAdmin);
|
|
214
218
|
}
|
|
215
219
|
|
|
216
220
|
function test_renounceRole_Revert_DefaultAdminRoleDuringPendingTransfer() public {
|
|
217
|
-
|
|
221
|
+
accessControl.beginDefaultAdminTransfer(alice);
|
|
218
222
|
|
|
219
223
|
vm.expectRevert(abi.encodeWithSelector(IAccessControl2Step.AccessControlEnforcedDefaultAdminRules.selector));
|
|
220
|
-
|
|
224
|
+
accessControl.renounceRole(defaultAdminRole, initialAdmin);
|
|
221
225
|
}
|
|
222
226
|
|
|
223
227
|
function test_renounceRole_Success_NonAdminRole_NonAdmin() public {
|
|
224
|
-
|
|
228
|
+
accessControl.grantRole(testRole, alice);
|
|
225
229
|
|
|
226
230
|
vm.startPrank(alice);
|
|
227
|
-
|
|
231
|
+
accessControl.renounceRole(testRole, alice);
|
|
228
232
|
vm.stopPrank();
|
|
229
233
|
|
|
230
|
-
assertFalse(
|
|
234
|
+
assertFalse(accessControl.hasRole(testRole, alice));
|
|
231
235
|
}
|
|
232
236
|
|
|
233
237
|
function test_renounceRole_Success_NonAdminRole_Admin() public {
|
|
234
|
-
|
|
235
|
-
|
|
238
|
+
accessControl.grantRole(testRole, initialAdmin);
|
|
239
|
+
accessControl.renounceRole(testRole, initialAdmin);
|
|
236
240
|
|
|
237
|
-
assertFalse(
|
|
241
|
+
assertFalse(accessControl.hasRole(testRole, initialAdmin));
|
|
238
242
|
}
|
|
239
243
|
|
|
240
244
|
// ============ setRoleAdmin ============
|
|
241
245
|
|
|
242
246
|
function test_setRoleAdmin_Success_NonAdminRole_Self() public {
|
|
243
|
-
|
|
244
|
-
assertEq(
|
|
247
|
+
accessControl.exposedSetRoleAdmin(testRole, defaultAdminRole);
|
|
248
|
+
assertEq(accessControl.getRoleAdmin(testRole), defaultAdminRole);
|
|
245
249
|
}
|
|
246
250
|
|
|
247
251
|
function test_setRoleAdmin_Success_NonAdminRole_Other() public {
|
|
248
|
-
bytes32 otherRole =
|
|
249
|
-
|
|
250
|
-
assertEq(
|
|
252
|
+
bytes32 otherRole = accessControl.OTHER_ROLE();
|
|
253
|
+
accessControl.exposedSetRoleAdmin(testRole, otherRole);
|
|
254
|
+
assertEq(accessControl.getRoleAdmin(testRole), otherRole);
|
|
251
255
|
}
|
|
252
256
|
|
|
253
257
|
function test_setRoleAdmin_Revert_DefaultAdminRole() public {
|
|
254
258
|
vm.expectRevert(abi.encodeWithSelector(IAccessControl2Step.AccessControlEnforcedDefaultAdminRules.selector));
|
|
255
|
-
|
|
259
|
+
accessControl.exposedSetRoleAdmin(defaultAdminRole, testRole);
|
|
256
260
|
}
|
|
257
261
|
|
|
258
262
|
// ============ Storage ============
|
|
@@ -268,9 +272,9 @@ contract AccessControl2StepUpgradeableTest is Test {
|
|
|
268
272
|
// ============ Fuzz ============
|
|
269
273
|
|
|
270
274
|
function test_beginDefaultAdminTransfer_Fuzz(address _newAdmin) public {
|
|
271
|
-
|
|
272
|
-
assertEq(
|
|
273
|
-
assertEq(
|
|
275
|
+
accessControl.beginDefaultAdminTransfer(_newAdmin);
|
|
276
|
+
assertEq(accessControl.pendingDefaultAdmin(), _newAdmin);
|
|
277
|
+
assertEq(accessControl.defaultAdmin(), initialAdmin);
|
|
274
278
|
}
|
|
275
279
|
|
|
276
280
|
function test_acceptDefaultAdminTransfer_Fuzz(address _newAdmin) public {
|
|
@@ -278,97 +282,97 @@ contract AccessControl2StepUpgradeableTest is Test {
|
|
|
278
282
|
vm.assume(_newAdmin != proxyAdmin);
|
|
279
283
|
vm.assume(_newAdmin != initialAdmin);
|
|
280
284
|
|
|
281
|
-
|
|
285
|
+
accessControl.beginDefaultAdminTransfer(_newAdmin);
|
|
282
286
|
vm.prank(_newAdmin);
|
|
283
|
-
|
|
287
|
+
accessControl.acceptDefaultAdminTransfer();
|
|
284
288
|
|
|
285
|
-
assertTrue(
|
|
286
|
-
assertFalse(
|
|
287
|
-
assertEq(
|
|
288
|
-
assertEq(
|
|
289
|
-
assertEq(
|
|
290
|
-
assertEq(
|
|
289
|
+
assertTrue(accessControl.hasRole(defaultAdminRole, _newAdmin));
|
|
290
|
+
assertFalse(accessControl.hasRole(defaultAdminRole, initialAdmin));
|
|
291
|
+
assertEq(accessControl.defaultAdmin(), _newAdmin);
|
|
292
|
+
assertEq(accessControl.pendingDefaultAdmin(), address(0));
|
|
293
|
+
assertEq(accessControl.getRoleMemberCount(defaultAdminRole), 1);
|
|
294
|
+
assertEq(accessControl.getRoleMember(defaultAdminRole, 0), _newAdmin);
|
|
291
295
|
}
|
|
292
296
|
|
|
293
297
|
// ============ Edge Cases ============
|
|
294
298
|
|
|
295
299
|
function test_acceptDefaultAdminTransfer_Revert_StalePendingAfterOverwrite() public {
|
|
296
|
-
|
|
297
|
-
|
|
300
|
+
accessControl.beginDefaultAdminTransfer(alice);
|
|
301
|
+
accessControl.beginDefaultAdminTransfer(bob); // Overwrite
|
|
298
302
|
|
|
299
303
|
// `alice` (stale pending) cannot accept.
|
|
300
304
|
vm.expectRevert(abi.encodeWithSelector(IAccessControl2Step.CallerNotPendingAdmin.selector, bob));
|
|
301
305
|
vm.prank(alice);
|
|
302
|
-
|
|
306
|
+
accessControl.acceptDefaultAdminTransfer();
|
|
303
307
|
|
|
304
308
|
// `bob` (current pending) can accept.
|
|
305
309
|
vm.prank(bob);
|
|
306
|
-
|
|
310
|
+
accessControl.acceptDefaultAdminTransfer();
|
|
307
311
|
|
|
308
|
-
assertTrue(
|
|
309
|
-
assertFalse(
|
|
312
|
+
assertTrue(accessControl.hasRole(defaultAdminRole, bob));
|
|
313
|
+
assertFalse(accessControl.hasRole(defaultAdminRole, alice));
|
|
310
314
|
}
|
|
311
315
|
|
|
312
316
|
function test_acceptDefaultAdminTransfer_Revert_AfterCancel() public {
|
|
313
|
-
|
|
314
|
-
|
|
317
|
+
accessControl.beginDefaultAdminTransfer(alice);
|
|
318
|
+
accessControl.beginDefaultAdminTransfer(address(0)); // Cancel
|
|
315
319
|
|
|
316
320
|
vm.expectRevert(abi.encodeWithSelector(IAccessControl2Step.CallerNotPendingAdmin.selector, address(0)));
|
|
317
321
|
vm.prank(alice);
|
|
318
|
-
|
|
322
|
+
accessControl.acceptDefaultAdminTransfer();
|
|
319
323
|
}
|
|
320
324
|
|
|
321
325
|
function test_acceptDefaultAdminTransfer_Events() public {
|
|
322
|
-
|
|
326
|
+
accessControl.beginDefaultAdminTransfer(alice);
|
|
323
327
|
|
|
324
|
-
vm.expectEmit(true, true, true, true, address(
|
|
328
|
+
vm.expectEmit(true, true, true, true, address(accessControl));
|
|
325
329
|
emit IAccessControl.RoleRevoked(defaultAdminRole, initialAdmin, alice);
|
|
326
|
-
vm.expectEmit(true, true, true, true, address(
|
|
330
|
+
vm.expectEmit(true, true, true, true, address(accessControl));
|
|
327
331
|
emit IAccessControl.RoleGranted(defaultAdminRole, alice, alice);
|
|
328
332
|
|
|
329
333
|
vm.prank(alice);
|
|
330
|
-
|
|
334
|
+
accessControl.acceptDefaultAdminTransfer();
|
|
331
335
|
}
|
|
332
336
|
|
|
333
337
|
// ============ Integration ============
|
|
334
338
|
|
|
335
339
|
function test_integration_TransferAndTransferAgain() public {
|
|
336
340
|
// Admin transfers to `alice`.
|
|
337
|
-
|
|
341
|
+
accessControl.beginDefaultAdminTransfer(alice);
|
|
338
342
|
vm.prank(alice);
|
|
339
|
-
|
|
343
|
+
accessControl.acceptDefaultAdminTransfer();
|
|
340
344
|
|
|
341
345
|
// `alice` transfers to `bob`.
|
|
342
346
|
vm.prank(alice);
|
|
343
|
-
|
|
347
|
+
accessControl.beginDefaultAdminTransfer(bob);
|
|
344
348
|
vm.prank(bob);
|
|
345
|
-
|
|
349
|
+
accessControl.acceptDefaultAdminTransfer();
|
|
346
350
|
|
|
347
351
|
// `bob` transfers to `charlie`.
|
|
348
352
|
vm.prank(bob);
|
|
349
|
-
|
|
353
|
+
accessControl.beginDefaultAdminTransfer(charlie);
|
|
350
354
|
vm.prank(charlie);
|
|
351
|
-
|
|
355
|
+
accessControl.acceptDefaultAdminTransfer();
|
|
352
356
|
|
|
353
|
-
assertTrue(
|
|
354
|
-
assertFalse(
|
|
355
|
-
assertFalse(
|
|
356
|
-
assertFalse(
|
|
357
|
-
assertEq(
|
|
357
|
+
assertTrue(accessControl.hasRole(defaultAdminRole, charlie));
|
|
358
|
+
assertFalse(accessControl.hasRole(defaultAdminRole, bob));
|
|
359
|
+
assertFalse(accessControl.hasRole(defaultAdminRole, alice));
|
|
360
|
+
assertFalse(accessControl.hasRole(defaultAdminRole, initialAdmin));
|
|
361
|
+
assertEq(accessControl.getRoleMemberCount(defaultAdminRole), 1);
|
|
358
362
|
}
|
|
359
363
|
|
|
360
364
|
function test_integration_TransferCancelRetransfer() public {
|
|
361
365
|
// Admin starts transfer to `alice` then cancels.
|
|
362
|
-
|
|
363
|
-
|
|
366
|
+
accessControl.beginDefaultAdminTransfer(alice);
|
|
367
|
+
accessControl.beginDefaultAdminTransfer(address(0)); // Cancel
|
|
364
368
|
|
|
365
369
|
// Admin starts transfer to `bob` and `bob` accepts.
|
|
366
|
-
|
|
370
|
+
accessControl.beginDefaultAdminTransfer(bob);
|
|
367
371
|
vm.prank(bob);
|
|
368
|
-
|
|
372
|
+
accessControl.acceptDefaultAdminTransfer();
|
|
369
373
|
|
|
370
|
-
assertTrue(
|
|
371
|
-
assertFalse(
|
|
372
|
-
assertEq(
|
|
374
|
+
assertTrue(accessControl.hasRole(defaultAdminRole, bob));
|
|
375
|
+
assertFalse(accessControl.hasRole(defaultAdminRole, initialAdmin));
|
|
376
|
+
assertEq(accessControl.getRoleMemberCount(defaultAdminRole), 1);
|
|
373
377
|
}
|
|
374
378
|
}
|
|
@@ -6,14 +6,7 @@ import { TransparentUpgradeableProxy } from "@openzeppelin/contracts/proxy/trans
|
|
|
6
6
|
import { Test } from "forge-std/Test.sol";
|
|
7
7
|
import { AllowlistBaseUpgradeable } from "./../contracts/allowlist/AllowlistBaseUpgradeable.sol";
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
function setAllowlistMode(AllowlistMode _mode) external;
|
|
11
|
-
function setWhitelisted(SetAllowlistParam[] calldata _params) external;
|
|
12
|
-
function setBlacklisted(SetAllowlistParam[] calldata _params) external;
|
|
13
|
-
function restrictedFunction() external view returns (bool);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
contract AllowlistBaseUpgradeableMock is AllowlistBaseUpgradeable {
|
|
9
|
+
contract AllowlistBaseUpgradeableHarness is AllowlistBaseUpgradeable {
|
|
17
10
|
constructor() {
|
|
18
11
|
_disableInitializers();
|
|
19
12
|
}
|
|
@@ -40,24 +33,26 @@ contract AllowlistBaseUpgradeableMock is AllowlistBaseUpgradeable {
|
|
|
40
33
|
}
|
|
41
34
|
|
|
42
35
|
contract AllowlistBaseUpgradeableTest is Test {
|
|
43
|
-
|
|
36
|
+
AllowlistBaseUpgradeableHarness allowlist;
|
|
44
37
|
|
|
45
38
|
address alice = makeAddr("alice");
|
|
46
39
|
address bob = makeAddr("bob");
|
|
47
40
|
address charlie = makeAddr("charlie");
|
|
48
41
|
|
|
49
|
-
function
|
|
50
|
-
|
|
42
|
+
function _deployAllowlist(
|
|
43
|
+
IAllowlist.AllowlistMode _mode
|
|
44
|
+
) internal virtual returns (AllowlistBaseUpgradeableHarness) {
|
|
45
|
+
AllowlistBaseUpgradeableHarness impl = new AllowlistBaseUpgradeableHarness();
|
|
51
46
|
TransparentUpgradeableProxy proxy = new TransparentUpgradeableProxy(
|
|
52
47
|
address(impl),
|
|
53
48
|
address(this),
|
|
54
|
-
abi.encodeWithSelector(
|
|
49
|
+
abi.encodeWithSelector(AllowlistBaseUpgradeableHarness.initialize.selector, _mode)
|
|
55
50
|
);
|
|
56
|
-
return
|
|
51
|
+
return AllowlistBaseUpgradeableHarness(address(proxy));
|
|
57
52
|
}
|
|
58
53
|
|
|
59
54
|
function setUp() public virtual {
|
|
60
|
-
allowlist =
|
|
55
|
+
allowlist = _deployAllowlist(IAllowlist.AllowlistMode.Open);
|
|
61
56
|
}
|
|
62
57
|
|
|
63
58
|
// ============ Initial State Tests ============
|
|
@@ -67,7 +62,7 @@ contract AllowlistBaseUpgradeableTest is Test {
|
|
|
67
62
|
}
|
|
68
63
|
|
|
69
64
|
function test_constructor_InitializeWhitelist() public {
|
|
70
|
-
|
|
65
|
+
AllowlistBaseUpgradeableHarness al = _deployAllowlist(IAllowlist.AllowlistMode.Whitelist);
|
|
71
66
|
assertEq(uint256(al.allowlistMode()), uint256(IAllowlist.AllowlistMode.Whitelist));
|
|
72
67
|
}
|
|
73
68
|
|
|
@@ -5,9 +5,9 @@ import { IAllowlist } from "@layerzerolabs/utils-evm-contracts/contracts/interfa
|
|
|
5
5
|
import { IAccessControl } from "@openzeppelin/contracts/access/IAccessControl.sol";
|
|
6
6
|
import { TransparentUpgradeableProxy } from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
|
|
7
7
|
import { AllowlistRBACUpgradeable } from "./../contracts/allowlist/AllowlistRBACUpgradeable.sol";
|
|
8
|
-
import { AllowlistBaseUpgradeableTest,
|
|
8
|
+
import { AllowlistBaseUpgradeableTest, AllowlistBaseUpgradeableHarness } from "./AllowlistBaseUpgradeable.t.sol";
|
|
9
9
|
|
|
10
|
-
contract
|
|
10
|
+
contract AllowlistRBACUpgradeableHarness is AllowlistRBACUpgradeable {
|
|
11
11
|
constructor() {
|
|
12
12
|
_disableInitializers();
|
|
13
13
|
}
|
|
@@ -24,22 +24,26 @@ contract AllowlistRBACUpgradeableMock is AllowlistRBACUpgradeable {
|
|
|
24
24
|
|
|
25
25
|
contract AllowlistRBACUpgradeableTest is AllowlistBaseUpgradeableTest {
|
|
26
26
|
address dave = makeAddr("dave");
|
|
27
|
+
AllowlistRBACUpgradeableHarness allowlistRbac;
|
|
27
28
|
|
|
28
|
-
function
|
|
29
|
-
|
|
29
|
+
function _deployAllowlist(
|
|
30
|
+
IAllowlist.AllowlistMode _mode
|
|
31
|
+
) internal virtual override returns (AllowlistBaseUpgradeableHarness) {
|
|
32
|
+
AllowlistRBACUpgradeableHarness impl = new AllowlistRBACUpgradeableHarness();
|
|
30
33
|
TransparentUpgradeableProxy proxy = new TransparentUpgradeableProxy(
|
|
31
34
|
address(impl),
|
|
32
35
|
address(this),
|
|
33
|
-
abi.encodeWithSelector(
|
|
36
|
+
abi.encodeWithSelector(AllowlistRBACUpgradeableHarness.initialize.selector, _mode, address(this))
|
|
34
37
|
);
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return
|
|
38
|
+
AllowlistRBACUpgradeableHarness rbac = AllowlistRBACUpgradeableHarness(address(proxy));
|
|
39
|
+
rbac.grantRole(rbac.WHITELISTER_ROLE(), address(this));
|
|
40
|
+
rbac.grantRole(rbac.BLACKLISTER_ROLE(), address(this));
|
|
41
|
+
return AllowlistBaseUpgradeableHarness(address(proxy));
|
|
39
42
|
}
|
|
40
43
|
|
|
41
44
|
function setUp() public override {
|
|
42
|
-
|
|
45
|
+
super.setUp();
|
|
46
|
+
allowlistRbac = AllowlistRBACUpgradeableHarness(address(allowlist));
|
|
43
47
|
}
|
|
44
48
|
|
|
45
49
|
function test_setAllowlistMode_Revert_Unauthorized() public virtual {
|
|
@@ -47,11 +51,11 @@ contract AllowlistRBACUpgradeableTest is AllowlistBaseUpgradeableTest {
|
|
|
47
51
|
abi.encodeWithSelector(
|
|
48
52
|
IAccessControl.AccessControlUnauthorizedAccount.selector,
|
|
49
53
|
dave,
|
|
50
|
-
|
|
54
|
+
allowlistRbac.DEFAULT_ADMIN_ROLE()
|
|
51
55
|
)
|
|
52
56
|
);
|
|
53
57
|
vm.prank(dave);
|
|
54
|
-
|
|
58
|
+
allowlistRbac.setAllowlistMode(IAllowlist.AllowlistMode.Whitelist);
|
|
55
59
|
}
|
|
56
60
|
|
|
57
61
|
function test_setWhitelisted_Revert_Unauthorized() public virtual {
|
|
@@ -61,11 +65,11 @@ contract AllowlistRBACUpgradeableTest is AllowlistBaseUpgradeableTest {
|
|
|
61
65
|
abi.encodeWithSelector(
|
|
62
66
|
IAccessControl.AccessControlUnauthorizedAccount.selector,
|
|
63
67
|
dave,
|
|
64
|
-
|
|
68
|
+
allowlistRbac.WHITELISTER_ROLE()
|
|
65
69
|
)
|
|
66
70
|
);
|
|
67
71
|
vm.prank(dave);
|
|
68
|
-
|
|
72
|
+
allowlistRbac.setWhitelisted(params);
|
|
69
73
|
}
|
|
70
74
|
|
|
71
75
|
function test_setBlacklisted_Revert_Unauthorized() public virtual {
|
|
@@ -75,10 +79,10 @@ contract AllowlistRBACUpgradeableTest is AllowlistBaseUpgradeableTest {
|
|
|
75
79
|
abi.encodeWithSelector(
|
|
76
80
|
IAccessControl.AccessControlUnauthorizedAccount.selector,
|
|
77
81
|
dave,
|
|
78
|
-
|
|
82
|
+
allowlistRbac.BLACKLISTER_ROLE()
|
|
79
83
|
)
|
|
80
84
|
);
|
|
81
85
|
vm.prank(dave);
|
|
82
|
-
|
|
86
|
+
allowlistRbac.setBlacklisted(params);
|
|
83
87
|
}
|
|
84
88
|
}
|