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 1 commit
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
Prev Previous commit
wip
  • Loading branch information
bukata-sa committed Nov 26, 2024
commit 66678d2ecf54fc239c797dbabc4c90a0c1db325f
90 changes: 36 additions & 54 deletions integration-tests/smoke/ccip/ccip_test.go
Original file line number Diff line number Diff line change
@@ -2,17 +2,16 @@

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

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

jobv1 "github.com/smartcontractkit/chainlink-protos/job-distributor/v1/job"
"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"

"github.com/smartcontractkit/chainlink/deployment/ccip/changeset"
"github.com/smartcontractkit/chainlink/integration-tests/ccip-tests/actions"
"github.com/smartcontractkit/chainlink/integration-tests/testsetups"
@@ -214,65 +213,41 @@

func TestReorgBelowFinality(t *testing.T) {
lggr := logger.TestLogger(t)
ctx := ccdeploy.Context(t)
tenv, cl, _ := testsetups.NewLocalDevEnvironmentWithDefaultPrice(t, lggr)
//tenv := ccdeploy.NewMemoryEnvironment(t, lggr, 2, 4, big.NewInt(1), big.NewInt(1))
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 := ccdeploy.LoadOnchainState(e)
require.NoError(t, err)
output, err := changeset.DeployPrerequisites(e, changeset.DeployPrerequisiteConfig{
ChainSelectors: e.AllChainSelectors(),
})
require.NoError(t, err)
require.NoError(t, e.ExistingAddresses.Merge(output.AddressBook))

// Apply migration
output, err = changeset.InitialDeploy(e, ccdeploy.DeployCCIPContractConfig{
HomeChainSel: tenv.HomeChainSel,
FeedChainSel: tenv.FeedChainSel,
ChainsToDeploy: e.AllChainSelectors(),
TokenConfig: ccdeploy.NewTestTokenConfig(state.Chains[tenv.FeedChainSel].USDFeeds),
MCMSConfig: ccdeploy.NewTestMCMSConfig(t, e),
OCRSecrets: deployment.XXXGenerateTestOCRSecrets(),
})
state, err := changeset.LoadOnchainState(e)
require.NoError(t, err)
require.NoError(t, e.ExistingAddresses.Merge(output.AddressBook))

// Get new state after migration and mock USDC token deployment.
state, err = ccdeploy.LoadOnchainState(e)
require.NoError(t, err) // Add all lanes
// Ensure capreg logs are up to date.
ccdeploy.ReplayLogs(t, e.Offchain, tenv.ReplayBlocks)
// Apply the jobs.
for nodeID, jobs := range output.JobSpecs {
for _, job := range jobs {
// Note these auto-accept
_, err := e.Offchain.ProposeJob(ctx,
&jobv1.ProposeJobRequest{
NodeId: nodeID,
Spec: job,
})
require.NoError(t, err)
}
}

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

srcNetwork, err := cl.GetEVMNetworkForChainId(int64(tenv.HomeChainSel))
destNetwork, err := cl.GetEVMNetworkForChainId(int64(tenv.FeedChainSel))
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: srcNetwork.FinalityDepth,
DstFinalityDepth: destNetwork.FinalityDepth,
SrcFinalityDepth: int(srcNetwork.FinalityDepth),

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

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

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[uint64]uint64)
expectedSeqNum := make(map[changeset.SourceDestPair]uint64)
expectedSeqNumExec := make(map[changeset.SourceDestPair][]uint64)

for srcChainSel, srcChain := range e.Chains {
for destChainSel, destChain := range e.Chains {
@@ -289,26 +264,33 @@
data = []byte("hello world")
feeToken = common.HexToAddress("0x0")
)
msgSentEvent := ccdeploy.TestSendRequest(t, e, state, srcChainSel, destChainSel, false, router.ClientEVM2AnyMessage{
msgSentEvent := changeset.TestSendRequest(t, e, state, srcChainSel, destChainSel, false, router.ClientEVM2AnyMessage{
Receiver: receiver,
Data: data,
TokenAmounts: nil,
FeeToken: feeToken,
ExtraArgs: nil,
})
expectedSeqNum[destChainSel] = msgSentEvent.SequenceNumber
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)
if latest.Number.Uint64()-msgSentEvent.Raw.BlockNumber > srcNetwork.FinalityDepth {
blocksTillLatest := latest.Number.Uint64() - msgSentEvent.Raw.BlockNumber
if blocksTillLatest >= srcNetwork.FinalityDepth {
lggr.Warn("Message sent after finality depth")
}
suite.RunReorg(suite.SrcClient, int(srcNetwork.FinalityDepth-1), "Source", 0)
suite.RunReorg(suite.SrcClient, int(blocksTillLatest), "Source", 0)

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

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.
ccdeploy.ConfirmCommitForAllWithExpectedSeqNums(t, e, state, expectedSeqNum, startBlocks)
changeset.ConfirmCommitForAllWithExpectedSeqNums(t, e, state, expectedSeqNum, startBlocks)

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