diff --git a/CHANGELOG.md b/CHANGELOG.md index 22a94af272..0345af7539 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,6 +44,7 @@ balances or a single balance by denom when the `denom` query parameter is presen * (client) [\#5640](https://github.com/cosmos/cosmos-sdk/pull/5640) The rest server endpoint `/swagger-ui/` is replaced by ´/´. * (x/auth) [\#5702](https://github.com/cosmos/cosmos-sdk/pull/5702) The `x/auth` querier route has changed from `"acc"` to `"auth"`. * (store/types) [\#5730](https://github.com/cosmos/cosmos-sdk/pull/5730) store.types.Cp() is removed in favour of types.CopyBytes(). +* (client) [\#5640](https://github.com/cosmos/cosmos-sdk/issues/5783) Unify all coins representations on JSON client requests for governance proposals. * [\#5785](https://github.com/cosmos/cosmos-sdk/issues/5785) JSON strings coerced to valid UTF-8 bytes at JSON marshalling time are now replaced by human-readable expressions. This change can potentially break compatibility with all those client side tools that parse log messages. diff --git a/x/distribution/client/cli/tx.go b/x/distribution/client/cli/tx.go index a033fd28dc..35d12391d0 100644 --- a/x/distribution/client/cli/tx.go +++ b/x/distribution/client/cli/tx.go @@ -220,18 +220,8 @@ Where proposal.json contains: "title": "Community Pool Spend", "description": "Pay me some Atoms!", "recipient": "cosmos1s5afhd6gxevu37mkqcvvsj8qeylhn0rz46zdlq", - "amount": [ - { - "denom": "stake", - "amount": "10000" - } - ], - "deposit": [ - { - "denom": "stake", - "amount": "10000" - } - ] + "amount": "1000stake", + "deposit": "1000stake" } `, version.ClientName, @@ -248,9 +238,18 @@ Where proposal.json contains: } from := cliCtx.GetFromAddress() - content := types.NewCommunityPoolSpendProposal(proposal.Title, proposal.Description, proposal.Recipient, proposal.Amount) - msg := gov.NewMsgSubmitProposal(content, proposal.Deposit, from) + amount, err := sdk.ParseCoins(proposal.Amount) + if err != nil { + return err + } + content := types.NewCommunityPoolSpendProposal(proposal.Title, proposal.Description, proposal.Recipient, amount) + + deposit, err := sdk.ParseCoins(proposal.Deposit) + if err != nil { + return err + } + msg := gov.NewMsgSubmitProposal(content, deposit, from) if err := msg.ValidateBasic(); err != nil { return err } diff --git a/x/distribution/client/cli/tx_test.go b/x/distribution/client/cli/tx_test.go index 860b31fa63..d8f8b3921c 100644 --- a/x/distribution/client/cli/tx_test.go +++ b/x/distribution/client/cli/tx_test.go @@ -1,8 +1,11 @@ package cli import ( + "io/ioutil" "testing" + "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" "github.com/tendermint/tendermint/crypto/secp256k1" @@ -77,3 +80,30 @@ func Test_splitAndCall_Splitting(t *testing.T) { assert.NoError(t, err, "") assert.Equal(t, 3, callCount) } + +func TestParseProposal(t *testing.T) { + cdc := codec.New() + okJSON, err := ioutil.TempFile("", "proposal") + require.Nil(t, err, "unexpected error") + okJSON.WriteString(` +{ + "title": "Community Pool Spend", + "description": "Pay me some Atoms!", + "recipient": "cosmos1s5afhd6gxevu37mkqcvvsj8qeylhn0rz46zdlq", + "amount": "1000stake", + "deposit": "1000stake" +} +`) + + proposal, err := ParseCommunityPoolSpendProposalJSON(cdc, okJSON.Name()) + require.NoError(t, err) + + addr, err := sdk.AccAddressFromBech32("cosmos1s5afhd6gxevu37mkqcvvsj8qeylhn0rz46zdlq") + require.NoError(t, err) + + require.Equal(t, "Community Pool Spend", proposal.Title) + require.Equal(t, "Pay me some Atoms!", proposal.Description) + require.Equal(t, addr, proposal.Recipient) + require.Equal(t, "1000stake", proposal.Deposit) + require.Equal(t, "1000stake", proposal.Amount) +} diff --git a/x/distribution/client/cli/utils.go b/x/distribution/client/cli/utils.go index 2860162502..4d4169a7fa 100644 --- a/x/distribution/client/cli/utils.go +++ b/x/distribution/client/cli/utils.go @@ -13,8 +13,8 @@ type ( Title string `json:"title" yaml:"title"` Description string `json:"description" yaml:"description"` Recipient sdk.AccAddress `json:"recipient" yaml:"recipient"` - Amount sdk.Coins `json:"amount" yaml:"amount"` - Deposit sdk.Coins `json:"deposit" yaml:"deposit"` + Amount string `json:"amount" yaml:"amount"` + Deposit string `json:"deposit" yaml:"deposit"` } ) diff --git a/x/params/client/cli/tx.go b/x/params/client/cli/tx.go index 67a890a51e..969d9052ea 100644 --- a/x/params/client/cli/tx.go +++ b/x/params/client/cli/tx.go @@ -53,12 +53,7 @@ Where proposal.json contains: "value": 105 } ], - "deposit": [ - { - "denom": "stake", - "amount": "10000" - } - ] + "deposit": "1000stake" } `, version.ClientName, @@ -77,7 +72,12 @@ Where proposal.json contains: from := cliCtx.GetFromAddress() content := paramproposal.NewParameterChangeProposal(proposal.Title, proposal.Description, proposal.Changes.ToParamChanges()) - msg := govtypes.NewMsgSubmitProposal(content, proposal.Deposit, from) + deposit, err := sdk.ParseCoins(proposal.Deposit) + if err != nil { + return err + } + + msg := govtypes.NewMsgSubmitProposal(content, deposit, from) if err := msg.ValidateBasic(); err != nil { return err } diff --git a/x/params/client/cli/tx_test.go b/x/params/client/cli/tx_test.go new file mode 100644 index 0000000000..0f3cb5c499 --- /dev/null +++ b/x/params/client/cli/tx_test.go @@ -0,0 +1,45 @@ +package cli + +import ( + "io/ioutil" + "testing" + + "github.com/stretchr/testify/require" + + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/x/params/client/utils" +) + +func TestParseProposal(t *testing.T) { + cdc := codec.New() + okJSON, err := ioutil.TempFile("", "proposal") + require.Nil(t, err, "unexpected error") + okJSON.WriteString(` +{ + "title": "Staking Param Change", + "description": "Update max validators", + "changes": [ + { + "subspace": "staking", + "key": "MaxValidators", + "value": 1 + } + ], + "deposit": "1000stake" +} +`) + + proposal, err := utils.ParseParamChangeProposalJSON(cdc, okJSON.Name()) + require.NoError(t, err) + + require.Equal(t, "Staking Param Change", proposal.Title) + require.Equal(t, "Update max validators", proposal.Description) + require.Equal(t, "1000stake", proposal.Deposit) + require.Equal(t, utils.ParamChangesJSON{ + { + Subspace: "staking", + Key: "MaxValidators", + Value: []byte{0x31}, + }, + }, proposal.Changes) +} diff --git a/x/params/client/utils/utils.go b/x/params/client/utils/utils.go index 231c5e2b06..2cac0b21a8 100644 --- a/x/params/client/utils/utils.go +++ b/x/params/client/utils/utils.go @@ -29,7 +29,7 @@ type ( Title string `json:"title" yaml:"title"` Description string `json:"description" yaml:"description"` Changes ParamChangesJSON `json:"changes" yaml:"changes"` - Deposit sdk.Coins `json:"deposit" yaml:"deposit"` + Deposit string `json:"deposit" yaml:"deposit"` } // ParamChangeProposalReq defines a parameter change proposal request body.