-
Notifications
You must be signed in to change notification settings - Fork 386
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: lock token transfer and parameter module
- Loading branch information
Showing
48 changed files
with
1,212 additions
and
240 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!' |
Oops, something went wrong.