diff --git a/.changeset/chilly-ladybugs-visit.md b/.changeset/chilly-ladybugs-visit.md new file mode 100644 index 00000000000..aaa2dfc3ef4 --- /dev/null +++ b/.changeset/chilly-ladybugs-visit.md @@ -0,0 +1,5 @@ +--- +"chainlink": patch +--- + +Cleanup txm tests #internal diff --git a/core/chains/evm/testutils/evmtypes.go b/core/chains/evm/testutils/evmtypes.go index eda284284ba..fedcd52ea2f 100644 --- a/core/chains/evm/testutils/evmtypes.go +++ b/core/chains/evm/testutils/evmtypes.go @@ -84,3 +84,8 @@ func NewLegacyTransaction(nonce uint64, to common.Address, value *big.Int, gasLi } return types.NewTx(&tx) } + +func NewAddressPtr() *common.Address { + a := common.BytesToAddress(randomBytes(20)) + return &a +} diff --git a/core/chains/evm/txmgr/attempts_test.go b/core/chains/evm/txmgr/attempts_test.go index 52340ce51a5..6be8cd7067b 100644 --- a/core/chains/evm/txmgr/attempts_test.go +++ b/core/chains/evm/txmgr/attempts_test.go @@ -15,16 +15,16 @@ import ( "github.com/stretchr/testify/require" "github.com/smartcontractkit/chainlink-common/pkg/logger" + "github.com/smartcontractkit/chainlink-common/pkg/utils/tests" + "github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets" + "github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/toml" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/gas" gasmocks "github.com/smartcontractkit/chainlink/v2/core/chains/evm/gas/mocks" ksmocks "github.com/smartcontractkit/chainlink/v2/core/chains/evm/keystore/mocks" + "github.com/smartcontractkit/chainlink/v2/core/chains/evm/testutils" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/txmgr" evmtypes "github.com/smartcontractkit/chainlink/v2/core/chains/evm/types" - "github.com/smartcontractkit/chainlink/v2/core/internal/testutils" - "github.com/smartcontractkit/chainlink/v2/core/internal/testutils/configtest" - "github.com/smartcontractkit/chainlink/v2/core/internal/testutils/evmtest" - "github.com/smartcontractkit/chainlink/v2/core/services/chainlink" ) func NewEvmAddress() gethcommon.Address { @@ -72,7 +72,7 @@ func TestTxm_SignTx(t *testing.T) { kst := ksmocks.NewEth(t) kst.On("SignTx", mock.Anything, to, tx, chainID).Return(tx, nil).Once() cks := txmgr.NewEvmTxAttemptBuilder(*chainID, newFeeConfig(), kst, nil) - hash, rawBytes, err := cks.SignTx(testutils.Context(t), addr, tx) + hash, rawBytes, err := cks.SignTx(tests.Context(t), addr, tx) require.NoError(t, err) require.NotNil(t, rawBytes) require.Equal(t, "0xdd68f554373fdea7ec6713a6e437e7646465d553a6aa0b43233093366cc87ef0", hash.String()) @@ -83,7 +83,7 @@ func TestTxm_SignTx(t *testing.T) { kst := ksmocks.NewEth(t) kst.On("SignTx", mock.Anything, to, tx, chainID).Return(tx, nil).Once() cks := txmgr.NewEvmTxAttemptBuilder(*chainID, newFeeConfig(), kst, nil) - hash, rawBytes, err := cks.SignTx(testutils.Context(t), addr, tx) + hash, rawBytes, err := cks.SignTx(tests.Context(t), addr, tx) require.NoError(t, err) require.NotNil(t, rawBytes) require.Equal(t, "0xdd68f554373fdea7ec6713a6e437e7646465d553a6aa0b43233093366cc87ef0", hash.String()) @@ -94,7 +94,7 @@ func TestTxm_SignTx(t *testing.T) { kst.On("SignTx", mock.Anything, to, tx, chainID).Return(tx, nil).Once() cks := txmgr.NewEvmTxAttemptBuilder(*chainID, newFeeConfig(), kst, nil) - _, rawBytes, err := cks.SignTx(testutils.Context(t), addr, tx) + _, rawBytes, err := cks.SignTx(tests.Context(t), addr, tx) require.NoError(t, err) require.NotNil(t, rawBytes) require.Equal(t, "0xe42a82015681f294b921f7763960b296b9cbad586ff066a18d749724818e83010203808080", hexutil.Encode(rawBytes)) @@ -116,7 +116,7 @@ func TestTxm_SignTx(t *testing.T) { }) kst.On("SignTx", mock.Anything, to, typedTx, chainID).Return(typedTx, nil).Once() cks := txmgr.NewEvmTxAttemptBuilder(*chainID, newFeeConfig(), kst, nil) - _, rawBytes, err := cks.SignTx(testutils.Context(t), addr, typedTx) + _, rawBytes, err := cks.SignTx(tests.Context(t), addr, typedTx) require.NoError(t, err) require.NotNil(t, rawBytes) require.Equal(t, "0xa702e5802a808081f294b921f7763960b296b9cbad586ff066a18d749724818e83010203c0808080", hexutil.Encode(rawBytes)) @@ -141,7 +141,7 @@ func TestTxm_NewDynamicFeeTx(t *testing.T) { feeCfg.priceMax = assets.GWei(200) cks := txmgr.NewEvmTxAttemptBuilder(*big.NewInt(1), feeCfg, kst, nil) dynamicFee := gas.DynamicFee{TipCap: assets.GWei(100), FeeCap: assets.GWei(200)} - a, _, err := cks.NewCustomTxAttempt(testutils.Context(t), txmgr.Tx{Sequence: &n, FromAddress: addr}, gas.EvmFee{ + a, _, err := cks.NewCustomTxAttempt(tests.Context(t), txmgr.Tx{Sequence: &n, FromAddress: addr}, gas.EvmFee{ DynamicTipCap: dynamicFee.TipCap, DynamicFeeCap: dynamicFee.FeeCap, }, 100, 0x2, lggr) @@ -155,35 +155,34 @@ func TestTxm_NewDynamicFeeTx(t *testing.T) { }) t.Run("verifies gas tip and fees", func(t *testing.T) { - tests := []struct { + cases := []struct { name string tipcap *assets.Wei feecap *assets.Wei - setCfg func(*chainlink.Config, *chainlink.Secrets) + setCfg func(c *toml.EVMConfig) expectError string }{ {"gas tip = fee cap", assets.GWei(5), assets.GWei(5), nil, ""}, {"gas tip < fee cap", assets.GWei(4), assets.GWei(5), nil, ""}, {"gas tip > fee cap", assets.GWei(6), assets.GWei(5), nil, "gas fee cap must be greater than or equal to gas tip cap (fee cap: 5 gwei, tip cap: 6 gwei)"}, - {"fee cap exceeds max allowed", assets.GWei(5), assets.GWei(5), func(c *chainlink.Config, s *chainlink.Secrets) { - c.EVM[0].GasEstimator.PriceMax = assets.GWei(4) + {"fee cap exceeds max allowed", assets.GWei(5), assets.GWei(5), func(c *toml.EVMConfig) { + c.GasEstimator.PriceMax = assets.GWei(4) }, "specified gas fee cap of 5 gwei would exceed max configured gas price of 4 gwei"}, - {"ignores global min gas price", assets.GWei(5), assets.GWei(5), func(c *chainlink.Config, s *chainlink.Secrets) { - c.EVM[0].GasEstimator.PriceMin = assets.GWei(6) + {"ignores global min gas price", assets.GWei(5), assets.GWei(5), func(c *toml.EVMConfig) { + c.GasEstimator.PriceMin = assets.GWei(6) }, ""}, - {"tip cap below min allowed", assets.GWei(5), assets.GWei(5), func(c *chainlink.Config, s *chainlink.Secrets) { - c.EVM[0].GasEstimator.TipCapMin = assets.GWei(6) + {"tip cap below min allowed", assets.GWei(5), assets.GWei(5), func(c *toml.EVMConfig) { + c.GasEstimator.TipCapMin = assets.GWei(6) }, "specified gas tip cap of 5 gwei is below min configured gas tip of 6 gwei"}, } - for _, tt := range tests { + for _, tt := range cases { test := tt t.Run(test.name, func(t *testing.T) { - gcfg := configtest.NewGeneralConfig(t, test.setCfg) - cfg := evmtest.NewChainScopedConfig(t, gcfg) + cfg := testutils.NewTestChainScopedConfig(t, test.setCfg) cks := txmgr.NewEvmTxAttemptBuilder(*big.NewInt(1), cfg.EVM().GasEstimator(), kst, nil) dynamicFee := gas.DynamicFee{TipCap: test.tipcap, FeeCap: test.feecap} - _, _, err := cks.NewCustomTxAttempt(testutils.Context(t), txmgr.Tx{Sequence: &n, FromAddress: addr}, gas.EvmFee{ + _, _, err := cks.NewCustomTxAttempt(tests.Context(t), txmgr.Tx{Sequence: &n, FromAddress: addr}, gas.EvmFee{ DynamicTipCap: dynamicFee.TipCap, DynamicFeeCap: dynamicFee.FeeCap, }, 100, 0x2, lggr) @@ -210,7 +209,7 @@ func TestTxm_NewLegacyAttempt(t *testing.T) { t.Run("creates attempt with fields", func(t *testing.T) { var n evmtypes.Nonce - a, _, err := cks.NewCustomTxAttempt(testutils.Context(t), txmgr.Tx{Sequence: &n, FromAddress: addr}, gas.EvmFee{Legacy: assets.NewWeiI(25)}, 100, 0x0, lggr) + a, _, err := cks.NewCustomTxAttempt(tests.Context(t), txmgr.Tx{Sequence: &n, FromAddress: addr}, gas.EvmFee{Legacy: assets.NewWeiI(25)}, 100, 0x0, lggr) require.NoError(t, err) assert.Equal(t, 100, int(a.ChainSpecificFeeLimit)) assert.NotNil(t, a.TxFee.Legacy) @@ -220,7 +219,7 @@ func TestTxm_NewLegacyAttempt(t *testing.T) { }) t.Run("verifies max gas price", func(t *testing.T) { - _, _, err := cks.NewCustomTxAttempt(testutils.Context(t), txmgr.Tx{FromAddress: addr}, gas.EvmFee{Legacy: assets.NewWeiI(100)}, 100, 0x0, lggr) + _, _, err := cks.NewCustomTxAttempt(tests.Context(t), txmgr.Tx{FromAddress: addr}, gas.EvmFee{Legacy: assets.NewWeiI(100)}, 100, 0x0, lggr) require.Error(t, err) assert.Contains(t, err.Error(), fmt.Sprintf("specified gas price of 100 wei would exceed max configured gas price of 50 wei for key %s", addr.String())) }) @@ -243,7 +242,7 @@ func TestTxm_NewPurgeAttempt(t *testing.T) { est.On("BumpFee", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(bumpedFee, uint64(10_000), nil) cks := txmgr.NewEvmTxAttemptBuilder(*big.NewInt(1), gc, kst, est) lggr := logger.Test(t) - ctx := testutils.Context(t) + ctx := tests.Context(t) t.Run("creates legacy purge attempt with fields if previous attempt is legacy", func(t *testing.T) { n := evmtypes.Nonce(0) @@ -318,7 +317,7 @@ func TestTxm_NewCustomTxAttempt_NonRetryableErrors(t *testing.T) { legacyFee := assets.NewWeiI(100) t.Run("dynamic fee with legacy tx type", func(t *testing.T) { - _, retryable, err := cks.NewCustomTxAttempt(testutils.Context(t), txmgr.Tx{}, gas.EvmFee{ + _, retryable, err := cks.NewCustomTxAttempt(tests.Context(t), txmgr.Tx{}, gas.EvmFee{ DynamicTipCap: dynamicFee.TipCap, DynamicFeeCap: dynamicFee.FeeCap, }, 100, 0x0, lggr) @@ -326,13 +325,13 @@ func TestTxm_NewCustomTxAttempt_NonRetryableErrors(t *testing.T) { assert.False(t, retryable) }) t.Run("legacy fee with dynamic tx type", func(t *testing.T) { - _, retryable, err := cks.NewCustomTxAttempt(testutils.Context(t), txmgr.Tx{}, gas.EvmFee{Legacy: legacyFee}, 100, 0x2, lggr) + _, retryable, err := cks.NewCustomTxAttempt(tests.Context(t), txmgr.Tx{}, gas.EvmFee{Legacy: legacyFee}, 100, 0x2, lggr) require.Error(t, err) assert.False(t, retryable) }) t.Run("invalid type", func(t *testing.T) { - _, retryable, err := cks.NewCustomTxAttempt(testutils.Context(t), txmgr.Tx{}, gas.EvmFee{}, 100, 0xA, lggr) + _, retryable, err := cks.NewCustomTxAttempt(tests.Context(t), txmgr.Tx{}, gas.EvmFee{}, 100, 0xA, lggr) require.Error(t, err) assert.False(t, retryable) }) @@ -345,7 +344,7 @@ func TestTxm_EvmTxAttemptBuilder_RetryableEstimatorError(t *testing.T) { kst := ksmocks.NewEth(t) lggr := logger.Test(t) - ctx := testutils.Context(t) + ctx := tests.Context(t) cks := txmgr.NewEvmTxAttemptBuilder(*big.NewInt(1), &feeConfig{eip1559DynamicFees: true}, kst, est) t.Run("NewAttempt", func(t *testing.T) { diff --git a/core/chains/evm/txmgr/broadcaster_test.go b/core/chains/evm/txmgr/broadcaster_test.go index c80ae781034..3559c329dee 100644 --- a/core/chains/evm/txmgr/broadcaster_test.go +++ b/core/chains/evm/txmgr/broadcaster_test.go @@ -26,6 +26,7 @@ import ( "github.com/smartcontractkit/chainlink-common/pkg/services/servicetest" "github.com/smartcontractkit/chainlink-common/pkg/sqlutil" commonutils "github.com/smartcontractkit/chainlink-common/pkg/utils" + "github.com/smartcontractkit/chainlink-common/pkg/utils/tests" commonclient "github.com/smartcontractkit/chainlink/v2/common/client" txmgrcommon "github.com/smartcontractkit/chainlink/v2/common/txmgr" @@ -37,11 +38,11 @@ import ( gasmocks "github.com/smartcontractkit/chainlink/v2/core/chains/evm/gas/mocks" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/keystore" ksmocks "github.com/smartcontractkit/chainlink/v2/core/chains/evm/keystore/mocks" + "github.com/smartcontractkit/chainlink/v2/core/chains/evm/testutils" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/txmgr" evmtypes "github.com/smartcontractkit/chainlink/v2/core/chains/evm/types" "github.com/smartcontractkit/chainlink/v2/core/internal/cltest" "github.com/smartcontractkit/chainlink/v2/core/internal/cltest/heavyweight" - "github.com/smartcontractkit/chainlink/v2/core/internal/testutils" "github.com/smartcontractkit/chainlink/v2/core/internal/testutils/configtest" "github.com/smartcontractkit/chainlink/v2/core/internal/testutils/evmtest" "github.com/smartcontractkit/chainlink/v2/core/internal/testutils/pgtest" @@ -81,7 +82,7 @@ func TestEthBroadcaster_Lifecycle(t *testing.T) { cfg, db := heavyweight.FullTestDBV2(t, nil) txStore := cltest.NewTestTxStore(t, db) evmcfg := evmtest.NewChainScopedConfig(t, cfg) - ethClient := evmtest.NewEthClientMockWithDefaultChain(t) + ethClient := testutils.NewEthClientMockWithDefaultChain(t) ethKeyStore := cltest.NewKeyStore(t, db).Eth() cltest.MustInsertRandomKeyReturningState(t, ethKeyStore) estimator := gasmocks.NewEvmFeeEstimator(t) @@ -105,7 +106,7 @@ func TestEthBroadcaster_Lifecycle(t *testing.T) { // Can't close an unstarted instance err := eb.Close() require.Error(t, err) - ctx := testutils.Context(t) + ctx := tests.Context(t) // Can start a new instance err = eb.Start(ctx) @@ -139,7 +140,7 @@ func TestEthBroadcaster_LoadNextSequenceMapFailure_StartupSuccess(t *testing.T) cfg := configtest.NewTestGeneralConfig(t) txStore := cltest.NewTestTxStore(t, db) evmcfg := evmtest.NewChainScopedConfig(t, cfg) - ethClient := evmtest.NewEthClientMockWithDefaultChain(t) + ethClient := testutils.NewEthClientMockWithDefaultChain(t) ethKeyStore := cltest.NewKeyStore(t, db).Eth() cltest.MustInsertRandomKeyReturningState(t, ethKeyStore) estimator := gasmocks.NewEvmFeeEstimator(t) @@ -161,7 +162,7 @@ func TestEthBroadcaster_LoadNextSequenceMapFailure_StartupSuccess(t *testing.T) ) // Instance starts without error even if loading next sequence map fails - err := eb.Start(testutils.Context(t)) + err := eb.Start(tests.Context(t)) require.NoError(t, err) t.Cleanup(func() { assert.NoError(t, eb.Close()) }) } @@ -169,13 +170,13 @@ func TestEthBroadcaster_LoadNextSequenceMapFailure_StartupSuccess(t *testing.T) func TestEthBroadcaster_ProcessUnstartedEthTxs_Success(t *testing.T) { db := pgtest.NewSqlxDB(t) cfg := configtest.NewTestGeneralConfig(t) - ctx := testutils.Context(t) + ctx := tests.Context(t) txStore := cltest.NewTestTxStore(t, db) ethKeyStore := cltest.NewKeyStore(t, db).Eth() _, fromAddress := cltest.MustInsertRandomKey(t, ethKeyStore) _, otherAddress := cltest.MustInsertRandomKey(t, ethKeyStore) - ethClient := evmtest.NewEthClientMockWithDefaultChain(t) + ethClient := testutils.NewEthClientMockWithDefaultChain(t) evmcfg := evmtest.NewChainScopedConfig(t, cfg) checkerFactory := &txmgr.CheckerFactory{Client: ethClient} @@ -195,14 +196,14 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Success(t *testing.T) { } t.Run("no eth_txes at all", func(t *testing.T) { - retryable, err := eb.ProcessUnstartedTxs(testutils.Context(t), fromAddress) + retryable, err := eb.ProcessUnstartedTxs(tests.Context(t), fromAddress) assert.NoError(t, err) assert.False(t, retryable) }) t.Run("eth_txes exist for a different from address", func(t *testing.T) { - mustCreateUnstartedTx(t, txStore, otherAddress, toAddress, encodedPayload, gasLimit, value, &cltest.FixtureChainID) - retryable, err := eb.ProcessUnstartedTxs(testutils.Context(t), fromAddress) + mustCreateUnstartedTx(t, txStore, otherAddress, toAddress, encodedPayload, gasLimit, value, testutils.FixtureChainID) + retryable, err := eb.ProcessUnstartedTxs(tests.Context(t), fromAddress) assert.NoError(t, err) assert.False(t, retryable) }) @@ -237,7 +238,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Success(t *testing.T) { require.NoError(t, txStore.InsertTx(ctx, &etxUnconfirmed)) require.NoError(t, txStore.InsertTx(ctx, &etxWithError)) - retryable, err := eb.ProcessUnstartedTxs(testutils.Context(t), fromAddress) + retryable, err := eb.ProcessUnstartedTxs(tests.Context(t), fromAddress) assert.NoError(t, err) assert.False(t, retryable) }) @@ -314,7 +315,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Success(t *testing.T) { require.NoError(t, txStore.InsertTx(ctx, &earlierEthTx)) // Do the thing - retryable, err := eb.ProcessUnstartedTxs(testutils.Context(t), fromAddress) + retryable, err := eb.ProcessUnstartedTxs(tests.Context(t), fromAddress) assert.NoError(t, err) assert.False(t, retryable) @@ -390,10 +391,10 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Success(t *testing.T) { return tx.Nonce() == uint64(343) && tx.Value().Cmp(big.NewInt(242)) == 0 }), fromAddress).Return(commonclient.Successful, nil).Once() - etx := mustCreateUnstartedTx(t, txStore, fromAddress, toAddress, []byte{42, 42, 0}, gasLimit, big.Int(assets.NewEthValue(242)), &cltest.FixtureChainID) + etx := mustCreateUnstartedTx(t, txStore, fromAddress, toAddress, []byte{42, 42, 0}, gasLimit, big.Int(assets.NewEthValue(242)), testutils.FixtureChainID) // Do the thing { - retryable, err := eb.ProcessUnstartedTxs(testutils.Context(t), fromAddress) + retryable, err := eb.ProcessUnstartedTxs(tests.Context(t), fromAddress) assert.NoError(t, err) assert.False(t, retryable) } @@ -455,10 +456,10 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Success(t *testing.T) { return false }), "latest").Return(nil).Once() - ethTx := mustCreateUnstartedTxFromEvmTxRequest(t, txStore, txRequest, &cltest.FixtureChainID) + ethTx := mustCreateUnstartedTxFromEvmTxRequest(t, txStore, txRequest, testutils.FixtureChainID) { - retryable, err := eb.ProcessUnstartedTxs(testutils.Context(t), fromAddress) + retryable, err := eb.ProcessUnstartedTxs(tests.Context(t), fromAddress) assert.NoError(t, err) assert.False(t, retryable) } @@ -477,12 +478,12 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Success(t *testing.T) { return fmt.Sprintf("%s", callarg["value"]) == "0x21e" // 542 }), "latest").Return(errors.New("this is not a revert, something unexpected went wrong")).Once() - ethTx := mustCreateUnstartedGeneratedTx(t, txStore, fromAddress, &cltest.FixtureChainID, + ethTx := mustCreateUnstartedGeneratedTx(t, txStore, fromAddress, testutils.FixtureChainID, txRequestWithChecker(checker), txRequestWithValue(big.Int(assets.NewEthValue(542)))) { - retryable, err := eb.ProcessUnstartedTxs(testutils.Context(t), fromAddress) + retryable, err := eb.ProcessUnstartedTxs(tests.Context(t), fromAddress) assert.NoError(t, err) assert.False(t, retryable) } @@ -502,11 +503,11 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Success(t *testing.T) { return fmt.Sprintf("%s", callarg["value"]) == "0x282" // 642 }), "latest").Return(&jerr).Once() - ethTx := mustCreateUnstartedGeneratedTx(t, txStore, fromAddress, &cltest.FixtureChainID, + ethTx := mustCreateUnstartedGeneratedTx(t, txStore, fromAddress, testutils.FixtureChainID, txRequestWithChecker(checker), txRequestWithValue(big.Int(assets.NewEthValue(642)))) { - retryable, err := eb.ProcessUnstartedTxs(testutils.Context(t), fromAddress) + retryable, err := eb.ProcessUnstartedTxs(tests.Context(t), fromAddress) assert.NoError(t, err) assert.False(t, retryable) } @@ -523,12 +524,12 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Success(t *testing.T) { func TestEthBroadcaster_TransmitChecking(t *testing.T) { db := pgtest.NewSqlxDB(t) cfg := configtest.NewTestGeneralConfig(t) - ctx := testutils.Context(t) + ctx := tests.Context(t) txStore := cltest.NewTestTxStore(t, db) ethKeyStore := cltest.NewKeyStore(t, db).Eth() _, fromAddress := cltest.MustInsertRandomKeyReturningState(t, ethKeyStore) - ethClient := evmtest.NewEthClientMockWithDefaultChain(t) + ethClient := testutils.NewEthClientMockWithDefaultChain(t) evmcfg := evmtest.NewChainScopedConfig(t, cfg) checkerFactory := &testCheckerFactory{} ethClient.On("PendingNonceAt", mock.Anything, fromAddress).Return(uint64(0), nil).Once() @@ -546,11 +547,11 @@ func TestEthBroadcaster_TransmitChecking(t *testing.T) { return tx.Nonce() == 0 && tx.Value().Cmp(big.NewInt(442)) == 0 }), fromAddress).Return(commonclient.Successful, nil).Once() - ethTx := mustCreateUnstartedGeneratedTx(t, txStore, fromAddress, &cltest.FixtureChainID, + ethTx := mustCreateUnstartedGeneratedTx(t, txStore, fromAddress, testutils.FixtureChainID, txRequestWithValue(big.Int(assets.NewEthValue(442))), txRequestWithChecker(checker)) { - retryable, err := eb.ProcessUnstartedTxs(testutils.Context(t), fromAddress) + retryable, err := eb.ProcessUnstartedTxs(tests.Context(t), fromAddress) assert.NoError(t, err) assert.False(t, retryable) } @@ -569,11 +570,11 @@ func TestEthBroadcaster_TransmitChecking(t *testing.T) { return tx.Nonce() == 1 && tx.Value().Cmp(big.NewInt(442)) == 0 }), fromAddress).Return(commonclient.Successful, nil).Once() - ethTx := mustCreateUnstartedGeneratedTx(t, txStore, fromAddress, &cltest.FixtureChainID, + ethTx := mustCreateUnstartedGeneratedTx(t, txStore, fromAddress, testutils.FixtureChainID, txRequestWithValue(big.Int(assets.NewEthValue(442))), txRequestWithChecker(checker)) { - retryable, err := eb.ProcessUnstartedTxs(testutils.Context(t), fromAddress) + retryable, err := eb.ProcessUnstartedTxs(tests.Context(t), fromAddress) assert.NoError(t, err) assert.False(t, retryable) } @@ -588,9 +589,9 @@ func TestEthBroadcaster_TransmitChecking(t *testing.T) { // Checker will return a fatal error checkerFactory.err = errors.New("fatal checker error") - ethTx := mustCreateUnstartedGeneratedTx(t, txStore, fromAddress, &cltest.FixtureChainID, txRequestWithChecker(checker)) + ethTx := mustCreateUnstartedGeneratedTx(t, txStore, fromAddress, testutils.FixtureChainID, txRequestWithChecker(checker)) { - retryable, err := eb.ProcessUnstartedTxs(testutils.Context(t), fromAddress) + retryable, err := eb.ProcessUnstartedTxs(tests.Context(t), fromAddress) assert.NoError(t, err) assert.False(t, retryable) } @@ -610,7 +611,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_OptimisticLockingOnEthTx(t *testi txStore := cltest.NewTestTxStore(t, db) ccfg := evmtest.NewChainScopedConfig(t, cfg) evmcfg := txmgr.NewEvmTxmConfig(ccfg.EVM()) - ethClient := evmtest.NewEthClientMockWithDefaultChain(t) + ethClient := testutils.NewEthClientMockWithDefaultChain(t) ethKeyStore := cltest.NewKeyStore(t, db).Eth() _, fromAddress := cltest.MustInsertRandomKeyReturningState(t, ethKeyStore) estimator := gasmocks.NewEvmFeeEstimator(t) @@ -643,7 +644,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_OptimisticLockingOnEthTx(t *testi // Start instance of broadcaster servicetest.Run(t, eb) - mustCreateUnstartedGeneratedTx(t, txStore, fromAddress, &cltest.FixtureChainID) + mustCreateUnstartedGeneratedTx(t, txStore, fromAddress, testutils.FixtureChainID) go func() { select { @@ -659,7 +660,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_OptimisticLockingOnEthTx(t *testi }() { - retryable, err := eb.ProcessUnstartedTxs(testutils.Context(t), fromAddress) + retryable, err := eb.ProcessUnstartedTxs(tests.Context(t), fromAddress) assert.NoError(t, err) assert.False(t, retryable) } @@ -679,7 +680,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Success_WithMultiplier(t *testing evmcfg := evmtest.NewChainScopedConfig(t, cfg) - ethClient := evmtest.NewEthClientMockWithDefaultChain(t) + ethClient := testutils.NewEthClientMockWithDefaultChain(t) ethClient.On("PendingNonceAt", mock.Anything, fromAddress).Return(uint64(0), nil).Once() nonceTracker := txmgr.NewNonceTracker(logger.Test(t), txStore, txmgr.NewEvmTxmClient(ethClient, nil)) eb := NewTestEthBroadcaster(t, txStore, ethClient, ethKeyStore, cfg, evmcfg, &testCheckerFactory{}, false, nonceTracker) @@ -697,11 +698,11 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Success_WithMultiplier(t *testing FeeLimit: 1231, Strategy: txmgrcommon.NewSendEveryStrategy(), } - mustCreateUnstartedTxFromEvmTxRequest(t, txStore, txRequest, &cltest.FixtureChainID) + mustCreateUnstartedTxFromEvmTxRequest(t, txStore, txRequest, testutils.FixtureChainID) // Do the thing { - retryable, err := eb.ProcessUnstartedTxs(testutils.Context(t), fromAddress) + retryable, err := eb.ProcessUnstartedTxs(tests.Context(t), fromAddress) assert.NoError(t, err) assert.False(t, retryable) } @@ -717,7 +718,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_ResumingFromCrash(t *testing.T) { secondNonce := nextNonce + 1 cfg := configtest.NewGeneralConfig(t, nil) evmcfg := evmtest.NewChainScopedConfig(t, cfg) - ctx := testutils.Context(t) + ctx := tests.Context(t) t.Run("cannot be more than one transaction per address in an unfinished state", func(t *testing.T) { db := pgtest.NewSqlxDB(t) @@ -761,7 +762,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_ResumingFromCrash(t *testing.T) { ethKeyStore := cltest.NewKeyStore(t, db).Eth() _, fromAddress := cltest.RandomKey{Nonce: nextNonce.Int64()}.MustInsertWithState(t, ethKeyStore) - ethClient := evmtest.NewEthClientMockWithDefaultChain(t) + ethClient := testutils.NewEthClientMockWithDefaultChain(t) ethClient.On("PendingNonceAt", mock.Anything, fromAddress).Return(uint64(0), nil).Once() nonceTracker := txmgr.NewNonceTracker(logger.Test(t), txStore, txmgr.NewEvmTxmClient(ethClient, nil)) eb := NewTestEthBroadcaster(t, txStore, ethClient, ethKeyStore, cfg, evmcfg, &testCheckerFactory{}, false, nonceTracker) @@ -777,7 +778,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_ResumingFromCrash(t *testing.T) { // Do the thing { - retryable, err := eb.ProcessUnstartedTxs(testutils.Context(t), fromAddress) + retryable, err := eb.ProcessUnstartedTxs(tests.Context(t), fromAddress) assert.NoError(t, err) assert.False(t, retryable) } @@ -800,7 +801,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_ResumingFromCrash(t *testing.T) { ethKeyStore := cltest.NewKeyStore(t, db).Eth() _, fromAddress := cltest.RandomKey{Nonce: nextNonce.Int64()}.MustInsertWithState(t, ethKeyStore) - ethClient := evmtest.NewEthClientMockWithDefaultChain(t) + ethClient := testutils.NewEthClientMockWithDefaultChain(t) ethClient.On("PendingNonceAt", mock.Anything, fromAddress).Return(uint64(0), nil).Once() nonceTracker := txmgr.NewNonceTracker(logger.Test(t), txStore, txmgr.NewEvmTxmClient(ethClient, nil)) eb := NewTestEthBroadcaster(t, txStore, ethClient, ethKeyStore, cfg, evmcfg, &testCheckerFactory{}, false, nonceTracker) @@ -814,7 +815,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_ResumingFromCrash(t *testing.T) { // Do the thing { - retryable, err := eb.ProcessUnstartedTxs(testutils.Context(t), fromAddress) + retryable, err := eb.ProcessUnstartedTxs(tests.Context(t), fromAddress) assert.NoError(t, err) assert.False(t, retryable) } @@ -837,7 +838,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_ResumingFromCrash(t *testing.T) { ethKeyStore := cltest.NewKeyStore(t, db).Eth() _, fromAddress := cltest.RandomKey{Nonce: nextNonce.Int64()}.MustInsertWithState(t, ethKeyStore) - ethClient := evmtest.NewEthClientMockWithDefaultChain(t) + ethClient := testutils.NewEthClientMockWithDefaultChain(t) ethClient.On("PendingNonceAt", mock.Anything, fromAddress).Return(uint64(0), nil).Once() nonceTracker := txmgr.NewNonceTracker(logger.Test(t), txStore, txmgr.NewEvmTxmClient(ethClient, nil)) eb := NewTestEthBroadcaster(t, txStore, ethClient, ethKeyStore, cfg, evmcfg, &testCheckerFactory{}, false, nonceTracker) @@ -851,7 +852,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_ResumingFromCrash(t *testing.T) { // Do the thing { - retryable, err := eb.ProcessUnstartedTxs(testutils.Context(t), fromAddress) + retryable, err := eb.ProcessUnstartedTxs(tests.Context(t), fromAddress) assert.NoError(t, err) assert.False(t, retryable) } @@ -873,7 +874,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_ResumingFromCrash(t *testing.T) { ethKeyStore := cltest.NewKeyStore(t, db).Eth() _, fromAddress := cltest.RandomKey{Nonce: nextNonce.Int64()}.MustInsertWithState(t, ethKeyStore) - ethClient := evmtest.NewEthClientMockWithDefaultChain(t) + ethClient := testutils.NewEthClientMockWithDefaultChain(t) ethClient.On("PendingNonceAt", mock.Anything, fromAddress).Return(uint64(0), nil).Once() nonceTracker := txmgr.NewNonceTracker(logger.Test(t), txStore, txmgr.NewEvmTxmClient(ethClient, nil)) eb := NewTestEthBroadcaster(t, txStore, ethClient, ethKeyStore, cfg, evmcfg, &testCheckerFactory{}, false, nonceTracker) @@ -887,7 +888,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_ResumingFromCrash(t *testing.T) { // Do the thing { - retryable, err := eb.ProcessUnstartedTxs(testutils.Context(t), fromAddress) + retryable, err := eb.ProcessUnstartedTxs(tests.Context(t), fromAddress) assert.NoError(t, err) assert.False(t, retryable) } @@ -911,7 +912,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_ResumingFromCrash(t *testing.T) { ethKeyStore := cltest.NewKeyStore(t, db).Eth() _, fromAddress := cltest.RandomKey{Nonce: nextNonce.Int64()}.MustInsertWithState(t, ethKeyStore) - ethClient := evmtest.NewEthClientMockWithDefaultChain(t) + ethClient := testutils.NewEthClientMockWithDefaultChain(t) ethClient.On("PendingNonceAt", mock.Anything, fromAddress).Return(uint64(0), nil).Once() nonceTracker := txmgr.NewNonceTracker(logger.Test(t), txStore, txmgr.NewEvmTxmClient(ethClient, nil)) eb := NewTestEthBroadcaster(t, txStore, ethClient, ethKeyStore, cfg, evmcfg, &testCheckerFactory{}, false, nonceTracker) @@ -924,7 +925,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_ResumingFromCrash(t *testing.T) { }), fromAddress).Return(commonclient.Retryable, failedToReachNodeError).Once() // Do the thing - retryable, err := eb.ProcessUnstartedTxs(testutils.Context(t), fromAddress) + retryable, err := eb.ProcessUnstartedTxs(tests.Context(t), fromAddress) require.Error(t, err) assert.Contains(t, err.Error(), failedToReachNodeError.Error()) assert.True(t, retryable) @@ -953,7 +954,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_ResumingFromCrash(t *testing.T) { }) evmcfg := evmtest.NewChainScopedConfig(t, cfg) - ethClient := evmtest.NewEthClientMockWithDefaultChain(t) + ethClient := testutils.NewEthClientMockWithDefaultChain(t) ethClient.On("PendingNonceAt", mock.Anything, fromAddress).Return(uint64(0), nil).Once() nonceTracker := txmgr.NewNonceTracker(logger.Test(t), txStore, txmgr.NewEvmTxmClient(ethClient, nil)) eb := NewTestEthBroadcaster(t, txStore, ethClient, ethKeyStore, cfg, evmcfg, &testCheckerFactory{}, false, nonceTracker) @@ -972,7 +973,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_ResumingFromCrash(t *testing.T) { // Do the thing { - retryable, err := eb.ProcessUnstartedTxs(testutils.Context(t), fromAddress) + retryable, err := eb.ProcessUnstartedTxs(tests.Context(t), fromAddress) assert.NoError(t, err) assert.False(t, retryable) } @@ -994,7 +995,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_ResumingFromCrash(t *testing.T) { } func getLocalNextNonce(t *testing.T, nonceTracker txmgr.NonceTracker, fromAddress gethCommon.Address) uint64 { - n, err := nonceTracker.GetNextSequence(testutils.Context(t), fromAddress) + n, err := nonceTracker.GetNextSequence(tests.Context(t), fromAddress) require.NoError(t, err) require.NotNil(t, n) return uint64(n) @@ -1017,19 +1018,19 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Errors(t *testing.T) { _, fromAddress := cltest.MustInsertRandomKey(t, ethKeyStore) evmcfg := evmtest.NewChainScopedConfig(t, cfg) - ethClient := evmtest.NewEthClientMockWithDefaultChain(t) + ethClient := testutils.NewEthClientMockWithDefaultChain(t) ethClient.On("PendingNonceAt", mock.Anything, fromAddress).Return(uint64(0), nil).Once() lggr := logger.Test(t) txmClient := txmgr.NewEvmTxmClient(ethClient, nil) nonceTracker := txmgr.NewNonceTracker(lggr, txStore, txmClient) eb := NewTestEthBroadcaster(t, txStore, ethClient, ethKeyStore, cfg, evmcfg, &testCheckerFactory{}, false, nonceTracker) - ctx := testutils.Context(t) + ctx := tests.Context(t) require.NoError(t, commonutils.JustError(db.Exec(`SET CONSTRAINTS fk_pipeline_runs_pruning_key DEFERRED`))) require.NoError(t, commonutils.JustError(db.Exec(`SET CONSTRAINTS pipeline_runs_pipeline_spec_id_fkey DEFERRED`))) t.Run("if external wallet sent a transaction from the account and now the nonce is one higher than it should be and we got replacement underpriced then we assume a previous transaction of ours was the one that succeeded, and hand off to EthConfirmer", func(t *testing.T) { - mustCreateUnstartedTx(t, txStore, fromAddress, toAddress, encodedPayload, gasLimit, value, &cltest.FixtureChainID) + mustCreateUnstartedTx(t, txStore, fromAddress, toAddress, encodedPayload, gasLimit, value, testutils.FixtureChainID) // First send, replacement underpriced ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *gethTypes.Transaction) bool { return tx.Nonce() == uint64(0) @@ -1067,7 +1068,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Errors(t *testing.T) { localNextNonce := getLocalNextNonce(t, nonceTracker, fromAddress) t.Run("without callback", func(t *testing.T) { - etx := mustCreateUnstartedTx(t, txStore, fromAddress, toAddress, encodedPayload, gasLimit, value, &cltest.FixtureChainID) + etx := mustCreateUnstartedTx(t, txStore, fromAddress, toAddress, encodedPayload, gasLimit, value, testutils.FixtureChainID) ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *gethTypes.Transaction) bool { return tx.Nonce() == localNextNonce }), fromAddress).Return(commonclient.Fatal, errors.New(fatalErrorExample)).Once() @@ -1111,7 +1112,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Errors(t *testing.T) { } t.Run("with erroring callback bails out", func(t *testing.T) { - require.NoError(t, txStore.InsertTx(testutils.Context(t), &etx)) + require.NoError(t, txStore.InsertTx(tests.Context(t), &etx)) fn := func(ctx context.Context, id uuid.UUID, result interface{}, err error) error { return errors.New("something exploded in the callback") } @@ -1171,7 +1172,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Errors(t *testing.T) { TxFeeExceedsCapError := "tx fee (1.10 ether) exceeds the configured cap (1.00 ether)" localNextNonce := getLocalNextNonce(t, nonceTracker, fromAddress) ethClient.On("PendingNonceAt", mock.Anything, fromAddress).Return(localNextNonce, nil).Once() - etx := mustCreateUnstartedTx(t, txStore, fromAddress, toAddress, encodedPayload, gasLimit, value, &cltest.FixtureChainID) + etx := mustCreateUnstartedTx(t, txStore, fromAddress, toAddress, encodedPayload, gasLimit, value, testutils.FixtureChainID) ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *gethTypes.Transaction) bool { return tx.Nonce() == localNextNonce }), fromAddress).Return(commonclient.ExceedsMaxFee, errors.New(TxFeeExceedsCapError)).Twice() @@ -1229,7 +1230,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Errors(t *testing.T) { t.Run("eth Client call fails with an unexpected random error, and transaction was not accepted into mempool", func(t *testing.T) { retryableErrorExample := "some unknown error" localNextNonce := getLocalNextNonce(t, nonceTracker, fromAddress) - etx := mustCreateUnstartedTx(t, txStore, fromAddress, toAddress, encodedPayload, gasLimit, value, &cltest.FixtureChainID) + etx := mustCreateUnstartedTx(t, txStore, fromAddress, toAddress, encodedPayload, gasLimit, value, testutils.FixtureChainID) ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *gethTypes.Transaction) bool { return tx.Nonce() == localNextNonce }), fromAddress).Return(commonclient.Unknown, errors.New(retryableErrorExample)).Once() @@ -1281,7 +1282,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Errors(t *testing.T) { t.Run("eth client call fails with an unexpected random error, and the nonce check also subsequently fails", func(t *testing.T) { retryableErrorExample := "some unknown error" localNextNonce := getLocalNextNonce(t, nonceTracker, fromAddress) - etx := mustCreateUnstartedTx(t, txStore, fromAddress, toAddress, encodedPayload, gasLimit, value, &cltest.FixtureChainID) + etx := mustCreateUnstartedTx(t, txStore, fromAddress, toAddress, encodedPayload, gasLimit, value, testutils.FixtureChainID) ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *gethTypes.Transaction) bool { return tx.Nonce() == localNextNonce }), fromAddress).Return(commonclient.Unknown, errors.New(retryableErrorExample)).Once() @@ -1333,7 +1334,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Errors(t *testing.T) { t.Run("eth Client call fails with an unexpected random error, and transaction was accepted into mempool", func(t *testing.T) { retryableErrorExample := "some strange RPC returns an unexpected thing" localNextNonce := getLocalNextNonce(t, nonceTracker, fromAddress) - etx := mustCreateUnstartedTx(t, txStore, fromAddress, toAddress, encodedPayload, gasLimit, value, &cltest.FixtureChainID) + etx := mustCreateUnstartedTx(t, txStore, fromAddress, toAddress, encodedPayload, gasLimit, value, testutils.FixtureChainID) ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *gethTypes.Transaction) bool { return tx.Nonce() == localNextNonce }), fromAddress).Return(commonclient.Unknown, errors.New(retryableErrorExample)).Once() @@ -1365,7 +1366,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Errors(t *testing.T) { // This is a configuration error by the node operator, since it means they set the base gas level too low. underpricedError := "transaction underpriced" localNextNonce := getLocalNextNonce(t, nonceTracker, fromAddress) - etx := mustCreateUnstartedTx(t, txStore, fromAddress, toAddress, encodedPayload, gasLimit, value, &cltest.FixtureChainID) + etx := mustCreateUnstartedTx(t, txStore, fromAddress, toAddress, encodedPayload, gasLimit, value, testutils.FixtureChainID) // First was underpriced ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *gethTypes.Transaction) bool { @@ -1481,7 +1482,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Errors(t *testing.T) { c.EVM[0].GasEstimator.BumpPercent = ptr[uint16](0) })) eb2 := NewTestEthBroadcaster(t, txStore, ethClient, ethKeyStore, cfg, evmcfg2, &testCheckerFactory{}, false, nonceTracker) - mustCreateUnstartedTx(t, txStore, fromAddress, toAddress, encodedPayload, gasLimit, value, &cltest.FixtureChainID) + mustCreateUnstartedTx(t, txStore, fromAddress, toAddress, encodedPayload, gasLimit, value, testutils.FixtureChainID) // First was underpriced ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *gethTypes.Transaction) bool { @@ -1501,7 +1502,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Errors(t *testing.T) { t.Run("eth tx is left in progress if eth node returns insufficient eth", func(t *testing.T) { insufficientEthError := "insufficient funds for transfer" localNextNonce := getLocalNextNonce(t, nonceTracker, fromAddress) - etx := mustCreateUnstartedTx(t, txStore, fromAddress, toAddress, encodedPayload, gasLimit, value, &cltest.FixtureChainID) + etx := mustCreateUnstartedTx(t, txStore, fromAddress, toAddress, encodedPayload, gasLimit, value, testutils.FixtureChainID) ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *gethTypes.Transaction) bool { return tx.Nonce() == localNextNonce }), fromAddress).Return(commonclient.InsufficientFunds, errors.New(insufficientEthError)).Once() @@ -1531,7 +1532,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Errors(t *testing.T) { t.Run("eth tx is left in progress if nonce is too high", func(t *testing.T) { localNextNonce := getLocalNextNonce(t, nonceTracker, fromAddress) nonceGapError := "NonceGap, Future nonce. Expected nonce: " + strconv.FormatUint(localNextNonce, 10) - etx := mustCreateUnstartedTx(t, txStore, fromAddress, toAddress, encodedPayload, gasLimit, value, &cltest.FixtureChainID) + etx := mustCreateUnstartedTx(t, txStore, fromAddress, toAddress, encodedPayload, gasLimit, value, testutils.FixtureChainID) ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *gethTypes.Transaction) bool { return tx.Nonce() == localNextNonce }), fromAddress).Return(commonclient.Retryable, errors.New(nonceGapError)).Once() @@ -1573,7 +1574,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Errors(t *testing.T) { localNextNonce := getLocalNextNonce(t, nonceTracker, fromAddress) ethClient.On("PendingNonceAt", mock.Anything, fromAddress).Return(localNextNonce, nil).Once() eb2 := NewTestEthBroadcaster(t, txStore, ethClient, ethKeyStore, cfg, evmcfg2, &testCheckerFactory{}, false, nonceTracker) - mustCreateUnstartedTx(t, txStore, fromAddress, toAddress, encodedPayload, gasLimit, value, &cltest.FixtureChainID) + mustCreateUnstartedTx(t, txStore, fromAddress, toAddress, encodedPayload, gasLimit, value, testutils.FixtureChainID) underpricedError := "transaction underpriced" localNextNonce = getLocalNextNonce(t, nonceTracker, fromAddress) ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *gethTypes.Transaction) bool { @@ -1595,7 +1596,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Errors(t *testing.T) { // This is a configuration error by the node operator, since it means they set the base gas level too low. underpricedError := "transaction underpriced" localNextNonce := getLocalNextNonce(t, nonceTracker, fromAddress) - mustCreateUnstartedTx(t, txStore, fromAddress, toAddress, encodedPayload, gasLimit, value, &cltest.FixtureChainID) + mustCreateUnstartedTx(t, txStore, fromAddress, toAddress, encodedPayload, gasLimit, value, testutils.FixtureChainID) // Check gas tip cap verification evmcfg2 := evmtest.NewChainScopedConfig(t, configtest.NewGeneralConfig(t, func(c *chainlink.Config, s *chainlink.Secrets) { @@ -1657,21 +1658,21 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_KeystoreErrors(t *testing.T) { _, fromAddress := cltest.MustInsertRandomKeyReturningState(t, realKeystore.Eth()) evmcfg := evmtest.NewChainScopedConfig(t, cfg) - ethClient := evmtest.NewEthClientMockWithDefaultChain(t) + ethClient := testutils.NewEthClientMockWithDefaultChain(t) kst := ksmocks.NewEth(t) addresses := []gethCommon.Address{fromAddress} - kst.On("EnabledAddressesForChain", mock.Anything, &cltest.FixtureChainID).Return(addresses, nil).Once() + kst.On("EnabledAddressesForChain", mock.Anything, testutils.FixtureChainID).Return(addresses, nil).Once() ethClient.On("PendingNonceAt", mock.Anything, fromAddress).Return(uint64(0), nil).Once() lggr := logger.Test(t) nonceTracker := txmgr.NewNonceTracker(lggr, txStore, txmgr.NewEvmTxmClient(ethClient, nil)) eb := NewTestEthBroadcaster(t, txStore, ethClient, kst, cfg, evmcfg, &testCheckerFactory{}, false, nonceTracker) - ctx := testutils.Context(t) + ctx := tests.Context(t) _, err := nonceTracker.GetNextSequence(ctx, fromAddress) require.NoError(t, err) t.Run("tx signing fails", func(t *testing.T) { - etx := mustCreateUnstartedTx(t, txStore, fromAddress, toAddress, encodedPayload, gasLimit, value, &cltest.FixtureChainID) + etx := mustCreateUnstartedTx(t, txStore, fromAddress, toAddress, encodedPayload, gasLimit, value, testutils.FixtureChainID) tx := *gethTypes.NewTx(&gethTypes.LegacyTx{}) kst.On("SignTx", mock.Anything, fromAddress, @@ -1711,7 +1712,7 @@ func TestEthBroadcaster_Trigger(t *testing.T) { txStore := cltest.NewTestTxStore(t, db) evmcfg := evmtest.NewChainScopedConfig(t, cfg) ethKeyStore := cltest.NewKeyStore(t, db).Eth() - ethClient := evmtest.NewEthClientMockWithDefaultChain(t) + ethClient := testutils.NewEthClientMockWithDefaultChain(t) lggr := logger.Test(t) nonceTracker := txmgr.NewNonceTracker(lggr, txStore, txmgr.NewEvmTxmClient(ethClient, nil)) eb := NewTestEthBroadcaster(t, txStore, ethClient, ethKeyStore, cfg, evmcfg, &testCheckerFactory{}, false, nonceTracker) @@ -1723,7 +1724,7 @@ func TestEthBroadcaster_Trigger(t *testing.T) { func TestEthBroadcaster_SyncNonce(t *testing.T) { db := pgtest.NewSqlxDB(t) - ctx := testutils.Context(t) + ctx := tests.Context(t) lggr, observed := logger.TestObserved(t, zapcore.DebugLevel) cfg := configtest.NewGeneralConfig(t, func(c *chainlink.Config, s *chainlink.Secrets) { @@ -1744,12 +1745,12 @@ func TestEthBroadcaster_SyncNonce(t *testing.T) { ge := evmcfg.EVM().GasEstimator() t.Run("does nothing if nonce sync is disabled", func(t *testing.T) { - ethClient := evmtest.NewEthClientMockWithDefaultChain(t) + ethClient := testutils.NewEthClientMockWithDefaultChain(t) txBuilder := txmgr.NewEvmTxAttemptBuilder(*ethClient.ConfiguredChainID(), ge, kst, estimator) kst := ksmocks.NewEth(t) addresses := []gethCommon.Address{fromAddress} - kst.On("EnabledAddressesForChain", mock.Anything, &cltest.FixtureChainID).Return(addresses, nil).Once() + kst.On("EnabledAddressesForChain", mock.Anything, testutils.FixtureChainID).Return(addresses, nil).Once() ethClient.On("PendingNonceAt", mock.Anything, fromAddress).Return(uint64(0), nil).Once() txmClient := txmgr.NewEvmTxmClient(ethClient, nil) eb := txmgr.NewEvmBroadcaster(txStore, txmClient, evmTxmCfg, txmgr.NewEvmTxmFeeConfig(ge), evmcfg.EVM().Transactions(), cfg.Database().Listener(), kst, txBuilder, lggr, checkerFactory, false) @@ -1758,7 +1759,7 @@ func TestEthBroadcaster_SyncNonce(t *testing.T) { defer func() { assert.NoError(t, eb.Close()) }() - testutils.WaitForLogMessage(t, observed, "Skipping sequence auto-sync") + tests.AssertLogEventually(t, observed, "Skipping sequence auto-sync") }) } @@ -1771,11 +1772,11 @@ func TestEthBroadcaster_NonceTracker_InProgressTx(t *testing.T) { ethKeyStore := cltest.NewKeyStore(t, db).Eth() _, fromAddress := cltest.MustInsertRandomKey(t, ethKeyStore) - ethClient := evmtest.NewEthClientMockWithDefaultChain(t) + ethClient := testutils.NewEthClientMockWithDefaultChain(t) evmcfg := evmtest.NewChainScopedConfig(t, cfg) checkerFactory := &txmgr.CheckerFactory{Client: ethClient} lggr := logger.Test(t) - ctx := testutils.Context(t) + ctx := tests.Context(t) t.Run("maintains the proper nonce if there is an in-progress tx during startup", func(t *testing.T) { inProgressTxNonce := uint64(0) diff --git a/core/chains/evm/txmgr/confirmer_test.go b/core/chains/evm/txmgr/confirmer_test.go index 2ce34505234..a3ae0a0a5db 100644 --- a/core/chains/evm/txmgr/confirmer_test.go +++ b/core/chains/evm/txmgr/confirmer_test.go @@ -23,6 +23,7 @@ import ( "github.com/smartcontractkit/chainlink-common/pkg/logger" "github.com/smartcontractkit/chainlink-common/pkg/services/servicetest" + "github.com/smartcontractkit/chainlink-common/pkg/utils/tests" commonclient "github.com/smartcontractkit/chainlink/v2/common/client" commonfee "github.com/smartcontractkit/chainlink/v2/common/fee" @@ -35,11 +36,11 @@ import ( gasmocks "github.com/smartcontractkit/chainlink/v2/core/chains/evm/gas/mocks" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/keystore" ksmocks "github.com/smartcontractkit/chainlink/v2/core/chains/evm/keystore/mocks" + "github.com/smartcontractkit/chainlink/v2/core/chains/evm/testutils" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/txmgr" evmtypes "github.com/smartcontractkit/chainlink/v2/core/chains/evm/types" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils" "github.com/smartcontractkit/chainlink/v2/core/internal/cltest" - "github.com/smartcontractkit/chainlink/v2/core/internal/testutils" "github.com/smartcontractkit/chainlink/v2/core/internal/testutils/configtest" "github.com/smartcontractkit/chainlink/v2/core/internal/testutils/evmtest" "github.com/smartcontractkit/chainlink/v2/core/internal/testutils/pgtest" @@ -62,7 +63,7 @@ func newBroadcastLegacyEthTxAttempt(t *testing.T, etxID int64, gasPrice ...int64 } func mustTxBeInState(t *testing.T, txStore txmgr.TestEvmTxStore, tx txmgr.Tx, expectedState txmgrtypes.TxState) { - etx, err := txStore.FindTxWithAttempts(testutils.Context(t), tx.ID) + etx, err := txStore.FindTxWithAttempts(tests.Context(t), tx.ID) require.NoError(t, err) require.Equal(t, expectedState, etx.State) } @@ -70,7 +71,7 @@ func mustTxBeInState(t *testing.T, txStore txmgr.TestEvmTxStore, tx txmgr.Tx, ex func newTxReceipt(hash gethCommon.Hash, blockNumber int, txIndex uint) evmtypes.Receipt { return evmtypes.Receipt{ TxHash: hash, - BlockHash: utils.NewHash(), + BlockHash: testutils.NewHash(), BlockNumber: big.NewInt(int64(blockNumber)), TransactionIndex: txIndex, Status: uint64(1), @@ -92,7 +93,7 @@ func mustInsertInProgressEthTx(t *testing.T, txStore txmgr.TestEvmTxStore, nonce etx.State = txmgrcommon.TxInProgress n := evmtypes.Nonce(nonce) etx.Sequence = &n - require.NoError(t, txStore.InsertTx(testutils.Context(t), &etx)) + require.NoError(t, txStore.InsertTx(tests.Context(t), &etx)) return etx } @@ -105,7 +106,7 @@ func mustInsertConfirmedEthTx(t *testing.T, txStore txmgr.TestEvmTxStore, nonce now := time.Now() etx.BroadcastAt = &now etx.InitialBroadcastAt = &now - require.NoError(t, txStore.InsertTx(testutils.Context(t), &etx)) + require.NoError(t, txStore.InsertTx(tests.Context(t), &etx)) return etx } @@ -117,7 +118,7 @@ func TestEthConfirmer_Lifecycle(t *testing.T) { gconfig, config := newTestChainScopedConfig(t) txStore := newTxStore(t, db) - ethClient := evmtest.NewEthClientMockWithDefaultChain(t) + ethClient := testutils.NewEthClientMockWithDefaultChain(t) ethKeyStore := cltest.NewKeyStore(t, db).Eth() // Add some fromAddresses @@ -131,7 +132,7 @@ func TestEthConfirmer_Lifecycle(t *testing.T) { txBuilder := txmgr.NewEvmTxAttemptBuilder(*ethClient.ConfiguredChainID(), ge, ethKeyStore, feeEstimator) stuckTxDetector := txmgr.NewStuckTxDetector(lggr, testutils.FixtureChainID, "", assets.NewWei(assets.NewEth(100).ToInt()), config.EVM().Transactions().AutoPurge(), feeEstimator, txStore, ethClient) ec := txmgr.NewEvmConfirmer(txStore, txmgr.NewEvmTxmClient(ethClient, nil), txmgr.NewEvmTxmConfig(config.EVM()), txmgr.NewEvmTxmFeeConfig(ge), config.EVM().Transactions(), gconfig.Database(), ethKeyStore, txBuilder, lggr, stuckTxDetector) - ctx := testutils.Context(t) + ctx := tests.Context(t) // Can't close unstarted instance err := ec.Close() @@ -145,14 +146,14 @@ func TestEthConfirmer_Lifecycle(t *testing.T) { err = ec.Start(ctx) require.Error(t, err) head := evmtypes.Head{ - Hash: utils.NewHash(), + Hash: testutils.NewHash(), Number: 10, Parent: &evmtypes.Head{ - Hash: utils.NewHash(), + Hash: testutils.NewHash(), Number: 9, Parent: &evmtypes.Head{ Number: 8, - Hash: utils.NewHash(), + Hash: testutils.NewHash(), Parent: nil, }, }, @@ -188,7 +189,7 @@ func TestEthConfirmer_CheckForReceipts(t *testing.T) { gconfig, config := newTestChainScopedConfig(t) txStore := cltest.NewTestTxStore(t, db) - ethClient := evmtest.NewEthClientMockWithDefaultChain(t) + ethClient := testutils.NewEthClientMockWithDefaultChain(t) ethKeyStore := cltest.NewKeyStore(t, db).Eth() _, fromAddress := cltest.MustInsertRandomKey(t, ethKeyStore) @@ -196,7 +197,7 @@ func TestEthConfirmer_CheckForReceipts(t *testing.T) { ec := newEthConfirmer(t, txStore, ethClient, gconfig, config, ethKeyStore, nil) nonce := int64(0) - ctx := testutils.Context(t) + ctx := tests.Context(t) blockNum := int64(0) t.Run("only finds eth_txes in unconfirmed state with at least one broadcast attempt", func(t *testing.T) { @@ -244,8 +245,8 @@ func TestEthConfirmer_CheckForReceipts(t *testing.T) { t.Run("saves nothing if returned receipt does not match the attempt", func(t *testing.T) { txmReceipt := evmtypes.Receipt{ - TxHash: utils.NewHash(), - BlockHash: utils.NewHash(), + TxHash: testutils.NewHash(), + BlockHash: testutils.NewHash(), BlockNumber: big.NewInt(42), TransactionIndex: uint(1), } @@ -272,7 +273,7 @@ func TestEthConfirmer_CheckForReceipts(t *testing.T) { t.Run("saves nothing if query returns error", func(t *testing.T) { txmReceipt := evmtypes.Receipt{ TxHash: attempt1_1.Hash, - BlockHash: utils.NewHash(), + BlockHash: testutils.NewHash(), BlockNumber: big.NewInt(42), TransactionIndex: uint(1), } @@ -305,7 +306,7 @@ func TestEthConfirmer_CheckForReceipts(t *testing.T) { t.Run("saves eth_receipt and marks eth_tx as confirmed when geth client returns valid receipt", func(t *testing.T) { txmReceipt := evmtypes.Receipt{ TxHash: attempt1_1.Hash, - BlockHash: utils.NewHash(), + BlockHash: testutils.NewHash(), BlockNumber: big.NewInt(42), TransactionIndex: uint(1), Status: uint64(1), @@ -364,7 +365,7 @@ func TestEthConfirmer_CheckForReceipts(t *testing.T) { txmReceipt := evmtypes.Receipt{ TxHash: attempt2_2.Hash, - BlockHash: utils.NewHash(), + BlockHash: testutils.NewHash(), BlockNumber: big.NewInt(42), TransactionIndex: uint(1), Status: uint64(1), @@ -431,7 +432,7 @@ func TestEthConfirmer_CheckForReceipts(t *testing.T) { // NOTE: This should never happen, but we shouldn't panic regardless receipt := evmtypes.Receipt{ TxHash: attempt3_1.Hash, - BlockHash: utils.NewHash(), + BlockHash: testutils.NewHash(), Status: uint64(1), } ethClient.On("BatchCallContext", mock.Anything, mock.MatchedBy(func(b []rpc.BatchElem) bool { @@ -454,7 +455,7 @@ func TestEthConfirmer_CheckForReceipts(t *testing.T) { require.Len(t, attempt3_1.Receipts, 0) }) t.Run("handles case where eth_receipt already exists somehow", func(t *testing.T) { - ethReceipt := mustInsertEthReceipt(t, txStore, 42, utils.NewHash(), attempt3_1.Hash) + ethReceipt := mustInsertEthReceipt(t, txStore, 42, testutils.NewHash(), attempt3_1.Hash) txmReceipt := evmtypes.Receipt{ TxHash: attempt3_1.Hash, BlockHash: ethReceipt.BlockHash, @@ -502,7 +503,7 @@ func TestEthConfirmer_CheckForReceipts(t *testing.T) { txmReceipt := evmtypes.Receipt{ TxHash: attempt4_2.Hash, - BlockHash: utils.NewHash(), + BlockHash: testutils.NewHash(), BlockNumber: big.NewInt(42), TransactionIndex: uint(1), Status: uint64(1), @@ -550,7 +551,7 @@ func TestEthConfirmer_CheckForReceipts(t *testing.T) { t.Run("simulate on revert", func(t *testing.T) { txmReceipt := evmtypes.Receipt{ TxHash: attempt5_1.Hash, - BlockHash: utils.NewHash(), + BlockHash: testutils.NewHash(), BlockNumber: big.NewInt(42), TransactionIndex: uint(1), Status: uint64(0), @@ -604,12 +605,12 @@ func TestEthConfirmer_CheckForReceipts_batching(t *testing.T) { _, fromAddress := cltest.MustInsertRandomKeyReturningState(t, ethKeyStore) - ethClient := evmtest.NewEthClientMockWithDefaultChain(t) + ethClient := testutils.NewEthClientMockWithDefaultChain(t) evmcfg := evmtest.NewChainScopedConfig(t, cfg) ec := newEthConfirmer(t, txStore, ethClient, cfg, evmcfg, ethKeyStore, nil) - ctx := testutils.Context(t) + ctx := tests.Context(t) etx := cltest.MustInsertUnconfirmedEthTx(t, txStore, 0, fromAddress) var attempts []txmgr.TxAttempt @@ -664,12 +665,12 @@ func TestEthConfirmer_CheckForReceipts_HandlesNonFwdTxsWithForwardingEnabled(t * txStore := cltest.NewTestTxStore(t, db) ethKeyStore := cltest.NewKeyStore(t, db).Eth() - ethClient := evmtest.NewEthClientMockWithDefaultChain(t) + ethClient := testutils.NewEthClientMockWithDefaultChain(t) evmcfg := evmtest.NewChainScopedConfig(t, cfg) _, fromAddress := cltest.MustInsertRandomKeyReturningState(t, ethKeyStore) ec := newEthConfirmer(t, txStore, ethClient, cfg, evmcfg, ethKeyStore, nil) - ctx := testutils.Context(t) + ctx := tests.Context(t) // tx is not forwarded and doesn't have meta set. EthConfirmer should handle nil meta values etx := cltest.MustInsertUnconfirmedEthTx(t, txStore, 0, fromAddress) attempt := newBroadcastLegacyEthTxAttempt(t, etx.ID, 2) @@ -681,7 +682,7 @@ func TestEthConfirmer_CheckForReceipts_HandlesNonFwdTxsWithForwardingEnabled(t * txmReceipt := evmtypes.Receipt{ TxHash: attempt.Hash, - BlockHash: utils.NewHash(), + BlockHash: testutils.NewHash(), BlockNumber: big.NewInt(42), TransactionIndex: uint(1), Status: uint64(1), @@ -717,12 +718,12 @@ func TestEthConfirmer_CheckForReceipts_only_likely_confirmed(t *testing.T) { _, fromAddress := cltest.MustInsertRandomKeyReturningState(t, ethKeyStore) - ethClient := evmtest.NewEthClientMockWithDefaultChain(t) + ethClient := testutils.NewEthClientMockWithDefaultChain(t) evmcfg := evmtest.NewChainScopedConfig(t, cfg) ec := newEthConfirmer(t, txStore, ethClient, cfg, evmcfg, ethKeyStore, nil) - ctx := testutils.Context(t) + ctx := tests.Context(t) var attempts []txmgr.TxAttempt // inserting in DESC nonce order to test DB ASC ordering @@ -773,10 +774,10 @@ func TestEthConfirmer_CheckForReceipts_should_not_check_for_likely_unconfirmed(t _, fromAddress := cltest.MustInsertRandomKeyReturningState(t, ethKeyStore) - ethClient := evmtest.NewEthClientMockWithDefaultChain(t) + ethClient := testutils.NewEthClientMockWithDefaultChain(t) ec := newEthConfirmer(t, txStore, ethClient, gconfig, config, ethKeyStore, nil) - ctx := testutils.Context(t) + ctx := tests.Context(t) etx := cltest.MustInsertUnconfirmedEthTx(t, txStore, 1, fromAddress) for i := 0; i < 4; i++ { @@ -802,12 +803,12 @@ func TestEthConfirmer_CheckForReceipts_confirmed_missing_receipt_scoped_to_key(t _, fromAddress1_2 := cltest.MustInsertRandomKeyReturningState(t, ethKeyStore) _, fromAddress2_1 := cltest.MustInsertRandomKeyReturningState(t, ethKeyStore) - ethClient := evmtest.NewEthClientMockWithDefaultChain(t) + ethClient := testutils.NewEthClientMockWithDefaultChain(t) ethClient.On("SequenceAt", mock.Anything, mock.Anything, mock.Anything).Return(evmtypes.Nonce(20), nil) evmcfg := evmtest.NewChainScopedConfig(t, cfg) ec := newEthConfirmer(t, txStore, ethClient, cfg, evmcfg, ethKeyStore, nil) - ctx := testutils.Context(t) + ctx := tests.Context(t) // STATE // key 1, tx with nonce 0 is unconfirmed @@ -869,12 +870,12 @@ func TestEthConfirmer_CheckForReceipts_confirmed_missing_receipt(t *testing.T) { _, fromAddress := cltest.MustInsertRandomKeyReturningState(t, ethKeyStore) - ethClient := evmtest.NewEthClientMockWithDefaultChain(t) + ethClient := testutils.NewEthClientMockWithDefaultChain(t) evmcfg := evmtest.NewChainScopedConfig(t, cfg) ec := newEthConfirmer(t, txStore, ethClient, cfg, evmcfg, ethKeyStore, nil) - ctx := testutils.Context(t) + ctx := tests.Context(t) // STATE // eth_txes with nonce 0 has two attempts (broadcast before block 21 and 41) the first of which will get a receipt @@ -911,14 +912,14 @@ func TestEthConfirmer_CheckForReceipts_confirmed_missing_receipt(t *testing.T) { t.Run("marks buried eth_txes as 'confirmed_missing_receipt'", func(t *testing.T) { txmReceipt0 := evmtypes.Receipt{ TxHash: attempt0_2.Hash, - BlockHash: utils.NewHash(), + BlockHash: testutils.NewHash(), BlockNumber: big.NewInt(42), TransactionIndex: uint(1), Status: uint64(1), } txmReceipt3 := evmtypes.Receipt{ TxHash: attempt3_1.Hash, - BlockHash: utils.NewHash(), + BlockHash: testutils.NewHash(), BlockNumber: big.NewInt(42), TransactionIndex: uint(1), Status: uint64(1), @@ -986,7 +987,7 @@ func TestEthConfirmer_CheckForReceipts_confirmed_missing_receipt(t *testing.T) { t.Run("marks eth_txes with state 'confirmed_missing_receipt' as 'confirmed' if a receipt finally shows up", func(t *testing.T) { txmReceipt := evmtypes.Receipt{ TxHash: attempt2_1.Hash, - BlockHash: utils.NewHash(), + BlockHash: testutils.NewHash(), BlockNumber: big.NewInt(43), TransactionIndex: uint(1), Status: uint64(1), @@ -1125,12 +1126,13 @@ func TestEthConfirmer_CheckConfirmedMissingReceipt(t *testing.T) { _, fromAddress := cltest.MustInsertRandomKeyReturningState(t, ethKeyStore) - ethClient := evmtest.NewEthClientMockWithDefaultChain(t) + ethClient := testutils.NewEthClientMockWithDefaultChain(t) + ethClient.On("IsL2").Return(false).Maybe() evmcfg := evmtest.NewChainScopedConfig(t, cfg) ec := newEthConfirmer(t, txStore, ethClient, cfg, evmcfg, ethKeyStore, nil) - ctx := testutils.Context(t) + ctx := tests.Context(t) // STATE // eth_txes with nonce 0 has two attempts, the later attempt with higher gas fees @@ -1204,12 +1206,13 @@ func TestEthConfirmer_CheckConfirmedMissingReceipt_batchSendTransactions_fails(t _, fromAddress := cltest.MustInsertRandomKeyReturningState(t, ethKeyStore) - ethClient := evmtest.NewEthClientMockWithDefaultChain(t) + ethClient := testutils.NewEthClientMockWithDefaultChain(t) + ethClient.On("IsL2").Return(false).Maybe() evmcfg := evmtest.NewChainScopedConfig(t, cfg) ec := newEthConfirmer(t, txStore, ethClient, cfg, evmcfg, ethKeyStore, nil) - ctx := testutils.Context(t) + ctx := tests.Context(t) // STATE // eth_txes with nonce 0 has two attempts, the later attempt with higher gas fees @@ -1268,12 +1271,13 @@ func TestEthConfirmer_CheckConfirmedMissingReceipt_smallEvmRPCBatchSize_middleBa _, fromAddress := cltest.MustInsertRandomKeyReturningState(t, ethKeyStore) - ethClient := evmtest.NewEthClientMockWithDefaultChain(t) + ethClient := testutils.NewEthClientMockWithDefaultChain(t) + ethClient.On("IsL2").Return(false).Maybe() evmcfg := evmtest.NewChainScopedConfig(t, cfg) ec := newEthConfirmer(t, txStore, ethClient, cfg, evmcfg, ethKeyStore, nil) - ctx := testutils.Context(t) + ctx := tests.Context(t) // STATE // eth_txes with nonce 0 has two attempts, the later attempt with higher gas fees @@ -1330,9 +1334,9 @@ func TestEthConfirmer_FindTxsRequiringRebroadcast(t *testing.T) { db := pgtest.NewSqlxDB(t) cfg := configtest.NewTestGeneralConfig(t) txStore := cltest.NewTestTxStore(t, db) - ctx := testutils.Context(t) + ctx := tests.Context(t) - ethClient := evmtest.NewEthClientMockWithDefaultChain(t) + ethClient := testutils.NewEthClientMockWithDefaultChain(t) evmcfg := evmtest.NewChainScopedConfig(t, cfg) @@ -1358,7 +1362,7 @@ func TestEthConfirmer_FindTxsRequiringRebroadcast(t *testing.T) { ec := newEthConfirmer(t, txStore, ethClient, cfg, evmcfg, ethKeyStore, nil) t.Run("returns nothing when there are no transactions", func(t *testing.T) { - etxs, err := ec.FindTxsRequiringRebroadcast(testutils.Context(t), lggr, evmFromAddress, currentHead, gasBumpThreshold, 10, 0, &cltest.FixtureChainID) + etxs, err := ec.FindTxsRequiringRebroadcast(tests.Context(t), lggr, evmFromAddress, currentHead, gasBumpThreshold, 10, 0, &cltest.FixtureChainID) require.NoError(t, err) assert.Len(t, etxs, 0) @@ -1368,7 +1372,7 @@ func TestEthConfirmer_FindTxsRequiringRebroadcast(t *testing.T) { nonce++ t.Run("returns nothing when the transaction is in_progress", func(t *testing.T) { - etxs, err := ec.FindTxsRequiringRebroadcast(testutils.Context(t), lggr, evmFromAddress, currentHead, gasBumpThreshold, 10, 0, &cltest.FixtureChainID) + etxs, err := ec.FindTxsRequiringRebroadcast(tests.Context(t), lggr, evmFromAddress, currentHead, gasBumpThreshold, 10, 0, &cltest.FixtureChainID) require.NoError(t, err) assert.Len(t, etxs, 0) @@ -1379,7 +1383,7 @@ func TestEthConfirmer_FindTxsRequiringRebroadcast(t *testing.T) { nonce++ t.Run("ignores unconfirmed transactions with nil BroadcastBeforeBlockNum", func(t *testing.T) { - etxs, err := ec.FindTxsRequiringRebroadcast(testutils.Context(t), lggr, evmFromAddress, currentHead, gasBumpThreshold, 10, 0, &cltest.FixtureChainID) + etxs, err := ec.FindTxsRequiringRebroadcast(tests.Context(t), lggr, evmFromAddress, currentHead, gasBumpThreshold, 10, 0, &cltest.FixtureChainID) require.NoError(t, err) assert.Len(t, etxs, 0) @@ -1397,7 +1401,7 @@ func TestEthConfirmer_FindTxsRequiringRebroadcast(t *testing.T) { require.NoError(t, txStore.InsertTxAttempt(ctx, &attempt1_2)) t.Run("returns nothing when the transaction is unconfirmed with an attempt that is recent", func(t *testing.T) { - etxs, err := ec.FindTxsRequiringRebroadcast(testutils.Context(t), lggr, evmFromAddress, currentHead, gasBumpThreshold, 10, 0, &cltest.FixtureChainID) + etxs, err := ec.FindTxsRequiringRebroadcast(tests.Context(t), lggr, evmFromAddress, currentHead, gasBumpThreshold, 10, 0, &cltest.FixtureChainID) require.NoError(t, err) assert.Len(t, etxs, 0) @@ -1411,7 +1415,7 @@ func TestEthConfirmer_FindTxsRequiringRebroadcast(t *testing.T) { require.NoError(t, db.Get(&dbAttempt, `UPDATE evm.tx_attempts SET broadcast_before_block_num=$1 WHERE id=$2 RETURNING *`, tooNew, attempt2_1.ID)) t.Run("returns nothing when the transaction has attempts that are too new", func(t *testing.T) { - etxs, err := ec.FindTxsRequiringRebroadcast(testutils.Context(t), lggr, evmFromAddress, currentHead, gasBumpThreshold, 10, 0, &cltest.FixtureChainID) + etxs, err := ec.FindTxsRequiringRebroadcast(tests.Context(t), lggr, evmFromAddress, currentHead, gasBumpThreshold, 10, 0, &cltest.FixtureChainID) require.NoError(t, err) assert.Len(t, etxs, 0) @@ -1430,14 +1434,14 @@ func TestEthConfirmer_FindTxsRequiringRebroadcast(t *testing.T) { nonce++ t.Run("does nothing if the transaction is from a different address than the one given", func(t *testing.T) { - etxs, err := ec.FindTxsRequiringRebroadcast(testutils.Context(t), lggr, evmOtherAddress, currentHead, gasBumpThreshold, 10, 0, &cltest.FixtureChainID) + etxs, err := ec.FindTxsRequiringRebroadcast(tests.Context(t), lggr, evmOtherAddress, currentHead, gasBumpThreshold, 10, 0, &cltest.FixtureChainID) require.NoError(t, err) assert.Len(t, etxs, 0) }) t.Run("returns the transaction if it is unconfirmed and has no attempts (note that this is an invariant violation, but we handle it anyway)", func(t *testing.T) { - etxs, err := ec.FindTxsRequiringRebroadcast(testutils.Context(t), lggr, evmFromAddress, currentHead, gasBumpThreshold, 10, 0, &cltest.FixtureChainID) + etxs, err := ec.FindTxsRequiringRebroadcast(tests.Context(t), lggr, evmFromAddress, currentHead, gasBumpThreshold, 10, 0, &cltest.FixtureChainID) require.NoError(t, err) require.Len(t, etxs, 1) @@ -1445,7 +1449,7 @@ func TestEthConfirmer_FindTxsRequiringRebroadcast(t *testing.T) { }) t.Run("returns nothing for different chain id", func(t *testing.T) { - etxs, err := ec.FindTxsRequiringRebroadcast(testutils.Context(t), lggr, evmFromAddress, currentHead, gasBumpThreshold, 10, 0, big.NewInt(42)) + etxs, err := ec.FindTxsRequiringRebroadcast(tests.Context(t), lggr, evmFromAddress, currentHead, gasBumpThreshold, 10, 0, big.NewInt(42)) require.NoError(t, err) require.Len(t, etxs, 0) @@ -1466,7 +1470,7 @@ func TestEthConfirmer_FindTxsRequiringRebroadcast(t *testing.T) { require.NoError(t, db.Get(&dbAttempt, `UPDATE evm.tx_attempts SET broadcast_before_block_num=$1 WHERE id=$2 RETURNING *`, oldEnough, attemptOther1.ID)) t.Run("returns the transaction if it is unconfirmed with an attempt that is older than gasBumpThreshold blocks", func(t *testing.T) { - etxs, err := ec.FindTxsRequiringRebroadcast(testutils.Context(t), lggr, evmFromAddress, currentHead, gasBumpThreshold, 10, 0, &cltest.FixtureChainID) + etxs, err := ec.FindTxsRequiringRebroadcast(tests.Context(t), lggr, evmFromAddress, currentHead, gasBumpThreshold, 10, 0, &cltest.FixtureChainID) require.NoError(t, err) require.Len(t, etxs, 2) @@ -1475,7 +1479,7 @@ func TestEthConfirmer_FindTxsRequiringRebroadcast(t *testing.T) { }) t.Run("returns nothing if threshold is zero", func(t *testing.T) { - etxs, err := ec.FindTxsRequiringRebroadcast(testutils.Context(t), lggr, evmFromAddress, currentHead, 0, 10, 0, &cltest.FixtureChainID) + etxs, err := ec.FindTxsRequiringRebroadcast(tests.Context(t), lggr, evmFromAddress, currentHead, 0, 10, 0, &cltest.FixtureChainID) require.NoError(t, err) require.Len(t, etxs, 0) @@ -1489,13 +1493,13 @@ func TestEthConfirmer_FindTxsRequiringRebroadcast(t *testing.T) { // etxWithoutAttempts (nonce 5) // etx3 (nonce 6) - ready for bump // etx4 (nonce 7) - ready for bump - etxs, err := ec.FindTxsRequiringRebroadcast(testutils.Context(t), lggr, evmFromAddress, currentHead, gasBumpThreshold, 4, 0, &cltest.FixtureChainID) + etxs, err := ec.FindTxsRequiringRebroadcast(tests.Context(t), lggr, evmFromAddress, currentHead, gasBumpThreshold, 4, 0, &cltest.FixtureChainID) require.NoError(t, err) require.Len(t, etxs, 1) // returns etxWithoutAttempts only - eligible for gas bumping because it technically doesn't have any attempts within gasBumpThreshold blocks assert.Equal(t, etxWithoutAttempts.ID, etxs[0].ID) - etxs, err = ec.FindTxsRequiringRebroadcast(testutils.Context(t), lggr, evmFromAddress, currentHead, gasBumpThreshold, 5, 0, &cltest.FixtureChainID) + etxs, err = ec.FindTxsRequiringRebroadcast(tests.Context(t), lggr, evmFromAddress, currentHead, gasBumpThreshold, 5, 0, &cltest.FixtureChainID) require.NoError(t, err) require.Len(t, etxs, 2) // includes etxWithoutAttempts, etx3 and etx4 @@ -1503,7 +1507,7 @@ func TestEthConfirmer_FindTxsRequiringRebroadcast(t *testing.T) { assert.Equal(t, etx3.ID, etxs[1].ID) // Zero limit disables it - etxs, err = ec.FindTxsRequiringRebroadcast(testutils.Context(t), lggr, evmFromAddress, currentHead, gasBumpThreshold, 0, 0, &cltest.FixtureChainID) + etxs, err = ec.FindTxsRequiringRebroadcast(tests.Context(t), lggr, evmFromAddress, currentHead, gasBumpThreshold, 0, 0, &cltest.FixtureChainID) require.NoError(t, err) require.Len(t, etxs, 2) // includes etxWithoutAttempts, etx3 and etx4 @@ -1524,7 +1528,7 @@ func TestEthConfirmer_FindTxsRequiringRebroadcast(t *testing.T) { dbAttempt.FromTxAttempt(&aOther) require.NoError(t, db.Get(&dbAttempt, `UPDATE evm.tx_attempts SET broadcast_before_block_num=$1 WHERE id=$2 RETURNING *`, oldEnough, aOther.ID)) - etxs, err := ec.FindTxsRequiringRebroadcast(testutils.Context(t), lggr, evmFromAddress, currentHead, gasBumpThreshold, 6, 0, &cltest.FixtureChainID) + etxs, err := ec.FindTxsRequiringRebroadcast(tests.Context(t), lggr, evmFromAddress, currentHead, gasBumpThreshold, 6, 0, &cltest.FixtureChainID) require.NoError(t, err) require.Len(t, etxs, 3) // includes etxWithoutAttempts, etx3 and etx4 @@ -1539,7 +1543,7 @@ func TestEthConfirmer_FindTxsRequiringRebroadcast(t *testing.T) { require.NoError(t, txStore.InsertTxAttempt(ctx, &attempt3_2)) t.Run("returns the transaction if it is unconfirmed with two attempts that are older than gasBumpThreshold blocks", func(t *testing.T) { - etxs, err := ec.FindTxsRequiringRebroadcast(testutils.Context(t), lggr, evmFromAddress, currentHead, gasBumpThreshold, 10, 0, &cltest.FixtureChainID) + etxs, err := ec.FindTxsRequiringRebroadcast(tests.Context(t), lggr, evmFromAddress, currentHead, gasBumpThreshold, 10, 0, &cltest.FixtureChainID) require.NoError(t, err) require.Len(t, etxs, 3) @@ -1554,7 +1558,7 @@ func TestEthConfirmer_FindTxsRequiringRebroadcast(t *testing.T) { require.NoError(t, txStore.InsertTxAttempt(ctx, &attempt3_3)) t.Run("does not return the transaction if it has some older but one newer attempt", func(t *testing.T) { - etxs, err := ec.FindTxsRequiringRebroadcast(testutils.Context(t), lggr, evmFromAddress, currentHead, gasBumpThreshold, 10, 0, &cltest.FixtureChainID) + etxs, err := ec.FindTxsRequiringRebroadcast(tests.Context(t), lggr, evmFromAddress, currentHead, gasBumpThreshold, 10, 0, &cltest.FixtureChainID) require.NoError(t, err) require.Len(t, etxs, 2) @@ -1591,7 +1595,7 @@ func TestEthConfirmer_FindTxsRequiringRebroadcast(t *testing.T) { require.NoError(t, txStore.InsertTxAttempt(ctx, &attempt6_2)) t.Run("returns unique attempts requiring resubmission due to insufficient eth, ordered by nonce asc", func(t *testing.T) { - etxs, err := ec.FindTxsRequiringRebroadcast(testutils.Context(t), lggr, evmFromAddress, currentHead, gasBumpThreshold, 10, 0, &cltest.FixtureChainID) + etxs, err := ec.FindTxsRequiringRebroadcast(tests.Context(t), lggr, evmFromAddress, currentHead, gasBumpThreshold, 10, 0, &cltest.FixtureChainID) require.NoError(t, err) require.Len(t, etxs, 4) @@ -1606,7 +1610,7 @@ func TestEthConfirmer_FindTxsRequiringRebroadcast(t *testing.T) { }) t.Run("applies limit", func(t *testing.T) { - etxs, err := ec.FindTxsRequiringRebroadcast(testutils.Context(t), lggr, evmFromAddress, currentHead, gasBumpThreshold, 10, 2, &cltest.FixtureChainID) + etxs, err := ec.FindTxsRequiringRebroadcast(tests.Context(t), lggr, evmFromAddress, currentHead, gasBumpThreshold, 10, 2, &cltest.FixtureChainID) require.NoError(t, err) require.Len(t, etxs, 2) @@ -1622,7 +1626,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary_WithConnectivityCheck(t *testing lggr := logger.Test(t) db := pgtest.NewSqlxDB(t) - ethClient := evmtest.NewEthClientMockWithDefaultChain(t) + ethClient := testutils.NewEthClientMockWithDefaultChain(t) t.Run("should retry previous attempt if connectivity check failed for legacy transactions", func(t *testing.T) { cfg := configtest.NewGeneralConfig(t, func(c *chainlink.Config, s *chainlink.Secrets) { @@ -1632,7 +1636,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary_WithConnectivityCheck(t *testing }) ccfg := evmtest.NewChainScopedConfig(t, cfg) - ctx := testutils.Context(t) + ctx := tests.Context(t) txStore := cltest.NewTestTxStore(t, db) ethKeyStore := cltest.NewKeyStore(t, db).Eth() _, fromAddress := cltest.MustInsertRandomKeyReturningState(t, ethKeyStore) @@ -1664,7 +1668,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary_WithConnectivityCheck(t *testing // Send transaction and assume success. ethClient.On("SendTransactionReturnCode", mock.Anything, mock.Anything, fromAddress).Return(commonclient.Successful, nil).Once() - err := ec.RebroadcastWhereNecessary(testutils.Context(t), currentHead) + err := ec.RebroadcastWhereNecessary(tests.Context(t), currentHead) require.NoError(t, err) etx, err = txStore.FindTxWithAttempts(ctx, etx.ID) @@ -1680,7 +1684,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary_WithConnectivityCheck(t *testing }) ccfg := evmtest.NewChainScopedConfig(t, cfg) - ctx := testutils.Context(t) + ctx := tests.Context(t) txStore := cltest.NewTestTxStore(t, db) ethKeyStore := cltest.NewKeyStore(t, db).Eth() _, fromAddress := cltest.MustInsertRandomKeyReturningState(t, ethKeyStore) @@ -1712,7 +1716,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary_WithConnectivityCheck(t *testing // Send transaction and assume success. ethClient.On("SendTransactionReturnCode", mock.Anything, mock.Anything, fromAddress).Return(commonclient.Successful, nil).Once() - err := ec.RebroadcastWhereNecessary(testutils.Context(t), currentHead) + err := ec.RebroadcastWhereNecessary(tests.Context(t), currentHead) require.NoError(t, err) etx, err = txStore.FindTxWithAttempts(ctx, etx.ID) @@ -1729,9 +1733,9 @@ func TestEthConfirmer_RebroadcastWhereNecessary_MaxFeeScenario(t *testing.T) { c.EVM[0].GasEstimator.PriceMax = assets.GWei(500) }) txStore := cltest.NewTestTxStore(t, db) - ctx := testutils.Context(t) + ctx := tests.Context(t) - ethClient := evmtest.NewEthClientMockWithDefaultChain(t) + ethClient := testutils.NewEthClientMockWithDefaultChain(t) ethKeyStore := cltest.NewKeyStore(t, db).Eth() evmcfg := evmtest.NewChainScopedConfig(t, cfg) @@ -1775,7 +1779,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary_MaxFeeScenario(t *testing.T) { }), fromAddress).Return(commonclient.ExceedsMaxFee, errors.New("tx fee (1.10 ether) exceeds the configured cap (1.00 ether)")).Once() // Do the thing - require.NoError(t, ec.RebroadcastWhereNecessary(testutils.Context(t), currentHead)) + require.NoError(t, ec.RebroadcastWhereNecessary(tests.Context(t), currentHead)) var err error etx, err = txStore.FindTxWithAttempts(ctx, etx.ID) require.NoError(t, err) @@ -1797,9 +1801,9 @@ func TestEthConfirmer_RebroadcastWhereNecessary(t *testing.T) { c.EVM[0].GasEstimator.PriceMax = assets.GWei(500) }) txStore := cltest.NewTestTxStore(t, db) - ctx := testutils.Context(t) + ctx := tests.Context(t) - ethClient := evmtest.NewEthClientMockWithDefaultChain(t) + ethClient := testutils.NewEthClientMockWithDefaultChain(t) ethKeyStore := cltest.NewKeyStore(t, db).Eth() evmcfg := evmtest.NewChainScopedConfig(t, cfg) @@ -1817,7 +1821,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary(t *testing.T) { nonce := int64(0) t.Run("does nothing if no transactions require bumping", func(t *testing.T) { - require.NoError(t, ec.RebroadcastWhereNecessary(testutils.Context(t), currentHead)) + require.NoError(t, ec.RebroadcastWhereNecessary(tests.Context(t), currentHead)) }) originalBroadcastAt := time.Unix(1616509100, 0) @@ -1836,7 +1840,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary(t *testing.T) { mock.Anything).Return(nil, errors.New("signing error")).Once() // Do the thing - err := ec.RebroadcastWhereNecessary(testutils.Context(t), currentHead) + err := ec.RebroadcastWhereNecessary(tests.Context(t), currentHead) require.Error(t, err) require.Contains(t, err.Error(), "signing error") @@ -1866,7 +1870,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary(t *testing.T) { }), fromAddress).Return(commonclient.Fatal, errors.New("exceeds block gas limit")).Once() // Do the thing - require.NoError(t, ec.RebroadcastWhereNecessary(testutils.Context(t), currentHead)) + require.NoError(t, ec.RebroadcastWhereNecessary(tests.Context(t), currentHead)) var err error etx, err = txStore.FindTxWithAttempts(ctx, etx.ID) require.NoError(t, err) @@ -1875,7 +1879,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary(t *testing.T) { }) var attempt1_2 txmgr.TxAttempt - ethClient = evmtest.NewEthClientMockWithDefaultChain(t) + ethClient = testutils.NewEthClientMockWithDefaultChain(t) ec.XXXTestSetClient(txmgr.NewEvmTxmClient(ethClient, nil)) t.Run("creates new attempt with higher gas price if transaction has an attempt older than threshold", func(t *testing.T) { @@ -1900,7 +1904,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary(t *testing.T) { }), fromAddress).Return(commonclient.Successful, nil).Once() // Do the thing - require.NoError(t, ec.RebroadcastWhereNecessary(testutils.Context(t), currentHead)) + require.NoError(t, ec.RebroadcastWhereNecessary(tests.Context(t), currentHead)) var err error etx, err = txStore.FindTxWithAttempts(ctx, etx.ID) require.NoError(t, err) @@ -1916,7 +1920,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary(t *testing.T) { t.Run("does nothing if there is an attempt without BroadcastBeforeBlockNum set", func(t *testing.T) { // Do the thing - require.NoError(t, ec.RebroadcastWhereNecessary(testutils.Context(t), currentHead)) + require.NoError(t, ec.RebroadcastWhereNecessary(tests.Context(t), currentHead)) var err error etx, err = txStore.FindTxWithAttempts(ctx, etx.ID) require.NoError(t, err) @@ -1946,7 +1950,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary(t *testing.T) { }), fromAddress).Return(commonclient.Successful, fmt.Errorf("known transaction: %s", ethTx.Hash().Hex())).Once() // Do the thing - require.NoError(t, ec.RebroadcastWhereNecessary(testutils.Context(t), currentHead)) + require.NoError(t, ec.RebroadcastWhereNecessary(tests.Context(t), currentHead)) var err error etx, err = txStore.FindTxWithAttempts(ctx, etx.ID) require.NoError(t, err) @@ -1986,7 +1990,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary(t *testing.T) { }), fromAddress).Return(commonclient.TransactionAlreadyKnown, errors.New("nonce too low")).Once() // Do the thing - require.NoError(t, ec.RebroadcastWhereNecessary(testutils.Context(t), currentHead)) + require.NoError(t, ec.RebroadcastWhereNecessary(tests.Context(t), currentHead)) var err error etx, err = txStore.FindTxWithAttempts(ctx, etx.ID) require.NoError(t, err) @@ -2038,7 +2042,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary(t *testing.T) { }), fromAddress).Return(commonclient.Unknown, errors.New("some network error")).Once() // Do the thing - err := ec.RebroadcastWhereNecessary(testutils.Context(t), currentHead) + err := ec.RebroadcastWhereNecessary(tests.Context(t), currentHead) require.Error(t, err) require.Contains(t, err.Error(), "some network error") @@ -2065,7 +2069,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary(t *testing.T) { return evmtypes.Nonce(tx.Nonce()) == n && expectedBumpedGasPrice.Cmp(tx.GasPrice()) == 0 }), fromAddress).Return(commonclient.Successful, nil).Once() - require.NoError(t, ec.RebroadcastWhereNecessary(testutils.Context(t), currentHead)) + require.NoError(t, ec.RebroadcastWhereNecessary(tests.Context(t), currentHead)) // Attempt marked "broadcast" etx2, err = txStore.FindTxWithAttempts(ctx, etx2.ID) @@ -2105,7 +2109,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary(t *testing.T) { }), fromAddress).Return(commonclient.TransactionAlreadyKnown, errors.New("nonce too low")).Once() // Creates new attempt as normal if currentHead is not high enough - require.NoError(t, ec.RebroadcastWhereNecessary(testutils.Context(t), currentHead)) + require.NoError(t, ec.RebroadcastWhereNecessary(tests.Context(t), currentHead)) var err error etx2, err = txStore.FindTxWithAttempts(ctx, etx2.ID) require.NoError(t, err) @@ -2146,7 +2150,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary(t *testing.T) { }), fromAddress).Return(commonclient.Successful, errors.New("replacement transaction underpriced")).Once() // Do the thing - require.NoError(t, ec.RebroadcastWhereNecessary(testutils.Context(t), currentHead)) + require.NoError(t, ec.RebroadcastWhereNecessary(tests.Context(t), currentHead)) var err error etx3, err = txStore.FindTxWithAttempts(ctx, etx3.ID) require.NoError(t, err) @@ -2183,7 +2187,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary(t *testing.T) { }), fromAddress).Return(commonclient.Successful, fmt.Errorf("known transaction: %s", ethTx.Hash().Hex())).Once() // Do the thing - require.NoError(t, ec.RebroadcastWhereNecessary(testutils.Context(t), currentHead)) + require.NoError(t, ec.RebroadcastWhereNecessary(tests.Context(t), currentHead)) var err error etx3, err = txStore.FindTxWithAttempts(ctx, etx3.ID) require.NoError(t, err) @@ -2222,7 +2226,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary(t *testing.T) { }), fromAddress).Return(commonclient.Successful, errors.New(temporarilyUnderpricedError)).Once() // Do the thing - require.NoError(t, ec.RebroadcastWhereNecessary(testutils.Context(t), currentHead)) + require.NoError(t, ec.RebroadcastWhereNecessary(tests.Context(t), currentHead)) var err error etx3, err = txStore.FindTxWithAttempts(ctx, etx3.ID) require.NoError(t, err) @@ -2251,7 +2255,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary(t *testing.T) { }), fromAddress).Return(commonclient.Successful, errors.New("already known")).Once() // we already submitted at this price, now it's time to bump and submit again but since we simply resubmitted rather than increasing gas price, geth already knows about this tx // Do the thing - require.NoError(t, ec2.RebroadcastWhereNecessary(testutils.Context(t), currentHead)) + require.NoError(t, ec2.RebroadcastWhereNecessary(tests.Context(t), currentHead)) var err error etx3, err = txStore.FindTxWithAttempts(ctx, etx3.ID) require.NoError(t, err) @@ -2281,7 +2285,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary(t *testing.T) { }), fromAddress).Return(commonclient.Successful, errors.New("already known")).Once() // we already submitted at this price, now it's time to bump and submit again but since we simply resubmitted rather than increasing gas price, geth already knows about this tx // Do the thing - require.NoError(t, ec2.RebroadcastWhereNecessary(testutils.Context(t), currentHead)) + require.NoError(t, ec2.RebroadcastWhereNecessary(tests.Context(t), currentHead)) var err error etx3, err = txStore.FindTxWithAttempts(ctx, etx3.ID) require.NoError(t, err) @@ -2318,7 +2322,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary(t *testing.T) { ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *types.Transaction) bool { return evmtypes.Nonce(tx.Nonce()) == *etx4.Sequence && gasTipCap.ToInt().Cmp(tx.GasTipCap()) == 0 }), fromAddress).Return(commonclient.Successful, nil).Once() - require.NoError(t, ec.RebroadcastWhereNecessary(testutils.Context(t), currentHead)) + require.NoError(t, ec.RebroadcastWhereNecessary(tests.Context(t), currentHead)) var err error etx4, err = txStore.FindTxWithAttempts(ctx, etx4.ID) require.NoError(t, err) @@ -2349,7 +2353,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary(t *testing.T) { return evmtypes.Nonce(tx.Nonce()) == *etx4.Sequence && attempt4_2.Hash.String() == tx.Hash().String() }), fromAddress).Return(commonclient.Successful, nil).Once() - require.NoError(t, ec2.RebroadcastWhereNecessary(testutils.Context(t), currentHead)) + require.NoError(t, ec2.RebroadcastWhereNecessary(tests.Context(t), currentHead)) var err error etx4, err = txStore.FindTxWithAttempts(ctx, etx4.ID) require.NoError(t, err) @@ -2386,7 +2390,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary(t *testing.T) { }), fromAddress).Return(commonclient.Successful, errors.New("replacement transaction underpriced")).Once() // Do it - require.NoError(t, ec.RebroadcastWhereNecessary(testutils.Context(t), currentHead)) + require.NoError(t, ec.RebroadcastWhereNecessary(tests.Context(t), currentHead)) var err error etx4, err = txStore.FindTxWithAttempts(ctx, etx4.ID) require.NoError(t, err) @@ -2427,7 +2431,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary_TerminallyUnderpriced_ThenGoesTh nonce := int64(0) t.Run("terminally underpriced transaction with in_progress attempt is retried with more gas", func(t *testing.T) { - ethClient := evmtest.NewEthClientMockWithDefaultChain(t) + ethClient := testutils.NewEthClientMockWithDefaultChain(t) ec := newEthConfirmer(t, txStore, ethClient, cfg, evmcfg, kst, nil) originalBroadcastAt := time.Unix(1616509100, 0) @@ -2447,11 +2451,11 @@ func TestEthConfirmer_RebroadcastWhereNecessary_TerminallyUnderpriced_ThenGoesTh kst.On("SignTx", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return( signedTx, nil, ).Once() - require.NoError(t, ec.RebroadcastWhereNecessary(testutils.Context(t), currentHead)) + require.NoError(t, ec.RebroadcastWhereNecessary(tests.Context(t), currentHead)) }) t.Run("multiple gas bumps with existing broadcast attempts are retried with more gas until success in legacy mode", func(t *testing.T) { - ethClient := evmtest.NewEthClientMockWithDefaultChain(t) + ethClient := testutils.NewEthClientMockWithDefaultChain(t) ec := newEthConfirmer(t, txStore, ethClient, cfg, evmcfg, kst, nil) etx := cltest.MustInsertUnconfirmedEthTxWithBroadcastLegacyAttempt(t, txStore, nonce, fromAddress) @@ -2475,15 +2479,15 @@ func TestEthConfirmer_RebroadcastWhereNecessary_TerminallyUnderpriced_ThenGoesTh ).Run(func(args mock.Arguments) { unsignedLegacyTx := args.Get(2).(*types.Transaction) // Use the real keystore to do the actual signing - thisSignedLegacyTx, err := ethKeyStore.SignTx(testutils.Context(t), fromAddress, unsignedLegacyTx, testutils.FixtureChainID) + thisSignedLegacyTx, err := ethKeyStore.SignTx(tests.Context(t), fromAddress, unsignedLegacyTx, testutils.FixtureChainID) require.NoError(t, err) *signedLegacyTx = *thisSignedLegacyTx }).Times(4) // 3 failures 1 success - require.NoError(t, ec.RebroadcastWhereNecessary(testutils.Context(t), currentHead)) + require.NoError(t, ec.RebroadcastWhereNecessary(tests.Context(t), currentHead)) }) t.Run("multiple gas bumps with existing broadcast attempts are retried with more gas until success in EIP-1559 mode", func(t *testing.T) { - ethClient := evmtest.NewEthClientMockWithDefaultChain(t) + ethClient := testutils.NewEthClientMockWithDefaultChain(t) ec := newEthConfirmer(t, txStore, ethClient, cfg, evmcfg, kst, nil) etx := mustInsertUnconfirmedEthTxWithBroadcastDynamicFeeAttempt(t, txStore, nonce, fromAddress) @@ -2507,11 +2511,11 @@ func TestEthConfirmer_RebroadcastWhereNecessary_TerminallyUnderpriced_ThenGoesTh ).Run(func(args mock.Arguments) { unsignedDxFeeTx := args.Get(2).(*types.Transaction) // Use the real keystore to do the actual signing - thisSignedDxFeeTx, err := ethKeyStore.SignTx(testutils.Context(t), fromAddress, unsignedDxFeeTx, testutils.FixtureChainID) + thisSignedDxFeeTx, err := ethKeyStore.SignTx(tests.Context(t), fromAddress, unsignedDxFeeTx, testutils.FixtureChainID) require.NoError(t, err) *signedDxFeeTx = *thisSignedDxFeeTx }).Times(4) // 3 failures 1 success - require.NoError(t, ec.RebroadcastWhereNecessary(testutils.Context(t), currentHead)) + require.NoError(t, ec.RebroadcastWhereNecessary(tests.Context(t), currentHead)) }) } @@ -2519,14 +2523,14 @@ func TestEthConfirmer_RebroadcastWhereNecessary_WhenOutOfEth(t *testing.T) { t.Parallel() db := pgtest.NewSqlxDB(t) txStore := cltest.NewTestTxStore(t, db) - ctx := testutils.Context(t) + ctx := tests.Context(t) - ethClient := evmtest.NewEthClientMockWithDefaultChain(t) + ethClient := testutils.NewEthClientMockWithDefaultChain(t) ethKeyStore := cltest.NewKeyStore(t, db).Eth() _, fromAddress := cltest.MustInsertRandomKeyReturningState(t, ethKeyStore) - _, err := ethKeyStore.EnabledKeysForChain(testutils.Context(t), testutils.FixtureChainID) + _, err := ethKeyStore.EnabledKeysForChain(tests.Context(t), testutils.FixtureChainID) require.NoError(t, err) require.NoError(t, err) // keyStates, err := ethKeyStore.GetStatesForKeys(keys) @@ -2558,7 +2562,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary_WhenOutOfEth(t *testing.T) { }), fromAddress).Return(commonclient.InsufficientFunds, insufficientEthError).Once() // Do the thing - require.NoError(t, ec.RebroadcastWhereNecessary(testutils.Context(t), currentHead)) + require.NoError(t, ec.RebroadcastWhereNecessary(tests.Context(t), currentHead)) etx, err = txStore.FindTxWithAttempts(ctx, etx.ID) require.NoError(t, err) @@ -2584,7 +2588,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary_WhenOutOfEth(t *testing.T) { }), fromAddress).Return(commonclient.InsufficientFunds, insufficientEthError).Once() // Do the thing - require.NoError(t, ec.RebroadcastWhereNecessary(testutils.Context(t), currentHead)) + require.NoError(t, ec.RebroadcastWhereNecessary(tests.Context(t), currentHead)) etx, err = txStore.FindTxWithAttempts(ctx, etx.ID) require.NoError(t, err) @@ -2609,7 +2613,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary_WhenOutOfEth(t *testing.T) { }), fromAddress).Return(commonclient.Successful, nil).Once() // Do the thing - require.NoError(t, ec.RebroadcastWhereNecessary(testutils.Context(t), currentHead)) + require.NoError(t, ec.RebroadcastWhereNecessary(tests.Context(t), currentHead)) etx, err = txStore.FindTxWithAttempts(ctx, etx.ID) require.NoError(t, err) @@ -2643,7 +2647,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary_WhenOutOfEth(t *testing.T) { nonce++ } - require.NoError(t, ec.RebroadcastWhereNecessary(testutils.Context(t), currentHead)) + require.NoError(t, ec.RebroadcastWhereNecessary(tests.Context(t), currentHead)) var dbAttempts []txmgr.DbEthTxAttempt @@ -2657,40 +2661,40 @@ func TestEthConfirmer_EnsureConfirmedTransactionsInLongestChain(t *testing.T) { db := pgtest.NewSqlxDB(t) txStore := cltest.NewTestTxStore(t, db) - ctx := testutils.Context(t) + ctx := tests.Context(t) ethKeyStore := cltest.NewKeyStore(t, db).Eth() _, fromAddress := cltest.MustInsertRandomKeyReturningState(t, ethKeyStore) - ethClient := evmtest.NewEthClientMockWithDefaultChain(t) + ethClient := testutils.NewEthClientMockWithDefaultChain(t) gconfig, config := newTestChainScopedConfig(t) ec := newEthConfirmer(t, txStore, ethClient, gconfig, config, ethKeyStore, nil) head := evmtypes.Head{ - Hash: utils.NewHash(), + Hash: testutils.NewHash(), Number: 10, Parent: &evmtypes.Head{ - Hash: utils.NewHash(), + Hash: testutils.NewHash(), Number: 9, Parent: &evmtypes.Head{ Number: 8, - Hash: utils.NewHash(), + Hash: testutils.NewHash(), Parent: nil, }, }, } t.Run("does nothing if there aren't any transactions", func(t *testing.T) { - require.NoError(t, ec.EnsureConfirmedTransactionsInLongestChain(testutils.Context(t), &head)) + require.NoError(t, ec.EnsureConfirmedTransactionsInLongestChain(tests.Context(t), &head)) }) t.Run("does nothing to unconfirmed transactions", func(t *testing.T) { etx := cltest.MustInsertUnconfirmedEthTxWithBroadcastLegacyAttempt(t, txStore, 0, fromAddress) // Do the thing - require.NoError(t, ec.EnsureConfirmedTransactionsInLongestChain(testutils.Context(t), &head)) + require.NoError(t, ec.EnsureConfirmedTransactionsInLongestChain(tests.Context(t), &head)) etx, err := txStore.FindTxWithAttempts(ctx, etx.ID) require.NoError(t, err) @@ -2702,7 +2706,7 @@ func TestEthConfirmer_EnsureConfirmedTransactionsInLongestChain(t *testing.T) { mustInsertEthReceipt(t, txStore, head.Number, head.Hash, etx.TxAttempts[0].Hash) // Do the thing - require.NoError(t, ec.EnsureConfirmedTransactionsInLongestChain(testutils.Context(t), &head)) + require.NoError(t, ec.EnsureConfirmedTransactionsInLongestChain(tests.Context(t), &head)) etx, err := txStore.FindTxWithAttempts(ctx, etx.ID) require.NoError(t, err) @@ -2712,10 +2716,10 @@ func TestEthConfirmer_EnsureConfirmedTransactionsInLongestChain(t *testing.T) { t.Run("does nothing to confirmed transactions that only have receipts older than the start of the chain", func(t *testing.T) { etx := cltest.MustInsertConfirmedEthTxWithLegacyAttempt(t, txStore, 3, 1, fromAddress) // Add receipt that is older than the lowest block of the chain - mustInsertEthReceipt(t, txStore, head.Parent.Parent.Number-1, utils.NewHash(), etx.TxAttempts[0].Hash) + mustInsertEthReceipt(t, txStore, head.Parent.Parent.Number-1, testutils.NewHash(), etx.TxAttempts[0].Hash) // Do the thing - require.NoError(t, ec.EnsureConfirmedTransactionsInLongestChain(testutils.Context(t), &head)) + require.NoError(t, ec.EnsureConfirmedTransactionsInLongestChain(tests.Context(t), &head)) etx, err := txStore.FindTxWithAttempts(ctx, etx.ID) require.NoError(t, err) @@ -2726,7 +2730,7 @@ func TestEthConfirmer_EnsureConfirmedTransactionsInLongestChain(t *testing.T) { etx := cltest.MustInsertConfirmedEthTxWithLegacyAttempt(t, txStore, 4, 1, fromAddress) attempt := etx.TxAttempts[0] // Include one within head height but a different block hash - mustInsertEthReceipt(t, txStore, head.Parent.Number, utils.NewHash(), attempt.Hash) + mustInsertEthReceipt(t, txStore, head.Parent.Number, testutils.NewHash(), attempt.Hash) ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *types.Transaction) bool { atx, err := txmgr.GetGethSignedTx(attempt.SignedRawTx) @@ -2736,7 +2740,7 @@ func TestEthConfirmer_EnsureConfirmedTransactionsInLongestChain(t *testing.T) { }), fromAddress).Return(commonclient.Successful, nil).Once() // Do the thing - require.NoError(t, ec.EnsureConfirmedTransactionsInLongestChain(testutils.Context(t), &head)) + require.NoError(t, ec.EnsureConfirmedTransactionsInLongestChain(tests.Context(t), &head)) etx, err := txStore.FindTxWithAttempts(ctx, etx.ID) require.NoError(t, err) @@ -2751,15 +2755,15 @@ func TestEthConfirmer_EnsureConfirmedTransactionsInLongestChain(t *testing.T) { attempt := etx.TxAttempts[0] attemptHash := attempt.Hash // Add receipt that is older than the lowest block of the chain - mustInsertEthReceipt(t, txStore, head.Parent.Parent.Number-1, utils.NewHash(), attemptHash) + mustInsertEthReceipt(t, txStore, head.Parent.Parent.Number-1, testutils.NewHash(), attemptHash) // Include one within head height but a different block hash - mustInsertEthReceipt(t, txStore, head.Parent.Number, utils.NewHash(), attemptHash) + mustInsertEthReceipt(t, txStore, head.Parent.Number, testutils.NewHash(), attemptHash) ethClient.On("SendTransactionReturnCode", mock.Anything, mock.Anything, fromAddress).Return( commonclient.Successful, nil).Once() // Do the thing - require.NoError(t, ec.EnsureConfirmedTransactionsInLongestChain(testutils.Context(t), &head)) + require.NoError(t, ec.EnsureConfirmedTransactionsInLongestChain(tests.Context(t), &head)) etx, err := txStore.FindTxWithAttempts(ctx, etx.ID) require.NoError(t, err) @@ -2783,9 +2787,9 @@ func TestEthConfirmer_EnsureConfirmedTransactionsInLongestChain(t *testing.T) { require.NoError(t, txStore.InsertTxAttempt(ctx, &attempt3)) // Receipt is within head height but a different block hash - mustInsertEthReceipt(t, txStore, head.Parent.Number, utils.NewHash(), attempt2.Hash) + mustInsertEthReceipt(t, txStore, head.Parent.Number, testutils.NewHash(), attempt2.Hash) // Receipt is within head height but a different block hash - mustInsertEthReceipt(t, txStore, head.Parent.Number, utils.NewHash(), attempt3.Hash) + mustInsertEthReceipt(t, txStore, head.Parent.Number, testutils.NewHash(), attempt3.Hash) ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *types.Transaction) bool { s, err := txmgr.GetGethSignedTx(attempt3.SignedRawTx) @@ -2794,7 +2798,7 @@ func TestEthConfirmer_EnsureConfirmedTransactionsInLongestChain(t *testing.T) { }), fromAddress).Return(commonclient.Successful, nil).Once() // Do the thing - require.NoError(t, ec.EnsureConfirmedTransactionsInLongestChain(testutils.Context(t), &head)) + require.NoError(t, ec.EnsureConfirmedTransactionsInLongestChain(tests.Context(t), &head)) etx, err := txStore.FindTxWithAttempts(ctx, etx.ID) require.NoError(t, err) @@ -2812,9 +2816,9 @@ func TestEthConfirmer_EnsureConfirmedTransactionsInLongestChain(t *testing.T) { etx := cltest.MustInsertConfirmedEthTxWithLegacyAttempt(t, txStore, 7, 1, fromAddress) attempt := etx.TxAttempts[0] // Add receipt that is higher than head - mustInsertEthReceipt(t, txStore, head.Number+1, utils.NewHash(), attempt.Hash) + mustInsertEthReceipt(t, txStore, head.Number+1, testutils.NewHash(), attempt.Hash) - require.NoError(t, ec.EnsureConfirmedTransactionsInLongestChain(testutils.Context(t), &head)) + require.NoError(t, ec.EnsureConfirmedTransactionsInLongestChain(tests.Context(t), &head)) etx, err := txStore.FindTxWithAttempts(ctx, etx.ID) require.NoError(t, err) @@ -2845,7 +2849,7 @@ func TestEthConfirmer_ForceRebroadcast(t *testing.T) { overrideGasLimit := uint64(20000) t.Run("rebroadcasts one eth_tx if it falls within in nonce range", func(t *testing.T) { - ethClient := evmtest.NewEthClientMockWithDefaultChain(t) + ethClient := testutils.NewEthClientMockWithDefaultChain(t) ec := newEthConfirmer(t, txStore, ethClient, gconfig, config, ethKeyStore, nil) ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *types.Transaction) bool { @@ -2856,11 +2860,11 @@ func TestEthConfirmer_ForceRebroadcast(t *testing.T) { tx.To().String() == etx1.ToAddress.String() }), mock.Anything).Return(commonclient.Successful, nil).Once() - require.NoError(t, ec.ForceRebroadcast(testutils.Context(t), []evmtypes.Nonce{1}, gasPriceWei, fromAddress, overrideGasLimit)) + require.NoError(t, ec.ForceRebroadcast(tests.Context(t), []evmtypes.Nonce{1}, gasPriceWei, fromAddress, overrideGasLimit)) }) t.Run("uses default gas limit if overrideGasLimit is 0", func(t *testing.T) { - ethClient := evmtest.NewEthClientMockWithDefaultChain(t) + ethClient := testutils.NewEthClientMockWithDefaultChain(t) ec := newEthConfirmer(t, txStore, ethClient, gconfig, config, ethKeyStore, nil) ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *types.Transaction) bool { @@ -2871,11 +2875,11 @@ func TestEthConfirmer_ForceRebroadcast(t *testing.T) { tx.To().String() == etx1.ToAddress.String() }), mock.Anything).Return(commonclient.Successful, nil).Once() - require.NoError(t, ec.ForceRebroadcast(testutils.Context(t), []evmtypes.Nonce{(1)}, gasPriceWei, fromAddress, 0)) + require.NoError(t, ec.ForceRebroadcast(tests.Context(t), []evmtypes.Nonce{(1)}, gasPriceWei, fromAddress, 0)) }) t.Run("rebroadcasts several eth_txes in nonce range", func(t *testing.T) { - ethClient := evmtest.NewEthClientMockWithDefaultChain(t) + ethClient := testutils.NewEthClientMockWithDefaultChain(t) ec := newEthConfirmer(t, txStore, ethClient, gconfig, config, ethKeyStore, nil) ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *types.Transaction) bool { @@ -2885,11 +2889,11 @@ func TestEthConfirmer_ForceRebroadcast(t *testing.T) { return tx.Nonce() == uint64(*etx2.Sequence) && tx.GasPrice().Int64() == gasPriceWei.Legacy.Int64() && tx.Gas() == overrideGasLimit }), mock.Anything).Return(commonclient.Successful, nil).Once() - require.NoError(t, ec.ForceRebroadcast(testutils.Context(t), []evmtypes.Nonce{(1), (2)}, gasPriceWei, fromAddress, overrideGasLimit)) + require.NoError(t, ec.ForceRebroadcast(tests.Context(t), []evmtypes.Nonce{(1), (2)}, gasPriceWei, fromAddress, overrideGasLimit)) }) t.Run("broadcasts zero transactions if eth_tx doesn't exist for that nonce", func(t *testing.T) { - ethClient := evmtest.NewEthClientMockWithDefaultChain(t) + ethClient := testutils.NewEthClientMockWithDefaultChain(t) ec := newEthConfirmer(t, txStore, ethClient, gconfig, config, ethKeyStore, nil) ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *types.Transaction) bool { @@ -2911,18 +2915,18 @@ func TestEthConfirmer_ForceRebroadcast(t *testing.T) { } nonces := []evmtypes.Nonce{(1), (2), (3), (4), (5)} - require.NoError(t, ec.ForceRebroadcast(testutils.Context(t), nonces, gasPriceWei, fromAddress, overrideGasLimit)) + require.NoError(t, ec.ForceRebroadcast(tests.Context(t), nonces, gasPriceWei, fromAddress, overrideGasLimit)) }) t.Run("zero transactions use default gas limit if override wasn't specified", func(t *testing.T) { - ethClient := evmtest.NewEthClientMockWithDefaultChain(t) + ethClient := testutils.NewEthClientMockWithDefaultChain(t) ec := newEthConfirmer(t, txStore, ethClient, gconfig, config, ethKeyStore, nil) ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *types.Transaction) bool { return tx.Nonce() == uint64(0) && tx.GasPrice().Int64() == gasPriceWei.Legacy.Int64() && tx.Gas() == config.EVM().GasEstimator().LimitDefault() }), mock.Anything).Return(commonclient.Successful, nil).Once() - require.NoError(t, ec.ForceRebroadcast(testutils.Context(t), []evmtypes.Nonce{(0)}, gasPriceWei, fromAddress, 0)) + require.NoError(t, ec.ForceRebroadcast(tests.Context(t), []evmtypes.Nonce{(0)}, gasPriceWei, fromAddress, 0)) }) } @@ -2937,19 +2941,19 @@ func TestEthConfirmer_ResumePendingRuns(t *testing.T) { _, fromAddress := cltest.MustInsertRandomKey(t, ethKeyStore) - ethClient := evmtest.NewEthClientMockWithDefaultChain(t) + ethClient := testutils.NewEthClientMockWithDefaultChain(t) evmcfg := evmtest.NewChainScopedConfig(t, config) head := evmtypes.Head{ - Hash: utils.NewHash(), + Hash: testutils.NewHash(), Number: 10, Parent: &evmtypes.Head{ - Hash: utils.NewHash(), + Hash: testutils.NewHash(), Number: 9, Parent: &evmtypes.Head{ Number: 8, - Hash: utils.NewHash(), + Hash: testutils.NewHash(), Parent: nil, }, }, @@ -2975,7 +2979,7 @@ func TestEthConfirmer_ResumePendingRuns(t *testing.T) { // It would only be in a state past suspended if the resume callback was called and callback_completed was set to TRUE pgtest.MustExec(t, db, `UPDATE evm.txes SET pipeline_task_run_id = $1, min_confirmations = $2, signal_callback = TRUE, callback_completed = TRUE WHERE id = $3`, &tr.ID, minConfirmations, etx.ID) - err := ec.ResumePendingTaskRuns(testutils.Context(t), &head) + err := ec.ResumePendingTaskRuns(tests.Context(t), &head) require.NoError(t, err) }) @@ -2993,7 +2997,7 @@ func TestEthConfirmer_ResumePendingRuns(t *testing.T) { pgtest.MustExec(t, db, `UPDATE evm.txes SET pipeline_task_run_id = $1, min_confirmations = $2, signal_callback = TRUE WHERE id = $3`, &tr.ID, minConfirmations, etx.ID) - err := ec.ResumePendingTaskRuns(testutils.Context(t), &head) + err := ec.ResumePendingTaskRuns(tests.Context(t), &head) require.NoError(t, err) }) @@ -3021,12 +3025,12 @@ func TestEthConfirmer_ResumePendingRuns(t *testing.T) { t.Cleanup(func() { <-done }) go func() { defer close(done) - err2 := ec.ResumePendingTaskRuns(testutils.Context(t), &head) + err2 := ec.ResumePendingTaskRuns(tests.Context(t), &head) if !assert.NoError(t, err2) { return } // Retrieve Tx to check if callback completed flag was set to true - updateTx, err3 := txStore.FindTxWithSequence(testutils.Context(t), fromAddress, nonce) + updateTx, err3 := txStore.FindTxWithSequence(tests.Context(t), fromAddress, nonce) if assert.NoError(t, err3) { assert.Equal(t, true, updateTx.CallbackCompleted) } @@ -3075,12 +3079,12 @@ func TestEthConfirmer_ResumePendingRuns(t *testing.T) { t.Cleanup(func() { <-done }) go func() { defer close(done) - err2 := ec.ResumePendingTaskRuns(testutils.Context(t), &head) + err2 := ec.ResumePendingTaskRuns(tests.Context(t), &head) if !assert.NoError(t, err2) { return } // Retrieve Tx to check if callback completed flag was set to true - updateTx, err3 := txStore.FindTxWithSequence(testutils.Context(t), fromAddress, nonce) + updateTx, err3 := txStore.FindTxWithSequence(tests.Context(t), fromAddress, nonce) if assert.NoError(t, err3) { assert.Equal(t, true, updateTx.CallbackCompleted) } @@ -3094,7 +3098,7 @@ func TestEthConfirmer_ResumePendingRuns(t *testing.T) { assert.Nil(t, data.value) - case <-testutils.AfterWaitTimeout(t): + case <-time.After(tests.WaitTimeout(t)): t.Fatal("no value received") } }) @@ -3112,11 +3116,11 @@ func TestEthConfirmer_ResumePendingRuns(t *testing.T) { mustInsertEthReceipt(t, txStore, head.Number-minConfirmations, head.Hash, etx.TxAttempts[0].Hash) pgtest.MustExec(t, db, `UPDATE evm.txes SET pipeline_task_run_id = $1, min_confirmations = $2, signal_callback = TRUE WHERE id = $3`, &tr.ID, minConfirmations, etx.ID) - err := ec.ResumePendingTaskRuns(testutils.Context(t), &head) + err := ec.ResumePendingTaskRuns(tests.Context(t), &head) require.Error(t, err) // Retrieve Tx to check if callback completed flag was left unchanged - updateTx, err := txStore.FindTxWithSequence(testutils.Context(t), fromAddress, nonce) + updateTx, err := txStore.FindTxWithSequence(tests.Context(t), fromAddress, nonce) require.NoError(t, err) require.Equal(t, false, updateTx.CallbackCompleted) }) @@ -3129,7 +3133,7 @@ func TestEthConfirmer_ProcessStuckTransactions(t *testing.T) { txStore := cltest.NewTestTxStore(t, db) ethKeyStore := cltest.NewKeyStore(t, db).Eth() _, fromAddress := cltest.MustInsertRandomKey(t, ethKeyStore) - ethClient := evmtest.NewEthClientMockWithDefaultChain(t) + ethClient := testutils.NewEthClientMockWithDefaultChain(t) ethClient.On("SendTransactionReturnCode", mock.Anything, mock.Anything, fromAddress).Return(commonclient.Successful, nil).Once() lggr := logger.Test(t) feeEstimator := gasmocks.NewEvmFeeEstimator(t) @@ -3157,7 +3161,7 @@ func TestEthConfirmer_ProcessStuckTransactions(t *testing.T) { ec := txmgr.NewEvmConfirmer(txStore, txmgr.NewEvmTxmClient(ethClient, nil), txmgr.NewEvmTxmConfig(evmcfg.EVM()), txmgr.NewEvmTxmFeeConfig(ge), evmcfg.EVM().Transactions(), cfg.Database(), ethKeyStore, txBuilder, lggr, stuckTxDetector) servicetest.Run(t, ec) - ctx := testutils.Context(t) + ctx := tests.Context(t) blockNum := int64(100) t.Run("detects and processes stuck transactions", func(t *testing.T) { @@ -3168,7 +3172,7 @@ func TestEthConfirmer_ProcessStuckTransactions(t *testing.T) { tx := mustInsertUnconfirmedTxWithBroadcastAttempts(t, txStore, nonce, fromAddress, autoPurgeMinAttempts, blockNum-int64(autoPurgeThreshold), marketGasPrice.Add(oneGwei)) head := evmtypes.Head{ - Hash: utils.NewHash(), + Hash: testutils.NewHash(), Number: blockNum, } ethClient.On("SequenceAt", mock.Anything, mock.Anything, mock.Anything).Return(evmtypes.Nonce(0), nil).Once() @@ -3192,7 +3196,7 @@ func TestEthConfirmer_ProcessStuckTransactions(t *testing.T) { require.Equal(t, bumpedFee.Legacy, latestAttempt.TxFee.Legacy) head = evmtypes.Head{ - Hash: utils.NewHash(), + Hash: testutils.NewHash(), Number: blockNum + 1, } ethClient.On("SequenceAt", mock.Anything, mock.Anything, mock.Anything).Return(evmtypes.Nonce(1), nil) @@ -3203,7 +3207,7 @@ func TestEthConfirmer_ProcessStuckTransactions(t *testing.T) { // First transaction confirmed *(elems[0].Result.(*evmtypes.Receipt)) = evmtypes.Receipt{ TxHash: latestAttempt.Hash, - BlockHash: utils.NewHash(), + BlockHash: testutils.NewHash(), BlockNumber: big.NewInt(blockNum + 1), TransactionIndex: uint(1), Status: uint64(1), diff --git a/core/chains/evm/txmgr/evm_tx_store_test.go b/core/chains/evm/txmgr/evm_tx_store_test.go index 23b8a9fde33..71b1bd52851 100644 --- a/core/chains/evm/txmgr/evm_tx_store_test.go +++ b/core/chains/evm/txmgr/evm_tx_store_test.go @@ -16,16 +16,17 @@ import ( commonconfig "github.com/smartcontractkit/chainlink-common/pkg/config" "github.com/smartcontractkit/chainlink-common/pkg/logger" "github.com/smartcontractkit/chainlink-common/pkg/sqlutil" + "github.com/smartcontractkit/chainlink-common/pkg/utils/tests" txmgrcommon "github.com/smartcontractkit/chainlink/v2/common/txmgr" txmgrtypes "github.com/smartcontractkit/chainlink/v2/common/txmgr/types" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/gas" + "github.com/smartcontractkit/chainlink/v2/core/chains/evm/testutils" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/txmgr" evmtypes "github.com/smartcontractkit/chainlink/v2/core/chains/evm/types" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils" "github.com/smartcontractkit/chainlink/v2/core/internal/cltest" - "github.com/smartcontractkit/chainlink/v2/core/internal/testutils" "github.com/smartcontractkit/chainlink/v2/core/internal/testutils/configtest" "github.com/smartcontractkit/chainlink/v2/core/internal/testutils/evmtest" "github.com/smartcontractkit/chainlink/v2/core/internal/testutils/pgtest" @@ -37,7 +38,7 @@ func TestORM_TransactionsWithAttempts(t *testing.T) { db := pgtest.NewSqlxDB(t) txStore := cltest.NewTestTxStore(t, db) ethKeyStore := cltest.NewKeyStore(t, db).Eth() - ctx := testutils.Context(t) + ctx := tests.Context(t) _, from := cltest.MustInsertRandomKey(t, ethKeyStore) @@ -53,7 +54,7 @@ func TestORM_TransactionsWithAttempts(t *testing.T) { require.NoError(t, txStore.InsertTxAttempt(ctx, &attempt)) // tx 3 has no attempts - mustCreateUnstartedGeneratedTx(t, txStore, from, &cltest.FixtureChainID) + mustCreateUnstartedGeneratedTx(t, txStore, from, testutils.FixtureChainID) var count int err := db.Get(&count, `SELECT count(*) FROM evm.txes`) @@ -82,7 +83,7 @@ func TestORM_Transactions(t *testing.T) { db := pgtest.NewSqlxDB(t) txStore := cltest.NewTestTxStore(t, db) ethKeyStore := cltest.NewKeyStore(t, db).Eth() - ctx := testutils.Context(t) + ctx := tests.Context(t) _, from := cltest.MustInsertRandomKey(t, ethKeyStore) @@ -98,7 +99,7 @@ func TestORM_Transactions(t *testing.T) { require.NoError(t, txStore.InsertTxAttempt(ctx, &attempt)) // tx 3 has no attempts - mustCreateUnstartedGeneratedTx(t, txStore, from, &cltest.FixtureChainID) + mustCreateUnstartedGeneratedTx(t, txStore, from, testutils.FixtureChainID) var count int err := db.Get(&count, `SELECT count(*) FROM evm.txes`) @@ -122,7 +123,7 @@ func TestORM(t *testing.T) { keyStore := cltest.NewKeyStore(t, db) orm := cltest.NewTestTxStore(t, db) _, fromAddress := cltest.MustInsertRandomKey(t, keyStore.Eth()) - ctx := testutils.Context(t) + ctx := tests.Context(t) var etx txmgr.Tx t.Run("InsertTx", func(t *testing.T) { @@ -188,7 +189,7 @@ func TestORM_FindTxAttemptConfirmedByTxIDs(t *testing.T) { db := pgtest.NewSqlxDB(t) orm := cltest.NewTestTxStore(t, db) ethKeyStore := cltest.NewKeyStore(t, db).Eth() - ctx := testutils.Context(t) + ctx := tests.Context(t) _, from := cltest.MustInsertRandomKey(t, ethKeyStore) @@ -208,7 +209,7 @@ func TestORM_FindTxAttemptConfirmedByTxIDs(t *testing.T) { _, err := orm.InsertReceipt(ctx, &r.Receipt) require.NoError(t, err) // tx 3 has no attempts - mustCreateUnstartedGeneratedTx(t, orm, from, &cltest.FixtureChainID) + mustCreateUnstartedGeneratedTx(t, orm, from, testutils.FixtureChainID) cltest.MustInsertUnconfirmedEthTx(t, orm, 3, from) // tx4 cltest.MustInsertUnconfirmedEthTxWithBroadcastLegacyAttempt(t, orm, 4, from) // tx5 @@ -237,7 +238,7 @@ func TestORM_FindTxAttemptsRequiringResend(t *testing.T) { db := pgtest.NewSqlxDB(t) txStore := cltest.NewTestTxStore(t, db) - ctx := testutils.Context(t) + ctx := tests.Context(t) ethKeyStore := cltest.NewKeyStore(t, db).Eth() @@ -245,7 +246,7 @@ func TestORM_FindTxAttemptsRequiringResend(t *testing.T) { t.Run("returns nothing if there are no transactions", func(t *testing.T) { olderThan := time.Now() - attempts, err := txStore.FindTxAttemptsRequiringResend(testutils.Context(t), olderThan, 10, &cltest.FixtureChainID, fromAddress) + attempts, err := txStore.FindTxAttemptsRequiringResend(tests.Context(t), olderThan, 10, testutils.FixtureChainID, fromAddress) require.NoError(t, err) assert.Len(t, attempts, 0) }) @@ -288,14 +289,14 @@ func TestORM_FindTxAttemptsRequiringResend(t *testing.T) { t.Run("returns nothing if there are transactions from a different key", func(t *testing.T) { olderThan := time.Now() - attempts, err := txStore.FindTxAttemptsRequiringResend(testutils.Context(t), olderThan, 10, &cltest.FixtureChainID, utils.RandomAddress()) + attempts, err := txStore.FindTxAttemptsRequiringResend(tests.Context(t), olderThan, 10, testutils.FixtureChainID, utils.RandomAddress()) require.NoError(t, err) assert.Len(t, attempts, 0) }) t.Run("returns the highest price attempt for each transaction that was last broadcast before or on the given time", func(t *testing.T) { olderThan := time.Unix(1616509200, 0) - attempts, err := txStore.FindTxAttemptsRequiringResend(testutils.Context(t), olderThan, 0, &cltest.FixtureChainID, fromAddress) + attempts, err := txStore.FindTxAttemptsRequiringResend(tests.Context(t), olderThan, 0, testutils.FixtureChainID, fromAddress) require.NoError(t, err) assert.Len(t, attempts, 2) assert.Equal(t, attempt1_2.ID, attempts[0].ID) @@ -304,7 +305,7 @@ func TestORM_FindTxAttemptsRequiringResend(t *testing.T) { t.Run("returns the highest price attempt for EIP-1559 transactions", func(t *testing.T) { olderThan := time.Unix(1616509400, 0) - attempts, err := txStore.FindTxAttemptsRequiringResend(testutils.Context(t), olderThan, 0, &cltest.FixtureChainID, fromAddress) + attempts, err := txStore.FindTxAttemptsRequiringResend(tests.Context(t), olderThan, 0, testutils.FixtureChainID, fromAddress) require.NoError(t, err) assert.Len(t, attempts, 4) assert.Equal(t, attempt4_4.ID, attempts[3].ID) @@ -312,7 +313,7 @@ func TestORM_FindTxAttemptsRequiringResend(t *testing.T) { t.Run("applies limit", func(t *testing.T) { olderThan := time.Unix(1616509200, 0) - attempts, err := txStore.FindTxAttemptsRequiringResend(testutils.Context(t), olderThan, 1, &cltest.FixtureChainID, fromAddress) + attempts, err := txStore.FindTxAttemptsRequiringResend(tests.Context(t), olderThan, 1, testutils.FixtureChainID, fromAddress) require.NoError(t, err) assert.Len(t, attempts, 1) assert.Equal(t, attempt1_2.ID, attempts[0].ID) @@ -329,14 +330,14 @@ func TestORM_UpdateBroadcastAts(t *testing.T) { t.Run("does not update when broadcast_at is NULL", func(t *testing.T) { t.Parallel() - ctx := testutils.Context(t) - etx := mustCreateUnstartedGeneratedTx(t, orm, fromAddress, &cltest.FixtureChainID) + ctx := tests.Context(t) + etx := mustCreateUnstartedGeneratedTx(t, orm, fromAddress, testutils.FixtureChainID) var nullTime *time.Time assert.Equal(t, nullTime, etx.BroadcastAt) currTime := time.Now() - err := orm.UpdateBroadcastAts(testutils.Context(t), currTime, []int64{etx.ID}) + err := orm.UpdateBroadcastAts(tests.Context(t), currTime, []int64{etx.ID}) require.NoError(t, err) etx, err = orm.FindTxWithAttempts(ctx, etx.ID) @@ -347,7 +348,7 @@ func TestORM_UpdateBroadcastAts(t *testing.T) { t.Run("updates when broadcast_at is non-NULL", func(t *testing.T) { t.Parallel() - ctx := testutils.Context(t) + ctx := tests.Context(t) time1 := time.Now() etx := cltest.NewEthTx(fromAddress) etx.Sequence = new(evmtypes.Nonce) @@ -378,14 +379,14 @@ func TestORM_SetBroadcastBeforeBlockNum(t *testing.T) { _, fromAddress := cltest.MustInsertRandomKeyReturningState(t, ethKeyStore) etx := cltest.MustInsertUnconfirmedEthTxWithBroadcastLegacyAttempt(t, txStore, 0, fromAddress) chainID := ethClient.ConfiguredChainID() - ctx := testutils.Context(t) + ctx := tests.Context(t) headNum := int64(9000) var err error t.Run("saves block num to unconfirmed evm.tx_attempts without one", func(t *testing.T) { // Do the thing - require.NoError(t, txStore.SetBroadcastBeforeBlockNum(testutils.Context(t), headNum, chainID)) + require.NoError(t, txStore.SetBroadcastBeforeBlockNum(tests.Context(t), headNum, chainID)) etx, err = txStore.FindTxWithAttempts(ctx, etx.ID) require.NoError(t, err) @@ -402,7 +403,7 @@ func TestORM_SetBroadcastBeforeBlockNum(t *testing.T) { require.NoError(t, txStore.InsertTxAttempt(ctx, &attempt)) // Do the thing - require.NoError(t, txStore.SetBroadcastBeforeBlockNum(testutils.Context(t), headNum, chainID)) + require.NoError(t, txStore.SetBroadcastBeforeBlockNum(tests.Context(t), headNum, chainID)) etx, err = txStore.FindTxWithAttempts(ctx, etx.ID) require.NoError(t, err) @@ -413,12 +414,12 @@ func TestORM_SetBroadcastBeforeBlockNum(t *testing.T) { }) t.Run("only updates evm.tx_attempts for the current chain", func(t *testing.T) { - require.NoError(t, ethKeyStore.Add(testutils.Context(t), fromAddress, testutils.SimulatedChainID)) - require.NoError(t, ethKeyStore.Enable(testutils.Context(t), fromAddress, testutils.SimulatedChainID)) + require.NoError(t, ethKeyStore.Add(tests.Context(t), fromAddress, testutils.SimulatedChainID)) + require.NoError(t, ethKeyStore.Enable(tests.Context(t), fromAddress, testutils.SimulatedChainID)) etxThisChain := cltest.MustInsertUnconfirmedEthTxWithBroadcastLegacyAttempt(t, txStore, 1, fromAddress, cfg.EVM().ChainID()) etxOtherChain := cltest.MustInsertUnconfirmedEthTxWithBroadcastLegacyAttempt(t, txStore, 0, fromAddress, testutils.SimulatedChainID) - require.NoError(t, txStore.SetBroadcastBeforeBlockNum(testutils.Context(t), headNum, chainID)) + require.NoError(t, txStore.SetBroadcastBeforeBlockNum(tests.Context(t), headNum, chainID)) etxThisChain, err = txStore.FindTxWithAttempts(ctx, etxThisChain.ID) require.NoError(t, err) @@ -449,7 +450,7 @@ func TestORM_FindTxAttemptsConfirmedMissingReceipt(t *testing.T) { etx0 := mustInsertConfirmedMissingReceiptEthTxWithLegacyAttempt( t, txStore, 0, 1, originalBroadcastAt, fromAddress) - attempts, err := txStore.FindTxAttemptsConfirmedMissingReceipt(testutils.Context(t), ethClient.ConfiguredChainID()) + attempts, err := txStore.FindTxAttemptsConfirmedMissingReceipt(tests.Context(t), ethClient.ConfiguredChainID()) require.NoError(t, err) @@ -461,7 +462,7 @@ func TestORM_FindTxAttemptsConfirmedMissingReceipt(t *testing.T) { func TestORM_UpdateTxsUnconfirmed(t *testing.T) { t.Parallel() - ctx := testutils.Context(t) + ctx := tests.Context(t) db := pgtest.NewSqlxDB(t) txStore := cltest.NewTestTxStore(t, db) ethKeyStore := cltest.NewKeyStore(t, db).Eth() @@ -471,7 +472,7 @@ func TestORM_UpdateTxsUnconfirmed(t *testing.T) { etx0 := mustInsertConfirmedMissingReceiptEthTxWithLegacyAttempt( t, txStore, 0, 1, originalBroadcastAt, fromAddress) assert.Equal(t, etx0.State, txmgrcommon.TxConfirmedMissingReceipt) - require.NoError(t, txStore.UpdateTxsUnconfirmed(testutils.Context(t), []int64{etx0.ID})) + require.NoError(t, txStore.UpdateTxsUnconfirmed(tests.Context(t), []int64{etx0.ID})) etx0, err := txStore.FindTxWithAttempts(ctx, etx0.ID) require.NoError(t, err) @@ -491,7 +492,7 @@ func TestORM_FindTxAttemptsRequiringReceiptFetch(t *testing.T) { etx0 := mustInsertConfirmedMissingReceiptEthTxWithLegacyAttempt( t, txStore, 0, 1, originalBroadcastAt, fromAddress) - attempts, err := txStore.FindTxAttemptsRequiringReceiptFetch(testutils.Context(t), ethClient.ConfiguredChainID()) + attempts, err := txStore.FindTxAttemptsRequiringReceiptFetch(tests.Context(t), ethClient.ConfiguredChainID()) require.NoError(t, err) assert.Len(t, attempts, 1) assert.Len(t, etx0.TxAttempts, 1) @@ -506,7 +507,7 @@ func TestORM_SaveFetchedReceipts(t *testing.T) { ethKeyStore := cltest.NewKeyStore(t, db).Eth() ethClient := evmtest.NewEthClientMockWithDefaultChain(t) _, fromAddress := cltest.MustInsertRandomKeyReturningState(t, ethKeyStore) - ctx := testutils.Context(t) + ctx := tests.Context(t) originalBroadcastAt := time.Unix(1616509100, 0) etx0 := mustInsertConfirmedMissingReceiptEthTxWithLegacyAttempt( @@ -521,7 +522,7 @@ func TestORM_SaveFetchedReceipts(t *testing.T) { TransactionIndex: uint(1), } - err := txStore.SaveFetchedReceipts(testutils.Context(t), []*evmtypes.Receipt{&txmReceipt}, txmgrcommon.TxConfirmed, nil, ethClient.ConfiguredChainID()) + err := txStore.SaveFetchedReceipts(tests.Context(t), []*evmtypes.Receipt{&txmReceipt}, txmgrcommon.TxConfirmed, nil, ethClient.ConfiguredChainID()) require.NoError(t, err) etx0, err = txStore.FindTxWithAttempts(ctx, etx0.ID) @@ -540,7 +541,7 @@ func TestORM_MarkAllConfirmedMissingReceipt(t *testing.T) { ethKeyStore := cltest.NewKeyStore(t, db).Eth() _, fromAddress := cltest.MustInsertRandomKeyReturningState(t, ethKeyStore) ethClient := evmtest.NewEthClientMockWithDefaultChain(t) - ctx := testutils.Context(t) + ctx := tests.Context(t) // create transaction 0 (nonce 0) that is unconfirmed (block 7) etx0_blocknum := int64(7) @@ -555,7 +556,7 @@ func TestORM_MarkAllConfirmedMissingReceipt(t *testing.T) { assert.Equal(t, etx1.State, txmgrcommon.TxConfirmed) // mark transaction 0 confirmed_missing_receipt - err := txStore.MarkAllConfirmedMissingReceipt(testutils.Context(t), ethClient.ConfiguredChainID()) + err := txStore.MarkAllConfirmedMissingReceipt(tests.Context(t), ethClient.ConfiguredChainID()) require.NoError(t, err) etx0, err = txStore.FindTxWithAttempts(ctx, etx0.ID) require.NoError(t, err) @@ -582,7 +583,7 @@ func TestORM_PreloadTxes(t *testing.T) { attempts := []txmgr.TxAttempt{unloadedAttempt} - err := txStore.PreloadTxes(testutils.Context(t), attempts) + err := txStore.PreloadTxes(tests.Context(t), attempts) require.NoError(t, err) assert.Equal(t, etx.ID, attempts[0].Tx.ID) @@ -590,7 +591,7 @@ func TestORM_PreloadTxes(t *testing.T) { t.Run("returns nil when attempts slice is empty", func(t *testing.T) { emptyAttempts := []txmgr.TxAttempt{} - err := txStore.PreloadTxes(testutils.Context(t), emptyAttempts) + err := txStore.PreloadTxes(tests.Context(t), emptyAttempts) require.NoError(t, err) }) } @@ -608,7 +609,7 @@ func TestORM_GetInProgressTxAttempts(t *testing.T) { etx := mustInsertUnconfirmedEthTxWithAttemptState(t, txStore, int64(7), fromAddress, txmgrtypes.TxAttemptInProgress) // fetch attempt - attempts, err := txStore.GetInProgressTxAttempts(testutils.Context(t), fromAddress, ethClient.ConfiguredChainID()) + attempts, err := txStore.GetInProgressTxAttempts(tests.Context(t), fromAddress, ethClient.ConfiguredChainID()) require.NoError(t, err) assert.Len(t, attempts, 1) @@ -683,7 +684,7 @@ func TestORM_FindTxesPendingCallback(t *testing.T) { pgtest.MustExec(t, db, `UPDATE evm.txes SET min_confirmations = $1 WHERE id = $2`, minConfirmations, etx5.ID) // Search evm.txes table for tx requiring callback - receiptsPlus, err := txStore.FindTxesPendingCallback(testutils.Context(t), head.Number, ethClient.ConfiguredChainID()) + receiptsPlus, err := txStore.FindTxesPendingCallback(tests.Context(t), head.Number, ethClient.ConfiguredChainID()) require.NoError(t, err) assert.Len(t, receiptsPlus, 1) assert.Equal(t, tr1.ID, receiptsPlus[0].ID) @@ -699,7 +700,7 @@ func Test_FindTxWithIdempotencyKey(t *testing.T) { t.Run("returns nil if no results", func(t *testing.T) { idempotencyKey := "777" - etx, err := txStore.FindTxWithIdempotencyKey(testutils.Context(t), idempotencyKey, big.NewInt(0)) + etx, err := txStore.FindTxWithIdempotencyKey(tests.Context(t), idempotencyKey, big.NewInt(0)) require.NoError(t, err) assert.Nil(t, etx) }) @@ -711,7 +712,7 @@ func Test_FindTxWithIdempotencyKey(t *testing.T) { txRequestWithIdempotencyKey(idempotencyKey)) require.Equal(t, idempotencyKey, *etx.IdempotencyKey) - res, err := txStore.FindTxWithIdempotencyKey(testutils.Context(t), idempotencyKey, big.NewInt(0)) + res, err := txStore.FindTxWithIdempotencyKey(tests.Context(t), idempotencyKey, big.NewInt(0)) require.NoError(t, err) assert.Equal(t, etx.Sequence, res.Sequence) require.Equal(t, idempotencyKey, *res.IdempotencyKey) @@ -727,7 +728,7 @@ func TestORM_FindTxWithSequence(t *testing.T) { _, fromAddress := cltest.MustInsertRandomKeyReturningState(t, ethKeyStore) t.Run("returns nil if no results", func(t *testing.T) { - etx, err := txStore.FindTxWithSequence(testutils.Context(t), fromAddress, evmtypes.Nonce(777)) + etx, err := txStore.FindTxWithSequence(tests.Context(t), fromAddress, evmtypes.Nonce(777)) require.NoError(t, err) assert.Nil(t, etx) }) @@ -736,7 +737,7 @@ func TestORM_FindTxWithSequence(t *testing.T) { etx := cltest.MustInsertConfirmedEthTxWithLegacyAttempt(t, txStore, 777, 1, fromAddress) require.Equal(t, evmtypes.Nonce(777), *etx.Sequence) - res, err := txStore.FindTxWithSequence(testutils.Context(t), fromAddress, evmtypes.Nonce(777)) + res, err := txStore.FindTxWithSequence(tests.Context(t), fromAddress, evmtypes.Nonce(777)) require.NoError(t, err) assert.Equal(t, etx.Sequence, res.Sequence) }) @@ -749,7 +750,7 @@ func TestORM_UpdateTxForRebroadcast(t *testing.T) { txStore := cltest.NewTestTxStore(t, db) ethKeyStore := cltest.NewKeyStore(t, db).Eth() _, fromAddress := cltest.MustInsertRandomKeyReturningState(t, ethKeyStore) - ctx := testutils.Context(t) + ctx := tests.Context(t) t.Run("delete all receipts for eth transaction", func(t *testing.T) { etx := mustInsertConfirmedEthTxWithReceipt(t, txStore, fromAddress, 777, 1) @@ -764,7 +765,7 @@ func TestORM_UpdateTxForRebroadcast(t *testing.T) { assert.Len(t, etx.TxAttempts[0].Receipts, 1) // use exported method - err = txStore.UpdateTxForRebroadcast(testutils.Context(t), etx, attempt) + err = txStore.UpdateTxForRebroadcast(tests.Context(t), etx, attempt) require.NoError(t, err) resultTx, err := txStore.FindTxWithAttempts(ctx, etx.ID) @@ -792,7 +793,7 @@ func TestORM_IsTxFinalized(t *testing.T) { t.Run("confirmed tx not past finality_depth", func(t *testing.T) { confirmedAddr := cltest.MustGenerateRandomKey(t).Address tx := mustInsertConfirmedEthTxWithReceipt(t, txStore, confirmedAddr, 123, 1) - finalized, err := txStore.IsTxFinalized(testutils.Context(t), 2, tx.ID, ethClient.ConfiguredChainID()) + finalized, err := txStore.IsTxFinalized(tests.Context(t), 2, tx.ID, ethClient.ConfiguredChainID()) require.NoError(t, err) require.False(t, finalized) }) @@ -800,7 +801,7 @@ func TestORM_IsTxFinalized(t *testing.T) { t.Run("confirmed tx past finality_depth", func(t *testing.T) { confirmedAddr := cltest.MustGenerateRandomKey(t).Address tx := mustInsertConfirmedEthTxWithReceipt(t, txStore, confirmedAddr, 123, 1) - finalized, err := txStore.IsTxFinalized(testutils.Context(t), 10, tx.ID, ethClient.ConfiguredChainID()) + finalized, err := txStore.IsTxFinalized(tests.Context(t), 10, tx.ID, ethClient.ConfiguredChainID()) require.NoError(t, err) require.True(t, finalized) }) @@ -833,7 +834,7 @@ func TestORM_FindTransactionsConfirmedInBlockRange(t *testing.T) { etx_8 := mustInsertConfirmedEthTxWithReceipt(t, txStore, fromAddress, 700, 8) etx_9 := mustInsertConfirmedEthTxWithReceipt(t, txStore, fromAddress, 777, 9) - etxes, err := txStore.FindTransactionsConfirmedInBlockRange(testutils.Context(t), head.Number, 8, ethClient.ConfiguredChainID()) + etxes, err := txStore.FindTransactionsConfirmedInBlockRange(tests.Context(t), head.Number, 8, ethClient.ConfiguredChainID()) require.NoError(t, err) assert.Len(t, etxes, 2) assert.Equal(t, etxes[0].Sequence, etx_8.Sequence) @@ -851,14 +852,14 @@ func TestORM_FindEarliestUnconfirmedBroadcastTime(t *testing.T) { _, fromAddress := cltest.MustInsertRandomKeyReturningState(t, ethKeyStore) t.Run("no unconfirmed eth txes", func(t *testing.T) { - broadcastAt, err := txStore.FindEarliestUnconfirmedBroadcastTime(testutils.Context(t), ethClient.ConfiguredChainID()) + broadcastAt, err := txStore.FindEarliestUnconfirmedBroadcastTime(tests.Context(t), ethClient.ConfiguredChainID()) require.NoError(t, err) require.False(t, broadcastAt.Valid) }) t.Run("verify broadcast time", func(t *testing.T) { tx := cltest.MustInsertUnconfirmedEthTx(t, txStore, 123, fromAddress) - broadcastAt, err := txStore.FindEarliestUnconfirmedBroadcastTime(testutils.Context(t), ethClient.ConfiguredChainID()) + broadcastAt, err := txStore.FindEarliestUnconfirmedBroadcastTime(tests.Context(t), ethClient.ConfiguredChainID()) require.NoError(t, err) require.True(t, broadcastAt.Ptr().Equal(*tx.BroadcastAt)) }) @@ -875,7 +876,7 @@ func TestORM_FindEarliestUnconfirmedTxAttemptBlock(t *testing.T) { _, fromAddress2 := cltest.MustInsertRandomKeyReturningState(t, ethKeyStore) t.Run("no earliest unconfirmed tx block", func(t *testing.T) { - earliestBlock, err := txStore.FindEarliestUnconfirmedTxAttemptBlock(testutils.Context(t), ethClient.ConfiguredChainID()) + earliestBlock, err := txStore.FindEarliestUnconfirmedTxAttemptBlock(tests.Context(t), ethClient.ConfiguredChainID()) require.NoError(t, err) require.False(t, earliestBlock.Valid) }) @@ -884,10 +885,10 @@ func TestORM_FindEarliestUnconfirmedTxAttemptBlock(t *testing.T) { var blockNum int64 = 2 tx := mustInsertConfirmedMissingReceiptEthTxWithLegacyAttempt(t, txStore, 123, blockNum, time.Now(), fromAddress) _ = mustInsertConfirmedMissingReceiptEthTxWithLegacyAttempt(t, txStore, 123, blockNum, time.Now().Add(time.Minute), fromAddress2) - err := txStore.UpdateTxsUnconfirmed(testutils.Context(t), []int64{tx.ID}) + err := txStore.UpdateTxsUnconfirmed(tests.Context(t), []int64{tx.ID}) require.NoError(t, err) - earliestBlock, err := txStore.FindEarliestUnconfirmedTxAttemptBlock(testutils.Context(t), ethClient.ConfiguredChainID()) + earliestBlock, err := txStore.FindEarliestUnconfirmedTxAttemptBlock(tests.Context(t), ethClient.ConfiguredChainID()) require.NoError(t, err) require.True(t, earliestBlock.Valid) require.Equal(t, blockNum, earliestBlock.Int64) @@ -897,7 +898,7 @@ func TestORM_FindEarliestUnconfirmedTxAttemptBlock(t *testing.T) { func TestORM_SaveInsufficientEthAttempt(t *testing.T) { t.Parallel() - ctx := testutils.Context(t) + ctx := tests.Context(t) db := pgtest.NewSqlxDB(t) txStore := cltest.NewTestTxStore(t, db) ethKeyStore := cltest.NewKeyStore(t, db).Eth() @@ -909,7 +910,7 @@ func TestORM_SaveInsufficientEthAttempt(t *testing.T) { etx := mustInsertInProgressEthTxWithAttempt(t, txStore, 1, fromAddress) now := time.Now() - err = txStore.SaveInsufficientFundsAttempt(testutils.Context(t), defaultDuration, &etx.TxAttempts[0], now) + err = txStore.SaveInsufficientFundsAttempt(tests.Context(t), defaultDuration, &etx.TxAttempts[0], now) require.NoError(t, err) attempt, err := txStore.FindTxAttempt(ctx, etx.TxAttempts[0].Hash) @@ -921,7 +922,7 @@ func TestORM_SaveInsufficientEthAttempt(t *testing.T) { func TestORM_SaveSentAttempt(t *testing.T) { t.Parallel() - ctx := testutils.Context(t) + ctx := tests.Context(t) db := pgtest.NewSqlxDB(t) txStore := cltest.NewTestTxStore(t, db) ethKeyStore := cltest.NewKeyStore(t, db).Eth() @@ -934,7 +935,7 @@ func TestORM_SaveSentAttempt(t *testing.T) { require.Nil(t, etx.BroadcastAt) now := time.Now() - err = txStore.SaveSentAttempt(testutils.Context(t), defaultDuration, &etx.TxAttempts[0], now) + err = txStore.SaveSentAttempt(tests.Context(t), defaultDuration, &etx.TxAttempts[0], now) require.NoError(t, err) attempt, err := txStore.FindTxAttempt(ctx, etx.TxAttempts[0].Hash) @@ -946,7 +947,7 @@ func TestORM_SaveSentAttempt(t *testing.T) { func TestORM_SaveConfirmedMissingReceiptAttempt(t *testing.T) { t.Parallel() - ctx := testutils.Context(t) + ctx := tests.Context(t) db := pgtest.NewSqlxDB(t) txStore := cltest.NewTestTxStore(t, db) ethKeyStore := cltest.NewKeyStore(t, db).Eth() @@ -958,7 +959,7 @@ func TestORM_SaveConfirmedMissingReceiptAttempt(t *testing.T) { etx := mustInsertUnconfirmedEthTxWithAttemptState(t, txStore, 1, fromAddress, txmgrtypes.TxAttemptInProgress) now := time.Now() - err = txStore.SaveConfirmedMissingReceiptAttempt(testutils.Context(t), defaultDuration, &etx.TxAttempts[0], now) + err = txStore.SaveConfirmedMissingReceiptAttempt(tests.Context(t), defaultDuration, &etx.TxAttempts[0], now) require.NoError(t, err) etx, err := txStore.FindTxWithAttempts(ctx, etx.ID) @@ -971,7 +972,7 @@ func TestORM_SaveConfirmedMissingReceiptAttempt(t *testing.T) { func TestORM_DeleteInProgressAttempt(t *testing.T) { t.Parallel() - ctx := testutils.Context(t) + ctx := tests.Context(t) db := pgtest.NewSqlxDB(t) txStore := cltest.NewTestTxStore(t, db) ethKeyStore := cltest.NewKeyStore(t, db).Eth() @@ -981,7 +982,7 @@ func TestORM_DeleteInProgressAttempt(t *testing.T) { etx := mustInsertInProgressEthTxWithAttempt(t, txStore, 1, fromAddress) attempt := etx.TxAttempts[0] - err := txStore.DeleteInProgressAttempt(testutils.Context(t), etx.TxAttempts[0]) + err := txStore.DeleteInProgressAttempt(tests.Context(t), etx.TxAttempts[0]) require.NoError(t, err) nilResult, err := txStore.FindTxAttempt(ctx, attempt.Hash) @@ -993,7 +994,7 @@ func TestORM_DeleteInProgressAttempt(t *testing.T) { func TestORM_SaveInProgressAttempt(t *testing.T) { t.Parallel() - ctx := testutils.Context(t) + ctx := tests.Context(t) db := pgtest.NewSqlxDB(t) txStore := cltest.NewTestTxStore(t, db) ethKeyStore := cltest.NewKeyStore(t, db).Eth() @@ -1005,7 +1006,7 @@ func TestORM_SaveInProgressAttempt(t *testing.T) { attempt := cltest.NewLegacyEthTxAttempt(t, etx.ID) require.Equal(t, int64(0), attempt.ID) - err := txStore.SaveInProgressAttempt(testutils.Context(t), &attempt) + err := txStore.SaveInProgressAttempt(tests.Context(t), &attempt) require.NoError(t, err) attemptResult, err := txStore.FindTxAttempt(ctx, attempt.Hash) @@ -1021,7 +1022,7 @@ func TestORM_SaveInProgressAttempt(t *testing.T) { attempt.BroadcastBeforeBlockNum = nil attempt.State = txmgrtypes.TxAttemptInProgress - err := txStore.SaveInProgressAttempt(testutils.Context(t), &attempt) + err := txStore.SaveInProgressAttempt(tests.Context(t), &attempt) require.NoError(t, err) attemptResult, err := txStore.FindTxAttempt(ctx, attempt.Hash) @@ -1033,7 +1034,7 @@ func TestORM_SaveInProgressAttempt(t *testing.T) { func TestORM_FindTxsRequiringGasBump(t *testing.T) { t.Parallel() - ctx := testutils.Context(t) + ctx := tests.Context(t) db := pgtest.NewSqlxDB(t) txStore := cltest.NewTestTxStore(t, db) ethKeyStore := cltest.NewKeyStore(t, db).Eth() @@ -1044,7 +1045,7 @@ func TestORM_FindTxsRequiringGasBump(t *testing.T) { t.Run("gets txs requiring gas bump", func(t *testing.T) { etx := mustInsertUnconfirmedEthTxWithAttemptState(t, txStore, 1, fromAddress, txmgrtypes.TxAttemptBroadcast) - err := txStore.SetBroadcastBeforeBlockNum(testutils.Context(t), currentBlockNum, ethClient.ConfiguredChainID()) + err := txStore.SetBroadcastBeforeBlockNum(tests.Context(t), currentBlockNum, ethClient.ConfiguredChainID()) require.NoError(t, err) // this tx will require gas bump @@ -1057,13 +1058,13 @@ func TestORM_FindTxsRequiringGasBump(t *testing.T) { // this tx will not require gas bump mustInsertUnconfirmedEthTxWithAttemptState(t, txStore, 2, fromAddress, txmgrtypes.TxAttemptBroadcast) - err = txStore.SetBroadcastBeforeBlockNum(testutils.Context(t), currentBlockNum+1, ethClient.ConfiguredChainID()) + err = txStore.SetBroadcastBeforeBlockNum(tests.Context(t), currentBlockNum+1, ethClient.ConfiguredChainID()) require.NoError(t, err) // any tx broadcast <= 10 will require gas bump newBlock := int64(12) gasBumpThreshold := int64(2) - etxs, err := txStore.FindTxsRequiringGasBump(testutils.Context(t), fromAddress, newBlock, gasBumpThreshold, int64(0), ethClient.ConfiguredChainID()) + etxs, err := txStore.FindTxsRequiringGasBump(tests.Context(t), fromAddress, newBlock, gasBumpThreshold, int64(0), ethClient.ConfiguredChainID()) require.NoError(t, err) assert.Len(t, etxs, 1) assert.Equal(t, etx.ID, etxs[0].ID) @@ -1075,7 +1076,7 @@ func TestEthConfirmer_FindTxsRequiringResubmissionDueToInsufficientEth(t *testin db := pgtest.NewSqlxDB(t) txStore := cltest.NewTestTxStore(t, db) - ctx := testutils.Context(t) + ctx := tests.Context(t) ethKeyStore := cltest.NewKeyStore(t, db).Eth() @@ -1097,7 +1098,7 @@ func TestEthConfirmer_FindTxsRequiringResubmissionDueToInsufficientEth(t *testin mustInsertUnconfirmedEthTxWithInsufficientEthAttempt(t, txStore, 0, otherAddress) t.Run("returns all eth_txes with at least one attempt that is in insufficient_eth state", func(t *testing.T) { - etxs, err := txStore.FindTxsRequiringResubmissionDueToInsufficientFunds(testutils.Context(t), fromAddress, &cltest.FixtureChainID) + etxs, err := txStore.FindTxsRequiringResubmissionDueToInsufficientFunds(tests.Context(t), fromAddress, testutils.FixtureChainID) require.NoError(t, err) assert.Len(t, etxs, 3) @@ -1111,7 +1112,7 @@ func TestEthConfirmer_FindTxsRequiringResubmissionDueToInsufficientEth(t *testin }) t.Run("does not return eth_txes with different chain ID", func(t *testing.T) { - etxs, err := txStore.FindTxsRequiringResubmissionDueToInsufficientFunds(testutils.Context(t), fromAddress, big.NewInt(42)) + etxs, err := txStore.FindTxsRequiringResubmissionDueToInsufficientFunds(tests.Context(t), fromAddress, big.NewInt(42)) require.NoError(t, err) assert.Len(t, etxs, 0) @@ -1121,7 +1122,7 @@ func TestEthConfirmer_FindTxsRequiringResubmissionDueToInsufficientEth(t *testin pgtest.MustExec(t, db, `UPDATE evm.txes SET state='confirmed' WHERE id = $1`, etx1.ID) pgtest.MustExec(t, db, `UPDATE evm.txes SET state='fatal_error', nonce=NULL, error='foo', broadcast_at=NULL, initial_broadcast_at=NULL WHERE id = $1`, etx2.ID) - etxs, err := txStore.FindTxsRequiringResubmissionDueToInsufficientFunds(testutils.Context(t), fromAddress, &cltest.FixtureChainID) + etxs, err := txStore.FindTxsRequiringResubmissionDueToInsufficientFunds(tests.Context(t), fromAddress, testutils.FixtureChainID) require.NoError(t, err) assert.Len(t, etxs, 1) @@ -1136,7 +1137,7 @@ func TestORM_MarkOldTxesMissingReceiptAsErrored(t *testing.T) { db := pgtest.NewSqlxDB(t) txStore := cltest.NewTestTxStore(t, db) - ctx := testutils.Context(t) + ctx := tests.Context(t) ethKeyStore := cltest.NewKeyStore(t, db).Eth() ethClient := evmtest.NewEthClientMockWithDefaultChain(t) _, fromAddress := cltest.MustInsertRandomKeyReturningState(t, ethKeyStore) @@ -1146,7 +1147,7 @@ func TestORM_MarkOldTxesMissingReceiptAsErrored(t *testing.T) { t.Run("successfully mark errored transactions", func(t *testing.T) { etx := mustInsertConfirmedMissingReceiptEthTxWithLegacyAttempt(t, txStore, 1, 7, time.Now(), fromAddress) - err := txStore.MarkOldTxesMissingReceiptAsErrored(testutils.Context(t), 10, 2, ethClient.ConfiguredChainID()) + err := txStore.MarkOldTxesMissingReceiptAsErrored(tests.Context(t), 10, 2, ethClient.ConfiguredChainID()) require.NoError(t, err) etx, err = txStore.FindTxWithAttempts(ctx, etx.ID) @@ -1156,7 +1157,7 @@ func TestORM_MarkOldTxesMissingReceiptAsErrored(t *testing.T) { t.Run("successfully mark errored transactions w/ qopt passing in sql.Tx", func(t *testing.T) { etx := mustInsertConfirmedMissingReceiptEthTxWithLegacyAttempt(t, txStore, 1, 7, time.Now(), fromAddress) - err := txStore.MarkOldTxesMissingReceiptAsErrored(testutils.Context(t), 10, 2, ethClient.ConfiguredChainID()) + err := txStore.MarkOldTxesMissingReceiptAsErrored(tests.Context(t), 10, 2, ethClient.ConfiguredChainID()) require.NoError(t, err) // must run other query outside of postgres transaction so changes are committed @@ -1169,7 +1170,7 @@ func TestORM_MarkOldTxesMissingReceiptAsErrored(t *testing.T) { func TestORM_LoadEthTxesAttempts(t *testing.T) { t.Parallel() - ctx := testutils.Context(t) + ctx := tests.Context(t) db := pgtest.NewSqlxDB(t) txStore := cltest.NewTestTxStore(t, db) ethKeyStore := cltest.NewKeyStore(t, db).Eth() @@ -1222,7 +1223,7 @@ func TestORM_LoadEthTxesAttempts(t *testing.T) { func TestORM_SaveReplacementInProgressAttempt(t *testing.T) { t.Parallel() - ctx := testutils.Context(t) + ctx := tests.Context(t) db := pgtest.NewSqlxDB(t) txStore := cltest.NewTestTxStore(t, db) ethKeyStore := cltest.NewKeyStore(t, db).Eth() @@ -1233,7 +1234,7 @@ func TestORM_SaveReplacementInProgressAttempt(t *testing.T) { oldAttempt := etx.TxAttempts[0] newAttempt := cltest.NewDynamicFeeEthTxAttempt(t, etx.ID) - err := txStore.SaveReplacementInProgressAttempt(testutils.Context(t), oldAttempt, &newAttempt) + err := txStore.SaveReplacementInProgressAttempt(tests.Context(t), oldAttempt, &newAttempt) require.NoError(t, err) etx, err = txStore.FindTxWithAttempts(ctx, etx.ID) @@ -1256,14 +1257,14 @@ func TestORM_FindNextUnstartedTransactionFromAddress(t *testing.T) { t.Run("cannot find unstarted tx", func(t *testing.T) { mustInsertInProgressEthTxWithAttempt(t, txStore, 13, fromAddress) - resultEtx, err := txStore.FindNextUnstartedTransactionFromAddress(testutils.Context(t), fromAddress, ethClient.ConfiguredChainID()) + resultEtx, err := txStore.FindNextUnstartedTransactionFromAddress(tests.Context(t), fromAddress, ethClient.ConfiguredChainID()) assert.ErrorIs(t, err, sql.ErrNoRows) assert.Nil(t, resultEtx) }) t.Run("finds unstarted tx", func(t *testing.T) { - mustCreateUnstartedGeneratedTx(t, txStore, fromAddress, &cltest.FixtureChainID) - resultEtx, err := txStore.FindNextUnstartedTransactionFromAddress(testutils.Context(t), fromAddress, ethClient.ConfiguredChainID()) + mustCreateUnstartedGeneratedTx(t, txStore, fromAddress, testutils.FixtureChainID) + resultEtx, err := txStore.FindNextUnstartedTransactionFromAddress(tests.Context(t), fromAddress, ethClient.ConfiguredChainID()) require.NoError(t, err) assert.NotNil(t, resultEtx) }) @@ -1272,7 +1273,7 @@ func TestORM_FindNextUnstartedTransactionFromAddress(t *testing.T) { func TestORM_UpdateTxFatalError(t *testing.T) { t.Parallel() - ctx := testutils.Context(t) + ctx := tests.Context(t) db := pgtest.NewSqlxDB(t) txStore := cltest.NewTestTxStore(t, db) ethKeyStore := cltest.NewKeyStore(t, db).Eth() @@ -1284,7 +1285,7 @@ func TestORM_UpdateTxFatalError(t *testing.T) { etxPretendError := null.StringFrom("no more toilet paper") etx.Error = etxPretendError - err := txStore.UpdateTxFatalError(testutils.Context(t), &etx) + err := txStore.UpdateTxFatalError(tests.Context(t), &etx) require.NoError(t, err) etx, err = txStore.FindTxWithAttempts(ctx, etx.ID) require.NoError(t, err) @@ -1296,7 +1297,7 @@ func TestORM_UpdateTxFatalError(t *testing.T) { func TestORM_UpdateTxAttemptInProgressToBroadcast(t *testing.T) { t.Parallel() - ctx := testutils.Context(t) + ctx := tests.Context(t) db := pgtest.NewSqlxDB(t) txStore := cltest.NewTestTxStore(t, db) ethKeyStore := cltest.NewKeyStore(t, db).Eth() @@ -1311,7 +1312,7 @@ func TestORM_UpdateTxAttemptInProgressToBroadcast(t *testing.T) { i := int16(0) etx.BroadcastAt = &time1 etx.InitialBroadcastAt = &time1 - err := txStore.UpdateTxAttemptInProgressToBroadcast(testutils.Context(t), &etx, attempt, txmgrtypes.TxAttemptBroadcast) + err := txStore.UpdateTxAttemptInProgressToBroadcast(tests.Context(t), &etx, attempt, txmgrtypes.TxAttemptBroadcast) require.NoError(t, err) // Increment sequence i++ @@ -1327,7 +1328,7 @@ func TestORM_UpdateTxAttemptInProgressToBroadcast(t *testing.T) { func TestORM_UpdateTxUnstartedToInProgress(t *testing.T) { t.Parallel() - ctx := testutils.Context(t) + ctx := tests.Context(t) db := pgtest.NewSqlxDB(t) txStore := cltest.NewTestTxStore(t, db) ethKeyStore := cltest.NewKeyStore(t, db).Eth() @@ -1335,11 +1336,11 @@ func TestORM_UpdateTxUnstartedToInProgress(t *testing.T) { nonce := evmtypes.Nonce(123) t.Run("update successful", func(t *testing.T) { - etx := mustCreateUnstartedGeneratedTx(t, txStore, fromAddress, &cltest.FixtureChainID) + etx := mustCreateUnstartedGeneratedTx(t, txStore, fromAddress, testutils.FixtureChainID) etx.Sequence = &nonce attempt := cltest.NewLegacyEthTxAttempt(t, etx.ID) - err := txStore.UpdateTxUnstartedToInProgress(testutils.Context(t), &etx, &attempt) + err := txStore.UpdateTxUnstartedToInProgress(tests.Context(t), &etx, &attempt) require.NoError(t, err) etx, err = txStore.FindTxWithAttempts(ctx, etx.ID) @@ -1349,7 +1350,7 @@ func TestORM_UpdateTxUnstartedToInProgress(t *testing.T) { }) t.Run("update fails because tx is removed", func(t *testing.T) { - etx := mustCreateUnstartedGeneratedTx(t, txStore, fromAddress, &cltest.FixtureChainID) + etx := mustCreateUnstartedGeneratedTx(t, txStore, fromAddress, testutils.FixtureChainID) etx.Sequence = &nonce attempt := cltest.NewLegacyEthTxAttempt(t, etx.ID) @@ -1357,7 +1358,7 @@ func TestORM_UpdateTxUnstartedToInProgress(t *testing.T) { _, err := db.ExecContext(ctx, "DELETE FROM evm.txes WHERE id = $1", etx.ID) require.NoError(t, err) - err = txStore.UpdateTxUnstartedToInProgress(testutils.Context(t), &etx, &attempt) + err = txStore.UpdateTxUnstartedToInProgress(tests.Context(t), &etx, &attempt) require.ErrorContains(t, err, "tx removed") }) @@ -1385,14 +1386,14 @@ func TestORM_UpdateTxUnstartedToInProgress(t *testing.T) { err := txMgr.XXXTestAbandon(fromAddress) // mark transaction as abandoned require.NoError(t, err) - etx2 := mustCreateUnstartedGeneratedTx(t, txStore, fromAddress, &cltest.FixtureChainID) + etx2 := mustCreateUnstartedGeneratedTx(t, txStore, fromAddress, testutils.FixtureChainID) etx2.Sequence = &nonce attempt2 := cltest.NewLegacyEthTxAttempt(t, etx2.ID) attempt2.Hash = etx.TxAttempts[0].Hash // Even though this will initially fail due to idx_eth_tx_attempts_hash constraint, because the conflicting tx has been abandoned // it should succeed after removing the abandoned attempt and retrying the insert - err = txStore.UpdateTxUnstartedToInProgress(testutils.Context(t), &etx2, &attempt2) + err = txStore.UpdateTxUnstartedToInProgress(tests.Context(t), &etx2, &attempt2) require.NoError(t, err) }) @@ -1406,7 +1407,7 @@ func TestORM_UpdateTxUnstartedToInProgress(t *testing.T) { etx.State = txmgrcommon.TxUnstarted // Should fail due to idx_eth_tx_attempt_hash constraint - err := txStore.UpdateTxUnstartedToInProgress(testutils.Context(t), &etx, &etx.TxAttempts[0]) + err := txStore.UpdateTxUnstartedToInProgress(tests.Context(t), &etx, &etx.TxAttempts[0]) assert.ErrorContains(t, err, "idx_eth_tx_attempts_hash") txStore = cltest.NewTestTxStore(t, db) // current txStore is poisened now, next test will need fresh one }) @@ -1421,7 +1422,7 @@ func TestORM_GetTxInProgress(t *testing.T) { _, fromAddress := cltest.MustInsertRandomKeyReturningState(t, ethKeyStore) t.Run("gets 0 in progress eth transaction", func(t *testing.T) { - etxResult, err := txStore.GetTxInProgress(testutils.Context(t), fromAddress) + etxResult, err := txStore.GetTxInProgress(tests.Context(t), fromAddress) require.NoError(t, err) require.Nil(t, etxResult) }) @@ -1429,7 +1430,7 @@ func TestORM_GetTxInProgress(t *testing.T) { t.Run("get 1 in progress eth transaction", func(t *testing.T) { etx := mustInsertInProgressEthTxWithAttempt(t, txStore, 123, fromAddress) - etxResult, err := txStore.GetTxInProgress(testutils.Context(t), fromAddress) + etxResult, err := txStore.GetTxInProgress(tests.Context(t), fromAddress) require.NoError(t, err) assert.Equal(t, etxResult.ID, etx.ID) }) @@ -1447,7 +1448,7 @@ func TestORM_GetAbandonedTransactionsByBatch(t *testing.T) { enabledAddrs := []common.Address{enabled} t.Run("get 0 abandoned transactions", func(t *testing.T) { - txes, err := txStore.GetAbandonedTransactionsByBatch(testutils.Context(t), ethClient.ConfiguredChainID(), enabledAddrs, 0, 10) + txes, err := txStore.GetAbandonedTransactionsByBatch(tests.Context(t), ethClient.ConfiguredChainID(), enabledAddrs, 0, 10) require.NoError(t, err) require.Empty(t, txes) }) @@ -1455,7 +1456,7 @@ func TestORM_GetAbandonedTransactionsByBatch(t *testing.T) { t.Run("do not return enabled addresses", func(t *testing.T) { _ = mustInsertInProgressEthTxWithAttempt(t, txStore, 123, enabled) _ = mustCreateUnstartedGeneratedTx(t, txStore, enabled, ethClient.ConfiguredChainID()) - txes, err := txStore.GetAbandonedTransactionsByBatch(testutils.Context(t), ethClient.ConfiguredChainID(), enabledAddrs, 0, 10) + txes, err := txStore.GetAbandonedTransactionsByBatch(tests.Context(t), ethClient.ConfiguredChainID(), enabledAddrs, 0, 10) require.NoError(t, err) require.Empty(t, txes) }) @@ -1464,7 +1465,7 @@ func TestORM_GetAbandonedTransactionsByBatch(t *testing.T) { inProgressTx := mustInsertInProgressEthTxWithAttempt(t, txStore, 123, fromAddress) unstartedTx := mustCreateUnstartedGeneratedTx(t, txStore, fromAddress, ethClient.ConfiguredChainID()) - txes, err := txStore.GetAbandonedTransactionsByBatch(testutils.Context(t), ethClient.ConfiguredChainID(), enabledAddrs, 0, 10) + txes, err := txStore.GetAbandonedTransactionsByBatch(tests.Context(t), ethClient.ConfiguredChainID(), enabledAddrs, 0, 10) require.NoError(t, err) require.Len(t, txes, 2) @@ -1482,7 +1483,7 @@ func TestORM_GetAbandonedTransactionsByBatch(t *testing.T) { allTxes := make([]*txmgr.Tx, 0) err := sqlutil.Batch(func(offset, limit uint) (count uint, err error) { - batchTxes, err := txStore.GetAbandonedTransactionsByBatch(testutils.Context(t), ethClient.ConfiguredChainID(), enabledAddrs, offset, limit) + batchTxes, err := txStore.GetAbandonedTransactionsByBatch(tests.Context(t), ethClient.ConfiguredChainID(), enabledAddrs, offset, limit) require.NoError(t, err) allTxes = append(allTxes, batchTxes...) return uint(len(batchTxes)), nil @@ -1501,14 +1502,14 @@ func TestORM_GetTxByID(t *testing.T) { _, fromAddress := cltest.MustInsertRandomKeyReturningState(t, ethKeyStore) t.Run("no transaction", func(t *testing.T) { - tx, err := txStore.GetTxByID(testutils.Context(t), int64(0)) + tx, err := txStore.GetTxByID(tests.Context(t), int64(0)) require.NoError(t, err) require.Nil(t, tx) }) t.Run("get transaction by ID", func(t *testing.T) { insertedTx := mustInsertInProgressEthTxWithAttempt(t, txStore, 123, fromAddress) - tx, err := txStore.GetTxByID(testutils.Context(t), insertedTx.ID) + tx, err := txStore.GetTxByID(tests.Context(t), insertedTx.ID) require.NoError(t, err) require.NotNil(t, tx) }) @@ -1523,14 +1524,14 @@ func TestORM_GetFatalTransactions(t *testing.T) { _, fromAddress := cltest.MustInsertRandomKeyReturningState(t, ethKeyStore) t.Run("gets 0 fatal eth transactions", func(t *testing.T) { - txes, err := txStore.GetFatalTransactions(testutils.Context(t)) + txes, err := txStore.GetFatalTransactions(tests.Context(t)) require.NoError(t, err) require.Empty(t, txes) }) t.Run("get fatal transactions", func(t *testing.T) { fatalTx := mustInsertFatalErrorEthTx(t, txStore, fromAddress) - txes, err := txStore.GetFatalTransactions(testutils.Context(t)) + txes, err := txStore.GetFatalTransactions(tests.Context(t)) require.NoError(t, err) require.Equal(t, txes[0].ID, fatalTx.ID) }) @@ -1546,7 +1547,7 @@ func TestORM_HasInProgressTransaction(t *testing.T) { _, fromAddress := cltest.MustInsertRandomKeyReturningState(t, ethKeyStore) t.Run("no in progress eth transaction", func(t *testing.T) { - exists, err := txStore.HasInProgressTransaction(testutils.Context(t), fromAddress, ethClient.ConfiguredChainID()) + exists, err := txStore.HasInProgressTransaction(tests.Context(t), fromAddress, ethClient.ConfiguredChainID()) require.NoError(t, err) require.False(t, exists) }) @@ -1554,7 +1555,7 @@ func TestORM_HasInProgressTransaction(t *testing.T) { t.Run("has in progress eth transaction", func(t *testing.T) { mustInsertInProgressEthTxWithAttempt(t, txStore, 123, fromAddress) - exists, err := txStore.HasInProgressTransaction(testutils.Context(t), fromAddress, ethClient.ConfiguredChainID()) + exists, err := txStore.HasInProgressTransaction(tests.Context(t), fromAddress, ethClient.ConfiguredChainID()) require.NoError(t, err) require.True(t, exists) }) @@ -1575,7 +1576,7 @@ func TestORM_CountUnconfirmedTransactions(t *testing.T) { cltest.MustInsertUnconfirmedEthTxWithBroadcastLegacyAttempt(t, txStore, 1, fromAddress) cltest.MustInsertUnconfirmedEthTxWithBroadcastLegacyAttempt(t, txStore, 2, fromAddress) - count, err := txStore.CountUnconfirmedTransactions(testutils.Context(t), fromAddress, &cltest.FixtureChainID) + count, err := txStore.CountUnconfirmedTransactions(tests.Context(t), fromAddress, testutils.FixtureChainID) require.NoError(t, err) assert.Equal(t, int(count), 3) } @@ -1595,7 +1596,7 @@ func TestORM_CountTransactionsByState(t *testing.T) { cltest.MustInsertUnconfirmedEthTxWithBroadcastLegacyAttempt(t, txStore, 1, fromAddress2) cltest.MustInsertUnconfirmedEthTxWithBroadcastLegacyAttempt(t, txStore, 2, fromAddress3) - count, err := txStore.CountTransactionsByState(testutils.Context(t), txmgrcommon.TxUnconfirmed, &cltest.FixtureChainID) + count, err := txStore.CountTransactionsByState(tests.Context(t), txmgrcommon.TxUnconfirmed, testutils.FixtureChainID) require.NoError(t, err) assert.Equal(t, int(count), 3) } @@ -1610,12 +1611,12 @@ func TestORM_CountUnstartedTransactions(t *testing.T) { _, fromAddress := cltest.MustInsertRandomKey(t, ethKeyStore) _, otherAddress := cltest.MustInsertRandomKey(t, ethKeyStore) - mustCreateUnstartedGeneratedTx(t, txStore, fromAddress, &cltest.FixtureChainID) - mustCreateUnstartedGeneratedTx(t, txStore, fromAddress, &cltest.FixtureChainID) - mustCreateUnstartedGeneratedTx(t, txStore, otherAddress, &cltest.FixtureChainID) + mustCreateUnstartedGeneratedTx(t, txStore, fromAddress, testutils.FixtureChainID) + mustCreateUnstartedGeneratedTx(t, txStore, fromAddress, testutils.FixtureChainID) + mustCreateUnstartedGeneratedTx(t, txStore, otherAddress, testutils.FixtureChainID) cltest.MustInsertUnconfirmedEthTxWithBroadcastLegacyAttempt(t, txStore, 2, fromAddress) - count, err := txStore.CountUnstartedTransactions(testutils.Context(t), fromAddress, &cltest.FixtureChainID) + count, err := txStore.CountUnstartedTransactions(tests.Context(t), fromAddress, testutils.FixtureChainID) require.NoError(t, err) assert.Equal(t, int(count), 2) } @@ -1637,17 +1638,17 @@ func TestORM_CheckTxQueueCapacity(t *testing.T) { var maxUnconfirmedTransactions uint64 = 2 t.Run("with no eth_txes returns nil", func(t *testing.T) { - err := txStore.CheckTxQueueCapacity(testutils.Context(t), fromAddress, maxUnconfirmedTransactions, &cltest.FixtureChainID) + err := txStore.CheckTxQueueCapacity(tests.Context(t), fromAddress, maxUnconfirmedTransactions, testutils.FixtureChainID) require.NoError(t, err) }) // deliberately one extra to exceed limit for i := 0; i <= int(maxUnconfirmedTransactions); i++ { - mustCreateUnstartedTx(t, txStore, otherAddress, toAddress, encodedPayload, feeLimit, value, &cltest.FixtureChainID) + mustCreateUnstartedTx(t, txStore, otherAddress, toAddress, encodedPayload, feeLimit, value, testutils.FixtureChainID) } t.Run("with eth_txes from another address returns nil", func(t *testing.T) { - err := txStore.CheckTxQueueCapacity(testutils.Context(t), fromAddress, maxUnconfirmedTransactions, &cltest.FixtureChainID) + err := txStore.CheckTxQueueCapacity(tests.Context(t), fromAddress, maxUnconfirmedTransactions, testutils.FixtureChainID) require.NoError(t, err) }) @@ -1656,7 +1657,7 @@ func TestORM_CheckTxQueueCapacity(t *testing.T) { } t.Run("ignores fatally_errored transactions", func(t *testing.T) { - err := txStore.CheckTxQueueCapacity(testutils.Context(t), fromAddress, maxUnconfirmedTransactions, &cltest.FixtureChainID) + err := txStore.CheckTxQueueCapacity(tests.Context(t), fromAddress, maxUnconfirmedTransactions, testutils.FixtureChainID) require.NoError(t, err) }) @@ -1667,7 +1668,7 @@ func TestORM_CheckTxQueueCapacity(t *testing.T) { n++ t.Run("unconfirmed and in_progress transactions do not count", func(t *testing.T) { - err := txStore.CheckTxQueueCapacity(testutils.Context(t), fromAddress, 1, &cltest.FixtureChainID) + err := txStore.CheckTxQueueCapacity(tests.Context(t), fromAddress, 1, testutils.FixtureChainID) require.NoError(t, err) }) @@ -1678,39 +1679,39 @@ func TestORM_CheckTxQueueCapacity(t *testing.T) { } t.Run("with many confirmed eth_txes from the same address returns nil", func(t *testing.T) { - err := txStore.CheckTxQueueCapacity(testutils.Context(t), fromAddress, maxUnconfirmedTransactions, &cltest.FixtureChainID) + err := txStore.CheckTxQueueCapacity(tests.Context(t), fromAddress, maxUnconfirmedTransactions, testutils.FixtureChainID) require.NoError(t, err) }) for i := 0; i < int(maxUnconfirmedTransactions)-1; i++ { - mustCreateUnstartedTx(t, txStore, fromAddress, toAddress, encodedPayload, feeLimit, value, &cltest.FixtureChainID) + mustCreateUnstartedTx(t, txStore, fromAddress, toAddress, encodedPayload, feeLimit, value, testutils.FixtureChainID) } t.Run("with fewer unstarted eth_txes than limit returns nil", func(t *testing.T) { - err := txStore.CheckTxQueueCapacity(testutils.Context(t), fromAddress, maxUnconfirmedTransactions, &cltest.FixtureChainID) + err := txStore.CheckTxQueueCapacity(tests.Context(t), fromAddress, maxUnconfirmedTransactions, testutils.FixtureChainID) require.NoError(t, err) }) - mustCreateUnstartedTx(t, txStore, fromAddress, toAddress, encodedPayload, feeLimit, value, &cltest.FixtureChainID) + mustCreateUnstartedTx(t, txStore, fromAddress, toAddress, encodedPayload, feeLimit, value, testutils.FixtureChainID) t.Run("with equal or more unstarted eth_txes than limit returns error", func(t *testing.T) { - err := txStore.CheckTxQueueCapacity(testutils.Context(t), fromAddress, maxUnconfirmedTransactions, &cltest.FixtureChainID) + err := txStore.CheckTxQueueCapacity(tests.Context(t), fromAddress, maxUnconfirmedTransactions, testutils.FixtureChainID) require.Error(t, err) require.Contains(t, err.Error(), fmt.Sprintf("cannot create transaction; too many unstarted transactions in the queue (2/%d). WARNING: Hitting EVM.Transactions.MaxQueued", maxUnconfirmedTransactions)) - mustCreateUnstartedTx(t, txStore, fromAddress, toAddress, encodedPayload, feeLimit, value, &cltest.FixtureChainID) - err = txStore.CheckTxQueueCapacity(testutils.Context(t), fromAddress, maxUnconfirmedTransactions, &cltest.FixtureChainID) + mustCreateUnstartedTx(t, txStore, fromAddress, toAddress, encodedPayload, feeLimit, value, testutils.FixtureChainID) + err = txStore.CheckTxQueueCapacity(tests.Context(t), fromAddress, maxUnconfirmedTransactions, testutils.FixtureChainID) require.Error(t, err) require.Contains(t, err.Error(), fmt.Sprintf("cannot create transaction; too many unstarted transactions in the queue (3/%d). WARNING: Hitting EVM.Transactions.MaxQueued", maxUnconfirmedTransactions)) }) t.Run("with different chain ID ignores txes", func(t *testing.T) { - err := txStore.CheckTxQueueCapacity(testutils.Context(t), fromAddress, maxUnconfirmedTransactions, big.NewInt(42)) + err := txStore.CheckTxQueueCapacity(tests.Context(t), fromAddress, maxUnconfirmedTransactions, big.NewInt(42)) require.NoError(t, err) }) t.Run("disables check with 0 limit", func(t *testing.T) { - err := txStore.CheckTxQueueCapacity(testutils.Context(t), fromAddress, 0, &cltest.FixtureChainID) + err := txStore.CheckTxQueueCapacity(tests.Context(t), fromAddress, 0, testutils.FixtureChainID) require.NoError(t, err) }) } @@ -1733,7 +1734,7 @@ func TestORM_CreateTransaction(t *testing.T) { subject := uuid.New() strategy := newMockTxStrategy(t) strategy.On("Subject").Return(uuid.NullUUID{UUID: subject, Valid: true}) - etx, err := txStore.CreateTransaction(testutils.Context(t), txmgr.TxRequest{ + etx, err := txStore.CreateTransaction(tests.Context(t), txmgr.TxRequest{ FromAddress: fromAddress, ToAddress: toAddress, EncodedPayload: payload, @@ -1776,10 +1777,10 @@ func TestORM_CreateTransaction(t *testing.T) { PipelineTaskRunID: &id, Strategy: txmgrcommon.NewSendEveryStrategy(), } - tx1, err := txStore.CreateTransaction(testutils.Context(t), txRequest, ethClient.ConfiguredChainID()) + tx1, err := txStore.CreateTransaction(tests.Context(t), txRequest, ethClient.ConfiguredChainID()) assert.NoError(t, err) - tx2, err := txStore.CreateTransaction(testutils.Context(t), txRequest, ethClient.ConfiguredChainID()) + tx2, err := txStore.CreateTransaction(tests.Context(t), txRequest, ethClient.ConfiguredChainID()) assert.NoError(t, err) assert.Equal(t, tx1.GetID(), tx2.GetID()) @@ -1789,7 +1790,7 @@ func TestORM_CreateTransaction(t *testing.T) { subject := uuid.New() strategy := newMockTxStrategy(t) strategy.On("Subject").Return(uuid.NullUUID{UUID: subject, Valid: true}) - etx, err := txStore.CreateTransaction(testutils.Context(t), txmgr.TxRequest{ + etx, err := txStore.CreateTransaction(tests.Context(t), txmgr.TxRequest{ FromAddress: fromAddress, ToAddress: toAddress, EncodedPayload: payload, @@ -1827,7 +1828,7 @@ func TestORM_PruneUnstartedTxQueue(t *testing.T) { subject1 := uuid.New() strategy1 := txmgrcommon.NewDropOldestStrategy(subject1, uint32(5)) for i := 0; i < 5; i++ { - mustCreateUnstartedGeneratedTx(t, txStore, fromAddress, &cltest.FixtureChainID, txRequestWithStrategy(strategy1)) + mustCreateUnstartedGeneratedTx(t, txStore, fromAddress, testutils.FixtureChainID, txRequestWithStrategy(strategy1)) } AssertCountPerSubject(t, txStore, int64(4), subject1) }) @@ -1836,7 +1837,7 @@ func TestORM_PruneUnstartedTxQueue(t *testing.T) { subject2 := uuid.New() strategy2 := txmgrcommon.NewDropOldestStrategy(subject2, uint32(3)) for i := 0; i < 5; i++ { - mustCreateUnstartedGeneratedTx(t, txStore, fromAddress, &cltest.FixtureChainID, txRequestWithStrategy(strategy2)) + mustCreateUnstartedGeneratedTx(t, txStore, fromAddress, testutils.FixtureChainID, txRequestWithStrategy(strategy2)) } AssertCountPerSubject(t, txStore, int64(2), subject2) }) @@ -1848,7 +1849,7 @@ func TestORM_FindTxesWithAttemptsAndReceiptsByIdsAndState(t *testing.T) { db := pgtest.NewSqlxDB(t) txStore := cltest.NewTestTxStore(t, db) ethKeyStore := cltest.NewKeyStore(t, db).Eth() - ctx := testutils.Context(t) + ctx := tests.Context(t) _, from := cltest.MustInsertRandomKey(t, ethKeyStore) @@ -1866,7 +1867,7 @@ func TestORM_FindTxesWithAttemptsAndReceiptsByIdsAndState(t *testing.T) { func AssertCountPerSubject(t *testing.T, txStore txmgr.TestEvmTxStore, expected int64, subject uuid.UUID) { t.Helper() - count, err := txStore.CountTxesByStateAndSubject(testutils.Context(t), "unstarted", subject) + count, err := txStore.CountTxesByStateAndSubject(tests.Context(t), "unstarted", subject) require.NoError(t, err) require.Equal(t, int(expected), count) } diff --git a/core/chains/evm/txmgr/nonce_tracker_test.go b/core/chains/evm/txmgr/nonce_tracker_test.go index 17c042e375e..c9e3cbd76c3 100644 --- a/core/chains/evm/txmgr/nonce_tracker_test.go +++ b/core/chains/evm/txmgr/nonce_tracker_test.go @@ -13,12 +13,12 @@ import ( "github.com/smartcontractkit/chainlink-common/pkg/logger" "github.com/smartcontractkit/chainlink-common/pkg/services" + "github.com/smartcontractkit/chainlink-common/pkg/utils/tests" clientmock "github.com/smartcontractkit/chainlink/v2/core/chains/evm/client/mocks" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/txmgr" txstoremock "github.com/smartcontractkit/chainlink/v2/core/chains/evm/txmgr/mocks" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/types" - "github.com/smartcontractkit/chainlink/v2/core/internal/cltest" "github.com/smartcontractkit/chainlink/v2/core/internal/testutils" "github.com/smartcontractkit/chainlink/v2/core/internal/testutils/pgtest" ) @@ -26,7 +26,7 @@ import ( func TestNonceTracker_LoadSequenceMap(t *testing.T) { t.Parallel() - ctx := testutils.Context(t) + ctx := tests.Context(t) chainID := big.NewInt(0) txStore := txstoremock.NewEvmTxStore(t) @@ -77,7 +77,7 @@ func TestNonceTracker_LoadSequenceMap(t *testing.T) { func TestNonceTracker_syncOnChain(t *testing.T) { t.Parallel() - ctx := testutils.Context(t) + ctx := tests.Context(t) chainID := big.NewInt(0) txStore := txstoremock.NewEvmTxStore(t) @@ -133,7 +133,7 @@ func TestNonceTracker_syncOnChain(t *testing.T) { func TestNonceTracker_SyncSequence(t *testing.T) { t.Parallel() - ctx := testutils.Context(t) + ctx := tests.Context(t) chainID := big.NewInt(0) txStore := txstoremock.NewEvmTxStore(t) @@ -180,7 +180,7 @@ func TestNonceTracker_SyncSequence(t *testing.T) { func TestNonceTracker_GetNextSequence(t *testing.T) { t.Parallel() - ctx := testutils.Context(t) + ctx := tests.Context(t) chainID := big.NewInt(0) txStore := txstoremock.NewEvmTxStore(t) @@ -230,7 +230,7 @@ func TestNonceTracker_GetNextSequence(t *testing.T) { func TestNonceTracker_GenerateNextSequence(t *testing.T) { t.Parallel() - ctx := testutils.Context(t) + ctx := tests.Context(t) chainID := big.NewInt(0) txStore := txstoremock.NewEvmTxStore(t) @@ -259,10 +259,10 @@ func TestNonceTracker_GenerateNextSequence(t *testing.T) { func Test_SetNonceAfterInit(t *testing.T) { t.Parallel() - ctx := testutils.Context(t) + ctx := tests.Context(t) chainID := big.NewInt(0) db := pgtest.NewSqlxDB(t) - txStore := cltest.NewTestTxStore(t, db) + txStore := txmgr.NewTxStore(db, logger.Test(t)) client := clientmock.NewClient(t) client.On("ConfiguredChainID").Return(chainID) diff --git a/core/chains/evm/txmgr/resender_test.go b/core/chains/evm/txmgr/resender_test.go index 331e39d6ccf..48a1ec3af16 100644 --- a/core/chains/evm/txmgr/resender_test.go +++ b/core/chains/evm/txmgr/resender_test.go @@ -15,15 +15,14 @@ import ( commonconfig "github.com/smartcontractkit/chainlink-common/pkg/config" "github.com/smartcontractkit/chainlink-common/pkg/logger" + "github.com/smartcontractkit/chainlink-common/pkg/utils/tests" + "github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/toml" + "github.com/smartcontractkit/chainlink/v2/core/chains/evm/testutils" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/txmgr" ubig "github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils/big" "github.com/smartcontractkit/chainlink/v2/core/internal/cltest" - "github.com/smartcontractkit/chainlink/v2/core/internal/testutils" - "github.com/smartcontractkit/chainlink/v2/core/internal/testutils/configtest" - "github.com/smartcontractkit/chainlink/v2/core/internal/testutils/evmtest" "github.com/smartcontractkit/chainlink/v2/core/internal/testutils/pgtest" - "github.com/smartcontractkit/chainlink/v2/core/services/chainlink" ) func Test_EthResender_resendUnconfirmed(t *testing.T) { @@ -32,9 +31,9 @@ func Test_EthResender_resendUnconfirmed(t *testing.T) { db := pgtest.NewSqlxDB(t) lggr := logger.Test(t) ethKeyStore := cltest.NewKeyStore(t, db).Eth() - ethClient := evmtest.NewEthClientMockWithDefaultChain(t) - cfg := configtest.NewGeneralConfig(t, func(c *chainlink.Config, s *chainlink.Secrets) {}) - ccfg := evmtest.NewChainScopedConfig(t, cfg) + ethClient := testutils.NewEthClientMockWithDefaultChain(t) + ethClient.On("IsL2").Return(false).Maybe() + ccfg := testutils.NewTestChainScopedConfig(t, nil) _, fromAddress := cltest.MustInsertRandomKey(t, ethKeyStore) _, fromAddress2 := cltest.MustInsertRandomKey(t, ethKeyStore) @@ -102,17 +101,15 @@ func Test_EthResender_alertUnconfirmed(t *testing.T) { db := pgtest.NewSqlxDB(t) lggr, o := logger.TestObserved(t, zapcore.DebugLevel) ethKeyStore := cltest.NewKeyStore(t, db).Eth() - ethClient := evmtest.NewEthClientMockWithDefaultChain(t) + ethClient := testutils.NewEthClientMockWithDefaultChain(t) + ethClient.On("IsL2").Return(false).Maybe() // Set this to the smallest non-zero value possible for the attempt to be eligible for resend delay := commonconfig.MustNewDuration(1 * time.Nanosecond) - cfg := configtest.NewGeneralConfig(t, func(c *chainlink.Config, s *chainlink.Secrets) { - c.EVM[0] = &toml.EVMConfig{ - Chain: toml.Defaults(ubig.New(big.NewInt(0)), &toml.Chain{ - Transactions: toml.Transactions{ResendAfterThreshold: delay}, - }), - } + ccfg := testutils.NewTestChainScopedConfig(t, func(c *toml.EVMConfig) { + c.Chain = toml.Defaults(ubig.New(big.NewInt(0)), &toml.Chain{ + Transactions: toml.Transactions{ResendAfterThreshold: delay}, + }) }) - ccfg := evmtest.NewChainScopedConfig(t, cfg) _, fromAddress := cltest.MustInsertRandomKey(t, ethKeyStore) @@ -132,7 +129,7 @@ func Test_EthResender_alertUnconfirmed(t *testing.T) { err2 := er.XXXTestResendUnconfirmed() require.NoError(t, err2) - testutils.WaitForLogMessageCount(t, o, "TxAttempt has been unconfirmed for more than max duration", 1) + tests.AssertLogCountEventually(t, o, "TxAttempt has been unconfirmed for more than max duration", 1) }) } @@ -140,21 +137,22 @@ func Test_EthResender_Start(t *testing.T) { t.Parallel() db := pgtest.NewSqlxDB(t) - cfg := configtest.NewGeneralConfig(t, func(c *chainlink.Config, s *chainlink.Secrets) { + ccfg := testutils.NewTestChainScopedConfig(t, func(c *toml.EVMConfig) { // This can be anything as long as it isn't zero - c.EVM[0].Transactions.ResendAfterThreshold = commonconfig.MustNewDuration(42 * time.Hour) + c.Transactions.ResendAfterThreshold = commonconfig.MustNewDuration(42 * time.Hour) // Set batch size low to test batching - c.EVM[0].RPCDefaultBatchSize = ptr[uint32](1) + c.RPCDefaultBatchSize = ptr[uint32](1) }) + txStore := cltest.NewTestTxStore(t, db) ethKeyStore := cltest.NewKeyStore(t, db).Eth() - ccfg := evmtest.NewChainScopedConfig(t, cfg) _, fromAddress := cltest.MustInsertRandomKey(t, ethKeyStore) lggr := logger.Test(t) t.Run("resends transactions that have been languishing unconfirmed for too long", func(t *testing.T) { - ctx := testutils.Context(t) - ethClient := evmtest.NewEthClientMockWithDefaultChain(t) + ctx := tests.Context(t) + ethClient := testutils.NewEthClientMockWithDefaultChain(t) + ethClient.On("IsL2").Return(false).Maybe() er := txmgr.NewEvmResender(lggr, txStore, txmgr.NewEvmTxmClient(ethClient, nil), txmgr.NewEvmTracker(txStore, ethKeyStore, big.NewInt(0), lggr), ethKeyStore, 100*time.Millisecond, ccfg.EVM(), ccfg.EVM().Transactions()) diff --git a/core/chains/evm/txmgr/strategies_test.go b/core/chains/evm/txmgr/strategies_test.go index d7f4ceaf450..4b04009fd24 100644 --- a/core/chains/evm/txmgr/strategies_test.go +++ b/core/chains/evm/txmgr/strategies_test.go @@ -8,9 +8,10 @@ import ( "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" + "github.com/smartcontractkit/chainlink-common/pkg/utils/tests" + txmgrcommon "github.com/smartcontractkit/chainlink/v2/common/txmgr" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/txmgr/mocks" - "github.com/smartcontractkit/chainlink/v2/core/internal/testutils" ) func Test_SendEveryStrategy(t *testing.T) { @@ -20,7 +21,7 @@ func Test_SendEveryStrategy(t *testing.T) { assert.Equal(t, uuid.NullUUID{}, s.Subject()) - ids, err := s.PruneQueue(testutils.Context(t), nil) + ids, err := s.PruneQueue(tests.Context(t), nil) assert.NoError(t, err) assert.Len(t, ids, 0) } @@ -44,7 +45,7 @@ func Test_DropOldestStrategy_PruneQueue(t *testing.T) { t.Run("calls PrineUnstartedTxQueue for the given subject and queueSize, ignoring fromAddress", func(t *testing.T) { strategy1 := txmgrcommon.NewDropOldestStrategy(subject, queueSize) mockTxStore.On("PruneUnstartedTxQueue", mock.Anything, queueSize-1, subject, mock.Anything, mock.Anything).Once().Return([]int64{1, 2}, nil) - ids, err := strategy1.PruneQueue(testutils.Context(t), mockTxStore) + ids, err := strategy1.PruneQueue(tests.Context(t), mockTxStore) require.NoError(t, err) assert.Equal(t, []int64{1, 2}, ids) }) diff --git a/core/chains/evm/txmgr/stuck_tx_detector_test.go b/core/chains/evm/txmgr/stuck_tx_detector_test.go index 39c275d286f..02d34206ab9 100644 --- a/core/chains/evm/txmgr/stuck_tx_detector_test.go +++ b/core/chains/evm/txmgr/stuck_tx_detector_test.go @@ -16,17 +16,18 @@ import ( "gopkg.in/guregu/null.v4" "github.com/smartcontractkit/chainlink-common/pkg/logger" + "github.com/smartcontractkit/chainlink-common/pkg/utils/tests" + commonconfig "github.com/smartcontractkit/chainlink/v2/common/config" txmgrcommon "github.com/smartcontractkit/chainlink/v2/common/txmgr" txmgrtypes "github.com/smartcontractkit/chainlink/v2/common/txmgr/types" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/gas" gasmocks "github.com/smartcontractkit/chainlink/v2/core/chains/evm/gas/mocks" + "github.com/smartcontractkit/chainlink/v2/core/chains/evm/testutils" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/txmgr" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/types" "github.com/smartcontractkit/chainlink/v2/core/internal/cltest" - "github.com/smartcontractkit/chainlink/v2/core/internal/testutils" - "github.com/smartcontractkit/chainlink/v2/core/internal/testutils/evmtest" "github.com/smartcontractkit/chainlink/v2/core/internal/testutils/pgtest" ) @@ -44,7 +45,7 @@ func TestStuckTxDetector_Disabled(t *testing.T) { _, fromAddress := cltest.MustInsertRandomKey(t, ethKeyStore) lggr := logger.Test(t) - ethClient := evmtest.NewEthClientMockWithDefaultChain(t) + ethClient := testutils.NewEthClientMockWithDefaultChain(t) feeEstimator := gasmocks.NewEvmFeeEstimator(t) autoPurgeCfg := testAutoPurgeConfig{ enabled: false, @@ -52,7 +53,7 @@ func TestStuckTxDetector_Disabled(t *testing.T) { stuckTxDetector := txmgr.NewStuckTxDetector(lggr, testutils.FixtureChainID, "", assets.NewWei(assets.NewEth(100).ToInt()), autoPurgeCfg, feeEstimator, txStore, ethClient) t.Run("returns empty list if auto-purge feature is disabled", func(t *testing.T) { - txs, err := stuckTxDetector.DetectStuckTransactions(testutils.Context(t), []common.Address{fromAddress}, 100) + txs, err := stuckTxDetector.DetectStuckTransactions(tests.Context(t), []common.Address{fromAddress}, 100) require.NoError(t, err) require.Len(t, txs, 0) }) @@ -64,11 +65,11 @@ func TestStuckTxDetector_LoadPurgeBlockNumMap(t *testing.T) { db := pgtest.NewSqlxDB(t) txStore := cltest.NewTestTxStore(t, db) ethKeyStore := cltest.NewKeyStore(t, db).Eth() - ctx := testutils.Context(t) + ctx := tests.Context(t) blockNum := int64(100) lggr := logger.Test(t) - ethClient := evmtest.NewEthClientMockWithDefaultChain(t) + ethClient := testutils.NewEthClientMockWithDefaultChain(t) feeEstimator := gasmocks.NewEvmFeeEstimator(t) marketGasPrice := assets.GWei(15) fee := gas.EvmFee{Legacy: marketGasPrice} @@ -109,10 +110,10 @@ func TestStuckTxDetector_FindPotentialStuckTxs(t *testing.T) { _, config := newTestChainScopedConfig(t) txStore := cltest.NewTestTxStore(t, db) ethKeyStore := cltest.NewKeyStore(t, db).Eth() - ctx := testutils.Context(t) + ctx := tests.Context(t) lggr := logger.Test(t) - ethClient := evmtest.NewEthClientMockWithDefaultChain(t) + ethClient := testutils.NewEthClientMockWithDefaultChain(t) feeEstimator := gasmocks.NewEvmFeeEstimator(t) stuckTxDetector := txmgr.NewStuckTxDetector(lggr, testutils.FixtureChainID, "", assets.NewWei(assets.NewEth(100).ToInt()), config.EVM().Transactions().AutoPurge(), feeEstimator, txStore, ethClient) @@ -162,7 +163,7 @@ func TestStuckTxDetector_DetectStuckTransactionsHeuristic(t *testing.T) { db := pgtest.NewSqlxDB(t) txStore := cltest.NewTestTxStore(t, db) ethKeyStore := cltest.NewKeyStore(t, db).Eth() - ctx := testutils.Context(t) + ctx := tests.Context(t) lggr := logger.Test(t) feeEstimator := gasmocks.NewEvmFeeEstimator(t) @@ -170,7 +171,7 @@ func TestStuckTxDetector_DetectStuckTransactionsHeuristic(t *testing.T) { marketGasPrice := tenGwei fee := gas.EvmFee{Legacy: marketGasPrice} feeEstimator.On("GetFee", mock.Anything, []byte{}, uint64(0), mock.Anything).Return(fee, uint64(0), nil) - ethClient := evmtest.NewEthClientMockWithDefaultChain(t) + ethClient := testutils.NewEthClientMockWithDefaultChain(t) autoPurgeThreshold := uint32(5) autoPurgeMinAttempts := uint32(3) autoPurgeCfg := testAutoPurgeConfig{ @@ -261,11 +262,11 @@ func TestStuckTxDetector_DetectStuckTransactionsZkEVM(t *testing.T) { db := pgtest.NewSqlxDB(t) txStore := cltest.NewTestTxStore(t, db) ethKeyStore := cltest.NewKeyStore(t, db).Eth() - ctx := testutils.Context(t) + ctx := tests.Context(t) lggr := logger.Test(t) feeEstimator := gasmocks.NewEvmFeeEstimator(t) - ethClient := evmtest.NewEthClientMockWithDefaultChain(t) + ethClient := testutils.NewEthClientMockWithDefaultChain(t) autoPurgeCfg := testAutoPurgeConfig{ enabled: true, } @@ -323,11 +324,11 @@ func TestStuckTxDetector_DetectStuckTransactionsScroll(t *testing.T) { db := pgtest.NewSqlxDB(t) txStore := cltest.NewTestTxStore(t, db) ethKeyStore := cltest.NewKeyStore(t, db).Eth() - ctx := testutils.Context(t) + ctx := tests.Context(t) lggr := logger.Test(t) feeEstimator := gasmocks.NewEvmFeeEstimator(t) - ethClient := evmtest.NewEthClientMockWithDefaultChain(t) + ethClient := testutils.NewEthClientMockWithDefaultChain(t) blockNum := int64(100) t.Run("returns stuck tx identified using the custom scroll API", func(t *testing.T) { @@ -363,7 +364,7 @@ func TestStuckTxDetector_DetectStuckTransactionsScroll(t *testing.T) { } func mustInsertUnconfirmedTxWithBroadcastAttempts(t *testing.T, txStore txmgr.TestEvmTxStore, nonce int64, fromAddress common.Address, numAttempts uint32, latestBroadcastBlockNum int64, latestGasPrice *assets.Wei) txmgr.Tx { - ctx := testutils.Context(t) + ctx := tests.Context(t) etx := cltest.MustInsertUnconfirmedEthTx(t, txStore, nonce, fromAddress) // Insert attempts from oldest to newest for i := int64(numAttempts - 1); i >= 0; i-- { @@ -390,10 +391,10 @@ func mustInsertFatalErrorTxWithError(t *testing.T, txStore txmgr.TestEvmTxStore, n := types.Nonce(nonce) etx.Sequence = &n etx.ChainID = testutils.FixtureChainID - require.NoError(t, txStore.InsertTx(testutils.Context(t), &etx)) + require.NoError(t, txStore.InsertTx(tests.Context(t), &etx)) attempt := cltest.NewLegacyEthTxAttempt(t, etx.ID) - ctx := testutils.Context(t) + ctx := tests.Context(t) attempt.State = txmgrtypes.TxAttemptBroadcast attempt.IsPurgeAttempt = true require.NoError(t, txStore.InsertTxAttempt(ctx, &attempt)) @@ -410,7 +411,7 @@ func mustInsertFatalErrorTxWithError(t *testing.T, txStore txmgr.TestEvmTxStore, func mustInsertUnconfirmedEthTxWithBroadcastPurgeAttempt(t *testing.T, txStore txmgr.TestEvmTxStore, nonce int64, fromAddress common.Address) txmgr.Tx { etx := cltest.MustInsertUnconfirmedEthTx(t, txStore, nonce, fromAddress) attempt := cltest.NewLegacyEthTxAttempt(t, etx.ID) - ctx := testutils.Context(t) + ctx := tests.Context(t) attempt.State = txmgrtypes.TxAttemptBroadcast attempt.IsPurgeAttempt = true diff --git a/core/chains/evm/txmgr/tracker_test.go b/core/chains/evm/txmgr/tracker_test.go index a0503253591..904a10d48c3 100644 --- a/core/chains/evm/txmgr/tracker_test.go +++ b/core/chains/evm/txmgr/tracker_test.go @@ -5,17 +5,18 @@ import ( "testing" "time" + "github.com/ethereum/go-ethereum/common" + "github.com/stretchr/testify/require" + + "github.com/smartcontractkit/chainlink-common/pkg/logger" + "github.com/smartcontractkit/chainlink-common/pkg/utils/tests" + "github.com/smartcontractkit/chainlink/v2/core/chains/evm/keystore" + "github.com/smartcontractkit/chainlink/v2/core/chains/evm/testutils" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/txmgr" ubig "github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils/big" "github.com/smartcontractkit/chainlink/v2/core/internal/cltest" - "github.com/smartcontractkit/chainlink/v2/core/internal/testutils" - "github.com/smartcontractkit/chainlink/v2/core/internal/testutils/evmtest" "github.com/smartcontractkit/chainlink/v2/core/internal/testutils/pgtest" - "github.com/smartcontractkit/chainlink/v2/core/logger" - - "github.com/ethereum/go-ethereum/common" - "github.com/stretchr/testify/require" ) const waitTime = 5 * time.Millisecond @@ -29,7 +30,7 @@ func newTestEvmTrackerSetup(t *testing.T) (*txmgr.Tracker, txmgr.TestEvmTxStore, _, addr1 := cltest.MustInsertRandomKey(t, ethKeyStore, *ubig.NewI(chainID.Int64())) _, addr2 := cltest.MustInsertRandomKey(t, ethKeyStore, *ubig.NewI(chainID.Int64())) enabledAddresses = append(enabledAddresses, addr1, addr2) - lggr := logger.TestLogger(t) + lggr := logger.Test(t) return txmgr.NewEvmTracker(txStore, ethKeyStore, chainID, lggr), txStore, ethKeyStore, enabledAddresses } @@ -46,7 +47,7 @@ func TestEvmTracker_Initialization(t *testing.T) { t.Parallel() tracker, _, _, _ := newTestEvmTrackerSetup(t) - ctx := testutils.Context(t) + ctx := tests.Context(t) require.NoError(t, tracker.Start(ctx)) require.True(t, tracker.IsStarted()) @@ -59,10 +60,10 @@ func TestEvmTracker_Initialization(t *testing.T) { func TestEvmTracker_AddressTracking(t *testing.T) { t.Parallel() - ctx := testutils.Context(t) + ctx := tests.Context(t) t.Run("track abandoned addresses", func(t *testing.T) { - ethClient := evmtest.NewEthClientMockWithDefaultChain(t) + ethClient := testutils.NewEthClientMockWithDefaultChain(t) tracker, txStore, _, _ := newTestEvmTrackerSetup(t) inProgressAddr := cltest.MustGenerateRandomKey(t).Address unstartedAddr := cltest.MustGenerateRandomKey(t).Address @@ -119,7 +120,7 @@ func TestEvmTracker_AddressTracking(t *testing.T) { func TestEvmTracker_ExceedingTTL(t *testing.T) { t.Parallel() - ctx := testutils.Context(t) + ctx := tests.Context(t) t.Run("exceeding ttl", func(t *testing.T) { tracker, txStore, _, _ := newTestEvmTrackerSetup(t) diff --git a/core/chains/evm/txmgr/transmitchecker_test.go b/core/chains/evm/txmgr/transmitchecker_test.go index 2fce9cf7aac..af41bbfdaa6 100644 --- a/core/chains/evm/txmgr/transmitchecker_test.go +++ b/core/chains/evm/txmgr/transmitchecker_test.go @@ -14,27 +14,24 @@ import ( "github.com/ethereum/go-ethereum/rpc" pkgerrors "github.com/pkg/errors" "github.com/stretchr/testify/mock" - - "github.com/smartcontractkit/chainlink-common/pkg/logger" - - txmgrtypes "github.com/smartcontractkit/chainlink/v2/common/txmgr/types" - evmtypes "github.com/smartcontractkit/chainlink/v2/core/chains/evm/types" - "github.com/stretchr/testify/require" + "github.com/smartcontractkit/chainlink-common/pkg/logger" "github.com/smartcontractkit/chainlink-common/pkg/sqlutil" + "github.com/smartcontractkit/chainlink-common/pkg/utils/tests" + txmgrcommon "github.com/smartcontractkit/chainlink/v2/common/txmgr" + txmgrtypes "github.com/smartcontractkit/chainlink/v2/common/txmgr/types" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets" evmclient "github.com/smartcontractkit/chainlink/v2/core/chains/evm/client" + "github.com/smartcontractkit/chainlink/v2/core/chains/evm/testutils" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/txmgr" + evmtypes "github.com/smartcontractkit/chainlink/v2/core/chains/evm/types" v1 "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/solidity_vrf_coordinator_interface" - "github.com/smartcontractkit/chainlink/v2/core/internal/cltest" - "github.com/smartcontractkit/chainlink/v2/core/internal/testutils" - "github.com/smartcontractkit/chainlink/v2/core/internal/testutils/evmtest" ) func TestFactory(t *testing.T) { - client := cltest.NewEthMocksWithDefaultChain(t) + client := testutils.NewEthClientMockWithDefaultChain(t) factory := &txmgr.CheckerFactory{Client: client} t.Run("no checker", func(t *testing.T) { @@ -105,9 +102,9 @@ func TestFactory(t *testing.T) { } func TestTransmitCheckers(t *testing.T) { - client := evmtest.NewEthClientMockWithDefaultChain(t) + client := testutils.NewEthClientMockWithDefaultChain(t) log := logger.Sugared(logger.Test(t)) - ctx := testutils.Context(t) + ctx := tests.Context(t) t.Run("no checker", func(t *testing.T) { checker := txmgr.NoChecker diff --git a/core/chains/evm/txmgr/txmgr_test.go b/core/chains/evm/txmgr/txmgr_test.go index b0823c99705..de5847dc715 100644 --- a/core/chains/evm/txmgr/txmgr_test.go +++ b/core/chains/evm/txmgr/txmgr_test.go @@ -23,6 +23,7 @@ import ( "github.com/smartcontractkit/chainlink-common/pkg/logger" "github.com/smartcontractkit/chainlink-common/pkg/services/servicetest" commonutils "github.com/smartcontractkit/chainlink-common/pkg/utils" + "github.com/smartcontractkit/chainlink-common/pkg/utils/tests" txmgrcommon "github.com/smartcontractkit/chainlink/v2/common/txmgr" txmgrtypes "github.com/smartcontractkit/chainlink/v2/common/txmgr/types" @@ -35,12 +36,12 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/chains/evm/keystore" ksmocks "github.com/smartcontractkit/chainlink/v2/core/chains/evm/keystore/mocks" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/logpoller" + "github.com/smartcontractkit/chainlink/v2/core/chains/evm/testutils" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/txmgr" evmtypes "github.com/smartcontractkit/chainlink/v2/core/chains/evm/types" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils" ubig "github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils/big" "github.com/smartcontractkit/chainlink/v2/core/internal/cltest" - "github.com/smartcontractkit/chainlink/v2/core/internal/testutils" "github.com/smartcontractkit/chainlink/v2/core/internal/testutils/configtest" "github.com/smartcontractkit/chainlink/v2/core/internal/testutils/evmtest" "github.com/smartcontractkit/chainlink/v2/core/internal/testutils/pgtest" @@ -93,12 +94,12 @@ func TestTxm_SendNativeToken_DoesNotSendToZero(t *testing.T) { config, dbConfig, evmConfig := txmgr.MakeTestConfigs(t) keyStore := cltest.NewKeyStore(t, db).Eth() - ethClient := evmtest.NewEthClientMockWithDefaultChain(t) + ethClient := testutils.NewEthClientMockWithDefaultChain(t) estimator := gas.NewEstimator(logger.Test(t), ethClient, config, evmConfig.GasEstimator()) txm, err := makeTestEvmTxm(t, db, ethClient, estimator, evmConfig, evmConfig.GasEstimator(), evmConfig.Transactions(), dbConfig, dbConfig.Listener(), keyStore) require.NoError(t, err) - _, err = txm.SendNativeToken(testutils.Context(t), big.NewInt(0), from, to, *value, 21000) + _, err = txm.SendNativeToken(tests.Context(t), big.NewInt(0), from, to, *value, 21000) require.Error(t, err) require.EqualError(t, err, "cannot send native token to zero address") } @@ -117,7 +118,7 @@ func TestTxm_CreateTransaction(t *testing.T) { config, dbConfig, evmConfig := txmgr.MakeTestConfigs(t) - ethClient := evmtest.NewEthClientMockWithDefaultChain(t) + ethClient := testutils.NewEthClientMockWithDefaultChain(t) estimator := gas.NewEstimator(logger.Test(t), ethClient, config, evmConfig.GasEstimator()) txm, err := makeTestEvmTxm(t, db, ethClient, estimator, evmConfig, evmConfig.GasEstimator(), evmConfig.Transactions(), dbConfig, dbConfig.Listener(), kst.Eth()) @@ -129,7 +130,7 @@ func TestTxm_CreateTransaction(t *testing.T) { strategy.On("Subject").Return(uuid.NullUUID{UUID: subject, Valid: true}) strategy.On("PruneQueue", mock.Anything, mock.Anything).Return(nil, nil) evmConfig.MaxQueued = uint64(1) - etx, err := txm.CreateTransaction(testutils.Context(t), txmgr.TxRequest{ + etx, err := txm.CreateTransaction(tests.Context(t), txmgr.TxRequest{ FromAddress: fromAddress, ToAddress: toAddress, EncodedPayload: payload, @@ -165,7 +166,7 @@ func TestTxm_CreateTransaction(t *testing.T) { t.Run("with queue at capacity does not insert eth_tx", func(t *testing.T) { evmConfig.MaxQueued = uint64(1) - _, err := txm.CreateTransaction(testutils.Context(t), txmgr.TxRequest{ + _, err := txm.CreateTransaction(tests.Context(t), txmgr.TxRequest{ FromAddress: fromAddress, ToAddress: testutils.NewAddress(), EncodedPayload: []byte{1, 2, 3}, @@ -180,7 +181,7 @@ func TestTxm_CreateTransaction(t *testing.T) { t.Run("doesn't insert eth_tx if a matching tx already exists for that pipeline_task_run_id", func(t *testing.T) { evmConfig.MaxQueued = uint64(3) id := uuid.New() - tx1, err := txm.CreateTransaction(testutils.Context(t), txmgr.TxRequest{ + tx1, err := txm.CreateTransaction(tests.Context(t), txmgr.TxRequest{ FromAddress: fromAddress, ToAddress: testutils.NewAddress(), EncodedPayload: []byte{1, 2, 3}, @@ -190,7 +191,7 @@ func TestTxm_CreateTransaction(t *testing.T) { }) assert.NoError(t, err) - tx2, err := txm.CreateTransaction(testutils.Context(t), txmgr.TxRequest{ + tx2, err := txm.CreateTransaction(tests.Context(t), txmgr.TxRequest{ FromAddress: fromAddress, ToAddress: testutils.NewAddress(), EncodedPayload: []byte{1, 2, 3}, @@ -205,7 +206,7 @@ func TestTxm_CreateTransaction(t *testing.T) { t.Run("returns error if eth key state is missing or doesn't match chain ID", func(t *testing.T) { rndAddr := testutils.NewAddress() - _, err := txm.CreateTransaction(testutils.Context(t), txmgr.TxRequest{ + _, err := txm.CreateTransaction(tests.Context(t), txmgr.TxRequest{ FromAddress: rndAddr, ToAddress: testutils.NewAddress(), EncodedPayload: []byte{1, 2, 3}, @@ -217,7 +218,7 @@ func TestTxm_CreateTransaction(t *testing.T) { _, otherAddress := cltest.MustInsertRandomKey(t, kst.Eth(), *ubig.NewI(1337)) - _, err = txm.CreateTransaction(testutils.Context(t), txmgr.TxRequest{ + _, err = txm.CreateTransaction(tests.Context(t), txmgr.TxRequest{ FromAddress: otherAddress, ToAddress: testutils.NewAddress(), EncodedPayload: []byte{1, 2, 3}, @@ -235,7 +236,7 @@ func TestTxm_CreateTransaction(t *testing.T) { CheckerType: txmgr.TransmitCheckerTypeSimulate, } evmConfig.MaxQueued = uint64(1) - etx, err := txm.CreateTransaction(testutils.Context(t), txmgr.TxRequest{ + etx, err := txm.CreateTransaction(tests.Context(t), txmgr.TxRequest{ FromAddress: fromAddress, ToAddress: toAddress, EncodedPayload: payload, @@ -278,7 +279,7 @@ func TestTxm_CreateTransaction(t *testing.T) { CheckerType: txmgr.TransmitCheckerTypeVRFV2, VRFCoordinatorAddress: testutils.NewAddressPtr(), } - etx, err := txm.CreateTransaction(testutils.Context(t), txmgr.TxRequest{ + etx, err := txm.CreateTransaction(tests.Context(t), txmgr.TxRequest{ FromAddress: fromAddress, ToAddress: toAddress, EncodedPayload: payload, @@ -310,11 +311,11 @@ func TestTxm_CreateTransaction(t *testing.T) { // Create mock forwarder, mock authorizedsenders call. form := forwarders.NewORM(db) fwdrAddr := testutils.NewAddress() - fwdr, err := form.CreateForwarder(testutils.Context(t), fwdrAddr, ubig.Big(cltest.FixtureChainID)) + fwdr, err := form.CreateForwarder(tests.Context(t), fwdrAddr, ubig.Big(cltest.FixtureChainID)) require.NoError(t, err) require.Equal(t, fwdr.Address, fwdrAddr) - etx, err := txm.CreateTransaction(testutils.Context(t), txmgr.TxRequest{ + etx, err := txm.CreateTransaction(tests.Context(t), txmgr.TxRequest{ FromAddress: fromAddress, ToAddress: toAddress, EncodedPayload: payload, @@ -338,7 +339,7 @@ func TestTxm_CreateTransaction(t *testing.T) { evmConfig.MaxQueued = uint64(3) id := uuid.New() idempotencyKey := "1" - _, err := txm.CreateTransaction(testutils.Context(t), txmgr.TxRequest{ + _, err := txm.CreateTransaction(tests.Context(t), txmgr.TxRequest{ IdempotencyKey: &idempotencyKey, FromAddress: fromAddress, ToAddress: testutils.NewAddress(), @@ -354,7 +355,7 @@ func TestTxm_CreateTransaction(t *testing.T) { evmConfig.MaxQueued = uint64(3) id := uuid.New() idempotencyKey := "2" - tx1, err := txm.CreateTransaction(testutils.Context(t), txmgr.TxRequest{ + tx1, err := txm.CreateTransaction(tests.Context(t), txmgr.TxRequest{ IdempotencyKey: &idempotencyKey, FromAddress: fromAddress, ToAddress: testutils.NewAddress(), @@ -365,7 +366,7 @@ func TestTxm_CreateTransaction(t *testing.T) { }) assert.NoError(t, err) - tx2, err := txm.CreateTransaction(testutils.Context(t), txmgr.TxRequest{ + tx2, err := txm.CreateTransaction(tests.Context(t), txmgr.TxRequest{ IdempotencyKey: &idempotencyKey, FromAddress: fromAddress, ToAddress: testutils.NewAddress(), @@ -399,7 +400,7 @@ func TestTxm_CreateTransaction_OutOfEth(t *testing.T) { config, dbConfig, evmConfig := txmgr.MakeTestConfigs(t) - ethClient := evmtest.NewEthClientMockWithDefaultChain(t) + ethClient := testutils.NewEthClientMockWithDefaultChain(t) estimator := gas.NewEstimator(logger.Test(t), ethClient, config, evmConfig.GasEstimator()) txm, err := makeTestEvmTxm(t, db, ethClient, estimator, evmConfig, evmConfig.GasEstimator(), evmConfig.Transactions(), dbConfig, dbConfig.Listener(), etKeyStore) require.NoError(t, err) @@ -413,7 +414,7 @@ func TestTxm_CreateTransaction_OutOfEth(t *testing.T) { strategy.On("Subject").Return(uuid.NullUUID{}) strategy.On("PruneQueue", mock.Anything, mock.Anything).Return(nil, nil) - etx, err := txm.CreateTransaction(testutils.Context(t), txmgr.TxRequest{ + etx, err := txm.CreateTransaction(tests.Context(t), txmgr.TxRequest{ FromAddress: evmFromAddress, ToAddress: toAddress, EncodedPayload: payload, @@ -437,7 +438,7 @@ func TestTxm_CreateTransaction_OutOfEth(t *testing.T) { strategy.On("Subject").Return(uuid.NullUUID{}) strategy.On("PruneQueue", mock.Anything, mock.Anything).Return(nil, nil) - etx, err := txm.CreateTransaction(testutils.Context(t), txmgr.TxRequest{ + etx, err := txm.CreateTransaction(tests.Context(t), txmgr.TxRequest{ FromAddress: evmFromAddress, ToAddress: toAddress, EncodedPayload: payload, @@ -459,7 +460,7 @@ func TestTxm_CreateTransaction_OutOfEth(t *testing.T) { strategy.On("PruneQueue", mock.Anything, mock.Anything).Return(nil, nil) evmConfig.MaxQueued = uint64(1) - etx, err := txm.CreateTransaction(testutils.Context(t), txmgr.TxRequest{ + etx, err := txm.CreateTransaction(tests.Context(t), txmgr.TxRequest{ FromAddress: evmFromAddress, ToAddress: toAddress, EncodedPayload: payload, @@ -475,7 +476,7 @@ func TestTxm_CreateTransaction_OutOfEth(t *testing.T) { func TestTxm_Lifecycle(t *testing.T) { db := pgtest.NewSqlxDB(t) - ethClient := evmtest.NewEthClientMockWithDefaultChain(t) + ethClient := testutils.NewEthClientMockWithDefaultChain(t) kst := ksmocks.NewEth(t) config, dbConfig, evmConfig := txmgr.MakeTestConfigs(t) @@ -497,13 +498,13 @@ func TestTxm_Lifecycle(t *testing.T) { head := cltest.Head(42) // It should not hang or panic - txm.OnNewLongestChain(testutils.Context(t), head) + txm.OnNewLongestChain(tests.Context(t), head) evmConfig.BumpThreshold = uint64(1) - require.NoError(t, txm.Start(testutils.Context(t))) + require.NoError(t, txm.Start(tests.Context(t))) - ctx, cancel := context.WithTimeout(testutils.Context(t), 5*time.Second) + ctx, cancel := context.WithTimeout(tests.Context(t), 5*time.Second) t.Cleanup(cancel) txm.OnNewLongestChain(ctx, head) require.NoError(t, ctx.Err()) @@ -540,7 +541,7 @@ func TestTxm_Reset(t *testing.T) { cltest.MustInsertConfirmedEthTxWithLegacyAttempt(t, txStore, i, i*42+1, addr2) } - ethClient := evmtest.NewEthClientMockWithDefaultChain(t) + ethClient := testutils.NewEthClientMockWithDefaultChain(t) ethClient.On("HeadByNumber", mock.Anything, (*big.Int)(nil)).Return(nil, nil) ethClient.On("BatchCallContextAll", mock.Anything, mock.Anything).Return(nil).Maybe() ethClient.On("PendingNonceAt", mock.Anything, addr).Return(uint64(128), nil).Maybe() @@ -612,7 +613,7 @@ func newEthReceipt(blockNumber int64, blockHash common.Hash, txHash common.Hash, func mustInsertEthReceipt(t *testing.T, txStore txmgr.TestEvmTxStore, blockNumber int64, blockHash common.Hash, txHash common.Hash) txmgr.Receipt { r := newEthReceipt(blockNumber, blockHash, txHash, 0x1) - id, err := txStore.InsertReceipt(testutils.Context(t), &r.Receipt) + id, err := txStore.InsertReceipt(tests.Context(t), &r.Receipt) require.NoError(t, err) r.ID = id return r @@ -620,7 +621,7 @@ func mustInsertEthReceipt(t *testing.T, txStore txmgr.TestEvmTxStore, blockNumbe func mustInsertRevertedEthReceipt(t *testing.T, txStore txmgr.TestEvmTxStore, blockNumber int64, blockHash common.Hash, txHash common.Hash) txmgr.Receipt { r := newEthReceipt(blockNumber, blockHash, txHash, 0x0) - id, err := txStore.InsertReceipt(testutils.Context(t), &r.Receipt) + id, err := txStore.InsertReceipt(tests.Context(t), &r.Receipt) require.NoError(t, err) r.ID = id return r @@ -641,7 +642,7 @@ func mustInsertConfirmedEthTxBySaveFetchedReceipts(t *testing.T, txStore txmgr.T BlockNumber: big.NewInt(nonce), TransactionIndex: uint(1), } - err := txStore.SaveFetchedReceipts(testutils.Context(t), []*evmtypes.Receipt{&receipt}, txmgrcommon.TxConfirmed, nil, &chainID) + err := txStore.SaveFetchedReceipts(tests.Context(t), []*evmtypes.Receipt{&receipt}, txmgrcommon.TxConfirmed, nil, &chainID) require.NoError(t, err) return etx } @@ -651,14 +652,14 @@ func mustInsertFatalErrorEthTx(t *testing.T, txStore txmgr.TestEvmTxStore, fromA etx.Error = null.StringFrom("something exploded") etx.State = txmgrcommon.TxFatalError - require.NoError(t, txStore.InsertTx(testutils.Context(t), &etx)) + require.NoError(t, txStore.InsertTx(tests.Context(t), &etx)) return etx } func mustInsertUnconfirmedEthTxWithAttemptState(t *testing.T, txStore txmgr.TestEvmTxStore, nonce int64, fromAddress common.Address, txAttemptState txmgrtypes.TxAttemptState, opts ...interface{}) txmgr.Tx { etx := cltest.MustInsertUnconfirmedEthTx(t, txStore, nonce, fromAddress, opts...) attempt := cltest.NewLegacyEthTxAttempt(t, etx.ID) - ctx := testutils.Context(t) + ctx := tests.Context(t) tx := cltest.NewLegacyTransaction(uint64(nonce), testutils.NewAddress(), big.NewInt(142), 242, big.NewInt(342), []byte{1, 2, 3}) rlp := new(bytes.Buffer) @@ -676,7 +677,7 @@ func mustInsertUnconfirmedEthTxWithAttemptState(t *testing.T, txStore txmgr.Test func mustInsertUnconfirmedEthTxWithBroadcastDynamicFeeAttempt(t *testing.T, txStore txmgr.TestEvmTxStore, nonce int64, fromAddress common.Address, opts ...interface{}) txmgr.Tx { etx := cltest.MustInsertUnconfirmedEthTx(t, txStore, nonce, fromAddress, opts...) attempt := cltest.NewDynamicFeeEthTxAttempt(t, etx.ID) - ctx := testutils.Context(t) + ctx := tests.Context(t) addr := testutils.NewAddress() dtx := types.DynamicFeeTx{ @@ -705,7 +706,7 @@ func mustInsertUnconfirmedEthTxWithBroadcastDynamicFeeAttempt(t *testing.T, txSt func mustInsertUnconfirmedEthTxWithInsufficientEthAttempt(t *testing.T, txStore txmgr.TestEvmTxStore, nonce int64, fromAddress common.Address) txmgr.Tx { timeNow := time.Now() etx := cltest.NewEthTx(fromAddress) - ctx := testutils.Context(t) + ctx := tests.Context(t) etx.BroadcastAt = &timeNow etx.InitialBroadcastAt = &timeNow @@ -732,7 +733,7 @@ func mustInsertConfirmedMissingReceiptEthTxWithLegacyAttempt( t *testing.T, txStore txmgr.TestEvmTxStore, nonce int64, broadcastBeforeBlockNum int64, broadcastAt time.Time, fromAddress common.Address) txmgr.Tx { etx := cltest.NewEthTx(fromAddress) - ctx := testutils.Context(t) + ctx := tests.Context(t) etx.BroadcastAt = &broadcastAt etx.InitialBroadcastAt = &broadcastAt @@ -750,7 +751,7 @@ func mustInsertConfirmedMissingReceiptEthTxWithLegacyAttempt( func mustInsertInProgressEthTxWithAttempt(t *testing.T, txStore txmgr.TestEvmTxStore, nonce evmtypes.Nonce, fromAddress common.Address) txmgr.Tx { etx := cltest.NewEthTx(fromAddress) - ctx := testutils.Context(t) + ctx := tests.Context(t) etx.Sequence = &nonce etx.State = txmgrcommon.TxInProgress @@ -807,10 +808,10 @@ func mustCreateUnstartedTx(t testing.TB, txStore txmgr.EvmTxStore, fromAddress c } func mustCreateUnstartedTxFromEvmTxRequest(t testing.TB, txStore txmgr.EvmTxStore, txRequest txmgr.TxRequest, chainID *big.Int) (tx txmgr.Tx) { - tx, err := txStore.CreateTransaction(testutils.Context(t), txRequest, chainID) + tx, err := txStore.CreateTransaction(tests.Context(t), txRequest, chainID) require.NoError(t, err) - _, err = txRequest.Strategy.PruneQueue(testutils.Context(t), txStore) + _, err = txRequest.Strategy.PruneQueue(tests.Context(t), txStore) require.NoError(t, err) return tx diff --git a/core/internal/testutils/testutils.go b/core/internal/testutils/testutils.go index f4867eda69a..6b4388fccf4 100644 --- a/core/internal/testutils/testutils.go +++ b/core/internal/testutils/testutils.go @@ -62,11 +62,6 @@ func NewAddress() common.Address { return common.BytesToAddress(randomBytes(20)) } -func NewAddressPtr() *common.Address { - a := common.BytesToAddress(randomBytes(20)) - return &a -} - // NewPrivateKeyAndAddress returns a new private key and the corresponding address func NewPrivateKeyAndAddress(t testing.TB) (*ecdsa.PrivateKey, common.Address) { privateKey, err := crypto.GenerateKey() @@ -128,12 +123,6 @@ func WaitTimeout(t *testing.T) time.Duration { return DefaultWaitTimeout } -// AfterWaitTimeout returns a channel that will send a time value when the -// WaitTimeout is reached -func AfterWaitTimeout(t *testing.T) <-chan time.Time { - return time.After(WaitTimeout(t)) -} - // Context returns a context with the test's deadline, if available. func Context(tb testing.TB) context.Context { ctx := context.Background()