Documentation ¶
Index ¶
- type Backend
- func (n *Backend) AdjustTime(adjustment time.Duration) error
- func (n *Backend) Client() *ethclient.Client
- func (n *Backend) Close() error
- func (n *Backend) Commit() common.Hash
- func (n *Backend) CommitAndExpectTx(txHash common.Hash) common.Hash
- func (n *Backend) Fork(parentHash common.Hash) error
- func (n *Backend) Rollback()
- type MineOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Backend ¶
type Backend struct {
// contains filtered or unexported fields
}
Backend is a simulated blockchain. You can use it to test your contracts or other code that interacts with the Ethereum chain.
func NewAutoMineBackend ¶
func NewAutoMineBackend(alloc types.GenesisAlloc, mineOption MineOption) *Backend
func NewBackend ¶
func NewBackend(alloc types.GenesisAlloc, options ...func(nodeConf *node.Config, ethConf *ethconfig.Config)) *Backend
NewBackend creates a new simulated blockchain that can be used as a backend for contract bindings in unit tests.
A simulated backend always uses chainID 1337.
func NewBackendFromConfig ¶
func (*Backend) AdjustTime ¶
AdjustTime changes the block timestamp and creates a new block. It can only be called on empty blocks.
func (*Backend) Close ¶
Close shuts down the simBackend. The simulated backend can't be used afterwards.
func (*Backend) CommitAndExpectTx ¶
func (*Backend) Fork ¶
Fork creates a side-chain that can be used to simulate reorgs.
This function should be called with the ancestor block where the new side chain should be started. Transactions (old and new) can then be applied on top and Commit-ed.
Note, the side-chain will only become canonical (and trigger the events) when it becomes longer. Until then CallContract will still operate on the current canonical chain.
There is a % chance that the side chain becomes canonical at the same length to simulate live network behavior.