refactor parsing to use unified version

This commit is contained in:
Jonathan Gimeno 2020-03-11 17:45:02 +01:00
parent 7b338c84dc
commit 34e22fbcb8
4 changed files with 54 additions and 3 deletions

View File

@ -24,7 +24,8 @@ func parseSubmitProposalFlags() (*proposal, error) {
for _, flag := range ProposalFlags {
if viper.GetString(flag) != "" {
return nil, fmt.Errorf("--%s flag provided alongside --proposal, which is a noop", flag)
return nil, fmt.Errorf(
"--%s flag provided alongside --proposal, which is a noop", flag)
}
}

View File

@ -77,7 +77,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
}

View File

@ -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)
}

View File

@ -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.