Skip to content

Commit

Permalink
Update test for reorg above finality with FinalityTagEnabled false (#…
Browse files Browse the repository at this point in the history
…13539)

* Add test for reorg above finality with FinalityTagEnabled

* Fix lint

* Add reorg_above_finality to integration-tests.yml pipeline

* Remove TestReorgAboveFinality_FinalityTagEnabled test

We cannot test it with current state of Geth or Anvil. Related ticket: TT-1272
  • Loading branch information
lukaszcl authored Jun 14, 2024
1 parent 90924dc commit c2a9612
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 11 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,12 @@ jobs:
os: ubuntu-latest
file: ocr
pyroscope_env: ci-smoke-ocr-evm-simulated
- name: reorg_above_finality
id: reorg_above_finality
nodes: 1
os: ubuntu-latest
file: reorg_above_finality
pyroscope_env: ci-smoke-reorg-above-finality-evm-simulated
- name: ocr2
id: ocr2
nodes: 6
Expand Down
35 changes: 24 additions & 11 deletions integration-tests/smoke/reorg_above_finality_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package smoke

import (
"math/big"
"log"
"testing"
"time"

ctf_client "github.com/smartcontractkit/chainlink-testing-framework/client"

"github.com/pelletier/go-toml/v2"
"github.com/stretchr/testify/require"

"github.com/smartcontractkit/chainlink-testing-framework/logging"
Expand All @@ -15,25 +16,39 @@ import (
tc "github.com/smartcontractkit/chainlink/integration-tests/testconfig"
)

func TestReorgAboveFinality(t *testing.T) {
func TestReorgAboveFinality_FinalityTagDisabled(t *testing.T) {
t.Parallel()

l := logging.GetTestLogger(t)
config, err := tc.GetConfig("Smoke", tc.OCR2)
config, err := tc.GetConfig(t.Name(), tc.LogPoller)
require.NoError(t, err, "Error getting config")

privateNetworkConf, err := actions.EthereumNetworkConfigFromConfig(l, &config)
require.NoError(t, err)

nodeFinalityDepthInt := int64(10)
// Get values from the node config
configMap := make(map[string]interface{})
err = toml.Unmarshal([]byte(config.NodeConfig.CommonChainConfigTOML), &configMap)
if err != nil {
log.Fatalf("Error unmarshaling TOML: %s", err)
}
nodeFinalityDepthInt, isFinalityDepthSet := configMap["FinalityDepth"].(int64)
nodeFinalityTagEnabled := configMap["FinalityTagEnabled"].(bool)
l.Info().Int64("nodeFinalityDepth", nodeFinalityDepthInt).Bool("nodeFinalityTagEnabled", nodeFinalityTagEnabled).Msg("Node reorg config")

var reorgDepth int
if isFinalityDepthSet {
reorgDepth = int(nodeFinalityDepthInt) + 5
} else {
reorgDepth = 15
}
minChainBlockNumberBeforeReorg := reorgDepth + 10

testEnv, err := test_env.NewCLTestEnvBuilder().
WithTestInstance(t).
WithTestConfig(&config).
WithPrivateEthereumNetwork(privateNetworkConf.EthereumNetworkConfig).
WithMockAdapter().
WithCLNodes(6).
WithFunding(big.NewFloat(*config.Common.ChainlinkNodeFunding)).
WithoutCleanup().
WithSeth().
Build()
Expand All @@ -43,16 +58,14 @@ func TestReorgAboveFinality(t *testing.T) {
client := ctf_client.NewRPCClient(network.HTTPURLs[0])

// Wait for chain to progress
targetBlockNumber := nodeFinalityDepthInt * 3
require.Eventually(t, func() bool {
bn, err := client.BlockNumber()
require.NoError(t, err)
l.Info().Int64("blockNumber", bn).Int64("targetBlockNumber", targetBlockNumber).Msg("Waiting for chain to progress above target block number")
return bn > nodeFinalityDepthInt*3
}, 3*time.Minute, 3*time.Second, "chain did not progress above the target block number")
l.Info().Int64("blockNumber", bn).Int("targetBlockNumber", minChainBlockNumberBeforeReorg).Msg("Waiting for chain to progress above target block number")
return bn >= int64(minChainBlockNumberBeforeReorg)
}, 8*time.Minute, 3*time.Second, "timeout exceeded: chain did not progress above the target block number")

// Run reorg above finality depth
reorgDepth := int(nodeFinalityDepthInt) + 20
l.Info().
Str("URL", client.URL).
Int64("nodeFinalityDepth", nodeFinalityDepthInt).
Expand Down
12 changes: 12 additions & 0 deletions integration-tests/testconfig/log_poller/log_poller.toml
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,15 @@ FinalityTagEnabled = false
[TestLogPollerReplayFixedDepth.LogPoller.General]
use_finality_tag = false

[TestReorgAboveFinality_FinalityTagDisabled.NodeConfig]
CommonChainConfigTOML = """
AutoCreateKey = true
MinContractPayment = 0
LogPollInterval="500ms"
BackupLogPollerBlockDelay = 0
FinalityDepth = 10
FinalityTagEnabled = false
"""
[TestReorgAboveFinality_FinalityTagDisabled.PrivateEthereumNetwork]
ethereum_version = "eth1"
execution_layer = "geth"

0 comments on commit c2a9612

Please sign in to comment.