hookstest

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: 6 Imported by: 0

Documentation

Overview

Package hookstest provides test doubles and convenience wrappers for testing libevm hooks.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register[C params.ChainConfigHooks, R params.RulesHooks](tb testing.TB, extras params.Extras[C, R]) params.ExtraPayloads[C, R]

Register clears any registered params.Extras and then registers `extras` for the lifetime of the current test, clearing them via tb's testing.TB.Cleanup.

Types

type Stub

type Stub struct {
	CheckConfigForkOrderFn  func() error
	CheckConfigCompatibleFn func(*params.ChainConfig, *big.Int, uint64) *params.ConfigCompatError
	DescriptionSuffix       string
	PrecompileOverrides     map[common.Address]libevm.PrecompiledContract
	ActivePrecompilesFn     func([]common.Address) []common.Address
	CanExecuteTransactionFn func(common.Address, *common.Address, libevm.StateReader) error
	CanCreateContractFn     func(*libevm.AddressContext, uint64, libevm.StateReader) (uint64, error)
	MinimumGasConsumptionFn func(txGasLimit uint64) uint64
}

A Stub is a test double for params.ChainConfigHooks and params.RulesHooks. Each of the fields, if non-nil, back their respective hook methods, which otherwise fall back to the default behaviour.

func (Stub) ActivePrecompiles

func (s Stub) ActivePrecompiles(active []common.Address) []common.Address

ActivePrecompiles proxies arguments to the s.ActivePrecompilesFn function if non-nil, otherwise it acts as a noop.

func (Stub) CanCreateContract

func (s Stub) CanCreateContract(cc *libevm.AddressContext, gas uint64, sr libevm.StateReader) (uint64, error)

CanCreateContract proxies arguments to the s.CanCreateContractFn function if non-nil, otherwise it acts as a noop.

func (Stub) CanExecuteTransaction

func (s Stub) CanExecuteTransaction(from common.Address, to *common.Address, sr libevm.StateReader) error

CanExecuteTransaction proxies arguments to the s.CanExecuteTransactionFn function if non-nil, otherwise it acts as a noop.

func (Stub) CheckConfigCompatible

func (s Stub) CheckConfigCompatible(newcfg *params.ChainConfig, headNumber *big.Int, headTimestamp uint64) *params.ConfigCompatError

CheckConfigCompatible proxies arguments to the s.CheckConfigCompatibleFn function if non-nil, otherwise it acts as a noop.

func (Stub) CheckConfigForkOrder

func (s Stub) CheckConfigForkOrder() error

CheckConfigForkOrder proxies arguments to the s.CheckConfigForkOrderFn function if non-nil, otherwise it acts as a noop.

func (Stub) Description

func (s Stub) Description() string

Description returns s.DescriptionSuffix.

func (Stub) MarshalJSON

func (Stub) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler and always returns the JSON null object. This avoids errors due to incompatible field types.

func (Stub) MinimumGasConsumption

func (s Stub) MinimumGasConsumption(limit uint64) uint64

MinimumGasConsumption proxies arguments to the s.MinimumGasConsumptionFn function if non-nil, otherwise it acts as a noop.

func (Stub) PrecompileOverride

func (s Stub) PrecompileOverride(a common.Address) (libevm.PrecompiledContract, bool)

PrecompileOverride uses the s.PrecompileOverrides map, if non-empty, as the canonical source of all overrides. If the map is empty then no precompiles are overridden.

func (*Stub) Register

func (s *Stub) Register(tb testing.TB) params.ExtraPayloads[*Stub, *Stub]

Register is a convenience wrapper for registering s as both the params.ChainConfigHooks and params.RulesHooks via Register.

func (Stub) UnmarshalJSON

func (Stub) UnmarshalJSON([]byte) error

UnmarshalJSON implements json.Unmarshaler and always returns nil, ignoring its input.

Jump to

Keyboard shortcuts

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