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.

erratademo_test.gno

2.58 Kb · 61 lines
 1package erratademo
 2
 3import (
 4	"strconv"
 5	"strings"
 6	"testing"
 7
 8	"gno.land/r/g132vz03ycpaagtef4jmxjakstkppgyc5wn3r807/erratabank/v1"
 9)
10
11func TestEmbedAcceptedErrata(cur realm, t *testing.T) {
12	if BookID() != 0 || !strings.Contains(Render(""), "No errata yet.") {
13		t.Fatal("an unlinked guide should render its empty state")
14	}
15	// The unit-test loader has no deployment transaction or creator.
16	owner = address("g1dmt3sa5ucvecxuhf3j6ne5r0e3z4x7h6c03xc0")
17	reader := address("g1akeqsvhucjt8gf5yupyzjxsjd29wv8fayng37c")
18	testing.SetRealm(testing.NewUserRealm(owner))
19	id := erratabank.CreateBook(cross(cur), "Quickstart", "First", "https://example.org/guide", 0)
20	testing.SetRealm(testing.NewUserRealm(reader))
21	reportID := erratabank.Submit(cross(cur), id, "Section 1", "Use the new endpoint.")
22	if got := revive(func() { SetBook(cross(cur), id) }); got != "demo deployer only" {
23		t.Fatalf("unexpected unauthorized result: %v", got)
24	}
25
26	testing.SetRealm(testing.NewUserRealm(owner))
27	if got := revive(func() { SetBook(cross(cur), 0) }); got != "book not found" {
28		t.Fatalf("unexpected missing book result: %v", got)
29	}
30	SetBook(cross(cur), id)
31	if got := revive(func() { SetBook(cross(cur), id) }); got != "demo book already set" {
32		t.Fatalf("unexpected second link result: %v", got)
33	}
34	if BookID() != id || strings.Contains(Render(""), "Use the new endpoint") {
35		t.Fatal("pending reports should stay out of the embedded section")
36	}
37
38	erratabank.Accept(cross(cur), reportID, "Confirmed")
39	rendered := Render("")
40	if !strings.Contains(rendered, "## Errata") || !strings.Contains(rendered, "Use the new endpoint") {
41		t.Fatalf("accepted correction missing from guide: %s", rendered)
42	}
43	if got := Render("?page=2"); !strings.Contains(got, "Errata page not found.") {
44		t.Fatalf("unexpected out-of-range page: %s", got)
45	}
46	for i := 2; i <= 21; i++ {
47		testing.SetRealm(testing.NewUserRealm(reader))
48		report := erratabank.Submit(cross(cur), id, "Example "+strconv.Itoa(i), "Use the corrected example.")
49		testing.SetRealm(testing.NewUserRealm(owner))
50		erratabank.Accept(cross(cur), report, "")
51	}
52	firstPage, secondPage := Render(""), Render("?page=2")
53	if !strings.Contains(firstPage, "Example 20") || strings.Contains(firstPage, "Example 21") ||
54		!strings.Contains(firstPage, "[Next]") || !strings.Contains(secondPage, "Example 21") ||
55		strings.Contains(secondPage, "Example 20") || !strings.Contains(secondPage, "[Previous]") {
56		t.Fatalf("wrong embedded pagination: %s", secondPage)
57	}
58	if !strings.Contains(firstPage, "Reports are public and permanent on-chain.") {
59		t.Fatal("the guide is missing the public submission notice")
60	}
61}