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 60 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
2279644
feat: lock token transfer and parameter module
piux2 Nov 21, 2024
c293926
chores: ufmt
piux2 Nov 21, 2024
3591b39
addressed comments
piux2 Dec 9, 2024
c84c819
merge master
piux2 Dec 27, 2024
5cecf36
merge master
piux2 Dec 27, 2024
599e64a
fmt
piux2 Dec 27, 2024
b7f317a
fix test
piux2 Dec 27, 2024
41d1633
lint
piux2 Dec 27, 2024
9fd24d5
fix test
piux2 Dec 27, 2024
9f05d03
gno tidy
piux2 Dec 27, 2024
692bc1d
addressed review comments
piux2 Jan 20, 2025
df5cc2f
fix bugs
piux2 Jan 21, 2025
41378f5
lint
piux2 Jan 21, 2025
f95e945
fix bugs and clean up
piux2 Jan 21, 2025
ad9eb84
Merged master into this branch
piux2 Jan 22, 2025
529bd97
fix test
piux2 Jan 22, 2025
bd27b2e
fix integration test
piux2 Jan 22, 2025
696ab02
refactor the unlocksend proposal
piux2 Jan 22, 2025
52cdd68
remove unnecessary check
piux2 Jan 23, 2025
ba1c49e
refactor gno account attributes
piux2 Jan 25, 2025
0313890
added tests
piux2 Jan 25, 2025
625fa5b
fix test
piux2 Jan 25, 2025
842c80d
cleaned up interfaces and addressed empty genesis state
piux2 Jan 30, 2025
c3c64e1
added setPrefixedXXX, fixed keeper.initGenesis
piux2 Feb 6, 2025
8f93911
updated prefix setters
piux2 Feb 7, 2025
304d56a
refactor SDKParam
piux2 Feb 8, 2025
7c111e8
more tests and clean up
piux2 Feb 10, 2025
6bc4602
merged master to this branch
piux2 Feb 10, 2025
1f6ce70
lint
piux2 Feb 10, 2025
d7aaf22
fix test
piux2 Feb 10, 2025
5f67b6d
fixed merge
piux2 Feb 10, 2025
5812fcc
merged the lastest master
piux2 Feb 10, 2025
d282741
fix tests
piux2 Feb 10, 2025
0459dd8
Merge remote-tracking branch 'origin/master' into feat_lock_transfer
piux2 Feb 10, 2025
ab4a676
remove iavl/testdata
piux2 Feb 10, 2025
6c9da8b
Merge branch 'master' into feat_lock_transfer
moul Feb 11, 2025
fb627fa
updated prefix, validation and tests
piux2 Feb 13, 2025
76fb5ee
merge the Master in this branch
piux2 Feb 13, 2025
cf36f63
Merge branch 'feat_lock_transfer' of https://github.com/piux2/gno int…
piux2 Feb 13, 2025
3002f65
fix test
piux2 Feb 13, 2025
cf9fe49
fix the test
piux2 Feb 14, 2025
bfe737f
lint
piux2 Feb 14, 2025
d98a5d2
fix test
piux2 Feb 14, 2025
8f6b1a8
more testing coverage
piux2 Feb 14, 2025
1c653cc
fix
piux2 Feb 14, 2025
b3ee19f
Merge remote-tracking branch 'origin/master' into feat_lock_transfer
piux2 Feb 14, 2025
3fd67eb
Minor fixes and code cleanup.
piux2 Feb 17, 2025
8c598e2
fix lower case const
piux2 Feb 17, 2025
1c84000
Merge remote-tracking branch 'origin/master' into feat_lock_transfer
piux2 Feb 18, 2025
9889ece
updated the CI workflows go version to 1.23.xx
piux2 Feb 18, 2025
98af87b
Merge branch 'master' into feat_lock_transfer
thehowl Feb 18, 2025
02d1a61
more tests and clean up
piux2 Feb 20, 2025
d3a24d9
merged master in this branch
piux2 Feb 20, 2025
1edd921
Merge branch 'feat_lock_transfer' of https://github.com/piux2/gno int…
piux2 Feb 20, 2025
228a273
fix test
piux2 Feb 20, 2025
3ceaadf
fix test
piux2 Feb 20, 2025
12b6f19
fix test
piux2 Feb 20, 2025
6e07d28
remove account.IsRestrict() and use account.IsUnrestricted() instead
piux2 Feb 20, 2025
a1e2517
fix test
piux2 Feb 24, 2025
250df38
address comments
piux2 Feb 24, 2025
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
28 changes: 13 additions & 15 deletions contribs/gnodev/pkg/dev/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,9 @@
}

// generate genesis state
genesis := gnoland.GnoGenesisState{
Balances: cfg.BalancesList,
Txs: append(pkgsTxs, cfg.InitialTxs...),
}
genesis := gnoland.DefaultGenState()
genesis.Balances = cfg.BalancesList
genesis.Txs = append(pkgsTxs, cfg.InitialTxs...)

if err := devnode.rebuildNode(ctx, genesis); err != nil {
return nil, fmt.Errorf("unable to initialize the node: %w", err)
Expand Down Expand Up @@ -276,10 +275,9 @@

// Append initialTxs
txs := append(pkgsTxs, n.initialState...)
genesis := gnoland.GnoGenesisState{
Balances: n.config.BalancesList,
Txs: txs,
}
genesis := gnoland.DefaultGenState()
genesis.Balances = n.config.BalancesList
genesis.Txs = txs

// Reset the node with the new genesis state.
err = n.rebuildNode(ctx, genesis)
Expand Down Expand Up @@ -402,9 +400,10 @@
return fmt.Errorf("unable to load pkgs: %w", err)
}

return n.rebuildNode(ctx, gnoland.GnoGenesisState{
Balances: n.config.BalancesList, Txs: txs,
})
genesis := gnoland.DefaultGenState()
genesis.Balances = n.config.BalancesList
genesis.Txs = txs
return n.rebuildNode(ctx, genesis)

Check warning on line 406 in contribs/gnodev/pkg/dev/node.go

View check run for this annotation

Codecov / codecov/patch

contribs/gnodev/pkg/dev/node.go#L403-L406

Added lines #L403 - L406 were not covered by tests
}

state, err := n.getBlockStoreState(ctx)
Expand All @@ -419,10 +418,9 @@
}

// Create genesis with loaded pkgs + previous state
genesis := gnoland.GnoGenesisState{
Balances: n.config.BalancesList,
Txs: append(pkgsTxs, state...),
}
genesis := gnoland.DefaultGenState()
genesis.Balances = n.config.BalancesList
genesis.Txs = append(pkgsTxs, state...)

// Reset the node with the new genesis state.
err = n.rebuildNode(ctx, genesis)
Expand Down
15 changes: 7 additions & 8 deletions contribs/gnodev/pkg/dev/node_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,9 @@ func (n *Node) MoveBy(ctx context.Context, x int) error {
newState := n.state[:newIndex]

// Create genesis with loaded pkgs + previous state
genesis := gnoland.GnoGenesisState{
Balances: n.config.BalancesList,
Txs: append(pkgsTxs, newState...),
}
genesis := gnoland.DefaultGenState()
genesis.Balances = n.config.BalancesList
genesis.Txs = append(pkgsTxs, newState...)

// Reset the node with the new genesis state.
if err = n.rebuildNode(ctx, genesis); err != nil {
Expand Down Expand Up @@ -132,10 +131,10 @@ func (n *Node) ExportStateAsGenesis(ctx context.Context) (*bft.GenesisDoc, error

// Get current blockstore state
doc := *n.Node.GenesisDoc() // copy doc
doc.AppState = gnoland.GnoGenesisState{
Balances: n.config.BalancesList,
Txs: state,
}
genState := doc.AppState.(gnoland.GnoGenesisState)
genState.Balances = n.config.BalancesList
genState.Txs = state
doc.AppState = genState

return &doc, nil
}
1 change: 0 additions & 1 deletion examples/gno.land/r/sys/params/gno.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
module gno.land/r/sys/params

require (
gno.land/p/demo/dao v0.0.0-latest
gno.land/r/gov/dao/bridge v0.0.0-latest
Expand Down
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.

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

import (
"std"

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

const lockSendKey = "lockSend.bool"
const UnlockSendDesc = "Proposal to unlock the sending functionality for ugnot."
const LockSendDesc = "Proposal to lock the sending functionality for ugnot."

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

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

func propose(callback func() error, 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{
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, UnlockSendDesc, p.Description())
}

func TestFailUnlockSend(t *testing.T) {
govdao := bridge.GovDAO()
id := ProposeUnlockSend()
urequire.PanicsWithMessage(
t,
simpledao.ErrProposalNotAccepted.Error(),
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())
}
8 changes: 4 additions & 4 deletions gno.land/cmd/gnoland/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,10 +410,10 @@ func generateGenesisFile(genesisFile string, pk crypto.PubKey, c *startCfg) erro
genesisTxs = append(pkgsTxs, genesisTxs...)

// Construct genesis AppState.
gen.AppState = gnoland.GnoGenesisState{
Balances: balances,
Txs: genesisTxs,
}
defaultGenState := gnoland.DefaultGenState()
defaultGenState.Balances = balances
defaultGenState.Txs = genesisTxs
gen.AppState = defaultGenState

// Write genesis state
if err := gen.SaveAs(genesisFile); err != nil {
Expand Down
54 changes: 54 additions & 0 deletions gno.land/cmd/gnoland/testdata/transfer_lock.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
## It tests locking token transfers while allowing the payment of gas fees.

## locking transfer applies to regular acocunts
adduser regular1


loadpkg gno.land/r/demo/wugnot
loadpkg gno.land/r/demo/echo

## start a new node.
## The -lock-transfer flag is intended for integration testing purposes
## and is not a valid application flag for gnoland.

gnoland start -lock-transfer

## User test1 is an unrestricted account specified in the genesis state
gnokey maketx send -send "9999999ugnot" -to $USER_ADDR_regular1 -gas-fee 1ugnot -gas-wanted 10000000 -broadcast -chainid=tendermint_test test1

stdout 'OK!'

## Restricted simple token transfer
! gnokey maketx send -send "9999999ugnot" -to g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5 -gas-fee 1ugnot -gas-wanted 10000000 -broadcast -chainid=tendermint_test regular1
stderr 'restricted token transfer error'

## Restricted token transfer by calling a realm deposit function.
! gnokey maketx call -pkgpath gno.land/r/demo/wugnot -func Deposit -gas-fee 1000000ugnot -send "10000ugnot" -gas-wanted 2000000 -broadcast -chainid=tendermint_test regular1
stderr 'restricted token transfer error'


## Restricted token transfer with depositing to a realm package while adding a package.
! gnokey maketx addpkg -pkgdir $WORK -pkgpath gno.land/r/bank -deposit "1000ugnot" -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test regular1
stderr 'restricted token transfer error'

## paying gas fees to add a package is acceptable.
gnokey maketx addpkg -pkgdir $WORK -pkgpath gno.land/r/bank -gas-fee 1000000ugnot -gas-wanted 2500000 -broadcast -chainid=tendermint_test regular1
stdout 'OK!'

## paying gas fees to call a realm function is acceptable.
gnokey maketx call -pkgpath gno.land/r/demo/echo -func Render -args "Hello!" -gas-fee 1000000ugnot -gas-wanted 2500000 -broadcast -chainid=tendermint_test regular1
stdout 'Hello!'

-- bank.gno --
package bank
import (
"std"
)
func Withdraw(denom string, amt int64) string{
caller := std.GetOrigCaller()
coin := std.Coins{{denom, amt}}
banker := std.GetBanker(std.BankerTypeOrigSend)
pkgaddr := std.GetOrigPkgAddr()
banker.SendCoins(pkgaddr, caller, coin)
return "Withdrawed!"
}
42 changes: 42 additions & 0 deletions gno.land/cmd/gnoland/testdata/transfer_unlock.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
## It tests unlocking token transfers through GovDAO voting
loadpkg gno.land/r/sys/params
loadpkg gno.land/r/gov/dao/v2

patchpkg "g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm" "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5"

adduser regular1

## start a new node
gnoland start -lock-transfer

## User test1 is an unrestricted account specified in the genesis state
gnokey maketx send -send "9999999ugnot" -to $USER_ADDR_regular1 -gas-fee 1ugnot -gas-wanted 10000000 -broadcast -chainid=tendermint_test test1

stdout 'OK!'

## Restricted simple token transfer for a regular account
! gnokey maketx send -send "100ugnot" -to g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5 -gas-fee 1ugnot -gas-wanted 10000000 -broadcast -chainid=tendermint_test regular1

stderr 'restricted token transfer error'

## Submit a proposal to unlock the transfer. When token transfer is locked, only the predefined unrestricted account test1 in the genesis state can
## pay the fee and submit a proposal to unlock the transfer.
gnokey maketx call -pkgpath gno.land/r/sys/params -func ProposeUnlockSend -send 250000000ugnot -gas-fee 1ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1

stdout '(0 uint64)'


## vote unlock proposal with unrestricted account test1
gnokey maketx call -pkgpath gno.land/r/gov/dao/v2 -func VoteOnProposal -args 0 -args "YES" -send 250000000ugnot -gas-fee 1ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1

stdout 'OK!'

## vote unlock proposal with unrestricted account test1
gnokey maketx call -pkgpath gno.land/r/gov/dao/v2 -func ExecuteProposal -args 0 -send 250000000ugnot -gas-fee 1ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1

stdout 'OK!'

## Restricted transfer is unlocked, allowing simple token transfers for regular accounts.
gnokey maketx send -send "100ugnot" -to g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5 -gas-fee 1ugnot -gas-wanted 10000000 -broadcast -chainid=tendermint_test regular1

stdout 'OK!'
Loading
Loading