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_00_filetest.gno

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