z_8_b_filetest.gno
1.18 Kb · 53 lines
1package main
2
3import (
4 "testing"
5
6 "gno.land/r/nt/commondao/v0"
7)
8
9const (
10 owner = address("g16jpf0puufcpcjkph5nxueec8etpcldz7zwgydq") // @devx
11 user = address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") // @test1
12)
13
14var rootID uint64
15
16func init() {
17 // Invite a user to be able to start creating DAOs
18 testing.SetRealm(testing.NewUserRealm(owner))
19 commondao.Invite(cross, user)
20
21 // The origin must be the invited user where invitation
22 // is removed after the first user call to create a DAO
23 testing.SetRealm(testing.NewUserRealm(user))
24
25 // Create root DAO with subDAOs
26 testing.SetRealm(testing.NewCodeRealm("gno.land/r/test"))
27 rootDAO := commondao.New(cross, "Root DAO")
28 fooDAO := commondao.NewSubDAO(cross, "A", rootDAO.ID())
29 barDAO := commondao.NewSubDAO(cross, "B", fooDAO.ID())
30 commondao.NewSubDAO(cross, "C", barDAO.ID())
31 commondao.NewSubDAO(cross, "D", fooDAO.ID())
32
33 rootID = rootDAO.ID()
34}
35
36func main() {
37 testing.SetRealm(testing.NewCodeRealm("gno.land/r/test"))
38
39 iter := commondao.NewIterator(rootID, commondao.WithCount(2))
40
41 println("Count =", iter.Count())
42
43 for iter.Next() {
44 if dao := iter.DAO(); dao != nil {
45 println(dao.Name())
46 }
47 }
48}
49
50// Output:
51// Count = 2
52// A
53// B