Skip to content

Commit

Permalink
Merge PR cosmos#5790: Standarize the representation of Governance par…
Browse files Browse the repository at this point in the history
…am changes on cli requests.
  • Loading branch information
alexanderbez authored Mar 12, 2020
2 parents 39f416f + 50c0aec commit 241894a
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 24 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
27 changes: 13 additions & 14 deletions x/distribution/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
}
Expand Down
30 changes: 30 additions & 0 deletions x/distribution/client/cli/tx_test.go
Original file line number Diff line number Diff line change
@@ -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"

Expand Down Expand Up @@ -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)
}
4 changes: 2 additions & 2 deletions x/distribution/client/cli/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
)

Expand Down
14 changes: 7 additions & 7 deletions x/params/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,7 @@ Where proposal.json contains:
"value": 105
}
],
"deposit": [
{
"denom": "stake",
"amount": "10000"
}
]
"deposit": "1000stake"
}
`,
version.ClientName,
Expand All @@ -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
}
Expand Down
45 changes: 45 additions & 0 deletions x/params/client/cli/tx_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
2 changes: 1 addition & 1 deletion x/params/client/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 241894a

Please sign in to comment.