z_commondao_execute_2_filetest.gno
1.38 Kb · 57 lines
1// PKGPATH: gno.land/r/test
2package test
3
4import (
5 "testing"
6 "time"
7
8 "gno.land/p/nt/commondao/v0"
9)
10
11const member address = "g16jpf0puufcpcjkph5nxueec8etpcldz7zwgydq" // @devx
12
13var (
14 dao *commondao.CommonDAO
15 proposal *commondao.Proposal
16 executed bool
17)
18
19type testPropDef struct{}
20
21func (testPropDef) Title() string { return "" }
22func (testPropDef) Body() string { return "" }
23func (testPropDef) VotingPeriod() time.Duration { return time.Hour } // Voting ends in 1 hour
24func (testPropDef) Tally(commondao.VotingContext) (bool, error) { return true, nil }
25
26func (testPropDef) Executor() commondao.ExecFunc {
27 return func(realm) error {
28 executed = true
29 return nil
30 }
31}
32
33func init() {
34 dao = commondao.New(
35 commondao.WithMember(member),
36 commondao.DisableVotingDeadlineCheck(), // Disable to be able to execute before voting deadline
37 )
38 proposal = dao.MustPropose(member, testPropDef{})
39}
40
41func main() {
42 // Make sure proposal is executed in a realm different than the one where definition has been defined
43 testing.SetRealm(testing.NewCodeRealm("gno.land/r/testing/dao"))
44
45 // Should be able to execute before voting deadline because deadline check is disabled
46 err := dao.Execute(proposal.ID())
47 if err != nil {
48 panic(err)
49 }
50
51 println(executed)
52 println(string(proposal.Status()))
53}
54
55// Output:
56// true
57// executed