accounts/abi/bind/backends: fix review comments

This commit is contained in:
Marius van der Wijden 2023-12-01 11:59:20 +01:00
parent b608a39b2f
commit cb549c9455

View file

@ -28,7 +28,6 @@ import (
"github.com/ethereum/go-ethereum/eth/ethconfig" "github.com/ethereum/go-ethereum/eth/ethconfig"
"github.com/ethereum/go-ethereum/eth/filters" "github.com/ethereum/go-ethereum/eth/filters"
"github.com/ethereum/go-ethereum/ethclient" "github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/node" "github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
@ -48,10 +47,10 @@ type SimulatedBackend struct {
// A simulated backend always uses chainID 1337. // A simulated backend always uses chainID 1337.
func NewSimulatedBackend(alloc core.GenesisAlloc, gasLimit uint64) *SimulatedBackend { func NewSimulatedBackend(alloc core.GenesisAlloc, gasLimit uint64) *SimulatedBackend {
// Setup the node object // Setup the node object
nodeConf := &node.DefaultConfig nodeConf := node.DefaultConfig
nodeConf.DataDir = "" nodeConf.DataDir = ""
nodeConf.P2P = p2p.Config{DiscAddr: "", ListenAddr: ""} nodeConf.P2P = p2p.Config{DiscAddr: "", ListenAddr: ""}
stack, err := node.New(nodeConf) stack, err := node.New(&nodeConf)
if err != nil { if err != nil {
// This should never happen, if it does, please open an issue // This should never happen, if it does, please open an issue
panic(err) panic(err)
@ -63,10 +62,10 @@ func NewSimulatedBackend(alloc core.GenesisAlloc, gasLimit uint64) *SimulatedBac
GasLimit: gasLimit, GasLimit: gasLimit,
Alloc: alloc, Alloc: alloc,
} }
conf := &ethconfig.Defaults conf := ethconfig.Defaults
conf.Genesis = &genesis conf.Genesis = &genesis
conf.SyncMode = downloader.FullSync conf.SyncMode = downloader.FullSync
sim, err := NewSimWithNode(stack, conf, math.MaxUint64) sim, err := NewSimWithNode(stack, &conf, math.MaxUint64)
if err != nil { if err != nil {
// This should never happen, if it does, please open an issue // This should never happen, if it does, please open an issue
panic(err) panic(err)
@ -76,6 +75,7 @@ func NewSimulatedBackend(alloc core.GenesisAlloc, gasLimit uint64) *SimulatedBac
// NewSimWithNode sets up a simulated backend on an existing node // NewSimWithNode sets up a simulated backend on an existing node
// this allows users to do persistent simulations. // this allows users to do persistent simulations.
// The provided node must not be started and will be started by NewSimWithNode
func NewSimWithNode(stack *node.Node, conf *eth.Config, blockPeriod uint64) (*SimulatedBackend, error) { func NewSimWithNode(stack *node.Node, conf *eth.Config, blockPeriod uint64) (*SimulatedBackend, error) {
backend, err := eth.New(stack, conf) backend, err := eth.New(stack, conf)
if err != nil { if err != nil {
@ -113,16 +113,14 @@ func NewSimWithNode(stack *node.Node, conf *eth.Config, blockPeriod uint64) (*Si
} }
func (n *SimulatedBackend) Close() error { func (n *SimulatedBackend) Close() error {
n.Client.Close() if n.Client != nil {
return n.SimulatedBeacon.Stop() n.Client.Close()
} n.Client = nil
}
// Blockchain is needed for LES-tests if n.SimulatedBeacon != nil {
func (n *SimulatedBackend) Blockchain() *core.BlockChain { err := n.SimulatedBeacon.Stop()
return n.eth.BlockChain() n.SimulatedBeacon = nil
} return err
}
// ChainDB is needed for LES-tests return nil
func (n *SimulatedBackend) ChainDB() ethdb.Database {
return n.eth.ChainDb()
} }