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.

receipt_test.gno

2.20 Kb · 69 lines
 1package receipt
 2
 3import (
 4	"testing"
 5
 6	"gno.land/p/nt/testutils/v0"
 7	"gno.land/p/nt/uassert/v0"
 8)
 9
10var (
11	agentKey = testutils.TestAddress("agent")
12	val1     = testutils.TestAddress("validator1")
13	val2     = testutils.TestAddress("validator2")
14)
15
16func TestRecordAndAttest(cur realm, t *testing.T) {
17	testing.SetRealm(testing.NewUserRealm(agentKey))
18	seq := Record(cross(cur), "percy", "task#1", "in#1", "out#1", "claude-opus-4-8", "policy-v1", "tools#1", false)
19	uassert.Equal(t, uint64(1), seq)
20	uassert.Equal(t, 1, Count())
21
22	// Fresh receipt is unverified: no attestations.
23	pos, rej := Confirmations(seq)
24	uassert.Equal(t, 0, pos)
25	uassert.Equal(t, 0, rej)
26
27	// Two independent validators attest.
28	testing.SetRealm(testing.NewUserRealm(val1))
29	Attest(cross(cur), seq, VerdictReproduced, "re-ran, matched")
30	testing.SetRealm(testing.NewUserRealm(val2))
31	Attest(cross(cur), seq, VerdictTestsPass, "suite green")
32
33	pos, rej = Confirmations(seq)
34	uassert.Equal(t, 2, pos)
35	uassert.Equal(t, 0, rej)
36
37	uassert.True(t, len(Render("")) > 0)
38	uassert.True(t, len(Render("1")) > 0)
39}
40
41func TestNoSelfAttest(cur realm, t *testing.T) {
42	testing.SetRealm(testing.NewUserRealm(agentKey))
43	seq := Record(cross(cur), "percy", "task#2", "in#2", "out#2", "rt", "p", "tr", false)
44
45	// The author cannot attest to their own receipt.
46	uassert.AbortsWithMessage(t, cur, "author cannot attest to their own receipt", func(cur realm) {
47		Attest(cur, seq, VerdictReproduced, "trust me")
48	})
49}
50
51func TestNoDoubleAttest(cur realm, t *testing.T) {
52	testing.SetRealm(testing.NewUserRealm(agentKey))
53	seq := Record(cross(cur), "percy", "task#3", "in#3", "out#3", "rt", "p", "tr", false)
54
55	testing.SetRealm(testing.NewUserRealm(val1))
56	Attest(cross(cur), seq, VerdictOutputMatch, "ok")
57	uassert.AbortsWithMessage(t, cur, "validator already attested", func(cur realm) {
58		Attest(cur, seq, VerdictRejected, "changed my mind")
59	})
60}
61
62func TestBadVerdict(cur realm, t *testing.T) {
63	testing.SetRealm(testing.NewUserRealm(agentKey))
64	seq := Record(cross(cur), "percy", "task#4", "in#4", "out#4", "rt", "p", "tr", false)
65	testing.SetRealm(testing.NewUserRealm(val1))
66	uassert.AbortsWithMessage(t, cur, "unknown verdict: maybe", func(cur realm) {
67		Attest(cur, seq, "maybe", "")
68	})
69}