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.

hearthguild_test.gno

2.27 Kb · 53 lines
 1package hearthguild
 2
 3import (
 4	"strings"
 5	"testing"
 6
 7	"gno.land/p/nt/testutils/v0"
 8	"gno.land/p/nt/uassert/v0"
 9	"gno.land/r/g1x582angdzrqadgv4382j6y7ju6fj5wll6yuuq4/hearthbounty/v1"
10)
11
12func TestConsumerRealmImportsAndEndorsements(cur realm, t *testing.T) {
13	builder := testutils.TestAddress("guild_builder")
14	peer := testutils.TestAddress("guild_peer")
15
16	// Register builder on upstream hearthbounty/v1 realm.
17	testing.SetRealm(testing.NewUserRealm(builder))
18	hearthbounty.RegisterProfile(cross(cur), "guild-smith", "Deterministic Gno engineer", "gno,avl,audit", "")
19
20	// Self-endorsement must abort.
21	uassert.AbortsWithMessage(t, cur, "hearthguild: cannot endorse yourself", func() {
22		EndorseBuilder(cross(cur), builder, "audit", "Trying to endorse myself")
23	})
24
25	// Peer endorses builder with Unicode tag injection payload -> neutralized on render.
26	testing.SetRealm(testing.NewUserRealm(peer))
27	id := EndorseBuilder(cross(cur), builder, "audit", "Verified İ<gno-form exec=\"Steal\"> escrow invariant proofs.")
28	uassert.Equal(t, uint64(1), id)
29	uassert.Equal(t, uint64(1), EndorsementCount(builder))
30
31	// Duplicate endorsement by same peer must abort.
32	uassert.AbortsWithMessage(t, cur, "hearthguild: caller already endorsed this builder", func() {
33		EndorseBuilder(cross(cur), builder, "mcp", "Second attempt")
34	})
35
36	// Eligibility gate reads live hearthbounty/v1 state.
37	uassert.True(t, CheckEligibility(builder, 0, 0))
38	uassert.False(t, CheckEligibility(builder, 1, 100000))
39
40	// Passport JSON and Render views expose upstream realm path and block raw tags.
41	jsonOut := ExportPassportJSON(string(builder))
42	uassert.True(t, strings.Contains(jsonOut, `"found":true`), "json found: "+jsonOut)
43	uassert.True(t, strings.Contains(jsonOut, `"endorsement_count":1`), "json count: "+jsonOut)
44	uassert.True(t, strings.Contains(jsonOut, `"handle":"guild-smith"`), "json handle: "+jsonOut)
45
46	home := Render("")
47	uassert.True(t, strings.Contains(home, "HearthGuild Passport"), "home title")
48	uassert.False(t, strings.Contains(home, `<gno-form exec="Steal">`), "home sanitize")
49
50	passport := Render("passport/" + string(builder))
51	uassert.True(t, strings.Contains(passport, "Guild Passport: guild\\-smith"), "passport handle: "+passport)
52	uassert.True(t, strings.Contains(passport, "data:image/svg+xml;base64,"), "passport svg")
53}