diff --git a/pkg/client/chain_client_test.go b/pkg/client/chain_client_test.go index 47ce847146..8be608619a 100644 --- a/pkg/client/chain_client_test.go +++ b/pkg/client/chain_client_test.go @@ -504,7 +504,8 @@ type sendTxService struct { sentCount atomic.Int32 } -func (x *sendTxService) ChainID(ctx context.Context) (*hexutil.Big, error) { +//nolint:revive // ChainId must match JSON-RPC method name eth_chainId, not ChainID +func (x *sendTxService) ChainId(ctx context.Context) (*hexutil.Big, error) { return (*hexutil.Big)(x.chainID), nil } @@ -846,7 +847,7 @@ func TestEthClient_ErroringClient(t *testing.T) { require.Equal(t, multinode.ErrNodeError, err) id := erroringClient.ConfiguredChainID() - require.Equal(t, id, big.NewInt(0)) + require.Equal(t, id, big.NewInt(evmtypes.NullClientChainID)) _, err = erroringClient.CodeAt(ctx, common.Address{}, nil) require.Equal(t, multinode.ErrNodeError, err) diff --git a/pkg/client/clienttest/clienttest.go b/pkg/client/clienttest/clienttest.go index a3928bee98..f31d2447f7 100644 --- a/pkg/client/clienttest/clienttest.go +++ b/pkg/client/clienttest/clienttest.go @@ -8,11 +8,13 @@ import ( "github.com/ethereum/go-ethereum" "github.com/stretchr/testify/mock" + + "github.com/smartcontractkit/chainlink-evm/pkg/types" ) func NewClientWithDefaultChainID(t testing.TB) *Client { c := NewClient(t) - c.On("ConfiguredChainID").Return(big.NewInt(0)).Maybe() + c.On("ConfiguredChainID").Return(big.NewInt(types.NullClientChainID)).Maybe() return c } diff --git a/pkg/client/null_client.go b/pkg/client/null_client.go index e2fe66610d..06cd56db9a 100644 --- a/pkg/client/null_client.go +++ b/pkg/client/null_client.go @@ -30,7 +30,7 @@ func NewNullClient(cid *big.Int, lggr logger.Logger) *NullClient { // NullClientChainID the ChainID that nullclient will return // 0 is never used as a real chain ID so makes sense as a dummy value here -const NullClientChainID = 0 +const NullClientChainID = evmtypes.NullClientChainID // // Client methods diff --git a/pkg/config/configtest/configtest.go b/pkg/config/configtest/configtest.go index fa74f5bf11..f55f40c7c5 100644 --- a/pkg/config/configtest/configtest.go +++ b/pkg/config/configtest/configtest.go @@ -5,11 +5,12 @@ import ( "github.com/smartcontractkit/chainlink-evm/pkg/config" "github.com/smartcontractkit/chainlink-evm/pkg/config/toml" + "github.com/smartcontractkit/chainlink-evm/pkg/types" "github.com/smartcontractkit/chainlink-evm/pkg/utils/big" ) func NewChainScopedConfig(t testing.TB, overrideFn func(c *toml.EVMConfig)) *config.ChainScoped { - chainID := big.NewI(0) + chainID := big.NewI(types.NullClientChainID) evmCfg := &toml.EVMConfig{ ChainID: chainID, Chain: toml.Defaults(chainID), diff --git a/pkg/gas/fee_history_estimator_test.go b/pkg/gas/fee_history_estimator_test.go index 72235435cb..7bcd1b98fd 100644 --- a/pkg/gas/fee_history_estimator_test.go +++ b/pkg/gas/fee_history_estimator_test.go @@ -16,6 +16,7 @@ import ( "github.com/smartcontractkit/chainlink-evm/pkg/assets" "github.com/smartcontractkit/chainlink-evm/pkg/gas" "github.com/smartcontractkit/chainlink-evm/pkg/gas/mocks" + "github.com/smartcontractkit/chainlink-evm/pkg/testutils" "github.com/smartcontractkit/chainlink-framework/chains/fees" ) @@ -23,7 +24,7 @@ func TestFeeHistoryEstimatorLifecycle(t *testing.T) { t.Parallel() var gasLimit uint64 = 21000 maxPrice := assets.NewWeiI(100) - chainID := big.NewInt(0) + chainID := testutils.FixtureChainID t.Run("fails if you fetch gas price before the estimator starts", func(t *testing.T) { cfg := gas.FeeHistoryEstimatorConfig{ @@ -78,7 +79,7 @@ func TestFeeHistoryEstimatorGetLegacyGas(t *testing.T) { var gasLimit uint64 = 21000 maxPrice := assets.NewWeiI(100) - chainID := big.NewInt(0) + chainID := testutils.FixtureChainID t.Run("fetches a new gas price when first called", func(t *testing.T) { client := mocks.NewFeeHistoryEstimatorClient(t) @@ -125,7 +126,7 @@ func TestFeeHistoryEstimatorBumpLegacyGas(t *testing.T) { var gasLimit uint64 = 21000 maxPrice := assets.NewWeiI(100) - chainID := big.NewInt(0) + chainID := testutils.FixtureChainID t.Run("bumps a previous attempt by BumpPercent", func(t *testing.T) { client := mocks.NewFeeHistoryEstimatorClient(t) @@ -216,7 +217,7 @@ func TestFeeHistoryEstimatorGetDynamicFee(t *testing.T) { t.Parallel() maxPrice := assets.NewWeiI(100) - chainID := big.NewInt(0) + chainID := testutils.FixtureChainID t.Run("fetches a new dynamic fee when first called", func(t *testing.T) { client := mocks.NewFeeHistoryEstimatorClient(t) @@ -287,7 +288,7 @@ func TestFeeHistoryEstimatorBumpDynamicFee(t *testing.T) { t.Parallel() globalMaxPrice := assets.NewWeiI(100) - chainID := big.NewInt(0) + chainID := testutils.FixtureChainID t.Run("bumps a previous attempt by BumpPercent", func(t *testing.T) { client := mocks.NewFeeHistoryEstimatorClient(t) diff --git a/pkg/heads/saver_test.go b/pkg/heads/saver_test.go index ff83910b06..a4633f566d 100644 --- a/pkg/heads/saver_test.go +++ b/pkg/heads/saver_test.go @@ -12,11 +12,11 @@ import ( "github.com/smartcontractkit/chainlink-common/pkg/utils/tests" evmheads "github.com/smartcontractkit/chainlink-evm/pkg/heads" + ubig "github.com/smartcontractkit/chainlink-evm/pkg/utils/big" "github.com/smartcontractkit/chainlink-evm/pkg/testutils" evmtypes "github.com/smartcontractkit/chainlink-evm/pkg/types" "github.com/smartcontractkit/chainlink-evm/pkg/utils" - ubig "github.com/smartcontractkit/chainlink-evm/pkg/utils/big" ) type trackerConfig struct { @@ -121,7 +121,7 @@ func TestHeadSaver_Load(t *testing.T) { // H2Uncle // newHead := func(num int, parent common.Hash) *evmtypes.Head { - h := evmtypes.NewHead(big.NewInt(int64(num)), utils.NewHash(), parent, ubig.NewI(0)) + h := evmtypes.NewHead(big.NewInt(int64(num)), utils.NewHash(), parent, ubig.New(testutils.FixtureChainID)) return &h } h0 := newHead(0, utils.NewHash()) diff --git a/pkg/log/integration_test.go b/pkg/log/integration_test.go index 74605acec5..5d70fc7cf7 100644 --- a/pkg/log/integration_test.go +++ b/pkg/log/integration_test.go @@ -1545,7 +1545,7 @@ func TestBroadcaster_BroadcastsWithZeroConfirmations(t *testing.T) { ethClient := clienttest.NewClient(t) mockEth := &clienttest.MockEth{EthClient: ethClient} - ethClient.On("ConfiguredChainID").Return(big.NewInt(0)).Maybe() + ethClient.On("ConfiguredChainID").Return(testutils.FixtureChainID).Maybe() logsChCh := make(chan testutils.RawSub[types.Log]) ethClient.On("SubscribeFilterLogs", mock.Anything, mock.Anything, mock.Anything). Return( diff --git a/pkg/testutils/evmtypes.go b/pkg/testutils/evmtypes.go index ecb7e8e475..3c81dfed61 100644 --- a/pkg/testutils/evmtypes.go +++ b/pkg/testutils/evmtypes.go @@ -19,10 +19,10 @@ import ( ubig "github.com/smartcontractkit/chainlink-evm/pkg/utils/big" ) -// FixtureChainID matches the chain always added by fixtures.sql -// It is set to 0 since no real chain ever has this ID and allows a virtual -// "test" chain ID to be used without clashes -var FixtureChainID = big.NewInt(0) +// FixtureChainID is set to a chainID that is unlikely to be used in production. +// It can no longer be zero due to a breaking change in go-ethereum: +// https://github.com/ethereum/go-ethereum/blob/master/core/types/transaction_signing.go#L193 +var FixtureChainID = big.NewInt(evmtypes.NullClientChainID) // SimulatedChainID is the chain ID for the go-ethereum simulated backend var SimulatedChainID = big.NewInt(1337) diff --git a/pkg/txmgr/broadcaster_benchmark_test.go b/pkg/txmgr/broadcaster_benchmark_test.go index c63c504d78..87a3781690 100644 --- a/pkg/txmgr/broadcaster_benchmark_test.go +++ b/pkg/txmgr/broadcaster_benchmark_test.go @@ -54,6 +54,7 @@ func BenchmarkEthBroadcaster_ProcessUnstartedEthTxs_Success(b *testing.B) { FeeLimit: gasLimit, CreatedAt: time.Unix(0, 0), State: txmgrcommon.TxUnstarted, + ChainID: testutils.FixtureChainID, } evmcfg := configtest.NewChainScopedConfig(b, nil) diff --git a/pkg/txmgr/broadcaster_test.go b/pkg/txmgr/broadcaster_test.go index 67ec070535..1055793780 100644 --- a/pkg/txmgr/broadcaster_test.go +++ b/pkg/txmgr/broadcaster_test.go @@ -253,6 +253,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Success(t *testing.T) { FeeLimit: gasLimit, BroadcastAt: &timeNow, InitialBroadcastAt: &timeNow, + ChainID: testutils.FixtureChainID, Error: null.String{}, State: txmgrcommon.TxUnconfirmed, } @@ -285,6 +286,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Success(t *testing.T) { FeeLimit: gasLimit, CreatedAt: time.Unix(0, 0), State: txmgrcommon.TxUnstarted, + ChainID: testutils.FixtureChainID, } ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *gethTypes.Transaction) bool { return tx.Nonce() == uint64(2) && tx.Value().Cmp(big.NewInt(242)) == 0 @@ -304,6 +306,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Success(t *testing.T) { CreatedAt: time.Unix(0, 1), State: txmgrcommon.TxUnstarted, Meta: &meta, + ChainID: testutils.FixtureChainID, } ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *gethTypes.Transaction) bool { if tx.Nonce() != uint64(0) { @@ -327,6 +330,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Success(t *testing.T) { FeeLimit: gasLimit, CreatedAt: time.Unix(1, 0), State: txmgrcommon.TxUnstarted, + ChainID: testutils.FixtureChainID, } ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *gethTypes.Transaction) bool { if tx.Nonce() != uint64(1) { @@ -786,6 +790,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_ResumingFromCrash(t *testing.T) { FeeLimit: gasLimit, Error: null.String{}, State: txmgrcommon.TxInProgress, + ChainID: testutils.FixtureChainID, } secondInProgress := txmgr.Tx{ @@ -797,6 +802,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_ResumingFromCrash(t *testing.T) { FeeLimit: gasLimit, Error: null.String{}, State: txmgrcommon.TxInProgress, + ChainID: testutils.FixtureChainID, } require.NoError(t, txStore.InsertTx(ctx, &firstInProgress)) @@ -1162,6 +1168,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Errors(t *testing.T) { State: txmgrcommon.TxUnstarted, PipelineTaskRunID: uuid.NullUUID{UUID: trID, Valid: true}, SignalCallback: true, + ChainID: testutils.FixtureChainID, } t.Run("with erroring callback bails out", func(t *testing.T) { @@ -1464,6 +1471,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Errors(t *testing.T) { Value: value, FeeLimit: gasLimit, State: txmgrcommon.TxUnstarted, + ChainID: testutils.FixtureChainID, } require.NoError(t, txStore.InsertTx(ctx, &etxUnfinished)) @@ -1874,7 +1882,7 @@ func TestEthBroadcaster_NonceTracker_InProgressTx(t *testing.T) { txStore := txmgrtest.NewTestTxStore(t, db) memKS := keystest.NewMemoryChainStore() fromAddress := memKS.MustCreate(t) - ethKeyStore := keys.NewChainStore(memKS, big.NewInt(0)) + ethKeyStore := keys.NewChainStore(memKS, testutils.FixtureChainID) ethClient := clienttest.NewClientWithDefaultChainID(t) evmcfg := configtest.NewChainScopedConfig(t, nil) @@ -1912,7 +1920,7 @@ func TestEthBroadcaster_HederaBroadcastValidation(t *testing.T) { db := testutils.NewSqlxDB(t) txStore := txmgrtest.NewTestTxStore(t, db) memKS := keystest.NewMemoryChainStore() - ethKeyStore := keys.NewChainStore(memKS, big.NewInt(0)) + ethKeyStore := keys.NewChainStore(memKS, testutils.FixtureChainID) evmcfg := configtest.NewChainScopedConfig(t, nil) ethClient := clienttest.NewClientWithDefaultChainID(t) lggr, observed := logger.TestObserved(t, zapcore.DebugLevel) diff --git a/pkg/txmgr/confirmer_test.go b/pkg/txmgr/confirmer_test.go index 09548afb66..727d747621 100644 --- a/pkg/txmgr/confirmer_test.go +++ b/pkg/txmgr/confirmer_test.go @@ -1281,7 +1281,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary_TerminallyUnderpriced_ThenGoesTh memKS := keystest.NewMemoryChainStore() fromAddress := memKS.MustCreate(t) - kst := keys.NewChainStore(memKS, big.NewInt(0)) + kst := keys.NewChainStore(memKS, testutils.FixtureChainID) evmcfg := configtest.NewChainScopedConfig(t, func(c *toml.EVMConfig) { c.GasEstimator.PriceMax = assets.GWei(500) @@ -1547,7 +1547,7 @@ func TestEthConfirmer_ForceRebroadcast(t *testing.T) { memKS := keystest.NewMemoryChainStore() fromAddress := memKS.MustCreate(t) config := configtest.NewChainScopedConfig(t, nil) - ethKeyStore := keys.NewChainStore(memKS, big.NewInt(0)) + ethKeyStore := keys.NewChainStore(memKS, testutils.FixtureChainID) mustCreateUnstartedGeneratedTx(t, txStore, fromAddress, config.EVM().ChainID()) mustInsertInProgressEthTx(t, txStore, 0, fromAddress) diff --git a/pkg/txmgr/evm_tx_store_test.go b/pkg/txmgr/evm_tx_store_test.go index a489310112..c1594fd829 100644 --- a/pkg/txmgr/evm_tx_store_test.go +++ b/pkg/txmgr/evm_tx_store_test.go @@ -650,7 +650,7 @@ func Test_FindTxWithIdempotencyKey(t *testing.T) { t.Run("returns nil error if no results", func(t *testing.T) { idempotencyKey := "777" - etx, err := txStore.FindTxWithIdempotencyKey(tests.Context(t), idempotencyKey, big.NewInt(0)) + etx, err := txStore.FindTxWithIdempotencyKey(t.Context(), idempotencyKey, testutils.FixtureChainID) require.NoError(t, err) assert.Nil(t, etx) }) @@ -658,11 +658,11 @@ func Test_FindTxWithIdempotencyKey(t *testing.T) { t.Run("returns transaction if it exists", func(t *testing.T) { idempotencyKey := "777" cfg.EVM().ChainID() - etx := mustCreateUnstartedGeneratedTx(t, txStore, fromAddress, big.NewInt(0), + etx := mustCreateUnstartedGeneratedTx(t, txStore, fromAddress, testutils.FixtureChainID, txRequestWithIdempotencyKey(idempotencyKey)) require.Equal(t, idempotencyKey, *etx.IdempotencyKey) - res, err := txStore.FindTxWithIdempotencyKey(tests.Context(t), idempotencyKey, big.NewInt(0)) + res, err := txStore.FindTxWithIdempotencyKey(t.Context(), idempotencyKey, testutils.FixtureChainID) require.NoError(t, err) assert.Equal(t, etx.Sequence, res.Sequence) require.Equal(t, idempotencyKey, *res.IdempotencyKey) @@ -679,7 +679,7 @@ func Test_FindReceiptWithIdempotencyKey(t *testing.T) { idempotencyKey := "654" t.Run("returns nil error if no results", func(t *testing.T) { - r, err := txStore.FindReceiptWithIdempotencyKey(tests.Context(t), idempotencyKey, big.NewInt(0)) + r, err := txStore.FindReceiptWithIdempotencyKey(t.Context(), idempotencyKey, testutils.FixtureChainID) require.NoError(t, err) assert.Nil(t, r) }) @@ -1862,6 +1862,7 @@ func TestORM_UpdateTxStatesToFinalizedUsingTxHashes(t *testing.T) { State: txmgrcommon.TxConfirmed, BroadcastAt: &broadcast, InitialBroadcastAt: &broadcast, + ChainID: testutils.FixtureChainID, } err := txStore.InsertTx(ctx, tx) require.NoError(t, err) @@ -2060,6 +2061,7 @@ func mustInsertTerminallyStuckTxWithAttempt(t testing.TB, txStore txmgr.TestEvmT BroadcastAt: &broadcast, InitialBroadcastAt: &broadcast, Error: null.StringFrom(client.TerminallyStuckMsg), + ChainID: testutils.FixtureChainID, } require.NoError(t, txStore.InsertTx(ctx, &tx)) attempt := txmgrtest.NewLegacyEthTxAttempt(t, tx.ID) diff --git a/pkg/txmgr/finalizer_benchmark_test.go b/pkg/txmgr/finalizer_benchmark_test.go index 48e73d39d5..6874b605f4 100644 --- a/pkg/txmgr/finalizer_benchmark_test.go +++ b/pkg/txmgr/finalizer_benchmark_test.go @@ -66,6 +66,7 @@ func BenchmarkFinalizer(b *testing.B) { State: txmgrcommon.TxConfirmed, BroadcastAt: &broadcast, InitialBroadcastAt: &broadcast, + ChainID: testutils.FixtureChainID, } attemptHash := insertTxAndAttemptWithIdempotencyKey(b, txStore, tx, idempotencyKey) // Insert receipt for finalized block num diff --git a/pkg/txmgr/finalizer_test.go b/pkg/txmgr/finalizer_test.go index 9b0c1a18a3..599e928f17 100644 --- a/pkg/txmgr/finalizer_test.go +++ b/pkg/txmgr/finalizer_test.go @@ -78,6 +78,7 @@ func TestFinalizer_MarkTxFinalized(t *testing.T) { State: txmgrcommon.TxConfirmed, BroadcastAt: &broadcast, InitialBroadcastAt: &broadcast, + ChainID: testutils.FixtureChainID, } attemptHash := insertTxAndAttemptWithIdempotencyKey(t, txStore, tx, idempotencyKey) // Insert receipt for unfinalized block num @@ -108,6 +109,7 @@ func TestFinalizer_MarkTxFinalized(t *testing.T) { State: txmgrcommon.TxConfirmed, BroadcastAt: &broadcast, InitialBroadcastAt: &broadcast, + ChainID: testutils.FixtureChainID, } attemptHash := insertTxAndAttemptWithIdempotencyKey(t, txStore, tx, idempotencyKey) // Insert receipt for finalized block num @@ -140,6 +142,7 @@ func TestFinalizer_MarkTxFinalized(t *testing.T) { State: txmgrcommon.TxConfirmed, BroadcastAt: &broadcast, InitialBroadcastAt: &broadcast, + ChainID: testutils.FixtureChainID, } attemptHash := insertTxAndAttemptWithIdempotencyKey(t, txStore, tx, idempotencyKey) // Insert receipt for finalized block num @@ -170,6 +173,7 @@ func TestFinalizer_MarkTxFinalized(t *testing.T) { State: txmgrcommon.TxConfirmed, BroadcastAt: &broadcast, InitialBroadcastAt: &broadcast, + ChainID: testutils.FixtureChainID, } attemptHash := insertTxAndAttemptWithIdempotencyKey(t, txStore, tx, idempotencyKey) // Insert receipt for finalized block num @@ -186,6 +190,7 @@ func TestFinalizer_MarkTxFinalized(t *testing.T) { State: txmgrcommon.TxConfirmed, BroadcastAt: &broadcast, InitialBroadcastAt: &broadcast, + ChainID: testutils.FixtureChainID, } attemptHash = insertTxAndAttemptWithIdempotencyKey(t, txStore, tx, idempotencyKey) // Insert receipt for finalized block num diff --git a/pkg/txmgr/nonce_tracker_test.go b/pkg/txmgr/nonce_tracker_test.go index d91ee1979e..3a2b20d6fa 100644 --- a/pkg/txmgr/nonce_tracker_test.go +++ b/pkg/txmgr/nonce_tracker_test.go @@ -3,7 +3,6 @@ package txmgr_test import ( "errors" "fmt" - "math/big" "math/rand" "testing" @@ -27,7 +26,7 @@ func TestNonceTracker_LoadSequenceMap(t *testing.T) { t.Parallel() ctx := tests.Context(t) - chainID := big.NewInt(0) + chainID := testutils.FixtureChainID txStore := txstoremock.NewEvmTxStore(t) client := clienttest.NewClient(t) @@ -78,7 +77,7 @@ func TestNonceTracker_syncOnChain(t *testing.T) { t.Parallel() ctx := tests.Context(t) - chainID := big.NewInt(0) + chainID := testutils.FixtureChainID txStore := txstoremock.NewEvmTxStore(t) client := clienttest.NewClient(t) @@ -134,7 +133,7 @@ func TestNonceTracker_SyncSequence(t *testing.T) { t.Parallel() ctx := tests.Context(t) - chainID := big.NewInt(0) + chainID := testutils.FixtureChainID txStore := txstoremock.NewEvmTxStore(t) client := clienttest.NewClient(t) @@ -181,7 +180,7 @@ func TestNonceTracker_GetNextSequence(t *testing.T) { t.Parallel() ctx := tests.Context(t) - chainID := big.NewInt(0) + chainID := testutils.FixtureChainID txStore := txstoremock.NewEvmTxStore(t) client := clienttest.NewClient(t) @@ -231,7 +230,7 @@ func TestNonceTracker_GenerateNextSequence(t *testing.T) { t.Parallel() ctx := tests.Context(t) - chainID := big.NewInt(0) + chainID := testutils.FixtureChainID txStore := txstoremock.NewEvmTxStore(t) client := clienttest.NewClient(t) @@ -260,7 +259,7 @@ func Test_SetNonceAfterInit(t *testing.T) { t.Parallel() ctx := tests.Context(t) - chainID := big.NewInt(0) + chainID := testutils.FixtureChainID db := testutils.NewSqlxDB(t) txStore := txmgr.NewTxStore(db, logger.Test(t)) diff --git a/pkg/txmgr/resender_test.go b/pkg/txmgr/resender_test.go index bc29376aaf..5d8e826700 100644 --- a/pkg/txmgr/resender_test.go +++ b/pkg/txmgr/resender_test.go @@ -1,7 +1,6 @@ package txmgr_test import ( - "math/big" "testing" "time" @@ -41,7 +40,7 @@ func Test_EthResender_resendUnconfirmed(t *testing.T) { fromAddress := memKS.MustCreate(t) fromAddress2 := memKS.MustCreate(t) fromAddress3 := memKS.MustCreate(t) - ethKeyStore := keys.NewChainStore(memKS, big.NewInt(0)) + ethKeyStore := keys.NewChainStore(memKS, testutils.FixtureChainID) txStore := txmgrtest.NewTestTxStore(t, db) @@ -67,7 +66,7 @@ func Test_EthResender_resendUnconfirmed(t *testing.T) { addr3TxesRawHex = append(addr3TxesRawHex, hexutil.Encode(etx.TxAttempts[0].SignedRawTx)) } - 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()) + er := txmgr.NewEvmResender(lggr, txStore, txmgr.NewEvmTxmClient(ethClient, nil), txmgr.NewEvmTracker(txStore, ethKeyStore, testutils.FixtureChainID, lggr), ethKeyStore, 100*time.Millisecond, ccfg.EVM(), ccfg.EVM().Transactions()) var resentHex = make(map[string]struct{}) ethClient.On("BatchCallContextAll", mock.Anything, mock.MatchedBy(func(elems []rpc.BatchElem) bool { @@ -108,13 +107,13 @@ func Test_EthResender_alertUnconfirmed(t *testing.T) { ethClient := clienttest.NewClientWithDefaultChainID(t) memKS := keystest.NewMemoryChainStore() fromAddress := memKS.MustCreate(t) - ethKeyStore := keys.NewChainStore(memKS, big.NewInt(0)) + ethKeyStore := keys.NewChainStore(memKS, testutils.FixtureChainID) 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) ccfg := testutils.NewTestChainScopedConfig(t, func(c *toml.EVMConfig) { - c.Chain = toml.Defaults(ubig.New(big.NewInt(0)), &toml.Chain{ + c.Chain = toml.Defaults(ubig.New(testutils.FixtureChainID), &toml.Chain{ Transactions: toml.Transactions{ResendAfterThreshold: delay}, }) }) @@ -122,7 +121,7 @@ func Test_EthResender_alertUnconfirmed(t *testing.T) { txStore := txmgrtest.NewTestTxStore(t, db) originalBroadcastAt := time.Unix(1616509100, 0) - 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()) + er := txmgr.NewEvmResender(lggr, txStore, txmgr.NewEvmTxmClient(ethClient, nil), txmgr.NewEvmTracker(txStore, ethKeyStore, testutils.FixtureChainID, lggr), ethKeyStore, 100*time.Millisecond, ccfg.EVM(), ccfg.EVM().Transactions()) t.Run("alerts only once for unconfirmed transaction attempt within the unconfirmedTxAlertDelay duration", func(t *testing.T) { _ = txmgrtest.MustInsertUnconfirmedEthTxWithBroadcastLegacyAttempt(t, txStore, int64(1), fromAddress, originalBroadcastAt) @@ -153,7 +152,7 @@ func Test_EthResender_Start(t *testing.T) { txStore := txmgrtest.NewTestTxStore(t, db) memKS := keystest.NewMemoryChainStore() fromAddress := memKS.MustCreate(t) - ethKeyStore := keys.NewChainStore(memKS, big.NewInt(0)) + ethKeyStore := keys.NewChainStore(memKS, testutils.FixtureChainID) lggr := logger.Test(t) t.Run("resends transactions that have been languishing unconfirmed for too long", func(t *testing.T) { @@ -161,7 +160,7 @@ func Test_EthResender_Start(t *testing.T) { ethClient := clienttest.NewClientWithDefaultChainID(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()) + er := txmgr.NewEvmResender(lggr, txStore, txmgr.NewEvmTxmClient(ethClient, nil), txmgr.NewEvmTracker(txStore, ethKeyStore, testutils.FixtureChainID, lggr), ethKeyStore, 100*time.Millisecond, ccfg.EVM(), ccfg.EVM().Transactions()) originalBroadcastAt := time.Unix(1616509100, 0) etx := txmgrtest.MustInsertUnconfirmedEthTxWithBroadcastLegacyAttempt(t, txStore, 0, fromAddress, originalBroadcastAt) diff --git a/pkg/txmgr/tracker_test.go b/pkg/txmgr/tracker_test.go index 7480a851e7..61352efce6 100644 --- a/pkg/txmgr/tracker_test.go +++ b/pkg/txmgr/tracker_test.go @@ -23,7 +23,7 @@ import ( func newTestEvmTrackerSetup(t *testing.T) (*txmgr.Tracker, txmgr.TestEvmTxStore) { db := testutils.NewSqlxDB(t) txStore := txmgrtest.NewTestTxStore(t, db) - chainID := big.NewInt(0) + chainID := testutils.FixtureChainID memKS := keystest.NewMemoryChainStore() addr1 := memKS.MustCreate(t) addr2 := memKS.MustCreate(t) diff --git a/pkg/txmgr/txmgr_test.go b/pkg/txmgr/txmgr_test.go index 9ae4f1c866..84e35b697d 100644 --- a/pkg/txmgr/txmgr_test.go +++ b/pkg/txmgr/txmgr_test.go @@ -107,7 +107,7 @@ func TestTxm_SendNativeToken_DoesNotSendToZero(t *testing.T) { txm, err := makeTestEvmTxm(t, db, ethClient, estimator, evmConfig, evmConfig.GasEstimator(), evmConfig.Transactions(), dbConfig, dbConfig.Listener(), &keystest.FakeChainStore{}) require.NoError(t, err) - _, err = txm.SendNativeToken(tests.Context(t), big.NewInt(0), from, to, *value, 21000) + _, err = txm.SendNativeToken(t.Context(), testutils.FixtureChainID, from, to, *value, 21000) require.Error(t, err) require.EqualError(t, err, "cannot send native token to zero address") } @@ -119,7 +119,7 @@ func TestTxm_CreateTransaction(t *testing.T) { txStore := txmgrtest.NewTestTxStore(t, db) memKS := keystest.NewMemoryChainStore() fromAddress := memKS.MustCreate(t) - ethKeyStore := keys.NewChainStore(memKS, big.NewInt(0)) + ethKeyStore := keys.NewChainStore(memKS, testutils.FixtureChainID) toAddress := testutils.NewAddress() gasLimit := uint64(1000) @@ -395,7 +395,7 @@ func BenchmarkCreateTransaction(b *testing.B) { config, dbConfig, evmConfig := txmgr.MakeTestConfigs(b) ethClient := clienttest.NewClient(b) - ethClient.On("ConfiguredChainID").Return(big.NewInt(0)).Maybe() + ethClient.On("ConfiguredChainID").Return(testutils.FixtureChainID).Maybe() estimator, err := gas.NewEstimator(logger.Test(b), ethClient, config.ChainType(), ethClient.ConfiguredChainID(), evmConfig.GasEstimator(), nil) require.NoError(b, err) @@ -433,7 +433,7 @@ func TestTxm_CreateTransaction_OutOfEth(t *testing.T) { memKS := keystest.NewMemoryChainStore() fromAddress := memKS.MustCreate(t) otherAddress := memKS.MustCreate(t) - ethKeyStore := keys.NewChainStore(memKS, big.NewInt(0)) + ethKeyStore := keys.NewChainStore(memKS, testutils.FixtureChainID) gasLimit := uint64(1000) toAddress := testutils.NewAddress() @@ -567,7 +567,7 @@ func TestTxm_Reset(t *testing.T) { memKS := keystest.NewMemoryChainStore() addr := memKS.MustCreate(t) addr2 := memKS.MustCreate(t) - ethKeyStore := keys.NewChainStore(memKS, big.NewInt(0)) + ethKeyStore := keys.NewChainStore(memKS, testutils.FixtureChainID) txStore := txmgrtest.NewTestTxStore(t, db) // 4 confirmed tx from addr1 @@ -632,7 +632,7 @@ func TestTxm_GetTransactionFee(t *testing.T) { db := testutils.NewSqlxDB(t) txStore := txmgrtest.NewTestTxStore(t, db) memKS := keystest.NewMemoryChainStore() - ethKeyStore := keys.NewChainStore(memKS, big.NewInt(0)) + ethKeyStore := keys.NewChainStore(memKS, testutils.FixtureChainID) feeLimit := uint64(10_000) _, dbConfig, evmConfig := txmgr.MakeTestConfigs(t) @@ -678,6 +678,7 @@ func TestTxm_GetTransactionFee(t *testing.T) { EncodedPayload: []byte{1, 2, 3}, FeeLimit: feeLimit, State: txmgrcommon.TxUnstarted, + ChainID: testutils.FixtureChainID, } err := txStore.InsertTx(ctx, tx) require.NoError(t, err) @@ -710,6 +711,7 @@ func TestTxm_GetTransactionFee(t *testing.T) { State: txmgrcommon.TxFinalized, BroadcastAt: &broadcast, InitialBroadcastAt: &broadcast, + ChainID: testutils.FixtureChainID, } err := txStore.InsertTx(ctx, tx) require.NoError(t, err) @@ -737,7 +739,7 @@ func TestTxm_GetTransactionStatus(t *testing.T) { db := testutils.NewSqlxDB(t) txStore := txmgrtest.NewTestTxStore(t, db) memKS := keystest.NewMemoryChainStore() - ethKeyStore := keys.NewChainStore(memKS, big.NewInt(0)) + ethKeyStore := keys.NewChainStore(memKS, testutils.FixtureChainID) feeLimit := uint64(10_000) _, dbConfig, evmConfig := txmgr.MakeTestConfigs(t) @@ -784,6 +786,7 @@ func TestTxm_GetTransactionStatus(t *testing.T) { EncodedPayload: []byte{1, 2, 3}, FeeLimit: feeLimit, State: txmgrcommon.TxUnstarted, + ChainID: testutils.FixtureChainID, } err := txStore.InsertTx(ctx, tx) require.NoError(t, err) @@ -803,6 +806,7 @@ func TestTxm_GetTransactionStatus(t *testing.T) { EncodedPayload: []byte{1, 2, 3}, FeeLimit: feeLimit, State: txmgrcommon.TxInProgress, + ChainID: testutils.FixtureChainID, } err := txStore.InsertTx(ctx, tx) require.NoError(t, err) @@ -825,6 +829,7 @@ func TestTxm_GetTransactionStatus(t *testing.T) { State: txmgrcommon.TxUnconfirmed, BroadcastAt: &broadcast, InitialBroadcastAt: &broadcast, + ChainID: testutils.FixtureChainID, } err := txStore.InsertTx(ctx, tx) require.NoError(t, err) @@ -847,6 +852,7 @@ func TestTxm_GetTransactionStatus(t *testing.T) { State: txmgrcommon.TxConfirmed, BroadcastAt: &broadcast, InitialBroadcastAt: &broadcast, + ChainID: testutils.FixtureChainID, } err := txStore.InsertTx(ctx, tx) require.NoError(t, err) @@ -876,6 +882,7 @@ func TestTxm_GetTransactionStatus(t *testing.T) { State: txmgrcommon.TxFinalized, BroadcastAt: &broadcast, InitialBroadcastAt: &broadcast, + ChainID: testutils.FixtureChainID, } err := txStore.InsertTx(ctx, tx) require.NoError(t, err) @@ -905,6 +912,7 @@ func TestTxm_GetTransactionStatus(t *testing.T) { State: txmgrcommon.TxConfirmedMissingReceipt, BroadcastAt: &broadcast, InitialBroadcastAt: &broadcast, + ChainID: testutils.FixtureChainID, } err := txStore.InsertTx(ctx, tx) require.NoError(t, err) @@ -929,6 +937,7 @@ func TestTxm_GetTransactionStatus(t *testing.T) { Error: null.NewString(evmclient.TerminallyStuckMsg, true), BroadcastAt: &broadcast, InitialBroadcastAt: &broadcast, + ChainID: testutils.FixtureChainID, } err := txStore.InsertTx(ctx, tx) require.NoError(t, err) @@ -951,6 +960,7 @@ func TestTxm_GetTransactionStatus(t *testing.T) { Error: null.NewString(terminallyStuckClientError, true), BroadcastAt: &broadcast, InitialBroadcastAt: &broadcast, + ChainID: testutils.FixtureChainID, } err = txStore.InsertTx(ctx, tx) require.NoError(t, err) @@ -971,6 +981,7 @@ func TestTxm_GetTransactionStatus(t *testing.T) { FeeLimit: feeLimit, State: txmgrcommon.TxFatalError, Error: null.NewString(errorMsg, true), + ChainID: testutils.FixtureChainID, } err := txStore.InsertTx(ctx, tx) require.NoError(t, err) @@ -1065,7 +1076,7 @@ func mustInsertUnconfirmedEthTxWithBroadcastDynamicFeeAttempt(t *testing.T, txSt addr := testutils.NewAddress() dtx := types.DynamicFeeTx{ - ChainID: big.NewInt(0), + ChainID: testutils.FixtureChainID, Nonce: uint64(nonce), GasTipCap: big.NewInt(1), GasFeeCap: big.NewInt(1), @@ -1127,6 +1138,7 @@ func mustInsertConfirmedMissingReceiptEthTxWithLegacyAttempt( require.NoError(t, txStore.InsertTx(ctx, &etx)) attempt := txmgrtest.NewLegacyEthTxAttempt(t, etx.ID) attempt.BroadcastBeforeBlockNum = &broadcastBeforeBlockNum + attempt.Tx.ChainID = testutils.FixtureChainID attempt.State = txmgrtypes.TxAttemptBroadcast require.NoError(t, txStore.InsertTxAttempt(ctx, &attempt)) etx.TxAttempts = append(etx.TxAttempts, attempt) @@ -1145,6 +1157,7 @@ func mustInsertInProgressEthTxWithAttempt(t testing.TB, txStore txmgr.TestEvmTxS rlp := new(bytes.Buffer) require.NoError(t, tx.EncodeRLP(rlp)) attempt.SignedRawTx = rlp.Bytes() + attempt.Tx.ChainID = testutils.FixtureChainID attempt.State = txmgrtypes.TxAttemptInProgress require.NoError(t, txStore.InsertTxAttempt(ctx, &attempt)) var err error diff --git a/pkg/txmgr/txmgrtest/utils.go b/pkg/txmgr/txmgrtest/utils.go index 54f337d001..8a6e926347 100644 --- a/pkg/txmgr/txmgrtest/utils.go +++ b/pkg/txmgr/txmgrtest/utils.go @@ -35,6 +35,7 @@ func NewEthTx(fromAddress common.Address) txmgr.Tx { Value: big.Int(assets.NewEthValue(142)), FeeLimit: uint64(1000000000), State: txmgrcommon.TxUnstarted, + ChainID: evmtestutils.FixtureChainID, } } diff --git a/pkg/types/utils.go b/pkg/types/utils.go index 96e0a02e2c..33c5f0f9cd 100644 --- a/pkg/types/utils.go +++ b/pkg/types/utils.go @@ -13,3 +13,8 @@ func MustGetABI(json string) abi.ABI { } return abi } + +// NullClientChainID is set to a chainID that is unlikely to be used in production. +// It cannot be zero due to a breaking change in go-ethereum: +// https://github.com/ethereum/go-ethereum/blob/master/core/types/transaction_signing.go#L193 +const NullClientChainID = 1399100