Skip to content

Commit

Permalink
ethclient/simulated: stop eth backend in Close
Browse files Browse the repository at this point in the history
  • Loading branch information
jwasinger committed Jan 14, 2025
1 parent 5372700 commit b16e65f
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions ethclient/simulated/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package simulated

import (
"errors"
"github.com/ethereum/go-ethereum/log"
"time"

"github.com/ethereum/go-ethereum"
Expand Down Expand Up @@ -62,9 +63,10 @@ type simClient struct {
// Backend is a simulated blockchain. You can use it to test your contracts or
// other code that interacts with the Ethereum chain.
type Backend struct {
node *node.Node
beacon *catalyst.SimulatedBeacon
client simClient
node *node.Node
beacon *catalyst.SimulatedBeacon
ethBackend *eth.Ethereum
client simClient
}

// NewBackend creates a new simulated blockchain that can be used as a backend for
Expand Down Expand Up @@ -129,9 +131,10 @@ func newWithNode(stack *node.Node, conf *eth.Config, blockPeriod uint64) (*Backe
return nil, err
}
return &Backend{
node: stack,
beacon: beacon,
client: simClient{ethclient.NewClient(stack.Attach())},
node: stack,
beacon: beacon,
ethBackend: backend,
client: simClient{ethclient.NewClient(stack.Attach())},
}, nil
}

Expand All @@ -147,6 +150,9 @@ func (n *Backend) Close() error {
err = n.beacon.Stop()
n.beacon = nil
}
if err := n.ethBackend.Stop(); err != nil {
log.Error("error stopping eth backend", "err", err)
}
if n.node != nil {
err = errors.Join(err, n.node.Close())
n.node = nil
Expand Down

0 comments on commit b16e65f

Please sign in to comment.