@layerzerolabs/utils-upgradeable-evm-contracts 0.2.74
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 +491 -0
- package/.turbo/turbo-test.log +1356 -0
- package/LICENSE +23 -0
- package/contracts/access/AccessControl2StepUpgradeable.sol +144 -0
- package/contracts/allowlist/AllowlistBaseUpgradeable.sol +184 -0
- package/contracts/allowlist/AllowlistRBACUpgradeable.sol +55 -0
- package/contracts/fee-accounting/FeeHandlerBaseUpgradeable.sol +69 -0
- package/contracts/fee-accounting/FeeHandlerRBACUpgradeable.sol +34 -0
- package/contracts/fee-config/FeeConfigBaseUpgradeable.sol +128 -0
- package/contracts/fee-config/FeeConfigRBACUpgradeable.sol +44 -0
- package/contracts/libs/EnumerableSetPagination.sol +77 -0
- package/contracts/pause/PauseBaseUpgradeable.sol +107 -0
- package/contracts/pause/PauseRBACUpgradeable.sol +47 -0
- package/contracts/pause-by-id/PauseByIDBaseUpgradeable.sol +127 -0
- package/contracts/pause-by-id/PauseByIDRBACUpgradeable.sol +74 -0
- package/contracts/rate-limiter/RateLimiterBaseUpgradeable.sol +636 -0
- package/contracts/rate-limiter/RateLimiterRBACUpgradeable.sol +89 -0
- package/contracts/rate-limiter/libs/RateLimiterUtils.sol +82 -0
- package/foundry.toml +27 -0
- package/package.json +34 -0
- package/solhint.config.js +3 -0
- package/test/AccessControl2StepUpgradeable.t.sol +374 -0
- package/test/AllowlistBaseUpgradeable.t.sol +380 -0
- package/test/AllowlistRBACUpgradeable.t.sol +84 -0
- package/test/EnumerableSetPagination.t.sol +445 -0
- package/test/FeeConfigBaseUpgradeable.t.sol +232 -0
- package/test/FeeConfigRBACUpgradeable.t.sol +59 -0
- package/test/FeeHandlerBaseUpgradeable.t.sol +78 -0
- package/test/FeeHandlerRBACUpgradeable.t.sol +45 -0
- package/test/PauseBaseUpgradeable.t.sol +244 -0
- package/test/PauseByIDBaseUpgradeable.t.sol +337 -0
- package/test/PauseByIDRBACUpgradeable.t.sol +414 -0
- package/test/PauseRBACUpgradeable.t.sol +258 -0
- package/test/RateLimiterBaseUpgradeable.t.sol +826 -0
- package/test/RateLimiterRBACUpgradeable.t.sol +128 -0
- package/test/RateLimiterRBACUpgradeableInvariant.t.sol +444 -0
- package/test/RateLimiterUtils.t.sol +137 -0
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.22;
|
|
3
|
+
|
|
4
|
+
import { IAllowlist } from "@layerzerolabs/utils-evm-contracts/contracts/interfaces/IAllowlist.sol";
|
|
5
|
+
import { TransparentUpgradeableProxy } from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
|
|
6
|
+
import { Test } from "forge-std/Test.sol";
|
|
7
|
+
import { AllowlistBaseUpgradeable } from "./../contracts/allowlist/AllowlistBaseUpgradeable.sol";
|
|
8
|
+
|
|
9
|
+
interface IAllowlistMock is IAllowlist {
|
|
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 {
|
|
17
|
+
constructor() {
|
|
18
|
+
_disableInitializers();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function initialize(AllowlistMode _mode) public initializer {
|
|
22
|
+
__AllowlistBase_init(_mode);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function setAllowlistMode(AllowlistMode _mode) public {
|
|
26
|
+
_setAllowlistMode(_mode);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function setWhitelisted(IAllowlist.SetAllowlistParam[] calldata _params) public {
|
|
30
|
+
_setWhitelisted(_params);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function setBlacklisted(IAllowlist.SetAllowlistParam[] calldata _params) public {
|
|
34
|
+
_setBlacklisted(_params);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function restrictedFunction() external view onlyAllowlisted(msg.sender) returns (bool) {
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
contract AllowlistBaseUpgradeableTest is Test {
|
|
43
|
+
IAllowlistMock allowlist;
|
|
44
|
+
|
|
45
|
+
address alice = makeAddr("alice");
|
|
46
|
+
address bob = makeAddr("bob");
|
|
47
|
+
address charlie = makeAddr("charlie");
|
|
48
|
+
|
|
49
|
+
function _createAllowlist(IAllowlist.AllowlistMode _mode) internal virtual returns (IAllowlistMock) {
|
|
50
|
+
AllowlistBaseUpgradeableMock impl = new AllowlistBaseUpgradeableMock();
|
|
51
|
+
TransparentUpgradeableProxy proxy = new TransparentUpgradeableProxy(
|
|
52
|
+
address(impl),
|
|
53
|
+
address(this),
|
|
54
|
+
abi.encodeWithSelector(AllowlistBaseUpgradeableMock.initialize.selector, _mode)
|
|
55
|
+
);
|
|
56
|
+
return IAllowlistMock(address(proxy));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function setUp() public virtual {
|
|
60
|
+
allowlist = _createAllowlist(IAllowlist.AllowlistMode.Open);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// ============ Initial State Tests ============
|
|
64
|
+
|
|
65
|
+
function test_constructor_InitialMode() public view {
|
|
66
|
+
assertEq(uint256(allowlist.allowlistMode()), uint256(IAllowlist.AllowlistMode.Open));
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function test_constructor_InitializeWhitelist() public {
|
|
70
|
+
IAllowlistMock al = _createAllowlist(IAllowlist.AllowlistMode.Whitelist);
|
|
71
|
+
assertEq(uint256(al.allowlistMode()), uint256(IAllowlist.AllowlistMode.Whitelist));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// ============ Open Mode Tests ============
|
|
75
|
+
|
|
76
|
+
function test_isAllowlisted_Open_AllAllowed() public view {
|
|
77
|
+
assertTrue(allowlist.isAllowlisted(alice));
|
|
78
|
+
assertTrue(allowlist.isAllowlisted(bob));
|
|
79
|
+
assertTrue(allowlist.isAllowlisted(charlie));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function test_onlyAllowlisted_Open_AllAllowed() public {
|
|
83
|
+
vm.prank(alice);
|
|
84
|
+
assertTrue(allowlist.restrictedFunction());
|
|
85
|
+
|
|
86
|
+
vm.prank(bob);
|
|
87
|
+
assertTrue(allowlist.restrictedFunction());
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// ============ Blacklist Mode Tests ============
|
|
91
|
+
|
|
92
|
+
function test_setMode_Blacklist() public {
|
|
93
|
+
vm.expectEmit(true, true, true, true);
|
|
94
|
+
emit IAllowlist.AllowlistModeUpdated(IAllowlist.AllowlistMode.Blacklist);
|
|
95
|
+
allowlist.setAllowlistMode(IAllowlist.AllowlistMode.Blacklist);
|
|
96
|
+
|
|
97
|
+
assertEq(uint256(allowlist.allowlistMode()), uint256(IAllowlist.AllowlistMode.Blacklist));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function test_isAllowlisted_Blacklist_NotBlacklisted() public {
|
|
101
|
+
allowlist.setAllowlistMode(IAllowlist.AllowlistMode.Blacklist);
|
|
102
|
+
assertTrue(allowlist.isAllowlisted(alice));
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function test_isAllowlisted_Blacklist_Blacklisted() public {
|
|
106
|
+
allowlist.setAllowlistMode(IAllowlist.AllowlistMode.Blacklist);
|
|
107
|
+
|
|
108
|
+
IAllowlist.SetAllowlistParam[] memory params = new IAllowlist.SetAllowlistParam[](1);
|
|
109
|
+
params[0] = IAllowlist.SetAllowlistParam(alice, true);
|
|
110
|
+
|
|
111
|
+
vm.expectEmit(true, true, true, true);
|
|
112
|
+
emit IAllowlist.BlacklistUpdated(alice, true);
|
|
113
|
+
allowlist.setBlacklisted(params);
|
|
114
|
+
|
|
115
|
+
assertFalse(allowlist.isAllowlisted(alice));
|
|
116
|
+
assertTrue(allowlist.isBlacklisted(alice));
|
|
117
|
+
assertTrue(allowlist.isAllowlisted(bob));
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function test_onlyAllowlisted_Blacklist_RevertIfBlacklisted() public {
|
|
121
|
+
allowlist.setAllowlistMode(IAllowlist.AllowlistMode.Blacklist);
|
|
122
|
+
|
|
123
|
+
IAllowlist.SetAllowlistParam[] memory params = new IAllowlist.SetAllowlistParam[](1);
|
|
124
|
+
params[0] = IAllowlist.SetAllowlistParam(alice, true);
|
|
125
|
+
allowlist.setBlacklisted(params);
|
|
126
|
+
|
|
127
|
+
vm.startPrank(alice);
|
|
128
|
+
vm.expectRevert(
|
|
129
|
+
abi.encodeWithSelector(IAllowlist.NotAllowlisted.selector, alice, IAllowlist.AllowlistMode.Blacklist)
|
|
130
|
+
);
|
|
131
|
+
allowlist.restrictedFunction();
|
|
132
|
+
vm.stopPrank();
|
|
133
|
+
|
|
134
|
+
vm.prank(bob);
|
|
135
|
+
assertTrue(allowlist.restrictedFunction());
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function test_setBlacklisted_RemoveFromBlacklist() public {
|
|
139
|
+
allowlist.setAllowlistMode(IAllowlist.AllowlistMode.Blacklist);
|
|
140
|
+
|
|
141
|
+
IAllowlist.SetAllowlistParam[] memory params = new IAllowlist.SetAllowlistParam[](1);
|
|
142
|
+
params[0] = IAllowlist.SetAllowlistParam(alice, true);
|
|
143
|
+
allowlist.setBlacklisted(params);
|
|
144
|
+
assertFalse(allowlist.isAllowlisted(alice));
|
|
145
|
+
|
|
146
|
+
vm.expectEmit(true, true, true, true);
|
|
147
|
+
emit IAllowlist.BlacklistUpdated(alice, false);
|
|
148
|
+
params[0] = IAllowlist.SetAllowlistParam(alice, false);
|
|
149
|
+
allowlist.setBlacklisted(params);
|
|
150
|
+
|
|
151
|
+
assertTrue(allowlist.isAllowlisted(alice));
|
|
152
|
+
assertFalse(allowlist.isBlacklisted(alice));
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function test_setBlacklisted_MultipleUsers() public {
|
|
156
|
+
allowlist.setAllowlistMode(IAllowlist.AllowlistMode.Blacklist);
|
|
157
|
+
|
|
158
|
+
IAllowlist.SetAllowlistParam[] memory params = new IAllowlist.SetAllowlistParam[](2);
|
|
159
|
+
params[0] = IAllowlist.SetAllowlistParam(alice, true);
|
|
160
|
+
params[1] = IAllowlist.SetAllowlistParam(bob, true);
|
|
161
|
+
allowlist.setBlacklisted(params);
|
|
162
|
+
|
|
163
|
+
assertFalse(allowlist.isAllowlisted(alice));
|
|
164
|
+
assertFalse(allowlist.isAllowlisted(bob));
|
|
165
|
+
assertTrue(allowlist.isBlacklisted(alice));
|
|
166
|
+
assertTrue(allowlist.isBlacklisted(bob));
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// ============ Whitelist Mode Tests ============
|
|
170
|
+
|
|
171
|
+
function test_setMode_Whitelist() public {
|
|
172
|
+
vm.expectEmit(true, true, true, true);
|
|
173
|
+
emit IAllowlist.AllowlistModeUpdated(IAllowlist.AllowlistMode.Whitelist);
|
|
174
|
+
allowlist.setAllowlistMode(IAllowlist.AllowlistMode.Whitelist);
|
|
175
|
+
|
|
176
|
+
assertEq(uint256(allowlist.allowlistMode()), uint256(IAllowlist.AllowlistMode.Whitelist));
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function test_isAllowlisted_Whitelist_NotWhitelisted() public {
|
|
180
|
+
allowlist.setAllowlistMode(IAllowlist.AllowlistMode.Whitelist);
|
|
181
|
+
assertFalse(allowlist.isAllowlisted(alice));
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function test_isAllowlisted_Whitelist_Whitelisted() public {
|
|
185
|
+
allowlist.setAllowlistMode(IAllowlist.AllowlistMode.Whitelist);
|
|
186
|
+
|
|
187
|
+
IAllowlist.SetAllowlistParam[] memory params = new IAllowlist.SetAllowlistParam[](1);
|
|
188
|
+
params[0] = IAllowlist.SetAllowlistParam(alice, true);
|
|
189
|
+
|
|
190
|
+
vm.expectEmit(true, true, true, true);
|
|
191
|
+
emit IAllowlist.WhitelistUpdated(alice, true);
|
|
192
|
+
allowlist.setWhitelisted(params);
|
|
193
|
+
|
|
194
|
+
assertTrue(allowlist.isAllowlisted(alice));
|
|
195
|
+
assertTrue(allowlist.isWhitelisted(alice));
|
|
196
|
+
assertFalse(allowlist.isAllowlisted(bob));
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function test_onlyAllowlisted_Whitelist_RevertIfNotWhitelisted() public {
|
|
200
|
+
allowlist.setAllowlistMode(IAllowlist.AllowlistMode.Whitelist);
|
|
201
|
+
|
|
202
|
+
vm.startPrank(alice);
|
|
203
|
+
vm.expectRevert(
|
|
204
|
+
abi.encodeWithSelector(IAllowlist.NotAllowlisted.selector, alice, IAllowlist.AllowlistMode.Whitelist)
|
|
205
|
+
);
|
|
206
|
+
allowlist.restrictedFunction();
|
|
207
|
+
vm.stopPrank();
|
|
208
|
+
|
|
209
|
+
IAllowlist.SetAllowlistParam[] memory params = new IAllowlist.SetAllowlistParam[](1);
|
|
210
|
+
params[0] = IAllowlist.SetAllowlistParam(alice, true);
|
|
211
|
+
allowlist.setWhitelisted(params);
|
|
212
|
+
|
|
213
|
+
vm.prank(alice);
|
|
214
|
+
assertTrue(allowlist.restrictedFunction());
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function test_setWhitelisted_RemoveFromWhitelist() public {
|
|
218
|
+
allowlist.setAllowlistMode(IAllowlist.AllowlistMode.Whitelist);
|
|
219
|
+
|
|
220
|
+
IAllowlist.SetAllowlistParam[] memory params = new IAllowlist.SetAllowlistParam[](1);
|
|
221
|
+
params[0] = IAllowlist.SetAllowlistParam(alice, true);
|
|
222
|
+
allowlist.setWhitelisted(params);
|
|
223
|
+
assertTrue(allowlist.isAllowlisted(alice));
|
|
224
|
+
|
|
225
|
+
vm.expectEmit(true, true, true, true);
|
|
226
|
+
emit IAllowlist.WhitelistUpdated(alice, false);
|
|
227
|
+
params[0] = IAllowlist.SetAllowlistParam(alice, false);
|
|
228
|
+
allowlist.setWhitelisted(params);
|
|
229
|
+
|
|
230
|
+
assertFalse(allowlist.isAllowlisted(alice));
|
|
231
|
+
assertFalse(allowlist.isWhitelisted(alice));
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function test_setWhitelisted_MultipleUsers() public {
|
|
235
|
+
allowlist.setAllowlistMode(IAllowlist.AllowlistMode.Whitelist);
|
|
236
|
+
|
|
237
|
+
IAllowlist.SetAllowlistParam[] memory params = new IAllowlist.SetAllowlistParam[](2);
|
|
238
|
+
params[0] = IAllowlist.SetAllowlistParam(alice, true);
|
|
239
|
+
params[1] = IAllowlist.SetAllowlistParam(bob, true);
|
|
240
|
+
allowlist.setWhitelisted(params);
|
|
241
|
+
|
|
242
|
+
assertTrue(allowlist.isAllowlisted(alice));
|
|
243
|
+
assertTrue(allowlist.isAllowlisted(bob));
|
|
244
|
+
assertTrue(allowlist.isWhitelisted(alice));
|
|
245
|
+
assertTrue(allowlist.isWhitelisted(bob));
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// ============ Integration & Edge Tests ============
|
|
249
|
+
|
|
250
|
+
function test_SwitchModes_PreservesState() public {
|
|
251
|
+
allowlist.setAllowlistMode(IAllowlist.AllowlistMode.Whitelist);
|
|
252
|
+
IAllowlist.SetAllowlistParam[] memory aParams = new IAllowlist.SetAllowlistParam[](1);
|
|
253
|
+
aParams[0] = IAllowlist.SetAllowlistParam(alice, true);
|
|
254
|
+
allowlist.setWhitelisted(aParams);
|
|
255
|
+
assertTrue(allowlist.isAllowlisted(alice));
|
|
256
|
+
|
|
257
|
+
IAllowlist.SetAllowlistParam[] memory bParams = new IAllowlist.SetAllowlistParam[](1);
|
|
258
|
+
bParams[0] = IAllowlist.SetAllowlistParam(bob, true);
|
|
259
|
+
allowlist.setBlacklisted(bParams);
|
|
260
|
+
|
|
261
|
+
// `bob` is not allowlisted in Whitelist mode because he is not whitelisted.
|
|
262
|
+
assertFalse(allowlist.isAllowlisted(bob));
|
|
263
|
+
|
|
264
|
+
allowlist.setAllowlistMode(IAllowlist.AllowlistMode.Blacklist);
|
|
265
|
+
|
|
266
|
+
assertTrue(allowlist.isAllowlisted(alice));
|
|
267
|
+
assertFalse(allowlist.isAllowlisted(bob));
|
|
268
|
+
|
|
269
|
+
allowlist.setAllowlistMode(IAllowlist.AllowlistMode.Open);
|
|
270
|
+
|
|
271
|
+
assertTrue(allowlist.isAllowlisted(alice));
|
|
272
|
+
assertTrue(allowlist.isAllowlisted(bob));
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
function test_setWhitelisted_EmptyArray() public {
|
|
276
|
+
IAllowlist.SetAllowlistParam[] memory params = new IAllowlist.SetAllowlistParam[](0);
|
|
277
|
+
allowlist.setWhitelisted(params);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
function test_setBlacklisted_EmptyArray() public {
|
|
281
|
+
IAllowlist.SetAllowlistParam[] memory params = new IAllowlist.SetAllowlistParam[](0);
|
|
282
|
+
allowlist.setBlacklisted(params);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
function test_setMode_MultipleChanges() public {
|
|
286
|
+
assertEq(uint256(allowlist.allowlistMode()), uint256(IAllowlist.AllowlistMode.Open));
|
|
287
|
+
|
|
288
|
+
allowlist.setAllowlistMode(IAllowlist.AllowlistMode.Blacklist);
|
|
289
|
+
assertEq(uint256(allowlist.allowlistMode()), uint256(IAllowlist.AllowlistMode.Blacklist));
|
|
290
|
+
|
|
291
|
+
allowlist.setAllowlistMode(IAllowlist.AllowlistMode.Whitelist);
|
|
292
|
+
assertEq(uint256(allowlist.allowlistMode()), uint256(IAllowlist.AllowlistMode.Whitelist));
|
|
293
|
+
|
|
294
|
+
allowlist.setAllowlistMode(IAllowlist.AllowlistMode.Blacklist);
|
|
295
|
+
assertEq(uint256(allowlist.allowlistMode()), uint256(IAllowlist.AllowlistMode.Blacklist));
|
|
296
|
+
|
|
297
|
+
allowlist.setAllowlistMode(IAllowlist.AllowlistMode.Open);
|
|
298
|
+
assertEq(uint256(allowlist.allowlistMode()), uint256(IAllowlist.AllowlistMode.Open));
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
function test_setMode_RevertSameMode() public {
|
|
302
|
+
assertEq(uint256(allowlist.allowlistMode()), uint256(IAllowlist.AllowlistMode.Open));
|
|
303
|
+
vm.expectRevert(abi.encodeWithSelector(IAllowlist.ModeAlreadySet.selector, IAllowlist.AllowlistMode.Open));
|
|
304
|
+
allowlist.setAllowlistMode(IAllowlist.AllowlistMode.Open);
|
|
305
|
+
|
|
306
|
+
allowlist.setAllowlistMode(IAllowlist.AllowlistMode.Blacklist);
|
|
307
|
+
assertEq(uint256(allowlist.allowlistMode()), uint256(IAllowlist.AllowlistMode.Blacklist));
|
|
308
|
+
|
|
309
|
+
vm.expectRevert(abi.encodeWithSelector(IAllowlist.ModeAlreadySet.selector, IAllowlist.AllowlistMode.Blacklist));
|
|
310
|
+
allowlist.setAllowlistMode(IAllowlist.AllowlistMode.Blacklist);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
function test_setWhitelisted_Revert_AlreadyWhitelisted() public {
|
|
314
|
+
allowlist.setAllowlistMode(IAllowlist.AllowlistMode.Whitelist);
|
|
315
|
+
|
|
316
|
+
IAllowlist.SetAllowlistParam[] memory params = new IAllowlist.SetAllowlistParam[](1);
|
|
317
|
+
params[0] = IAllowlist.SetAllowlistParam(alice, true);
|
|
318
|
+
allowlist.setWhitelisted(params);
|
|
319
|
+
assertTrue(allowlist.isWhitelisted(alice));
|
|
320
|
+
assertEq(allowlist.whitelistedCount(), 1);
|
|
321
|
+
|
|
322
|
+
vm.expectRevert(abi.encodeWithSelector(IAllowlist.AllowlistStateIdempotent.selector, alice, true));
|
|
323
|
+
allowlist.setWhitelisted(params);
|
|
324
|
+
|
|
325
|
+
assertEq(allowlist.whitelistedCount(), 1);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
function test_setBlacklisted_Revert_AlreadyBlacklisted() public {
|
|
329
|
+
allowlist.setAllowlistMode(IAllowlist.AllowlistMode.Blacklist);
|
|
330
|
+
|
|
331
|
+
IAllowlist.SetAllowlistParam[] memory params = new IAllowlist.SetAllowlistParam[](1);
|
|
332
|
+
params[0] = IAllowlist.SetAllowlistParam(alice, true);
|
|
333
|
+
allowlist.setBlacklisted(params);
|
|
334
|
+
assertTrue(allowlist.isBlacklisted(alice));
|
|
335
|
+
assertEq(allowlist.blacklistedCount(), 1);
|
|
336
|
+
|
|
337
|
+
vm.expectRevert(abi.encodeWithSelector(IAllowlist.AllowlistStateIdempotent.selector, alice, true));
|
|
338
|
+
allowlist.setBlacklisted(params);
|
|
339
|
+
|
|
340
|
+
assertEq(allowlist.blacklistedCount(), 1);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
// ============ Fuzz Tests ============
|
|
344
|
+
|
|
345
|
+
function test_isAllowlisted_Fuzz_Open(address _user) public view {
|
|
346
|
+
assertTrue(allowlist.isAllowlisted(_user));
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
function test_isAllowlisted_Fuzz_Blacklist_NotBlacklisted(address _user) public {
|
|
350
|
+
allowlist.setAllowlistMode(IAllowlist.AllowlistMode.Blacklist);
|
|
351
|
+
assertTrue(allowlist.isAllowlisted(_user));
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
function test_isAllowlisted_Fuzz_Blacklist_Blacklisted(address _user) public {
|
|
355
|
+
allowlist.setAllowlistMode(IAllowlist.AllowlistMode.Blacklist);
|
|
356
|
+
IAllowlist.SetAllowlistParam[] memory params = new IAllowlist.SetAllowlistParam[](1);
|
|
357
|
+
params[0] = IAllowlist.SetAllowlistParam(_user, true);
|
|
358
|
+
allowlist.setBlacklisted(params);
|
|
359
|
+
assertFalse(allowlist.isAllowlisted(_user));
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
function test_isAllowlisted_Fuzz_Whitelist_NotWhitelisted(address _user) public {
|
|
363
|
+
allowlist.setAllowlistMode(IAllowlist.AllowlistMode.Whitelist);
|
|
364
|
+
assertFalse(allowlist.isAllowlisted(_user));
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
function test_isAllowlisted_Fuzz_Whitelist_Whitelisted(address _user) public {
|
|
368
|
+
allowlist.setAllowlistMode(IAllowlist.AllowlistMode.Whitelist);
|
|
369
|
+
IAllowlist.SetAllowlistParam[] memory params = new IAllowlist.SetAllowlistParam[](1);
|
|
370
|
+
params[0] = IAllowlist.SetAllowlistParam(_user, true);
|
|
371
|
+
allowlist.setWhitelisted(params);
|
|
372
|
+
assertTrue(allowlist.isAllowlisted(_user));
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
function test_storageHash() public pure {
|
|
376
|
+
bytes32 storageHash = keccak256(abi.encode(uint256(keccak256("layerzerov2.storage.allowlist")) - 1)) &
|
|
377
|
+
~bytes32(uint256(0xff));
|
|
378
|
+
assertEq(storageHash, 0xa9f917c522fb3fd8673bbc655e92a5c1f1ee3df7bf7ad06a1821b937d0205e00);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.22;
|
|
3
|
+
|
|
4
|
+
import { IAllowlist } from "@layerzerolabs/utils-evm-contracts/contracts/interfaces/IAllowlist.sol";
|
|
5
|
+
import { IAccessControl } from "@openzeppelin/contracts/access/IAccessControl.sol";
|
|
6
|
+
import { TransparentUpgradeableProxy } from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
|
|
7
|
+
import { AllowlistRBACUpgradeable } from "./../contracts/allowlist/AllowlistRBACUpgradeable.sol";
|
|
8
|
+
import { AllowlistBaseUpgradeableTest, IAllowlistMock } from "./AllowlistBaseUpgradeable.t.sol";
|
|
9
|
+
|
|
10
|
+
contract AllowlistRBACUpgradeableMock is AllowlistRBACUpgradeable {
|
|
11
|
+
constructor() {
|
|
12
|
+
_disableInitializers();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function initialize(AllowlistMode _mode, address _initialAdmin) public initializer {
|
|
16
|
+
__AccessControl2Step_init(_initialAdmin);
|
|
17
|
+
__AllowlistBase_init(_mode);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function restrictedFunction() external view onlyAllowlisted(msg.sender) returns (bool) {
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
contract AllowlistRBACUpgradeableTest is AllowlistBaseUpgradeableTest {
|
|
26
|
+
address dave = makeAddr("dave");
|
|
27
|
+
|
|
28
|
+
function _createAllowlist(IAllowlist.AllowlistMode _mode) internal virtual override returns (IAllowlistMock) {
|
|
29
|
+
AllowlistRBACUpgradeableMock impl = new AllowlistRBACUpgradeableMock();
|
|
30
|
+
TransparentUpgradeableProxy proxy = new TransparentUpgradeableProxy(
|
|
31
|
+
address(impl),
|
|
32
|
+
address(this),
|
|
33
|
+
abi.encodeWithSelector(AllowlistRBACUpgradeableMock.initialize.selector, _mode, address(this))
|
|
34
|
+
);
|
|
35
|
+
AllowlistRBACUpgradeableMock _allowlist = AllowlistRBACUpgradeableMock(address(proxy));
|
|
36
|
+
_allowlist.grantRole(_allowlist.WHITELISTER_ROLE(), address(this));
|
|
37
|
+
_allowlist.grantRole(_allowlist.BLACKLISTER_ROLE(), address(this));
|
|
38
|
+
return IAllowlistMock(address(proxy));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function setUp() public override {
|
|
42
|
+
allowlist = _createAllowlist(IAllowlist.AllowlistMode.Open);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function test_setAllowlistMode_Revert_Unauthorized() public virtual {
|
|
46
|
+
vm.expectRevert(
|
|
47
|
+
abi.encodeWithSelector(
|
|
48
|
+
IAccessControl.AccessControlUnauthorizedAccount.selector,
|
|
49
|
+
dave,
|
|
50
|
+
AllowlistRBACUpgradeableMock(address(allowlist)).DEFAULT_ADMIN_ROLE()
|
|
51
|
+
)
|
|
52
|
+
);
|
|
53
|
+
vm.prank(dave);
|
|
54
|
+
AllowlistRBACUpgradeableMock(address(allowlist)).setAllowlistMode(IAllowlist.AllowlistMode.Whitelist);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function test_setWhitelisted_Revert_Unauthorized() public virtual {
|
|
58
|
+
IAllowlist.SetAllowlistParam[] memory params = new IAllowlist.SetAllowlistParam[](1);
|
|
59
|
+
params[0] = IAllowlist.SetAllowlistParam({ user: alice, isEnabled: true });
|
|
60
|
+
vm.expectRevert(
|
|
61
|
+
abi.encodeWithSelector(
|
|
62
|
+
IAccessControl.AccessControlUnauthorizedAccount.selector,
|
|
63
|
+
dave,
|
|
64
|
+
AllowlistRBACUpgradeableMock(address(allowlist)).WHITELISTER_ROLE()
|
|
65
|
+
)
|
|
66
|
+
);
|
|
67
|
+
vm.prank(dave);
|
|
68
|
+
AllowlistRBACUpgradeableMock(address(allowlist)).setWhitelisted(params);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function test_setBlacklisted_Revert_Unauthorized() public virtual {
|
|
72
|
+
IAllowlist.SetAllowlistParam[] memory params = new IAllowlist.SetAllowlistParam[](1);
|
|
73
|
+
params[0] = IAllowlist.SetAllowlistParam({ user: alice, isEnabled: true });
|
|
74
|
+
vm.expectRevert(
|
|
75
|
+
abi.encodeWithSelector(
|
|
76
|
+
IAccessControl.AccessControlUnauthorizedAccount.selector,
|
|
77
|
+
dave,
|
|
78
|
+
AllowlistRBACUpgradeableMock(address(allowlist)).BLACKLISTER_ROLE()
|
|
79
|
+
)
|
|
80
|
+
);
|
|
81
|
+
vm.prank(dave);
|
|
82
|
+
AllowlistRBACUpgradeableMock(address(allowlist)).setBlacklisted(params);
|
|
83
|
+
}
|
|
84
|
+
}
|