From 7b19b406019a9c5a053af50950917bd93fde08f8 Mon Sep 17 00:00:00 2001 From: Chunkai Yang Date: Tue, 7 Nov 2023 09:11:53 -0500 Subject: [PATCH] Simple test to include USDC burn in snapshot (#261) --- contracts/gas-snapshots/ccip.gas-snapshot | 7 ++-- .../v0.8/ccip/test/pools/USDCTokenPool.t.sol | 38 +++++++++++++++++++ 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/contracts/gas-snapshots/ccip.gas-snapshot b/contracts/gas-snapshots/ccip.gas-snapshot index 87deccaf75..cb3d4c9f7d 100644 --- a/contracts/gas-snapshots/ccip.gas-snapshot +++ b/contracts/gas-snapshots/ccip.gas-snapshot @@ -399,9 +399,10 @@ TokenProxy_getFee:testGetFeeInvalidTokenReverts() (gas: 12628) TokenProxy_getFee:testGetFeeNoDataAllowedReverts() (gas: 15775) TokenProxy_getFee:testGetFeeSuccess() (gas: 74453) USDCTokenPool__validateMessage:testValidateInvalidMessageReverts() (gas: 25338) -USDCTokenPool_lockOrBurn:testLockOrBurnWithAllowListReverts() (gas: 21968) -USDCTokenPool_lockOrBurn:testPermissionsErrorReverts() (gas: 12498) -USDCTokenPool_lockOrBurn:testUnknownDomainReverts() (gas: 183561) +USDCTokenPool_lockOrBurn:testLockOrBurnSuccess() (gas: 92355) +USDCTokenPool_lockOrBurn:testLockOrBurnWithAllowListReverts() (gas: 21946) +USDCTokenPool_lockOrBurn:testPermissionsErrorReverts() (gas: 12476) +USDCTokenPool_lockOrBurn:testUnknownDomainReverts() (gas: 183544) USDCTokenPool_releaseOrMint:testReleaseOrMintRealTxSuccess() (gas: 56035) USDCTokenPool_releaseOrMint:testTokenMaxCapacityExceededReverts() (gas: 27922) USDCTokenPool_releaseOrMint:testUnlockingUSDCFailedReverts() (gas: 50764) diff --git a/contracts/src/v0.8/ccip/test/pools/USDCTokenPool.t.sol b/contracts/src/v0.8/ccip/test/pools/USDCTokenPool.t.sol index 13e5a61ace..9e8696d934 100644 --- a/contracts/src/v0.8/ccip/test/pools/USDCTokenPool.t.sol +++ b/contracts/src/v0.8/ccip/test/pools/USDCTokenPool.t.sol @@ -146,6 +146,44 @@ contract USDCTokenPool_lockOrBurn is USDCTokenPoolSetup { event Burned(address indexed sender, uint256 amount); event TokensConsumed(uint256 tokens); + // Base test case, included for PR gas comparisons as fuzz tests are excluded from forge snapshot due to being flaky. + function testLockOrBurnSuccess() public { + bytes32 receiver = bytes32(uint256(uint160(STRANGER))); + uint256 amount = 1; + changePrank(s_routerAllowedOnRamp); + s_token.approve(address(s_usdcTokenPool), amount); + + USDCTokenPool.Domain memory expectedDomain = s_usdcTokenPool.getDomain(DEST_CHAIN_ID); + + vm.expectEmit(); + emit TokensConsumed(amount); + + vm.expectEmit(); + emit DepositForBurn( + s_mockUSDC.s_nonce(), + address(s_token), + amount, + address(s_usdcTokenPool), + receiver, + expectedDomain.domainIdentifier, + s_mockUSDC.i_destinationTokenMessenger(), + expectedDomain.allowedCaller + ); + + vm.expectEmit(); + emit Burned(s_routerAllowedOnRamp, amount); + + bytes memory encodedNonce = s_usdcTokenPool.lockOrBurn( + OWNER, + abi.encodePacked(receiver), + amount, + DEST_CHAIN_ID, + bytes("") + ); + uint64 nonce = abi.decode(encodedNonce, (uint64)); + assertEq(s_mockUSDC.s_nonce() - 1, nonce); + } + function testFuzz_LockOrBurnSuccess(bytes32 destinationReceiver, uint256 amount) public { vm.assume(amount < rateLimiterConfig().capacity); vm.assume(amount > 0);