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.

scan_test.gno

2.79 Kb · 84 lines
 1package home
 2
 3import (
 4	"testing"
 5
 6	"gno.land/p/nym-moultest123/mygnoscan/v0"
 7	"gno.land/p/nt/uassert/v0"
 8)
 9
10// TestScanPlaceholdersAreReserved is the one that actually protects the
11// design: every placeholder scan.gno answers for must also be refused as a
12// slot name, or a slot could take the name and the page would depend on which
13// callback dynreplacer registered last.
14func TestScanPlaceholdersAreReserved(t *testing.T) {
15	for _, p := range scanPlaceholders {
16		found := false
17		for _, r := range reservedSlugs {
18			if r == p {
19				found = true
20				break
21			}
22		}
23		uassert.True(t, found, "scan placeholder not reserved: "+p)
24	}
25}
26
27func TestScanSlugsAreWritableShapes(t *testing.T) {
28	// A reserved slug still has to be a legal slug, or reserving it is a
29	// no-op: an illegal name is refused for a different reason and the
30	// reservation never gets exercised.
31	for _, p := range scanPlaceholders {
32		uassert.True(t, validSlug(p), "scan placeholder is not a valid slug: "+p)
33	}
34}
35
36func TestSetRefusesScanSlugs(cur realm, t *testing.T) {
37	reset()
38	testing.SetRealm(testing.NewUserRealm(admin))
39	uassert.AbortsWithMessage(t, cur, "reserved slug: scan.realm is computed at render time", func() {
40		Set(cross(cur), "scan.realm", "anything")
41	})
42}
43
44// TestScanLinksFollowConfig is the end-to-end claim of this whole change: what
45// the page renders follows gno.land/r/nym-moultest123/config, so pointing moul's realms
46// at a different explorer is a transaction and not a redeploy.
47//
48// It cannot set the config from here (that needs config's own authority and a
49// crossing call into another realm), so it asserts the default path: unset
50// config means mygnoscan.DefaultBase, in the page, for real.
51func TestScanLinksFollowConfig(t *testing.T) {
52	reset()
53	seed("layout", ":scan.realm:")
54
55	uassert.Equal(t,
56		"[mygnoscan]("+mygnoscan.DefaultBase+"/realm/r/nym-moultest123/home)",
57		Render(""),
58		"with nothing configured the page falls back to the package default")
59}
60
61// ExampleRender_scan pins the explorer footer as a layout would use it. The
62// block link is deliberately absent: it moves with the chain, and an example
63// that pins it would fail on whichever test ran SkipHeights before it.
64func ExampleRender_scan() {
65	reset()
66	seed("layout", "# :owner:\n\n---\n\n:scan.realm: · :scan.me:\n")
67	print(Render(""))
68	// Output:
69	// # g1manfred47kzduec920z88wfr64ylksmdcedlf5
70	//
71	// ---
72	//
73	// [mygnoscan](https://mygnoscan.moul.p2p.team/realm/r/nym-moultest123/home) · [my account](https://mygnoscan.moul.p2p.team/address/g1manfred47kzduec920z88wfr64ylksmdcedlf5)
74}
75
76// ExampleRender_scanBase pins the raw base URL placeholder, which is what a
77// slot uses to build a link this realm has no helper for.
78func ExampleRender_scanBase() {
79	reset()
80	seed("layout", ":scan:\n")
81	print(Render(""))
82	// Output:
83	// https://mygnoscan.moul.p2p.team
84}