Skip to content

Commit

Permalink
ccip_messaging_test: GetLatestNonce
Browse files Browse the repository at this point in the history
  • Loading branch information
archseer committed Jan 21, 2025
1 parent d32bac5 commit 52ecab8
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions integration-tests/smoke/ccip/ccip_messaging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand All @@ -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)

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 52ecab8

Please sign in to comment.