Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

pilot_test.gno

1.74 Kb · 52 lines
 1package pilot
 2
 3import (
 4	"testing"
 5
 6	"gno.land/p/nt/testutils/v0"
 7	"gno.land/p/nt/uassert/v0"
 8)
 9
10var (
11	// the address Claim is pinned to, not a test address
12	moul    = address("g1manfred47kzduec920z88wfr64ylksmdcedlf5")
13	someone = testutils.TestAddress("someone")
14)
15
16func TestClaimIsOnceAndOwnerGated(cur realm, t *testing.T) {
17	// anyone else racing the deploy is refused, which is the whole point of
18	// pinning the address in the source
19	testing.SetRealm(testing.NewUserRealm(someone))
20	uassert.AbortsContains(t, cur, "only g1manfred", func() { Claim(cross(cur)) })
21
22	testing.SetRealm(testing.NewUserRealm(moul))
23	Claim(cross(cur))
24	uassert.Equal(t, moul.String(), acct.Owner().String())
25
26	testing.SetRealm(testing.NewUserRealm(someone))
27	uassert.AbortsContains(t, cur, "already claimed", func() { Claim(cross(cur)) })
28	uassert.AbortsContains(t, cur, "not the owner", func() {
29		Approve(cross(cur), "gno.land/r/x/nope/v0", "nope", false, 1)
30	})
31
32	testing.SetRealm(testing.NewUserRealm(moul))
33	uassert.AbortsContains(t, cur, "[a-zA-Z0-9._/-]", func() {
34		Approve(cross(cur), "gno.land/r/x/nope/v0", "pay|out", false, 1)
35	})
36}
37
38func TestRender(cur realm, t *testing.T) {
39	testing.SetRealm(testing.NewUserRealm(moul))
40	Approve(cross(cur), "gno.land/r/moul/x/pilotdemo/v0", "payout", false, 250)
41
42	want := "# gno.land/r/moul/pilot/v0\n\n" +
43		"| | |\n|---|---|\n" +
44		"| owner | " + moul.String() + " |\n" +
45		"| treasury | " + Address().String() + " |\n" +
46		"| balance | 0 ugnot |\n\n" +
47		"## powers\n\n" +
48		"| path | grant | identity | state | left | runs | sub-treasury |\n" +
49		"|---|---|---|---|---|---|---|\n" +
50		"| `gno.land/r/moul/x/pilotdemo/v0` | purse | `gno.land/r/moul/pilot/v0#payout` | approved | 250 | 0 | 0 ugnot |\n"
51	uassert.Equal(t, want, Render(""))
52}