limits_test.gno
1.99 Kb · 59 lines
1package wiki
2
3import (
4 "strings"
5 "testing"
6
7 "gno.land/p/nt/uassert/v0"
8)
9
10// maxLines is how many typical lines fit in DefaultMaxBody: 32 KiB at 43
11// bytes per line.
12const maxLines = 758
13
14func buildLines(n int) string {
15 var b strings.Builder
16 for i := 0; i < n; i++ {
17 b.WriteString("some article line of moderate length here.\n")
18 }
19 return b.String()
20}
21
22// TestWorstCaseRendersStayWithinTheQueryBudget exercises the two render paths
23// at the largest body MaxBody admits.
24//
25// vm/qrender runs under a fixed ceiling (maxGasQuery = 3e9 in
26// gno.land/pkg/sdk/vm/keeper.go), which a reader cannot raise, so a render
27// that exceeds it makes the page permanently unreadable. Measured with
28// `gno test -v` on gno master.184 (2026-09-17):
29//
30// diff of a 33 KB body against itself plus one line 691M gas 23% of the ceiling
31// article render of a 33 KB body with links 693M gas 23% of the ceiling
32//
33// gno test reports gas per test function but a test cannot assert on it, so
34// this test pins the shape, not the number: it fails if either path starts
35// panicking or truncating at the limit. Re-measure with `gno test -v` and
36// update the table when either path changes.
37func TestWorstCaseRendersStayWithinTheQueryBudget(t *testing.T) {
38 w := New(3, DefaultMaxBody)
39 body := buildLines(maxLines-2) + "see [[Other page]]\n[[Category:Big]]\n"
40 uassert.True(t, len(body) < DefaultMaxBody, "the fixture must fit in MaxBody")
41
42 now, h := at(1)
43 _, err := w.Edit(alice, now, h, "Big", body, "", false)
44 uassert.NoError(t, err)
45
46 p, err := w.Page("Big")
47 uassert.NoError(t, err)
48
49 c := Ctx{Base: "/r/moul/x/wiki/v0", Exists: w.Exists}
50 uassert.True(t, len(RenderArticle(c, w, p, nil)) > len(body), "the article must render in full")
51
52 now, h = at(2)
53 _, err = w.Edit(alice, now, h, "Big", body+"added\n", "", false)
54 uassert.NoError(t, err)
55
56 hist := p.History(0, 2)
57 out := RenderDiff(c, p, hist[1], hist[0])
58 uassert.True(t, strings.Contains(out, "+1 −0 lines"), "a one-line append to a 32 KiB body diffs exactly")
59}