Skip to content Search Apps Documentation Source Content 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.33 Kb · 41 lines
 1package crews
 2
 3import (
 4	"strconv"
 5	"strings"
 6	"testing"
 7)
 8
 9// Finding 325-cost-at-caps-1. A crew's page rendered every proposal the crew
10// had ever had. Proposing is open to every member and nothing deletes one, so
11// the cost every reader of that page paid grew without a bound anybody
12// controls.
13//
14// Both comparison points are above the cap on purpose: comparing a count below
15// it with one above measures the cap arriving, not the page being bounded.
16func TestACrewPageIsBoundedByWhatItShows(cur realm, t *testing.T) {
17	reset()
18	id := create(cur, alice, 1000000, "the crew")
19
20	for i := 0; i < 40; i++ {
21		testing.SetRealm(testing.NewUserRealm(alice))
22		Propose(cross(cur), id, "proposal number "+strconv.Itoa(i))
23	}
24	small := Render("crew/" + strconv.FormatInt(id, 10))
25
26	for i := 40; i < 200; i++ {
27		testing.SetRealm(testing.NewUserRealm(alice))
28		Propose(cross(cur), id, "proposal number "+strconv.Itoa(i))
29	}
30	big := Render("crew/" + strconv.FormatInt(id, 10))
31
32	rowsSmall := strings.Count(small, "\n|")
33	rowsBig := strings.Count(big, "\n|")
34	if rowsSmall == 0 {
35		t.Fatal("no table rows rendered at all, so this test is measuring nothing")
36	}
37	if rowsBig > rowsSmall {
38		t.Errorf("the crew page grew from %d rows to %d when the proposals went from 40 to 200: "+
39			"every reader pays for every proposal the crew has ever had", rowsSmall, rowsBig)
40	}
41}