From 52ecab85afd73913501a5c89b174948405eccee1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20Hrastnik?= Date: Fri, 17 Jan 2025 17:14:25 +0900 Subject: [PATCH] ccip_messaging_test: GetLatestNonce --- .../smoke/ccip/ccip_messaging_test.go | 31 ++++++++++++++----- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/integration-tests/smoke/ccip/ccip_messaging_test.go b/integration-tests/smoke/ccip/ccip_messaging_test.go index c4153205442..b41f6491b1c 100644 --- a/integration-tests/smoke/ccip/ccip_messaging_test.go +++ b/integration-tests/smoke/ccip/ccip_messaging_test.go @@ -12,6 +12,7 @@ import ( "github.com/stretchr/testify/require" "golang.org/x/exp/maps" + chain_selectors "github.com/smartcontractkit/chain-selectors" "github.com/smartcontractkit/chainlink-common/pkg/hashutil" "github.com/smartcontractkit/chainlink-common/pkg/merklemulti" "github.com/smartcontractkit/chainlink-common/pkg/utils/tests" @@ -298,6 +299,26 @@ func sleepAndReplay(t *testing.T, e testhelpers.DeployedEnv, sourceChain, destCh testhelpers.ReplayLogs(t, e.Env.Offchain, replayBlocks) } +func GetLatestNonce(tc messagingTestCase) uint64 { + family, err := chain_selectors.GetSelectorFamily(tc.destChain) + require.NoError(tc.t, err) + + var latestNonce uint64 + switch family { + case chain_selectors.FamilyEVM: + latestNonce, err = tc.onchainState.Chains[tc.destChain].NonceManager.GetInboundNonce(&bind.CallOpts{ + Context: tests.Context(tc.t), + }, tc.sourceChain, tc.sender) + require.NoError(tc.t, err) + case chain_selectors.FamilySolana: + // var nonceCounterAccount ccip_router.Nonce + // err = common.GetAccountDataBorshInto(ctx, solanaGoClient, nonceEvmPDA, config.DefaultCommitment, &nonceCounterAccount) + // require.NoError(t, err, "failed to get account info") + // require.Equal(t, uint64(1), nonceCounterAccount.Counter) + } + return latestNonce +} + func runMessagingTestCase( tc messagingTestCase, receiver []byte, @@ -307,10 +328,7 @@ func runMessagingTestCase( extraAssertions ...func(t *testing.T), ) (out messagingTestCaseOutput) { // check latest nonce - latestNonce, err := tc.onchainState.Chains[tc.destChain].NonceManager.GetInboundNonce(&bind.CallOpts{ - Context: tests.Context(tc.t), - }, tc.sourceChain, tc.sender) - require.NoError(tc.t, err) + latestNonce := GetLatestNonce(tc) require.Equal(tc.t, tc.nonce, latestNonce) require.LessOrEqual(tc.t, 32, receiver) @@ -362,10 +380,7 @@ func runMessagingTestCase( ) // check the sender latestNonce on the dest, should be incremented - latestNonce, err = tc.onchainState.Chains[tc.destChain].NonceManager.GetInboundNonce(&bind.CallOpts{ - Context: tests.Context(tc.t), - }, tc.sourceChain, tc.sender) - require.NoError(tc.t, err) + latestNonce = GetLatestNonce(tc) require.Equal(tc.t, tc.nonce+1, latestNonce) out.nonce = latestNonce tc.t.Logf("confirmed nonce bump for sender %x, latestNonce %d", tc.sender, latestNonce)