Search Apps Documentation Source Content File Folder Download Copy Actions Download

z_commondao_execute_0_filetest.gno

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