z_5_a_filetest.gno
1.61 Kb · 69 lines
1package main
2
3import (
4 "testing"
5 "time"
6
7 pdao "gno.land/p/nt/commondao/v0"
8
9 "gno.land/r/nt/commondao/v0"
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.VotingContext) (bool, error) { return false, nil }
24
25var (
26 daoID uint64
27 proposal *pdao.Proposal
28 vote pdao.VoteChoice = pdao.ChoiceYes
29)
30
31func init() {
32 // Invite a user to be able to start creating DAOs
33 testing.SetRealm(testing.NewUserRealm(owner))
34 commondao.Invite(cross, user)
35
36 // Create a new DAO which gives ownership to `test`
37 testing.SetRealm(testing.NewUserRealm(user))
38 testing.SetRealm(testing.NewCodeRealm("gno.land/r/demo/test"))
39 dao := commondao.New(cross, "Foo")
40 daoID = dao.ID()
41
42 // Configure DAO
43 dao.Members().Add(user)
44
45 // Create a new proposal
46 proposal, _ = dao.Propose(user, propDef{})
47}
48
49func main() {
50 // User must be the caller to Vote()
51 testing.SetRealm(testing.NewUserRealm(user))
52
53 commondao.Vote(cross, daoID, proposal.ID(), vote, "")
54
55 record := proposal.VotingRecord()
56 if record.Size() != 1 {
57 panic("expected a single vote")
58 }
59
60 println(record.HasVoted(user))
61 record.Iterate(0, record.Size(), false, func(v pdao.Vote) bool {
62 println(v.Choice == vote)
63 return false
64 })
65}
66
67// Output:
68// true
69// true