bounded_test.gno
1.74 Kb · 51 lines
1package vouch
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. Anyone can add a vouch edge to somebody else's
12// page, with a zero bond, and nothing sweeps them. Both tables on an address
13// page rendered every edge, so the cost every reader of that page paid was set
14// by whoever had been most persistent.
15//
16// The loop is inline rather than in a helper on purpose: testing.SetRealm is
17// call-frame scoped, so switching account inside a helper leaves the crossing
18// call running as whoever the test body was, and every iteration records the
19// same edge. The first version of this test did exactly that, recorded one
20// voucher instead of two hundred, and still passed.
21func TestAnAddressPageIsBoundedByWhatItShows(cur realm, t *testing.T) {
22 reset()
23
24 for i := 0; i < 40; i++ {
25 fund(0)
26 testing.SetRealm(testing.NewUserRealm(testutils.TestAddress("v" + strconv.Itoa(i))))
27 Vouch(cross(cur), alice, "because "+strconv.Itoa(i))
28 }
29 small := Render("addr/" + alice.String())
30
31 for i := 40; i < 200; i++ {
32 fund(0)
33 testing.SetRealm(testing.NewUserRealm(testutils.TestAddress("v" + strconv.Itoa(i))))
34 Vouch(cross(cur), alice, "because "+strconv.Itoa(i))
35 }
36 big := Render("addr/" + alice.String())
37
38 if n := len(VouchedBy(alice)); n != 200 {
39 t.Fatalf("only %d voucher(s) were recorded, so this test is measuring nothing", n)
40 }
41
42 rowsSmall := strings.Count(small, "\n|")
43 rowsBig := strings.Count(big, "\n|")
44 if rowsSmall == 0 {
45 t.Fatal("no table rows rendered at all, so this test is measuring nothing")
46 }
47 if rowsBig > rowsSmall {
48 t.Errorf("the address page grew from %d rows to %d when the vouchers went from 40 to 200: "+
49 "anybody can set what every reader of this page pays", rowsSmall, rowsBig)
50 }
51}