Skip to content

Commit

Permalink
Merge branch 'develop' into verify-single-payment-token
Browse files Browse the repository at this point in the history
  • Loading branch information
austinborn authored Sep 14, 2023
2 parents c575c18 + c9e080b commit 985c17e
Show file tree
Hide file tree
Showing 85 changed files with 496 additions and 483 deletions.
19 changes: 2 additions & 17 deletions core/chains/evm/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ type LegacyChains struct {
//
//go:generate mockery --quiet --name LegacyChainContainer --output ./mocks/ --case=underscore
type LegacyChainContainer interface {
SetDefault(Chain)
Default() (Chain, error)
Get(id string) (Chain, error)
Len() int
List(ids ...string) ([]Chain, error)
Expand All @@ -100,27 +98,14 @@ func (c *LegacyChains) ChainNodeConfigs() evmtypes.Configs {
return c.cfgs
}

// TODO BCR-2510 this may not be needed if EVM is not enabled by default
func (c *LegacyChains) SetDefault(dflt Chain) {
c.dflt = dflt
}

func (c *LegacyChains) Default() (Chain, error) {
if c.dflt == nil {
return nil, fmt.Errorf("no default chain specified")
}
return c.dflt, nil
}

// backward compatibility.
// eth keys are represented as multiple types in the code base;
// *big.Int, string, and int64. this lead to special 'default' handling
// of nil big.Int and empty string.
// *big.Int, string, and int64.
//
// TODO BCF-2507 unify the type system
func (c *LegacyChains) Get(id string) (Chain, error) {
if id == nilBigInt.String() || id == emptyString {
return c.Default()
return nil, fmt.Errorf("invalid chain id requested: %q", id)
}
return c.ChainsKV.Get(id)
}
Expand Down
18 changes: 0 additions & 18 deletions core/chains/evm/config/mocks/chain_scoped_config.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions core/chains/evm/headtracker/head_tracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ func TestHeadTracker_SwitchesToLongestChainWithHeadSamplingEnabled(t *testing.T)
ethClient := evmtest.NewEthClientMockWithDefaultChain(t)

checker := commonmocks.NewHeadTrackable[*evmtypes.Head, gethCommon.Hash](t)
orm := headtracker.NewORM(db, logger, config.Database(), *config.DefaultChainID())
orm := headtracker.NewORM(db, logger, config.Database(), *evmtest.MustGetDefaultChainID(t, config.EVMConfigs()))
csCfg := evmtest.NewChainScopedConfig(t, config)
ht := createHeadTrackerWithChecker(t, ethClient, csCfg.EVM(), csCfg.EVM().HeadTracker(), orm, checker)

Expand Down Expand Up @@ -779,7 +779,7 @@ func TestHeadTracker_Backfill(t *testing.T) {
}

ethClient := evmtest.NewEthClientMock(t)
ethClient.On("ConfiguredChainID", mock.Anything).Return(cfg.DefaultChainID(), nil)
ethClient.On("ConfiguredChainID", mock.Anything).Return(evmtest.MustGetDefaultChainID(t, cfg.EVMConfigs()), nil)
ht := createHeadTrackerWithNeverSleeper(t, ethClient, cfg, orm)

err := ht.Backfill(ctx, &h12, 2)
Expand All @@ -796,7 +796,7 @@ func TestHeadTracker_Backfill(t *testing.T) {
}

ethClient := evmtest.NewEthClientMock(t)
ethClient.On("ConfiguredChainID", mock.Anything).Return(cfg.DefaultChainID(), nil)
ethClient.On("ConfiguredChainID", mock.Anything).Return(evmtest.MustGetDefaultChainID(t, cfg.EVMConfigs()), nil)
ethClient.On("HeadByHash", mock.Anything, head10.Hash).
Return(&head10, nil)

Expand Down Expand Up @@ -832,7 +832,7 @@ func TestHeadTracker_Backfill(t *testing.T) {
}

ethClient := evmtest.NewEthClientMock(t)
ethClient.On("ConfiguredChainID", mock.Anything).Return(cfg.DefaultChainID(), nil)
ethClient.On("ConfiguredChainID", mock.Anything).Return(evmtest.MustGetDefaultChainID(t, cfg.EVMConfigs()), nil)

ht := createHeadTrackerWithNeverSleeper(t, ethClient, cfg, orm)

Expand Down Expand Up @@ -865,7 +865,7 @@ func TestHeadTracker_Backfill(t *testing.T) {
}

ethClient := evmtest.NewEthClientMock(t)
ethClient.On("ConfiguredChainID", mock.Anything).Return(cfg.DefaultChainID(), nil)
ethClient.On("ConfiguredChainID", mock.Anything).Return(evmtest.MustGetDefaultChainID(t, cfg.EVMConfigs()), nil)

ht := createHeadTrackerWithNeverSleeper(t, ethClient, cfg, orm)

Expand All @@ -883,7 +883,7 @@ func TestHeadTracker_Backfill(t *testing.T) {
orm := headtracker.NewORM(db, logger, cfg.Database(), cltest.FixtureChainID)

ethClient := evmtest.NewEthClientMock(t)
ethClient.On("ConfiguredChainID", mock.Anything).Return(cfg.DefaultChainID(), nil)
ethClient.On("ConfiguredChainID", mock.Anything).Return(evmtest.MustGetDefaultChainID(t, cfg.EVMConfigs()), nil)
ethClient.On("HeadByHash", mock.Anything, head0.Hash).
Return(&head0, nil)

Expand Down Expand Up @@ -911,7 +911,7 @@ func TestHeadTracker_Backfill(t *testing.T) {
}

ethClient := evmtest.NewEthClientMock(t)
ethClient.On("ConfiguredChainID", mock.Anything).Return(cfg.DefaultChainID(), nil)
ethClient.On("ConfiguredChainID", mock.Anything).Return(evmtest.MustGetDefaultChainID(t, cfg.EVMConfigs()), nil)
ethClient.On("HeadByHash", mock.Anything, head10.Hash).
Return(&head10, nil).
Once()
Expand Down Expand Up @@ -942,7 +942,7 @@ func TestHeadTracker_Backfill(t *testing.T) {
}

ethClient := evmtest.NewEthClientMock(t)
ethClient.On("ConfiguredChainID", mock.Anything).Return(cfg.DefaultChainID(), nil)
ethClient.On("ConfiguredChainID", mock.Anything).Return(evmtest.MustGetDefaultChainID(t, cfg.EVMConfigs()), nil)
ethClient.On("HeadByHash", mock.Anything, head10.Hash).
Return(&head10, nil)
ethClient.On("HeadByHash", mock.Anything, head8.Hash).
Expand All @@ -967,7 +967,7 @@ func TestHeadTracker_Backfill(t *testing.T) {
logger := logger.TestLogger(t)
orm := headtracker.NewORM(db, logger, cfg.Database(), cltest.FixtureChainID)
ethClient := evmtest.NewEthClientMock(t)
ethClient.On("ConfiguredChainID", mock.Anything).Return(cfg.DefaultChainID(), nil)
ethClient.On("ConfiguredChainID", mock.Anything).Return(evmtest.MustGetDefaultChainID(t, cfg.EVMConfigs()), nil)
ethClient.On("HeadByHash", mock.Anything, h14.Hash).Return(&h14, nil).Once()
ethClient.On("HeadByHash", mock.Anything, h13.Hash).Return(&h13, nil).Once()
ethClient.On("HeadByHash", mock.Anything, h12.Hash).Return(nil, errors.New("not found")).Once()
Expand Down
31 changes: 0 additions & 31 deletions core/chains/evm/mocks/legacy_chain_container.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/chains/evm/txmgr/evm_tx_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ 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(fromAddress, testutils.SimulatedChainID))
require.NoError(t, ethKeyStore.Enable(fromAddress, testutils.SimulatedChainID))
etxThisChain := cltest.MustInsertUnconfirmedEthTxWithBroadcastLegacyAttempt(t, txStore, 1, fromAddress, cfg.DefaultChainID())
etxThisChain := cltest.MustInsertUnconfirmedEthTxWithBroadcastLegacyAttempt(t, txStore, 1, fromAddress, cfg.EVM().ChainID())
etxOtherChain := cltest.MustInsertUnconfirmedEthTxWithBroadcastLegacyAttempt(t, txStore, 0, fromAddress, testutils.SimulatedChainID)

require.NoError(t, txStore.SetBroadcastBeforeBlockNum(headNum, chainID))
Expand Down
31 changes: 15 additions & 16 deletions core/cmd/eth_keys_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/assets"
"github.com/smartcontractkit/chainlink/v2/core/cmd"
"github.com/smartcontractkit/chainlink/v2/core/internal/cltest"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils"
"github.com/smartcontractkit/chainlink/v2/core/services/chainlink"
"github.com/smartcontractkit/chainlink/v2/core/utils"
"github.com/smartcontractkit/chainlink/v2/core/web/presenters"
Expand Down Expand Up @@ -182,28 +183,21 @@ func TestShell_CreateETHKey(t *testing.T) {
require.NoError(t, err)
require.Equal(t, 1, len(keys))

// create a key on the default chain
set := flag.NewFlagSet("test", 0)
cltest.FlagSetApplyFromAction(client.CreateETHKey, set, "")
c := cli.NewContext(nil, set, nil)
assert.NoError(t, client.CreateETHKey(c))

// create the key on a specific chainID
id := big.NewInt(0)

set = flag.NewFlagSet("test", 0)
set := flag.NewFlagSet("test", 0)
cltest.FlagSetApplyFromAction(client.CreateETHKey, set, "")

require.NoError(t, set.Set("evmChainID", ""))
require.NoError(t, set.Set("evm-chain-id", testutils.FixtureChainID.String()))

c = cli.NewContext(nil, set, nil)
require.NoError(t, set.Parse([]string{"-evmChainID", id.String()}))
c := cli.NewContext(nil, set, nil)
require.NoError(t, set.Parse([]string{"-evm-chain-id", id.String()}))
assert.NoError(t, client.CreateETHKey(c))

cltest.AssertCount(t, db, "evm.key_states", 3)
cltest.AssertCount(t, db, "evm.key_states", 2)
keys, err = app.KeyStore.Eth().GetAll()
require.NoError(t, err)
require.Equal(t, 3, len(keys))
require.Equal(t, 2, len(keys))
}

func TestShell_DeleteETHKey(t *testing.T) {
Expand Down Expand Up @@ -308,9 +302,12 @@ func TestShell_ImportExportETHKey_NoChains(t *testing.T) {

// Import the key
set = flag.NewFlagSet("test", 0)
set.String("old-password", "../internal/fixtures/incorrect_password.txt", "")
err = set.Parse([]string{keyfilepath})
require.NoError(t, err)
cltest.FlagSetApplyFromAction(client.ImportETHKey, set, "")

require.NoError(t, set.Set("evmChainID", testutils.FixtureChainID.String()))
require.NoError(t, set.Set("old-password", "../internal/fixtures/incorrect_password.txt"))
require.NoError(t, set.Parse([]string{keyfilepath}))

c = cli.NewContext(nil, set, nil)
err = client.ImportETHKey(c)
require.NoError(t, err)
Expand Down Expand Up @@ -412,6 +409,8 @@ func TestShell_ImportExportETHKey_WithChains(t *testing.T) {
set = flag.NewFlagSet("test", 0)
cltest.FlagSetApplyFromAction(client.ImportETHKey, set, "")

require.NoError(t, set.Set("evmChainID", testutils.FixtureChainID.String()))
require.NoError(t, set.Set("evmChainID", testutils.FixtureChainID.String()))
require.NoError(t, set.Set("old-password", "../internal/fixtures/incorrect_password.txt"))
require.NoError(t, set.Parse([]string{keyfilepath}))

Expand Down
4 changes: 4 additions & 0 deletions core/cmd/evm_transaction_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (
evmtypes "github.com/smartcontractkit/chainlink/v2/core/chains/evm/types"
"github.com/smartcontractkit/chainlink/v2/core/cmd"
"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/services/chainlink"
"github.com/smartcontractkit/chainlink/v2/core/store/models"
)
Expand Down Expand Up @@ -160,6 +162,7 @@ func TestShell_SendEther_From_Txm(t *testing.T) {
amount := "100.5"
to := "0x342156c8d3bA54Abc67920d35ba1d1e67201aC9C"
require.NoError(t, set.Parse([]string{amount, fromAddress.Hex(), to}))
require.NoError(t, set.Set("id", evmtest.MustGetDefaultChainID(t, app.Config.EVMConfigs()).String()))

cliapp := cli.NewApp()
c := cli.NewContext(cliapp, set, nil)
Expand Down Expand Up @@ -215,6 +218,7 @@ func TestShell_SendEther_From_Txm_WEI(t *testing.T) {
set := flag.NewFlagSet("sendether", 0)
cltest.FlagSetApplyFromAction(client.SendEther, set, "")

require.NoError(t, set.Set("id", testutils.FixtureChainID.String()))
require.NoError(t, set.Set("wei", "false"))

amount := "1000000000000000000"
Expand Down
4 changes: 2 additions & 2 deletions core/cmd/forwarders_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func TestShell_TrackEVMForwarder(t *testing.T) {
cltest.FlagSetApplyFromAction(client.TrackForwarder, set, "")

require.NoError(t, set.Set("address", "0x5431F5F973781809D18643b87B44921b11355d81"))
require.NoError(t, set.Set("evmChainID", id.String()))
require.NoError(t, set.Set("evm-chain-id", id.String()))

err := client.TrackForwarder(cli.NewContext(nil, set, nil))
require.NoError(t, err)
Expand Down Expand Up @@ -122,7 +122,7 @@ func TestShell_TrackEVMForwarder_BadAddress(t *testing.T) {
cltest.FlagSetApplyFromAction(client.TrackForwarder, set, "")

require.NoError(t, set.Set("address", "0xWrongFormatAddress"))
require.NoError(t, set.Set("evmChainID", id.String()))
require.NoError(t, set.Set("evm-chain-id", id.String()))

err := client.TrackForwarder(cli.NewContext(nil, set, nil))
require.Contains(t, err.Error(), "could not decode address: invalid hex string")
Expand Down
12 changes: 0 additions & 12 deletions core/cmd/shell_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,18 +375,6 @@ func (s *Shell) runNode(c *cli.Context) error {

legacyEVMChains := app.GetRelayers().LegacyEVMChains()

// By passing in a function we can be lazy trying to look up a default
// chain - if there are no existing keys, there is no need to check for
// a chain ID
DefaultEVMChainIDFunc := func() (*big.Int, error) {
def, err2 := legacyEVMChains.Default()
if err2 != nil {
return nil, errors.Wrap(err2, "cannot get default EVM chain ID; no default EVM chain available")
}
return def.ID(), nil
}
err = keyStore.Migrate(s.Config.Password().VRF(), DefaultEVMChainIDFunc)

if s.Config.EVMEnabled() {
if err != nil {
return errors.Wrap(err, "error migrating keystore")
Expand Down
3 changes: 3 additions & 0 deletions core/cmd/shell_local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ func TestShell_RebroadcastTransactions_Txm(t *testing.T) {
set := flag.NewFlagSet("test", 0)
cltest.FlagSetApplyFromAction(client.RebroadcastTransactions, set, "")

require.NoError(t, set.Set("evmChainID", testutils.FixtureChainID.String()))
require.NoError(t, set.Set("beginningNonce", strconv.FormatUint(beginningNonce, 10)))
require.NoError(t, set.Set("endingNonce", strconv.FormatUint(endingNonce, 10)))
require.NoError(t, set.Set("gasPriceWei", "100000000000"))
Expand Down Expand Up @@ -402,6 +403,7 @@ func TestShell_RebroadcastTransactions_OutsideRange_Txm(t *testing.T) {
set := flag.NewFlagSet("test", 0)
cltest.FlagSetApplyFromAction(client.RebroadcastTransactions, set, "")

require.NoError(t, set.Set("evmChainID", testutils.FixtureChainID.String()))
require.NoError(t, set.Set("beginningNonce", strconv.FormatUint(uint64(beginningNonce), 10)))
require.NoError(t, set.Set("endingNonce", strconv.FormatUint(uint64(endingNonce), 10)))
require.NoError(t, set.Set("gasPriceWei", gasPrice.String()))
Expand Down Expand Up @@ -482,6 +484,7 @@ func TestShell_RebroadcastTransactions_AddressCheck(t *testing.T) {
set := flag.NewFlagSet("test", 0)
cltest.FlagSetApplyFromAction(client.RebroadcastTransactions, set, "")

require.NoError(t, set.Set("evmChainID", testutils.FixtureChainID.String()))
require.NoError(t, set.Set("address", fromAddress.Hex()))
require.NoError(t, set.Set("password", "../internal/fixtures/correct_password.txt"))
c := cli.NewContext(nil, set, nil)
Expand Down
6 changes: 1 addition & 5 deletions core/cmd/shell_remote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,8 @@ func TestShell_ReplayBlocks(t *testing.T) {
cltest.FlagSetApplyFromAction(client.ReplayFromBlock, set, "")

require.NoError(t, set.Set("block-number", "42"))

c := cli.NewContext(nil, set, nil)
assert.NoError(t, client.ReplayFromBlock(c))

require.NoError(t, set.Set("evm-chain-id", "12345678"))
c = cli.NewContext(nil, set, nil)
c := cli.NewContext(nil, set, nil)
assert.ErrorContains(t, client.ReplayFromBlock(c), "chain id does not match any local chains")

require.NoError(t, set.Set("evm-chain-id", "0"))
Expand Down
2 changes: 0 additions & 2 deletions core/config/app_config.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package config

import (
"math/big"
"time"

"github.com/google/uuid"
Expand All @@ -21,7 +20,6 @@ type AppConfig interface {
RootDir() string
ShutdownGracePeriod() time.Duration
InsecureFastScrypt() bool
DefaultChainID() *big.Int
EVMEnabled() bool
EVMRPCEnabled() bool
CosmosEnabled() bool
Expand Down
9 changes: 0 additions & 9 deletions core/config/ethereum_config.go

This file was deleted.

Loading

0 comments on commit 985c17e

Please sign in to comment.