Skip to content

Commit

Permalink
Merge branch 'main' into feat-feed-article-markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
hthieu1110 authored Dec 30, 2024
2 parents a1632dd + 3d27860 commit ad5c97c
Show file tree
Hide file tree
Showing 75 changed files with 1,672 additions and 739 deletions.
2 changes: 1 addition & 1 deletion .gnoversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9786fa366f922f04e1251ec6f1df6423b4fd2bf4
c8cd8f4b6ccbe9f4ee5622032228553496186d51
6 changes: 4 additions & 2 deletions cypress/e2e/gno/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ export const resetChain = () => {

export const connectWallet = () => {
// NOTE: Wait a little bit to ensure that Connect wallet exist and clickable
cy.wait(500);
cy.wait(2000);

cy.contains("Connect wallet").click({ force: true });

cy.get("div[data-testid=connect-gnotest-wallet]", {
timeout: 5_000,
}).click({ force: true });
})
.should("exist")
.click({ force: true });
cy.contains("Connect wallet").should("not.exist");
};
48 changes: 3 additions & 45 deletions gno/p/dao_core/dao_core.gno
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import (
"strconv"
"strings"

"gno.land/p/demo/json"
dao_interfaces "gno.land/p/teritori/dao_interfaces"
"gno.land/p/teritori/jsonutil"
)

// TODO: add wrapper message handler to handle multiple proposal modules messages
Expand All @@ -16,7 +14,6 @@ type daoCore struct {
dao_interfaces.IDAOCore

votingModule dao_interfaces.IVotingModule
rolesModule dao_interfaces.IRolesModule
proposalModules []dao_interfaces.ActivableProposalModule
activeProposalModuleCount int
realm std.Realm
Expand All @@ -25,18 +22,13 @@ type daoCore struct {

func NewDAOCore(
votingModuleFactory dao_interfaces.VotingModuleFactory,
rolesModuleFactory dao_interfaces.RolesModuleFactory,
proposalModulesFactories []dao_interfaces.ProposalModuleFactory,
messageHandlersFactories []dao_interfaces.MessageHandlerFactory,
) dao_interfaces.IDAOCore {
if votingModuleFactory == nil {
panic("Missing voting module factory")
}

if rolesModuleFactory == nil {
panic("Missing roles module factory")
}

if len(proposalModulesFactories) == 0 {
panic("No proposal modules factories")
}
Expand All @@ -53,11 +45,6 @@ func NewDAOCore(
panic("voting module factory returned nil")
}

core.rolesModule = rolesModuleFactory(core)
if core.rolesModule == nil {
panic("roles module factory returned nil")
}

for i, modFactory := range proposalModulesFactories {
mod := modFactory(core)
if mod == nil {
Expand Down Expand Up @@ -130,34 +117,8 @@ func (d *daoCore) VotingModule() dao_interfaces.IVotingModule {
return d.votingModule
}

func (d *daoCore) RolesModule() dao_interfaces.IRolesModule {
return d.rolesModule
}

func (d *daoCore) GetMembersJSON(start, end string, limit uint64, height int64) string {
vMembers := d.votingModule.GetMembersJSON(start, end, limit, height)
nodes, err := json.Unmarshal([]byte(vMembers))
if err != nil {
panic("failed to unmarshal voting module members")
}
vals := nodes.MustArray()
for i, val := range vals {
obj := val.MustObject()
addr := jsonutil.MustAddress(obj["address"])
roles := d.rolesModule.GetMemberRoles(addr)
rolesJSON := make([]*json.Node, len(roles))
for j, role := range roles {
rolesJSON[j] = json.StringNode("", role)
}
obj["roles"] = json.ArrayNode("", rolesJSON)
vals[i] = json.ObjectNode("", obj)

}
return json.ArrayNode("", vals).String()
}

func (d *daoCore) VotingPowerAtHeight(address std.Address, height int64) uint64 {
return d.VotingModule().VotingPowerAtHeight(address, height)
return d.VotingModule().VotingPowerAtHeight(address, height, []string{})
}

func (d *daoCore) ActiveProposalModuleCount() int {
Expand All @@ -168,15 +129,12 @@ func (d *daoCore) Render(path string) string {
sb := strings.Builder{}
sb.WriteString("# DAO Core\n")
votingInfo := d.votingModule.Info()

sb.WriteString("## Voting Module: ")
sb.WriteString(votingInfo.String())
sb.WriteRune('\n')
sb.WriteString(d.votingModule.Render(""))
rolesInfo := d.rolesModule.Info()
sb.WriteString("# Roles Module: ")
sb.WriteString(rolesInfo.String())
sb.WriteRune('\n')
sb.WriteString(d.rolesModule.Render(""))

sb.WriteString("## Supported Messages:\n")
sb.WriteString(d.registry.Render())

Expand Down
60 changes: 2 additions & 58 deletions gno/p/dao_core/dao_core_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -38,61 +38,14 @@ func (vm *votingModule) Render(path string) string {
return "# Test Voting Module"
}

func (vm *votingModule) VotingPowerAtHeight(address std.Address, height int64) uint64 {
func (vm *votingModule) VotingPowerAtHeight(address std.Address, height int64, resources []string) uint64 {
return 0
}

func (vm *votingModule) TotalPowerAtHeight(height int64) uint64 {
return 0
}

type rolesModule struct {
core dao_interfaces.IDAOCore
}

func rolesModuleFactory(core dao_interfaces.IDAOCore) dao_interfaces.IRolesModule {
return &rolesModule{core: core}
}

func (rm *rolesModule) Info() dao_interfaces.ModuleInfo {
return dao_interfaces.ModuleInfo{
Kind: "TestRoles",
Version: "42.21",
}
}

func (rm *rolesModule) ConfigJSON() string {
return "{}"
}

func (rm *rolesModule) Render(path string) string {
return "# Test Roles Module"
}

func (rm *rolesModule) HasRole(address std.Address, role string) bool {
return false
}

func (rm *rolesModule) NewRole(roleName string) {
panic("not implemented")
}

func (rm *rolesModule) DeleteRole(roleName string) {
panic("not implemented")
}

func (rm *rolesModule) GrantRole(address std.Address, role string) {
panic("not implemented")
}

func (rm *rolesModule) RevokeRole(address std.Address, role string) {
panic("not implemented")
}

func (rm *rolesModule) GetMemberRoles(address std.Address) []string {
return []string{}
}

type proposalModule struct {
core dao_interfaces.IDAOCore
}
Expand Down Expand Up @@ -147,7 +100,7 @@ func TestDAOCore(t *testing.T) {
return handler
}

core := NewDAOCore(votingModuleFactory, rolesModuleFactory, []dao_interfaces.ProposalModuleFactory{proposalModuleFactory}, []dao_interfaces.MessageHandlerFactory{handlerFactory})
core := NewDAOCore(votingModuleFactory, []dao_interfaces.ProposalModuleFactory{proposalModuleFactory}, []dao_interfaces.MessageHandlerFactory{handlerFactory})
if core == nil {
t.Fatal("core is nil")
}
Expand All @@ -165,15 +118,6 @@ func TestDAOCore(t *testing.T) {
t.Fatal("voting module has wrong kind")
}

rolesMod := core.RolesModule()
if rolesMod == nil {
t.Fatal("roles module is nil")
}

if rolesMod.Info().Kind != "TestRoles" {
t.Fatal("roles module has wrong kind")
}

propMods := core.ProposalModules()
if len(propMods) != 1 {
t.Fatal("expected 1 proposal module")
Expand Down
6 changes: 0 additions & 6 deletions gno/p/dao_core/gno.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
module gno.land/p/teritori/dao_core

require (
gno.land/p/demo/json v0.0.0-latest
gno.land/p/teritori/dao_interfaces v0.0.0-latest
gno.land/p/teritori/jsonutil v0.0.0-latest
)
3 changes: 0 additions & 3 deletions gno/p/dao_interfaces/core.gno
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,10 @@ type IDAOCore interface {
Render(path string) string

VotingModule() IVotingModule
RolesModule() IRolesModule
ProposalModules() []ActivableProposalModule
ActiveProposalModuleCount() int
Registry() *MessagesRegistry

UpdateVotingModule(newVotingModule IVotingModule)
UpdateProposalModules(toAdd []IProposalModule, toDisable []int)

GetMembersJSON(start, end string, limit uint64, height int64) string
}
10 changes: 2 additions & 8 deletions gno/p/dao_interfaces/core_testing.gno
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package dao_interfaces

type dummyCore struct{}

var _ IDAOCore = (*dummyCore)(nil)

func NewDummyCore() IDAOCore {
return &dummyCore{}
}
Expand All @@ -14,10 +16,6 @@ func (d *dummyCore) VotingModule() IVotingModule {
panic("not implemented")
}

func (d *dummyCore) RolesModule() IRolesModule {
panic("not implemented")
}

func (d *dummyCore) ProposalModules() []ActivableProposalModule {
panic("not implemented")
}
Expand All @@ -37,7 +35,3 @@ func (d *dummyCore) UpdateVotingModule(newVotingModule IVotingModule) {
func (d *dummyCore) UpdateProposalModules(toAdd []IProposalModule, toDisable []int) {
panic("not implemented")
}

func (d *dummyCore) GetMembersJSON(start, end string, limit uint64, height int64) string {
panic("not implemented")
}
5 changes: 0 additions & 5 deletions gno/p/dao_interfaces/gno.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
module gno.land/p/teritori/dao_interfaces

require (
gno.land/p/demo/avl v0.0.0-latest
gno.land/p/demo/json v0.0.0-latest
)
17 changes: 1 addition & 16 deletions gno/p/dao_interfaces/modules.gno
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@ type IVotingModule interface {
ConfigJSON() string
GetMembersJSON(start, end string, limit uint64, height int64) string
Render(path string) string
VotingPowerAtHeight(address std.Address, height int64) (power uint64)
VotingPowerAtHeight(address std.Address, height int64, resources []string) (power uint64)
TotalPowerAtHeight(height int64) uint64
}

type VotingModuleFactory func(core IDAOCore) IVotingModule

type IProposalModule interface {
Core() IDAOCore
Info() ModuleInfo
ConfigJSON() string
Render(path string) string
Expand All @@ -37,17 +36,3 @@ type IProposalModule interface {
}

type ProposalModuleFactory func(core IDAOCore) IProposalModule

type IRolesModule interface {
Info() ModuleInfo
ConfigJSON() string
Render(path string) string
GetMemberRoles(address std.Address) []string
HasRole(address std.Address, role string) bool
NewRole(roleName string)
DeleteRole(roleName string)
GrantRole(address std.Address, role string)
RevokeRole(address std.Address, role string)
}

type RolesModuleFactory func(core IDAOCore) IRolesModule
15 changes: 8 additions & 7 deletions gno/p/dao_proposal_single/dao_proposal_single.gno
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ func (opts DAOProposalSingleOpts) ToJSON() *json.Node {
}

type DAOProposalSingle struct {
dao_interfaces.IProposalModule

core dao_interfaces.IDAOCore
opts *DAOProposalSingleOpts
proposals []*Proposal
}

var _ dao_interfaces.IProposalModule = (*DAOProposalSingle)(nil)

func NewDAOProposalSingle(core dao_interfaces.IDAOCore, opts *DAOProposalSingleOpts) *DAOProposalSingle {
if core == nil {
panic("core cannot be nil")
Expand Down Expand Up @@ -238,10 +238,6 @@ func (d *DAOProposalSingle) Render(path string) string {
return sb.String()
}

func (d *DAOProposalSingle) Core() dao_interfaces.IDAOCore {
return d.core
}

func (d *DAOProposalSingle) Info() dao_interfaces.ModuleInfo {
return dao_interfaces.ModuleInfo{
Kind: "gno.land/p/teritori/dao_proposal_single",
Expand Down Expand Up @@ -331,7 +327,12 @@ func (d *DAOProposalSingle) VoteJSON(proposalID int, voteJSON string) {
panic("proposal is expired")
}

votePower := d.core.VotingModule().VotingPowerAtHeight(voter, proposal.StartHeight)
resources := make([]string, len(proposal.Messages))
for i, m := range proposal.Messages {
resources[i] = m.Type()
}

votePower := d.core.VotingModule().VotingPowerAtHeight(voter, proposal.StartHeight, resources)
if votePower == 0 {
panic("not registered")
}
Expand Down
8 changes: 0 additions & 8 deletions gno/p/dao_proposal_single/gno.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1 @@
module gno.land/p/teritori/dao_proposal_single

require (
gno.land/p/demo/avl v0.0.0-latest
gno.land/p/demo/json v0.0.0-latest
gno.land/p/teritori/dao_interfaces v0.0.0-latest
gno.land/p/teritori/dao_utils v0.0.0-latest
gno.land/p/teritori/jsonutil v0.0.0-latest
)
7 changes: 0 additions & 7 deletions gno/p/dao_roles_group/gno.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1 @@
module gno.land/p/teritori/dao_roles_group

require (
gno.land/p/demo/json v0.0.0-latest
gno.land/p/teritori/dao_interfaces v0.0.0-latest
gno.land/p/teritori/jsonutil v0.0.0-latest
gno.land/p/teritori/role_manager v0.0.0-latest
)
Loading

0 comments on commit ad5c97c

Please sign in to comment.