Playground
access.gno
package testutils
// for testing access. see tests/files/access*.go
// NOTE: non-package variables cannot be overridden, except during init().
var (
TestVar1 int
testVar2 int
)
func init() {
TestVar1 = 123
testVar2 = 456
}
type TestAccessStruct struct {
PublicField string
privateField string
}
func (tas TestAccessStruct) PublicMethod() string {
return tas.PublicField + "/" + tas.privateField
}
func (tas TestAccessStruct) privateMethod() string {
return tas.PublicField + "/" + tas.privateField
}
func NewTestAccessStruct(pub, priv string) TestAccessStruct {
return TestAccessStruct{
PublicField: pub,
privateField: priv,
}
}
// see access6.g0 etc.
type PrivateInterface interface {
privateMethod() string
}
func PrintPrivateInterface(pi PrivateInterface) {
println("testutils.PrintPrivateInterface", pi.privateMethod())
}
crypto.gno
package testutils
import "crypto/bech32"
func TestAddress(name string) address {
if len(name) > 20 {
panic("address name cannot be greater than 20 bytes")
}
addr := []byte("____________________")
copy(addr[:], name)
converted, err := bech32.ConvertBits(addr, 8, 5, true)
if err != nil {
panic(err)
}
enc, err := bech32.Encode("g", converted)
if err != nil {
panic(err)
}
return address(enc)
}
crypto_test.gno
package testutils
import (
"testing"
)
func TestTestAddress(t *testing.T) {
testAddr := TestAddress("author1")
if string(testAddr) != "g1v96hg6r0wgc47h6lta047h6lta047h6lm33tq6" {
panic("not equal")
}
}
doc.gno
// 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. package testutils
gnomod.toml
module = "gno.land/p/nt/testutils/v0" gno = "0.9" [addpkg] creator = "g1edq4dugw0sgat4zxcw9xardvuydqf6cgleuc8p"
misc.gno
package testutils
// WrapCall adds a frame to the call stack, for testing call stack depth.
func WrapCall(fn func()) {
fn()
}