govdao_execute_proposal_00_filetest.gno
2.18 Kb · 82 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/v3/impl"
11 "gno.land/r/gov/dao/v3/memberstore"
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() {
24 // Initialize GovDAO members
25 memberstore.Get().DeleteAll()
26 memberstore.Get().SetTier(memberstore.T1)
27 memberstore.Get().SetMember(memberstore.T1, user, &memberstore.Member{InvitationPoints: 3})
28 dao.UpdateImpl(cross, dao.UpdateRequest{DAO: impl.NewGovDAO()})
29
30 // Create an executor that always fails
31 cb := func(realm) error { return errors.New("Boom!") }
32 executor = dao.NewSimpleExecutor(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, request)
40 renderPath = strconv.FormatUint(uint64(proposalID), 10)
41
42 // Register proposal with the local GovDAO instance
43 govdao.PostCreateProposal(request, proposalID)
44}
45
46func main() {
47 // Execute proposal, status should be REJECTED
48 err := govdao.ExecuteProposal(proposalID, executor)
49
50 println(err.Error())
51 println()
52 println(govdao.Render("gno.land/r/gov/dao/v3/impl", renderPath))
53}
54
55// Output:
56// Boom!
57//
58// ## Prop #0 - Test
59// Author: g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5
60//
61// This proposal always fails on execution
62//
63//
64//
65// ---
66//
67// ### Stats
68// - **PROPOSAL HAS BEEN DENIED**
69// REASON: execution failed: Boom!
70// - Tiers eligible to vote: T1, T2, T3
71// - YES PERCENT: 0%
72// - NO PERCENT: 0%
73// - ABSTAIN PERCENT: 0%
74//
75// [Detailed voting list](/r/gov/dao/v3/impl:0/votes)
76//
77// ---
78//
79// ### Actions
80// [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)
81//
82// WARNING: Please double check transaction data before voting.