Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] CCIP-4171 v1.6 reorg test #15327

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 89 additions & 1 deletion integration-tests/smoke/ccip/ccip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@

import (
"math/big"
"strconv"
"testing"

"github.com/ethereum/go-ethereum/common"
chain_selectors "github.com/smartcontractkit/chain-selectors"
"github.com/stretchr/testify/require"

"github.com/smartcontractkit/chainlink-testing-framework/lib/logging"
"github.com/smartcontractkit/chainlink-testing-framework/lib/utils/ptr"
"github.com/smartcontractkit/chainlink-testing-framework/lib/utils/testcontext"

"github.com/smartcontractkit/chainlink/deployment/ccip/changeset"
"github.com/smartcontractkit/chainlink/integration-tests/ccip-tests/actions"
"github.com/smartcontractkit/chainlink/integration-tests/testsetups"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/onramp"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/router"
Expand Down Expand Up @@ -206,3 +210,87 @@
require.NoError(t, err)
require.Equal(t, twoCoins, balance)
}

func TestReorgBelowFinality(t *testing.T) {
lggr := logger.TestLogger(t)
tenv, cl, _ := testsetups.NewLocalDevEnvironmentWithDefaultPrice(t, lggr, nil)
//tenv := changeset.NewMemoryEnvironment(t, lggr, 2, 4, big.NewInt(1), big.NewInt(1))
e := tenv.Env
state, err := changeset.LoadOnchainState(e)
require.NoError(t, err)

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

srcChainIDStr, err := chain_selectors.GetChainIDFromSelector(tenv.HomeChainSel)
require.NoError(t, err)
srcChainID, err := strconv.ParseInt(srcChainIDStr, 10, 64)
require.NoError(t, err)
srcNetwork, err := cl.GetEVMNetworkForChainId(srcChainID)
require.NoError(t, err)
destChainIDStr, err := chain_selectors.GetChainIDFromSelector(tenv.HomeChainSel)
require.NoError(t, err)
destChainID, err := strconv.ParseInt(destChainIDStr, 10, 64)
require.NoError(t, err)
destNetwork, err := cl.GetEVMNetworkForChainId(destChainID)
require.NoError(t, err)
suite, err := actions.NewReorgSuite(t, ptr.Ptr(logging.GetTestLogger(t)), &actions.ReorgConfig{
SrcGethHTTPURL: srcNetwork.URL,
DstGethHTTPURL: destNetwork.URL,
SrcFinalityDepth: int(srcNetwork.FinalityDepth),

Check failure on line 240 in integration-tests/smoke/ccip/ccip_test.go

View workflow job for this annotation

GitHub Actions / Lint integration-tests

G115: integer overflow conversion uint64 -> int (gosec)
DstFinalityDepth: int(destNetwork.FinalityDepth),

Check failure on line 241 in integration-tests/smoke/ccip/ccip_test.go

View workflow job for this annotation

GitHub Actions / Lint integration-tests

G115: integer overflow conversion uint64 -> int (gosec)
FinalityDelta: 5,
})
require.NoError(t, err)

// Need to keep track of the block number for each chain so that event subscription can be done from that block.
startBlocks := make(map[uint64]*uint64)
// Send a message from each chain to every other chain.
expectedSeqNum := make(map[changeset.SourceDestPair]uint64)
expectedSeqNumExec := make(map[changeset.SourceDestPair][]uint64)

for srcChainSel, srcChain := range e.Chains {
for destChainSel, destChain := range e.Chains {
if srcChainSel == destChainSel {
continue
}
latesthdr, err := destChain.Client.HeaderByNumber(testcontext.Get(t), nil)
require.NoError(t, err)
block := latesthdr.Number.Uint64()
startBlocks[destChainSel] = &block

var (
receiver = common.LeftPadBytes(state.Chains[srcChainSel].Receiver.Address().Bytes(), 32)
data = []byte("hello world")
feeToken = common.HexToAddress("0x0")
)
msgSentEvent := changeset.TestSendRequest(t, e, state, srcChainSel, destChainSel, false, router.ClientEVM2AnyMessage{
Receiver: receiver,
Data: data,
TokenAmounts: nil,
FeeToken: feeToken,
ExtraArgs: nil,
})
sourceDestPair := changeset.SourceDestPair{
SourceChainSelector: srcChainSel,
DestChainSelector: destChainSel,
}
expectedSeqNum[sourceDestPair] = msgSentEvent.SequenceNumber
expectedSeqNumExec[sourceDestPair] = []uint64{msgSentEvent.SequenceNumber}
latest, err := srcChain.Client.HeaderByNumber(testcontext.Get(t), nil)
require.NoError(t, err)
blocksTillLatest := latest.Number.Uint64() - msgSentEvent.Raw.BlockNumber
if blocksTillLatest >= srcNetwork.FinalityDepth {
lggr.Warn("Message sent after finality depth")
}
suite.RunReorg(suite.SrcClient, int(blocksTillLatest), "Source", 0)

Check failure on line 286 in integration-tests/smoke/ccip/ccip_test.go

View workflow job for this annotation

GitHub Actions / Lint integration-tests

G115: integer overflow conversion uint64 -> int (gosec)
suite.RunReorg(suite.DstClient, int(blocksTillLatest), "Destination", 0)
}
}

// Wait for all commit reports to land.
changeset.ConfirmCommitForAllWithExpectedSeqNums(t, e, state, expectedSeqNum, startBlocks)

// Wait for all exec reports to land
changeset.ConfirmExecWithSeqNrsForAll(t, e, state, expectedSeqNumExec, startBlocks)
}
Loading