Skip to content

Commit

Permalink
Merge PR #1627: ready-for-review: Gov modules enums marshalJSON to St…
Browse files Browse the repository at this point in the history
…ring
  • Loading branch information
cwgoes authored Jul 12, 2018
2 parents e9db4a8 + cba7fd7 commit 432c109
Show file tree
Hide file tree
Showing 11 changed files with 323 additions and 289 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ BREAKING CHANGES
* [lcd] Switch key creation output to return bech32
* [lcd] Removed shorthand CLI flags (`a`, `c`, `n`, `o`)
* [gaiad] genesis transactions now use bech32 addresses / pubkeys
* [gov] VoteStatus renamed to ProposalStatus
* [gov] VoteOption, ProposalType, and ProposalStatus all marshal to string form in JSON

DEPRECATED
* [cli] Deprecated `--name` flag in commands that send txs, in favor of `--from`
Expand Down
60 changes: 30 additions & 30 deletions client/lcd/lcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ func TestSubmitProposal(t *testing.T) {

// query proposal
proposal := getProposal(t, port, proposalID)
require.Equal(t, "Test", proposal.Title)
require.Equal(t, "Test", proposal.GetTitle())
}

func TestDeposit(t *testing.T) {
Expand All @@ -465,15 +465,15 @@ func TestDeposit(t *testing.T) {

// query proposal
proposal := getProposal(t, port, proposalID)
require.Equal(t, "Test", proposal.Title)
require.Equal(t, "Test", proposal.GetTitle())

// create SubmitProposal TX
resultTx = doDeposit(t, port, seed, name, password, addr, proposalID)
tests.WaitForHeight(resultTx.Height+1, port)

// query proposal
proposal = getProposal(t, port, proposalID)
require.True(t, proposal.TotalDeposit.IsEqual(sdk.Coins{sdk.NewCoin("steak", 10)}))
require.True(t, proposal.GetTotalDeposit().IsEqual(sdk.Coins{sdk.NewCoin("steak", 10)}))

// query deposit
deposit := getDeposit(t, port, proposalID, addr)
Expand All @@ -499,23 +499,23 @@ func TestVote(t *testing.T) {

// query proposal
proposal := getProposal(t, port, proposalID)
require.Equal(t, "Test", proposal.Title)
require.Equal(t, "Test", proposal.GetTitle())

// create SubmitProposal TX
resultTx = doDeposit(t, port, seed, name, password, addr, proposalID)
tests.WaitForHeight(resultTx.Height+1, port)

// query proposal
proposal = getProposal(t, port, proposalID)
require.Equal(t, gov.StatusToString(gov.StatusVotingPeriod), proposal.Status)
require.Equal(t, gov.StatusVotingPeriod, proposal.GetStatus())

// create SubmitProposal TX
resultTx = doVote(t, port, seed, name, password, addr, proposalID)
tests.WaitForHeight(resultTx.Height+1, port)

vote := getVote(t, port, proposalID, addr)
require.Equal(t, proposalID, vote.ProposalID)
require.Equal(t, gov.VoteOptionToString(gov.OptionYes), vote.Option)
require.Equal(t, gov.OptionYes, vote.Option)
}

func TestUnrevoke(t *testing.T) {
Expand Down Expand Up @@ -576,31 +576,31 @@ func TestProposalsQuery(t *testing.T) {

// Test query all proposals
proposals := getProposalsAll(t, port)
require.Equal(t, proposalID1, (proposals[0]).ProposalID)
require.Equal(t, proposalID2, (proposals[1]).ProposalID)
require.Equal(t, proposalID3, (proposals[2]).ProposalID)
require.Equal(t, proposalID1, (proposals[0]).GetProposalID())
require.Equal(t, proposalID2, (proposals[1]).GetProposalID())
require.Equal(t, proposalID3, (proposals[2]).GetProposalID())

// Test query deposited by addr1
proposals = getProposalsFilterDepositer(t, port, addr)
require.Equal(t, proposalID1, (proposals[0]).ProposalID)
require.Equal(t, proposalID1, (proposals[0]).GetProposalID())

// Test query deposited by addr2
proposals = getProposalsFilterDepositer(t, port, addr2)
require.Equal(t, proposalID2, (proposals[0]).ProposalID)
require.Equal(t, proposalID3, (proposals[1]).ProposalID)
require.Equal(t, proposalID2, (proposals[0]).GetProposalID())
require.Equal(t, proposalID3, (proposals[1]).GetProposalID())

// Test query voted by addr1
proposals = getProposalsFilterVoter(t, port, addr)
require.Equal(t, proposalID2, (proposals[0]).ProposalID)
require.Equal(t, proposalID3, (proposals[1]).ProposalID)
require.Equal(t, proposalID2, (proposals[0]).GetProposalID())
require.Equal(t, proposalID3, (proposals[1]).GetProposalID())

// Test query voted by addr2
proposals = getProposalsFilterVoter(t, port, addr2)
require.Equal(t, proposalID3, (proposals[0]).ProposalID)
require.Equal(t, proposalID3, (proposals[0]).GetProposalID())

// Test query voted and deposited by addr1
proposals = getProposalsFilterVoterDepositer(t, port, addr, addr)
require.Equal(t, proposalID2, (proposals[0]).ProposalID)
require.Equal(t, proposalID2, (proposals[0]).GetProposalID())
}

//_____________________________________________________________________________
Expand Down Expand Up @@ -838,68 +838,68 @@ func getValidators(t *testing.T, port string) []stakerest.StakeValidatorOutput {
return validators
}

func getProposal(t *testing.T, port string, proposalID int64) gov.ProposalRest {
func getProposal(t *testing.T, port string, proposalID int64) gov.Proposal {
res, body := Request(t, port, "GET", fmt.Sprintf("/gov/proposals/%d", proposalID), nil)
require.Equal(t, http.StatusOK, res.StatusCode, body)
var proposal gov.ProposalRest
var proposal gov.Proposal
err := cdc.UnmarshalJSON([]byte(body), &proposal)
require.Nil(t, err)
return proposal
}

func getDeposit(t *testing.T, port string, proposalID int64, depositerAddr sdk.AccAddress) gov.DepositRest {
func getDeposit(t *testing.T, port string, proposalID int64, depositerAddr sdk.AccAddress) gov.Deposit {
res, body := Request(t, port, "GET", fmt.Sprintf("/gov/proposals/%d/deposits/%s", proposalID, depositerAddr), nil)
require.Equal(t, http.StatusOK, res.StatusCode, body)
var deposit gov.DepositRest
var deposit gov.Deposit
err := cdc.UnmarshalJSON([]byte(body), &deposit)
require.Nil(t, err)
return deposit
}

func getVote(t *testing.T, port string, proposalID int64, voterAddr sdk.AccAddress) gov.VoteRest {
func getVote(t *testing.T, port string, proposalID int64, voterAddr sdk.AccAddress) gov.Vote {
res, body := Request(t, port, "GET", fmt.Sprintf("/gov/proposals/%d/votes/%s", proposalID, voterAddr), nil)
require.Equal(t, http.StatusOK, res.StatusCode, body)
var vote gov.VoteRest
var vote gov.Vote
err := cdc.UnmarshalJSON([]byte(body), &vote)
require.Nil(t, err)
return vote
}

func getProposalsAll(t *testing.T, port string) []gov.ProposalRest {
func getProposalsAll(t *testing.T, port string) []gov.Proposal {
res, body := Request(t, port, "GET", "/gov/proposals", nil)
require.Equal(t, http.StatusOK, res.StatusCode, body)

var proposals []gov.ProposalRest
var proposals []gov.Proposal
err := cdc.UnmarshalJSON([]byte(body), &proposals)
require.Nil(t, err)
return proposals
}

func getProposalsFilterDepositer(t *testing.T, port string, depositerAddr sdk.AccAddress) []gov.ProposalRest {
func getProposalsFilterDepositer(t *testing.T, port string, depositerAddr sdk.AccAddress) []gov.Proposal {
res, body := Request(t, port, "GET", fmt.Sprintf("/gov/proposals?depositer=%s", depositerAddr), nil)
require.Equal(t, http.StatusOK, res.StatusCode, body)

var proposals []gov.ProposalRest
var proposals []gov.Proposal
err := cdc.UnmarshalJSON([]byte(body), &proposals)
require.Nil(t, err)
return proposals
}

func getProposalsFilterVoter(t *testing.T, port string, voterAddr sdk.AccAddress) []gov.ProposalRest {
func getProposalsFilterVoter(t *testing.T, port string, voterAddr sdk.AccAddress) []gov.Proposal {
res, body := Request(t, port, "GET", fmt.Sprintf("/gov/proposals?voter=%s", voterAddr), nil)
require.Equal(t, http.StatusOK, res.StatusCode, body)

var proposals []gov.ProposalRest
var proposals []gov.Proposal
err := cdc.UnmarshalJSON([]byte(body), &proposals)
require.Nil(t, err)
return proposals
}

func getProposalsFilterVoterDepositer(t *testing.T, port string, voterAddr, depositerAddr sdk.AccAddress) []gov.ProposalRest {
func getProposalsFilterVoterDepositer(t *testing.T, port string, voterAddr, depositerAddr sdk.AccAddress) []gov.Proposal {
res, body := Request(t, port, "GET", fmt.Sprintf("/gov/proposals?depositer=%s&voter=%s", depositerAddr, voterAddr), nil)
require.Equal(t, http.StatusOK, res.StatusCode, body)

var proposals []gov.ProposalRest
var proposals []gov.Proposal
err := cdc.UnmarshalJSON([]byte(body), &proposals)
require.Nil(t, err)
return proposals
Expand Down
18 changes: 9 additions & 9 deletions cmd/gaia/cli_test/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,24 +183,24 @@ func TestGaiaCLISubmitProposal(t *testing.T) {
require.Equal(t, int64(45), fooAcc.GetCoins().AmountOf("steak").Int64())

proposal1 := executeGetProposal(t, fmt.Sprintf("gaiacli gov query-proposal --proposalID=1 --output=json %v", flags))
require.Equal(t, int64(1), proposal1.ProposalID)
require.Equal(t, gov.StatusToString(gov.StatusDepositPeriod), proposal1.Status)
require.Equal(t, int64(1), proposal1.GetProposalID())
require.Equal(t, gov.StatusDepositPeriod, proposal1.GetStatus())

executeWrite(t, fmt.Sprintf("gaiacli gov deposit %v --depositer=%s --deposit=10steak --proposalID=1 --from=foo", flags, fooAddr), pass)
tests.WaitForNextHeightTM(port)

fooAcc = executeGetAccount(t, fmt.Sprintf("gaiacli account %s %v", fooAddr, flags))
require.Equal(t, int64(35), fooAcc.GetCoins().AmountOf("steak").Int64())
proposal1 = executeGetProposal(t, fmt.Sprintf("gaiacli gov query-proposal --proposalID=1 --output=json %v", flags))
require.Equal(t, int64(1), proposal1.ProposalID)
require.Equal(t, gov.StatusToString(gov.StatusVotingPeriod), proposal1.Status)
require.Equal(t, int64(1), proposal1.GetProposalID())
require.Equal(t, gov.StatusVotingPeriod, proposal1.GetStatus())

executeWrite(t, fmt.Sprintf("gaiacli gov vote %v --proposalID=1 --voter=%s --option=Yes --from=foo", flags, fooAddr), pass)
tests.WaitForNextHeightTM(port)

vote := executeGetVote(t, fmt.Sprintf("gaiacli gov query-vote --proposalID=1 --voter=%s --output=json %v", fooAddr, flags))
require.Equal(t, int64(1), vote.ProposalID)
require.Equal(t, gov.VoteOptionToString(gov.OptionYes), vote.Option)
require.Equal(t, gov.OptionYes, vote.Option)
}

//___________________________________________________________________________________
Expand Down Expand Up @@ -288,18 +288,18 @@ func executeGetValidator(t *testing.T, cmdStr string) stake.Validator {
return validator
}

func executeGetProposal(t *testing.T, cmdStr string) gov.ProposalRest {
func executeGetProposal(t *testing.T, cmdStr string) gov.Proposal {
out := tests.ExecuteT(t, cmdStr)
var proposal gov.ProposalRest
var proposal gov.Proposal
cdc := app.MakeCodec()
err := cdc.UnmarshalJSON([]byte(out), &proposal)
require.NoError(t, err, "out %v\n, err %v", out, err)
return proposal
}

func executeGetVote(t *testing.T, cmdStr string) gov.VoteRest {
func executeGetVote(t *testing.T, cmdStr string) gov.Vote {
out := tests.ExecuteT(t, cmdStr)
var vote gov.VoteRest
var vote gov.Vote
cdc := app.MakeCodec()
err := cdc.UnmarshalJSON([]byte(out), &vote)
require.NoError(t, err, "out %v\n, err %v", out, err)
Expand Down
12 changes: 5 additions & 7 deletions x/gov/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func GetCmdSubmitProposal(cdc *wire.Codec) *cobra.Command {
return err
}

proposalType, err := gov.StringToProposalType(strProposalType)
proposalType, err := gov.ProposalTypeFromString(strProposalType)
if err != nil {
return err
}
Expand Down Expand Up @@ -145,7 +145,7 @@ func GetCmdVote(cdc *wire.Codec) *cobra.Command {

option := viper.GetString(flagOption)

byteVoteOption, err := gov.StringToVoteOption(option)
byteVoteOption, err := gov.VoteOptionFromString(option)
if err != nil {
return err
}
Expand All @@ -158,7 +158,7 @@ func GetCmdVote(cdc *wire.Codec) *cobra.Command {
return err
}

fmt.Printf("Vote[Voter:%s,ProposalID:%d,Option:%s]", bechVoter, msg.ProposalID, gov.VoteOptionToString(msg.Option))
fmt.Printf("Vote[Voter:%s,ProposalID:%d,Option:%s]", bechVoter, msg.ProposalID, msg.Option)

// build and sign the transaction, then broadcast to Tendermint
ctx := context.NewCoreContextFromViper().WithDecoder(authcmd.GetAccountDecoder(cdc))
Expand Down Expand Up @@ -195,8 +195,7 @@ func GetCmdQueryProposal(storeName string, cdc *wire.Codec) *cobra.Command {

var proposal gov.Proposal
cdc.MustUnmarshalBinary(res, &proposal)
proposalRest := gov.ProposalToRest(proposal)
output, err := wire.MarshalJSONIndent(cdc, proposalRest)
output, err := wire.MarshalJSONIndent(cdc, proposal)
if err != nil {
return err
}
Expand Down Expand Up @@ -232,8 +231,7 @@ func GetCmdQueryVote(storeName string, cdc *wire.Codec) *cobra.Command {

var vote gov.Vote
cdc.MustUnmarshalBinary(res, &vote)
voteRest := gov.VoteToRest(vote)
output, err := wire.MarshalJSONIndent(cdc, voteRest)
output, err := wire.MarshalJSONIndent(cdc, vote)
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit 432c109

Please sign in to comment.