Skip to content

Commit

Permalink
test: update token pool rate limit
Browse files Browse the repository at this point in the history
  • Loading branch information
CheyenneAtapour committed Jul 10, 2024
1 parent eb204c4 commit 554ded7
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/test/TestGhoBase.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ import {SampleSwapFreezer} from '../contracts/facilitators/gsm/misc/SampleSwapFr
import {GsmRegistry} from '../contracts/facilitators/gsm/misc/GsmRegistry.sol';

// CCIP contracts
import {UpgradeableTokenPool} from 'ccip/v0.8/ccip/pools/GHO/UpgradeableTokenPool.sol';
import {UpgradeableLockReleaseTokenPool} from 'ccip/v0.8/ccip/pools/GHO/UpgradeableLockReleaseTokenPool.sol';
import {RateLimiter} from 'ccip/v0.8/ccip/libraries/RateLimiter.sol';

contract TestGhoBase is Test, Constants, Events {
using WadRayMath for uint256;
Expand Down Expand Up @@ -348,6 +350,29 @@ contract TestGhoBase is Test, Constants, Events {
GHO_TOKEN_POOL.setBridgeLimitAdmin(address(GHO_STEWARD_V2));
GHO_TOKEN_POOL.setRateLimitAdmin(address(GHO_STEWARD_V2));
vm.stopPrank();
// Setup GHO Token Pool
uint64 SOURCE_CHAIN_SELECTOR = 1;
uint64 DEST_CHAIN_SELECTOR = 2;
UpgradeableTokenPool.ChainUpdate[] memory chainUpdate = new UpgradeableTokenPool.ChainUpdate[](
1
);
chainUpdate[0] = UpgradeableTokenPool.ChainUpdate({
remoteChainSelector: DEST_CHAIN_SELECTOR,
allowed: true,
outboundRateLimiterConfig: getOutboundRateLimiterConfig(),
inboundRateLimiterConfig: getInboundRateLimiterConfig()
});

vm.prank(OWNER);
GHO_TOKEN_POOL.applyChainUpdates(chainUpdate);
}

function getOutboundRateLimiterConfig() public pure returns (RateLimiter.Config memory) {
return RateLimiter.Config({isEnabled: true, capacity: 100e28, rate: 1e15});
}

function getInboundRateLimiterConfig() public pure returns (RateLimiter.Config memory) {
return RateLimiter.Config({isEnabled: true, capacity: 222e30, rate: 1e18});
}

function ghoFaucet(address to, uint256 amount) public {
Expand Down
32 changes: 32 additions & 0 deletions src/test/TestGhoStewardV2.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@
pragma solidity ^0.8.0;

import './TestGhoBase.t.sol';
import {RateLimiter} from 'ccip/v0.8/ccip/libraries/RateLimiter.sol';

contract TestGhoStewardV2 is TestGhoBase {
using ReserveConfiguration for DataTypes.ReserveConfigurationMap;

event ChainConfigured(
uint64 remoteChainSelector,
RateLimiter.Config outboundRateLimiterConfig,
RateLimiter.Config inboundRateLimiterConfig
);

function setUp() public {
/// @dev Since block.timestamp starts at 0 this is a necessary condition (block.timestamp > `MINIMUM_DELAY`) for the timelocked contract methods to work.
vm.warp(GHO_STEWARD_V2.MINIMUM_DELAY() + 1);
Expand Down Expand Up @@ -852,6 +859,31 @@ contract TestGhoStewardV2 is TestGhoBase {
GHO_STEWARD_V2.updateBridgeLimit(newBridgeLimit);
}

function testUpdateRateLimit() public {
vm.expectEmit(false, false, false, true);
emit ChainConfigured(
2,
RateLimiter.Config({isEnabled: true, capacity: type(uint128).max, rate: 1e15}),
RateLimiter.Config({isEnabled: true, capacity: type(uint128).max, rate: 1e15})
);
vm.prank(RISK_COUNCIL);
GHO_STEWARD_V2.updateRateLimit(
2,
RateLimiter.Config({isEnabled: true, capacity: type(uint128).max, rate: 1e15}),
RateLimiter.Config({isEnabled: true, capacity: type(uint128).max, rate: 1e15})
);
}

function testRevertUpdateRateLimitIfUnauthorized() public {
vm.prank(ALICE);
vm.expectRevert('INVALID_CALLER');
GHO_STEWARD_V2.updateRateLimit(
2,
RateLimiter.Config({isEnabled: true, capacity: type(uint128).max, rate: 1e15}),
RateLimiter.Config({isEnabled: true, capacity: type(uint128).max, rate: 1e15})
);
}

function testSetControlledFacilitatorAdd() public {
address[] memory oldControlledFacilitators = GHO_STEWARD_V2.getControlledFacilitators();
address[] memory newGsmList = new address[](1);
Expand Down

0 comments on commit 554ded7

Please sign in to comment.