refactor cli tx for distribution param change request

This commit is contained in:
Jonathan Gimeno 2020-03-11 18:03:47 +01:00
parent 34e22fbcb8
commit 36554e73e2
3 changed files with 43 additions and 4 deletions

View File

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

View File

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

View File

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