Skip to content Search Apps Documentation Source Content 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.

counter.gno

1.35 Kb · 46 lines
 1// Package counter is the smallest realm that still proves the whole pipeline:
 2// it is deployed, approved, called with an int and a string, read back through
 3// Render and through QEval, and made to abort on purpose.
 4//
 5// It imports nothing but strconv, deliberately. A smoke test that fails because
 6// a stdlib package moved between chain versions reports a problem with itself,
 7// not with the chain, and that is the one failure mode this file must not have.
 8package counter
 9
10import "strconv"
11
12var (
13	count int
14	note  string
15)
16
17// Increment adds n and returns the new total. It panics on a non-positive n,
18// which is what the scenario's expect_fail step exercises: a realm that aborts
19// is a different outcome from one that is unreachable, and only a real chain
20// tells the two apart.
21func Increment(cur realm, n int) int {
22	if n <= 0 {
23		panic("increment must be positive")
24	}
25	count += n
26	return count
27}
28
29// SetNote stores a short string, so the scenario covers a string argument
30// surviving the round trip through amino and back out of Render.
31func SetNote(cur realm, s string) {
32	if len(s) > 64 {
33		panic("note too long")
34	}
35	note = s
36}
37
38// Get is the QEval target: an int return, read with no gas and no key.
39func Get() int { return count }
40
41func Render(path string) string {
42	if path == "note" {
43		return "note: " + note
44	}
45	return "count: " + strconv.Itoa(count)
46}