Skip to content

Commit ac0d139

Browse files
authored
feat: reorganize examples for upcoming namespace support (#336)
* [x] move `examples/gno.land/*` to future namespaces `r/system`, ... * [x] update contracts’ imports. * [x] update genesis with new paths. * [x] update various links pointing to previous URLs. Signed-off-by: Manfred Touron <[email protected]>
1 parent 789c909 commit ac0d139

File tree

215 files changed

+732
-730
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

215 files changed

+732
-730
lines changed

cmd/gnodev/main_test.go

+14-14
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func TestMain(t *testing.T) {
3939
{args: []string{"repl", "--help"}, stdoutShouldContain: "# replOptions options\n-"},
4040

4141
// custom
42-
{args: []string{"test", "../../examples/gno.land/p/rand"}, stderrShouldContain: "ok ./../../examples/gno.land/p/rand \t"},
42+
{args: []string{"test", "../../examples/gno.land/p/demo/rand"}, stderrShouldContain: "ok ./../../examples/gno.land/p/demo/rand \t"},
4343
{args: []string{"test", "../../tests/integ/no-such-dir"}, errShouldContain: "no such file or directory"},
4444
{args: []string{"test", "../../tests/integ/empty-dir"}}, // FIXME: should have an output
4545
{args: []string{"test", "../../tests/integ/minimalist-gno1"}, stderrShouldBe: "? ./../../tests/integ/minimalist-gno1 \t[no test files]\n"},
@@ -72,19 +72,19 @@ func TestMain(t *testing.T) {
7272
{args: []string{"test", "../../tests/integ/failing2", "--verbose", "--precompile"}, stderrShouldBe: "=== PREC ./../../tests/integ/failing2\n=== BUILD ./../../tests/integ/failing2\n=== RUN file/failing_filetest.gno\n", recoverShouldBe: "fail on ../../tests/integ/failing2/failing_filetest.gno: got unexpected error: beep boop"},
7373

7474
// test opts
75-
{args: []string{"test", "../../examples/gno.land/p/ufmt"}, stderrShouldContain: "ok ./../../examples/gno.land/p/ufmt"},
76-
{args: []string{"test", "../../examples/gno.land/p/ufmt", "--verbose"}, stderrShouldContain: "ok ./../../examples/gno.land/p/ufmt"},
77-
{args: []string{"test", "../../examples/gno.land/p/ufmt", "--verbose", "--run", ".*"}, stderrShouldContain: "ok ./../../examples/gno.land/p/ufmt"},
78-
{args: []string{"test", "../../examples/gno.land/p/ufmt", "--verbose", "--run", "NoExists"}, stderrShouldContain: "ok ./../../examples/gno.land/p/ufmt"},
79-
{args: []string{"test", "../../examples/gno.land/p/ufmt", "--verbose", "--run", ".*/hello"}, stderrShouldContain: "ok ./../../examples/gno.land/p/ufmt"},
80-
{args: []string{"test", "../../examples/gno.land/p/ufmt", "--verbose", "--run", ".*/hi"}, stderrShouldContain: "ok ./../../examples/gno.land/p/ufmt"},
81-
{args: []string{"test", "../../examples/gno.land/p/ufmt", "--verbose", "--run", ".*/NoExists"}, stderrShouldContain: "ok ./../../examples/gno.land/p/ufmt"},
82-
{args: []string{"test", "../../examples/gno.land/p/ufmt", "--verbose", "--run", ".*/hello/NoExists"}, stderrShouldContain: "ok ./../../examples/gno.land/p/ufmt"},
83-
{args: []string{"test", "../../examples/gno.land/p/ufmt", "--verbose", "--run", "Sprintf/"}, stderrShouldContain: "ok ./../../examples/gno.land/p/ufmt"},
84-
{args: []string{"test", "../../examples/gno.land/p/ufmt", "--verbose", "--run", "Sprintf/.*"}, stderrShouldContain: "ok ./../../examples/gno.land/p/ufmt"},
85-
{args: []string{"test", "../../examples/gno.land/p/ufmt", "--verbose", "--run", "Sprintf/hello"}, stderrShouldContain: "ok ./../../examples/gno.land/p/ufmt"},
86-
{args: []string{"test", "../../examples/gno.land/p/ufmt", "--verbose", "--timeout", "100000000000" /* 100s */}, stderrShouldContain: "ok ./../../examples/gno.land/p/ufmt"},
87-
// {args: []string{"test", "../../examples/gno.land/p/ufmt", "--verbose", "--timeout", "10000" /* 10µs */}, recoverShouldContain: "test timed out after"}, // FIXME: should be testable
75+
{args: []string{"test", "../../examples/gno.land/p/demo/ufmt"}, stderrShouldContain: "ok ./../../examples/gno.land/p/demo/ufmt"},
76+
{args: []string{"test", "../../examples/gno.land/p/demo/ufmt", "--verbose"}, stderrShouldContain: "ok ./../../examples/gno.land/p/demo/ufmt"},
77+
{args: []string{"test", "../../examples/gno.land/p/demo/ufmt", "--verbose", "--run", ".*"}, stderrShouldContain: "ok ./../../examples/gno.land/p/demo/ufmt"},
78+
{args: []string{"test", "../../examples/gno.land/p/demo/ufmt", "--verbose", "--run", "NoExists"}, stderrShouldContain: "ok ./../../examples/gno.land/p/demo/ufmt"},
79+
{args: []string{"test", "../../examples/gno.land/p/demo/ufmt", "--verbose", "--run", ".*/hello"}, stderrShouldContain: "ok ./../../examples/gno.land/p/demo/ufmt"},
80+
{args: []string{"test", "../../examples/gno.land/p/demo/ufmt", "--verbose", "--run", ".*/hi"}, stderrShouldContain: "ok ./../../examples/gno.land/p/demo/ufmt"},
81+
{args: []string{"test", "../../examples/gno.land/p/demo/ufmt", "--verbose", "--run", ".*/NoExists"}, stderrShouldContain: "ok ./../../examples/gno.land/p/demo/ufmt"},
82+
{args: []string{"test", "../../examples/gno.land/p/demo/ufmt", "--verbose", "--run", ".*/hello/NoExists"}, stderrShouldContain: "ok ./../../examples/gno.land/p/demo/ufmt"},
83+
{args: []string{"test", "../../examples/gno.land/p/demo/ufmt", "--verbose", "--run", "Sprintf/"}, stderrShouldContain: "ok ./../../examples/gno.land/p/demo/ufmt"},
84+
{args: []string{"test", "../../examples/gno.land/p/demo/ufmt", "--verbose", "--run", "Sprintf/.*"}, stderrShouldContain: "ok ./../../examples/gno.land/p/demo/ufmt"},
85+
{args: []string{"test", "../../examples/gno.land/p/demo/ufmt", "--verbose", "--run", "Sprintf/hello"}, stderrShouldContain: "ok ./../../examples/gno.land/p/demo/ufmt"},
86+
{args: []string{"test", "../../examples/gno.land/p/demo/ufmt", "--verbose", "--timeout", "100000000000" /* 100s */}, stderrShouldContain: "ok ./../../examples/gno.land/p/demo/ufmt"},
87+
// {args: []string{"test", "../../examples/gno.land/p/demo/ufmt", "--verbose", "--timeout", "10000" /* 10µs */}, recoverShouldContain: "test timed out after"}, // FIXME: should be testable
8888
}
8989

9090
for _, test := range tc {

cmd/gnoland/main.go

+13-12
Original file line numberDiff line numberDiff line change
@@ -132,18 +132,19 @@ func makeGenesisDoc(pvPub crypto.PubKey) *bft.GenesisDoc {
132132
test1 := crypto.MustAddressFromString("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5")
133133
txs := []std.Tx{}
134134
for _, path := range []string{
135-
"p/ufmt",
136-
"p/avl",
137-
"p/grc/exts",
138-
"p/grc/grc20",
139-
"p/grc/grc721",
140-
"p/maths",
141-
"p/blog",
142-
"r/users",
143-
"r/foo20",
144-
"r/boards",
145-
"r/banktest",
146-
"r/gnoblog", // TODO: move to gnoland/blog
135+
"p/demo/ufmt",
136+
"p/demo/avl",
137+
"p/demo/grc/exts",
138+
"p/demo/grc/grc20",
139+
"p/demo/grc/grc721",
140+
"p/demo/maths",
141+
"p/demo/blog",
142+
"r/demo/users",
143+
"r/demo/foo20",
144+
"r/demo/boards",
145+
"r/demo/banktest",
146+
"r/gnoland/blog",
147+
"r/gnoland/faucet",
147148
} {
148149
// open files in directory as MemPackage.
149150
memPkg := gno.ReadMemPackage(filepath.Join(".", "examples", "gno.land", path), "gno.land/"+path)

examples/gno.land/p/acl/acl_test.gno

-140
This file was deleted.

examples/gno.land/p/acl/acl.gno examples/gno.land/p/demo/acl/acl.gno

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package acl
33
import (
44
"std"
55

6-
"gno.land/p/avl"
6+
"gno.land/p/demo/avl"
77
)
88

99
func New() *Directory {
+140
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
package acl
2+
3+
import (
4+
"std"
5+
"testing"
6+
7+
"gno.land/p/demo/testutils"
8+
)
9+
10+
func Test(t *testing.T) {
11+
adm := testutils.TestAddress("admin")
12+
mod := testutils.TestAddress("mod")
13+
usr := testutils.TestAddress("user")
14+
cst := testutils.TestAddress("custom")
15+
16+
dir := New()
17+
18+
// by default, no one has perm.
19+
shouldNotHasRole(t, dir, adm, "foo")
20+
shouldNotHasRole(t, dir, mod, "foo")
21+
shouldNotHasRole(t, dir, usr, "foo")
22+
shouldNotHasRole(t, dir, cst, "foo")
23+
shouldNotHasPerm(t, dir, adm, "write", "r/demo/boards:gnolang/1")
24+
shouldNotHasPerm(t, dir, mod, "write", "r/demo/boards:gnolang/1")
25+
shouldNotHasPerm(t, dir, usr, "write", "r/demo/boards:gnolang/1")
26+
shouldNotHasPerm(t, dir, cst, "write", "r/demo/boards:gnolang/1")
27+
shouldNotHasPerm(t, dir, adm, "read", "r/demo/boards:gnolang/1")
28+
shouldNotHasPerm(t, dir, mod, "read", "r/demo/boards:gnolang/1")
29+
shouldNotHasPerm(t, dir, usr, "read", "r/demo/boards:gnolang/1")
30+
shouldNotHasPerm(t, dir, cst, "read", "r/demo/boards:gnolang/1")
31+
32+
// adding all the rights to admin.
33+
dir.AddUserPerm(adm, ".*", ".*")
34+
shouldHasRole(t, dir, adm, "foo")
35+
shouldNotHasRole(t, dir, mod, "foo")
36+
shouldNotHasRole(t, dir, usr, "foo")
37+
shouldNotHasRole(t, dir, cst, "foo")
38+
shouldHasPerm(t, dir, adm, "write", "r/demo/boards:gnolang/1") // new
39+
shouldNotHasPerm(t, dir, mod, "write", "r/demo/boards:gnolang/1")
40+
shouldNotHasPerm(t, dir, usr, "write", "r/demo/boards:gnolang/1")
41+
shouldNotHasPerm(t, dir, cst, "write", "r/demo/boards:gnolang/1")
42+
shouldHasPerm(t, dir, adm, "read", "r/demo/boards:gnolang/1") // new
43+
shouldNotHasPerm(t, dir, mod, "read", "r/demo/boards:gnolang/1")
44+
shouldNotHasPerm(t, dir, usr, "read", "r/demo/boards:gnolang/1")
45+
shouldNotHasPerm(t, dir, cst, "read", "r/demo/boards:gnolang/1")
46+
47+
// adding custom regexp rule for user "cst".
48+
dir.AddUserPerm(cst, "write", "r/demo/boards:gnolang/.*")
49+
shouldHasRole(t, dir, adm, "foo")
50+
shouldNotHasRole(t, dir, mod, "foo")
51+
shouldNotHasRole(t, dir, usr, "foo")
52+
shouldNotHasRole(t, dir, cst, "foo")
53+
shouldHasPerm(t, dir, adm, "write", "r/demo/boards:gnolang/1")
54+
shouldNotHasPerm(t, dir, mod, "write", "r/demo/boards:gnolang/1")
55+
shouldNotHasPerm(t, dir, usr, "write", "r/demo/boards:gnolang/1")
56+
shouldHasPerm(t, dir, cst, "write", "r/demo/boards:gnolang/1") // new
57+
shouldHasPerm(t, dir, adm, "read", "r/demo/boards:gnolang/1")
58+
shouldNotHasPerm(t, dir, mod, "read", "r/demo/boards:gnolang/1")
59+
shouldNotHasPerm(t, dir, usr, "read", "r/demo/boards:gnolang/1")
60+
shouldNotHasPerm(t, dir, cst, "read", "r/demo/boards:gnolang/1")
61+
62+
// adding a group perm for a new group.
63+
// no changes expected.
64+
dir.AddGroupPerm("mods", "role", "moderator")
65+
dir.AddGroupPerm("mods", "write", ".*")
66+
shouldHasRole(t, dir, adm, "foo")
67+
shouldNotHasRole(t, dir, mod, "foo")
68+
shouldNotHasRole(t, dir, usr, "foo")
69+
shouldNotHasRole(t, dir, cst, "foo")
70+
shouldHasPerm(t, dir, adm, "write", "r/demo/boards:gnolang/1")
71+
shouldNotHasPerm(t, dir, mod, "write", "r/demo/boards:gnolang/1")
72+
shouldNotHasPerm(t, dir, usr, "write", "r/demo/boards:gnolang/1")
73+
shouldHasPerm(t, dir, cst, "write", "r/demo/boards:gnolang/1")
74+
shouldHasPerm(t, dir, adm, "read", "r/demo/boards:gnolang/1")
75+
shouldNotHasPerm(t, dir, mod, "read", "r/demo/boards:gnolang/1")
76+
shouldNotHasPerm(t, dir, usr, "read", "r/demo/boards:gnolang/1")
77+
shouldNotHasPerm(t, dir, cst, "read", "r/demo/boards:gnolang/1")
78+
79+
// assigning the user "mod" to the "mods" group.
80+
dir.AddUserToGroup(mod, "mods")
81+
shouldHasRole(t, dir, adm, "foo")
82+
shouldNotHasRole(t, dir, mod, "foo")
83+
shouldNotHasRole(t, dir, usr, "foo")
84+
shouldNotHasRole(t, dir, cst, "foo")
85+
shouldHasPerm(t, dir, adm, "write", "r/demo/boards:gnolang/1")
86+
shouldHasPerm(t, dir, mod, "write", "r/demo/boards:gnolang/1") // new
87+
shouldNotHasPerm(t, dir, usr, "write", "r/demo/boards:gnolang/1")
88+
shouldHasPerm(t, dir, cst, "write", "r/demo/boards:gnolang/1")
89+
shouldHasPerm(t, dir, adm, "read", "r/demo/boards:gnolang/1")
90+
shouldNotHasPerm(t, dir, mod, "read", "r/demo/boards:gnolang/1")
91+
shouldNotHasPerm(t, dir, usr, "read", "r/demo/boards:gnolang/1")
92+
shouldNotHasPerm(t, dir, cst, "read", "r/demo/boards:gnolang/1")
93+
94+
// adding "read" permission for everyone.
95+
dir.AddGroupPerm(Everyone, "read", ".*")
96+
shouldHasRole(t, dir, adm, "foo")
97+
shouldNotHasRole(t, dir, mod, "foo")
98+
shouldNotHasRole(t, dir, usr, "foo")
99+
shouldNotHasRole(t, dir, cst, "foo")
100+
shouldHasPerm(t, dir, adm, "write", "r/demo/boards:gnolang/1")
101+
shouldHasPerm(t, dir, mod, "write", "r/demo/boards:gnolang/1")
102+
shouldNotHasPerm(t, dir, usr, "write", "r/demo/boards:gnolang/1")
103+
shouldHasPerm(t, dir, cst, "write", "r/demo/boards:gnolang/1")
104+
shouldHasPerm(t, dir, adm, "read", "r/demo/boards:gnolang/1")
105+
shouldHasPerm(t, dir, mod, "read", "r/demo/boards:gnolang/1") // new
106+
shouldHasPerm(t, dir, usr, "read", "r/demo/boards:gnolang/1") // new
107+
shouldHasPerm(t, dir, cst, "read", "r/demo/boards:gnolang/1") // new
108+
}
109+
110+
func shouldHasRole(t *testing.T, dir *Directory, addr std.Address, role string) {
111+
t.Helper()
112+
check := dir.HasRole(addr, role)
113+
if !check {
114+
t.Errorf("%q should has role %q", addr.String(), role)
115+
}
116+
}
117+
118+
func shouldNotHasRole(t *testing.T, dir *Directory, addr std.Address, role string) {
119+
t.Helper()
120+
check := dir.HasRole(addr, role)
121+
if check {
122+
t.Errorf("%q should not has role %q", addr.String(), role)
123+
}
124+
}
125+
126+
func shouldHasPerm(t *testing.T, dir *Directory, addr std.Address, verb string, resource string) {
127+
t.Helper()
128+
check := dir.HasPerm(addr, verb, resource)
129+
if !check {
130+
t.Errorf("%q should has perm for %q - %q", addr.String(), verb, resource)
131+
}
132+
}
133+
134+
func shouldNotHasPerm(t *testing.T, dir *Directory, addr std.Address, verb string, resource string) {
135+
t.Helper()
136+
check := dir.HasPerm(addr, verb, resource)
137+
if check {
138+
t.Errorf("%q should not has perm for %q - %q", addr.String(), verb, resource)
139+
}
140+
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)