z_6_a_filetest.gno

1.67 Kb ยท 69 lines
 1// PKGPATH: gno.land/r/demo/test
 2package test
 3
 4import (
 5	"testing"
 6	"time"
 7
 8	pdao "gno.land/p/nt/commondao"
 9	"gno.land/p/nt/testutils"
10
11	"gno.land/r/nt/commondao"
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.ReadonlyVotingRecord, pdao.MemberSet) (bool, error) { return true, nil }
30
31func (propDef) Execute(cur realm) error {
32	executed = true
33	return nil
34}
35
36func init() {
37	// Invite a user to be able to start creating DAOs
38	testing.SetRealm(testing.NewUserRealm(owner))
39	commondao.Invite(cross, user1)
40
41	// Create a new DAO which gives ownership to `test`
42	testing.SetRealm(testing.NewUserRealm(user1))
43	testing.SetRealm(testing.NewCodeRealm("gno.land/r/demo/test"))
44	dao = commondao.New(cross, "Foo")
45
46	// Configure DAO
47	dao.Members().Add(user1)
48
49	// Create a new proposal
50	proposal, _ = dao.Propose(user1, propDef{})
51}
52
53func main() {
54	testing.SetRealm(testing.NewUserRealm(user1))
55
56	commondao.Execute(cross, dao.ID(), proposal.ID())
57
58	p := dao.FinishedProposals().Get(proposal.ID())
59	if p == nil {
60		panic("expected proposal to be finished")
61	}
62
63	println(p.Status() == pdao.StatusPassed)
64	println(executed)
65}
66
67// Output:
68// true
69// true