Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

v0 source pure

v0 - Unaudited: This is an initial version that has not yet been formally audited. A fully audited version will be pu...

Readme View source

v0 - Unaudited This is an initial version of this package that has not yet been formally audited. A fully audited version will be published as a subsequent release. Use in production at your own risk.

testutils - misc testing helpers

Small grab-bag of helpers for _test.gno files: deterministic fake addresses, a call-stack wrapper, and fixtures exercising access rules (exported/unexported fields, methods, and interfaces).

Usage

 1import (
 2    "testing"
 3
 4    "gno.land/p/nt/testutils/v0"
 5)
 6
 7func TestTransfer(t *testing.T) {
 8    alice := testutils.TestAddress("alice") // deterministic g1... address
 9    bob := testutils.TestAddress("bob")
10
11    testutils.WrapCall(func() {
12        Transfer(alice, bob, 100)
13    })
14}

API

Addresses:

1// TestAddress returns a deterministic bech32 g1... address derived from name.
2// name must be at most 20 bytes; it is right-padded with '_' before encoding.
3func TestAddress(name string) address

Call-stack helper:

1// WrapCall invokes fn after adding one extra frame to the call stack.
2// Useful for tests that inspect caller depth.
3func WrapCall(fn func())

Access-rule fixtures (used by VM file tests to exercise exported vs. unexported visibility):

 1type TestAccessStruct struct {
 2    PublicField  string
 3    // privateField is unexported on purpose.
 4}
 5
 6func NewTestAccessStruct(pub, priv string) TestAccessStruct
 7func (TestAccessStruct) PublicMethod() string
 8
 9type PrivateInterface interface {
10    // unexported method — only satisfiable from within this package.
11}
12
13func PrintPrivateInterface(pi PrivateInterface)
14
15var TestVar1 int // initialized to 123 in init()

Notes

  • TestAddress panics if name exceeds 20 bytes; the resulting address is reproducible across runs, which is what you want in tests.
  • The access fixtures exist mainly to back GnoVM file tests under gnovm/tests/files/; most user code only needs TestAddress.

Overview

v0 - Unaudited: This is an initial version that has not yet been formally audited. A fully audited version will be published as a subsequent release. Use in production at your own risk.

Package testutils provides testing utilities for Gno packages and realms.

Variables 1

var TestVar1, testVar2

1var (
2	TestVar1 int
3	testVar2 int
4)
source

NOTE: non-package variables cannot be overridden, except during init().

Functions 3

func WrapCall

1func WrapCall(fn func())
source

WrapCall adds a frame to the call stack, for testing call stack depth.

Types 2

type PrivateInterface

interface
1type PrivateInterface interface {
2	privateMethod() string
3}
source

see access6.g0 etc.

type TestAccessStruct

struct
1type TestAccessStruct struct {
2	PublicField  string
3	privateField string
4}
source

Methods on TestAccessStruct

func PublicMethod

method on TestAccessStruct
1func (tas TestAccessStruct) PublicMethod() string
source

Imports 1

  • crypto/bech32 stdlib

Source Files 7