diff --git a/deployment/ccip/changeset/test_assertions.go b/deployment/ccip/changeset/test_assertions.go index ad2ea4257ea..a7d3ecf61f8 100644 --- a/deployment/ccip/changeset/test_assertions.go +++ b/deployment/ccip/changeset/test_assertions.go @@ -259,6 +259,40 @@ func (c *commitReportTracker) allCommited(sourceChainSelector uint64) bool { return true } +// ConfirmMultipleCommits waits for multiple ccipocr3.SeqNumRange to be committed by the Offramp. +// Waiting is done in parallel per every sourceChain/destChain (lane) passed as argument. +func ConfirmMultipleCommits( + t *testing.T, + chains map[uint64]deployment.Chain, + state map[uint64]CCIPChainState, + startBlocks map[uint64]*uint64, + enforceSingleCommit bool, + expectedSeqNums map[SourceDestPair]ccipocr3.SeqNumRange, +) error { + errGrp := &errgroup.Group{} + + for sourceDest, seqRange := range expectedSeqNums { + seqRange := seqRange + srcChain := sourceDest.SourceChainSelector + destChain := sourceDest.DestChainSelector + + errGrp.Go(func() error { + _, err := ConfirmCommitWithExpectedSeqNumRange( + t, + chains[srcChain], + chains[destChain], + state[destChain].OffRamp, + startBlocks[destChain], + seqRange, + enforceSingleCommit, + ) + return err + }) + } + + return errGrp.Wait() +} + // ConfirmCommitWithExpectedSeqNumRange waits for a commit report on the destination chain with the expected sequence number range. // startBlock is the block number to start watching from. // If startBlock is nil, it will start watching from the latest block. @@ -449,7 +483,7 @@ func ConfirmExecWithSeqNrs( return nil, fmt.Errorf("no expected sequence numbers provided") } - timer := time.NewTimer(3 * time.Minute) + timer := time.NewTimer(8 * time.Minute) defer timer.Stop() tick := time.NewTicker(3 * time.Second) defer tick.Stop() @@ -564,6 +598,22 @@ func RequireConsistently(t *testing.T, condition func() bool, duration time.Dura } } +func SeqNumberRageToSlice(seqRanges map[SourceDestPair]ccipocr3.SeqNumRange) map[SourceDestPair][]uint64 { + flatten := make(map[SourceDestPair][]uint64) + + for srcDst, seqRange := range seqRanges { + if _, ok := flatten[srcDst]; !ok { + flatten[srcDst] = make([]uint64, 0, seqRange.End()-seqRange.Start()+1) + } + + for i := seqRange.Start(); i <= seqRange.End(); i++ { + flatten[srcDst] = append(flatten[srcDst], uint64(i)) + } + } + + return flatten +} + const ( EXECUTION_STATE_UNTOUCHED = 0 EXECUTION_STATE_INPROGRESS = 1 diff --git a/deployment/ccip/changeset/test_helpers.go b/deployment/ccip/changeset/test_helpers.go index 742fe39200a..eb719450a0a 100644 --- a/deployment/ccip/changeset/test_helpers.go +++ b/deployment/ccip/changeset/test_helpers.go @@ -1225,6 +1225,78 @@ func Transfer( return msgSentEvent, startBlocks } +type TestTransferRequest struct { + Name string + SourceChain, DestChain uint64 + Receiver common.Address + ExpectedStatus int + // optional + Tokens []router.ClientEVMTokenAmount + Data []byte + ExtraArgs []byte + ExpectedTokenBalances map[common.Address]*big.Int +} + +// TransferMultiple sends multiple CCIPMessages (represented as TestTransferRequest) sequentially. +// It verifies whether message is not reverted on the source and proper event is emitted by OnRamp. +// However, it doesn't wait for message to be committed or executed. Therefore, you can send multiple messages very fast, +// but you need to make sure they are committed/executed on your own (if that's the intention). +// It saves some time during test execution, because we let plugins batch instead of executing one by one +// If you want to wait for execution in a "batch" manner you will need to pass maps returned by TransferMultiple to +// either ConfirmMultipleCommits (for commit) or ConfirmExecWithSeqNrsForAll (for exec). Check example usage in the tests. +func TransferMultiple( + ctx context.Context, + t *testing.T, + env deployment.Environment, + state CCIPOnChainState, + requests []TestTransferRequest, +) ( + map[uint64]*uint64, + map[SourceDestPair]cciptypes.SeqNumRange, + map[SourceDestPair]map[uint64]int, + map[uint64]map[TokenReceiverIdentifier]*big.Int, +) { + startBlocks := make(map[uint64]*uint64) + expectedSeqNums := make(map[SourceDestPair]cciptypes.SeqNumRange) + expectedExecutionStates := make(map[SourceDestPair]map[uint64]int) + expectedTokenBalances := make(TokenBalanceAccumulator) + + for _, tt := range requests { + t.Run(tt.Name, func(t *testing.T) { + expectedTokenBalances.add(tt.DestChain, tt.Receiver, tt.ExpectedTokenBalances) + + pairId := SourceDestPair{ + SourceChainSelector: tt.SourceChain, + DestChainSelector: tt.DestChain, + } + + msg, blocks := Transfer( + ctx, t, env, state, tt.SourceChain, tt.DestChain, tt.Tokens, tt.Receiver, tt.Data, tt.ExtraArgs) + if _, ok := expectedExecutionStates[pairId]; !ok { + expectedExecutionStates[pairId] = make(map[uint64]int) + } + expectedExecutionStates[pairId][msg.SequenceNumber] = tt.ExpectedStatus + + if _, ok := startBlocks[tt.DestChain]; !ok { + startBlocks[tt.DestChain] = blocks[tt.DestChain] + } + + seqNr, ok := expectedSeqNums[pairId] + if ok { + expectedSeqNums[pairId] = cciptypes.NewSeqNumRange( + seqNr.Start(), cciptypes.SeqNum(msg.SequenceNumber), + ) + } else { + expectedSeqNums[pairId] = cciptypes.NewSeqNumRange( + cciptypes.SeqNum(msg.SequenceNumber), cciptypes.SeqNum(msg.SequenceNumber), + ) + } + }) + } + + return startBlocks, expectedSeqNums, expectedExecutionStates, expectedTokenBalances +} + // TransferAndWaitForSuccess sends a message from sourceChain to destChain and waits for it to be executed func TransferAndWaitForSuccess( ctx context.Context, @@ -1258,6 +1330,60 @@ func TransferAndWaitForSuccess( require.Equal(t, expectedStatus, states[identifier][msgSentEvent.SequenceNumber]) } +// TokenBalanceAccumulator is a convenient accumulator to aggregate expected balances of different tokens +// used across the tests. You can iterate over your test cases and build the final "expected" balances for tokens (per chain, per sender) +// For instance, if your test runs multiple transfers for the same token, and you want to verify the balance of tokens at +// the end of the execution, you can simply use that struct for aggregating expected tokens +// Please also see WaitForTokenBalances to better understand how you can assert token balances +type TokenBalanceAccumulator map[uint64]map[TokenReceiverIdentifier]*big.Int + +func (t TokenBalanceAccumulator) add( + destChain uint64, + receiver common.Address, + expectedBalance map[common.Address]*big.Int) { + for token, balance := range expectedBalance { + tkIdentifier := TokenReceiverIdentifier{token, receiver} + + if _, ok := t[destChain]; !ok { + t[destChain] = make(map[TokenReceiverIdentifier]*big.Int) + } + actual, ok := t[destChain][tkIdentifier] + if !ok { + actual = big.NewInt(0) + } + t[destChain][tkIdentifier] = new(big.Int).Add(actual, balance) + } +} + +type TokenReceiverIdentifier struct { + token common.Address + receiver common.Address +} + +// WaitForTokenBalances waits for multiple ERC20 tokens to reach a particular balance +// It works in a batch manner, so you can pass and exhaustive list of different tokens (per senders and chains) +// and it would work concurrently for the balance to be met. Check WaitForTheTokenBalance to see how balance +// checking is made for a token/receiver pair +func WaitForTokenBalances( + ctx context.Context, + t *testing.T, + chains map[uint64]deployment.Chain, + expectedBalances map[uint64]map[TokenReceiverIdentifier]*big.Int, +) { + errGrp := &errgroup.Group{} + for chainID, tokens := range expectedBalances { + for id, balance := range tokens { + id := id + balance := balance + errGrp.Go(func() error { + WaitForTheTokenBalance(ctx, t, id.token, id.receiver, chains[chainID], balance) + return nil + }) + } + } + require.NoError(t, errGrp.Wait()) +} + func WaitForTheTokenBalance( ctx context.Context, t *testing.T, diff --git a/integration-tests/smoke/ccip/ccip_token_transfer_test.go b/integration-tests/smoke/ccip/ccip_token_transfer_test.go index 06ee06297ae..81920246bed 100644 --- a/integration-tests/smoke/ccip/ccip_token_transfer_test.go +++ b/integration-tests/smoke/ccip/ccip_token_transfer_test.go @@ -96,54 +96,44 @@ func TestTokenTransfer(t *testing.T) { }, ) - tcs := []struct { - name string - srcChain uint64 - dstChain uint64 - tokenAmounts []router.ClientEVMTokenAmount - receiver common.Address - data []byte - extraData []byte - expectedTokenBalances map[common.Address]*big.Int - expectedExecutionState int - }{ + tcs := []changeset.TestTransferRequest{ { - name: "Send token to EOA", - srcChain: sourceChain, - dstChain: destChain, - tokenAmounts: []router.ClientEVMTokenAmount{ + Name: "Send token to EOA", + SourceChain: sourceChain, + DestChain: destChain, + Tokens: []router.ClientEVMTokenAmount{ { Token: srcToken.Address(), Amount: oneE18, }, }, - receiver: utils.RandomAddress(), - expectedTokenBalances: map[common.Address]*big.Int{ + Receiver: utils.RandomAddress(), + ExpectedTokenBalances: map[common.Address]*big.Int{ destToken.Address(): oneE18, }, - expectedExecutionState: changeset.EXECUTION_STATE_SUCCESS, + ExpectedStatus: changeset.EXECUTION_STATE_SUCCESS, }, { - name: "Send token to contract", - srcChain: sourceChain, - dstChain: destChain, - tokenAmounts: []router.ClientEVMTokenAmount{ + Name: "Send token to contract", + SourceChain: sourceChain, + DestChain: destChain, + Tokens: []router.ClientEVMTokenAmount{ { Token: srcToken.Address(), Amount: oneE18, }, }, - receiver: state.Chains[destChain].Receiver.Address(), - expectedTokenBalances: map[common.Address]*big.Int{ + Receiver: state.Chains[destChain].Receiver.Address(), + ExpectedTokenBalances: map[common.Address]*big.Int{ destToken.Address(): oneE18, }, - expectedExecutionState: changeset.EXECUTION_STATE_SUCCESS, + ExpectedStatus: changeset.EXECUTION_STATE_SUCCESS, }, { - name: "Send N tokens to contract", - srcChain: destChain, - dstChain: sourceChain, - tokenAmounts: []router.ClientEVMTokenAmount{ + Name: "Send N tokens to contract", + SourceChain: destChain, + DestChain: sourceChain, + Tokens: []router.ClientEVMTokenAmount{ { Token: selfServeDestToken.Address(), Amount: oneE18, @@ -157,19 +147,19 @@ func TestTokenTransfer(t *testing.T) { Amount: oneE18, }, }, - receiver: state.Chains[sourceChain].Receiver.Address(), - extraData: changeset.MakeEVMExtraArgsV2(300_000, false), - expectedTokenBalances: map[common.Address]*big.Int{ + Receiver: state.Chains[sourceChain].Receiver.Address(), + ExtraArgs: changeset.MakeEVMExtraArgsV2(300_000, false), + ExpectedTokenBalances: map[common.Address]*big.Int{ selfServeSrcToken.Address(): new(big.Int).Add(oneE18, oneE18), srcToken.Address(): oneE18, }, - expectedExecutionState: changeset.EXECUTION_STATE_SUCCESS, + ExpectedStatus: changeset.EXECUTION_STATE_SUCCESS, }, { - name: "Sending token transfer with custom gasLimits to the EOA is successful", - srcChain: destChain, - dstChain: sourceChain, - tokenAmounts: []router.ClientEVMTokenAmount{ + Name: "Sending token transfer with custom gasLimits to the EOA is successful", + SourceChain: destChain, + DestChain: sourceChain, + Tokens: []router.ClientEVMTokenAmount{ { Token: selfServeDestToken.Address(), Amount: oneE18, @@ -179,19 +169,19 @@ func TestTokenTransfer(t *testing.T) { Amount: new(big.Int).Add(oneE18, oneE18), }, }, - receiver: utils.RandomAddress(), - extraData: changeset.MakeEVMExtraArgsV2(1, false), - expectedTokenBalances: map[common.Address]*big.Int{ + Receiver: utils.RandomAddress(), + ExtraArgs: changeset.MakeEVMExtraArgsV2(1, false), + ExpectedTokenBalances: map[common.Address]*big.Int{ selfServeSrcToken.Address(): oneE18, srcToken.Address(): new(big.Int).Add(oneE18, oneE18), }, - expectedExecutionState: changeset.EXECUTION_STATE_SUCCESS, + ExpectedStatus: changeset.EXECUTION_STATE_SUCCESS, }, { - name: "Sending PTT with too low gas limit leads to the revert when receiver is a contract", - srcChain: destChain, - dstChain: sourceChain, - tokenAmounts: []router.ClientEVMTokenAmount{ + Name: "Sending PTT with too low gas limit leads to the revert when receiver is a contract", + SourceChain: destChain, + DestChain: sourceChain, + Tokens: []router.ClientEVMTokenAmount{ { Token: selfServeDestToken.Address(), Amount: oneE18, @@ -201,45 +191,40 @@ func TestTokenTransfer(t *testing.T) { Amount: oneE18, }, }, - receiver: state.Chains[sourceChain].Receiver.Address(), - data: []byte("this should be reverted because gasLimit is too low, no tokens are transferred as well"), - extraData: changeset.MakeEVMExtraArgsV2(1, false), - expectedTokenBalances: map[common.Address]*big.Int{ + Receiver: state.Chains[sourceChain].Receiver.Address(), + Data: []byte("this should be reverted because gasLimit is too low, no tokens are transferred as well"), + ExtraArgs: changeset.MakeEVMExtraArgsV2(1, false), + ExpectedTokenBalances: map[common.Address]*big.Int{ selfServeSrcToken.Address(): big.NewInt(0), srcToken.Address(): big.NewInt(0), }, - expectedExecutionState: changeset.EXECUTION_STATE_FAILURE, + ExpectedStatus: changeset.EXECUTION_STATE_FAILURE, }, } - for _, tt := range tcs { - t.Run(tt.name, func(t *testing.T) { - initialBalances := map[common.Address]*big.Int{} - for token := range tt.expectedTokenBalances { - initialBalance := changeset.GetTokenBalance(ctx, t, token, tt.receiver, e.Chains[tt.dstChain]) - initialBalances[token] = initialBalance - } + startBlocks, expectedSeqNums, expectedExecutionStates, expectedTokenBalances := + changeset.TransferMultiple(ctx, t, e, state, tcs) - changeset.TransferAndWaitForSuccess( - ctx, - t, - e, - state, - tt.srcChain, - tt.dstChain, - tt.tokenAmounts, - tt.receiver, - tt.data, - tt.expectedExecutionState, - tt.extraData, - ) + err = changeset.ConfirmMultipleCommits( + t, + e.Chains, + state.Chains, + startBlocks, + false, + expectedSeqNums, + ) + require.NoError(t, err) - for token, balance := range tt.expectedTokenBalances { - expected := new(big.Int).Add(initialBalances[token], balance) - changeset.WaitForTheTokenBalance(ctx, t, token, tt.receiver, e.Chains[tt.dstChain], expected) - } - }) - } + execStates := changeset.ConfirmExecWithSeqNrsForAll( + t, + e, + state, + changeset.SeqNumberRageToSlice(expectedSeqNums), + startBlocks, + ) + require.Equal(t, expectedExecutionStates, execStates) + + changeset.WaitForTokenBalances(ctx, t, e.Chains, expectedTokenBalances) } func createAndFundSelfServeActor( diff --git a/integration-tests/smoke/ccip/ccip_usdc_test.go b/integration-tests/smoke/ccip/ccip_usdc_test.go index d1df2a6da92..eacf03df926 100644 --- a/integration-tests/smoke/ccip/ccip_usdc_test.go +++ b/integration-tests/smoke/ccip/ccip_usdc_test.go @@ -11,12 +11,10 @@ import ( "golang.org/x/sync/errgroup" "github.com/smartcontractkit/chainlink-common/pkg/utils/tests" - "github.com/smartcontractkit/chainlink-testing-framework/lib/utils/testcontext" "github.com/smartcontractkit/chainlink/deployment" "github.com/smartcontractkit/chainlink/deployment/ccip/changeset" testsetups "github.com/smartcontractkit/chainlink/integration-tests/testsetups/ccip" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils" - "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/onramp" "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" @@ -37,7 +35,12 @@ func TestUSDCTokenTransfer(t *testing.T) { IsUSDC: true, } tenv, _, _ := testsetups.NewLocalDevEnvironmentWithDefaultPrice(t, lggr, config) - //tenv := changeset.NewMemoryEnvironmentWithJobsAndContracts(t, lggr, 3, 4, config) + //tenv := changeset.NewMemoryEnvironmentWithJobsAndContracts(t, lggr, memory.MemoryEnvironmentConfig{ + // Chains: 3, + // NumOfUsersPerChain: 3, + // Nodes: 5, + // Bootstraps: 1, + //}, config) e := tenv.Env state, err := changeset.LoadOnchainState(e) @@ -97,37 +100,28 @@ func TestUSDCTokenTransfer(t *testing.T) { // MockE2EUSDCTransmitter always mint 1, see MockE2EUSDCTransmitter.sol for more details tinyOneCoin := new(big.Int).SetUint64(1) - tcs := []struct { - name string - receiver common.Address - sourceChain uint64 - destChain uint64 - tokens []router.ClientEVMTokenAmount - data []byte - expectedTokenBalances map[common.Address]*big.Int - expectedExecutionState int - }{ + tcs := []changeset.TestTransferRequest{ { - name: "single USDC token transfer to EOA", - receiver: utils.RandomAddress(), - sourceChain: chainC, - destChain: chainA, - tokens: []router.ClientEVMTokenAmount{ + Name: "single USDC token transfer to EOA", + Receiver: utils.RandomAddress(), + SourceChain: chainC, + DestChain: chainA, + Tokens: []router.ClientEVMTokenAmount{ { Token: cChainUSDC.Address(), Amount: tinyOneCoin, }}, - expectedTokenBalances: map[common.Address]*big.Int{ + ExpectedTokenBalances: map[common.Address]*big.Int{ aChainUSDC.Address(): tinyOneCoin, }, - expectedExecutionState: changeset.EXECUTION_STATE_SUCCESS, + ExpectedStatus: changeset.EXECUTION_STATE_SUCCESS, }, { - name: "multiple USDC tokens within the same message", - receiver: utils.RandomAddress(), - sourceChain: chainC, - destChain: chainA, - tokens: []router.ClientEVMTokenAmount{ + Name: "multiple USDC tokens within the same message", + Receiver: utils.RandomAddress(), + SourceChain: chainC, + DestChain: chainA, + Tokens: []router.ClientEVMTokenAmount{ { Token: cChainUSDC.Address(), Amount: tinyOneCoin, @@ -137,18 +131,18 @@ func TestUSDCTokenTransfer(t *testing.T) { Amount: tinyOneCoin, }, }, - expectedTokenBalances: map[common.Address]*big.Int{ - // 2 coins because of the same receiver + ExpectedTokenBalances: map[common.Address]*big.Int{ + // 2 coins because of the same Receiver aChainUSDC.Address(): new(big.Int).Add(tinyOneCoin, tinyOneCoin), }, - expectedExecutionState: changeset.EXECUTION_STATE_SUCCESS, + ExpectedStatus: changeset.EXECUTION_STATE_SUCCESS, }, { - name: "USDC token together with another token transferred to EOA", - receiver: utils.RandomAddress(), - sourceChain: chainA, - destChain: chainC, - tokens: []router.ClientEVMTokenAmount{ + Name: "USDC token together with another token transferred to EOA", + Receiver: utils.RandomAddress(), + SourceChain: chainA, + DestChain: chainC, + Tokens: []router.ClientEVMTokenAmount{ { Token: aChainUSDC.Address(), Amount: tinyOneCoin, @@ -158,105 +152,89 @@ func TestUSDCTokenTransfer(t *testing.T) { Amount: new(big.Int).Mul(tinyOneCoin, big.NewInt(10)), }, }, - expectedTokenBalances: map[common.Address]*big.Int{ + ExpectedTokenBalances: map[common.Address]*big.Int{ cChainUSDC.Address(): tinyOneCoin, cChainToken.Address(): new(big.Int).Mul(tinyOneCoin, big.NewInt(10)), }, - expectedExecutionState: changeset.EXECUTION_STATE_SUCCESS, + ExpectedStatus: changeset.EXECUTION_STATE_SUCCESS, }, { - name: "programmable token transfer to valid contract receiver", - receiver: state.Chains[chainC].Receiver.Address(), - sourceChain: chainA, - destChain: chainC, - tokens: []router.ClientEVMTokenAmount{ + Name: "USDC programmable token transfer to valid contract receiver", + Receiver: state.Chains[chainC].Receiver.Address(), + SourceChain: chainA, + DestChain: chainC, + Tokens: []router.ClientEVMTokenAmount{ { Token: aChainUSDC.Address(), Amount: tinyOneCoin, }, }, - data: []byte("hello world"), - expectedTokenBalances: map[common.Address]*big.Int{ + Data: []byte("hello world"), + ExpectedTokenBalances: map[common.Address]*big.Int{ cChainUSDC.Address(): tinyOneCoin, }, - expectedExecutionState: changeset.EXECUTION_STATE_SUCCESS, + ExpectedStatus: changeset.EXECUTION_STATE_SUCCESS, + }, + { + Name: "USDC programmable token transfer with too little gas", + Receiver: state.Chains[chainB].Receiver.Address(), + SourceChain: chainC, + DestChain: chainB, + Tokens: []router.ClientEVMTokenAmount{ + { + Token: cChainUSDC.Address(), + Amount: tinyOneCoin, + }, + }, + Data: []byte("gimme more gas to execute that!"), + ExpectedTokenBalances: map[common.Address]*big.Int{ + bChainUSDC.Address(): new(big.Int).SetUint64(0), + }, + ExtraArgs: changeset.MakeEVMExtraArgsV2(1, false), + ExpectedStatus: changeset.EXECUTION_STATE_FAILURE, + }, + { + Name: "USDC token transfer from a different source chain", + Receiver: utils.RandomAddress(), + SourceChain: chainB, + DestChain: chainC, + Tokens: []router.ClientEVMTokenAmount{ + { + Token: bChainUSDC.Address(), + Amount: tinyOneCoin, + }, + }, + Data: nil, + ExpectedTokenBalances: map[common.Address]*big.Int{ + cChainUSDC.Address(): tinyOneCoin, + }, + ExpectedStatus: changeset.EXECUTION_STATE_SUCCESS, }, } - for _, tt := range tcs { - t.Run(tt.name, func(t *testing.T) { - initialBalances := map[common.Address]*big.Int{} - for token := range tt.expectedTokenBalances { - initialBalance := changeset.GetTokenBalance(ctx, t, token, tt.receiver, e.Chains[tt.destChain]) - initialBalances[token] = initialBalance - } - - changeset.TransferAndWaitForSuccess( - ctx, - t, - e, - state, - tt.sourceChain, - tt.destChain, - tt.tokens, - tt.receiver, - tt.data, - tt.expectedExecutionState, - nil, - ) - - for token, balance := range tt.expectedTokenBalances { - expected := new(big.Int).Add(initialBalances[token], balance) - changeset.WaitForTheTokenBalance(ctx, t, token, tt.receiver, e.Chains[tt.destChain], expected) - } - }) - } - - t.Run("multi-source USDC transfer targeting the same dest receiver", func(t *testing.T) { - sendSingleTokenTransfer := func(source, dest uint64, token common.Address, receiver common.Address) (*onramp.OnRampCCIPMessageSent, changeset.SourceDestPair) { - msg := changeset.TestSendRequest(t, e, state, source, dest, false, router.ClientEVM2AnyMessage{ - Receiver: common.LeftPadBytes(receiver.Bytes(), 32), - Data: []byte{}, - TokenAmounts: []router.ClientEVMTokenAmount{{Token: token, Amount: tinyOneCoin}}, - FeeToken: common.HexToAddress("0x0"), - ExtraArgs: nil, - }) - return msg, changeset.SourceDestPair{ - SourceChainSelector: source, - DestChainSelector: dest, - } - } - - receiver := utils.RandomAddress() - - startBlocks := make(map[uint64]*uint64) - expectedSeqNum := make(map[changeset.SourceDestPair]uint64) - expectedSeqNumExec := make(map[changeset.SourceDestPair][]uint64) + startBlocks, expectedSeqNums, expectedExecutionStates, expectedTokenBalances := + changeset.TransferMultiple(ctx, t, e, state, tcs) - latesthdr, err := e.Chains[chainC].Client.HeaderByNumber(testcontext.Get(t), nil) - require.NoError(t, err) - block := latesthdr.Number.Uint64() - startBlocks[chainC] = &block - - message1, message1ID := sendSingleTokenTransfer(chainA, chainC, aChainUSDC.Address(), receiver) - expectedSeqNum[message1ID] = message1.SequenceNumber - expectedSeqNumExec[message1ID] = []uint64{message1.SequenceNumber} - - message2, message2ID := sendSingleTokenTransfer(chainB, chainC, bChainUSDC.Address(), receiver) - expectedSeqNum[message2ID] = message2.SequenceNumber - expectedSeqNumExec[message2ID] = []uint64{message2.SequenceNumber} - - changeset.ConfirmCommitForAllWithExpectedSeqNums(t, e, state, expectedSeqNum, startBlocks) - states := changeset.ConfirmExecWithSeqNrsForAll(t, e, state, expectedSeqNumExec, startBlocks) + err = changeset.ConfirmMultipleCommits( + t, + e.Chains, + state.Chains, + startBlocks, + false, + expectedSeqNums, + ) + require.NoError(t, err) - require.Equal(t, changeset.EXECUTION_STATE_SUCCESS, states[message1ID][message1.SequenceNumber]) - require.Equal(t, changeset.EXECUTION_STATE_SUCCESS, states[message2ID][message2.SequenceNumber]) + execStates := changeset.ConfirmExecWithSeqNrsForAll( + t, + e, + state, + changeset.SeqNumberRageToSlice(expectedSeqNums), + startBlocks, + ) + require.Equal(t, expectedExecutionStates, execStates) - // We sent 1 coin from each source chain, so we should have 2 coins on the destination chain - // Receiver is randomly generated so we don't need to get the initial balance first - expectedBalance := new(big.Int).Add(tinyOneCoin, tinyOneCoin) - changeset.WaitForTheTokenBalance(ctx, t, cChainUSDC.Address(), receiver, e.Chains[chainC], expectedBalance) - }) + changeset.WaitForTokenBalances(ctx, t, e.Chains, expectedTokenBalances) } func updateFeeQuoters( @@ -274,7 +252,11 @@ func updateFeeQuoters( return changeset.UpdateFeeQuoterForUSDC(lggr, e.Chains[chainB], state.Chains[chainB], chainC, bChainUSDC) }) updateFeeQtrGrp.Go(func() error { - return changeset.UpdateFeeQuoterForUSDC(lggr, e.Chains[chainC], state.Chains[chainC], chainA, cChainUSDC) + err1 := changeset.UpdateFeeQuoterForUSDC(lggr, e.Chains[chainC], state.Chains[chainC], chainA, cChainUSDC) + if err1 != nil { + return err1 + } + return changeset.UpdateFeeQuoterForUSDC(lggr, e.Chains[chainC], state.Chains[chainC], chainB, cChainUSDC) }) return updateFeeQtrGrp.Wait() }