zz_bounds_test.gno
1.50 Kb · 44 lines
1package linktree
2
3import (
4 "strings"
5 "testing"
6
7 "gno.land/p/nt/testutils/v0"
8 "gno.land/p/nt/uassert/v0"
9)
10
11// A profile holds a bounded number of links of bounded size, and removing one
12// keeps the others in order.
13func TestLinksAreBounded(cur realm, t *testing.T) {
14 who := testutils.TestAddress("bounded")
15 testing.SetRealm(testing.NewUserRealm(who))
16 uassert.AbortsContains(t, cur, "bio too long", func() { SetBio(cross(cur), strings.Repeat("b", MaxBioLen+1)) })
17 for i := 0; i < MaxLinks; i++ {
18 AddLink(cross(cur), "l", "https://e.example/"+strings.Repeat("x", i))
19 }
20 uassert.AbortsContains(t, cur, "at most", func() { AddLink(cross(cur), "l", "https://e.example/") })
21 RemoveLink(cross(cur), 0)
22 p := profiles.Get(who.String()).(*profile)
23 uassert.Equal(t, MaxLinks-1, len(p.Links))
24 uassert.Equal(t, "https://e.example/x", p.Links[0].URL)
25}
26
27// The profile count is bounded globally, not just per address.
28func TestProfileCountIsBounded(cur realm, t *testing.T) {
29 var added []string
30 for i := 0; profiles.Size() < MaxProfiles; i++ {
31 k := testutils.TestAddress("p" + strings.Repeat("x", i%7) + string(rune('a'+i%26)) + string(rune('a'+i/26%26)) + string(rune('a'+i/676%26))).String()
32 if profiles.Get(k) == nil {
33 profiles.Set(k, &profile{})
34 added = append(added, k)
35 }
36 }
37 defer func() {
38 for _, k := range added {
39 profiles.Remove(k)
40 }
41 }()
42 testing.SetRealm(testing.NewUserRealm(testutils.TestAddress("latecomer")))
43 uassert.AbortsContains(t, cur, "linktree is full", func() { SetBio(cross(cur), "hi") })
44}