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.

helpers_test.gno

2.49 Kb · 73 lines
 1package forge
 2
 3import (
 4	"strings"
 5
 6	fg "gno.land/p/g1magld5ptgzaktqcexxq0pgq5lmdf0kz6re8hlv/forge/v1"
 7	"gno.land/p/nt/testutils/v0"
 8)
 9
10// Deterministic, checksum-valid test addresses.
11var (
12	alice = testutils.TestAddress("alice") // owner
13	bob   = testutils.TestAddress("bob")   // maintainer
14	carol = testutils.TestAddress("carol") // writer
15	eve   = testutils.TestAddress("eve")   // stranger
16)
17
18// Repo ids used by the crossing tests. The realm only lets an address create
19// under a namespace it owns, and no user name is registered in a unit test, so
20// these are all address namespaces.
21var (
22	demoID    = alice.String() + "/demo"
23	heightsID = alice.String() + "/heights"
24	rolesID   = alice.String() + "/roles"
25	ghostID   = alice.String() + "/ghost"
26)
27
28func oid(c string) string { return strings.Repeat(c, 40) }
29
30// reset restores realm state to empty. Realm globals persist for the whole test
31// binary and examples run after every Test, so anything that pins Render output
32// must reset and re-seed first.
33func reset() { f = fg.New() }
34
35// seedFixture builds one deterministic repo straight through the library: no
36// chain context needed, which is what lets an Example use it. It can use a name
37// namespace because namespace ownership is a realm rule (it needs a chain to
38// resolve a name); the library validates the shape and nothing more.
39func seedFixture() {
40	reset()
41	r, err := f.CreateRepo(alice, 100, "moul/forge", "an on chain software forge", "")
42	if err != nil {
43		panic(err)
44	}
45	if err := r.SetMember(alice, bob, fg.RoleMaintainer); err != nil {
46		panic(err)
47	}
48	if err := r.SetMember(alice, carol, fg.RoleWriter); err != nil {
49		panic(err)
50	}
51	if err := r.SetMirrors(alice, []string{"https://github.com/moul/gno-contracts.git"}); err != nil {
52		panic(err)
53	}
54	if _, err := r.SetRef(carol, 101, "refs/heads/main", "", oid("a"), "initial import"); err != nil {
55		panic(err)
56	}
57	if _, err := r.SetRef(carol, 102, "refs/heads/main", oid("a"), oid("b"), "add the log"); err != nil {
58		panic(err)
59	}
60	if _, err := r.OpenIssue(eve, 103, "force pushes are invisible", "A maintainer can rewrite a branch and nothing records it.", []string{"bug"}); err != nil {
61		panic(err)
62	}
63	if _, err := r.CommentIssue(bob, 104, 0, "that is what the log is for"); err != nil {
64		panic(err)
65	}
66	c, err := r.OpenChange(carol, 105, "record every ref move", "closes 0", "", "refs/heads/feat", oid("c"), "refs/heads/main")
67	if err != nil {
68		panic(err)
69	}
70	if err := r.ReviewChange(bob, 106, c.ID, fg.VerdictApprove, "lgtm"); err != nil {
71		panic(err)
72	}
73}