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.

bounded_test.gno

1.45 Kb · 46 lines
 1package patron
 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. A plan page rendered every all-time supporter.
12// Subscribe is permissionless and nothing ever removes a supporter, so the
13// cheapest way to make somebody's page expensive was to subscribe from many
14// addresses.
15//
16// Both comparison points are above the cap on purpose: comparing a count below
17// it with one above it measures the cap arriving, not the page being bounded.
18// The loops are inline because testing.SetRealm is call-frame scoped.
19func TestAPlanPageIsBoundedByWhatItShows(cur realm, t *testing.T) {
20	reset()
21	id := open(cur, t)
22
23	for i := 0; i < 40; i++ {
24		pay(price)
25		testing.SetRealm(testing.NewUserRealm(testutils.TestAddress("sub" + strconv.Itoa(i))))
26		Subscribe(cross(cur), id)
27	}
28	small := Render("plan/" + strconv.FormatInt(id, 10))
29
30	for i := 40; i < 200; i++ {
31		pay(price)
32		testing.SetRealm(testing.NewUserRealm(testutils.TestAddress("sub" + strconv.Itoa(i))))
33		Subscribe(cross(cur), id)
34	}
35	big := Render("plan/" + strconv.FormatInt(id, 10))
36
37	rowsSmall := strings.Count(small, "\n|")
38	rowsBig := strings.Count(big, "\n|")
39	if rowsSmall == 0 {
40		t.Fatal("no table rows rendered at all, so this test is measuring nothing")
41	}
42	if rowsBig > rowsSmall {
43		t.Errorf("the plan page grew from %d rows to %d when the supporters went from 40 to 200: "+
44			"every reader pays for every address that ever subscribed", rowsSmall, rowsBig)
45	}
46}