z_7_a_filetest.gno
1.33 Kb · 57 lines
1package main
2
3import (
4 "testing"
5
6 pcommondao "gno.land/p/nt/commondao/v0"
7
8 "gno.land/r/nt/commondao/v0"
9)
10
11const (
12 owner = address("g16jpf0puufcpcjkph5nxueec8etpcldz7zwgydq") // @devx
13 user = address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") // @test1
14 name = "Foo"
15)
16
17var parentID uint64
18
19func init() {
20 // Invite a user to be able to start creating DAOs
21 testing.SetRealm(testing.NewUserRealm(owner))
22 commondao.Invite(cross, user)
23
24 // The origin must be the invited user where invitation
25 // is removed after the first user call to create a DAO
26 testing.SetRealm(testing.NewUserRealm(user))
27
28 // Create the root DAO
29 testing.SetRealm(testing.NewCodeRealm("gno.land/r/nt/commondao/v0"))
30 parentDAO := commondao.New(cross, "Parent DAO", commondao.AllowChildren(true))
31 parentID = parentDAO.ID()
32}
33
34func main() {
35 testing.SetRealm(testing.NewUserRealm(user))
36 testing.SetRealm(testing.NewCodeRealm("gno.land/r/nt/commondao/v0"))
37
38 dao := commondao.NewSubDAO(cross, name, parentID)
39 if dao == nil {
40 panic("expected subDAO to be created")
41 }
42
43 println(dao.Name() == name)
44 println(dao.Parent().ID() == parentID)
45
46 // Check that SubDAO is added as a child to the parent DAO
47 if v := dao.Parent().Children().Get(0); v != nil {
48 if subDAO, ok := v.(*pcommondao.CommonDAO); ok {
49 println(subDAO.ID() == dao.ID())
50 }
51 }
52}
53
54// Output:
55// true
56// true
57// true