Search Apps Documentation Source Content File Folder Download Copy Actions Download

z_0_prop1_filetest.gno

4.39 Kb ยท 175 lines
  1package main
  2
  3// SEND: 1000000ugnot
  4
  5import (
  6	"chain/runtime"
  7	"testing"
  8
  9	"gno.land/p/nt/testutils"
 10	users "gno.land/r/gnoland/users/v1"
 11	"gno.land/r/gov/dao"
 12	daov3init "gno.land/r/gov/dao/v3/init"
 13	susers "gno.land/r/sys/users"
 14)
 15
 16// Test updating a name via GovDAO
 17var c address = runtime.OriginCaller()
 18
 19const gUsersV1Path = "gno.land/r/gnoland/users/v1"
 20
 21// Register a namespace for every addresses
 22// Necessary to test GovDAO Vote
 23func registerTestUser(addrs ...address) {
 24	// Set realm to users admin to register test user
 25	testing.SetRealm(testing.NewCodeRealm(gUsersV1Path))
 26	for _, addr := range addrs {
 27		err := susers.RegisterUser(cross, addr.String()[1:], addr)
 28		if err != nil {
 29			panic(err.Error() + " : " + addr.String())
 30		}
 31	}
 32}
 33
 34func init() {
 35	daov3init.InitWithUsers(c)
 36	registerTestUser(c)
 37
 38	alice := testutils.TestAddress("alice")
 39
 40	// Register alice
 41	testing.SetOriginCaller(alice)
 42	testing.SetRealm(testing.NewUserRealm(alice))
 43	users.Register(cross, "alice123")
 44
 45	// Prop to change name
 46	testing.SetOriginCaller(c)
 47	testing.SetRealm(testing.NewUserRealm(c))
 48	pr := users.ProposeNewName(alice, "alice_new123")
 49	dao.MustCreateProposal(cross, pr)
 50}
 51
 52func main() {
 53	testing.SetOriginCaller(c)
 54
 55	println("--")
 56	println(dao.Render(""))
 57	println("--")
 58	println(dao.Render("0"))
 59	println("--")
 60
 61	dao.MustVoteOnProposal(cross, dao.VoteRequest{
 62		Option:     dao.YesVote,
 63		ProposalID: dao.ProposalID(0),
 64	})
 65
 66	println("--")
 67	println(dao.Render("0"))
 68	println("--")
 69
 70	dao.ExecuteProposal(cross, dao.ProposalID(0))
 71
 72	println("--")
 73	println(dao.Render("0"))
 74
 75	data, _ := susers.ResolveName("alice_new123")
 76	println(data.Addr())
 77}
 78
 79// Output:
 80// --
 81// # GovDAO
 82// ## Members
 83// [> Go to Memberstore <](/r/gov/dao/v3/memberstore)
 84// ## Proposals
 85// ### [Prop #0 - User Registry V1: Rename user `alice123` to `alice_new123`](/r/gov/dao:0)
 86// Author: [@1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm](/u/1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm)
 87//
 88// Status: ACTIVE
 89//
 90// Tiers eligible to vote: T1, T2, T3
 91//
 92// ---
 93//
 94//
 95// --
 96// ## Prop #0 - User Registry V1: Rename user `alice123` to `alice_new123`
 97// Author: [@1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm](/u/1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm)
 98//
 99//
100//
101//
102//
103// ---
104//
105// ### Stats
106// - **Proposal is open for votes**
107// - Tiers eligible to vote: T1, T2, T3
108// - YES PERCENT: 0%
109// - NO PERCENT: 0%
110//
111// [Detailed voting list](/r/gov/dao:0/votes)
112//
113// ---
114//
115// ### Actions
116// [Vote YES](/r/gov/dao$help&func=MustVoteOnProposalSimple&option=YES&pid=0) | [Vote NO](/r/gov/dao$help&func=MustVoteOnProposalSimple&option=NO&pid=0) | [Vote ABSTAIN](/r/gov/dao$help&func=MustVoteOnProposalSimple&option=ABSTAIN&pid=0)
117//
118// WARNING: Please double check transaction data before voting.
119//
120// **New**: Members **must** have a namespace to vote to enforce simpler tracking.
121// --
122// --
123// ## Prop #0 - User Registry V1: Rename user `alice123` to `alice_new123`
124// Author: [@1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm](/u/1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm)
125//
126//
127//
128//
129//
130// ---
131//
132// ### Stats
133// - **Proposal is open for votes**
134// - Tiers eligible to vote: T1, T2, T3
135// - YES PERCENT: 100%
136// - NO PERCENT: 0%
137//
138// [Detailed voting list](/r/gov/dao:0/votes)
139//
140// ---
141//
142// ### Actions
143// [Vote YES](/r/gov/dao$help&func=MustVoteOnProposalSimple&option=YES&pid=0) | [Vote NO](/r/gov/dao$help&func=MustVoteOnProposalSimple&option=NO&pid=0) | [Vote ABSTAIN](/r/gov/dao$help&func=MustVoteOnProposalSimple&option=ABSTAIN&pid=0)
144//
145// WARNING: Please double check transaction data before voting.
146//
147// **New**: Members **must** have a namespace to vote to enforce simpler tracking.
148// --
149// --
150// ## Prop #0 - User Registry V1: Rename user `alice123` to `alice_new123`
151// Author: [@1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm](/u/1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm)
152//
153//
154//
155//
156//
157// ---
158//
159// ### Stats
160// - **PROPOSAL HAS BEEN ACCEPTED**
161// - Tiers eligible to vote: T1, T2, T3
162// - YES PERCENT: 100%
163// - NO PERCENT: 0%
164//
165// [Detailed voting list](/r/gov/dao:0/votes)
166//
167// ---
168//
169// ### Actions
170// [Vote YES](/r/gov/dao$help&func=MustVoteOnProposalSimple&option=YES&pid=0) | [Vote NO](/r/gov/dao$help&func=MustVoteOnProposalSimple&option=NO&pid=0) | [Vote ABSTAIN](/r/gov/dao$help&func=MustVoteOnProposalSimple&option=ABSTAIN&pid=0)
171//
172// WARNING: Please double check transaction data before voting.
173//
174// **New**: Members **must** have a namespace to vote to enforce simpler tracking.
175// g1v9kxjcm9ta047h6lta047h6lta047h6lzd40gh