testutil

package
v1.13.5 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2025 License: MIT, MIT Imports: 38 Imported by: 0

Documentation

Index

Constants

View Source
const BaseAddrEnd = 0xbf_ff_ff_f0

0xbf_c0_00_00 ... BaseAddrEnd is used in tests to write the results to

View Source
const EndAddr = 0xa7ef00d0

EndAddr is used as return-address for tests

Variables

This section is empty.

Functions

func AssertEVMReverts added in v1.9.2

func AssertEVMReverts(t *testing.T, state mipsevm.FPVMState, contracts *ContractMetadata, tracer *tracing.Hooks, ProofData []byte, matcher ErrMatcher)

AssertEVMReverts runs a single evm step from an FPVM prestate and asserts that the VM panics

func AssertPreimageOracleReverts added in v1.9.3

func AssertPreimageOracleReverts(t *testing.T, preimageKey [32]byte, preimageValue []byte, preimageOffset arch.Word, contracts *ContractMetadata, opts ...evmOption)

func ClaimTestOracle

func ClaimTestOracle(t *testing.T) (po mipsevm.PreimageOracle, stdOut string, stdErr string)

func CreateLogger

func CreateLogger() log.Logger

func EncodeStepInput

func EncodeStepInput(t *testing.T, wit *mipsevm.StepWitness, localContext mipsevm.LocalContext, mips *foundry.Artifact) []byte

func GetInstruction added in v1.9.5

func GetInstruction(mem *memory.Memory, pc arch.Word) uint32

func LoadELFProgram

func LoadELFProgram[T mipsevm.FPVMState](t require.TestingT, name string, initState program.CreateInitialFPVMState[T]) (T, *program.Metadata)

func LogStepFailureAtCleanup

func LogStepFailureAtCleanup(t *testing.T, mipsEvm *MIPSEVM)

func MarkdownTracer

func MarkdownTracer() *tracing.Hooks

func NewEVMEnv

func NewEVMEnv(t testing.TB, contracts *ContractMetadata) (*vm.EVM, *state.StateDB)

func ProgramPath added in v1.9.5

func ProgramPath(programName string, goTarget GoTarget) string

ProgramPath returns the appropriate ELF test program for the current architecture

func RandomizeWordAndSetUint32 added in v1.11.0

func RandomizeWordAndSetUint32(mem *memory.Memory, addr Word, val uint32, randomizeWordSeed int64)

RandomizeWordAndSetUint32 writes a uint32 value and randomizes the rest of the Word containing the uint32 in memory

func SelectOracleFixture

func SelectOracleFixture(t *testing.T, programName string) mipsevm.PreimageOracle

func SetMemoryUint64 added in v1.9.5

func SetMemoryUint64(t require.TestingT, mem *memory.Memory, addr Word, value uint64)

SetMemoryUint64 sets 8 bytes of memory (1 or 2 Words depending on architecture) and enforces the use of addresses that are compatible across 32- and 64-bit architectures

func SourceMapTracer added in v1.9.1

func SourceMapTracer(t require.TestingT, version MipsVersion, mips *foundry.Artifact, oracle *foundry.Artifact, addrs *Addresses) *tracing.Hooks

func StoreInstruction added in v1.9.5

func StoreInstruction(mem *memory.Memory, pc arch.Word, insn uint32)

StoreInstruction writes a 4-byte instruction to memory

func ToSignedInteger added in v1.9.5

func ToSignedInteger(x Word) arch.SignedInteger

ToSignedInteger converts the unsigned Word to a SignedInteger. Useful for avoiding Go compiler warnings for literals that don't fit in a signed type

func Uint32ToBytes added in v1.9.5

func Uint32ToBytes(val uint32) []byte

func Uint64ToBytes added in v1.9.5

func Uint64ToBytes(val uint64) []byte

func ValidateEVM added in v1.9.2

func ValidateEVM(t *testing.T, stepWitness *mipsevm.StepWitness, step uint64, goVm mipsevm.FPVM, hashFn mipsevm.HashFn, contracts *ContractMetadata, opts ...evmOption)

ValidateEVM runs a single evm step and validates against an FPVM poststate

func WithLocalOracle added in v1.9.5

func WithLocalOracle(oracle mipsevm.PreimageOracle) evmOption

func WithSourceMapTracer added in v1.9.5

func WithSourceMapTracer(t *testing.T, ver MipsVersion) evmOption

func WithTracingHooks added in v1.9.5

func WithTracingHooks(tracer *tracing.Hooks) evmOption

Types

type Addresses

type Addresses struct {
	MIPS         common.Address
	Oracle       common.Address
	Sender       common.Address
	FeeRecipient common.Address
}

type Artifacts

type Artifacts struct {
	MIPS   *foundry.Artifact
	Oracle *foundry.Artifact
}

type ContractMetadata added in v1.9.1

type ContractMetadata struct {
	Artifacts *Artifacts
	Addresses *Addresses
	Version   uint8 // versions.StateVersion can't be used as it causes dependency cycles
}

func TestContractsSetup added in v1.9.1

func TestContractsSetup(t require.TestingT, version MipsVersion, stateVersion uint8) *ContractMetadata

type ErrMatcher added in v1.9.5

type ErrMatcher func(*testing.T, []byte)

func CreateCustomErrorMatcher added in v1.9.5

func CreateCustomErrorMatcher(sig string) ErrMatcher

CreateCustomErrorMatcher matches a custom error given the error signature

func CreateErrorStringMatcher added in v1.9.5

func CreateErrorStringMatcher(expect string) ErrMatcher

CreateErrorStringMatcher matches an Error(string)

func CreateNoopErrorMatcher added in v1.9.5

func CreateNoopErrorMatcher() ErrMatcher

type EvmValidator added in v1.9.5

type EvmValidator struct {
	// contains filtered or unexported fields
}

func NewEvmValidator added in v1.9.5

func NewEvmValidator(t *testing.T, hashFn mipsevm.HashFn, contracts *ContractMetadata, opts ...evmOption) *EvmValidator

NewEvmValidator creates a validator that can be run repeatedly across multiple steps

func (*EvmValidator) ValidateEVM added in v1.9.5

func (v *EvmValidator) ValidateEVM(t *testing.T, stepWitness *mipsevm.StepWitness, step uint64, goVm mipsevm.FPVM)

type GoTarget added in v1.13.4

type GoTarget string
const (
	Go1_23 GoTarget = "go-1-23"
	Go1_24 GoTarget = "go-1-24"
)

type HintTrackingOracle added in v1.9.1

type HintTrackingOracle struct {
	// contains filtered or unexported fields
}

func (*HintTrackingOracle) GetPreimage added in v1.9.1

func (t *HintTrackingOracle) GetPreimage(k [32]byte) []byte

func (*HintTrackingOracle) Hint added in v1.9.1

func (t *HintTrackingOracle) Hint(v []byte)

func (*HintTrackingOracle) Hints added in v1.9.1

func (t *HintTrackingOracle) Hints() [][]byte

type MIPSEVM

type MIPSEVM struct {
	// contains filtered or unexported fields
}

func (*MIPSEVM) SetLocalOracle

func (m *MIPSEVM) SetLocalOracle(oracle mipsevm.PreimageOracle)

func (*MIPSEVM) SetSourceMapTracer added in v1.9.1

func (m *MIPSEVM) SetSourceMapTracer(t *testing.T, version MipsVersion)

func (*MIPSEVM) SetTracer

func (m *MIPSEVM) SetTracer(tracer *tracing.Hooks)

func (*MIPSEVM) Step

func (m *MIPSEVM) Step(t *testing.T, stepWitness *mipsevm.StepWitness, step uint64, stateHashFn mipsevm.HashFn) []byte

Step is a pure function that computes the poststate from the VM state encoded in the StepWitness.

type MipsVersion added in v1.9.1

type MipsVersion int
const (
	MipsSingleThreaded MipsVersion = iota
	MipsMultithreaded
)

type RandHelper added in v1.9.3

type RandHelper struct {
	// contains filtered or unexported fields
}

func NewRandHelper added in v1.9.3

func NewRandHelper(seed int64) *RandHelper

func (*RandHelper) Fraction added in v1.9.3

func (h *RandHelper) Fraction() float64

func (*RandHelper) Intn added in v1.9.3

func (h *RandHelper) Intn(n int) int

func (*RandHelper) RandHash added in v1.9.3

func (h *RandHelper) RandHash() common.Hash

func (*RandHelper) RandHint added in v1.9.3

func (h *RandHelper) RandHint() []byte

func (*RandHelper) RandPC added in v1.9.3

func (h *RandHelper) RandPC() arch.Word

func (*RandHelper) RandRegisters added in v1.9.3

func (h *RandHelper) RandRegisters() *[32]arch.Word

func (*RandHelper) RandStep added in v1.9.3

func (h *RandHelper) RandStep() uint64

func (*RandHelper) RandomBytes added in v1.9.3

func (h *RandHelper) RandomBytes(t require.TestingT, length int) []byte

func (*RandHelper) Uint32 added in v1.9.3

func (h *RandHelper) Uint32() uint32

func (*RandHelper) Word added in v1.9.4

func (h *RandHelper) Word() arch.Word

type TestOracle

type TestOracle struct {
	// contains filtered or unexported fields
}

func AllocOracle

func AllocOracle(t *testing.T, numAllocs int, allocSize int) *TestOracle

func StaticOracle

func StaticOracle(t *testing.T, preimageData []byte) *TestOracle

func StaticPrecompileOracle

func StaticPrecompileOracle(t *testing.T, precompile common.Address, requiredGas uint64, input []byte, result []byte) *TestOracle

func (*TestOracle) GetPreimage

func (t *TestOracle) GetPreimage(k [32]byte) []byte

func (*TestOracle) Hint

func (t *TestOracle) Hint(v []byte)

type Word added in v1.9.5

type Word = arch.Word

func FlipSign added in v1.11.0

func FlipSign(val Word) Word

FlipSign flips the sign of a 2's complement Word

Jump to

Keyboard shortcuts

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