parent
a65f838eb1
commit
be23295bdf
|
@ -431,6 +431,14 @@ func (s *IntegrationTestSuite) TestCmdGetProposals() {
|
||||||
},
|
},
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"get proposals with invalid status",
|
||||||
|
[]string{
|
||||||
|
"--status=unknown",
|
||||||
|
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
|
||||||
|
},
|
||||||
|
true,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
|
|
|
@ -122,6 +122,7 @@ func (s *IntegrationTestSuite) TestGetProposalsGRPC() {
|
||||||
name string
|
name string
|
||||||
url string
|
url string
|
||||||
headers map[string]string
|
headers map[string]string
|
||||||
|
wantNumProposals int
|
||||||
expErr bool
|
expErr bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
|
@ -130,12 +131,21 @@ func (s *IntegrationTestSuite) TestGetProposalsGRPC() {
|
||||||
map[string]string{
|
map[string]string{
|
||||||
grpctypes.GRPCBlockHeightHeader: "1",
|
grpctypes.GRPCBlockHeightHeader: "1",
|
||||||
},
|
},
|
||||||
|
0,
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"valid request",
|
"valid request",
|
||||||
fmt.Sprintf("%s/cosmos/gov/v1beta1/proposals", val.APIAddress),
|
fmt.Sprintf("%s/cosmos/gov/v1beta1/proposals", val.APIAddress),
|
||||||
map[string]string{},
|
map[string]string{},
|
||||||
|
3,
|
||||||
|
false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"valid request with filter by status",
|
||||||
|
fmt.Sprintf("%s/cosmos/gov/v1beta1/proposals?proposal_status=1", val.APIAddress),
|
||||||
|
map[string]string{},
|
||||||
|
1,
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -153,7 +163,7 @@ func (s *IntegrationTestSuite) TestGetProposalsGRPC() {
|
||||||
s.Require().Empty(proposals.Proposals)
|
s.Require().Empty(proposals.Proposals)
|
||||||
} else {
|
} else {
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
s.Require().Len(proposals.Proposals, 3)
|
s.Require().Len(proposals.Proposals, tc.wantNumProposals)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,62 @@ import (
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func (s *IntegrationTestSuite) TestLegacyGetAllProposals() {
|
||||||
|
val := s.network.Validators[0]
|
||||||
|
|
||||||
|
testCases := []struct {
|
||||||
|
name string
|
||||||
|
url string
|
||||||
|
numProposals int
|
||||||
|
expErr bool
|
||||||
|
expErrMsg string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
"get all existing proposals",
|
||||||
|
fmt.Sprintf("%s/gov/proposals", val.APIAddress),
|
||||||
|
3, false, "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"get proposals in deposit period",
|
||||||
|
fmt.Sprintf("%s/gov/proposals?status=deposit_period", val.APIAddress),
|
||||||
|
1, false, "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"get proposals in voting period",
|
||||||
|
fmt.Sprintf("%s/gov/proposals?status=voting_period", val.APIAddress),
|
||||||
|
2, false, "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"wrong status parameter",
|
||||||
|
fmt.Sprintf("%s/gov/proposals?status=invalidstatus", val.APIAddress),
|
||||||
|
0, true, "'invalidstatus' is not a valid proposal status",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range testCases {
|
||||||
|
tc := tc
|
||||||
|
s.Run(tc.name, func() {
|
||||||
|
respJSON, err := rest.GetRequest(tc.url)
|
||||||
|
s.Require().NoError(err)
|
||||||
|
|
||||||
|
if tc.expErr {
|
||||||
|
var errResp rest.ErrorResponse
|
||||||
|
s.Require().NoError(val.ClientCtx.LegacyAmino.UnmarshalJSON(respJSON, &errResp))
|
||||||
|
s.Require().Equal(errResp.Error, tc.expErrMsg)
|
||||||
|
} else {
|
||||||
|
var resp = rest.ResponseWithHeight{}
|
||||||
|
err = val.ClientCtx.LegacyAmino.UnmarshalJSON(respJSON, &resp)
|
||||||
|
s.Require().NoError(err)
|
||||||
|
|
||||||
|
// Check results.
|
||||||
|
var proposals types.Proposals
|
||||||
|
s.Require().NoError(val.ClientCtx.LegacyAmino.UnmarshalJSON(resp.Result, &proposals))
|
||||||
|
s.Require().Equal(tc.numProposals, len(proposals))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (s *IntegrationTestSuite) TestLegacyGetVote() {
|
func (s *IntegrationTestSuite) TestLegacyGetVote() {
|
||||||
val := s.network.Validators[0]
|
val := s.network.Validators[0]
|
||||||
voterAddressBech32 := val.Address.String()
|
voterAddressBech32 := val.Address.String()
|
||||||
|
|
|
@ -55,13 +55,13 @@ func NormalizeProposalType(proposalType string) string {
|
||||||
func NormalizeProposalStatus(status string) string {
|
func NormalizeProposalStatus(status string) string {
|
||||||
switch status {
|
switch status {
|
||||||
case "DepositPeriod", "deposit_period":
|
case "DepositPeriod", "deposit_period":
|
||||||
return "DepositPeriod"
|
return types.StatusDepositPeriod.String()
|
||||||
case "VotingPeriod", "voting_period":
|
case "VotingPeriod", "voting_period":
|
||||||
return "VotingPeriod"
|
return types.StatusVotingPeriod.String()
|
||||||
case "Passed", "passed":
|
case "Passed", "passed":
|
||||||
return "Passed"
|
return types.StatusPassed.String()
|
||||||
case "Rejected", "rejected":
|
case "Rejected", "rejected":
|
||||||
return "Rejected"
|
return types.StatusRejected.String()
|
||||||
default:
|
default:
|
||||||
return status
|
return status
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
package utils
|
package utils_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
|
"github.com/cosmos/cosmos-sdk/x/gov/client/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNormalizeWeightedVoteOptions(t *testing.T) {
|
func TestNormalizeWeightedVoteOptions(t *testing.T) {
|
||||||
|
@ -50,7 +52,33 @@ func TestNormalizeWeightedVoteOptions(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range cases {
|
for _, tc := range cases {
|
||||||
normalized := NormalizeWeightedVoteOptions(tc.options)
|
normalized := utils.NormalizeWeightedVoteOptions(tc.options)
|
||||||
require.Equal(t, normalized, tc.normalized)
|
require.Equal(t, normalized, tc.normalized)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestNormalizeProposalStatus(t *testing.T) {
|
||||||
|
type args struct {
|
||||||
|
status string
|
||||||
|
}
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
args args
|
||||||
|
want string
|
||||||
|
}{
|
||||||
|
{"invalid", args{"unknown"}, "unknown"},
|
||||||
|
{"deposit_period", args{"deposit_period"}, "PROPOSAL_STATUS_DEPOSIT_PERIOD"},
|
||||||
|
{"DepositPeriod", args{"DepositPeriod"}, "PROPOSAL_STATUS_DEPOSIT_PERIOD"},
|
||||||
|
{"voting_period", args{"deposit_period"}, "PROPOSAL_STATUS_DEPOSIT_PERIOD"},
|
||||||
|
{"VotingPeriod", args{"DepositPeriod"}, "PROPOSAL_STATUS_DEPOSIT_PERIOD"},
|
||||||
|
{"passed", args{"passed"}, "PROPOSAL_STATUS_PASSED"},
|
||||||
|
{"Passed", args{"Passed"}, "PROPOSAL_STATUS_PASSED"},
|
||||||
|
{"Rejected", args{"Rejected"}, "PROPOSAL_STATUS_REJECTED"},
|
||||||
|
{"rejected", args{"rejected"}, "PROPOSAL_STATUS_REJECTED"},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
require.Equal(t, tt.want, utils.NormalizeProposalStatus(tt.args.status))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue