Skip to content

Commit

Permalink
CCIP-4114 refactor token pool tests for one function per file (#15119)
Browse files Browse the repository at this point in the history
* refactor for one function per file

* better align naming convention with source code

* rename allowList test files

* modify file name for more accuracy

* fix compiler bugs that weren't caught for some reason
  • Loading branch information
jhweintraub authored Nov 5, 2024
1 parent 0b38fca commit dc5c1ec
Show file tree
Hide file tree
Showing 51 changed files with 4,432 additions and 3,035 deletions.
78 changes: 43 additions & 35 deletions contracts/gas-snapshots/ccip.gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ARMProxyTest:test_ARMIsCursed_Success() (gas: 47082)
BurnFromMintTokenPool_lockOrBurn:test_ChainNotAllowed_Revert() (gas: 28962)
BurnFromMintTokenPool_lockOrBurn:test_PoolBurnRevertNotHealthy_Revert() (gas: 55341)
BurnFromMintTokenPool_lockOrBurn:test_PoolBurn_Success() (gas: 244152)
BurnFromMintTokenPool_lockOrBurn:test_Setup_Success() (gas: 24209)
BurnFromMintTokenPool_lockOrBurn:test_setup_Success() (gas: 24187)
BurnMintTokenPool_lockOrBurn:test_ChainNotAllowed_Revert() (gas: 27681)
BurnMintTokenPool_lockOrBurn:test_PoolBurnRevertNotHealthy_Revert() (gas: 55341)
BurnMintTokenPool_lockOrBurn:test_PoolBurn_Success() (gas: 242036)
Expand Down Expand Up @@ -227,38 +227,15 @@ FeeQuoter_validateDestFamilyAddress:test_InvalidEVMAddressPrecompiles_Revert() (
FeeQuoter_validateDestFamilyAddress:test_InvalidEVMAddress_Revert() (gas: 10884)
FeeQuoter_validateDestFamilyAddress:test_ValidEVMAddress_Success() (gas: 6819)
FeeQuoter_validateDestFamilyAddress:test_ValidNonEVMAddress_Success() (gas: 6545)
HybridUSDCTokenPoolMigrationTests:test_LockOrBurn_LockReleaseMechanism_then_switchToPrimary_Success() (gas: 209719)
HybridUSDCTokenPoolMigrationTests:test_LockOrBurn_PrimaryMechanism_Success() (gas: 136083)
HybridUSDCTokenPoolMigrationTests:test_LockOrBurn_WhileMigrationPause_Revert() (gas: 109924)
HybridUSDCTokenPoolMigrationTests:test_LockOrBurn_onLockReleaseMechanism_Success() (gas: 147189)
HybridUSDCTokenPoolMigrationTests:test_MintOrRelease_OnLockReleaseMechanism_Success() (gas: 217255)
HybridUSDCTokenPoolMigrationTests:test_MintOrRelease_OnLockReleaseMechanism_then_switchToPrimary_Success() (gas: 426523)
HybridUSDCTokenPoolMigrationTests:test_MintOrRelease_incomingMessageWithPrimaryMechanism() (gas: 269168)
HybridUSDCTokenPoolMigrationTests:test_ProposeMigration_ChainNotUsingLockRelease_Revert() (gas: 15876)
HybridUSDCTokenPoolMigrationTests:test_ReleaseOrMint_WhileMigrationPause_Revert() (gas: 113657)
HybridUSDCTokenPoolMigrationTests:test_burnLockedUSDC_invalidPermissions_Revert() (gas: 39333)
HybridUSDCTokenPoolMigrationTests:test_cancelExistingCCTPMigrationProposal() (gas: 56302)
HybridUSDCTokenPoolMigrationTests:test_cannotCancelANonExistentMigrationProposal() (gas: 12758)
HybridUSDCTokenPoolMigrationTests:test_cannotModifyLiquidityWithoutPermissions_Revert() (gas: 13423)
HybridUSDCTokenPoolMigrationTests:test_cannotProvideLiquidityWhenMigrationProposalPending_Revert() (gas: 67449)
HybridUSDCTokenPoolMigrationTests:test_cannotRevertChainMechanism_afterMigration_Revert() (gas: 313663)
HybridUSDCTokenPoolMigrationTests:test_cannotTransferLiquidityDuringPendingMigration_Revert() (gas: 177187)
HybridUSDCTokenPoolMigrationTests:test_cnanotProvideLiquidity_AfterMigration_Revert() (gas: 314046)
HybridUSDCTokenPoolMigrationTests:test_excludeTokensWhenNoMigrationProposalPending_Revert() (gas: 13712)
HybridUSDCTokenPoolMigrationTests:test_lockOrBurn_then_BurnInCCTPMigration_Success() (gas: 310162)
HybridUSDCTokenPoolMigrationTests:test_transferLiquidity_Success() (gas: 167156)
HybridUSDCTokenPoolMigrationTests:test_unstickManualTxAfterMigration_destChain_Success() (gas: 156334)
HybridUSDCTokenPoolMigrationTests:test_unstickManualTxAfterMigration_homeChain_Success() (gas: 516342)
HybridUSDCTokenPoolTests:test_LockOrBurn_LockReleaseMechanism_then_switchToPrimary_Success() (gas: 209569)
HybridUSDCTokenPoolTests:test_LockOrBurn_PrimaryMechanism_Success() (gas: 136048)
HybridUSDCTokenPoolTests:test_LockOrBurn_WhileMigrationPause_Revert() (gas: 109914)
HybridUSDCTokenPoolTests:test_LockOrBurn_onLockReleaseMechanism_Success() (gas: 147177)
HybridUSDCTokenPoolTests:test_MintOrRelease_OnLockReleaseMechanism_Success() (gas: 217112)
HybridUSDCTokenPoolTests:test_MintOrRelease_OnLockReleaseMechanism_then_switchToPrimary_Success() (gas: 426248)
HybridUSDCTokenPoolTests:test_MintOrRelease_incomingMessageWithPrimaryMechanism() (gas: 269124)
HybridUSDCTokenPoolTests:test_ReleaseOrMint_WhileMigrationPause_Revert() (gas: 113635)
HybridUSDCTokenPoolTests:test_cannotTransferLiquidityDuringPendingMigration_Revert() (gas: 177099)
HybridUSDCTokenPoolTests:test_transferLiquidity_Success() (gas: 167068)
HybridLockReleaseUSDCTokenPool_TransferLiquidity:test_cannotTransferLiquidityDuringPendingMigration_Revert() (gas: 176969)
HybridLockReleaseUSDCTokenPool_TransferLiquidity:test_transferLiquidity_Success() (gas: 167002)
HybridLockReleaseUSDCTokenPool_lockOrBurn:test_PrimaryMechanism_Success() (gas: 135921)
HybridLockReleaseUSDCTokenPool_lockOrBurn:test_WhileMigrationPause_Revert() (gas: 109740)
HybridLockReleaseUSDCTokenPool_lockOrBurn:test_onLockReleaseMechanism_Success() (gas: 147013)
HybridLockReleaseUSDCTokenPool_lockOrBurn:test_onLockReleaseMechanism_thenswitchToPrimary_Success() (gas: 209245)
HybridLockReleaseUSDCTokenPool_releaseOrMint:test_OnLockReleaseMechanism_Success() (gas: 216909)
HybridLockReleaseUSDCTokenPool_releaseOrMint:test_WhileMigrationPause_Revert() (gas: 113472)
HybridLockReleaseUSDCTokenPool_releaseOrMint:test_incomingMessageWithPrimaryMechanism() (gas: 268981)
LockReleaseTokenPool_canAcceptLiquidity:test_CanAcceptLiquidity_Success() (gas: 2778635)
LockReleaseTokenPool_lockOrBurn:test_LockOrBurnWithAllowList_Revert() (gas: 30110)
LockReleaseTokenPool_lockOrBurn:test_LockOrBurnWithAllowList_Success() (gas: 80282)
Expand All @@ -275,8 +252,6 @@ LockReleaseTokenPool_transferLiquidity:test_transferLiquidity_Success() (gas: 83
LockReleaseTokenPool_transferLiquidity:test_transferLiquidity_transferTooMuch_Revert() (gas: 56013)
LockReleaseTokenPool_withdrawalLiquidity:test_InsufficientLiquidity_Revert() (gas: 60164)
LockReleaseTokenPool_withdrawalLiquidity:test_Unauthorized_Revert() (gas: 11464)
LockRelease_setRateLimitAdmin:test_SetRateLimitAdmin_Revert() (gas: 11024)
LockRelease_setRateLimitAdmin:test_SetRateLimitAdmin_Success() (gas: 35126)
MerkleMultiProofTest:test_CVE_2023_34459() (gas: 5500)
MerkleMultiProofTest:test_EmptyLeaf_Revert() (gas: 3607)
MerkleMultiProofTest:test_MerkleRoot256() (gas: 394891)
Expand Down Expand Up @@ -734,9 +709,42 @@ TokenPool_onlyOnRamp:test_ChainNotAllowed_Revert() (gas: 254443)
TokenPool_onlyOnRamp:test_onlyOnRamp_Success() (gas: 305359)
TokenPool_setChainRateLimiterConfig:test_NonExistentChain_Revert() (gas: 17225)
TokenPool_setChainRateLimiterConfig:test_OnlyOwnerOrRateLimitAdmin_Revert() (gas: 15330)
TokenPool_setRateLimitAdmin:test_SetRateLimitAdmin_Revert() (gas: 11024)
TokenPool_setRateLimitAdmin:test_SetRateLimitAdmin_Success() (gas: 35126)
TokenPool_setRemotePool:test_setRemotePool_NonExistentChain_Reverts() (gas: 15796)
TokenPool_setRemotePool:test_setRemotePool_OnlyOwner_Reverts() (gas: 13285)
TokenPool_setRemotePool:test_setRemotePool_Success() (gas: 282581)
USDCBridgeMigrator_BurnLockedUSDC:test_PrimaryMechanism_Success() (gas: 135930)
USDCBridgeMigrator_BurnLockedUSDC:test_WhileMigrationPause_Revert() (gas: 109773)
USDCBridgeMigrator_BurnLockedUSDC:test_invalidPermissions_Revert() (gas: 39343)
USDCBridgeMigrator_BurnLockedUSDC:test_lockOrBurn_then_BurnInCCTPMigration_Success() (gas: 309779)
USDCBridgeMigrator_BurnLockedUSDC:test_onLockReleaseMechanism_Success() (gas: 147037)
USDCBridgeMigrator_BurnLockedUSDC:test_onLockReleaseMechanism_thenswitchToPrimary_Success() (gas: 209263)
USDCBridgeMigrator_cancelMigrationProposal:test_cancelExistingCCTPMigrationProposal_Success() (gas: 56190)
USDCBridgeMigrator_cancelMigrationProposal:test_cannotCancelANonExistentMigrationProposal_Revert() (gas: 12691)
USDCBridgeMigrator_excludeTokensFromBurn:test_excludeTokensWhenNoMigrationProposalPending_Revert() (gas: 13579)
USDCBridgeMigrator_proposeMigration:test_ChainNotUsingLockRelease_Revert() (gas: 15765)
USDCBridgeMigrator_provideLiquidity:test_PrimaryMechanism_Success() (gas: 135912)
USDCBridgeMigrator_provideLiquidity:test_WhileMigrationPause_Revert() (gas: 109795)
USDCBridgeMigrator_provideLiquidity:test_cannotModifyLiquidityWithoutPermissions_Revert() (gas: 13378)
USDCBridgeMigrator_provideLiquidity:test_cannotProvideLiquidityWhenMigrationProposalPending_Revert() (gas: 67436)
USDCBridgeMigrator_provideLiquidity:test_cannotProvideLiquidity_AfterMigration_Revert() (gas: 313619)
USDCBridgeMigrator_provideLiquidity:test_invalidPermissions_Revert() (gas: 39343)
USDCBridgeMigrator_provideLiquidity:test_lockOrBurn_then_BurnInCCTPMigration_Success() (gas: 309779)
USDCBridgeMigrator_provideLiquidity:test_onLockReleaseMechanism_Success() (gas: 147082)
USDCBridgeMigrator_provideLiquidity:test_onLockReleaseMechanism_thenswitchToPrimary_Success() (gas: 209299)
USDCBridgeMigrator_releaseOrMint:test_OnLockReleaseMechanism_Success() (gas: 216942)
USDCBridgeMigrator_releaseOrMint:test_WhileMigrationPause_Revert() (gas: 113505)
USDCBridgeMigrator_releaseOrMint:test_incomingMessageWithPrimaryMechanism() (gas: 269034)
USDCBridgeMigrator_releaseOrMint:test_unstickManualTxAfterMigration_destChain_Success() (gas: 156071)
USDCBridgeMigrator_releaseOrMint:test_unstickManualTxAfterMigration_homeChain_Success() (gas: 516094)
USDCBridgeMigrator_updateChainSelectorMechanism:test_PrimaryMechanism_Success() (gas: 135930)
USDCBridgeMigrator_updateChainSelectorMechanism:test_WhileMigrationPause_Revert() (gas: 109773)
USDCBridgeMigrator_updateChainSelectorMechanism:test_cannotRevertChainMechanism_afterMigration_Revert() (gas: 313216)
USDCBridgeMigrator_updateChainSelectorMechanism:test_invalidPermissions_Revert() (gas: 39321)
USDCBridgeMigrator_updateChainSelectorMechanism:test_lockOrBurn_then_BurnInCCTPMigration_Success() (gas: 309779)
USDCBridgeMigrator_updateChainSelectorMechanism:test_onLockReleaseMechanism_Success() (gas: 147037)
USDCBridgeMigrator_updateChainSelectorMechanism:test_onLockReleaseMechanism_thenswitchToPrimary_Success() (gas: 209263)
USDCTokenPool__validateMessage:test_ValidateInvalidMessage_Revert() (gas: 25854)
USDCTokenPool_lockOrBurn:test_CallerIsNotARampOnRouter_Revert() (gas: 35504)
USDCTokenPool_lockOrBurn:test_LockOrBurnWithAllowList_Revert() (gas: 30235)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,15 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.24;

import {Pool} from "../../libraries/Pool.sol";
import {RateLimiter} from "../../libraries/RateLimiter.sol";
import {BurnFromMintTokenPool} from "../../pools/BurnFromMintTokenPool.sol";
import {TokenPool} from "../../pools/TokenPool.sol";
import {BurnMintSetup} from "./BurnMintSetup.t.sol";
import {Pool} from "../../../libraries/Pool.sol";
import {RateLimiter} from "../../../libraries/RateLimiter.sol";
import {TokenPool} from "../../../pools/TokenPool.sol";
import {BurnFromMintTokenPoolSetup} from "./BurnFromMintTokenPoolSetup.t.sol";

import {IERC20} from "../../../vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/IERC20.sol";

contract BurnFromMintTokenPoolSetup is BurnMintSetup {
BurnFromMintTokenPool internal s_pool;

function setUp() public virtual override {
BurnMintSetup.setUp();

s_pool = new BurnFromMintTokenPool(s_burnMintERC677, new address[](0), address(s_mockRMN), address(s_sourceRouter));
s_burnMintERC677.grantMintAndBurnRoles(address(s_pool));

_applyChainUpdates(address(s_pool));
}
}
import {IERC20} from "../../../../vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/IERC20.sol";

contract BurnFromMintTokenPool_lockOrBurn is BurnFromMintTokenPoolSetup {
function test_Setup_Success() public view {
function test_setup_Success() public view {
assertEq(address(s_burnMintERC677), address(s_pool.getToken()));
assertEq(address(s_mockRMN), s_pool.getRmnProxy());
assertEq(false, s_pool.getAllowListEnabled());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.24;

import {BurnFromMintTokenPool} from "../../../pools/BurnFromMintTokenPool.sol";
import {BurnMintSetup} from "../BurnMintTokenPool/BurnMintSetup.t.sol";

contract BurnFromMintTokenPoolSetup is BurnMintSetup {
BurnFromMintTokenPool internal s_pool;

function setUp() public virtual override {
BurnMintSetup.setUp();

s_pool = new BurnFromMintTokenPool(s_burnMintERC677, new address[](0), address(s_mockRMN), address(s_sourceRouter));
s_burnMintERC677.grantMintAndBurnRoles(address(s_pool));

_applyChainUpdates(address(s_pool));
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.24;

import {BurnMintERC677} from "../../../shared/token/ERC677/BurnMintERC677.sol";
import {Router} from "../../Router.sol";
import {BurnMintTokenPool} from "../../pools/BurnMintTokenPool.sol";
import {TokenPool} from "../../pools/TokenPool.sol";
import {RouterSetup} from "../router/RouterSetup.t.sol";
import {BurnMintERC677} from "../../../../shared/token/ERC677/BurnMintERC677.sol";
import {Router} from "../../../Router.sol";
import {BurnMintTokenPool} from "../../../pools/BurnMintTokenPool.sol";
import {TokenPool} from "../../../pools/TokenPool.sol";
import {RouterSetup} from "../../router/RouterSetup.t.sol";

contract BurnMintSetup is RouterSetup {
BurnMintERC677 internal s_burnMintERC677;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.24;

import {Pool} from "../../libraries/Pool.sol";
import {RateLimiter} from "../../libraries/RateLimiter.sol";
import {BurnMintTokenPool} from "../../pools/BurnMintTokenPool.sol";
import {TokenPool} from "../../pools/TokenPool.sol";
import {Pool} from "../../../libraries/Pool.sol";
import {RateLimiter} from "../../../libraries/RateLimiter.sol";
import {BurnMintTokenPool} from "../../../pools/BurnMintTokenPool.sol";
import {TokenPool} from "../../../pools/TokenPool.sol";
import {BurnMintSetup} from "./BurnMintSetup.t.sol";

import {IERC20} from "../../../vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/IERC20.sol";
import {IERC20} from "../../../../vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/IERC20.sol";

contract BurnMintTokenPoolSetup is BurnMintSetup {
BurnMintTokenPool internal s_pool;
Expand Down Expand Up @@ -98,71 +98,3 @@ contract BurnMintTokenPool_lockOrBurn is BurnMintTokenPoolSetup {
);
}
}

contract BurnMintTokenPool_releaseOrMint is BurnMintTokenPoolSetup {
function test_PoolMint_Success() public {
uint256 amount = 1e19;
address receiver = makeAddr("receiver_address");

vm.startPrank(s_burnMintOffRamp);

vm.expectEmit();
emit IERC20.Transfer(address(0), receiver, amount);

s_pool.releaseOrMint(
Pool.ReleaseOrMintInV1({
originalSender: bytes(""),
receiver: receiver,
amount: amount,
localToken: address(s_burnMintERC677),
remoteChainSelector: DEST_CHAIN_SELECTOR,
sourcePoolAddress: abi.encode(s_remoteBurnMintPool),
sourcePoolData: "",
offchainTokenData: ""
})
);

assertEq(s_burnMintERC677.balanceOf(receiver), amount);
}

function test_PoolMintNotHealthy_Revert() public {
// Should not mint tokens if cursed.
s_mockRMN.setGlobalCursed(true);
uint256 before = s_burnMintERC677.balanceOf(OWNER);
vm.startPrank(s_burnMintOffRamp);

vm.expectRevert(TokenPool.CursedByRMN.selector);
s_pool.releaseOrMint(
Pool.ReleaseOrMintInV1({
originalSender: bytes(""),
receiver: OWNER,
amount: 1e5,
localToken: address(s_burnMintERC677),
remoteChainSelector: DEST_CHAIN_SELECTOR,
sourcePoolAddress: _generateSourceTokenData().sourcePoolAddress,
sourcePoolData: _generateSourceTokenData().extraData,
offchainTokenData: ""
})
);

assertEq(s_burnMintERC677.balanceOf(OWNER), before);
}

function test_ChainNotAllowed_Revert() public {
uint64 wrongChainSelector = 8838833;

vm.expectRevert(abi.encodeWithSelector(TokenPool.ChainNotAllowed.selector, wrongChainSelector));
s_pool.releaseOrMint(
Pool.ReleaseOrMintInV1({
originalSender: bytes(""),
receiver: OWNER,
amount: 1,
localToken: address(s_burnMintERC677),
remoteChainSelector: wrongChainSelector,
sourcePoolAddress: _generateSourceTokenData().sourcePoolAddress,
sourcePoolData: _generateSourceTokenData().extraData,
offchainTokenData: ""
})
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.24;

import {Pool} from "../../../libraries/Pool.sol";
import {BurnMintTokenPool} from "../../../pools/BurnMintTokenPool.sol";
import {TokenPool} from "../../../pools/TokenPool.sol";
import {BurnMintSetup} from "./BurnMintSetup.t.sol";

import {IERC20} from "../../../../vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/IERC20.sol";

contract BurnMintTokenPoolSetup is BurnMintSetup {
BurnMintTokenPool internal s_pool;

function setUp() public virtual override {
BurnMintSetup.setUp();

s_pool = new BurnMintTokenPool(s_burnMintERC677, new address[](0), address(s_mockRMN), address(s_sourceRouter));
s_burnMintERC677.grantMintAndBurnRoles(address(s_pool));

_applyChainUpdates(address(s_pool));
}
}

contract BurnMintTokenPool_releaseOrMint is BurnMintTokenPoolSetup {
function test_PoolMint_Success() public {
uint256 amount = 1e19;
address receiver = makeAddr("receiver_address");

vm.startPrank(s_burnMintOffRamp);

vm.expectEmit();
emit IERC20.Transfer(address(0), receiver, amount);

s_pool.releaseOrMint(
Pool.ReleaseOrMintInV1({
originalSender: bytes(""),
receiver: receiver,
amount: amount,
localToken: address(s_burnMintERC677),
remoteChainSelector: DEST_CHAIN_SELECTOR,
sourcePoolAddress: abi.encode(s_remoteBurnMintPool),
sourcePoolData: "",
offchainTokenData: ""
})
);

assertEq(s_burnMintERC677.balanceOf(receiver), amount);
}

function test_PoolMintNotHealthy_Revert() public {
// Should not mint tokens if cursed.
s_mockRMN.setGlobalCursed(true);
uint256 before = s_burnMintERC677.balanceOf(OWNER);
vm.startPrank(s_burnMintOffRamp);

vm.expectRevert(TokenPool.CursedByRMN.selector);
s_pool.releaseOrMint(
Pool.ReleaseOrMintInV1({
originalSender: bytes(""),
receiver: OWNER,
amount: 1e5,
localToken: address(s_burnMintERC677),
remoteChainSelector: DEST_CHAIN_SELECTOR,
sourcePoolAddress: _generateSourceTokenData().sourcePoolAddress,
sourcePoolData: _generateSourceTokenData().extraData,
offchainTokenData: ""
})
);

assertEq(s_burnMintERC677.balanceOf(OWNER), before);
}

function test_ChainNotAllowed_Revert() public {
uint64 wrongChainSelector = 8838833;

vm.expectRevert(abi.encodeWithSelector(TokenPool.ChainNotAllowed.selector, wrongChainSelector));
s_pool.releaseOrMint(
Pool.ReleaseOrMintInV1({
originalSender: bytes(""),
receiver: OWNER,
amount: 1,
localToken: address(s_burnMintERC677),
remoteChainSelector: wrongChainSelector,
sourcePoolAddress: _generateSourceTokenData().sourcePoolAddress,
sourcePoolData: _generateSourceTokenData().extraData,
offchainTokenData: ""
})
);
}
}
Loading

0 comments on commit dc5c1ec

Please sign in to comment.