Documentation ¶
Index ¶
- Variables
- type BlocksRemovedEvent
- type CheatCodeContract
- type ContractDeploymentsAddedEvent
- type ContractDeploymentsRemovedEvent
- type PendingBlockAddedTxEvent
- type PendingBlockCommittedEvent
- type PendingBlockCreatedEvent
- type PendingBlockDiscardedEvent
- type TestChain
- func (t *TestChain) AddTracer(tracer *TestChainTracer, txs bool, calls bool)
- func (t *TestChain) BlockFromNumber(blockNumber uint64) (*chainTypes.Block, error)
- func (t *TestChain) BlockHashFromNumber(blockNumber uint64) (common.Hash, error)
- func (t *TestChain) CallContract(msg *core.Message, state *state.StateDB, additionalTracers ...*TestChainTracer) (*core.ExecutionResult, error)
- func (t *TestChain) CheatCodeContracts() map[common.Address]*CheatCodeContract
- func (t *TestChain) Clone(onCreateFunc func(chain *TestChain) error) (*TestChain, error)
- func (t *TestChain) Close()
- func (t *TestChain) CommittedBlocks() []*chainTypes.Block
- func (t *TestChain) GenesisDefinition() *core.Genesis
- func (t *TestChain) Head() *chainTypes.Block
- func (t *TestChain) HeadBlockNumber() uint64
- func (t *TestChain) PendingBlock() *chainTypes.Block
- func (t *TestChain) PendingBlockAddTx(message *core.Message, additionalTracers ...*TestChainTracer) error
- func (t *TestChain) PendingBlockCommit() error
- func (t *TestChain) PendingBlockCreate() (*chainTypes.Block, error)
- func (t *TestChain) PendingBlockCreateWithParameters(blockNumber uint64, blockTime uint64, blockGasLimit *uint64) (*chainTypes.Block, error)
- func (t *TestChain) PendingBlockDiscard() error
- func (t *TestChain) RevertToBlockNumber(blockNumber uint64) error
- func (t *TestChain) State() *state.StateDB
- func (t *TestChain) StateAfterBlockNumber(blockNumber uint64) (*state.StateDB, error)
- func (t *TestChain) StateFromRoot(root common.Hash) (*state.StateDB, error)
- func (t *TestChain) StateRootAfterBlockNumber(blockNumber uint64) (common.Hash, error)
- type TestChainEvents
- type TestChainTracer
- type TestChainTracerRouter
- func (t *TestChainTracerRouter) AddTracer(tracer *TestChainTracer)
- func (t *TestChainTracerRouter) AddTracers(tracers ...*TestChainTracer)
- func (t *TestChainTracerRouter) CaptureTxEndSetAdditionalResults(results *types.MessageResults)
- func (t *TestChainTracerRouter) NativeTracer() *TestChainTracer
- func (t *TestChainTracerRouter) OnCodeChange(a common.Address, prevCodeHash common.Hash, prev []byte, codeHash common.Hash, ...)
- func (t *TestChainTracerRouter) OnEnter(depth int, typ byte, from common.Address, to common.Address, input []byte, ...)
- func (t *TestChainTracerRouter) OnExit(depth int, output []byte, gasUsed uint64, err error, reverted bool)
- func (t *TestChainTracerRouter) OnFault(pc uint64, op byte, gas, cost uint64, scope *vm.ScopeContext, depth int, ...)
- func (t *TestChainTracerRouter) OnOpcode(pc uint64, op byte, gas, cost uint64, scope tracing.OpContext, rData []byte, ...)
- func (t *TestChainTracerRouter) OnTxEnd(receipt *coretypes.Receipt, err error)
- func (t *TestChainTracerRouter) OnTxStart(vm *tracing.VMContext, tx *coretypes.Transaction, from common.Address)
- func (t *TestChainTracerRouter) Tracers() []*TestChainTracer
Constants ¶
This section is empty.
Variables ¶
var ConsoleLogContractAddress = common.HexToAddress("0x000000000000000000636F6e736F6c652e6c6f67")
ConsoleLogContractAddress is the address for the console.log precompile contract
var StandardCheatcodeContractAddress = common.HexToAddress("0x7109709ECfa91a80626fF3989D68f67F5b1DD12D")
StandardCheatcodeContractAddress is the address for the standard cheatcode contract
var _, MaxUint64 = utils.GetIntegerConstraints(false, 64)
MaxUint64 holds the max value an uint64 can take
Functions ¶
This section is empty.
Types ¶
type BlocksRemovedEvent ¶
type BlocksRemovedEvent struct { // Chain refers to the TestChain which emitted the event. Chain *TestChain // Blocks refers to the block(s) that was removed from the Chain. Blocks []*types.Block }
BlocksRemovedEvent describes an event where a block(s) is removed from the TestChain. This only considers internally committed blocks, not ones spoofed in between block number jumps.
type CheatCodeContract ¶
type CheatCodeContract struct {
// contains filtered or unexported fields
}
CheatCodeContract defines a struct which represents a pre-compiled contract with various methods that is meant to act as a contract.
func (*CheatCodeContract) Abi ¶
func (c *CheatCodeContract) Abi() *abi.ABI
Abi provides the cheat code contract interface.
func (*CheatCodeContract) Address ¶
func (c *CheatCodeContract) Address() common.Address
Address represents the address the cheat code contract is deployed at.
func (*CheatCodeContract) Name ¶
func (c *CheatCodeContract) Name() string
Name represents the name of the cheat code contract.
func (*CheatCodeContract) RequiredGas ¶
func (c *CheatCodeContract) RequiredGas(input []byte) uint64
RequiredGas determines the amount of gas necessary to execute the pre-compile with the given input data. Returns the gas cost.
type ContractDeploymentsAddedEvent ¶
type ContractDeploymentsAddedEvent struct { // Chain refers to the TestChain which emitted the event. Chain *TestChain // Contract defines information for the contract which was deployed to the Chain. Contract *types.DeployedContractBytecode // DynamicDeployment describes whether this contract deployment was dynamic (e.g. `c = new MyContract()`) or was // because of a traditional transaction DynamicDeployment bool }
ContractDeploymentsAddedEvent describes an event where a contract has become available on the TestChain, either due to contract creation, or a self-destruct operation being reverted.
type ContractDeploymentsRemovedEvent ¶
type ContractDeploymentsRemovedEvent struct { // Chain refers to the TestChain which emitted the event. Chain *TestChain // Contract defines information for the contract which was deployed to the Chain. Contract *types.DeployedContractBytecode }
ContractDeploymentsRemovedEvent describes an event where a contract has become unavailable on the TestChain, either due to the reverting of a contract creation, or a self-destruct operation.
type PendingBlockAddedTxEvent ¶
type PendingBlockAddedTxEvent struct { // Chain refers to the TestChain which emitted the event. Chain *TestChain // Block refers to the pending block which the transaction was added to. Block *types.Block // TransactionIndex describes the index of the transaction in the pending block. TransactionIndex int }
PendingBlockAddedTxEvent describes an event where a pending block had a transaction added to it.
type PendingBlockCommittedEvent ¶
type PendingBlockCommittedEvent struct { // Chain refers to the TestChain which emitted the event. Chain *TestChain // Block refers to the pending block that was committed to the Chain as the new head. Block *types.Block }
PendingBlockCommittedEvent describes an event where a pending block is committed to the chain as the new head.
type PendingBlockCreatedEvent ¶
type PendingBlockCreatedEvent struct { // Chain refers to the TestChain which emitted the event. Chain *TestChain // Block refers to the Chain's pending block which was just created. Block *types.Block }
PendingBlockCreatedEvent describes an event where a new pending block was created, prior to any transactions being added to it.
type PendingBlockDiscardedEvent ¶
type PendingBlockDiscardedEvent struct { // Chain refers to the TestChain which emitted the event. Chain *TestChain // Block refers to the pending block that was discarded before being committed to the Chain. Block *types.Block }
PendingBlockDiscardedEvent describes an event where a pending block is discarded from the chain before being committed.
type TestChain ¶
type TestChain struct { // BlockGasLimit defines the maximum amount of gas that can be consumed by transactions in a block. // Transactions which push the block gas usage beyond this limit will not be added to a block without error. BlockGasLimit uint64 // Events defines the event system for the TestChain. Events TestChainEvents // contains filtered or unexported fields }
TestChain represents a simulated Ethereum chain used for testing. It maintains blocks in-memory and strips away typical consensus/chain objects to allow for more specialized testing closer to the EVM.
func NewTestChain ¶
func NewTestChain(genesisAlloc types.GenesisAlloc, testChainConfig *config.TestChainConfig) (*TestChain, error)
NewTestChain creates a simulated Ethereum backend used for testing, or returns an error if one occurred. This creates a test chain with a test chain configuration and the provided genesis allocation and config. If a nil config is provided, a default one is used.
func (*TestChain) AddTracer ¶
func (t *TestChain) AddTracer(tracer *TestChainTracer, txs bool, calls bool)
AddTracer adds a given tracers.Tracer or TestChainTracer to the TestChain. If directed, the tracer will be attached for transactions and/or non-state changing calls made via CallContract.
func (*TestChain) BlockFromNumber ¶
func (t *TestChain) BlockFromNumber(blockNumber uint64) (*chainTypes.Block, error)
BlockFromNumber obtains the block with the provided block number from the current chain. If blocks committed to the TestChain skip block numbers, this method will simulate the existence of well-formed intermediate blocks to ensure chain validity throughout. Thus, this is a "simulated" chain API method. Returns the block, or an error if one occurs.
func (*TestChain) BlockHashFromNumber ¶
BlockHashFromNumber returns a block hash for a given block number. If the index is out of bounds, it returns an error.
func (*TestChain) CallContract ¶
func (t *TestChain) CallContract(msg *core.Message, state *state.StateDB, additionalTracers ...*TestChainTracer) (*core.ExecutionResult, error)
CallContract performs a message call over the current test chain state and obtains a core.ExecutionResult. This is similar to the CallContract method provided by Ethereum for use in calling pure/view functions, as it executed a transaction without committing any changes, instead discarding them. It takes an optional state argument, which is the state to execute the message over. If not provided, the current pending state (or committed state if none is pending) will be used instead. The state executed over may be a pending block state.
func (*TestChain) CheatCodeContracts ¶
func (t *TestChain) CheatCodeContracts() map[common.Address]*CheatCodeContract
CheatCodeContracts returns all cheat code contracts which are installed in the chain.
func (*TestChain) Clone ¶
Clone recreates the current TestChain state into a new instance. This simply reconstructs the block/chain state but does not perform any other API-related changes such as adding additional tracers the original had. Additionally, this does not clone pending blocks. The provided method, if non-nil, is used as callback to provide an intermediate step between chain creation, and copying of all blocks, allowing for tracers to be added. Returns the new chain, or an error if one occurred.
func (*TestChain) Close ¶ added in v0.1.3
func (t *TestChain) Close()
Close will release any objects from the TestChain that must be _explicitly_ released. Currently, the one object that must be explicitly released is the stateDB trie's underlying cache. This cache, if not released, prevents the TestChain object from being freed by the garbage collector and causes a severe memory leak.
func (*TestChain) CommittedBlocks ¶
func (t *TestChain) CommittedBlocks() []*chainTypes.Block
CommittedBlocks returns the real blocks which were committed to the chain, where methods such as BlockFromNumber return the simulated chain state with intermediate blocks injected for block number jumps, etc.
func (*TestChain) GenesisDefinition ¶
GenesisDefinition returns the core.Genesis definition used to initialize the chain.
func (*TestChain) Head ¶
func (t *TestChain) Head() *chainTypes.Block
Head returns the head of the chain (the latest block).
func (*TestChain) HeadBlockNumber ¶
HeadBlockNumber returns the test chain head's block number, where zero is the genesis block.
func (*TestChain) PendingBlock ¶
func (t *TestChain) PendingBlock() *chainTypes.Block
PendingBlock describes the current pending block which is being constructed and awaiting commitment to the chain. This may be nil if no pending block was created.
func (*TestChain) PendingBlockAddTx ¶
func (t *TestChain) PendingBlockAddTx(message *core.Message, additionalTracers ...*TestChainTracer) error
PendingBlockAddTx takes a message (internal txs) and adds it to the current pending block, updating the header with relevant execution information. If a pending block was not created, an error is returned. Returns an error if one occurred.
func (*TestChain) PendingBlockCommit ¶
PendingBlockCommit commits a pending block to the chain, so it is set as the new head. The pending block is set to nil after doing so. If there is no pending block when calling this function, an error is returned.
func (*TestChain) PendingBlockCreate ¶
func (t *TestChain) PendingBlockCreate() (*chainTypes.Block, error)
PendingBlockCreate constructs an empty block which is pending addition to the chain. The block produces by this method will have a block number and timestamp that is greater by the current chain head by 1. Returns the constructed block, or an error if one occurred.
func (*TestChain) PendingBlockCreateWithParameters ¶
func (t *TestChain) PendingBlockCreateWithParameters(blockNumber uint64, blockTime uint64, blockGasLimit *uint64) (*chainTypes.Block, error)
PendingBlockCreateWithParameters constructs an empty block which is pending addition to the chain, using the block properties provided. Values should be sensibly chosen (e.g., block number and timestamps should be greater than the previous block). Providing a block number that is greater than the previous block number plus one will simulate empty blocks between. Returns the constructed block, or an error if one occurred.
func (*TestChain) PendingBlockDiscard ¶
PendingBlockDiscard discards a pending block, allowing a different one to be created.
func (*TestChain) RevertToBlockNumber ¶
RevertToBlockNumber sets the head of the chain to the block specified by the provided block number and reloads the state from the underlying database.
func (*TestChain) StateAfterBlockNumber ¶
StateAfterBlockNumber obtains the Ethereum world state after processing all transactions in the provided block number. Returns the state, or an error if one occurs.
func (*TestChain) StateFromRoot ¶
StateFromRoot obtains a state from a given state root hash. Returns the state, or an error if one occurred.
func (*TestChain) StateRootAfterBlockNumber ¶
StateRootAfterBlockNumber obtains the Ethereum world state root hash after processing all transactions in the provided block number. Returns the state, or an error if one occurs.
type TestChainEvents ¶
type TestChainEvents struct { // PendingBlockCreated emits events indicating a pending block was created on the chain. PendingBlockCreated events.EventEmitter[PendingBlockCreatedEvent] // PendingBlockAddedTx emits events indicating a pending block had a transaction added to it. PendingBlockAddedTx events.EventEmitter[PendingBlockAddedTxEvent] // PendingBlockCommitted emits events indicating a pending block was committed to the chain. PendingBlockCommitted events.EventEmitter[PendingBlockCommittedEvent] // PendingBlockDiscarded emits events indicating a pending block was discarded before being committed to the chain. PendingBlockDiscarded events.EventEmitter[PendingBlockDiscardedEvent] // BlocksRemoved emits events indicating a block(s) was removed from the chain. BlocksRemoved events.EventEmitter[BlocksRemovedEvent] // ContractDeploymentAddedEventEmitter emits events indicating a new contract was created on chain. This is called // alongside ContractDeploymentRemovedEventEmitter when contract deployment changes are detected. e.g. If a // contract is deployed and immediately destroyed within the same transaction, a ContractDeploymentsAddedEvent // will be fired, followed immediately by a ContractDeploymentsRemovedEvent. ContractDeploymentAddedEventEmitter events.EventEmitter[ContractDeploymentsAddedEvent] // ContractDeploymentAddedEventEmitter emits events indicating a previously deployed contract was removed // from the chain. This is called alongside ContractDeploymentAddedEventEmitter when contract deployment changes // are detected. e.g. If a contract is deployed and immediately destroyed within the same transaction, a // ContractDeploymentsAddedEvent will be fired, followed immediately by a ContractDeploymentsRemovedEvent. ContractDeploymentRemovedEventEmitter events.EventEmitter[ContractDeploymentsRemovedEvent] }
TestChainEvents defines event emitters for a TestChain.
type TestChainTracer ¶
type TestChainTracer struct { // tracers.Tracer is extended by this logger. *tracers.Tracer // CaptureTxEndSetAdditionalResults can be used to set additional results captured from execution tracing. If this // tracer is used during transaction execution (block creation), the results can later be queried from the block. // This method will only be called on the added tracer if it implements the extended TestChainTracer interface. CaptureTxEndSetAdditionalResults func(results *types.MessageResults) }
TestChainTracer is an extended tracers.Tracer which can be used with a TestChain to store any captured information within call results, recorded in each block produced.
type TestChainTracerRouter ¶
type TestChainTracerRouter struct {
// contains filtered or unexported fields
}
TestChainTracerRouter acts as a tracers.Tracer, allowing multiple tracers to be used in place of one. When this tracer receives callback, it calls upon its underlying tracers.
func NewTestChainTracerRouter ¶
func NewTestChainTracerRouter() *TestChainTracerRouter
NewTestChainTracerRouter returns a new TestChainTracerRouter instance with no registered tracers.
func (*TestChainTracerRouter) AddTracer ¶
func (t *TestChainTracerRouter) AddTracer(tracer *TestChainTracer)
AddTracer adds a TestChainTracer to the TestChainTracerRouter so that all other tracing.Hooks calls are forwarded. are forwarded to it.
func (*TestChainTracerRouter) AddTracers ¶
func (t *TestChainTracerRouter) AddTracers(tracers ...*TestChainTracer)
AddTracers adds TestChainTracers to the TestChainTracerRouter so that all other tracing.Hooks calls are forwarded.
func (*TestChainTracerRouter) CaptureTxEndSetAdditionalResults ¶
func (t *TestChainTracerRouter) CaptureTxEndSetAdditionalResults(results *types.MessageResults)
CaptureTxEndSetAdditionalResults can be used to set additional results captured from execution tracing. If this tracer is used during transaction execution (block creation), the results can later be queried from the block. This method will only be called on the added tracer if it implements the extended TestChainTracer interface.
func (*TestChainTracerRouter) NativeTracer ¶ added in v0.1.4
func (t *TestChainTracerRouter) NativeTracer() *TestChainTracer
NativeTracer returns the underlying TestChainTracer.
func (*TestChainTracerRouter) OnCodeChange ¶ added in v0.1.4
func (*TestChainTracerRouter) OnEnter ¶ added in v0.1.4
func (t *TestChainTracerRouter) OnEnter(depth int, typ byte, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int)
OnEnter initializes the tracing operation for the top of a call frame, as defined by tracers.Tracer.
func (*TestChainTracerRouter) OnExit ¶ added in v0.1.4
func (t *TestChainTracerRouter) OnExit(depth int, output []byte, gasUsed uint64, err error, reverted bool)
OnExit is called after a call to finalize tracing completes for the top of a call frame, as defined by tracers.Tracer.
func (*TestChainTracerRouter) OnFault ¶ added in v0.1.4
func (t *TestChainTracerRouter) OnFault(pc uint64, op byte, gas, cost uint64, scope *vm.ScopeContext, depth int, err error)
OnFault records an execution fault, as defined by tracers.Tracer.
func (*TestChainTracerRouter) OnOpcode ¶ added in v0.1.4
func (t *TestChainTracerRouter) OnOpcode(pc uint64, op byte, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, err error)
OnOpcode records data from an EVM state update, as defined by tracers.Tracer.
func (*TestChainTracerRouter) OnTxEnd ¶ added in v0.1.4
func (t *TestChainTracerRouter) OnTxEnd(receipt *coretypes.Receipt, err error)
OnTxEnd is called upon the end of transaction execution, as defined by tracers.Tracer.
func (*TestChainTracerRouter) OnTxStart ¶ added in v0.1.4
func (t *TestChainTracerRouter) OnTxStart(vm *tracing.VMContext, tx *coretypes.Transaction, from common.Address)
OnTxStart is called upon the start of transaction execution, as defined by tracers.Tracer.
func (*TestChainTracerRouter) Tracers ¶
func (t *TestChainTracerRouter) Tracers() []*TestChainTracer
Tracers returns the tracers.Tracer instances added to the TestChainTracerRouter.