simulated

package
v1.13.14 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 27, 2024 License: GPL-3.0 Imports: 16 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithBlockGasLimit added in v1.13.11

func WithBlockGasLimit(gaslimit uint64) func(nodeConf *node.Config, ethConf *ethconfig.Config)

WithBlockGasLimit configures the simulated backend to target a specific gas limit when producing blocks.

func WithCallGasLimit added in v1.13.11

func WithCallGasLimit(gaslimit uint64) func(nodeConf *node.Config, ethConf *ethconfig.Config)

WithCallGasLimit configures the simulated backend to cap eth_calls to a specific gas limit when running client operations.

func WithMinerMinTip added in v1.13.12

func WithMinerMinTip(tip *big.Int) func(nodeConf *node.Config, ethConf *ethconfig.Config)

WithMinerMinTip configures the simulated backend to require a specific minimum gas tip for a transaction to be included.

0 is not possible as a live Geth node would reject that due to DoS protection, so the simulated backend will replicate that behavior for consistency.

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 NewBackend added in v1.13.11

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 (*Backend) AdjustTime

func (n *Backend) AdjustTime(adjustment time.Duration) error

AdjustTime changes the block timestamp and creates a new block. It can only be called on empty blocks.

func (*Backend) Client

func (n *Backend) Client() Client

Client returns a client that accesses the simulated chain.

func (*Backend) Close

func (n *Backend) Close() error

Close shuts down the simBackend. The simulated backend can't be used afterwards.

func (*Backend) Commit

func (n *Backend) Commit() common.Hash

Commit seals a block and moves the chain forward to a new empty block.

func (*Backend) Fork

func (n *Backend) Fork(parentHash common.Hash) error

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.

func (*Backend) Rollback

func (n *Backend) Rollback()

Rollback removes all pending transactions, reverting to the last committed state.

type Client

type Client interface {
	ethereum.BlockNumberReader
	ethereum.ChainReader
	ethereum.ChainStateReader
	ethereum.ContractCaller
	ethereum.GasEstimator
	ethereum.GasPricer
	ethereum.GasPricer1559
	ethereum.FeeHistoryReader
	ethereum.LogFilterer
	ethereum.PendingStateReader
	ethereum.PendingContractCaller
	ethereum.TransactionReader
	ethereum.TransactionSender
	ethereum.ChainIDReader
}

Client exposes the methods provided by the Ethereum RPC client.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL