Skip to content

Commit

Permalink
Update keeper integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
reductionista committed May 15, 2024
1 parent 81aa9b7 commit d31bfda
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
22 changes: 11 additions & 11 deletions core/internal/cltest/simulated_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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() {
Expand All @@ -29,18 +29,18 @@ 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())
}

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)

Expand All @@ -55,18 +55,18 @@ 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())
}

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)

Expand All @@ -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{}
Expand Down
3 changes: 2 additions & 1 deletion core/services/keeper/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()},
Expand Down

0 comments on commit d31bfda

Please sign in to comment.