Skip to content

Commit aacd485

Browse files
authored
Update FixtureChainID (#214)
* Update FixtureChainID, bump go-ethereum * fix lint * downgrade temporarily, add test fixes * more test fixes * fix lint, fix method name for go-ethereum JSON RPC mapping * silence linter * add clarifying comment
1 parent c054b4e commit aacd485

20 files changed

Lines changed: 88 additions & 49 deletions

pkg/client/chain_client_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,8 @@ type sendTxService struct {
504504
sentCount atomic.Int32
505505
}
506506

507-
func (x *sendTxService) ChainID(ctx context.Context) (*hexutil.Big, error) {
507+
//nolint:revive // ChainId must match JSON-RPC method name eth_chainId, not ChainID
508+
func (x *sendTxService) ChainId(ctx context.Context) (*hexutil.Big, error) {
508509
return (*hexutil.Big)(x.chainID), nil
509510
}
510511

@@ -846,7 +847,7 @@ func TestEthClient_ErroringClient(t *testing.T) {
846847
require.Equal(t, multinode.ErrNodeError, err)
847848

848849
id := erroringClient.ConfiguredChainID()
849-
require.Equal(t, id, big.NewInt(0))
850+
require.Equal(t, id, big.NewInt(evmtypes.NullClientChainID))
850851

851852
_, err = erroringClient.CodeAt(ctx, common.Address{}, nil)
852853
require.Equal(t, multinode.ErrNodeError, err)

pkg/client/clienttest/clienttest.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ import (
88

99
"github.com/ethereum/go-ethereum"
1010
"github.com/stretchr/testify/mock"
11+
12+
"github.com/smartcontractkit/chainlink-evm/pkg/types"
1113
)
1214

1315
func NewClientWithDefaultChainID(t testing.TB) *Client {
1416
c := NewClient(t)
15-
c.On("ConfiguredChainID").Return(big.NewInt(0)).Maybe()
17+
c.On("ConfiguredChainID").Return(big.NewInt(types.NullClientChainID)).Maybe()
1618
return c
1719
}
1820

pkg/client/null_client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func NewNullClient(cid *big.Int, lggr logger.Logger) *NullClient {
3030

3131
// NullClientChainID the ChainID that nullclient will return
3232
// 0 is never used as a real chain ID so makes sense as a dummy value here
33-
const NullClientChainID = 0
33+
const NullClientChainID = evmtypes.NullClientChainID
3434

3535
//
3636
// Client methods

pkg/config/configtest/configtest.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ import (
55

66
"github.com/smartcontractkit/chainlink-evm/pkg/config"
77
"github.com/smartcontractkit/chainlink-evm/pkg/config/toml"
8+
"github.com/smartcontractkit/chainlink-evm/pkg/types"
89
"github.com/smartcontractkit/chainlink-evm/pkg/utils/big"
910
)
1011

1112
func NewChainScopedConfig(t testing.TB, overrideFn func(c *toml.EVMConfig)) *config.ChainScoped {
12-
chainID := big.NewI(0)
13+
chainID := big.NewI(types.NullClientChainID)
1314
evmCfg := &toml.EVMConfig{
1415
ChainID: chainID,
1516
Chain: toml.Defaults(chainID),

pkg/gas/fee_history_estimator_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ import (
1616
"github.com/smartcontractkit/chainlink-evm/pkg/assets"
1717
"github.com/smartcontractkit/chainlink-evm/pkg/gas"
1818
"github.com/smartcontractkit/chainlink-evm/pkg/gas/mocks"
19+
"github.com/smartcontractkit/chainlink-evm/pkg/testutils"
1920
"github.com/smartcontractkit/chainlink-framework/chains/fees"
2021
)
2122

2223
func TestFeeHistoryEstimatorLifecycle(t *testing.T) {
2324
t.Parallel()
2425
var gasLimit uint64 = 21000
2526
maxPrice := assets.NewWeiI(100)
26-
chainID := big.NewInt(0)
27+
chainID := testutils.FixtureChainID
2728

2829
t.Run("fails if you fetch gas price before the estimator starts", func(t *testing.T) {
2930
cfg := gas.FeeHistoryEstimatorConfig{
@@ -78,7 +79,7 @@ func TestFeeHistoryEstimatorGetLegacyGas(t *testing.T) {
7879

7980
var gasLimit uint64 = 21000
8081
maxPrice := assets.NewWeiI(100)
81-
chainID := big.NewInt(0)
82+
chainID := testutils.FixtureChainID
8283

8384
t.Run("fetches a new gas price when first called", func(t *testing.T) {
8485
client := mocks.NewFeeHistoryEstimatorClient(t)
@@ -125,7 +126,7 @@ func TestFeeHistoryEstimatorBumpLegacyGas(t *testing.T) {
125126

126127
var gasLimit uint64 = 21000
127128
maxPrice := assets.NewWeiI(100)
128-
chainID := big.NewInt(0)
129+
chainID := testutils.FixtureChainID
129130

130131
t.Run("bumps a previous attempt by BumpPercent", func(t *testing.T) {
131132
client := mocks.NewFeeHistoryEstimatorClient(t)
@@ -216,7 +217,7 @@ func TestFeeHistoryEstimatorGetDynamicFee(t *testing.T) {
216217
t.Parallel()
217218

218219
maxPrice := assets.NewWeiI(100)
219-
chainID := big.NewInt(0)
220+
chainID := testutils.FixtureChainID
220221

221222
t.Run("fetches a new dynamic fee when first called", func(t *testing.T) {
222223
client := mocks.NewFeeHistoryEstimatorClient(t)
@@ -287,7 +288,7 @@ func TestFeeHistoryEstimatorBumpDynamicFee(t *testing.T) {
287288
t.Parallel()
288289

289290
globalMaxPrice := assets.NewWeiI(100)
290-
chainID := big.NewInt(0)
291+
chainID := testutils.FixtureChainID
291292

292293
t.Run("bumps a previous attempt by BumpPercent", func(t *testing.T) {
293294
client := mocks.NewFeeHistoryEstimatorClient(t)

pkg/heads/saver_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ import (
1212
"github.com/smartcontractkit/chainlink-common/pkg/utils/tests"
1313

1414
evmheads "github.com/smartcontractkit/chainlink-evm/pkg/heads"
15+
ubig "github.com/smartcontractkit/chainlink-evm/pkg/utils/big"
1516

1617
"github.com/smartcontractkit/chainlink-evm/pkg/testutils"
1718
evmtypes "github.com/smartcontractkit/chainlink-evm/pkg/types"
1819
"github.com/smartcontractkit/chainlink-evm/pkg/utils"
19-
ubig "github.com/smartcontractkit/chainlink-evm/pkg/utils/big"
2020
)
2121

2222
type trackerConfig struct {
@@ -121,7 +121,7 @@ func TestHeadSaver_Load(t *testing.T) {
121121
// H2Uncle
122122
//
123123
newHead := func(num int, parent common.Hash) *evmtypes.Head {
124-
h := evmtypes.NewHead(big.NewInt(int64(num)), utils.NewHash(), parent, ubig.NewI(0))
124+
h := evmtypes.NewHead(big.NewInt(int64(num)), utils.NewHash(), parent, ubig.New(testutils.FixtureChainID))
125125
return &h
126126
}
127127
h0 := newHead(0, utils.NewHash())

pkg/log/integration_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1545,7 +1545,7 @@ func TestBroadcaster_BroadcastsWithZeroConfirmations(t *testing.T) {
15451545

15461546
ethClient := clienttest.NewClient(t)
15471547
mockEth := &clienttest.MockEth{EthClient: ethClient}
1548-
ethClient.On("ConfiguredChainID").Return(big.NewInt(0)).Maybe()
1548+
ethClient.On("ConfiguredChainID").Return(testutils.FixtureChainID).Maybe()
15491549
logsChCh := make(chan testutils.RawSub[types.Log])
15501550
ethClient.On("SubscribeFilterLogs", mock.Anything, mock.Anything, mock.Anything).
15511551
Return(

pkg/testutils/evmtypes.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ import (
1919
ubig "github.com/smartcontractkit/chainlink-evm/pkg/utils/big"
2020
)
2121

22-
// FixtureChainID matches the chain always added by fixtures.sql
23-
// It is set to 0 since no real chain ever has this ID and allows a virtual
24-
// "test" chain ID to be used without clashes
25-
var FixtureChainID = big.NewInt(0)
22+
// FixtureChainID is set to a chainID that is unlikely to be used in production.
23+
// It can no longer be zero due to a breaking change in go-ethereum:
24+
// https://github.com/ethereum/go-ethereum/blob/master/core/types/transaction_signing.go#L193
25+
var FixtureChainID = big.NewInt(evmtypes.NullClientChainID)
2626

2727
// SimulatedChainID is the chain ID for the go-ethereum simulated backend
2828
var SimulatedChainID = big.NewInt(1337)

pkg/txmgr/broadcaster_benchmark_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ func BenchmarkEthBroadcaster_ProcessUnstartedEthTxs_Success(b *testing.B) {
5454
FeeLimit: gasLimit,
5555
CreatedAt: time.Unix(0, 0),
5656
State: txmgrcommon.TxUnstarted,
57+
ChainID: testutils.FixtureChainID,
5758
}
5859

5960
evmcfg := configtest.NewChainScopedConfig(b, nil)

pkg/txmgr/broadcaster_test.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Success(t *testing.T) {
253253
FeeLimit: gasLimit,
254254
BroadcastAt: &timeNow,
255255
InitialBroadcastAt: &timeNow,
256+
ChainID: testutils.FixtureChainID,
256257
Error: null.String{},
257258
State: txmgrcommon.TxUnconfirmed,
258259
}
@@ -285,6 +286,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Success(t *testing.T) {
285286
FeeLimit: gasLimit,
286287
CreatedAt: time.Unix(0, 0),
287288
State: txmgrcommon.TxUnstarted,
289+
ChainID: testutils.FixtureChainID,
288290
}
289291
ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *gethTypes.Transaction) bool {
290292
return tx.Nonce() == uint64(2) && tx.Value().Cmp(big.NewInt(242)) == 0
@@ -304,6 +306,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Success(t *testing.T) {
304306
CreatedAt: time.Unix(0, 1),
305307
State: txmgrcommon.TxUnstarted,
306308
Meta: &meta,
309+
ChainID: testutils.FixtureChainID,
307310
}
308311
ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *gethTypes.Transaction) bool {
309312
if tx.Nonce() != uint64(0) {
@@ -327,6 +330,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Success(t *testing.T) {
327330
FeeLimit: gasLimit,
328331
CreatedAt: time.Unix(1, 0),
329332
State: txmgrcommon.TxUnstarted,
333+
ChainID: testutils.FixtureChainID,
330334
}
331335
ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *gethTypes.Transaction) bool {
332336
if tx.Nonce() != uint64(1) {
@@ -786,6 +790,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_ResumingFromCrash(t *testing.T) {
786790
FeeLimit: gasLimit,
787791
Error: null.String{},
788792
State: txmgrcommon.TxInProgress,
793+
ChainID: testutils.FixtureChainID,
789794
}
790795

791796
secondInProgress := txmgr.Tx{
@@ -797,6 +802,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_ResumingFromCrash(t *testing.T) {
797802
FeeLimit: gasLimit,
798803
Error: null.String{},
799804
State: txmgrcommon.TxInProgress,
805+
ChainID: testutils.FixtureChainID,
800806
}
801807

802808
require.NoError(t, txStore.InsertTx(ctx, &firstInProgress))
@@ -1162,6 +1168,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Errors(t *testing.T) {
11621168
State: txmgrcommon.TxUnstarted,
11631169
PipelineTaskRunID: uuid.NullUUID{UUID: trID, Valid: true},
11641170
SignalCallback: true,
1171+
ChainID: testutils.FixtureChainID,
11651172
}
11661173

11671174
t.Run("with erroring callback bails out", func(t *testing.T) {
@@ -1464,6 +1471,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Errors(t *testing.T) {
14641471
Value: value,
14651472
FeeLimit: gasLimit,
14661473
State: txmgrcommon.TxUnstarted,
1474+
ChainID: testutils.FixtureChainID,
14671475
}
14681476
require.NoError(t, txStore.InsertTx(ctx, &etxUnfinished))
14691477

@@ -1874,7 +1882,7 @@ func TestEthBroadcaster_NonceTracker_InProgressTx(t *testing.T) {
18741882
txStore := txmgrtest.NewTestTxStore(t, db)
18751883
memKS := keystest.NewMemoryChainStore()
18761884
fromAddress := memKS.MustCreate(t)
1877-
ethKeyStore := keys.NewChainStore(memKS, big.NewInt(0))
1885+
ethKeyStore := keys.NewChainStore(memKS, testutils.FixtureChainID)
18781886

18791887
ethClient := clienttest.NewClientWithDefaultChainID(t)
18801888
evmcfg := configtest.NewChainScopedConfig(t, nil)
@@ -1912,7 +1920,7 @@ func TestEthBroadcaster_HederaBroadcastValidation(t *testing.T) {
19121920
db := testutils.NewSqlxDB(t)
19131921
txStore := txmgrtest.NewTestTxStore(t, db)
19141922
memKS := keystest.NewMemoryChainStore()
1915-
ethKeyStore := keys.NewChainStore(memKS, big.NewInt(0))
1923+
ethKeyStore := keys.NewChainStore(memKS, testutils.FixtureChainID)
19161924
evmcfg := configtest.NewChainScopedConfig(t, nil)
19171925
ethClient := clienttest.NewClientWithDefaultChainID(t)
19181926
lggr, observed := logger.TestObserved(t, zapcore.DebugLevel)

0 commit comments

Comments
 (0)