From 6c0a5e1d0bdf122c2fc3f8c890fa316df3cf897e Mon Sep 17 00:00:00 2001 From: Balamurali Gopalswami Date: Tue, 10 Sep 2024 11:44:11 -0400 Subject: [PATCH] Add reorg test to the pipeline and fix lint --- .github/e2e-tests.yml | 38 ++++++++++++++++++- .../ocr2/plugins/ccip/integration_test.go | 13 ++++++- .../ccip/testhelpers/integration/chainlink.go | 10 ++--- 3 files changed, 54 insertions(+), 7 deletions(-) diff --git a/.github/e2e-tests.yml b/.github/e2e-tests.yml index 30d1bf28a84..5318764f3c2 100644 --- a/.github/e2e-tests.yml +++ b/.github/e2e-tests.yml @@ -994,7 +994,43 @@ runner-test-matrix: - Nightly E2E Tests test_cmd: cd integration-tests/ccip-tests/smoke && go test ccip_test.go -test.run ^TestSmokeCCIPOffRampAggRateLimit$ -timeout 30m -count=1 -test.parallel=1 -json test_env_vars: - E2E_TEST_SELECTED_NETWORK: SIMULATED_1,SIMULATED_2 + E2E_TEST_SELECTED_NETWORK: SIMULATED_1,SIMULATED_2 + + - id: ccip-tests/smoke/ccip_test.go:^TestSmokeCCIPReorgBelowFinality$ + path: integration-tests/ccip-tests/smoke/ccip_test.go + test_env_type: docker + runs_on: ubuntu-latest + workflows: + - PR E2E CCIP Tests + - Nightly E2E Tests + test_cmd: cd integration-tests/ccip-tests/smoke && go test ccip_test.go -test.run ^TestSmokeCCIPReorgBelowFinality$ -timeout 30m -count=1 -test.parallel=1 -json + test_env_vars: + E2E_TEST_SELECTED_NETWORK: SIMULATED_1,SIMULATED_2 + test_config_override_path: integration-tests/ccip-tests/testconfig/tomls/ccip-reorg.toml + + - id: ccip-tests/smoke/ccip_test.go:^TestSmokeCCIPReorgAboveFinalityAtDestination$ + path: integration-tests/ccip-tests/smoke/ccip_test.go + test_env_type: docker + runs_on: ubuntu-latest + workflows: + - PR E2E CCIP Tests + - Nightly E2E Tests + test_cmd: cd integration-tests/ccip-tests/smoke && go test ccip_test.go -test.run ^TestSmokeCCIPReorgAboveFinalityAtDestination$ -timeout 30m -count=1 -test.parallel=1 -json + test_env_vars: + E2E_TEST_SELECTED_NETWORK: SIMULATED_1,SIMULATED_2 + test_config_override_path: integration-tests/ccip-tests/testconfig/tomls/ccip-reorg.toml + + - id: ccip-tests/smoke/ccip_test.go:^TestSmokeCCIPReorgAboveFinalityAtSource$ + path: integration-tests/ccip-tests/smoke/ccip_test.go + test_env_type: docker + runs_on: ubuntu-latest + workflows: + - PR E2E CCIP Tests + - Nightly E2E Tests + test_cmd: cd integration-tests/ccip-tests/smoke && go test ccip_test.go -test.run ^TestSmokeCCIPReorgAboveFinalityAtSource$ -timeout 30m -count=1 -test.parallel=1 -json + test_env_vars: + E2E_TEST_SELECTED_NETWORK: SIMULATED_1,SIMULATED_2 + test_config_override_path: integration-tests/ccip-tests/testconfig/tomls/ccip-reorg.toml - id: ccip-tests/chaos/ccip_test.go path: integration-tests/ccip-tests/chaos/ccip_test.go diff --git a/core/services/ocr2/plugins/ccip/integration_test.go b/core/services/ocr2/plugins/ccip/integration_test.go index a71dbc6ff70..5883df06705 100644 --- a/core/services/ocr2/plugins/ccip/integration_test.go +++ b/core/services/ocr2/plugins/ccip/integration_test.go @@ -6,6 +6,7 @@ import ( "fmt" "github.com/smartcontractkit/chainlink/v2/core/internal/testutils" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip" + "math" "math/big" "sync" "testing" @@ -686,7 +687,10 @@ func TestReorg(t *testing.T) { require.NoError(t, ccipTH.Dest.Chain.Fork(testutils.Context(t), forkBlock.Hash()), "Error while forking the chain") // Make sure that fork is longer than the canonical chain to enforce switch - noOfBlocks := int(currentBlock.NumberU64() - forkBlock.NumberU64()) + noOfBlocks, err := safeIntConversion(currentBlock.NumberU64() - forkBlock.NumberU64()) + if err != nil { + t.Fatalf("Error while finding number of blocks: %v", err) + } for i := 0; i < noOfBlocks+1; i++ { ccipTH.Dest.Chain.Commit() } @@ -707,3 +711,10 @@ func TestReorg(t *testing.T) { executionLog = ccipTH.AllNodesHaveExecutedSeqNums(t, 1, 2) ccipTH.AssertExecState(t, executionLog[0], testhelpers.ExecutionStateSuccess) } + +func safeIntConversion(n uint64) (int, error) { + if n > math.MaxInt { + return 0, fmt.Errorf("%d overflows int64", n) + } + return int(n), nil +} diff --git a/core/services/ocr2/plugins/ccip/testhelpers/integration/chainlink.go b/core/services/ocr2/plugins/ccip/testhelpers/integration/chainlink.go index 92276cad1d2..5adecad26d9 100644 --- a/core/services/ocr2/plugins/ccip/testhelpers/integration/chainlink.go +++ b/core/services/ocr2/plugins/ccip/testhelpers/integration/chainlink.go @@ -527,12 +527,12 @@ func setupNodeCCIP( return app, peerID.Raw(), transmitter, kb } -func createConfigV2Chain(chainId *big.Int, finalityDepth uint32) *v2.EVMConfig { +func createConfigV2Chain(chainID *big.Int, finalityDepth uint32) *v2.EVMConfig { // NOTE: For the executor jobs, the default of 500k is insufficient for a 3 message batch defaultGasLimit := uint64(5000000) tr := true - sourceC := v2.Defaults((*evmUtils.Big)(chainId)) + sourceC := v2.Defaults((*evmUtils.Big)(chainID)) sourceC.GasEstimator.LimitDefault = &defaultGasLimit fixedPrice := "FixedPrice" sourceC.GasEstimator.Mode = &fixedPrice @@ -540,7 +540,7 @@ func createConfigV2Chain(chainId *big.Int, finalityDepth uint32) *v2.EVMConfig { sourceC.LogPollInterval = &d sourceC.FinalityDepth = &finalityDepth return &v2.EVMConfig{ - ChainID: (*evmUtils.Big)(chainId), + ChainID: (*evmUtils.Big)(chainID), Enabled: &tr, Chain: sourceC, Nodes: v2.EVMNodes{&v2.Node{}}, @@ -553,10 +553,10 @@ type CCIPIntegrationTestHarness struct { Bootstrap Node } -func SetupCCIPIntegrationTH(t *testing.T, sourceChainID, sourceChainSelector, destChainId, destChainSelector uint64, +func SetupCCIPIntegrationTH(t *testing.T, sourceChainID, sourceChainSelector, destChainID, destChainSelector uint64, sourceFinalityDepth, destFinalityDepth uint32) CCIPIntegrationTestHarness { return CCIPIntegrationTestHarness{ - CCIPContracts: testhelpers.SetupCCIPContracts(t, sourceChainID, sourceChainSelector, destChainId, + CCIPContracts: testhelpers.SetupCCIPContracts(t, sourceChainID, sourceChainSelector, destChainID, destChainSelector, sourceFinalityDepth, destFinalityDepth), } }