Playground
gnomod.toml
module = "gno.land/p/nym-moultest123/xdao/v0" gno = "0.9" [addpkg] creator = "g1ml9grtwnpzqn3hre5ve5vjdlmv2srrmpmc0dsv" height = 186410 max_deposit = "5000000ugnot"
xdao.gno
package xdao
import (
"chain/runtime/unsafe"
"gno.land/p/nym-moultest123/udao/v0"
)
// DAO is a whitelist system that implements the udao.DAO interface.
// It can allow a trusted list of addresses to share the administration of realms that are designed to be managed by "DAOs".
// It's not a DAO per say. But makes sense to be used to bootstrap a realm until the DAO can replace itself with a really decnetralized autonomous organization. Asan inception.
// It's also useful for people who manages multiple keys, like on different computers so they can simulte being a single entity while managing several addresses.
type WhitelistDAO struct {
admins []address // for the sake of simplicity and because this simple DAO implementation isn't designed to scale, we just keep a simple slice
}
// check that DAO implements the udao.DAO interface.
var _ udao.DAO = (*WhitelistDAO)(nil)
func NewWhitelistDAO() *WhitelistDAO {
caller := unsafe.PreviousRealm().Address()
return &WhitelistDAO{
admins: []address{caller},
}
}
// udao.DAO methods
//
func (d *WhitelistDAO) Propose(prop udao.Proposal) (uint64, error) { panic("not implemented") }
func (d WhitelistDAO) GetProposalStatus(id uint64) (udao.ProposalStatus, error) {
panic("not implemented")
}
func (d *WhitelistDAO) Execute(id uint64) error { panic("not implemented") }
func (d WhitelistDAO) GetProposal(id uint64) (udao.Proposal, error) { panic("not implemented") }
// other methods
//
func (d *WhitelistDAO) AddAdmin(addr address) { panic("not implemented") }
func (d *WhitelistDAO) DelAdmin(addr address) { panic("not implemented") }
func (d WhitelistDAO) ListAdmins() []address { return d.admins[:] }
func (d WhitelistDAO) Render(path string) string { return "TODO" }
xdao_test.gno
package xdao
import (
"testing"
"gno.land/p/nt/testutils/v0"
"gno.land/p/nt/uassert/v0"
"gno.land/p/nym-moultest123/udao/v0"
)
// WhitelistDAO is a partial implementation: the constructor, ListAdmins and
// Render work; the udao.DAO proposal methods and the admin mutators are still
// `panic("not implemented")`. Pin both halves.
var alice = testutils.TestAddress("alice")
// NewWhitelistDAO reads unsafe.PreviousRealm(), which needs a real realm frame:
// a user realm gives "frame not found: cannot seek beyond origin caller override".
func TestNewWhitelistDAOSeedsCallerAsAdmin(cur realm, t *testing.T) {
testing.SetRealm(testing.NewCodeRealm("gno.land/r/test/daoone"))
d := NewWhitelistDAO()
admins := d.ListAdmins()
uassert.Equal(t, 1, len(admins), "the creator is the only admin")
uassert.True(t, admins[0].IsValid(), "the sole admin is a valid address")
}
// Note: caller-sensitivity of NewWhitelistDAO is NOT asserted here — see the
// same limitation described in p/moul/safe/v0's tests: from a `p/` test package
// unsafe.PreviousRealm() resolves to the origin regardless of SetRealm.
func TestListAdminsReflectsState(t *testing.T) {
bob := testutils.TestAddress("bob")
d := &WhitelistDAO{admins: []address{alice, bob}}
admins := d.ListAdmins()
uassert.Equal(t, 2, len(admins))
uassert.Equal(t, alice.String(), admins[0].String())
uassert.Equal(t, bob.String(), admins[1].String())
}
func TestRenderPlaceholder(t *testing.T) {
d := &WhitelistDAO{admins: []address{alice}}
// Still a placeholder — pinned so replacing it is a visible change.
uassert.Equal(t, "TODO", d.Render(""))
uassert.Equal(t, "TODO", d.Render("/anything"))
}
// TestImplementsUDAO is the compile-time assertion the source makes with
// `var _ udao.DAO = (*WhitelistDAO)(nil)`, restated as a test.
func TestImplementsUDAO(t *testing.T) {
var _ udao.DAO = (*WhitelistDAO)(nil)
uassert.True(t, true, "WhitelistDAO implements udao.DAO")
}
func TestUnimplementedMethodsPanic(cur realm, t *testing.T) {
d := &WhitelistDAO{admins: []address{alice}}
uassert.PanicsWithMessage(t, cur, "not implemented", func() { d.Propose(nil) })
uassert.PanicsWithMessage(t, cur, "not implemented", func() { d.GetProposalStatus(0) })
uassert.PanicsWithMessage(t, cur, "not implemented", func() { d.Execute(0) })
uassert.PanicsWithMessage(t, cur, "not implemented", func() { d.GetProposal(0) })
uassert.PanicsWithMessage(t, cur, "not implemented", func() { d.AddAdmin(alice) })
uassert.PanicsWithMessage(t, cur, "not implemented", func() { d.DelAdmin(alice) })
}