Skip to content Search Apps Documentation Source Content Run Reset Eval Playground File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

Playground

gnomod.toml

module = "gno.land/r/g1dxg6leh2vsde83qxcpprvj2xljqz6fg2jp2t08/probe"
gno = "0.9"

[addpkg]
  creator = "g1dxg6leh2vsde83qxcpprvj2xljqz6fg2jp2t08"
  height = 1360418
  max_deposit = "5000000ugnot"

probe.gno

// Package probe measures how long a package waits for approval on Onyx.
package probe

import "strconv"

var (
	count int
	last  address
)

// Bump increments the counter, remembers the caller and returns the new count.
func Bump(cur realm) int {
	count++
	last = cur.Previous().Address()
	return count
}

func Render(path string) string {
	s := "# probe\n\nCounter: " + strconv.Itoa(count) + "\n"
	if last != "" {
		s += "\nLast caller: " + last.String() + "\n"
	}
	return s
}

probe_test.gno

package probe

import (
	"strings"
	"testing"

	"gno.land/p/nt/testutils/v0"
	"gno.land/p/nt/uassert/v0"
)

func TestBump(cur realm, t *testing.T) {
	uassert.True(t, strings.Contains(Render(""), "Counter: 0"), "starts at zero")
	alice := testutils.TestAddress("alice")
	testing.SetRealm(testing.NewUserRealm(alice))
	uassert.Equal(t, 1, Bump(cross(cur)))
	uassert.Equal(t, 2, Bump(cross(cur)))
	uassert.True(t, strings.Contains(Render(""), "Counter: 2"), "render shows the count")
	uassert.True(t, strings.Contains(Render(""), alice.String()), "render shows the last caller")
}