Search Apps Documentation Source Content File Folder Download Copy Actions Download

z_0_filetest.gno

1.49 Kb ยท 62 lines
 1package main
 2
 3import (
 4	"chain/runtime"
 5	"testing"
 6
 7	"gno.land/p/nt/testutils"
 8	"gno.land/r/gnoland/users"
 9	"gno.land/r/gov/dao"
10	ini "gno.land/r/gov/dao/v3/init"
11	susers "gno.land/r/sys/users"
12)
13
14var alice = testutils.TestAddress("g1alice")
15
16func init() {
17	testing.SetRealm(testing.NewUserRealm(alice))
18	c := runtime.OriginCaller()
19	ini.InitWithUsers(c)
20	registerTestUsers(c)
21
22	pReq := users.ProposeNewRelease("gno.land/r/gnoland/users/v2", "This is a note!")
23
24	dao.MustCreateProposal(cross, pReq)
25}
26
27const gUsersV1Path = "gno.land/r/gnoland/users/v1"
28
29// Register a namespace for every addresses
30// Necessary to test GovDAO Vote
31func registerTestUsers(addrs ...address) {
32	// Set realm to users admin to register test user
33	testing.SetRealm(testing.NewCodeRealm(gUsersV1Path))
34	for _, addr := range addrs {
35		err := susers.RegisterUser(cross, addr.String()[1:], addr)
36		if err != nil {
37			panic(err.Error() + " : " + addr.String())
38		}
39	}
40}
41
42func main() {
43	testing.SetRealm(testing.NewUserRealm(alice))
44
45	dao.MustVoteOnProposal(cross, dao.VoteRequest{
46		Option:     dao.YesVote,
47		ProposalID: dao.ProposalID(0),
48	})
49
50	dao.ExecuteProposal(cross, dao.ProposalID(0))
51	println(users.Render(""))
52}
53
54// Output:
55// # r/gnoland/users
56// See the r/gnoland/users changelog below.
57//
58// | Version | Link | Notes |
59// | --- | --- | --- |
60// | v2 | [r/gnoland/users v2 (latest)](/r/gnoland/users/v2) | This is a note! |
61// | v1 | [r/gnoland/users v1](/r/gnoland/users/v1) | [Original PR](https://github.com/gnolang/gno/pull/3166) |
62//