z_5_a_filetest.gno
1.81 Kb ยท 70 lines
1package main
2
3import (
4 "testing"
5 "time"
6
7 pdao "gno.land/p/nt/commondao"
8
9 "gno.land/r/nt/commondao"
10)
11
12const (
13 owner = address("g16jpf0puufcpcjkph5nxueec8etpcldz7zwgydq") // @devx
14 user = address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") // @test1
15)
16
17type propDef struct{}
18
19func (propDef) Title() string { return "" }
20func (propDef) Body() string { return "" }
21func (propDef) VotingPeriod() time.Duration { return time.Hour }
22func (propDef) Validate() error { return nil }
23func (propDef) Tally(pdao.ReadonlyVotingRecord, pdao.MemberSet) (bool, error) { return false, nil }
24func (propDef) Execute() error { return nil }
25
26var (
27 daoID uint64
28 proposal *pdao.Proposal
29 vote pdao.VoteChoice = pdao.ChoiceYes
30)
31
32func init() {
33 // Invite a user to be able to start creating DAOs
34 testing.SetRealm(testing.NewUserRealm(owner))
35 commondao.Invite(cross, user)
36
37 // Create a new DAO which gives ownership to `test`
38 testing.SetRealm(testing.NewUserRealm(user))
39 testing.SetRealm(testing.NewCodeRealm("gno.land/r/demo/test"))
40 dao := commondao.New(cross, "Foo")
41 daoID = dao.ID()
42
43 // Configure DAO
44 dao.Members().Add(user)
45
46 // Create a new proposal
47 proposal, _ = dao.Propose(user, propDef{})
48}
49
50func main() {
51 // User must be the caller to Vote()
52 testing.SetRealm(testing.NewUserRealm(user))
53
54 commondao.Vote(cross, daoID, proposal.ID(), vote, "")
55
56 record := proposal.VotingRecord()
57 if record.Size() != 1 {
58 panic("expected a single vote")
59 }
60
61 println(record.HasVoted(user))
62 record.Iterate(0, record.Size(), false, func(v pdao.Vote) bool {
63 println(v.Choice == vote)
64 return false
65 })
66}
67
68// Output:
69// true
70// true