Skip to content Search Apps Documentation Source Content Run Reset Eval Playground File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

govdao_execute_proposal_01_filetest.gno

2.64 Kb · 90 lines
 1// PKGPATH: gno.land/r/test/govdao
 2package govdao
 3
 4import (
 5	"strconv"
 6	"testing"
 7
 8	"gno.land/r/gov/dao"
 9	"gno.land/r/gov/dao/impl/v0"
10	"gno.land/r/gov/dao/memberstore/v0"
11)
12
13const user address = "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5"
14
15var (
16	executor   dao.Executor
17	proposalID dao.ProposalID
18	renderPath string
19	govdao     = impl.NewGovDAO()
20)
21
22func init(cur realm) {
23	// Initialize GovDAO members
24	memberstore.Get(0, cur).DeleteAll()
25	memberstore.Get(0, cur).SetTier(memberstore.T1)
26	memberstore.Get(0, cur).SetMember(memberstore.T1, user, memberstore.NewMember(3))
27	dao.UpdateImpl(cross(cur), dao.NewUpdateRequest(impl.NewGovDAO(), nil))
28
29	// Create a dummy executor
30	cb := func(realm) error { return nil }
31	executor = dao.NewSimpleExecutor(0, cur, cb, "")
32
33	// Create a proposal request that pass on execution
34	request := dao.NewProposalRequest("Test", "This proposal always pass on execution", executor)
35
36	// Create the proposal from a realm so GovDAO instance is able to render the proposal
37	testing.SetRealm(testing.NewUserRealm(user))
38	proposalID = dao.MustCreateProposal(cross(cur), request)
39	renderPath = strconv.FormatUint(uint64(proposalID), 10)
40
41	// Register proposal with the local GovDAO instance
42	govdao.PostCreateProposal(0, cur, request, proposalID)
43}
44
45func main(cur realm) {
46	// Execute proposal, status should be ACTIVE
47	// SimpleExecutor.Execute is invocable only by the r/gov/dao proxy, which
48	// is the realm the live route calls it from (dao.ExecuteProposal ->
49	// impl.ExecuteProposal, both threading the proxy's cur non-crossing).
50	// This filetest calls impl.ExecuteProposal directly, so stand in for the
51	// proxy explicitly rather than exercising a route no transaction takes.
52	testing.SetRealm(testing.NewCodeRealm("gno.land/r/gov/dao"))
53
54	err := govdao.ExecuteProposal(0, cur, proposalID, executor)
55
56	println(err == nil)
57	println()
58	println(govdao.Render(cross(cur), "gno.land/r/gov/dao/impl/v0", renderPath))
59}
60
61// Output:
62// true
63//
64// ## Prop #0 - Test
65// Author: g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5
66//
67// This proposal always pass on execution
68//
69// Executor created in: `gno.land/r/test/govdao`
70//
71//
72//
73//
74// ---
75//
76// ### Stats
77// - **Proposal is open for votes**
78// - Tiers eligible to vote: T1, T2, T3
79// - YES PERCENT: 0%
80// - NO PERCENT: 0%
81// - ABSTAIN PERCENT: 0%
82//
83// [Detailed voting list](/r/gov/dao/impl/v0:0/votes)
84//
85// ---
86//
87// ### Actions
88// [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)
89//
90// WARNING: Please double check transaction data before voting.