Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions pkg/client/chain_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion pkg/client/clienttest/clienttest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/client/null_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion pkg/config/configtest/configtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
11 changes: 6 additions & 5 deletions pkg/gas/fee_history_estimator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ 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"
)

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{
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pkg/heads/saver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion pkg/log/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 4 additions & 4 deletions pkg/testutils/evmtypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions pkg/txmgr/broadcaster_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 10 additions & 2 deletions pkg/txmgr/broadcaster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -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
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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{
Expand All @@ -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))
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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))

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pkg/txmgr/confirmer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 6 additions & 4 deletions pkg/txmgr/evm_tx_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -650,19 +650,19 @@ 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)
})

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)
Expand All @@ -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)
})
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions pkg/txmgr/finalizer_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions pkg/txmgr/finalizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
Loading
Loading