Skip to content

Commit

Permalink
Use the same setup instead of separate ones (aka deploy once)
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusz-sekara committed Nov 22, 2024
1 parent 945fc73 commit 9c73a3d
Showing 1 changed file with 84 additions and 107 deletions.
191 changes: 84 additions & 107 deletions integration-tests/smoke/ccip/ccip_usdc_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package smoke

import (
"github.com/smartcontractkit/chainlink/integration-tests/testsetups"
"math/big"
"testing"
"time"
Expand All @@ -16,37 +17,47 @@ import (

"github.com/smartcontractkit/chainlink/deployment"
"github.com/smartcontractkit/chainlink/deployment/ccip/changeset"
"github.com/smartcontractkit/chainlink/integration-tests/testsetups"

"github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/router"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/shared/generated/burn_mint_erc677"
"github.com/smartcontractkit/chainlink/v2/core/logger"
)

/*
* Chain topology for this test
* sourceChain1 (USDC, MY_TOKEN)
* |
* | ------- destChain (USDC, MY_TOKEN)
* |
* sourceChain2 (USDC)
*/
func TestUSDCTokenTransfer(t *testing.T) {
lggr := logger.TestLogger(t)
config := &changeset.TestConfigs{
IsUSDC: true,
}
tenv, _, _ := testsetups.NewLocalDevEnvironmentWithDefaultPrice(t, lggr, config)
//tenv := changeset.NewMemoryEnvironmentWithJobsAndContracts(t, lggr, 2, 4, config)
//tenv := changeset.NewMemoryEnvironmentWithJobsAndContracts(t, lggr, 3, 4, config)

e := tenv.Env
state, err := changeset.LoadOnchainState(e)
require.NoError(t, err)

allChainSelectors := maps.Keys(e.Chains)
sourceChain := allChainSelectors[0]
sourceChain1 := allChainSelectors[0]
destChain := allChainSelectors[1]
sourceChain2 := allChainSelectors[2]

srcUSDC, dstUSDC, err := changeset.ConfigureUSDCTokenPools(lggr, e.Chains, sourceChain, destChain, state)
sourceUSDC1, destUSDC, err := changeset.ConfigureUSDCTokenPools(lggr, e.Chains, sourceChain1, destChain, state)
require.NoError(t, err)

srcToken, _, dstToken, _, err := changeset.DeployTransferableToken(
sourceUSDC2, _, err := changeset.ConfigureUSDCTokenPools(lggr, e.Chains, sourceChain2, destChain, state)
require.NoError(t, err)

sourceToken1, _, destToken, _, err := changeset.DeployTransferableToken(
lggr,
tenv.Env.Chains,
sourceChain,
sourceChain1,
destChain,
state,
e.ExistingAddresses,
Expand All @@ -58,14 +69,18 @@ func TestUSDCTokenTransfer(t *testing.T) {
require.NoError(t, changeset.AddLanesForAll(e, state))

mintAndAllow(t, e, state, map[uint64][]*burn_mint_erc677.BurnMintERC677{
sourceChain: {srcUSDC, srcToken},
destChain: {dstUSDC, dstToken},
sourceChain1: {sourceUSDC1, sourceToken1},
sourceChain2: {sourceUSDC2},
destChain: {destUSDC, destToken},
})

err = changeset.UpdateFeeQuoterForUSDC(lggr, e.Chains[sourceChain], state.Chains[sourceChain], destChain, srcUSDC)
err = changeset.UpdateFeeQuoterForUSDC(lggr, e.Chains[sourceChain1], state.Chains[sourceChain1], destChain, sourceUSDC1)
require.NoError(t, err)

err = changeset.UpdateFeeQuoterForUSDC(lggr, e.Chains[destChain], state.Chains[destChain], sourceChain, dstUSDC)
err = changeset.UpdateFeeQuoterForUSDC(lggr, e.Chains[sourceChain2], state.Chains[sourceChain2], destChain, sourceUSDC2)
require.NoError(t, err)

err = changeset.UpdateFeeQuoterForUSDC(lggr, e.Chains[destChain], state.Chains[destChain], sourceChain1, destUSDC)
require.NoError(t, err)

// MockE2EUSDCTransmitter always mint 1, see MockE2EUSDCTransmitter.sol for more details
Expand All @@ -85,73 +100,73 @@ func TestUSDCTokenTransfer(t *testing.T) {
name: "single USDC token transfer to EOA",
receiver: utils.RandomAddress(),
sourceChain: destChain,
destChain: sourceChain,
destChain: sourceChain1,
tokens: []router.ClientEVMTokenAmount{
{
Token: dstUSDC.Address(),
Token: destUSDC.Address(),
Amount: tinyOneCoin,
}},
expectedTokenBalances: map[common.Address]*big.Int{
srcUSDC.Address(): tinyOneCoin,
sourceUSDC1.Address(): tinyOneCoin,
},
expectedExecutionState: changeset.EXECUTION_STATE_SUCCESS,
},
{
name: "multiple USDC tokens within the same message",
receiver: utils.RandomAddress(),
sourceChain: destChain,
destChain: sourceChain,
destChain: sourceChain1,
tokens: []router.ClientEVMTokenAmount{
{
Token: dstUSDC.Address(),
Token: destUSDC.Address(),
Amount: tinyOneCoin,
},
{
Token: dstUSDC.Address(),
Token: destUSDC.Address(),
Amount: tinyOneCoin,
},
},
expectedTokenBalances: map[common.Address]*big.Int{
// 2 coins because of the same receiver
srcUSDC.Address(): new(big.Int).Add(tinyOneCoin, tinyOneCoin),
sourceUSDC1.Address(): new(big.Int).Add(tinyOneCoin, tinyOneCoin),
},
expectedExecutionState: changeset.EXECUTION_STATE_SUCCESS,
},
{
name: "USDC token together with another token transferred to EOA",
receiver: utils.RandomAddress(),
sourceChain: sourceChain,
sourceChain: sourceChain1,
destChain: destChain,
tokens: []router.ClientEVMTokenAmount{
{
Token: srcUSDC.Address(),
Token: sourceUSDC1.Address(),
Amount: tinyOneCoin,
},
{
Token: srcToken.Address(),
Token: sourceToken1.Address(),
Amount: new(big.Int).Mul(tinyOneCoin, big.NewInt(10)),
},
},
expectedTokenBalances: map[common.Address]*big.Int{
dstUSDC.Address(): tinyOneCoin,
dstToken.Address(): new(big.Int).Mul(tinyOneCoin, big.NewInt(10)),
destUSDC.Address(): tinyOneCoin,
destToken.Address(): new(big.Int).Mul(tinyOneCoin, big.NewInt(10)),
},
expectedExecutionState: changeset.EXECUTION_STATE_SUCCESS,
},
{
name: "programmable token transfer to valid contract receiver",
receiver: state.Chains[destChain].Receiver.Address(),
sourceChain: sourceChain,
sourceChain: sourceChain1,
destChain: destChain,
tokens: []router.ClientEVMTokenAmount{
{
Token: srcUSDC.Address(),
Token: sourceUSDC1.Address(),
Amount: tinyOneCoin,
},
},
data: []byte("hello world"),
expectedTokenBalances: map[common.Address]*big.Int{
dstUSDC.Address(): tinyOneCoin,
destUSDC.Address(): tinyOneCoin,
},
expectedExecutionState: changeset.EXECUTION_STATE_SUCCESS,
},
Expand Down Expand Up @@ -183,95 +198,57 @@ func TestUSDCTokenTransfer(t *testing.T) {
}
})
}
}

func TestMultiSourceUSDCTransfer(t *testing.T) {
lggr := logger.TestLogger(t)
tenv, _, _ := testsetups.NewLocalDevEnvironmentWithDefaultPrice(t, lggr, &changeset.TestConfigs{
IsUSDC: true,
})

e := tenv.Env
allChainSelectors := maps.Keys(e.Chains)
sourceChain1 := allChainSelectors[0]
sourceChain2 := allChainSelectors[1]
destChain := allChainSelectors[2]

state, err := changeset.LoadOnchainState(e)
require.NoError(t, err)

sourceUSDC1, dstUSDC, err := changeset.ConfigureUSDCTokenPools(lggr, e.Chains, sourceChain1, destChain, state)
require.NoError(t, err)

sourceUSDC2, _, err := changeset.ConfigureUSDCTokenPools(lggr, e.Chains, sourceChain2, destChain, state)
require.NoError(t, err)

// Add all lanes
require.NoError(t, changeset.AddLanesForAll(e, state))

mintAndAllow(t, e, state, map[uint64][]*burn_mint_erc677.BurnMintERC677{
sourceChain1: {sourceUSDC1},
sourceChain2: {sourceUSDC2},
destChain: {dstUSDC},
})

err = changeset.UpdateFeeQuoterForUSDC(lggr, e.Chains[sourceChain1], state.Chains[sourceChain1], destChain, sourceUSDC1)
require.NoError(t, err)
t.Run("multi-source USDC transfer targeting the same dest receiver", func(t *testing.T) {
receiver := utils.RandomAddress()

err = changeset.UpdateFeeQuoterForUSDC(lggr, e.Chains[sourceChain2], state.Chains[sourceChain2], destChain, sourceUSDC2)
require.NoError(t, err)

// MockE2EUSDCTransmitter always mint 1, see MockE2EUSDCTransmitter.sol for more details
tinyOneCoin := new(big.Int).SetUint64(1)
startBlocks := make(map[uint64]*uint64)
expectedSeqNum := make(map[changeset.SourceDestPair]uint64)
expectedSeqNumExec := make(map[changeset.SourceDestPair][]uint64)

receiver := utils.RandomAddress()
latesthdr, err := e.Chains[destChain].Client.HeaderByNumber(testcontext.Get(t), nil)
require.NoError(t, err)
block := latesthdr.Number.Uint64()
startBlocks[destChain] = &block

startBlocks := make(map[uint64]*uint64)
expectedSeqNum := make(map[changeset.SourceDestPair]uint64)
expectedSeqNumExec := make(map[changeset.SourceDestPair][]uint64)
message1ID := changeset.SourceDestPair{
SourceChainSelector: sourceChain1,
DestChainSelector: destChain,
}
message1 := changeset.TestSendRequest(t, e, state, sourceChain1, destChain, false, router.ClientEVM2AnyMessage{
Receiver: common.LeftPadBytes(receiver.Bytes(), 32),
Data: []byte{},
TokenAmounts: []router.ClientEVMTokenAmount{{Token: sourceUSDC1.Address(), Amount: tinyOneCoin}},
FeeToken: common.HexToAddress("0x0"),
ExtraArgs: nil,
})
expectedSeqNum[message1ID] = message1.SequenceNumber
expectedSeqNumExec[message1ID] = []uint64{message1.SequenceNumber}

message2 := changeset.TestSendRequest(t, e, state, sourceChain2, destChain, false, router.ClientEVM2AnyMessage{
Receiver: common.LeftPadBytes(receiver.Bytes(), 32),
Data: []byte{},
TokenAmounts: []router.ClientEVMTokenAmount{{Token: sourceUSDC2.Address(), Amount: tinyOneCoin}},
FeeToken: common.HexToAddress("0x0"),
ExtraArgs: nil,
})
message2ID := changeset.SourceDestPair{
SourceChainSelector: sourceChain2,
DestChainSelector: destChain,
}
expectedSeqNum[message2ID] = message2.SequenceNumber
expectedSeqNumExec[message2ID] = []uint64{message2.SequenceNumber}

latesthdr, err := e.Chains[destChain].Client.HeaderByNumber(testcontext.Get(t), nil)
require.NoError(t, err)
block := latesthdr.Number.Uint64()
startBlocks[destChain] = &block
changeset.ConfirmCommitForAllWithExpectedSeqNums(t, e, state, expectedSeqNum, startBlocks)
states := changeset.ConfirmExecWithSeqNrsForAll(t, e, state, expectedSeqNumExec, startBlocks)

message1ID := changeset.SourceDestPair{
SourceChainSelector: sourceChain1,
DestChainSelector: destChain,
}
message1 := changeset.TestSendRequest(t, e, state, sourceChain1, destChain, false, router.ClientEVM2AnyMessage{
Receiver: common.LeftPadBytes(receiver.Bytes(), 32),
Data: []byte{},
TokenAmounts: []router.ClientEVMTokenAmount{{Token: sourceUSDC1.Address(), Amount: tinyOneCoin}},
FeeToken: common.HexToAddress("0x0"),
ExtraArgs: nil,
})
expectedSeqNum[message1ID] = message1.SequenceNumber
expectedSeqNumExec[message1ID] = []uint64{message1.SequenceNumber}
require.Equal(t, changeset.EXECUTION_STATE_SUCCESS, states[message1ID][message1.SequenceNumber])
require.Equal(t, changeset.EXECUTION_STATE_SUCCESS, states[message2ID][message2.SequenceNumber])

message2 := changeset.TestSendRequest(t, e, state, sourceChain2, destChain, false, router.ClientEVM2AnyMessage{
Receiver: common.LeftPadBytes(receiver.Bytes(), 32),
Data: []byte{},
TokenAmounts: []router.ClientEVMTokenAmount{{Token: sourceUSDC2.Address(), Amount: tinyOneCoin}},
FeeToken: common.HexToAddress("0x0"),
ExtraArgs: nil,
// We sent 1 coin from each source chain, so we should have 2 coins on the destination chain
expectedBalance := new(big.Int).Add(tinyOneCoin, tinyOneCoin)
waitForTheTokenBalance(t, destUSDC.Address(), receiver, e.Chains[destChain], expectedBalance)
})
message2ID := changeset.SourceDestPair{
SourceChainSelector: sourceChain2,
DestChainSelector: destChain,
}
expectedSeqNum[message2ID] = message2.SequenceNumber
expectedSeqNumExec[message2ID] = []uint64{message2.SequenceNumber}

changeset.ConfirmCommitForAllWithExpectedSeqNums(t, e, state, expectedSeqNum, startBlocks)
states := changeset.ConfirmExecWithSeqNrsForAll(t, e, state, expectedSeqNumExec, startBlocks)

require.Equal(t, changeset.EXECUTION_STATE_SUCCESS, states[message1ID][message1.SequenceNumber])
require.Equal(t, changeset.EXECUTION_STATE_SUCCESS, states[message2ID][message2.SequenceNumber])

// We sent 1 coin from each source chain, so we should have 2 coins on the destination chain
expectedBalance := new(big.Int).Add(tinyOneCoin, tinyOneCoin)
waitForTheTokenBalance(t, dstUSDC.Address(), receiver, e.Chains[destChain], expectedBalance)
}

// mintAndAllow mints tokens for deployers and allow router to spend them
Expand Down

0 comments on commit 9c73a3d

Please sign in to comment.