Skip to content

Commit a194c76

Browse files
committed
test: fix change{enabled,disabled}rateLimit
1 parent 96e96f2 commit a194c76

File tree

1 file changed

+74
-2
lines changed

1 file changed

+74
-2
lines changed

src/test/TestGhoCcipSteward.t.sol

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,14 +257,15 @@ contract TestGhoCcipSteward is TestGhoBase {
257257
);
258258
}
259259

260-
function testDisableRateLimitFromNonZeroToZero() public {
260+
function testChangeEnabledRateLimit() public {
261261
RateLimiter.TokenBucket memory outboundConfig = MockUpgradeableLockReleaseTokenPool(
262262
GHO_TOKEN_POOL
263263
).getCurrentOutboundRateLimiterState(remoteChainSelector);
264264
RateLimiter.TokenBucket memory inboundConfig = MockUpgradeableLockReleaseTokenPool(
265265
GHO_TOKEN_POOL
266266
).getCurrentInboundRateLimiterState(remoteChainSelector);
267267

268+
// assert both inbound & outbound rate limiters are enabled
268269
assertTrue(outboundConfig.isEnabled);
269270
assertGt(outboundConfig.capacity, 0);
270271
assertGt(outboundConfig.rate, 0);
@@ -305,7 +306,72 @@ contract TestGhoCcipSteward is TestGhoBase {
305306
assertEq(inboundConfig.rate, 0);
306307
}
307308

308-
function testDisableRateLimitOnlyOutboundConfig() public {
309+
function testRevertChangeDisabledRateLimit() public {
310+
RateLimiter.TokenBucket memory outboundConfig = MockUpgradeableLockReleaseTokenPool(
311+
GHO_TOKEN_POOL
312+
).getCurrentOutboundRateLimiterState(remoteChainSelector);
313+
RateLimiter.TokenBucket memory inboundConfig = MockUpgradeableLockReleaseTokenPool(
314+
GHO_TOKEN_POOL
315+
).getCurrentInboundRateLimiterState(remoteChainSelector);
316+
317+
RateLimiter.Config memory disableLimitConfig = RateLimiter.Config({
318+
isEnabled: false,
319+
capacity: 0,
320+
rate: 0
321+
});
322+
323+
// disable both inbound & outbound config
324+
vm.prank(RISK_COUNCIL);
325+
GHO_CCIP_STEWARD.updateRateLimit(
326+
remoteChainSelector,
327+
disableLimitConfig.isEnabled,
328+
disableLimitConfig.capacity,
329+
disableLimitConfig.rate,
330+
disableLimitConfig.isEnabled,
331+
disableLimitConfig.capacity,
332+
disableLimitConfig.rate
333+
);
334+
335+
skip(GHO_CCIP_STEWARD.MINIMUM_DELAY() + 1);
336+
337+
// steward is not allowed to re-enable rate limit
338+
vm.expectRevert('INVALID_RATE_LIMIT_UPDATE');
339+
vm.prank(RISK_COUNCIL);
340+
GHO_CCIP_STEWARD.updateRateLimit(
341+
remoteChainSelector,
342+
outboundConfig.isEnabled,
343+
outboundConfig.capacity,
344+
outboundConfig.rate,
345+
inboundConfig.isEnabled,
346+
inboundConfig.capacity,
347+
inboundConfig.rate
348+
);
349+
350+
// risk admin/DAO can re-enable rate limit on token pool
351+
vm.prank(GHO_TOKEN_POOL.owner());
352+
GHO_TOKEN_POOL.setChainRateLimiterConfig(
353+
remoteChainSelector,
354+
_castTokenBucketToConfig(outboundConfig),
355+
_castTokenBucketToConfig(inboundConfig)
356+
);
357+
358+
RateLimiter.TokenBucket memory outboundConfigNew = MockUpgradeableLockReleaseTokenPool(
359+
GHO_TOKEN_POOL
360+
).getCurrentOutboundRateLimiterState(remoteChainSelector);
361+
RateLimiter.TokenBucket memory inboundConfigNew = MockUpgradeableLockReleaseTokenPool(
362+
GHO_TOKEN_POOL
363+
).getCurrentInboundRateLimiterState(remoteChainSelector);
364+
365+
assertTrue(outboundConfigNew.isEnabled);
366+
assertEq(outboundConfigNew.capacity, outboundConfig.capacity);
367+
assertEq(outboundConfigNew.rate, outboundConfig.rate);
368+
369+
assertTrue(inboundConfigNew.isEnabled);
370+
assertEq(inboundConfigNew.capacity, inboundConfig.capacity);
371+
assertEq(inboundConfigNew.rate, inboundConfig.rate);
372+
}
373+
374+
function testChangeEnabledRateLimitOnlyOneSide() public {
309375
RateLimiter.TokenBucket memory outboundConfig = MockUpgradeableLockReleaseTokenPool(
310376
GHO_TOKEN_POOL
311377
).getCurrentOutboundRateLimiterState(remoteChainSelector);
@@ -409,4 +475,10 @@ contract TestGhoCcipSteward is TestGhoBase {
409475
inboundRate
410476
);
411477
}
478+
479+
function _castTokenBucketToConfig(
480+
RateLimiter.TokenBucket memory arg
481+
) private view returns (RateLimiter.Config memory) {
482+
return RateLimiter.Config({isEnabled: arg.isEnabled, capacity: arg.capacity, rate: arg.rate});
483+
}
412484
}

0 commit comments

Comments
 (0)