Skip to content

Commit

Permalink
Fix lint errors, remove unused logpoller test definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
reductionista committed May 29, 2024
1 parent d78d549 commit 1a6e9ff
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 59 deletions.
46 changes: 2 additions & 44 deletions core/chains/evm/logpoller/log_poller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,49 +223,6 @@ func TestLogPoller_Integration(t *testing.T) {
assert.ErrorIs(t, th.LogPoller.Replay(ctx, 4), logpoller.ErrReplayRequestAborted)
}

type backendWrapper struct {
b *simulated.Backend
}

func (b backendWrapper) Client() simulated.Client {
return b.b.Client()
}

func (b backendWrapper) Close() error {
return b.b.Close()
}

func (b backendWrapper) Commit() common.Hash {
return b.b.Commit()
}

func (b backendWrapper) Rollback() {
b.b.Rollback()
}

func (b backendWrapper) Fork(parentHash common.Hash) error {
return b.b.Fork(parentHash)
}

func (b backendWrapper) AdjustTime(adjustment time.Duration) error {
return b.b.AdjustTime(adjustment)
}

// Behaves as primary simulated.Client until failoverBlockNumber is requested (via HeaderByNumber), then
// fails over to secondary simulated.Client.
type failoverClient struct {
primary simulated.Client
secondary simulated.Client
failoverBlockNumber *big.Int
}

func (f failoverClient) HeaderByNumber(ctx context.Context, n *big.Int) (*types.Header, error) {
if n.Cmp(f.failoverBlockNumber) < 0 {
return f.primary.HeaderByNumber(ctx, n)
}
return f.secondary.HeaderByNumber(ctx, n)
}

// Simulate an rpc failover event on optimism, where logs are requested from a block hash which doesn't
// exist on the new rpc server, but a successful error code is returned. This is bad/buggy behavior on the
// part of the rpc server, but we should be able to handle this without missing any logs, as
Expand Down Expand Up @@ -395,7 +352,7 @@ func Test_BackupLogPoller(t *testing.T) {

b, ok := primaryRpc.(*simulated.Backend)
require.True(t, ok)
th.SetActiveClient(backendWrapper{b}, evmtypes.Optimism) // restore primary rpc
th.SetActiveClient(b, evmtypes.Optimism) // restore primary rpc

// Run ordinary poller + backup poller at least once
require.NoError(t, err)
Expand Down Expand Up @@ -940,6 +897,7 @@ func TestLogPoller_PollAndSaveLogs(t *testing.T) {
th.assertHaveCanonical(t, 1, 3)

parent, err := th.Client.BlockByNumber(testutils.Context(t), big.NewInt(1))
require.NoError(t, err)

// Test scenario: reorg back to a chain that looks similar to the original chain. (simulated geth used to allow
// re-org'ing back to exactly the same chain--now the best we can do is re-emit the same logs on a new one to simulate that)
Expand Down
2 changes: 1 addition & 1 deletion core/chains/evm/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ type Backend interface {
Client() simulated.Client
}

type ChainFamily string
type ChainFamily uint

const (
Geth = ChainFamily(iota)
Expand Down
5 changes: 3 additions & 2 deletions core/internal/features/features_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
gethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/eth/ethconfig"
"github.com/ethereum/go-ethereum/ethclient/simulated"
"github.com/ethereum/go-ethereum/rpc"
Expand Down Expand Up @@ -298,7 +299,7 @@ type OperatorContracts struct {

func setupOperatorContracts(t *testing.T) OperatorContracts {
user := testutils.MustNewSimTransactor(t)
genesisData := types.GenesisAlloc{
genesisData := gethtypes.GenesisAlloc{
user.From: {Balance: assets.Ether(1000).ToInt()},
}
gasLimit := uint32(ethconfig.Defaults.Miner.GasCeil * 2)
Expand Down Expand Up @@ -639,7 +640,7 @@ func setupOCRContracts(t *testing.T) (*bind.TransactOpts, *simulated.Backend, co
owner := testutils.MustNewSimTransactor(t)
sb := new(big.Int)
sb, _ = sb.SetString("100000000000000000000000", 10) // 1000 eth
genesisData := types.GenesisAlloc{
genesisData := gethtypes.GenesisAlloc{
owner.From: {Balance: sb},
}
gasLimit := uint32(ethconfig.Defaults.Miner.GasCeil * 2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"time"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
Expand Down Expand Up @@ -177,19 +176,19 @@ func StartNewChainWithContracts(t *testing.T, nClients int) (*bind.TransactOpts,
sb, _ = sb.SetString("100000000000000000000", 10) // 1 eth
genesisData := types.GenesisAlloc{owner.From: {Balance: sb}}
gasLimit := ethconfig.Defaults.Miner.GasCeil * 2 // 60 M blocks
b := backends.NewSimulatedBackend(genesisData, gasLimit)
b := simulated.NewBackend(genesisData, simulated.WithBlockGasLimit(gasLimit))
b.Commit()

// Deploy LINK token
linkAddr, _, linkToken, err := link_token_interface.DeployLinkToken(owner, b)
linkAddr, _, linkToken, err := link_token_interface.DeployLinkToken(owner, b.Client())
require.NoError(t, err)

// Deploy mock LINK/ETH price feed
linkEthFeedAddr, _, _, err := mock_v3_aggregator_contract.DeployMockV3AggregatorContract(owner, b, 18, big.NewInt(5_000_000_000_000_000))
linkEthFeedAddr, _, _, err := mock_v3_aggregator_contract.DeployMockV3AggregatorContract(owner, b.Client(), 18, big.NewInt(5_000_000_000_000_000))
require.NoError(t, err)

// Deploy mock LINK/USD price feed
linkUsdFeedAddr, _, _, err := mock_v3_aggregator_contract.DeployMockV3AggregatorContract(owner, b, 18, big.NewInt(1_500_00_000))
linkUsdFeedAddr, _, _, err := mock_v3_aggregator_contract.DeployMockV3AggregatorContract(owner, b.Client(), 18, big.NewInt(1_500_00_000))
require.NoError(t, err)

// Deploy Router contract
Expand All @@ -206,7 +205,7 @@ func StartNewChainWithContracts(t *testing.T, nClients int) (*bind.TransactOpts,
SubscriptionDepositMinimumRequests: 10,
SubscriptionDepositJuels: big.NewInt(9 * 1e18), // 9 LINK
}
routerAddress, _, routerContract, err := functions_router.DeployFunctionsRouter(owner, b, linkAddr, functionsRouterConfig)
routerAddress, _, routerContract, err := functions_router.DeployFunctionsRouter(owner, b.Client(), linkAddr, functionsRouterConfig)
require.NoError(t, err)

// Deploy Allow List contract
Expand All @@ -219,7 +218,7 @@ func StartNewChainWithContracts(t *testing.T, nClients int) (*bind.TransactOpts,
}
var initialAllowedSenders []common.Address
var initialBlockedSenders []common.Address
allowListAddress, _, allowListContract, err := functions_allow_list.DeployTermsOfServiceAllowList(owner, b, allowListConfig, initialAllowedSenders, initialBlockedSenders)
allowListAddress, _, allowListContract, err := functions_allow_list.DeployTermsOfServiceAllowList(owner, b.Client(), allowListConfig, initialAllowedSenders, initialBlockedSenders)
require.NoError(t, err)

// Deploy Coordinator contract (matches updateConfig() in FunctionsBilling.sol)
Expand All @@ -238,15 +237,15 @@ func StartNewChainWithContracts(t *testing.T, nClients int) (*bind.TransactOpts,
FallbackUsdPerUnitLinkDecimals: uint8(8),
}
require.NoError(t, err)
coordinatorAddress, _, coordinatorContract, err := functions_coordinator.DeployFunctionsCoordinator(owner, b, routerAddress, coordinatorConfig, linkEthFeedAddr, linkUsdFeedAddr)
coordinatorAddress, _, coordinatorContract, err := functions_coordinator.DeployFunctionsCoordinator(owner, b.Client(), routerAddress, coordinatorConfig, linkEthFeedAddr, linkUsdFeedAddr)
require.NoError(t, err)
proposalAddress, _, proposalContract, err := functions_coordinator.DeployFunctionsCoordinator(owner, b, routerAddress, coordinatorConfig, linkEthFeedAddr, linkUsdFeedAddr)
proposalAddress, _, proposalContract, err := functions_coordinator.DeployFunctionsCoordinator(owner, b.Client(), routerAddress, coordinatorConfig, linkEthFeedAddr, linkUsdFeedAddr)
require.NoError(t, err)

// Deploy Client contracts
clientContracts := []deployedClientContract{}
for i := 0; i < nClients; i++ {
clientContractAddress, _, clientContract, err := functions_client_example.DeployFunctionsClientExample(owner, b, routerAddress)
clientContractAddress, _, clientContract, err := functions_client_example.DeployFunctionsClientExample(owner, b.Client(), routerAddress)
require.NoError(t, err)
clientContracts = append(clientContracts, deployedClientContract{
Address: clientContractAddress,
Expand All @@ -258,7 +257,7 @@ func StartNewChainWithContracts(t *testing.T, nClients int) (*bind.TransactOpts,
}
}

CommitWithFinality(b.Backend)
CommitWithFinality(b)
ticker := time.NewTicker(1 * time.Second)
go func() {
for range ticker.C {
Expand All @@ -274,7 +273,7 @@ func StartNewChainWithContracts(t *testing.T, nClients int) (*bind.TransactOpts,
Contract: proposalContract,
Address: proposalAddress,
}
return owner, b.Backend, ticker, active, proposed, clientContracts, routerAddress, routerContract, linkToken, allowListAddress, allowListContract
return owner, b, ticker, active, proposed, clientContracts, routerAddress, routerContract, linkToken, allowListAddress, allowListContract
}

func SetupRouterRoutes(t *testing.T, b *simulated.Backend, owner *bind.TransactOpts, routerContract *functions_router.FunctionsRouter, coordinatorAddress common.Address, proposedCoordinatorAddress common.Address, allowListAddress common.Address) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

gethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethclient/simulated"

"github.com/smartcontractkit/chainlink-automation/pkg/v3/types"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
Expand Down

0 comments on commit 1a6e9ff

Please sign in to comment.