Playground
entity.gno
// Package entity provides an interface that abstracts a notion of entity which
// can under the hood be an EOA (address), a package realm (PkgPath, address).
// It also tries to give a notion of type where for instance, a user can be
// either a simple user or a team, and a contract can be either an arbitrary
// contract, or one that implements a famous pattern/interface, such as a DAO.
// It also provides some composition utilities so that an entity can be a flow
// that matches multiple other entities.
package entity
import (
"chain/runtime"
)
type Entity interface {
Addr() address
Path() string
Kind
isEntity()
}
type Kind interface {
kind()
}
type UserEntity interface {
Entity
isUserEntity()
}
type RealmEntity interface {
Entity
isRealmEntity()
}
func NewUserByAddr(addr address) UserEntity { panic("not implemented") }
func NewUserByName(name string) UserEntity { panic("not implemented") }
func NewRealm(rlm runtime.Realm) RealmEntity { panic("not implemented") }
entity_test.gno
package entity
import (
"testing"
"gno.land/p/nt/testutils/v0"
"gno.land/p/nt/uassert/v0"
)
// This package is an API sketch recovered from an unmerged upstream proposal:
// it declares the Entity abstraction and its user/realm refinements, but all
// three constructors are `panic("not implemented")`. The tests pin that surface
// so implementing one is a deliberate, visible change.
func TestConstructorsAreNotImplemented(cur realm, t *testing.T) {
addr := testutils.TestAddress("alice")
uassert.PanicsWithMessage(t, cur, "not implemented", func() { NewUserByAddr(addr) })
uassert.PanicsWithMessage(t, cur, "not implemented", func() { NewUserByName("alice") })
}
// TestInterfacesAreDeclared is a compile-time check that the interface
// hierarchy still exists with its documented shape.
func TestInterfacesAreDeclared(t *testing.T) {
var (
_ Entity
_ Kind
_ UserEntity
_ RealmEntity
)
uassert.True(t, true, "entity interfaces are declared")
}
// TestRefinementsEmbedEntity pins that UserEntity and RealmEntity are still
// refinements of Entity — assigning them to an Entity must compile.
func TestRefinementsEmbedEntity(t *testing.T) {
var (
u UserEntity
r RealmEntity
)
var _ Entity = u
var _ Entity = r
uassert.True(t, true, "UserEntity and RealmEntity satisfy Entity")
}
gnomod.toml
module = "gno.land/p/nym-moultest123/entity/v0" gno = "0.9" [addpkg] creator = "g1ml9grtwnpzqn3hre5ve5vjdlmv2srrmpmc0dsv" height = 186404 max_deposit = "5000000ugnot"