ethtest

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2026 License: GPL-3.0 Imports: 22 Imported by: 0

Documentation

Overview

Package ethtest provides utility functions for use in testing Ethereum-related functionality.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DummyChainContext

func DummyChainContext() core.ChainContext

DummyChainContext returns a dummy that returns DummyEngine when its Engine() method is called, and panics when its GetHeader() method is called.

func DummyEngine

func DummyEngine() consensus.Engine

DummyEngine returns a dummy that panics when its Author() method is called.

func NewEmptyStateDB

func NewEmptyStateDB(tb testing.TB) (ethdb.Database, state.Database, *state.StateDB)

NewEmptyStateDB returns a fresh database from rawdb.NewMemoryDatabase, a state.Database wrapping it, and a state.StateDB wrapping that, opened to types.EmptyRootHash.

func NewTBLogHandler

func NewTBLogHandler(tb testing.TB, level slog.Level) slog.Handler

NewTBLogHandler constructs a slog.Handler that propagates logs to testing.TB. Logs at log.LevelWarn or above go to testing.TB.Errorf, except log.LevelCrit which goes to testing.TB.Fatalf. All other logs go to testing.TB.Logf. The level parameter controls which logs are enabled.

func NewZeroEVM

func NewZeroEVM(tb testing.TB, opts ...EVMOption) (*state.StateDB, *vm.EVM)

NewZeroEVM returns a new EVM backed by a rawdb.NewMemoryDatabase; all other arguments to vm.NewEVM are the zero values of their respective types, except for the use of core.CanTransfer and core.Transfer instead of nil functions.

func UNSAFEDeterministicPrivateKey

func UNSAFEDeterministicPrivateKey(tb testing.TB, seed []byte) *ecdsa.PrivateKey

UNSAFEDeterministicPrivateKey returns a new crypto.S256 private key, deterministically generated from the `seed`.

Types

type EVMOption

type EVMOption interface {
	// contains filtered or unexported methods
}

An EVMOption configures the EVM returned by NewZeroEVM.

func WithBlockContext

func WithBlockContext(c vm.BlockContext) EVMOption

WithBlockContext overrides the default context.

func WithChainConfig

func WithChainConfig(c *params.ChainConfig) EVMOption

WithBlockContext overrides the default context.

type PseudoRand

type PseudoRand struct {
	*rand.Rand
}

PseudoRand extends rand.Rand (*not* crypto/rand).

func NewPseudoRand

func NewPseudoRand(seed uint64) *PseudoRand

NewPseudoRand returns a new PseudoRand with the given seed.

func (*PseudoRand) Address

func (r *PseudoRand) Address() (a common.Address)

Address returns a pseudorandom address.

func (*PseudoRand) AddressPtr

func (r *PseudoRand) AddressPtr() *common.Address

AddressPtr returns a pointer to a pseudorandom address.

func (*PseudoRand) BigUint64

func (r *PseudoRand) BigUint64() *big.Int

Big returns rand.Rand.Uint64 as a big.Int.

func (*PseudoRand) BlockNonce

func (r *PseudoRand) BlockNonce() (n types.BlockNonce)

BlockNonce returns a pseudorandom BlockNonce.

func (*PseudoRand) Bloom

func (r *PseudoRand) Bloom() (b types.Bloom)

Bloom returns a pseudorandom Bloom.

func (*PseudoRand) Bytes

func (r *PseudoRand) Bytes(n uint) []byte

Bytes returns `n` pseudorandom bytes.

func (*PseudoRand) Hash

func (r *PseudoRand) Hash() (h common.Hash)

Hash returns a pseudorandom hash.

func (*PseudoRand) HashPtr

func (r *PseudoRand) HashPtr() *common.Hash

HashPtr returns a pointer to a pseudorandom hash.

func (*PseudoRand) Read

func (r *PseudoRand) Read(p []byte) int

Read is equivalent to rand.Rand.Read except that it doesn't return an error because it is guaranteed to be nil.

func (*PseudoRand) Uint64Ptr

func (r *PseudoRand) Uint64Ptr() *uint64

Uint64Ptr returns a pointer to a pseudorandom uint64.

func (*PseudoRand) Uint256

func (r *PseudoRand) Uint256() *uint256.Int

Uint256 returns a random 256-bit unsigned int.

Jump to

Keyboard shortcuts

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