From e28f8a4386fcd0baa09cf95e5f59e3312b592506 Mon Sep 17 00:00:00 2001 From: Lei Date: Tue, 16 Jul 2024 16:45:57 -0700 Subject: [PATCH] add reorg tests for v23 (#13749) * add chaos and reorg tests for v23 * updates for reorg test --- .changeset/angry-wolves-fix.md | 5 ++ .../actions/automation_ocr_helpers.go | 69 +++++++++++++++---- .../chaos/automation_chaos_test.go | 11 ++- .../contracts/ethereum_keeper_contracts.go | 2 +- .../reorg/automation_reorg_test.go | 23 +++++-- .../testsetups/keeper_benchmark.go | 7 +- .../universal/log_poller/helpers.go | 18 +++-- 7 files changed, 107 insertions(+), 28 deletions(-) create mode 100644 .changeset/angry-wolves-fix.md diff --git a/.changeset/angry-wolves-fix.md b/.changeset/angry-wolves-fix.md new file mode 100644 index 00000000000..51fe7d7be88 --- /dev/null +++ b/.changeset/angry-wolves-fix.md @@ -0,0 +1,5 @@ +--- +"chainlink": patch +--- + +add chaos and reorg tests #added diff --git a/integration-tests/actions/automation_ocr_helpers.go b/integration-tests/actions/automation_ocr_helpers.go index 9aa96040250..05c4501fbe6 100644 --- a/integration-tests/actions/automation_ocr_helpers.go +++ b/integration-tests/actions/automation_ocr_helpers.go @@ -12,6 +12,8 @@ import ( "github.com/pkg/errors" "github.com/smartcontractkit/seth" + "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/i_automation_registry_master_wrapper_2_3" + "github.com/ethereum/go-ethereum/common" "github.com/lib/pq" "github.com/stretchr/testify/require" @@ -41,8 +43,12 @@ func BuildAutoOCR2ConfigVars( deltaStage time.Duration, chainModuleAddress common.Address, reorgProtectionEnabled bool, + linkToken contracts.LinkToken, + wethToken contracts.WETHToken, + ethUSDFeed contracts.MockETHUSDFeed, + ) (contracts.OCRv2Config, error) { - return BuildAutoOCR2ConfigVarsWithKeyIndex(t, chainlinkNodes, registryConfig, registrar, deltaStage, 0, common.Address{}, chainModuleAddress, reorgProtectionEnabled) + return BuildAutoOCR2ConfigVarsWithKeyIndex(t, chainlinkNodes, registryConfig, registrar, deltaStage, 0, common.Address{}, chainModuleAddress, reorgProtectionEnabled, linkToken, wethToken, ethUSDFeed) } func BuildAutoOCR2ConfigVarsWithKeyIndex( @@ -55,6 +61,9 @@ func BuildAutoOCR2ConfigVarsWithKeyIndex( registryOwnerAddress common.Address, chainModuleAddress common.Address, reorgProtectionEnabled bool, + linkToken contracts.LinkToken, + wethToken contracts.WETHToken, + ethUSDFeed contracts.MockETHUSDFeed, ) (contracts.OCRv2Config, error) { l := logging.GetTestLogger(t) S, oracleIdentities, err := GetOracleIdentitiesWithKeyIndex(chainlinkNodes, keyIndex) @@ -69,7 +78,7 @@ func BuildAutoOCR2ConfigVarsWithKeyIndex( var offchainConfigVersion uint64 var offchainConfig []byte - if registryConfig.RegistryVersion == ethereum.RegistryVersion_2_1 || registryConfig.RegistryVersion == ethereum.RegistryVersion_2_2 { + if registryConfig.RegistryVersion == ethereum.RegistryVersion_2_1 || registryConfig.RegistryVersion == ethereum.RegistryVersion_2_2 || registryConfig.RegistryVersion == ethereum.RegistryVersion_2_3 { offC, err = json.Marshal(ocr2keepers30config.OffchainConfig{ TargetProbability: "0.999", TargetInRounds: 1, @@ -169,6 +178,31 @@ func BuildAutoOCR2ConfigVarsWithKeyIndex( ocrConfig.TypedOnchainConfig21 = registryConfig.Create21OnchainConfig(registrar, registryOwnerAddress) } else if registryConfig.RegistryVersion == ethereum.RegistryVersion_2_2 { ocrConfig.TypedOnchainConfig22 = registryConfig.Create22OnchainConfig(registrar, registryOwnerAddress, chainModuleAddress, reorgProtectionEnabled) + } else if registryConfig.RegistryVersion == ethereum.RegistryVersion_2_3 { + ocrConfig.TypedOnchainConfig23 = registryConfig.Create23OnchainConfig(registrar, registryOwnerAddress, chainModuleAddress, reorgProtectionEnabled) + ocrConfig.BillingTokens = []common.Address{ + common.HexToAddress(linkToken.Address()), + common.HexToAddress(wethToken.Address()), + } + + ocrConfig.BillingConfigs = []i_automation_registry_master_wrapper_2_3.AutomationRegistryBase23BillingConfig{ + { + GasFeePPB: 100, + FlatFeeMilliCents: big.NewInt(500), + PriceFeed: common.HexToAddress(ethUSDFeed.Address()), // ETH/USD feed and LINK/USD feed are the same + Decimals: 18, + FallbackPrice: big.NewInt(1000), + MinSpend: big.NewInt(200), + }, + { + GasFeePPB: 100, + FlatFeeMilliCents: big.NewInt(500), + PriceFeed: common.HexToAddress(ethUSDFeed.Address()), // ETH/USD feed and LINK/USD feed are the same + Decimals: 18, + FallbackPrice: big.NewInt(1000), + MinSpend: big.NewInt(200), + }, + } } l.Info().Msg("Done building OCR config") @@ -191,14 +225,14 @@ func CreateOCRKeeperJobs( bootstrapP2PId := bootstrapP2PIds.Data[0].Attributes.PeerID var contractVersion string - if registryVersion == ethereum.RegistryVersion_2_2 { + if registryVersion == ethereum.RegistryVersion_2_2 || registryVersion == ethereum.RegistryVersion_2_3 { contractVersion = "v2.1+" } else if registryVersion == ethereum.RegistryVersion_2_1 { contractVersion = "v2.1" } else if registryVersion == ethereum.RegistryVersion_2_0 { contractVersion = "v2.0" } else { - require.FailNow(t, fmt.Sprintf("v2.0, v2.1, and v2.2 are the only supported versions, but got something else: %v (iota)", registryVersion)) + require.FailNow(t, fmt.Sprintf("v2.0, v2.1, v2.2 and v2.3 are the only supported versions, but got something else: %v (iota)", registryVersion)) } bootstrapSpec := &client.OCR2TaskJobSpec{ @@ -265,9 +299,11 @@ func DeployAutoOCRRegistryAndRegistrar( registryVersion ethereum.KeeperRegistryVersion, registrySettings contracts.KeeperRegistrySettings, linkToken contracts.LinkToken, + wethToken contracts.WETHToken, + ethUSDFeed contracts.MockETHUSDFeed, ) (contracts.KeeperRegistry, contracts.KeeperRegistrar) { - registry := deployRegistry(t, client, registryVersion, registrySettings, linkToken) - registrar := deployRegistrar(t, client, registryVersion, registry, linkToken) + registry := deployRegistry(t, client, registryVersion, registrySettings, linkToken, wethToken, ethUSDFeed) + registrar := deployRegistrar(t, client, registryVersion, registry, linkToken, wethToken) return registry, registrar } @@ -379,12 +415,14 @@ func deployRegistrar( registryVersion ethereum.KeeperRegistryVersion, registry contracts.KeeperRegistry, linkToken contracts.LinkToken, + wethToken contracts.WETHToken, ) contracts.KeeperRegistrar { registrarSettings := contracts.KeeperRegistrarSettings{ AutoApproveConfigType: 2, AutoApproveMaxAllowed: math.MaxUint16, RegistryAddr: registry.Address(), MinLinkJuels: big.NewInt(0), + WETHTokenAddr: wethToken.Address(), } registrar, err := contracts.DeployKeeperRegistrar(client, registryVersion, linkToken.Address(), registrarSettings) require.NoError(t, err, "Deploying KeeperRegistrar contract shouldn't fail") @@ -397,6 +435,8 @@ func deployRegistry( registryVersion ethereum.KeeperRegistryVersion, registrySettings contracts.KeeperRegistrySettings, linkToken contracts.LinkToken, + wethToken contracts.WETHToken, + ethUSDFeed contracts.MockETHUSDFeed, ) contracts.KeeperRegistry { ef, err := contracts.DeployMockETHLINKFeed(client, big.NewInt(2e18)) require.NoError(t, err, "Deploying mock ETH-Link feed shouldn't fail") @@ -410,13 +450,16 @@ func deployRegistry( registry, err := contracts.DeployKeeperRegistry( client, &contracts.KeeperRegistryOpts{ - RegistryVersion: registryVersion, - LinkAddr: linkToken.Address(), - ETHFeedAddr: ef.Address(), - GasFeedAddr: gf.Address(), - TranscoderAddr: transcoder.Address(), - RegistrarAddr: ZeroAddress.Hex(), - Settings: registrySettings, + RegistryVersion: registryVersion, + LinkAddr: linkToken.Address(), + ETHFeedAddr: ef.Address(), + GasFeedAddr: gf.Address(), + TranscoderAddr: transcoder.Address(), + RegistrarAddr: ZeroAddress.Hex(), + Settings: registrySettings, + LinkUSDFeedAddr: ethUSDFeed.Address(), + NativeUSDFeedAddr: ethUSDFeed.Address(), + WrappedNativeAddr: wethToken.Address(), }, ) require.NoError(t, err, "Deploying KeeperRegistry contract shouldn't fail") diff --git a/integration-tests/chaos/automation_chaos_test.go b/integration-tests/chaos/automation_chaos_test.go index e14c35ed17b..79513b2e8fb 100644 --- a/integration-tests/chaos/automation_chaos_test.go +++ b/integration-tests/chaos/automation_chaos_test.go @@ -261,12 +261,21 @@ func TestAutomationChaos(t *testing.T) { linkToken, err := contracts.DeployLinkTokenContract(l, chainClient) require.NoError(t, err, "Error deploying LINK token") + wethToken, err := contracts.DeployWETHTokenContract(l, chainClient) + require.NoError(t, err, "Error deploying weth token contract") + + // This feed is used for both eth/usd and link/usd + ethUSDFeed, err := contracts.DeployMockETHUSDFeed(chainClient, defaultOCRRegistryConfig.FallbackLinkPrice) + require.NoError(t, err, "Error deploying eth usd feed contract") + registry, registrar := actions.DeployAutoOCRRegistryAndRegistrar( t, chainClient, rv, defaultOCRRegistryConfig, linkToken, + wethToken, + ethUSDFeed, ) // Fund the registry with LINK @@ -276,7 +285,7 @@ func TestAutomationChaos(t *testing.T) { actions.CreateOCRKeeperJobs(t, chainlinkNodes, registry.Address(), network.ChainID, 0, rv) nodesWithoutBootstrap := chainlinkNodes[1:] defaultOCRRegistryConfig.RegistryVersion = rv - ocrConfig, err := actions.BuildAutoOCR2ConfigVars(t, nodesWithoutBootstrap, defaultOCRRegistryConfig, registrar.Address(), 30*time.Second, registry.ChainModuleAddress(), registry.ReorgProtectionEnabled()) + ocrConfig, err := actions.BuildAutoOCR2ConfigVars(t, nodesWithoutBootstrap, defaultOCRRegistryConfig, registrar.Address(), 30*time.Second, registry.ChainModuleAddress(), registry.ReorgProtectionEnabled(), linkToken, wethToken, ethUSDFeed) require.NoError(t, err, "Error building OCR config vars") if rv == eth_contracts.RegistryVersion_2_0 { diff --git a/integration-tests/contracts/ethereum_keeper_contracts.go b/integration-tests/contracts/ethereum_keeper_contracts.go index 34c78b3fc60..28fdd15b13e 100644 --- a/integration-tests/contracts/ethereum_keeper_contracts.go +++ b/integration-tests/contracts/ethereum_keeper_contracts.go @@ -173,7 +173,7 @@ func (rcs *KeeperRegistrySettings) Create23OnchainConfig(registrar string, regis ChainModule: chainModuleAddress, ReorgProtectionEnabled: reorgProtectionEnabled, FinanceAdmin: registryOwnerAddress, - FallbackNativePrice: big.NewInt(1), + FallbackNativePrice: rcs.FallbackLinkPrice, // Just use the LINK price } } diff --git a/integration-tests/reorg/automation_reorg_test.go b/integration-tests/reorg/automation_reorg_test.go index 2a2350e1956..a393513ac49 100644 --- a/integration-tests/reorg/automation_reorg_test.go +++ b/integration-tests/reorg/automation_reorg_test.go @@ -6,6 +6,7 @@ import ( "math/big" "regexp" "strconv" + "strings" "testing" "time" @@ -119,6 +120,8 @@ func TestAutomationReorg(t *testing.T) { "registry_2_1_logtrigger": ethereum.RegistryVersion_2_1, "registry_2_2_conditional": ethereum.RegistryVersion_2_2, // Works only on Chainlink Node v2.10.0 or greater "registry_2_2_logtrigger": ethereum.RegistryVersion_2_2, // Works only on Chainlink Node v2.10.0 or greater + "registry_2_3_conditional": ethereum.RegistryVersion_2_3, + "registry_2_3_logtrigger": ethereum.RegistryVersion_2_3, } for n, rv := range registryVersions { @@ -192,12 +195,22 @@ func TestAutomationReorg(t *testing.T) { linkToken, err := contracts.DeployLinkTokenContract(l, chainClient) require.NoError(t, err, "Error deploying LINK token") + wethToken, err := contracts.DeployWETHTokenContract(l, chainClient) + require.NoError(t, err, "Error deploying weth token contract") + + // This feed is used for both eth/usd and link/usd + ethUSDFeed, err := contracts.DeployMockETHUSDFeed(chainClient, defaultOCRRegistryConfig.FallbackLinkPrice) + require.NoError(t, err, "Error deploying eth usd feed contract") + + defaultOCRRegistryConfig.RegistryVersion = registryVersion registry, registrar := actions.DeployAutoOCRRegistryAndRegistrar( t, chainClient, registryVersion, defaultOCRRegistryConfig, linkToken, + wethToken, + ethUSDFeed, ) // Fund the registry with LINK @@ -206,18 +219,18 @@ func TestAutomationReorg(t *testing.T) { actions.CreateOCRKeeperJobs(t, chainlinkNodes, registry.Address(), network.ChainID, 0, registryVersion) nodesWithoutBootstrap := chainlinkNodes[1:] - defaultOCRRegistryConfig.RegistryVersion = registryVersion - ocrConfig, err := actions.BuildAutoOCR2ConfigVars(t, nodesWithoutBootstrap, defaultOCRRegistryConfig, registrar.Address(), 5*time.Second, registry.ChainModuleAddress(), registry.ReorgProtectionEnabled()) + + ocrConfig, err := actions.BuildAutoOCR2ConfigVars(t, nodesWithoutBootstrap, defaultOCRRegistryConfig, registrar.Address(), 5*time.Second, registry.ChainModuleAddress(), registry.ReorgProtectionEnabled(), linkToken, wethToken, ethUSDFeed) require.NoError(t, err, "OCR2 config should be built successfully") if registryVersion == ethereum.RegistryVersion_2_0 { err = registry.SetConfig(defaultOCRRegistryConfig, ocrConfig) } else { err = registry.SetConfigTypeSafe(ocrConfig) } - require.NoError(t, err, "Registry config should be be set successfully") + require.NoError(t, err, "Registry config should be set successfully") // Use the name to determine if this is a log trigger or not - isLogTrigger := name == "registry_2_1_logtrigger" || name == "registry_2_2_logtrigger" + isLogTrigger := strings.Contains(name, "logtrigger") consumers, upkeepIDs := actions.DeployConsumers( t, chainClient, @@ -230,7 +243,7 @@ func TestAutomationReorg(t *testing.T) { isLogTrigger, false, false, - nil, + wethToken, ) if isLogTrigger { diff --git a/integration-tests/testsetups/keeper_benchmark.go b/integration-tests/testsetups/keeper_benchmark.go index d50355f39b6..4803a5249f0 100644 --- a/integration-tests/testsetups/keeper_benchmark.go +++ b/integration-tests/testsetups/keeper_benchmark.go @@ -240,8 +240,9 @@ func (k *KeeperBenchmarkTest) Run() { txKeyId = 0 } kr := k.keeperRegistries[rIndex] + // TODO: need to add the LINK, WETH and WETH/USD feed to support v23 ocrConfig, err := actions.BuildAutoOCR2ConfigVarsWithKeyIndex( - k.t, nodesWithoutBootstrap, *inputs.KeeperRegistrySettings, kr.Address(), k.Inputs.DeltaStage, txKeyId, common.Address{}, kr.ChainModuleAddress(), kr.ReorgProtectionEnabled(), + k.t, nodesWithoutBootstrap, *inputs.KeeperRegistrySettings, kr.Address(), k.Inputs.DeltaStage, txKeyId, common.Address{}, kr.ChainModuleAddress(), kr.ReorgProtectionEnabled(), nil, nil, nil, ) require.NoError(k.t, err, "Building OCR config shouldn't fail") @@ -730,13 +731,13 @@ func (k *KeeperBenchmarkTest) DeployBenchmarkKeeperContracts(index int) { require.NoError(k.t, err, "Funding keeper registrar contract shouldn't fail") } else { // OCR automation - v2.X registry, registrar = actions.DeployAutoOCRRegistryAndRegistrar( - k.t, k.chainClient, registryVersion, *k.Inputs.KeeperRegistrySettings, k.linkToken, + k.t, k.chainClient, registryVersion, *k.Inputs.KeeperRegistrySettings, k.linkToken, nil, nil, ) // Fund the registry with LINK err := k.linkToken.Transfer(registry.Address(), big.NewInt(0).Mul(big.NewInt(1e18), big.NewInt(int64(k.Inputs.Upkeeps.NumberOfUpkeeps)))) require.NoError(k.t, err, "Funding keeper registry contract shouldn't fail") - ocrConfig, err := actions.BuildAutoOCR2ConfigVars(k.t, k.chainlinkNodes[1:], *k.Inputs.KeeperRegistrySettings, registrar.Address(), k.Inputs.DeltaStage, registry.ChainModuleAddress(), registry.ReorgProtectionEnabled()) + ocrConfig, err := actions.BuildAutoOCR2ConfigVars(k.t, k.chainlinkNodes[1:], *k.Inputs.KeeperRegistrySettings, registrar.Address(), k.Inputs.DeltaStage, registry.ChainModuleAddress(), registry.ReorgProtectionEnabled(), nil, nil, nil) require.NoError(k.t, err, "Building OCR config shouldn't fail") k.log.Debug().Interface("KeeperRegistrySettings", *k.Inputs.KeeperRegistrySettings).Interface("OCRConfig", ocrConfig).Msg("Config") require.NoError(k.t, err, "Error building OCR config vars") diff --git a/integration-tests/universal/log_poller/helpers.go b/integration-tests/universal/log_poller/helpers.go index ee4060f7aba..daa4784ec16 100644 --- a/integration-tests/universal/log_poller/helpers.go +++ b/integration-tests/universal/log_poller/helpers.go @@ -13,25 +13,24 @@ import ( "testing" "time" + "github.com/jmoiron/sqlx" + "github.com/smartcontractkit/seth" + "github.com/smartcontractkit/wasp" + geth "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/common" geth_types "github.com/ethereum/go-ethereum/core/types" - "github.com/jmoiron/sqlx" "github.com/rs/zerolog" "github.com/scylladb/go-reflectx" "github.com/stretchr/testify/require" - "github.com/smartcontractkit/seth" - "github.com/smartcontractkit/wasp" - "github.com/smartcontractkit/chainlink-testing-framework/blockchain" ctf_concurrency "github.com/smartcontractkit/chainlink-testing-framework/concurrency" ctf_test_env "github.com/smartcontractkit/chainlink-testing-framework/docker/test_env" "github.com/smartcontractkit/chainlink-testing-framework/logging" "github.com/smartcontractkit/chainlink-testing-framework/networks" seth_utils "github.com/smartcontractkit/chainlink-testing-framework/utils/seth" - "github.com/smartcontractkit/chainlink/integration-tests/actions" "github.com/smartcontractkit/chainlink/integration-tests/client" "github.com/smartcontractkit/chainlink/integration-tests/contracts" @@ -1072,6 +1071,13 @@ func SetupLogPollerTestDocker( linkToken, err := contracts.DeployLinkTokenContract(l, chainClient) require.NoError(t, err, "Error deploying LINK token") + wethToken, err := contracts.DeployWETHTokenContract(l, chainClient) + require.NoError(t, err, "Error deploying weth token contract") + + // This feed is used for both eth/usd and link/usd + ethUSDFeed, err := contracts.DeployMockETHUSDFeed(chainClient, registryConfig.FallbackLinkPrice) + require.NoError(t, err, "Error deploying eth usd feed contract") + linkBalance, err := linkToken.BalanceOf(context.Background(), chainClient.MustGetRootKeyAddress().Hex()) require.NoError(t, err, "Error getting LINK balance") @@ -1088,6 +1094,8 @@ func SetupLogPollerTestDocker( registryVersion, registryConfig, linkToken, + wethToken, + ethUSDFeed, ) // Fund the registry with LINK