Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

xdao_test.gno

2.50 Kb · 66 lines
 1package xdao
 2
 3import (
 4	"testing"
 5
 6	"gno.land/p/nt/testutils/v0"
 7	"gno.land/p/nt/uassert/v0"
 8
 9	"gno.land/p/moul/udao/v0"
10)
11
12// WhitelistDAO is a partial implementation: the constructor, ListAdmins and
13// Render work; the udao.DAO proposal methods and the admin mutators are still
14// `panic("not implemented")`. Pin both halves.
15
16var alice = testutils.TestAddress("alice")
17
18// NewWhitelistDAO reads unsafe.PreviousRealm(), which needs a real realm frame:
19// a user realm gives "frame not found: cannot seek beyond origin caller override".
20func TestNewWhitelistDAOSeedsCallerAsAdmin(cur realm, t *testing.T) {
21	testing.SetRealm(testing.NewCodeRealm("gno.land/r/test/daoone"))
22	d := NewWhitelistDAO()
23
24	admins := d.ListAdmins()
25	uassert.Equal(t, 1, len(admins), "the creator is the only admin")
26	uassert.True(t, admins[0].IsValid(), "the sole admin is a valid address")
27}
28
29// Note: caller-sensitivity of NewWhitelistDAO is NOT asserted here — see the
30// same limitation described in p/moul/safe/v0's tests: from a `p/` test package
31// unsafe.PreviousRealm() resolves to the origin regardless of SetRealm.
32
33func TestListAdminsReflectsState(t *testing.T) {
34	bob := testutils.TestAddress("bob")
35	d := &WhitelistDAO{admins: []address{alice, bob}}
36
37	admins := d.ListAdmins()
38	uassert.Equal(t, 2, len(admins))
39	uassert.Equal(t, alice.String(), admins[0].String())
40	uassert.Equal(t, bob.String(), admins[1].String())
41}
42
43func TestRenderPlaceholder(t *testing.T) {
44	d := &WhitelistDAO{admins: []address{alice}}
45	// Still a placeholder — pinned so replacing it is a visible change.
46	uassert.Equal(t, "TODO", d.Render(""))
47	uassert.Equal(t, "TODO", d.Render("/anything"))
48}
49
50// TestImplementsUDAO is the compile-time assertion the source makes with
51// `var _ udao.DAO = (*WhitelistDAO)(nil)`, restated as a test.
52func TestImplementsUDAO(t *testing.T) {
53	var _ udao.DAO = (*WhitelistDAO)(nil)
54	uassert.True(t, true, "WhitelistDAO implements udao.DAO")
55}
56
57func TestUnimplementedMethodsPanic(cur realm, t *testing.T) {
58	d := &WhitelistDAO{admins: []address{alice}}
59
60	uassert.PanicsWithMessage(t, cur, "not implemented", func() { d.Propose(nil) })
61	uassert.PanicsWithMessage(t, cur, "not implemented", func() { d.GetProposalStatus(0) })
62	uassert.PanicsWithMessage(t, cur, "not implemented", func() { d.Execute(0) })
63	uassert.PanicsWithMessage(t, cur, "not implemented", func() { d.GetProposal(0) })
64	uassert.PanicsWithMessage(t, cur, "not implemented", func() { d.AddAdmin(alice) })
65	uassert.PanicsWithMessage(t, cur, "not implemented", func() { d.DelAdmin(alice) })
66}