x/gov: fix rest single vote and inactive proposal votes list queries (#6388)

* Fix single vote and votes list issues

* Add unmarshal json test
This commit is contained in:
Akhil Kumar P 2020-06-15 18:26:03 +05:30 committed by GitHub
parent 24b9be0ef8
commit 6336f95802
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 1 deletions

View File

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

View File

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

36
x/gov/types/vote_test.go Normal file
View File

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