diff --git a/.github/workflows/on-demand-vrfv2plus-smoke-tests.yml b/.github/workflows/on-demand-vrfv2plus-smoke-tests.yml index 5977f92622c..5bd8375c405 100644 --- a/.github/workflows/on-demand-vrfv2plus-smoke-tests.yml +++ b/.github/workflows/on-demand-vrfv2plus-smoke-tests.yml @@ -16,7 +16,7 @@ on: test_list_regex: description: "Regex for 'Selected Tests' to run" required: false - default: "(TestVRFv2Plus$/(Link_Billing|Native_Billing|Direct_Funding)|TestVRFV2PlusWithBHS|TestVRFV2PlusWithBHF)" + default: "TestVRFv2Plus$/(Link_Billing|Native_Billing|Direct_Funding)|TestVRFV2PlusWithBHS" test_secrets_override_key: description: 'Key to run tests with custom test secrets' required: false @@ -81,7 +81,7 @@ jobs: if: ${{ github.event.inputs.test_suite == 'Selected Tests' }} uses: smartcontractkit/chainlink-github-actions/chainlink-testing-framework/run-tests@2967f2287bd3f3ddbac7b476e9568993df01796e # v2.3.27 with: - test_command_to_run: cd ./integration-tests/smoke && go test -v -count=1 -parallel=1 -timeout 2h -run "${{ inputs.test_list_regex }}" + test_command_to_run: cd ./integration-tests/smoke && go test -v -count=1 -parallel=1 -timeout 2h -run "${{ inputs.test_list_regex }}" 2>&1 | tee /tmp/gotest.log | gotestloghelper -ci -singlepackage -hidepassingtests=false -hidepassinglogs test_download_vendor_packages_command: cd ./integration-tests && go mod download test_secrets_override_base64: ${{ secrets[inputs.test_secrets_override_key] }} cl_repo: ${{ env.CHAINLINK_IMAGE }} @@ -99,7 +99,7 @@ jobs: if: ${{ github.event.inputs.test_suite == 'All Tests' }} uses: smartcontractkit/chainlink-github-actions/chainlink-testing-framework/run-tests@2967f2287bd3f3ddbac7b476e9568993df01796e # v2.3.27 with: - test_command_to_run: cd ./integration-tests/smoke && go test -v -count=1 -parallel=1 -timeout 3h vrfv2plus_test.go + test_command_to_run: cd ./integration-tests/smoke && go test -v -count=1 -parallel=1 -timeout 3h vrfv2plus_test.go 2>&1 | tee /tmp/gotest.log | gotestloghelper -ci -singlepackage -hidepassingtests=false -hidepassinglogs test_download_vendor_packages_command: cd ./integration-tests && go mod download test_secrets_override_base64: ${{ secrets[inputs.test_secrets_override_key] }} cl_repo: ${{ env.CHAINLINK_IMAGE }} diff --git a/integration-tests/smoke/vrfv2_test.go b/integration-tests/smoke/vrfv2_test.go index 8d32204dd30..b21dafcacdf 100644 --- a/integration-tests/smoke/vrfv2_test.go +++ b/integration-tests/smoke/vrfv2_test.go @@ -40,6 +40,53 @@ const ( SethRootKeyIndex = 0 ) +// vrfv2CleanUpFn is a cleanup function that captures pointers from context, in which it's called and uses them to clean up the test environment +var vrfv2CleanUpFn = func( + t **testing.T, + sethClient **seth.Client, + config **tc.TestConfig, + testEnv **test_env.CLClusterTestEnv, + vrfContracts **vrfcommon.VRFContracts, + subIDsForCancellingAfterTest *[]uint64, + walletAddress **string, +) func() { + return func() { + logger := logging.GetTestLogger(*t) + testConfig := **config + network := networks.MustGetSelectedNetworkConfig(testConfig.GetNetworkConfig())[0] + if network.Simulated { + logger.Info(). + Str("Network Name", network.Name). + Msg("Network is a simulated network. Skipping fund return for Coordinator Subscriptions.") + } else { + if *vrfContracts != nil && *sethClient != nil { + if *testConfig.VRFv2.General.CancelSubsAfterTestRun { + client := *sethClient + var returnToAddress string + if walletAddress == nil || *walletAddress == nil { + returnToAddress = client.MustGetRootKeyAddress().Hex() + } else { + returnToAddress = **walletAddress + } + //cancel subs and return funds to sub owner + vrfv2.CancelSubsAndReturnFunds(testcontext.Get(*t), *vrfContracts, returnToAddress, *subIDsForCancellingAfterTest, logger) + } + } else { + logger.Error().Msg("VRF Contracts and/or Seth client are nil. Cannot execute cleanup") + } + } + if !*testConfig.VRFv2.General.UseExistingEnv { + if *testEnv == nil { + logger.Error().Msg("Test environment is nil. Cannot execute cleanup") + return + } + if err := (*testEnv).Cleanup(test_env.CleanupOpts{TestName: (*t).Name()}); err != nil { + logger.Error().Err(err).Msg("Error cleaning up test environment") + } + } + } +} + func TestVRFv2Basic(t *testing.T) { t.Parallel() var ( @@ -54,30 +101,13 @@ func TestVRFv2Basic(t *testing.T) { config, err := tc.GetChainAndTestTypeSpecificConfig("Smoke", tc.VRFv2) require.NoError(t, err, "Error getting config") - vrfv2Config := config.VRFv2 chainID := networks.MustGetSelectedNetworkConfig(config.GetNetworkConfig())[0].ChainID - cleanupFn := func() { - if sethClient.Cfg.IsSimulatedNetwork() { - l.Info(). - Str("Network Name", sethClient.Cfg.Network.Name). - Msg("Network is a simulated network. Skipping fund return for Coordinator Subscriptions.") - } else { - if *vrfv2Config.General.CancelSubsAfterTestRun { - //cancel subs and return funds to sub owner - vrfv2.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, sethClient.MustGetRootKeyAddress().Hex(), subIDsForCancellingAfterTest, l) - } - } - if !*vrfv2Config.General.UseExistingEnv { - if err := testEnv.Cleanup(test_env.CleanupOpts{TestName: t.Name()}); err != nil { - l.Error().Err(err).Msg("Error cleaning up test environment") - } - } - } + configPtr := &config vrfEnvConfig := vrfcommon.VRFEnvConfig{ TestConfig: config, ChainID: chainID, - CleanupFn: cleanupFn, + CleanupFn: vrfv2CleanUpFn(&t, &sethClient, &configPtr, &testEnv, &vrfContracts, &subIDsForCancellingAfterTest, nil), } newEnvConfig := vrfcommon.NewEnvConfig{ NodesToCreate: []vrfcommon.VRFNodeType{vrfcommon.VRF}, @@ -574,29 +604,12 @@ func TestVRFv2MultipleSendingKeys(t *testing.T) { t.Fatal(err) } chainID := networks.MustGetSelectedNetworkConfig(config.GetNetworkConfig())[0].ChainID - vrfv2Config := config.VRFv2 - cleanupFn := func() { - if sethClient.Cfg.IsSimulatedNetwork() { - l.Info(). - Str("Network Name", sethClient.Cfg.Network.Name). - Msg("Network is a simulated network. Skipping fund return for Coordinator Subscriptions.") - } else { - if *vrfv2Config.General.CancelSubsAfterTestRun { - //cancel subs and return funds to sub owner - vrfv2.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, sethClient.MustGetRootKeyAddress().Hex(), subIDsForCancellingAfterTest, l) - } - } - if !*vrfv2Config.General.UseExistingEnv { - if err := testEnv.Cleanup(test_env.CleanupOpts{TestName: t.Name()}); err != nil { - l.Error().Err(err).Msg("Error cleaning up test environment") - } - } - } + configPtr := &config vrfEnvConfig := vrfcommon.VRFEnvConfig{ TestConfig: config, ChainID: chainID, - CleanupFn: cleanupFn, + CleanupFn: vrfv2CleanUpFn(&t, &sethClient, &configPtr, &testEnv, &vrfContracts, &subIDsForCancellingAfterTest, nil), } newEnvConfig := vrfcommon.NewEnvConfig{ NodesToCreate: []vrfcommon.VRFNodeType{vrfcommon.VRF}, @@ -680,29 +693,12 @@ func TestVRFOwner(t *testing.T) { config, err := tc.GetChainAndTestTypeSpecificConfig("Smoke", tc.VRFv2) require.NoError(t, err, "Error getting config") chainID := networks.MustGetSelectedNetworkConfig(config.GetNetworkConfig())[0].ChainID - vrfv2Config := config.VRFv2 - cleanupFn := func() { - if sethClient.Cfg.IsSimulatedNetwork() { - l.Info(). - Str("Network Name", sethClient.Cfg.Network.Name). - Msg("Network is a simulated network. Skipping fund return for Coordinator Subscriptions.") - } else { - if *vrfv2Config.General.CancelSubsAfterTestRun { - //cancel subs and return funds to sub owner - vrfv2.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, sethClient.MustGetRootKeyAddress().Hex(), subIDsForCancellingAfterTest, l) - } - } - if !*vrfv2Config.General.UseExistingEnv { - if err := testEnv.Cleanup(test_env.CleanupOpts{TestName: t.Name()}); err != nil { - l.Error().Err(err).Msg("Error cleaning up test environment") - } - } - } + configPtr := &config vrfEnvConfig := vrfcommon.VRFEnvConfig{ TestConfig: config, ChainID: chainID, - CleanupFn: cleanupFn, + CleanupFn: vrfv2CleanUpFn(&t, &sethClient, &configPtr, &testEnv, &vrfContracts, &subIDsForCancellingAfterTest, nil), } newEnvConfig := vrfcommon.NewEnvConfig{ NodesToCreate: []vrfcommon.VRFNodeType{vrfcommon.VRF}, @@ -818,23 +814,7 @@ func TestVRFV2WithBHS(t *testing.T) { vrfv2Config := config.VRFv2 chainID := networks.MustGetSelectedNetworkConfig(config.GetNetworkConfig())[0].ChainID - cleanupFn := func() { - if sethClient.Cfg.IsSimulatedNetwork() { - l.Info(). - Str("Network Name", sethClient.Cfg.Network.Name). - Msg("Network is a simulated network. Skipping fund return for Coordinator Subscriptions.") - } else { - if *vrfv2Config.General.CancelSubsAfterTestRun { - //cancel subs and return funds to sub owner - vrfv2.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, sethClient.MustGetRootKeyAddress().Hex(), subIDsForCancellingAfterTest, l) - } - } - if !*vrfv2Config.General.UseExistingEnv { - if err := testEnv.Cleanup(test_env.CleanupOpts{TestName: t.Name()}); err != nil { - l.Error().Err(err).Msg("Error cleaning up test environment") - } - } - } + configPtr := &config //decrease default span for checking blockhashes for unfulfilled requests vrfv2Config.General.BHSJobWaitBlocks = ptr.Ptr(2) @@ -842,7 +822,7 @@ func TestVRFV2WithBHS(t *testing.T) { vrfEnvConfig := vrfcommon.VRFEnvConfig{ TestConfig: config, ChainID: chainID, - CleanupFn: cleanupFn, + CleanupFn: vrfv2CleanUpFn(&t, &sethClient, &configPtr, &testEnv, &vrfContracts, &subIDsForCancellingAfterTest, nil), } newEnvConfig := vrfcommon.NewEnvConfig{ NodesToCreate: []vrfcommon.VRFNodeType{vrfcommon.VRF, vrfcommon.BHS}, @@ -1036,30 +1016,13 @@ func TestVRFV2NodeReorg(t *testing.T) { config, err := tc.GetChainAndTestTypeSpecificConfig("Smoke", tc.VRFv2) require.NoError(t, err, "Error getting config") - vrfv2Config := config.VRFv2 network := networks.MustGetSelectedNetworkConfig(config.GetNetworkConfig())[0] if !network.Simulated { t.Skip("Skipped since Reorg test could only be run on Simulated chain.") } chainID := network.ChainID - cleanupFn := func() { - if sethClient.Cfg.IsSimulatedNetwork() { - l.Info(). - Str("Network Name", sethClient.Cfg.Network.Name). - Msg("Network is a simulated network. Skipping fund return for Coordinator Subscriptions.") - } else { - if *vrfv2Config.General.CancelSubsAfterTestRun { - //cancel subs and return funds to sub owner - vrfv2.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, sethClient.MustGetRootKeyAddress().Hex(), subIDsForCancellingAfterTest, l) - } - } - if !*vrfv2Config.General.UseExistingEnv { - if err := env.Cleanup(test_env.CleanupOpts{TestName: t.Name()}); err != nil { - l.Error().Err(err).Msg("Error cleaning up test environment") - } - } - } + configPtr := &config chainlinkNodeLogScannerSettings := test_env.GetDefaultChainlinkNodeLogScannerSettingsWithExtraAllowedMessages( testreporters.NewAllowedLogMessage( "Got very old block.", @@ -1075,7 +1038,7 @@ func TestVRFV2NodeReorg(t *testing.T) { vrfEnvConfig := vrfcommon.VRFEnvConfig{ TestConfig: config, ChainID: chainID, - CleanupFn: cleanupFn, + CleanupFn: vrfv2CleanUpFn(&t, &sethClient, &configPtr, &env, &vrfContracts, &subIDsForCancellingAfterTest, nil), } newEnvConfig := vrfcommon.NewEnvConfig{ NodesToCreate: []vrfcommon.VRFNodeType{vrfcommon.VRF}, @@ -1215,30 +1178,14 @@ func TestVRFv2BatchFulfillmentEnabledDisabled(t *testing.T) { config, err := tc.GetChainAndTestTypeSpecificConfig("Smoke", tc.VRFv2) require.NoError(t, err, "Error getting config") - vrfv2Config := config.VRFv2 network := networks.MustGetSelectedNetworkConfig(config.GetNetworkConfig())[0] chainID := network.ChainID - cleanupFn := func() { - if sethClient.Cfg.IsSimulatedNetwork() { - l.Info(). - Str("Network Name", sethClient.Cfg.Network.Name). - Msg("Network is a simulated network. Skipping fund return for Coordinator Subscriptions.") - } else { - if *vrfv2Config.General.CancelSubsAfterTestRun { - //cancel subs and return funds to sub owner - vrfv2.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, sethClient.MustGetRootKeyAddress().Hex(), subIDsForCancellingAfterTest, l) - } - } - if !*vrfv2Config.General.UseExistingEnv { - if err := env.Cleanup(test_env.CleanupOpts{TestName: t.Name()}); err != nil { - l.Error().Err(err).Msg("Error cleaning up test environment") - } - } - } + + configPtr := &config vrfEnvConfig := vrfcommon.VRFEnvConfig{ TestConfig: config, ChainID: chainID, - CleanupFn: cleanupFn, + CleanupFn: vrfv2CleanUpFn(&t, &sethClient, &configPtr, &env, &vrfContracts, &subIDsForCancellingAfterTest, nil), } newEnvConfig := vrfcommon.NewEnvConfig{ NodesToCreate: []vrfcommon.VRFNodeType{vrfcommon.VRF}, diff --git a/integration-tests/smoke/vrfv2plus_test.go b/integration-tests/smoke/vrfv2plus_test.go index d8ea7cac10d..30b0814a966 100644 --- a/integration-tests/smoke/vrfv2plus_test.go +++ b/integration-tests/smoke/vrfv2plus_test.go @@ -37,6 +37,47 @@ import ( it_utils "github.com/smartcontractkit/chainlink/integration-tests/utils" ) +// vrfv2PlusCleanUpFn is a cleanup function that captures pointers from context, in which it's called and uses them to clean up the test environment +var vrfv2PlusCleanUpFn = func( + t **testing.T, + sethClient **seth.Client, + config **tc.TestConfig, + testEnv **test_env.CLClusterTestEnv, + vrfContracts **vrfcommon.VRFContracts, + subIDsForCancellingAfterTest *[]*big.Int, +) func() { + return func() { + l := logging.GetTestLogger(*t) + testConfig := **config + network := networks.MustGetSelectedNetworkConfig(testConfig.GetNetworkConfig())[0] + if network.Simulated { + l.Info(). + Str("Network Name", network.Name). + Msg("Network is a simulated network. Skipping fund return for Coordinator Subscriptions.") + } else { + if *vrfContracts != nil && *sethClient != nil { + if *testConfig.VRFv2Plus.General.CancelSubsAfterTestRun { + client := *sethClient + returnToAddress := client.MustGetRootKeyAddress().Hex() + //cancel subs and return funds to sub owner + vrfv2plus.CancelSubsAndReturnFunds(testcontext.Get(*t), *vrfContracts, returnToAddress, *subIDsForCancellingAfterTest, l) + } + } else { + l.Error().Msg("VRF Contracts and/or Seth client are nil. Cannot execute cleanup") + } + } + if !*testConfig.VRFv2Plus.General.UseExistingEnv { + if *testEnv == nil { + l.Error().Msg("Test environment is nil. Cannot execute cleanup") + return + } + if err := (*testEnv).Cleanup(test_env.CleanupOpts{TestName: (*t).Name()}); err != nil { + l.Error().Err(err).Msg("Error cleaning up test environment") + } + } + } +} + func TestVRFv2Plus(t *testing.T) { t.Parallel() var ( @@ -52,30 +93,13 @@ func TestVRFv2Plus(t *testing.T) { config, err := tc.GetChainAndTestTypeSpecificConfig("Smoke", tc.VRFv2Plus) require.NoError(t, err, "Error getting config") - vrfv2PlusConfig := config.VRFv2Plus chainID := networks.MustGetSelectedNetworkConfig(config.GetNetworkConfig())[0].ChainID + configPtr := &config - cleanupFn := func() { - if sethClient.Cfg.IsSimulatedNetwork() { - l.Info(). - Str("Network Name", sethClient.Cfg.Network.Name). - Msg("Network is a simulated network. Skipping fund return for Coordinator Subscriptions.") - } else { - if *vrfv2PlusConfig.General.CancelSubsAfterTestRun { - //cancel subs and return funds to sub owner - vrfv2plus.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, sethClient.MustGetRootKeyAddress().Hex(), subIDsForCancellingAfterTest, l) - } - } - if !*vrfv2PlusConfig.General.UseExistingEnv { - if err := env.Cleanup(test_env.CleanupOpts{TestName: t.Name()}); err != nil { - l.Error().Err(err).Msg("Error cleaning up test environment") - } - } - } vrfEnvConfig := vrfcommon.VRFEnvConfig{ TestConfig: config, ChainID: chainID, - CleanupFn: cleanupFn, + CleanupFn: vrfv2PlusCleanUpFn(&t, &sethClient, &configPtr, &env, &vrfContracts, &subIDsForCancellingAfterTest), } newEnvConfig := vrfcommon.NewEnvConfig{ NodesToCreate: []vrfcommon.VRFNodeType{vrfcommon.VRF}, @@ -793,30 +817,13 @@ func TestVRFv2PlusMultipleSendingKeys(t *testing.T) { config, err := tc.GetChainAndTestTypeSpecificConfig("Smoke", tc.VRFv2Plus) require.NoError(t, err, "Error getting config") - vrfv2PlusConfig := config.VRFv2Plus - network := networks.MustGetSelectedNetworkConfig(config.GetNetworkConfig())[0] - chainID := network.ChainID - cleanupFn := func() { - if sethClient.Cfg.IsSimulatedNetwork() { - l.Info(). - Str("Network Name", sethClient.Cfg.Network.Name). - Msg("Network is a simulated network. Skipping fund return for Coordinator Subscriptions.") - } else { - if *vrfv2PlusConfig.General.CancelSubsAfterTestRun { - //cancel subs and return funds to sub owner - vrfv2plus.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, sethClient.MustGetRootKeyAddress().Hex(), subIDsForCancellingAfterTest, l) - } - } - if !*vrfv2PlusConfig.General.UseExistingEnv { - if err := env.Cleanup(test_env.CleanupOpts{TestName: t.Name()}); err != nil { - l.Error().Err(err).Msg("Error cleaning up test environment") - } - } - } + chainID := networks.MustGetSelectedNetworkConfig(config.GetNetworkConfig())[0].ChainID + configPtr := &config + vrfEnvConfig := vrfcommon.VRFEnvConfig{ TestConfig: config, ChainID: chainID, - CleanupFn: cleanupFn, + CleanupFn: vrfv2PlusCleanUpFn(&t, &sethClient, &configPtr, &env, &vrfContracts, &subIDsForCancellingAfterTest), } newEnvConfig := vrfcommon.NewEnvConfig{ NodesToCreate: []vrfcommon.VRFNodeType{vrfcommon.VRF}, @@ -898,30 +905,13 @@ func TestVRFv2PlusMigration(t *testing.T) { config, err := tc.GetChainAndTestTypeSpecificConfig("Smoke", tc.VRFv2Plus) require.NoError(t, err, "Error getting config") - vrfv2PlusConfig := config.VRFv2Plus chainID := networks.MustGetSelectedNetworkConfig(config.GetNetworkConfig())[0].ChainID + configPtr := &config - cleanupFn := func() { - if sethClient.Cfg.IsSimulatedNetwork() { - l.Info(). - Str("Network Name", sethClient.Cfg.Network.Name). - Msg("Network is a simulated network. Skipping fund return for Coordinator Subscriptions.") - } else { - if *vrfv2PlusConfig.General.CancelSubsAfterTestRun { - //cancel subs and return funds to sub owner - vrfv2plus.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, sethClient.MustGetRootKeyAddress().Hex(), subIDsForCancellingAfterTest, l) - } - } - if !*vrfv2PlusConfig.General.UseExistingEnv { - if err := env.Cleanup(test_env.CleanupOpts{TestName: t.Name()}); err != nil { - l.Error().Err(err).Msg("Error cleaning up test environment") - } - } - } vrfEnvConfig := vrfcommon.VRFEnvConfig{ TestConfig: config, ChainID: chainID, - CleanupFn: cleanupFn, + CleanupFn: vrfv2PlusCleanUpFn(&t, &sethClient, &configPtr, &env, &vrfContracts, &subIDsForCancellingAfterTest), } newEnvConfig := vrfcommon.NewEnvConfig{ NodesToCreate: []vrfcommon.VRFNodeType{vrfcommon.VRF}, @@ -1292,24 +1282,7 @@ func TestVRFV2PlusWithBHS(t *testing.T) { require.NoError(t, err, "Error getting config") vrfv2PlusConfig := config.VRFv2Plus chainID := networks.MustGetSelectedNetworkConfig(config.GetNetworkConfig())[0].ChainID - - cleanupFn := func() { - if sethClient.Cfg.IsSimulatedNetwork() { - l.Info(). - Str("Network Name", sethClient.Cfg.Network.Name). - Msg("Network is a simulated network. Skipping fund return for Coordinator Subscriptions.") - } else { - if *vrfv2PlusConfig.General.CancelSubsAfterTestRun { - //cancel subs and return funds to sub owner - vrfv2plus.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, sethClient.MustGetRootKeyAddress().Hex(), subIDsForCancellingAfterTest, l) - } - } - if !*vrfv2PlusConfig.General.UseExistingEnv { - if err := env.Cleanup(test_env.CleanupOpts{TestName: t.Name()}); err != nil { - l.Error().Err(err).Msg("Error cleaning up test environment") - } - } - } + configPtr := &config //decrease default span for checking blockhashes for unfulfilled requests vrfv2PlusConfig.General.BHSJobWaitBlocks = ptr.Ptr(2) @@ -1317,7 +1290,7 @@ func TestVRFV2PlusWithBHS(t *testing.T) { vrfEnvConfig := vrfcommon.VRFEnvConfig{ TestConfig: config, ChainID: chainID, - CleanupFn: cleanupFn, + CleanupFn: vrfv2PlusCleanUpFn(&t, &sethClient, &configPtr, &env, &vrfContracts, &subIDsForCancellingAfterTest), } newEnvConfig := vrfcommon.NewEnvConfig{ NodesToCreate: []vrfcommon.VRFNodeType{vrfcommon.VRF, vrfcommon.BHS}, @@ -1490,28 +1463,36 @@ func TestVRFV2PlusWithBHS(t *testing.T) { metrics, err := consumers[0].GetLoadTestMetrics(testcontext.Get(t)) require.Equal(t, 0, metrics.RequestCount.Cmp(big.NewInt(1))) require.Equal(t, 0, metrics.FulfilmentCount.Cmp(big.NewInt(0))) - - var clNodeTxs *client.TransactionsData - var txHash string gom := gomega.NewGomegaWithT(t) - gom.Eventually(func(g gomega.Gomega) { - clNodeTxs, _, err = nodeTypeToNodeMap[vrfcommon.BHS].CLNode.API.ReadTransactions() - g.Expect(err).ShouldNot(gomega.HaveOccurred(), "error getting CL Node transactions") - l.Info().Int("Number of TXs", len(clNodeTxs.Data)).Msg("BHS Node txs") - g.Expect(len(clNodeTxs.Data)).Should(gomega.BeNumerically("==", 1), "Expected 1 tx posted by BHS Node, but found %d", len(clNodeTxs.Data)) - txHash = clNodeTxs.Data[0].Attributes.Hash - }, "2m", "1s").Should(gomega.Succeed()) - require.Equal(t, strings.ToLower(vrfContracts.BHS.Address()), strings.ToLower(clNodeTxs.Data[0].Attributes.To)) - - bhsStoreTx, _, err := sethClient.Client.TransactionByHash(testcontext.Get(t), common.HexToHash(txHash)) - require.NoError(t, err, "error getting tx from hash") + if !*configCopy.VRFv2Plus.General.UseExistingEnv { + l.Info().Msg("Checking BHS Node's transactions") + var clNodeTxs *client.TransactionsData + var txHash string + gom.Eventually(func(g gomega.Gomega) { + clNodeTxs, _, err = nodeTypeToNodeMap[vrfcommon.BHS].CLNode.API.ReadTransactions() + g.Expect(err).ShouldNot(gomega.HaveOccurred(), "error getting CL Node transactions") + g.Expect(len(clNodeTxs.Data)).Should(gomega.BeNumerically("==", 1), "Expected 1 tx posted by BHS Node, but found %d", len(clNodeTxs.Data)) + txHash = clNodeTxs.Data[0].Attributes.Hash + l.Info(). + Str("TX Hash", txHash). + Int("Number of TXs", len(clNodeTxs.Data)). + Msg("BHS Node txs") + }, "2m", "1s").Should(gomega.Succeed()) + + require.Equal(t, strings.ToLower(vrfContracts.BHS.Address()), strings.ToLower(clNodeTxs.Data[0].Attributes.To)) + + bhsStoreTx, _, err := sethClient.Client.TransactionByHash(testcontext.Get(t), common.HexToHash(txHash)) + require.NoError(t, err, "error getting tx from hash") - bhsStoreTxInputData, err := actions.DecodeTxInputData(blockhash_store.BlockhashStoreABI, bhsStoreTx.Data()) - l.Info(). - Str("Block Number", bhsStoreTxInputData["n"].(*big.Int).String()). - Msg("BHS Node's Store Blockhash for Blocknumber Method TX") - require.Equal(t, randRequestBlockNumber, bhsStoreTxInputData["n"].(*big.Int).Uint64()) + bhsStoreTxInputData, err := actions.DecodeTxInputData(blockhash_store.BlockhashStoreABI, bhsStoreTx.Data()) + l.Info(). + Str("Block Number", bhsStoreTxInputData["n"].(*big.Int).String()). + Msg("BHS Node's Store Blockhash for Blocknumber Method TX") + require.Equal(t, randRequestBlockNumber, bhsStoreTxInputData["n"].(*big.Int).Uint64()) + } else { + l.Warn().Msg("Skipping BHS Node's transactions check as existing env is used") + } var randRequestBlockHash [32]byte gom.Eventually(func(g gomega.Gomega) { @@ -1540,28 +1521,10 @@ func TestVRFV2PlusWithBHF(t *testing.T) { config, err := tc.GetChainAndTestTypeSpecificConfig("Smoke", tc.VRFv2Plus) require.NoError(t, err, "Error getting config") - vrfv2PlusConfig := config.VRFv2Plus chainID := networks.MustGetSelectedNetworkConfig(config.GetNetworkConfig())[0].ChainID + configPtr := &config - cleanupFn := func() { - if sethClient.Cfg.IsSimulatedNetwork() { - l.Info(). - Str("Network Name", sethClient.Cfg.Network.Name). - Msg("Network is a simulated network. Skipping fund return for Coordinator Subscriptions.") - } else { - if *vrfv2PlusConfig.General.CancelSubsAfterTestRun { - //cancel subs and return funds to sub owner - vrfv2plus.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, sethClient.MustGetRootKeyAddress().Hex(), subIDsForCancellingAfterTest, l) - } - } - if !*vrfv2PlusConfig.General.UseExistingEnv { - if err := env.Cleanup(test_env.CleanupOpts{TestName: t.Name()}); err != nil { - l.Error().Err(err).Msg("Error cleaning up test environment") - } - } - } - - // BHF job config + // BHF job config - NOTE - not possible to create BHF job spec with waitBlocks being less than 256 blocks config.VRFv2Plus.General.BHFJobWaitBlocks = ptr.Ptr(260) config.VRFv2Plus.General.BHFJobLookBackBlocks = ptr.Ptr(500) config.VRFv2Plus.General.BHFJobPollPeriod = ptr.Ptr(blockchain.StrDuration{Duration: time.Second * 30}) @@ -1569,7 +1532,7 @@ func TestVRFV2PlusWithBHF(t *testing.T) { vrfEnvConfig := vrfcommon.VRFEnvConfig{ TestConfig: config, ChainID: chainID, - CleanupFn: cleanupFn, + CleanupFn: vrfv2PlusCleanUpFn(&t, &sethClient, &configPtr, &env, &vrfContracts, &subIDsForCancellingAfterTest), } chainlinkNodeLogScannerSettings := test_env.GetDefaultChainlinkNodeLogScannerSettingsWithExtraAllowedMessages(testreporters.NewAllowedLogMessage( "Pipeline error", @@ -1703,30 +1666,13 @@ func TestVRFv2PlusReplayAfterTimeout(t *testing.T) { config, err := tc.GetChainAndTestTypeSpecificConfig("Smoke", tc.VRFv2Plus) require.NoError(t, err, "Error getting config") - vrfv2PlusConfig := config.VRFv2Plus chainID := networks.MustGetSelectedNetworkConfig(config.GetNetworkConfig())[0].ChainID + configPtr := &config - cleanupFn := func() { - if sethClient.Cfg.IsSimulatedNetwork() { - l.Info(). - Str("Network Name", sethClient.Cfg.Network.Name). - Msg("Network is a simulated network. Skipping fund return for Coordinator Subscriptions.") - } else { - if *vrfv2PlusConfig.General.CancelSubsAfterTestRun { - //cancel subs and return funds to sub owner - vrfv2plus.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, sethClient.MustGetRootKeyAddress().Hex(), subIDsForCancellingAfterTest, l) - } - } - if !*vrfv2PlusConfig.General.UseExistingEnv { - if err := env.Cleanup(test_env.CleanupOpts{TestName: t.Name()}); err != nil { - l.Error().Err(err).Msg("Error cleaning up test environment") - } - } - } vrfEnvConfig := vrfcommon.VRFEnvConfig{ TestConfig: config, ChainID: chainID, - CleanupFn: cleanupFn, + CleanupFn: vrfv2PlusCleanUpFn(&t, &sethClient, &configPtr, &env, &vrfContracts, &subIDsForCancellingAfterTest), } newEnvConfig := vrfcommon.NewEnvConfig{ NodesToCreate: []vrfcommon.VRFNodeType{vrfcommon.VRF}, @@ -1744,7 +1690,7 @@ func TestVRFv2PlusReplayAfterTimeout(t *testing.T) { env, vrfContracts, vrfKey, nodeTypeToNodeMap, sethClient, err = vrfv2plus.SetupVRFV2PlusUniverse(testcontext.Get(t), t, vrfEnvConfig, newEnvConfig, l) require.NoError(t, err, "error setting up VRFV2Plus universe") - t.Run("Replaying Requests", func(t *testing.T) { + t.Run("Timed out request fulfilled after node restart with replay", func(t *testing.T) { configCopy := config.MustCopy().(tc.TestConfig) var isNativeBilling = false @@ -1876,30 +1822,13 @@ func TestVRFv2PlusPendingBlockSimulationAndZeroConfirmationDelays(t *testing.T) config, err := tc.GetChainAndTestTypeSpecificConfig("Smoke", tc.VRFv2Plus) require.NoError(t, err, "Error getting config") - vrfv2PlusConfig := config.VRFv2Plus chainID := networks.MustGetSelectedNetworkConfig(config.GetNetworkConfig())[0].ChainID + configPtr := &config - cleanupFn := func() { - if sethClient.Cfg.IsSimulatedNetwork() { - l.Info(). - Str("Network Name", sethClient.Cfg.Network.Name). - Msg("Network is a simulated network. Skipping fund return for Coordinator Subscriptions.") - } else { - if *vrfv2PlusConfig.General.CancelSubsAfterTestRun { - //cancel subs and return funds to sub owner - vrfv2plus.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, sethClient.MustGetRootKeyAddress().Hex(), subIDsForCancellingAfterTest, l) - } - } - if !*vrfv2PlusConfig.General.UseExistingEnv { - if err := env.Cleanup(test_env.CleanupOpts{TestName: t.Name()}); err != nil { - l.Error().Err(err).Msg("Error cleaning up test environment") - } - } - } vrfEnvConfig := vrfcommon.VRFEnvConfig{ TestConfig: config, ChainID: chainID, - CleanupFn: cleanupFn, + CleanupFn: vrfv2PlusCleanUpFn(&t, &sethClient, &configPtr, &env, &vrfContracts, &subIDsForCancellingAfterTest), } newEnvConfig := vrfcommon.NewEnvConfig{ NodesToCreate: []vrfcommon.VRFNodeType{vrfcommon.VRF}, @@ -1969,33 +1898,17 @@ func TestVRFv2PlusNodeReorg(t *testing.T) { config, err := tc.GetChainAndTestTypeSpecificConfig("Smoke", tc.VRFv2Plus) require.NoError(t, err, "Error getting config") - vrfv2PlusConfig := config.VRFv2Plus network := networks.MustGetSelectedNetworkConfig(config.GetNetworkConfig())[0] if !network.Simulated { t.Skip("Skipped since Reorg test could only be run on Simulated chain.") } chainID := network.ChainID - cleanupFn := func() { - if sethClient.Cfg.IsSimulatedNetwork() { - l.Info(). - Str("Network Name", sethClient.Cfg.Network.Name). - Msg("Network is a simulated network. Skipping fund return for Coordinator Subscriptions.") - } else { - if *vrfv2PlusConfig.General.CancelSubsAfterTestRun { - //cancel subs and return funds to sub owner - vrfv2plus.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, sethClient.MustGetRootKeyAddress().Hex(), subIDsForCancellingAfterTest, l) - } - } - if !*vrfv2PlusConfig.General.UseExistingEnv { - if err := env.Cleanup(test_env.CleanupOpts{TestName: t.Name()}); err != nil { - l.Error().Err(err).Msg("Error cleaning up test environment") - } - } - } + configPtr := &config + vrfEnvConfig := vrfcommon.VRFEnvConfig{ TestConfig: config, ChainID: chainID, - CleanupFn: cleanupFn, + CleanupFn: vrfv2PlusCleanUpFn(&t, &sethClient, &configPtr, &env, &vrfContracts, &subIDsForCancellingAfterTest), } chainlinkNodeLogScannerSettings := test_env.GetDefaultChainlinkNodeLogScannerSettingsWithExtraAllowedMessages( testreporters.NewAllowedLogMessage( @@ -2148,30 +2061,14 @@ func TestVRFv2PlusBatchFulfillmentEnabledDisabled(t *testing.T) { config, err := tc.GetChainAndTestTypeSpecificConfig("Smoke", tc.VRFv2Plus) require.NoError(t, err, "Error getting config") - vrfv2PlusConfig := config.VRFv2Plus network := networks.MustGetSelectedNetworkConfig(config.GetNetworkConfig())[0] chainID := network.ChainID - cleanupFn := func() { - if sethClient.Cfg.IsSimulatedNetwork() { - l.Info(). - Str("Network Name", sethClient.Cfg.Network.Name). - Msg("Network is a simulated network. Skipping fund return for Coordinator Subscriptions.") - } else { - if *vrfv2PlusConfig.General.CancelSubsAfterTestRun { - //cancel subs and return funds to sub owner - vrfv2plus.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, sethClient.MustGetRootKeyAddress().Hex(), subIDsForCancellingAfterTest, l) - } - } - if !*vrfv2PlusConfig.General.UseExistingEnv { - if err := env.Cleanup(test_env.CleanupOpts{TestName: t.Name()}); err != nil { - l.Error().Err(err).Msg("Error cleaning up test environment") - } - } - } + configPtr := &config + vrfEnvConfig := vrfcommon.VRFEnvConfig{ TestConfig: config, ChainID: chainID, - CleanupFn: cleanupFn, + CleanupFn: vrfv2PlusCleanUpFn(&t, &sethClient, &configPtr, &env, &vrfContracts, &subIDsForCancellingAfterTest), } newEnvConfig := vrfcommon.NewEnvConfig{ NodesToCreate: []vrfcommon.VRFNodeType{vrfcommon.VRF},