Search Apps Documentation Source Content File Folder Download Copy Actions Download

z_1_prop2_filetest.gno

3.99 Kb · 161 lines
  1// PKGPATH: gno.land/r/sys/namereg/v1/filetests/z_1_prop2_filetest
  2
  3package z_1_prop2_filetest
  4
  5import (
  6	"chain"
  7	"chain/runtime/unsafe"
  8	"testing"
  9
 10	"gno.land/p/nt/testutils/v0"
 11	"gno.land/r/gov/dao"
 12	daov3init "gno.land/r/gov/dao/v3/init"
 13	users "gno.land/r/sys/namereg/v1"
 14	susers "gno.land/r/sys/users"
 15)
 16
 17// Test updating a name via GovDAO
 18var c address = unsafe.OriginCaller()
 19
 20func init(cur realm) {
 21	// Whitelist this realm as a controller so its Register() can reach r/sys/users.
 22	testing.SetHeight(0)
 23	susers.AddControllerAtGenesis(cross(cur), chain.PackageAddress("gno.land/r/sys/namereg/v1"))
 24	testing.SetHeight(123)
 25
 26	daov3init.InitWithUsers(cross(cur), c)
 27
 28	alice := testutils.TestAddress("alice")
 29
 30	// Register alice
 31	testing.SetOriginCaller(alice)
 32	testing.SetRealm(testing.NewUserRealm(alice))
 33	users.Register(cross(cur), "nym-alice123")
 34
 35	// Prop to delete user
 36	testing.SetOriginCaller(c)
 37	testing.SetRealm(testing.NewUserRealm(c))
 38	pr := users.ProposeDeleteUser(cross(cur), alice, "delete user test")
 39	dao.MustCreateProposal(cross(cur), pr)
 40}
 41
 42func main(cur realm) {
 43	testing.SetOriginCaller(c)
 44
 45	println("--")
 46	println(dao.Render(cross(cur), ""))
 47	println("--")
 48	println(dao.Render(cross(cur), "0"))
 49	println("--")
 50
 51	dao.MustVoteOnProposal(cross(cur), dao.NewVoteRequest(dao.YesVote, dao.ProposalID(0)))
 52
 53	println("--")
 54	println(dao.Render(cross(cur), "0"))
 55	println("--")
 56
 57	dao.ExecuteProposal(cross(cur), dao.ProposalID(0))
 58
 59	println("--")
 60	println(dao.Render(cross(cur), "0"))
 61
 62	data, _ := susers.ResolveName("nym-alice123")
 63	if data == nil {
 64		println("Successfully deleted alice")
 65	}
 66}
 67
 68// Output:
 69// --
 70// # GovDAO
 71// ## Members
 72// [> Go to Memberstore <](/r/gov/dao/v3/memberstore)
 73// ## Proposals
 74// ### [Prop #0 - User Registry V1: Delete user \`nym\-alice123\`](/r/gov/dao:0)
 75// Author: g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm
 76//
 77// Status: ACTIVE
 78//
 79// Tiers eligible to vote: T1, T2, T3
 80//
 81// ---
 82//
 83//
 84// --
 85// ## Prop #0 - User Registry V1: Delete user \`nym\-alice123\`
 86// Author: g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm
 87//
 88// delete user test
 89//
 90//
 91//
 92// ---
 93//
 94// ### Stats
 95// - **Proposal is open for votes**
 96// - Tiers eligible to vote: T1, T2, T3
 97// - YES PERCENT: 0%
 98// - NO PERCENT: 0%
 99// - ABSTAIN PERCENT: 0%
100//
101// [Detailed voting list](/r/gov/dao:0/votes)
102//
103// ---
104//
105// ### Actions
106// [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)
107//
108// WARNING: Please double check transaction data before voting.
109// --
110// --
111// ## Prop #0 - User Registry V1: Delete user \`nym\-alice123\`
112// Author: g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm
113//
114// delete user test
115//
116//
117//
118// ---
119//
120// ### Stats
121// - **Proposal is open for votes**
122// - Tiers eligible to vote: T1, T2, T3
123// - YES PERCENT: 100%
124// - NO PERCENT: 0%
125// - ABSTAIN PERCENT: 0%
126//
127// [Detailed voting list](/r/gov/dao:0/votes)
128//
129// ---
130//
131// ### Actions
132// [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)
133//
134// WARNING: Please double check transaction data before voting.
135// --
136// --
137// ## Prop #0 - User Registry V1: Delete user \`nym\-alice123\`
138// Author: g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm
139//
140// delete user test
141//
142//
143//
144// ---
145//
146// ### Stats
147// - **PROPOSAL HAS BEEN ACCEPTED**
148// - Tiers eligible to vote: T1, T2, T3
149// - YES PERCENT: 100%
150// - NO PERCENT: 0%
151// - ABSTAIN PERCENT: 0%
152//
153// [Detailed voting list](/r/gov/dao:0/votes)
154//
155// ---
156//
157// ### Actions
158// [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)
159//
160// WARNING: Please double check transaction data before voting.
161// Successfully deleted alice