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(bank/v2): port tokenfactory into bank/v2 #22264

Open
wants to merge 39 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
f7c5def
add denomMetadata & authority metadata
hieuvubk Oct 15, 2024
a7c45d4
genesis & funcs
hieuvubk Oct 15, 2024
e3794b2
add handlers
hieuvubk Oct 15, 2024
1ed5ce2
default params & validate
hieuvubk Oct 15, 2024
78fa7d0
add todo
hieuvubk Oct 15, 2024
d2fc65f
add more query
hieuvubk Oct 15, 2024
dbdae75
add tests
hieuvubk Oct 15, 2024
638b1a0
check err
hieuvubk Oct 15, 2024
edfcd67
check setParams err
hieuvubk Oct 15, 2024
b20efbe
lint
hieuvubk Oct 15, 2024
007d595
Merge branch 'main' into hieu/bankv2/create_denom
hieuvubk Oct 15, 2024
d95d5fb
update proto
hieuvubk Oct 29, 2024
0d1ceaf
add tokenfatory logic into mint
hieuvubk Oct 29, 2024
13878ff
mint test
hieuvubk Oct 29, 2024
498208a
test send tokenfactory denoms
hieuvubk Oct 29, 2024
767299a
burn handler & tests
hieuvubk Oct 29, 2024
4ec773c
add query
hieuvubk Oct 31, 2024
9ae0291
test denom creation
hieuvubk Nov 4, 2024
3d937ca
add create denom tx cmd
hieuvubk Nov 4, 2024
0bfe528
add more query and tests
hieuvubk Nov 4, 2024
73eaed3
test mint
hieuvubk Nov 5, 2024
67489ff
Merge branch 'main' into hieu/bankv2/create_denom
hieuvubk Nov 5, 2024
f7c130c
pass mint cmd & mint proposal
hieuvubk Nov 5, 2024
b295e39
Merge branch 'main' into hieu/bankv2/create_denom
hieuvubk Nov 7, 2024
3c33c55
burn msg & cmd
hieuvubk Nov 7, 2024
f391ffe
burn systemtest
hieuvubk Nov 7, 2024
03b0438
unused
hieuvubk Nov 7, 2024
23a2703
lint
hieuvubk Nov 7, 2024
3d8967e
lint
hieuvubk Nov 7, 2024
a325394
add admin account type
hieuvubk Nov 13, 2024
081f723
admin disable
hieuvubk Nov 13, 2024
737463c
update logic
hieuvubk Nov 13, 2024
a18b33d
test
hieuvubk Nov 13, 2024
1ce441e
go mod tidy
hieuvubk Nov 13, 2024
880b20a
merge main
hieuvubk Nov 13, 2024
7b2bbcb
go mod tidy again
hieuvubk Nov 13, 2024
ede3f22
fix test
hieuvubk Nov 13, 2024
989643f
systemtests
hieuvubk Nov 14, 2024
710a95a
use address codec
hieuvubk Nov 25, 2024
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
4,810 changes: 4,810 additions & 0 deletions api/cosmos/accounts/defaults/admin/v1/admin.pulsar.go

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion simapp/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
cosmossdk.io/math v1.3.0
cosmossdk.io/store v1.1.1
cosmossdk.io/tools/confix v0.0.0-20230613133644-0a778132a60f
cosmossdk.io/x/accounts v0.0.0-20240913065641-0064ccbce64e
cosmossdk.io/x/accounts v0.0.0-20241112091912-96a1c1c833ea
cosmossdk.io/x/accounts/defaults/base v0.0.0-00010101000000-000000000000
cosmossdk.io/x/accounts/defaults/lockup v0.0.0-20240417181816-5e7aae0db1f5
cosmossdk.io/x/accounts/defaults/multisig v0.0.0-00010101000000-000000000000
Expand Down Expand Up @@ -63,6 +63,7 @@ require (
cloud.google.com/go/storage v1.43.0 // indirect
cosmossdk.io/errors v1.0.1 // indirect
cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac // indirect
cosmossdk.io/x/accounts/defaults/admin v0.0.0-00010101000000-000000000000 // indirect
filippo.io/edwards25519 v1.1.0 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
github.com/99designs/keyring v1.2.2 // indirect
Expand Down Expand Up @@ -257,6 +258,7 @@ replace (
cosmossdk.io/store => ../store
cosmossdk.io/tools/confix => ../tools/confix
cosmossdk.io/x/accounts => ../x/accounts
cosmossdk.io/x/accounts/defaults/admin => ../x/accounts/defaults/admin
cosmossdk.io/x/accounts/defaults/base => ../x/accounts/defaults/base
cosmossdk.io/x/accounts/defaults/lockup => ../x/accounts/defaults/lockup
cosmossdk.io/x/accounts/defaults/multisig => ../x/accounts/defaults/multisig
Expand Down
2 changes: 2 additions & 0 deletions simapp/v2/app_di.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
basedepinject "cosmossdk.io/x/accounts/defaults/base/depinject"
lockupdepinject "cosmossdk.io/x/accounts/defaults/lockup/depinject"
multisigdepinject "cosmossdk.io/x/accounts/defaults/multisig/depinject"
admindepinject "cosmossdk.io/x/accounts/defaults/admin/depinject"
stakingkeeper "cosmossdk.io/x/staking/keeper"
upgradekeeper "cosmossdk.io/x/upgrade/keeper"

Expand Down Expand Up @@ -55,6 +56,7 @@ func AppConfig() depinject.Config {
multisigdepinject.ProvideAccount,
basedepinject.ProvideAccount,
lockupdepinject.ProvideAllLockupAccounts,
admindepinject.ProvideAccount,

// provide base account options
basedepinject.ProvideSecp256K1PubKey,
Expand Down
4 changes: 3 additions & 1 deletion simapp/v2/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
cosmossdk.io/server/v2/cometbft v0.0.0-20241015140036-ee3d320eaa55
cosmossdk.io/store/v2 v2.0.0
cosmossdk.io/tools/confix v0.0.0-00010101000000-000000000000
cosmossdk.io/x/accounts v0.0.0-20240913065641-0064ccbce64e
cosmossdk.io/x/accounts v0.0.0-20241112091912-96a1c1c833ea
cosmossdk.io/x/authz v0.0.0-00010101000000-000000000000
cosmossdk.io/x/bank v0.0.0-20240226161501-23359a0b6d91
cosmossdk.io/x/circuit v0.0.0-20230613133644-0a778132a60f
Expand Down Expand Up @@ -65,6 +65,7 @@ require (
cosmossdk.io/server/v2/appmanager v0.0.0-20240802110823-cffeedff643d // indirect
cosmossdk.io/server/v2/stf v0.0.0-20240708142107-25e99c54bac1 // indirect
cosmossdk.io/store v1.1.1 // indirect
cosmossdk.io/x/accounts/defaults/admin v0.0.0-00010101000000-000000000000 // indirect
cosmossdk.io/x/tx v1.0.0-alpha.1 // indirect
filippo.io/edwards25519 v1.1.0 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
Expand Down Expand Up @@ -259,6 +260,7 @@ replace (
cosmossdk.io/collections => ../../collections
cosmossdk.io/tools/confix => ../../tools/confix
cosmossdk.io/x/accounts => ../../x/accounts
cosmossdk.io/x/accounts/defaults/admin => ../../x/accounts/defaults/admin
cosmossdk.io/x/accounts/defaults/base => ../../x/accounts/defaults/base
cosmossdk.io/x/accounts/defaults/lockup => ../../x/accounts/defaults/lockup
cosmossdk.io/x/accounts/defaults/multisig => ../../x/accounts/defaults/multisig
Expand Down
4 changes: 3 additions & 1 deletion tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ require (
cosmossdk.io/runtime/v2 v2.0.0-20240911143651-72620a577660
cosmossdk.io/server/v2/stf v0.0.0-00010101000000-000000000000
cosmossdk.io/store/v2 v2.0.0-00010101000000-000000000000
cosmossdk.io/x/accounts v0.0.0-20240913065641-0064ccbce64e
cosmossdk.io/x/accounts v0.0.0-20241112091912-96a1c1c833ea
cosmossdk.io/x/accounts/defaults/base v0.0.0-00010101000000-000000000000
cosmossdk.io/x/accounts/defaults/lockup v0.0.0-20240417181816-5e7aae0db1f5
cosmossdk.io/x/accounts/defaults/multisig v0.0.0-00010101000000-000000000000
Expand Down Expand Up @@ -73,6 +73,7 @@ require (
cosmossdk.io/indexer/postgres v0.1.0 // indirect
cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac // indirect
cosmossdk.io/server/v2/appmanager v0.0.0-00010101000000-000000000000 // indirect
cosmossdk.io/x/accounts/defaults/admin v0.0.0-00010101000000-000000000000 // indirect
cosmossdk.io/x/circuit v0.0.0-20230613133644-0a778132a60f // indirect
cosmossdk.io/x/epochs v0.0.0-20240522060652-a1ae4c3e0337 // indirect
filippo.io/edwards25519 v1.1.0 // indirect
Expand Down Expand Up @@ -263,6 +264,7 @@ replace (
cosmossdk.io/store => ../store
cosmossdk.io/store/v2 => ../store/v2
cosmossdk.io/x/accounts => ../x/accounts
cosmossdk.io/x/accounts/defaults/admin => ../x/accounts/defaults/admin
cosmossdk.io/x/accounts/defaults/base => ../x/accounts/defaults/base
cosmossdk.io/x/accounts/defaults/lockup => ../x/accounts/defaults/lockup
cosmossdk.io/x/accounts/defaults/multisig => ../x/accounts/defaults/multisig
Expand Down
277 changes: 277 additions & 0 deletions tests/systemtests/bankv2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ package systemtests
import (
"fmt"
"testing"
"time"

"cosmossdk.io/math"
"github.com/stretchr/testify/require"
"github.com/tidwall/gjson"
)
Expand Down Expand Up @@ -56,3 +58,278 @@ func TestBankV2SendTxCmd(t *testing.T) {
receiverBalance := gjson.Get(receiverRaw, "balance.amount").Int()
require.Equal(t, receiverBalance, transferAmount)
}

func TestCreateDenom(t *testing.T) {
// Currently only run with app v2
if !isV2() {
t.Skip()
}
// given a running chain

sut.ResetChain(t)
cli := NewCLIWrapper(t, sut, verbose)

// add new key
denom := "stake"
subDenom := "test"
feeAmount := math.NewInt(1000000)

sut.ModifyGenesisJSON(
t,
SetDenomCreationFee(t, denom, feeAmount),
)

// get validator address
valAddr := gjson.Get(cli.Keys("keys", "list"), "1.address").String()
require.NotEmpty(t, valAddr)

sut.StartChain(t)

raw := cli.CustomQuery("q", "bankv2", "balance", valAddr, denom)
valBalanceBefore := gjson.Get(raw, "balance.amount").Int()

rsp := cli.Run("tx", "bankv2", "create-denom", subDenom, "--from", valAddr)
txResult, found := cli.AwaitTxCommitted(rsp)
fmt.Println("txResult", txResult)
require.True(t, found)
RequireTxSuccess(t, txResult)
hieuvubk marked this conversation as resolved.
Show resolved Hide resolved
hieuvubk marked this conversation as resolved.
Show resolved Hide resolved

raw = cli.CustomQuery("q", "bankv2", "balance", valAddr, denom)
valBalanceAfter := gjson.Get(raw, "balance.amount").Int()

require.Equal(t, valBalanceBefore-valBalanceAfter, feeAmount.Int64())

raw = cli.CustomQuery("q", "bankv2", "denoms-from-creator", valAddr)
newDenoms := gjson.Get(raw, "denoms").Array()
require.Equal(t, len(newDenoms), 1)

raw = cli.CustomQuery("q", "bankv2", "denom-authority-metadata", newDenoms[0].String())
admin := gjson.Get(raw, "authority_metadata.admin").String()
require.Equal(t, admin, valAddr)
}

func TestMintBurnTokenCmd(t *testing.T) {
// Currently only run with app v2
if !isV2() {
t.Skip()
}
// given a running chain

sut.ResetChain(t)
cli := NewCLIWrapper(t, sut, verbose)

// add new key
denom := "stake"
subDenom := "test"
feeAmount := math.NewInt(1_000_000)
mintAmount := 1_000_000
burnAmount := 500_000

sut.ModifyGenesisJSON(
t,
SetDenomCreationFee(t, denom, feeAmount),
)

// get validator address
valAddr := gjson.Get(cli.Keys("keys", "list"), "1.address").String()
require.NotEmpty(t, valAddr)

// add new key
receiverAddr := cli.AddKey("account1")

sut.StartChain(t)

rsp := cli.Run("tx", "bankv2", "create-denom", subDenom, "--from", valAddr)
txResult, found := cli.AwaitTxCommitted(rsp)
require.True(t, found)
RequireTxSuccess(t, txResult)

raw := cli.CustomQuery("q", "bankv2", "denoms-from-creator", valAddr)
newDenoms := gjson.Get(raw, "denoms").Array()
require.Equal(t, len(newDenoms), 1)

// non tokenfactory should not be minted directly
rsp = cli.Run("tx", "bankv2", "mint", valAddr, receiverAddr, fmt.Sprintf("%d%s", mintAmount, denom))
code := gjson.Get(rsp, "code").Int()
require.NotEqual(t, code, int64(0))
rawLog := gjson.Get(rsp, "raw_log").String()
require.Contains(t, rawLog, "invalid authority")

rsp = cli.Run("tx", "bankv2", "mint", valAddr, receiverAddr, fmt.Sprintf("%d%s", mintAmount, newDenoms[0]))
txResult, found = cli.AwaitTxCommitted(rsp)
require.True(t, found)
RequireTxSuccess(t, txResult)

raw = cli.CustomQuery("q", "bankv2", "balance", receiverAddr, newDenoms[0].String())
balance := gjson.Get(raw, "balance.amount").Int()
require.Equal(t, balance, int64(mintAmount))

// Burn token from receiver
rsp = cli.Run("tx", "bankv2", "burn", valAddr, receiverAddr, fmt.Sprintf("%d%s", burnAmount, newDenoms[0]))
txResult, found = cli.AwaitTxCommitted(rsp)
require.True(t, found)
RequireTxSuccess(t, txResult)

raw = cli.CustomQuery("q", "bankv2", "balance", receiverAddr, newDenoms[0].String())
balance = gjson.Get(raw, "balance.amount").Int()
require.Equal(t, balance, int64(mintAmount-burnAmount))
}

func TestMintBurnTokenProposal(t *testing.T) {
// Currently only run with app v2
if !isV2() {
t.Skip()
}
// given a running chain

sut.ResetChain(t)
cli := NewCLIWrapper(t, sut, verbose)

// add new key
denom := "stake"
subDenom := "test"
mintAmount := 1_000_000
burnAmount := 500_000

sut.ModifyGenesisJSON(
t,
SetGovVotingPeriod(t, time.Second*8),
SetGovExpeditedVotingPeriod(t, time.Second*7),
)

// get validator address
valAddr := cli.GetKeyAddr("node0")
require.NotEmpty(t, valAddr)

valAddr1 := cli.GetKeyAddr("node1")
require.NotEmpty(t, valAddr1)

// add new key
receiverAddr := cli.AddKey("account1")

sut.StartChain(t)

// get gov module address
resp := cli.CustomQuery("q", "auth", "module-account", "gov")
govAddr := gjson.Get(resp, "account.value.address").String()

rsp := cli.Run("tx", "bankv2", "create-denom", subDenom, "--from", valAddr)
txResult, found := cli.AwaitTxCommitted(rsp)
require.True(t, found)
RequireTxSuccess(t, txResult)

raw := cli.CustomQuery("q", "bankv2", "denoms-from-creator", valAddr)
newDenoms := gjson.Get(raw, "denoms").Array()
require.Equal(t, len(newDenoms), 1)
fmt.Println("denoms", raw)

invalidMintProposal := fmt.Sprintf(`
{
"messages": [
{
"@type": "/cosmos.bank.v2.MsgMint",
"authority": "%s",
"to_address": "%s",
"amount": {
"denom": "%s",
"amount": "%d"
}
}
],
"metadata": "ipfs://CID",
"deposit": "100000000stake",
"title": "mint tokenfactory token",
"summary": "testing"
}`, govAddr, receiverAddr, newDenoms[0], mintAmount)

invalidMintProposalFile := StoreTempFile(t, []byte(invalidMintProposal))
rsp = cli.RunAndWait("tx", "gov", "submit-proposal", invalidMintProposalFile.Name(), "--from", valAddr)
RequireTxSuccess(t, rsp)

// vote to proposal from two validators
rsp = cli.RunAndWait("tx", "gov", "vote", "1", "yes", "--from", valAddr)
RequireTxSuccess(t, rsp)
rsp = cli.RunAndWait("tx", "gov", "vote", "1", "yes", "--from", valAddr1)
RequireTxSuccess(t, rsp)

time.Sleep(8 * time.Second)

// Token should not be minted to receiver
raw = cli.CustomQuery("q", "bankv2", "balance", receiverAddr, newDenoms[0].String())
balance := gjson.Get(raw, "balance.amount").Int()
require.Equal(t, balance, int64(0))

validMintProposal := fmt.Sprintf(`
{
"messages": [
{
"@type": "/cosmos.bank.v2.MsgMint",
"authority": "%s",
"to_address": "%s",
"amount": {
"denom": "%s",
"amount": "%d"
}
}
],
"metadata": "ipfs://CID",
"deposit": "100000000stake",
"title": "mint tokenfactory token",
"summary": "testing"
}`, govAddr, receiverAddr, denom, mintAmount)

mintProposalFile := StoreTempFile(t, []byte(validMintProposal))

rsp = cli.RunAndWait("tx", "gov", "submit-proposal", mintProposalFile.Name(), "--from", valAddr)
RequireTxSuccess(t, rsp)

// vote to proposal from two validators
rsp = cli.RunAndWait("tx", "gov", "vote", "2", "yes", "--from", valAddr)
RequireTxSuccess(t, rsp)
rsp = cli.RunAndWait("tx", "gov", "vote", "2", "yes", "--from", valAddr1)
RequireTxSuccess(t, rsp)

time.Sleep(8 * time.Second)

// stake should be minted to receiver
raw = cli.CustomQuery("q", "bankv2", "balance", receiverAddr, denom)
balance = gjson.Get(raw, "balance.amount").Int()
require.Equal(t, balance, int64(mintAmount))

validBurnProposal := fmt.Sprintf(`
{
"messages": [
{
"@type": "/cosmos.bank.v2.MsgBurn",
"authority": "%s",
"burn_from_address": "%s",
"amount": {
"denom": "%s",
"amount": "%d"
}
}
],
"metadata": "ipfs://CID",
"deposit": "100000000stake",
"title": "mint tokenfactory token",
"summary": "testing"
}`, govAddr, receiverAddr, denom, burnAmount)

burnProposalFile := StoreTempFile(t, []byte(validBurnProposal))

rsp = cli.RunAndWait("tx", "gov", "submit-proposal", burnProposalFile.Name(), "--from", valAddr)
RequireTxSuccess(t, rsp)

// vote to proposal from two validators
rsp = cli.RunAndWait("tx", "gov", "vote", "3", "yes", "--from", valAddr)
RequireTxSuccess(t, rsp)
rsp = cli.RunAndWait("tx", "gov", "vote", "3", "yes", "--from", valAddr1)
RequireTxSuccess(t, rsp)

time.Sleep(8 * time.Second)

// stake should be burned from receiver
raw = cli.CustomQuery("q", "bankv2", "balance", receiverAddr, denom)
balance = gjson.Get(raw, "balance.amount").Int()
require.Equal(t, balance, int64(mintAmount-burnAmount))
}
Loading
Loading