Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: lock token transfer and parameter module #3176

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions contribs/gnodev/pkg/dev/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ func NewDevNode(ctx context.Context, cfg *NodeConfig) (*Node, error) {
initialState: cfg.InitialTxs,
currentStateIndex: len(cfg.InitialTxs),
}

// generate genesis state
genesis := gnoland.DefaultGenState()
genesis.Balances = cfg.BalancesList
genesis.Txs = append(pkgsTxs, cfg.InitialTxs...)
Expand Down
1 change: 0 additions & 1 deletion contribs/gnodev/pkg/dev/node_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ func (n *Node) ExportStateAsGenesis(ctx context.Context) (*bft.GenesisDoc, error

// Get current blockstore state
doc := *n.Node.GenesisDoc() // copy doc

genState := doc.AppState.(gnoland.GnoGenesisState)
genState.Balances = n.config.BalancesList
genState.Txs = state
Expand Down
132 changes: 0 additions & 132 deletions examples/gno.land/r/gov/dao/v2/prop4_filetest.gno

This file was deleted.

2 changes: 1 addition & 1 deletion examples/gno.land/r/nemanya/config/gno.mod
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module gno.land/r/nemanya/config
module gno.land/r/nemanya/config
2 changes: 1 addition & 1 deletion examples/gno.land/r/nemanya/home/gno.mod
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module gno.land/r/nemanya/home
module gno.land/r/nemanya/home
28 changes: 14 additions & 14 deletions examples/gno.land/r/nemanya/home/home.gno
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ type Project struct {
}

var (
textArt string
aboutMe string
sponsorInfo string
socialLinks map[string]SocialLink
gnoProjects map[string]Project
otherProjects map[string]Project
textArt string
aboutMe string
sponsorInfo string
socialLinks map[string]SocialLink
gnoProjects map[string]Project
otherProjects map[string]Project
totalDonations std.Coins
)

Expand Down Expand Up @@ -266,15 +266,15 @@ func Withdraw() string {
panic(config.ErrUnauthorized)
}

banker := std.GetBanker(std.BankerTypeRealmSend)
realmAddress := std.GetOrigPkgAddr()
coins := banker.GetCoins(realmAddress)
banker := std.GetBanker(std.BankerTypeRealmSend)
realmAddress := std.GetOrigPkgAddr()
coins := banker.GetCoins(realmAddress)

if len(coins) == 0 {
return "No coins available to withdraw"
}
if len(coins) == 0 {
return "No coins available to withdraw"
}

banker.SendCoins(realmAddress, config.Address(), coins)
banker.SendCoins(realmAddress, config.Address(), coins)

return "Successfully withdrew all coins to config address"
return "Successfully withdrew all coins to config address"
}
54 changes: 0 additions & 54 deletions examples/gno.land/r/sys/params/params.gno

This file was deleted.

15 changes: 0 additions & 15 deletions examples/gno.land/r/sys/params/params_test.gno

This file was deleted.

42 changes: 42 additions & 0 deletions examples/gno.land/r/sys/params/unlock.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package params

import (
"std"

"gno.land/p/demo/dao"
"gno.land/r/gov/dao/bridge"
)

const (
lockSendKey = "lockSend.bool"
UnlockSendTitle = "Proposal to unlock the sending functionality for ugnot."
LockSendTitle = "Proposal to lock the sending functionality for ugnot."
)

func ProposeUnlockSend() uint64 {
callback := func() error {
std.SetParamBool(lockSendKey, false)
return nil
}
return propose(callback, UnlockSendTitle, "")
}

func ProposeLockSend() uint64 {
callback := func() error {
std.SetParamBool(lockSendKey, true)
return nil
}
return propose(callback, LockSendTitle, "")
}

func propose(callback func() error, title, desc string) uint64 {
// The callback function is executed only after the proposal is voted on
// and approved by the GovDAO.
exe := bridge.GovDAO().NewGovDAOExecutor(callback)
prop := dao.ProposalRequest{
Title: title,
Description: desc,
Executor: exe,
}
return bridge.GovDAO().Propose(prop)
}
49 changes: 49 additions & 0 deletions examples/gno.land/r/sys/params/unlock_test.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package params

import (
"testing"

"gno.land/p/demo/dao"
"gno.land/p/demo/simpledao"
"gno.land/p/demo/urequire"
"gno.land/r/gov/dao/bridge"
)

func TestProUnlockSend(t *testing.T) {
govdao := bridge.GovDAO()
id := ProposeUnlockSend()
p, err := govdao.GetPropStore().ProposalByID(id)
urequire.NoError(t, err)
urequire.Equal(t, UnlockSendTitle, p.Title())
}

func TestFailUnlockSend(t *testing.T) {
govdao := bridge.GovDAO()
id := ProposeUnlockSend()
urequire.PanicsWithMessage(
t,
simpledao.ErrProposalNotAccepted.Error(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think we should standardize errors like these, to avoid having to import simpledao?
It would mean that the dao package would need to know about specific implementation details like errors, so I'm not sure if this is the way to go

cc @moul

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, GovDAO is a wrapper around the SimpleDAO. All voting and proposal functionality are implemented in SimpleDAO. I'm not sure if using the proposal errors defined in SimpleDAO will cause any issues down the line unless we decide to flatten the GovDAO implementation and stop wrapping the SimpleDAO package entirely.

On the other hand, whether GovDAO should be implemented as a SimpleDAO wrapper or not can be a separate topic.

func() {
govdao.ExecuteProposal(id)
},
)
}

func TestExeUnlockSend(t *testing.T) {
govdao := bridge.GovDAO()
id := ProposeUnlockSend()
p, err := govdao.GetPropStore().ProposalByID(id)
urequire.NoError(t, err)
urequire.True(t, dao.Active == p.Status())

govdao.VoteOnProposal(id, dao.YesVote)
urequire.True(t, dao.Accepted == p.Status())
urequire.NotPanics(
t,
func() {
govdao.ExecuteProposal(id)
},
)

urequire.True(t, dao.ExecutionSuccessful == p.Status())
}
Loading
Loading