bounded_test.gno
1.55 Kb · 50 lines
1package grants
2
3import (
4 "strconv"
5 "strings"
6 "testing"
7
8 "gno.land/p/nt/testutils/v0"
9)
10
11// Finding 325-cost-at-caps-1. The board's index rendered every request ever
12// made. Apply is open to anyone and nothing removes a request, so the cost
13// every reader of the board paid was set by whoever had applied the most.
14//
15// Both comparison points are above the cap on purpose: comparing a count below
16// it with one above measures the cap arriving, not the page being bounded.
17func TestTheBoardIndexIsBoundedByWhatItShows(t *testing.T) {
18 p := NewProgram("ugnot", alice, bob, carol)
19 rr := Renderer{
20 Program: p, Title: "Board", Intro: "x",
21 Path: "gno.land/r/example/board/v0", Link: "/r/example/board/v0",
22 Treasury: testutils.TestAddress("treasury"), Balance: 0,
23 }
24
25 apply := func(from, to int) {
26 for i := from; i < to; i++ {
27 who := testutils.TestAddress("applicant" + strconv.Itoa(i))
28 if _, err := p.Apply(who, "Request "+strconv.Itoa(i),
29 "A body long enough to be accepted by the validator.",
30 "one milestone:100", int64(1000+i)); err != nil {
31 t.Fatalf("Apply(%d): %v", i, err)
32 }
33 }
34 }
35
36 apply(0, 40)
37 small := rr.Render("")
38 apply(40, 200)
39 big := rr.Render("")
40
41 rowsSmall := strings.Count(small, "\n|")
42 rowsBig := strings.Count(big, "\n|")
43 if rowsSmall == 0 {
44 t.Fatal("no table rows rendered at all, so this test is measuring nothing")
45 }
46 if rowsBig > rowsSmall {
47 t.Errorf("the board index grew from %d rows to %d when the requests went from 40 to 200: "+
48 "anybody can set what every reader of this board pays", rowsSmall, rowsBig)
49 }
50}