testutil

package
v1.9.4 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2024 License: MIT, MIT Imports: 37 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 AddHintLengthPrefix added in v1.9.3

func AddHintLengthPrefix(data []byte) []byte

func AddPreimageLengthPrefix added in v1.9.3

func AddPreimageLengthPrefix(data []byte) []byte

func AlignPC added in v1.9.2

func AlignPC(pc arch.Word) arch.Word

func AssertEVMReverts added in v1.9.2

func AssertEVMReverts(t *testing.T, state mipsevm.FPVMState, contracts *ContractMetadata, tracer *tracing.Hooks)

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, tracer *tracing.Hooks)

func BoundStep added in v1.9.2

func BoundStep(step uint64) uint64

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 LoadELFProgram

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

func LogStepFailureAtCleanup

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

func MarkdownTracer

func MarkdownTracer() *tracing.Hooks

func NewEVMEnv

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

func RunVMTest_Claim

func RunVMTest_Claim[T mipsevm.FPVMState](t *testing.T, initState program.CreateInitialFPVMState[T], vmFactory VMFactory[T], doPatchGo bool)

func RunVMTest_Hello

func RunVMTest_Hello[T mipsevm.FPVMState](t *testing.T, initState program.CreateInitialFPVMState[T], vmFactory VMFactory[T], doPatchGo bool)

func RunVMTests_OpenMips

func RunVMTests_OpenMips[T mipsevm.FPVMState](t *testing.T, stateFactory StateFactory[T], vmFactory VMFactory[T], excludedTests ...string)

func SelectOracleFixture

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

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 ValidateEVM added in v1.9.2

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

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

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
}

func TestContractsSetup added in v1.9.1

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

type ExpectedState added in v1.9.1

type ExpectedState struct {
	PreimageKey    common.Hash
	PreimageOffset arch.Word
	PC             arch.Word
	NextPC         arch.Word
	HI             arch.Word
	LO             arch.Word
	Heap           arch.Word
	ExitCode       uint8
	Exited         bool
	Step           uint64
	LastHint       hexutil.Bytes
	Registers      [32]arch.Word
	MemoryRoot     common.Hash
	// contains filtered or unexported fields
}

func NewExpectedState added in v1.9.2

func NewExpectedState(fromState mipsevm.FPVMState) *ExpectedState

func (*ExpectedState) ExpectMemoryWrite added in v1.9.3

func (e *ExpectedState) ExpectMemoryWrite(addr arch.Word, val uint32)

func (*ExpectedState) ExpectStep added in v1.9.3

func (e *ExpectedState) ExpectStep()

func (*ExpectedState) Validate added in v1.9.1

func (e *ExpectedState) Validate(t testing.TB, actualState mipsevm.FPVMState)

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 NewMIPSEVM

func NewMIPSEVM(contracts *ContractMetadata) *MIPSEVM

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 StateFactory

type StateFactory[T mipsevm.FPVMState] func() T

type StateMutator added in v1.9.1

type StateMutator interface {
	SetPreimageKey(val common.Hash)
	SetPreimageOffset(val arch.Word)
	SetPC(val arch.Word)
	SetNextPC(val arch.Word)
	SetHI(val arch.Word)
	SetLO(val arch.Word)
	SetHeap(addr arch.Word)
	SetExitCode(val uint8)
	SetExited(val bool)
	SetStep(val uint64)
	SetLastHint(val hexutil.Bytes)
	Randomize(randSeed int64)
}

type StateOption added in v1.9.1

type StateOption func(state StateMutator)

func WithHeap added in v1.9.1

func WithHeap(addr arch.Word) StateOption

func WithLastHint added in v1.9.1

func WithLastHint(lastHint hexutil.Bytes) StateOption

func WithNextPC added in v1.9.1

func WithNextPC(nextPC arch.Word) StateOption

func WithPC added in v1.9.1

func WithPC(pc arch.Word) StateOption

func WithPCAndNextPC added in v1.9.3

func WithPCAndNextPC(pc arch.Word) StateOption

func WithPreimageKey added in v1.9.1

func WithPreimageKey(key common.Hash) StateOption

func WithPreimageOffset added in v1.9.1

func WithPreimageOffset(offset arch.Word) StateOption

func WithRandomization added in v1.9.1

func WithRandomization(seed int64) StateOption

func WithStep added in v1.9.1

func WithStep(step uint64) StateOption

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 VMFactory

type VMFactory[T mipsevm.FPVMState] func(state T, po mipsevm.PreimageOracle, stdOut, stdErr io.Writer, log log.Logger) mipsevm.FPVM

Jump to

Keyboard shortcuts

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