|
|
@ -17,6 +17,7 @@ |
|
|
|
package simulated |
|
|
|
package simulated |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
|
|
|
|
"errors" |
|
|
|
"time" |
|
|
|
"time" |
|
|
|
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum" |
|
|
|
"github.com/ethereum/go-ethereum" |
|
|
@ -62,7 +63,7 @@ type simClient struct { |
|
|
|
// Backend is a simulated blockchain. You can use it to test your contracts or
|
|
|
|
// Backend is a simulated blockchain. You can use it to test your contracts or
|
|
|
|
// other code that interacts with the Ethereum chain.
|
|
|
|
// other code that interacts with the Ethereum chain.
|
|
|
|
type Backend struct { |
|
|
|
type Backend struct { |
|
|
|
eth *eth.Ethereum |
|
|
|
node *node.Node |
|
|
|
beacon *catalyst.SimulatedBeacon |
|
|
|
beacon *catalyst.SimulatedBeacon |
|
|
|
client simClient |
|
|
|
client simClient |
|
|
|
} |
|
|
|
} |
|
|
@ -129,7 +130,7 @@ func newWithNode(stack *node.Node, conf *eth.Config, blockPeriod uint64) (*Backe |
|
|
|
return nil, err |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
} |
|
|
|
return &Backend{ |
|
|
|
return &Backend{ |
|
|
|
eth: backend, |
|
|
|
node: stack, |
|
|
|
beacon: beacon, |
|
|
|
beacon: beacon, |
|
|
|
client: simClient{ethclient.NewClient(stack.Attach())}, |
|
|
|
client: simClient{ethclient.NewClient(stack.Attach())}, |
|
|
|
}, nil |
|
|
|
}, nil |
|
|
@ -142,12 +143,16 @@ func (n *Backend) Close() error { |
|
|
|
n.client.Close() |
|
|
|
n.client.Close() |
|
|
|
n.client = simClient{} |
|
|
|
n.client = simClient{} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
var err error |
|
|
|
if n.beacon != nil { |
|
|
|
if n.beacon != nil { |
|
|
|
err := n.beacon.Stop() |
|
|
|
err = n.beacon.Stop() |
|
|
|
n.beacon = nil |
|
|
|
n.beacon = nil |
|
|
|
return err |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
return nil |
|
|
|
if n.node != nil { |
|
|
|
|
|
|
|
err = errors.Join(err, n.node.Close()) |
|
|
|
|
|
|
|
n.node = nil |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Commit seals a block and moves the chain forward to a new empty block.
|
|
|
|
// Commit seals a block and moves the chain forward to a new empty block.
|
|
|
|