Skip to content

Commit

Permalink
x/gov: fix rest single vote and inactive proposal votes list queries (c…
Browse files Browse the repository at this point in the history
…osmos#6388)

* Fix single vote and votes list issues

* Add unmarshal json test
  • Loading branch information
akhilkumarpilli authored Jun 15, 2020
1 parent 24b9be0 commit 6336f95
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion x/gov/client/rest/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ func queryVoteHandlerFn(clientCtx client.Context) http.HandlerFunc {
// todo: Split this functionality into helper functions to remove the above
func queryVotesOnProposalHandlerFn(clientCtx client.Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
_, page, limit, err := rest.ParseHTTPArgsWithLimit(r, 0)
_, page, limit, err := rest.ParseHTTPArgs(r)
if rest.CheckBadRequestError(w, err) {
return
}
Expand Down
5 changes: 5 additions & 0 deletions x/gov/types/vote.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ func (vo *VoteOption) UnmarshalJSON(data []byte) error {
return err
}

if s == "" {
*vo = OptionEmpty
return nil
}

bz2, err := VoteOptionFromString(s)
if err != nil {
return err
Expand Down
36 changes: 36 additions & 0 deletions x/gov/types/vote_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package types

import (
"encoding/json"
"fmt"
"testing"

"github.com/stretchr/testify/require"
)

func TestVoteUnMarshalJSON(t *testing.T) {
tests := []struct {
option string
isError bool
}{
{"Yes", false},
{"No", false},
{"Abstain", false},
{"NoWithVeto", false},
{"", false},
{"misc", true},
}
for _, tt := range tests {
var vo VoteOption
data, err := json.Marshal(tt.option)
require.NoError(t, err)

err = vo.UnmarshalJSON(data)
if tt.isError {
require.Error(t, err)
require.EqualError(t, err, fmt.Sprintf("'%s' is not a valid vote option", tt.option))
} else {
require.NoError(t, err)
}
}
}

0 comments on commit 6336f95

Please sign in to comment.