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

/p/nt/testutils/v0

Directory · 7 Files
README.md Open

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.