Search Apps Documentation Source Content File Folder Download Copy Actions Download

z_6_a_filetest.gno

1.59 Kb · 71 lines
 1// PKGPATH: gno.land/r/demo/test
 2package test
 3
 4import (
 5	"testing"
 6	"time"
 7
 8	pdao "gno.land/p/nt/commondao/v0"
 9	"gno.land/p/nt/testutils/v0"
10
11	"gno.land/r/nt/commondao/v0"
12)
13
14const owner = address("g16jpf0puufcpcjkph5nxueec8etpcldz7zwgydq") // @devx
15
16var (
17	dao      *pdao.CommonDAO
18	proposal *pdao.Proposal
19	executed bool
20	user1    = testutils.TestAddress("user1")
21)
22
23type propDef struct{}
24
25func (propDef) Title() string                          { return "" }
26func (propDef) Body() string                           { return "" }
27func (propDef) VotingPeriod() time.Duration            { return 0 }
28func (propDef) Validate() error                        { return nil }
29func (propDef) Tally(pdao.VotingContext) (bool, error) { return true, nil }
30
31func (propDef) Executor() pdao.ExecFunc {
32	return func(realm) error {
33		executed = true
34		return nil
35	}
36}
37
38func init() {
39	// Invite a user to be able to start creating DAOs
40	testing.SetRealm(testing.NewUserRealm(owner))
41	commondao.Invite(cross, user1)
42
43	// Create a new DAO which gives ownership to `test`
44	testing.SetRealm(testing.NewUserRealm(user1))
45	testing.SetRealm(testing.NewCodeRealm("gno.land/r/demo/test"))
46	dao = commondao.New(cross, "Foo")
47
48	// Configure DAO
49	dao.Members().Add(user1)
50
51	// Create a new proposal
52	proposal, _ = dao.Propose(user1, propDef{})
53}
54
55func main() {
56	testing.SetRealm(testing.NewUserRealm(user1))
57
58	commondao.Execute(cross, dao.ID(), proposal.ID())
59
60	p := dao.FinishedProposals().Get(proposal.ID())
61	if p == nil {
62		panic("expected proposal to be finished")
63	}
64
65	println(string(p.Status()))
66	println(executed)
67}
68
69// Output:
70// executed
71// true