From d31bfda0f86bcc0bd814f5ff5fc9da282c9fed1c Mon Sep 17 00:00:00 2001 From: Domino Valdano <2644901+reductionista@users.noreply.github.com> Date: Tue, 14 May 2024 21:04:52 -0700 Subject: [PATCH] Update keeper integration tests --- core/internal/cltest/simulated_backend.go | 22 +++++++++++----------- core/services/keeper/integration_test.go | 3 ++- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/core/internal/cltest/simulated_backend.go b/core/internal/cltest/simulated_backend.go index b3714208547..3637adbd2dc 100644 --- a/core/internal/cltest/simulated_backend.go +++ b/core/internal/cltest/simulated_backend.go @@ -5,8 +5,8 @@ import ( "testing" "time" - "github.com/ethereum/go-ethereum/accounts/abi/bind/backends" - "github.com/ethereum/go-ethereum/core" + "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/ethclient/simulated" "github.com/stretchr/testify/require" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/client" @@ -17,8 +17,8 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/services/chainlink" ) -func NewSimulatedBackend(t *testing.T, alloc core.GenesisAlloc, gasLimit uint32) *backends.SimulatedBackend { - backend := backends.NewSimulatedBackend(alloc, uint64(gasLimit)) +func NewSimulatedBackend(t *testing.T, alloc types.GenesisAlloc, gasLimit uint32) *simulated.Backend { + backend := simulated.NewBackend(alloc, simulated.WithBlockGasLimit(uint64(gasLimit))) // NOTE: Make sure to finish closing any application/client before // backend.Close or they can hang t.Cleanup(func() { @@ -29,10 +29,10 @@ func NewSimulatedBackend(t *testing.T, alloc core.GenesisAlloc, gasLimit uint32) func NewApplicationWithConfigV2OnSimulatedBlockchain( t testing.TB, cfg chainlink.GeneralConfig, - backend *backends.SimulatedBackend, + backend *simulated.Backend, flagsAndDeps ...interface{}, ) *TestApplication { - bid, err := backend.ChainID(testutils.Context(t)) + bid, err := backend.Client().ChainID(testutils.Context(t)) require.NoError(t, err) if bid.Cmp(testutils.SimulatedChainID) != 0 { t.Fatalf("expected backend chain ID to be %s but it was %s", testutils.SimulatedChainID.String(), bid.String()) @@ -40,7 +40,7 @@ func NewApplicationWithConfigV2OnSimulatedBlockchain( require.Zero(t, evmtest.MustGetDefaultChainID(t, cfg.EVMConfigs()).Cmp(testutils.SimulatedChainID)) chainID := big.New(testutils.SimulatedChainID) - client := client.NewSimulatedBackendClient(t, backend.Backend, testutils.SimulatedChainID) + client := client.NewSimulatedBackendClient(t, backend, testutils.SimulatedChainID) flagsAndDeps = append(flagsAndDeps, client, chainID) @@ -55,10 +55,10 @@ func NewApplicationWithConfigV2OnSimulatedBlockchain( func NewApplicationWithConfigV2AndKeyOnSimulatedBlockchain( t testing.TB, cfg chainlink.GeneralConfig, - backend *backends.SimulatedBackend, + backend *simulated.Backend, flagsAndDeps ...interface{}, ) *TestApplication { - bid, err := backend.ChainID(testutils.Context(t)) + bid, err := backend.Client().ChainID(testutils.Context(t)) require.NoError(t, err) if bid.Cmp(testutils.SimulatedChainID) != 0 { t.Fatalf("expected backend chain ID to be %s but it was %s", testutils.SimulatedChainID.String(), bid.String()) @@ -66,7 +66,7 @@ func NewApplicationWithConfigV2AndKeyOnSimulatedBlockchain( require.Zero(t, evmtest.MustGetDefaultChainID(t, cfg.EVMConfigs()).Cmp(testutils.SimulatedChainID)) chainID := big.New(testutils.SimulatedChainID) - client := client.NewSimulatedBackendClient(t, backend.Backend, testutils.SimulatedChainID) + client := client.NewSimulatedBackendClient(t, backend, testutils.SimulatedChainID) flagsAndDeps = append(flagsAndDeps, client, chainID) @@ -75,7 +75,7 @@ func NewApplicationWithConfigV2AndKeyOnSimulatedBlockchain( } // Mine forces the simulated backend to produce a new block every X seconds -func Mine(backend *backends.SimulatedBackend, blockTime time.Duration) (stopMining func()) { +func Mine(backend *simulated.Backend, blockTime time.Duration) (stopMining func()) { timer := time.NewTicker(blockTime) chStop := make(chan struct{}) wg := sync.WaitGroup{} diff --git a/core/services/keeper/integration_test.go b/core/services/keeper/integration_test.go index 9e4cf5f9041..dc68d896649 100644 --- a/core/services/keeper/integration_test.go +++ b/core/services/keeper/integration_test.go @@ -17,6 +17,7 @@ import ( "github.com/stretchr/testify/require" commonconfig "github.com/smartcontractkit/chainlink-common/pkg/config" + "github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/client" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/forwarders" @@ -189,7 +190,7 @@ func TestKeeperEthIntegration(t *testing.T) { carrol := testutils.MustNewSimTransactor(t) // client nelly := testutils.MustNewSimTransactor(t) // other keeper operator 1 nick := testutils.MustNewSimTransactor(t) // other keeper operator 2 - genesisData := core.GenesisAlloc{ + genesisData := types.GenesisAlloc{ sergey.From: {Balance: assets.Ether(1000).ToInt()}, steve.From: {Balance: assets.Ether(1000).ToInt()}, carrol.From: {Balance: assets.Ether(1000).ToInt()},