helpers_test.gno
1.72 Kb · 43 lines
1package registry
2
3import (
4 pm "gno.land/p/moul/gnopm/v0"
5 "gno.land/p/nt/testutils/v0"
6)
7
8// Deterministic, checksum-valid test addresses. Made rather than typed: the
9// address-namespace rule turns on the bech32 alphabet, which drops 1, b, i and
10// o, so a plausible-looking hand-written "g1..." fails the check for a reason
11// that has nothing to do with what is under test.
12var (
13 alice = testutils.TestAddress("alice")
14 bob = testutils.TestAddress("bob")
15
16 // alicePkg sits in alice's OWN address namespace, which is the only
17 // ownership a test can create: r/sys/users is not writable from a unit
18 // test, so a name namespace can never resolve to a test account.
19 alicePkg = "gno.land/r/" + alice.String() + "/scratch/v0"
20)
21
22const (
23 repoURL = "https://github.com/moul/gno-contracts"
24 sha1Zero = "0000000000000000000000000000000000000000"
25 sha1One = "1111111111111111111111111111111111111111"
26 otherPkg = "gno.land/p/moul/md/v1"
27)
28
29// reset puts the realm back to its initial state. Realm globals persist for the
30// whole test binary and examples run after every Test, so anything that renders
31// starts from a known tree or its pinned output silently depends on test order.
32func reset() { reg = pm.New() }
33
34// seedFixture builds a deterministic registry straight through the library: no
35// chain context needed, which is what lets an Example use it. Going through the
36// library rather than through Register also skips the crossing call, which an
37// example cannot make.
38func seedFixture() {
39 reset()
40 reg.Register(alice, 100, alicePkg, repoURL, sha1Zero, "scratch", "refs/tags/v0.1.0")
41 reg.Register(bob, 110, alicePkg, "https://github.com/bob/impostor", sha1One, "", "")
42 reg.Register(alice, 120, otherPkg, repoURL, sha1One, "p/moul/md", "")
43}