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:
parent
24b9be0ef8
commit
6336f95802
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue