@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
|
@@ -6,9 +6,9 @@ import { Initializable } from "@openzeppelin/contracts-upgradeable/proxy/utils/I
|
|
|
6
6
|
import { IAccessControl } from "@openzeppelin/contracts/access/IAccessControl.sol";
|
|
7
7
|
import { TransparentUpgradeableProxy } from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
|
|
8
8
|
import { PauseRBACUpgradeable } from "./../contracts/pause/PauseRBACUpgradeable.sol";
|
|
9
|
-
import { PauseBaseUpgradeableTest,
|
|
9
|
+
import { PauseBaseUpgradeableTest, PauseBaseUpgradeableHarness } from "./PauseBaseUpgradeable.t.sol";
|
|
10
10
|
|
|
11
|
-
contract
|
|
11
|
+
contract PauseRBACUpgradeableHarness is PauseRBACUpgradeable {
|
|
12
12
|
uint256 public callCount;
|
|
13
13
|
|
|
14
14
|
constructor() {
|
|
@@ -35,17 +35,18 @@ contract PauseRBACUpgradeableMock is PauseRBACUpgradeable {
|
|
|
35
35
|
contract PauseRBACUpgradeableTest is PauseBaseUpgradeableTest {
|
|
36
36
|
address alice = makeAddr("alice");
|
|
37
37
|
address proxyAdmin;
|
|
38
|
+
PauseRBACUpgradeableHarness pauseRbac;
|
|
38
39
|
|
|
39
40
|
/**
|
|
40
|
-
* @dev Override parent test since `
|
|
41
|
+
* @dev Override parent test since `PauseRBACUpgradeableHarness.initialize(address)` has a different signature.
|
|
41
42
|
*/
|
|
42
43
|
function test_initialize_Revert_AlreadyInitialized() public override {
|
|
43
44
|
vm.expectRevert(Initializable.InvalidInitialization.selector);
|
|
44
|
-
|
|
45
|
+
pauseRbac.initialize(address(0x999));
|
|
45
46
|
}
|
|
46
47
|
|
|
47
|
-
function
|
|
48
|
-
|
|
48
|
+
function _deployPause() internal virtual override returns (PauseBaseUpgradeableHarness) {
|
|
49
|
+
PauseRBACUpgradeableHarness impl = new PauseRBACUpgradeableHarness();
|
|
49
50
|
|
|
50
51
|
uint256 currentNonce = vm.getNonce(address(this));
|
|
51
52
|
proxyAdmin = vm.computeCreateAddress(vm.computeCreateAddress(address(this), currentNonce), 1);
|
|
@@ -53,18 +54,17 @@ contract PauseRBACUpgradeableTest is PauseBaseUpgradeableTest {
|
|
|
53
54
|
TransparentUpgradeableProxy proxy = new TransparentUpgradeableProxy(
|
|
54
55
|
address(impl),
|
|
55
56
|
address(this),
|
|
56
|
-
abi.encodeWithSelector(
|
|
57
|
+
abi.encodeWithSelector(PauseRBACUpgradeableHarness.initialize.selector, address(this))
|
|
57
58
|
);
|
|
58
|
-
|
|
59
|
+
pauseRbac = PauseRBACUpgradeableHarness(address(proxy));
|
|
60
|
+
return PauseBaseUpgradeableHarness(address(proxy));
|
|
61
|
+
}
|
|
59
62
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
PauseRBACUpgradeableMock(address(pauseHelper)).UNPAUSER_ROLE(),
|
|
66
|
-
address(this)
|
|
67
|
-
);
|
|
63
|
+
function setUp() public override {
|
|
64
|
+
super.setUp();
|
|
65
|
+
|
|
66
|
+
pauseRbac.grantRole(pauseRbac.PAUSER_ROLE(), address(this));
|
|
67
|
+
pauseRbac.grantRole(pauseRbac.UNPAUSER_ROLE(), address(this));
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
function test_setPaused_Revert_Unauthorized() public {
|
|
@@ -72,75 +72,63 @@ contract PauseRBACUpgradeableTest is PauseBaseUpgradeableTest {
|
|
|
72
72
|
abi.encodeWithSelector(
|
|
73
73
|
IAccessControl.AccessControlUnauthorizedAccount.selector,
|
|
74
74
|
alice,
|
|
75
|
-
|
|
75
|
+
pauseRbac.PAUSER_ROLE()
|
|
76
76
|
)
|
|
77
77
|
);
|
|
78
78
|
vm.prank(alice);
|
|
79
|
-
|
|
79
|
+
pauseRbac.pause();
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
function test_setPaused_Success() public {
|
|
83
|
-
|
|
84
|
-
assertTrue(
|
|
83
|
+
pauseRbac.pause();
|
|
84
|
+
assertTrue(pause.isPaused());
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
function test_roleTransfer_GrantAndRevoke() public {
|
|
88
88
|
address newAdmin = address(0x123);
|
|
89
89
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
newAdmin
|
|
93
|
-
);
|
|
94
|
-
PauseRBACUpgradeableMock(address(pauseHelper)).grantRole(
|
|
95
|
-
PauseRBACUpgradeableMock(address(pauseHelper)).UNPAUSER_ROLE(),
|
|
96
|
-
newAdmin
|
|
97
|
-
);
|
|
90
|
+
pauseRbac.grantRole(pauseRbac.PAUSER_ROLE(), newAdmin);
|
|
91
|
+
pauseRbac.grantRole(pauseRbac.UNPAUSER_ROLE(), newAdmin);
|
|
98
92
|
|
|
99
|
-
|
|
93
|
+
pauseRbac.pause();
|
|
100
94
|
|
|
101
95
|
vm.prank(newAdmin);
|
|
102
|
-
|
|
103
|
-
assertFalse(
|
|
96
|
+
pauseRbac.unpause();
|
|
97
|
+
assertFalse(pause.isPaused());
|
|
104
98
|
|
|
105
|
-
|
|
106
|
-
PauseRBACUpgradeableMock(address(pauseHelper)).PAUSER_ROLE(),
|
|
107
|
-
address(this)
|
|
108
|
-
);
|
|
99
|
+
pauseRbac.revokeRole(pauseRbac.PAUSER_ROLE(), address(this));
|
|
109
100
|
|
|
110
101
|
vm.expectRevert(
|
|
111
102
|
abi.encodeWithSelector(
|
|
112
103
|
IAccessControl.AccessControlUnauthorizedAccount.selector,
|
|
113
104
|
address(this),
|
|
114
|
-
|
|
105
|
+
pauseRbac.PAUSER_ROLE()
|
|
115
106
|
)
|
|
116
107
|
);
|
|
117
|
-
|
|
108
|
+
pauseRbac.pause();
|
|
118
109
|
}
|
|
119
110
|
|
|
120
111
|
function test_renounceRole_Success_FunctionsRevert() public {
|
|
121
|
-
|
|
122
|
-
PauseRBACUpgradeableMock(address(pauseHelper)).PAUSER_ROLE(),
|
|
123
|
-
address(this)
|
|
124
|
-
);
|
|
112
|
+
pauseRbac.renounceRole(pauseRbac.PAUSER_ROLE(), address(this));
|
|
125
113
|
|
|
126
114
|
vm.expectRevert(
|
|
127
115
|
abi.encodeWithSelector(
|
|
128
116
|
IAccessControl.AccessControlUnauthorizedAccount.selector,
|
|
129
117
|
address(this),
|
|
130
|
-
|
|
118
|
+
pauseRbac.PAUSER_ROLE()
|
|
131
119
|
)
|
|
132
120
|
);
|
|
133
|
-
|
|
121
|
+
pauseRbac.pause();
|
|
134
122
|
|
|
135
123
|
vm.expectRevert(
|
|
136
124
|
abi.encodeWithSelector(
|
|
137
125
|
IAccessControl.AccessControlUnauthorizedAccount.selector,
|
|
138
126
|
alice,
|
|
139
|
-
|
|
127
|
+
pauseRbac.PAUSER_ROLE()
|
|
140
128
|
)
|
|
141
129
|
);
|
|
142
130
|
vm.prank(alice);
|
|
143
|
-
|
|
131
|
+
pauseRbac.pause();
|
|
144
132
|
}
|
|
145
133
|
|
|
146
134
|
function test_multipleRoleGrants() public {
|
|
@@ -148,111 +136,91 @@ contract PauseRBACUpgradeableTest is PauseBaseUpgradeableTest {
|
|
|
148
136
|
address admin2 = address(0x222);
|
|
149
137
|
address admin3 = address(0x333);
|
|
150
138
|
|
|
151
|
-
|
|
152
|
-
PauseRBACUpgradeableMock(address(pauseHelper)).PAUSER_ROLE(),
|
|
153
|
-
admin1
|
|
154
|
-
);
|
|
139
|
+
pauseRbac.grantRole(pauseRbac.PAUSER_ROLE(), admin1);
|
|
155
140
|
|
|
156
141
|
vm.prank(admin1);
|
|
157
|
-
|
|
158
|
-
assertTrue(
|
|
142
|
+
pauseRbac.pause();
|
|
143
|
+
assertTrue(pause.isPaused());
|
|
159
144
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
admin2
|
|
163
|
-
);
|
|
164
|
-
PauseRBACUpgradeableMock(address(pauseHelper)).grantRole(
|
|
165
|
-
PauseRBACUpgradeableMock(address(pauseHelper)).UNPAUSER_ROLE(),
|
|
166
|
-
admin2
|
|
167
|
-
);
|
|
145
|
+
pauseRbac.grantRole(pauseRbac.PAUSER_ROLE(), admin2);
|
|
146
|
+
pauseRbac.grantRole(pauseRbac.UNPAUSER_ROLE(), admin2);
|
|
168
147
|
|
|
169
148
|
vm.prank(admin2);
|
|
170
|
-
|
|
171
|
-
assertFalse(
|
|
149
|
+
pauseRbac.unpause();
|
|
150
|
+
assertFalse(pause.isPaused());
|
|
172
151
|
|
|
173
152
|
vm.prank(admin1);
|
|
174
|
-
|
|
175
|
-
assertTrue(
|
|
153
|
+
pauseRbac.pause();
|
|
154
|
+
assertTrue(pause.isPaused());
|
|
176
155
|
|
|
177
|
-
|
|
178
|
-
PauseRBACUpgradeableMock(address(pauseHelper)).PAUSER_ROLE(),
|
|
179
|
-
admin1
|
|
180
|
-
);
|
|
156
|
+
pauseRbac.revokeRole(pauseRbac.PAUSER_ROLE(), admin1);
|
|
181
157
|
|
|
182
158
|
vm.expectRevert(
|
|
183
159
|
abi.encodeWithSelector(
|
|
184
160
|
IAccessControl.AccessControlUnauthorizedAccount.selector,
|
|
185
161
|
admin1,
|
|
186
|
-
|
|
162
|
+
pauseRbac.UNPAUSER_ROLE()
|
|
187
163
|
)
|
|
188
164
|
);
|
|
189
165
|
vm.prank(admin1);
|
|
190
|
-
|
|
166
|
+
pauseRbac.unpause();
|
|
191
167
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
admin3
|
|
195
|
-
);
|
|
196
|
-
PauseRBACUpgradeableMock(address(pauseHelper)).grantRole(
|
|
197
|
-
PauseRBACUpgradeableMock(address(pauseHelper)).UNPAUSER_ROLE(),
|
|
198
|
-
admin3
|
|
199
|
-
);
|
|
168
|
+
pauseRbac.grantRole(pauseRbac.PAUSER_ROLE(), admin3);
|
|
169
|
+
pauseRbac.grantRole(pauseRbac.UNPAUSER_ROLE(), admin3);
|
|
200
170
|
|
|
201
171
|
vm.prank(admin3);
|
|
202
|
-
|
|
203
|
-
assertFalse(
|
|
172
|
+
pauseRbac.unpause();
|
|
173
|
+
assertFalse(pause.isPaused());
|
|
204
174
|
|
|
205
175
|
vm.prank(admin2);
|
|
206
|
-
|
|
207
|
-
assertTrue(
|
|
176
|
+
pauseRbac.pause();
|
|
177
|
+
assertTrue(pause.isPaused());
|
|
208
178
|
}
|
|
209
179
|
|
|
210
180
|
function test_setPaused_Success_MultipleOperations() public {
|
|
211
|
-
|
|
212
|
-
assertTrue(
|
|
181
|
+
pauseRbac.pause();
|
|
182
|
+
assertTrue(pause.isPaused());
|
|
213
183
|
|
|
214
|
-
|
|
215
|
-
assertFalse(
|
|
184
|
+
pauseRbac.unpause();
|
|
185
|
+
assertFalse(pause.isPaused());
|
|
216
186
|
|
|
217
|
-
|
|
218
|
-
assertTrue(
|
|
187
|
+
pauseRbac.pause();
|
|
188
|
+
assertTrue(pause.isPaused());
|
|
219
189
|
|
|
220
|
-
|
|
221
|
-
assertFalse(
|
|
190
|
+
pauseRbac.unpause();
|
|
191
|
+
assertFalse(pause.isPaused());
|
|
222
192
|
}
|
|
223
193
|
|
|
224
194
|
function test_initialize_Revert_AlreadyInitialized_AdminUnchanged() public {
|
|
225
195
|
vm.expectRevert(Initializable.InvalidInitialization.selector);
|
|
226
|
-
|
|
196
|
+
pauseRbac.initialize(address(0x999));
|
|
227
197
|
|
|
228
|
-
|
|
229
|
-
assertTrue(
|
|
198
|
+
pauseRbac.pause();
|
|
199
|
+
assertTrue(pause.isPaused());
|
|
230
200
|
}
|
|
231
201
|
|
|
232
202
|
function test_modifierEnforcement_WithRoles() public {
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
mock.functionWithModifier();
|
|
236
|
-
assertEq(mock.callCount(), 1);
|
|
203
|
+
pauseRbac.functionWithModifier();
|
|
204
|
+
assertEq(pauseRbac.callCount(), 1);
|
|
237
205
|
|
|
238
|
-
|
|
206
|
+
pauseRbac.pause();
|
|
239
207
|
|
|
240
208
|
vm.expectRevert(abi.encodeWithSelector(IPause.Paused.selector));
|
|
241
|
-
|
|
242
|
-
assertEq(
|
|
209
|
+
pauseRbac.functionWithModifier();
|
|
210
|
+
assertEq(pauseRbac.callCount(), 1);
|
|
243
211
|
|
|
244
212
|
address newAdmin = address(0xabc);
|
|
245
|
-
|
|
246
|
-
|
|
213
|
+
pauseRbac.grantRole(pauseRbac.PAUSER_ROLE(), newAdmin);
|
|
214
|
+
pauseRbac.grantRole(pauseRbac.UNPAUSER_ROLE(), newAdmin);
|
|
247
215
|
|
|
248
216
|
vm.expectRevert(abi.encodeWithSelector(IPause.Paused.selector));
|
|
249
|
-
|
|
250
|
-
assertEq(
|
|
217
|
+
pauseRbac.functionWithModifier();
|
|
218
|
+
assertEq(pauseRbac.callCount(), 1);
|
|
251
219
|
|
|
252
220
|
vm.prank(newAdmin);
|
|
253
|
-
|
|
221
|
+
pauseRbac.unpause();
|
|
254
222
|
|
|
255
|
-
|
|
256
|
-
assertEq(
|
|
223
|
+
pauseRbac.functionWithModifier();
|
|
224
|
+
assertEq(pauseRbac.callCount(), 2);
|
|
257
225
|
}
|
|
258
226
|
}
|
|
@@ -6,7 +6,7 @@ import { TransparentUpgradeableProxy } from "@openzeppelin/contracts/proxy/trans
|
|
|
6
6
|
import { Test } from "forge-std/Test.sol";
|
|
7
7
|
import { RateLimiterBaseUpgradeable } from "./../contracts/rate-limiter/RateLimiterBaseUpgradeable.sol";
|
|
8
8
|
|
|
9
|
-
contract
|
|
9
|
+
contract RateLimiterBaseUpgradeableHarness is RateLimiterBaseUpgradeable {
|
|
10
10
|
constructor(uint8 _scaleDecimals) RateLimiterBaseUpgradeable(_scaleDecimals) {
|
|
11
11
|
_disableInitializers();
|
|
12
12
|
}
|
|
@@ -71,12 +71,12 @@ contract RateLimiterBaseUpgradeableMock is RateLimiterBaseUpgradeable {
|
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
contract RateLimiterBaseUpgradeableTest is Test {
|
|
74
|
-
|
|
74
|
+
RateLimiterBaseUpgradeableHarness rateLimiter;
|
|
75
75
|
/// @dev Separate instance for global state tests to avoid warm storage overlap or conflict.
|
|
76
|
-
|
|
76
|
+
RateLimiterBaseUpgradeableHarness rateLimiterGlobal;
|
|
77
77
|
/// @dev Separate instances for conflicting default config permutations.
|
|
78
|
-
|
|
79
|
-
|
|
78
|
+
RateLimiterBaseUpgradeableHarness rateLimiterDefaultNet;
|
|
79
|
+
RateLimiterBaseUpgradeableHarness rateLimiterDefaultDisabled;
|
|
80
80
|
|
|
81
81
|
uint256 constant ID_1 = uint256(keccak256("ID_1"));
|
|
82
82
|
uint256 constant ID_2 = uint256(keccak256("ID_2"));
|
|
@@ -113,25 +113,29 @@ contract RateLimiterBaseUpgradeableTest is Test {
|
|
|
113
113
|
}
|
|
114
114
|
|
|
115
115
|
function setUp() public virtual {
|
|
116
|
-
rateLimiter =
|
|
117
|
-
rateLimiterGlobal =
|
|
118
|
-
rateLimiterDefaultNet =
|
|
119
|
-
rateLimiterDefaultDisabled =
|
|
116
|
+
rateLimiter = _deployRateLimiter(0, false);
|
|
117
|
+
rateLimiterGlobal = _deployRateLimiter(0, true);
|
|
118
|
+
rateLimiterDefaultNet = _deployRateLimiter(0, false);
|
|
119
|
+
rateLimiterDefaultDisabled = _deployRateLimiter(0, false);
|
|
120
120
|
|
|
121
121
|
_setUpConfigs();
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
-
function
|
|
124
|
+
function _deployRateLimiter(
|
|
125
125
|
uint8 _scaleDecimals,
|
|
126
126
|
bool _useGlobalState
|
|
127
|
-
) internal virtual returns (
|
|
128
|
-
|
|
127
|
+
) internal virtual returns (RateLimiterBaseUpgradeableHarness) {
|
|
128
|
+
RateLimiterBaseUpgradeableHarness impl = new RateLimiterBaseUpgradeableHarness(_scaleDecimals);
|
|
129
129
|
TransparentUpgradeableProxy proxy = new TransparentUpgradeableProxy(
|
|
130
130
|
address(impl),
|
|
131
131
|
address(this),
|
|
132
|
-
abi.encodeWithSelector(
|
|
132
|
+
abi.encodeWithSelector(
|
|
133
|
+
RateLimiterBaseUpgradeableHarness.initialize.selector,
|
|
134
|
+
_useGlobalState,
|
|
135
|
+
address(this)
|
|
136
|
+
)
|
|
133
137
|
);
|
|
134
|
-
return
|
|
138
|
+
return RateLimiterBaseUpgradeableHarness(address(proxy));
|
|
135
139
|
}
|
|
136
140
|
|
|
137
141
|
function _setUpConfigs() internal {
|
|
@@ -303,17 +307,17 @@ contract RateLimiterBaseUpgradeableTest is Test {
|
|
|
303
307
|
|
|
304
308
|
function test_constructor_Revert_InvalidScaledDecimals() public {
|
|
305
309
|
vm.expectRevert(abi.encodeWithSelector(IRateLimiter.InvalidScaledDecimals.selector, 19));
|
|
306
|
-
new
|
|
310
|
+
new RateLimiterBaseUpgradeableHarness(19);
|
|
307
311
|
}
|
|
308
312
|
|
|
309
313
|
function test_constructor_MaxScaledDecimals() public {
|
|
310
|
-
|
|
314
|
+
RateLimiterBaseUpgradeableHarness impl = new RateLimiterBaseUpgradeableHarness(18);
|
|
311
315
|
|
|
312
316
|
assertEq(impl.SCALE_DECIMALS(), 18);
|
|
313
317
|
}
|
|
314
318
|
|
|
315
319
|
function test_constructor_ZeroScaledDecimals() public {
|
|
316
|
-
|
|
320
|
+
RateLimiterBaseUpgradeableHarness impl = new RateLimiterBaseUpgradeableHarness(0);
|
|
317
321
|
|
|
318
322
|
assertEq(impl.SCALE_DECIMALS(), 0);
|
|
319
323
|
}
|
|
@@ -321,7 +325,7 @@ contract RateLimiterBaseUpgradeableTest is Test {
|
|
|
321
325
|
// ============ Scaling Tests ============
|
|
322
326
|
|
|
323
327
|
function test_outflow_WithScaleDecimals() public {
|
|
324
|
-
|
|
328
|
+
RateLimiterBaseUpgradeableHarness scaledLimiter = _deployRateLimiter(12, false);
|
|
325
329
|
|
|
326
330
|
uint96 limit = 1_000_000_000;
|
|
327
331
|
uint32 window = 1000;
|
|
@@ -341,7 +345,7 @@ contract RateLimiterBaseUpgradeableTest is Test {
|
|
|
341
345
|
}
|
|
342
346
|
|
|
343
347
|
function test_inflow_WithScaleDecimals() public {
|
|
344
|
-
|
|
348
|
+
RateLimiterBaseUpgradeableHarness scaledLimiter = _deployRateLimiter(12, false);
|
|
345
349
|
|
|
346
350
|
uint96 limit = 1_000_000_000;
|
|
347
351
|
uint32 window = 1000;
|
|
@@ -361,7 +365,7 @@ contract RateLimiterBaseUpgradeableTest is Test {
|
|
|
361
365
|
}
|
|
362
366
|
|
|
363
367
|
function test_upscaleRateLimitAmount() public {
|
|
364
|
-
|
|
368
|
+
RateLimiterBaseUpgradeableHarness scaledLimiter = _deployRateLimiter(12, false);
|
|
365
369
|
|
|
366
370
|
uint256 downscaled = 100;
|
|
367
371
|
uint256 upscaled = scaledLimiter.upscaleRateLimitAmount(downscaled);
|
|
@@ -372,7 +376,7 @@ contract RateLimiterBaseUpgradeableTest is Test {
|
|
|
372
376
|
// ============ Global State Tests ============
|
|
373
377
|
|
|
374
378
|
function test_globalState_UsesDefaultIdForState() public {
|
|
375
|
-
|
|
379
|
+
RateLimiterBaseUpgradeableHarness globalLimiter = _deployRateLimiter(0, true);
|
|
376
380
|
|
|
377
381
|
uint96 limit = 1000;
|
|
378
382
|
uint32 window = 1000;
|
|
@@ -391,7 +395,7 @@ contract RateLimiterBaseUpgradeableTest is Test {
|
|
|
391
395
|
}
|
|
392
396
|
|
|
393
397
|
function test_globalState_IgnoresIdSpecificConfig() public {
|
|
394
|
-
|
|
398
|
+
RateLimiterBaseUpgradeableHarness globalLimiter = _deployRateLimiter(0, true);
|
|
395
399
|
|
|
396
400
|
uint96 defaultLimit = 1000;
|
|
397
401
|
uint96 idSpecificLimit = 500;
|
|
@@ -430,7 +434,7 @@ contract RateLimiterBaseUpgradeableTest is Test {
|
|
|
430
434
|
}
|
|
431
435
|
|
|
432
436
|
function test_globalState_SharesStateAcrossIds() public {
|
|
433
|
-
|
|
437
|
+
RateLimiterBaseUpgradeableHarness globalLimiter = _deployRateLimiter(0, true);
|
|
434
438
|
|
|
435
439
|
uint96 limit = 1000;
|
|
436
440
|
uint32 window = 1000;
|
|
@@ -802,7 +806,7 @@ contract RateLimiterBaseUpgradeableTest is Test {
|
|
|
802
806
|
}
|
|
803
807
|
|
|
804
808
|
function test_initial_state_closed() public {
|
|
805
|
-
|
|
809
|
+
RateLimiterBaseUpgradeableHarness freshLimiter = _deployRateLimiter(0, false);
|
|
806
810
|
|
|
807
811
|
IRateLimiter.RateLimit memory rl = freshLimiter.rateLimits(0);
|
|
808
812
|
|
|
@@ -5,9 +5,9 @@ import { IRateLimiter } from "@layerzerolabs/utils-evm-contracts/contracts/inter
|
|
|
5
5
|
import { IAccessControl } from "@openzeppelin/contracts/access/IAccessControl.sol";
|
|
6
6
|
import { TransparentUpgradeableProxy } from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
|
|
7
7
|
import { RateLimiterRBACUpgradeable } from "./../contracts/rate-limiter/RateLimiterRBACUpgradeable.sol";
|
|
8
|
-
import { RateLimiterBaseUpgradeableTest,
|
|
8
|
+
import { RateLimiterBaseUpgradeableTest, RateLimiterBaseUpgradeableHarness } from "./RateLimiterBaseUpgradeable.t.sol";
|
|
9
9
|
|
|
10
|
-
contract
|
|
10
|
+
contract RateLimiterRBACUpgradeableHarness is RateLimiterRBACUpgradeable {
|
|
11
11
|
constructor(uint8 _scaleDecimals) RateLimiterRBACUpgradeable(_scaleDecimals) {
|
|
12
12
|
_disableInitializers();
|
|
13
13
|
}
|
|
@@ -39,18 +39,28 @@ contract RateLimiterRBACUpgradeableTest is RateLimiterBaseUpgradeableTest {
|
|
|
39
39
|
bytes32 constant RATE_LIMITER_MANAGER_ROLE = keccak256("RATE_LIMITER_MANAGER_ROLE");
|
|
40
40
|
|
|
41
41
|
address charlie = makeAddr("charlie");
|
|
42
|
+
RateLimiterRBACUpgradeableHarness rateLimiterRbac;
|
|
42
43
|
|
|
43
|
-
function
|
|
44
|
+
function setUp() public override {
|
|
45
|
+
super.setUp();
|
|
46
|
+
rateLimiterRbac = RateLimiterRBACUpgradeableHarness(address(rateLimiter));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function _deployRateLimiter(
|
|
44
50
|
uint8 _scaleDecimals,
|
|
45
51
|
bool _useGlobalState
|
|
46
|
-
) internal virtual override returns (
|
|
47
|
-
|
|
52
|
+
) internal virtual override returns (RateLimiterBaseUpgradeableHarness) {
|
|
53
|
+
RateLimiterRBACUpgradeableHarness impl = new RateLimiterRBACUpgradeableHarness(_scaleDecimals);
|
|
48
54
|
TransparentUpgradeableProxy proxy = new TransparentUpgradeableProxy(
|
|
49
55
|
address(impl),
|
|
50
56
|
address(this),
|
|
51
|
-
abi.encodeWithSelector(
|
|
57
|
+
abi.encodeWithSelector(
|
|
58
|
+
RateLimiterRBACUpgradeableHarness.initialize.selector,
|
|
59
|
+
_useGlobalState,
|
|
60
|
+
address(this)
|
|
61
|
+
)
|
|
52
62
|
);
|
|
53
|
-
return
|
|
63
|
+
return RateLimiterBaseUpgradeableHarness(address(proxy));
|
|
54
64
|
}
|
|
55
65
|
|
|
56
66
|
function test_setRateLimitGlobalConfig_Revert_Unauthorized() public {
|
|
@@ -66,7 +76,7 @@ contract RateLimiterRBACUpgradeableTest is RateLimiterBaseUpgradeableTest {
|
|
|
66
76
|
)
|
|
67
77
|
);
|
|
68
78
|
vm.prank(charlie);
|
|
69
|
-
|
|
79
|
+
rateLimiterRbac.setRateLimitGlobalConfig(config);
|
|
70
80
|
}
|
|
71
81
|
|
|
72
82
|
function test_setRateLimitConfigs_Revert_Unauthorized() public {
|
|
@@ -80,7 +90,7 @@ contract RateLimiterRBACUpgradeableTest is RateLimiterBaseUpgradeableTest {
|
|
|
80
90
|
)
|
|
81
91
|
);
|
|
82
92
|
vm.prank(charlie);
|
|
83
|
-
|
|
93
|
+
rateLimiterRbac.setRateLimitConfigs(configs);
|
|
84
94
|
}
|
|
85
95
|
|
|
86
96
|
function test_setRateLimitStates_Revert_Unauthorized() public {
|
|
@@ -94,7 +104,7 @@ contract RateLimiterRBACUpgradeableTest is RateLimiterBaseUpgradeableTest {
|
|
|
94
104
|
)
|
|
95
105
|
);
|
|
96
106
|
vm.prank(charlie);
|
|
97
|
-
|
|
107
|
+
rateLimiterRbac.setRateLimitStates(states);
|
|
98
108
|
}
|
|
99
109
|
|
|
100
110
|
function test_setRateLimitAddressExemptions_Revert_Unauthorized() public {
|
|
@@ -109,7 +119,7 @@ contract RateLimiterRBACUpgradeableTest is RateLimiterBaseUpgradeableTest {
|
|
|
109
119
|
)
|
|
110
120
|
);
|
|
111
121
|
vm.prank(charlie);
|
|
112
|
-
|
|
122
|
+
rateLimiterRbac.setRateLimitAddressExemptions(exemptions);
|
|
113
123
|
}
|
|
114
124
|
|
|
115
125
|
function test_checkpointRateLimits_Revert_Unauthorized() public {
|
|
@@ -123,6 +133,6 @@ contract RateLimiterRBACUpgradeableTest is RateLimiterBaseUpgradeableTest {
|
|
|
123
133
|
)
|
|
124
134
|
);
|
|
125
135
|
vm.prank(charlie);
|
|
126
|
-
|
|
136
|
+
rateLimiterRbac.checkpointRateLimits(ids);
|
|
127
137
|
}
|
|
128
138
|
}
|
|
@@ -8,7 +8,7 @@ import { StdInvariant } from "forge-std/StdInvariant.sol";
|
|
|
8
8
|
import { Test } from "forge-std/Test.sol";
|
|
9
9
|
import { RateLimiterRBACUpgradeable } from "./../contracts/rate-limiter/RateLimiterRBACUpgradeable.sol";
|
|
10
10
|
|
|
11
|
-
contract
|
|
11
|
+
contract RateLimiterRBACUpgradeableFuzzHarness is RateLimiterRBACUpgradeable {
|
|
12
12
|
constructor(uint8 _scaleDecimals) RateLimiterRBACUpgradeable(_scaleDecimals) {
|
|
13
13
|
_disableInitializers();
|
|
14
14
|
}
|
|
@@ -29,7 +29,7 @@ contract RateLimiterRBACUpgradeableFuzzMock is RateLimiterRBACUpgradeable {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
contract RateLimiterRBACUpgradeableHandler is Test {
|
|
32
|
-
|
|
32
|
+
RateLimiterRBACUpgradeableFuzzHarness public limiter;
|
|
33
33
|
|
|
34
34
|
uint256 public immutable ID;
|
|
35
35
|
address public constant USER = address(0x123);
|
|
@@ -49,7 +49,7 @@ contract RateLimiterRBACUpgradeableHandler is Test {
|
|
|
49
49
|
bool public ghost_globallyDisabled;
|
|
50
50
|
bool public ghost_revertMismatch;
|
|
51
51
|
|
|
52
|
-
constructor(
|
|
52
|
+
constructor(RateLimiterRBACUpgradeableFuzzHarness _limiter, uint256 _id) {
|
|
53
53
|
limiter = _limiter;
|
|
54
54
|
ID = _id;
|
|
55
55
|
|
|
@@ -294,12 +294,12 @@ contract RateLimiterRBACUpgradeableHandler is Test {
|
|
|
294
294
|
}
|
|
295
295
|
|
|
296
296
|
contract RateLimiterRBACUpgradeableInvariantTest is StdInvariant, Test {
|
|
297
|
-
|
|
297
|
+
RateLimiterRBACUpgradeableFuzzHarness limiter;
|
|
298
298
|
RateLimiterRBACUpgradeableHandler handler;
|
|
299
299
|
uint256 constant PRISTINE_ID = uint256(keccak256("PRISTINE_ID"));
|
|
300
300
|
|
|
301
301
|
function setUp() public virtual {
|
|
302
|
-
limiter =
|
|
302
|
+
limiter = _deployRateLimiter(0, _globalStateEnabled());
|
|
303
303
|
handler = new RateLimiterRBACUpgradeableHandler(limiter, _handlerId());
|
|
304
304
|
|
|
305
305
|
limiter.grantRole(limiter.RATE_LIMITER_MANAGER_ROLE(), address(handler));
|
|
@@ -317,21 +317,21 @@ contract RateLimiterRBACUpgradeableInvariantTest is StdInvariant, Test {
|
|
|
317
317
|
targetSelector(FuzzSelector({ addr: address(handler), selectors: selectors }));
|
|
318
318
|
}
|
|
319
319
|
|
|
320
|
-
function
|
|
320
|
+
function _deployRateLimiter(
|
|
321
321
|
uint8 _scaleDecimals,
|
|
322
322
|
bool _useGlobalState
|
|
323
|
-
) internal virtual returns (
|
|
324
|
-
|
|
323
|
+
) internal virtual returns (RateLimiterRBACUpgradeableFuzzHarness) {
|
|
324
|
+
RateLimiterRBACUpgradeableFuzzHarness impl = new RateLimiterRBACUpgradeableFuzzHarness(_scaleDecimals);
|
|
325
325
|
TransparentUpgradeableProxy proxy = new TransparentUpgradeableProxy(
|
|
326
326
|
address(impl),
|
|
327
327
|
address(this),
|
|
328
328
|
abi.encodeWithSelector(
|
|
329
|
-
|
|
329
|
+
RateLimiterRBACUpgradeableFuzzHarness.initialize.selector,
|
|
330
330
|
_useGlobalState,
|
|
331
331
|
address(this)
|
|
332
332
|
)
|
|
333
333
|
);
|
|
334
|
-
return
|
|
334
|
+
return RateLimiterRBACUpgradeableFuzzHarness(address(proxy));
|
|
335
335
|
}
|
|
336
336
|
|
|
337
337
|
function _globalStateEnabled() internal pure virtual returns (bool) {
|