-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
x/gov: fix NormalizeProposalType() return values (#8808)
Closes: #8806 (cherry picked from commit be23295) # Conflicts: # x/gov/client/rest/grpc_query_test.go # x/gov/client/utils/utils_test.go
- Loading branch information
Alessio Treglia
authored and
mergify-bot
committed
Mar 8, 2021
1 parent
a8ace5a
commit 947f8ec
Showing
5 changed files
with
170 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package utils_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/cosmos/cosmos-sdk/x/gov/client/utils" | ||
) | ||
|
||
func TestNormalizeWeightedVoteOptions(t *testing.T) { | ||
cases := map[string]struct { | ||
options string | ||
normalized string | ||
}{ | ||
"simple Yes": { | ||
options: "Yes", | ||
normalized: "VOTE_OPTION_YES=1", | ||
}, | ||
"simple yes": { | ||
options: "yes", | ||
normalized: "VOTE_OPTION_YES=1", | ||
}, | ||
"formal yes": { | ||
options: "yes=1", | ||
normalized: "VOTE_OPTION_YES=1", | ||
}, | ||
"half yes half no": { | ||
options: "yes=0.5,no=0.5", | ||
normalized: "VOTE_OPTION_YES=0.5,VOTE_OPTION_NO=0.5", | ||
}, | ||
"3 options": { | ||
options: "Yes=0.5,No=0.4,NoWithVeto=0.1", | ||
normalized: "VOTE_OPTION_YES=0.5,VOTE_OPTION_NO=0.4,VOTE_OPTION_NO_WITH_VETO=0.1", | ||
}, | ||
"zero weight option": { | ||
options: "Yes=0.5,No=0.5,NoWithVeto=0", | ||
normalized: "VOTE_OPTION_YES=0.5,VOTE_OPTION_NO=0.5,VOTE_OPTION_NO_WITH_VETO=0", | ||
}, | ||
"minus weight option": { | ||
options: "Yes=0.5,No=0.6,NoWithVeto=-0.1", | ||
normalized: "VOTE_OPTION_YES=0.5,VOTE_OPTION_NO=0.6,VOTE_OPTION_NO_WITH_VETO=-0.1", | ||
}, | ||
"empty options": { | ||
options: "", | ||
normalized: "=1", | ||
}, | ||
"not available option": { | ||
options: "Yessss=1", | ||
normalized: "Yessss=1", | ||
}, | ||
} | ||
|
||
for _, tc := range cases { | ||
normalized := utils.NormalizeWeightedVoteOptions(tc.options) | ||
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)) | ||
}) | ||
} | ||
} |