evmtest

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: 0BSD Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package evmtest provides named-entry fixtures for compiler and binding tests.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Callback

func Callback(vm *evm.VM, v values.Value, in, out []values.Value) error

Callback invokes a guest function value on vm and copies successful results to out.

Types

type Session

type Session struct {
	*evm.VM
	Limits evm.Limits
	// contains filtered or unexported fields
}

Session owns a VM and test limits for repeated guest calls. Release it when the test is done.

func New

func New(p *evm.Program) *Session

New acquires a VM for p with a background context.

func (*Session) Reset

func (s *Session) Reset() error

Reset releases the current VM and acquires another for the same program and context.

func (*Session) Run

func (s *Session) Run(ctx context.Context, name string, in, out []values.Value) error

Run invokes a named guest entry and copies successful results into out.

func (*Session) RunFunction

func (s *Session) RunFunction(ctx context.Context, fn *evm.Callable, in, out []values.Value) error

RunFunction calls a resolved entry with the session's test limits.

func (*Session) RunFunctionWithBudget

func (s *Session) RunFunctionWithBudget(ctx context.Context, fn *evm.Callable, in, out []values.Value, l evm.Limits) error

RunFunctionWithBudget calls a resolved entry with separate input and output slices. On failure, out is left untouched.

func (*Session) RunNative

func (s *Session) RunNative(ctx context.Context, fn evm.Native, l evm.Limits) error

RunNative runs a parameterless host function under the supplied limits.

func (*Session) RunWithBudget

func (s *Session) RunWithBudget(ctx context.Context, name string, in, out []values.Value, l evm.Limits) error

RunWithBudget invokes a named entry with per-call limits and tester defaults.

Example
package main

import (
	"context"
	"errors"
	"fmt"

	"github.com/andreyvit/evm"
	"github.com/andreyvit/evm/evmcompiler"
	"github.com/andreyvit/evm/evmtest"
)

func main() {
	module, err := evmcompiler.Compile("loop.go", "func Loop() { for {} }")
	if err != nil {
		panic(err)
	}
	program, err := evm.Link(module)
	if err != nil {
		panic(err)
	}
	session := evmtest.New(program)
	defer session.Release()
	err = session.RunWithBudget(context.Background(), "Loop", nil, nil, evm.Limits{Steps: 100})
	fmt.Println(errors.Is(err, evm.ErrSteps))
}
Output:
true

Jump to

Keyboard shortcuts

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