1package wiki23import (4 "strings"5 "testing"67 "gno.land/p/nt/uassert/v0"8)910// maxLines is how many typical lines fit in DefaultMaxBody: 32 KiB at 4311// bytes per line.12const maxLines = 7581314func buildLines(n int) string {15 var b strings.Builder16 for i := 0; i < n; i++ {17 b.WriteString("some article line of moderate length here.\n")18 }19 return b.String()20}2122// TestWorstCaseRendersStayWithinTheQueryBudget exercises the two render paths23// at the largest body MaxBody admits.24//25// vm/qrender runs under a fixed ceiling (maxGasQuery = 3e9 in26// gno.land/pkg/sdk/vm/keeper.go), which a reader cannot raise, so a render27// that exceeds it makes the page permanently unreadable. Measured with28// `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 ceiling31// article render of a 33 KB body with links 693M gas 23% of the ceiling32//33// gno test reports gas per test function but a test cannot assert on it, so34// this test pins the shape, not the number: it fails if either path starts35// panicking or truncating at the limit. Re-measure with `gno test -v` and36// 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")4142 now, h := at(1)43 _, err := w.Edit(alice, now, h, "Big", body, "", false)44 uassert.NoError(t, err)4546 p, err := w.Page("Big")47 uassert.NoError(t, err)4849 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")5152 now, h = at(2)53 _, err = w.Edit(alice, now, h, "Big", body+"added\n", "", false)54 uassert.NoError(t, err)5556 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}60Signatures reconstructed verbatim from vm/qfuncs — interface params keep their inline definitions.