github.com/cosmos/cosmos-sdk@v0.50.10/x/gov/client/utils/utils_test.go (about) 1 package utils_test 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/require" 7 8 "github.com/cosmos/cosmos-sdk/x/gov/client/utils" 9 ) 10 11 func TestNormalizeWeightedVoteOptions(t *testing.T) { 12 cases := map[string]struct { 13 options string 14 normalized string 15 }{ 16 "simple Yes": { 17 options: "Yes", 18 normalized: "VOTE_OPTION_YES=1", 19 }, 20 "simple yes": { 21 options: "yes", 22 normalized: "VOTE_OPTION_YES=1", 23 }, 24 "formal yes": { 25 options: "yes=1", 26 normalized: "VOTE_OPTION_YES=1", 27 }, 28 "half yes half no": { 29 options: "yes=0.5,no=0.5", 30 normalized: "VOTE_OPTION_YES=0.5,VOTE_OPTION_NO=0.5", 31 }, 32 "3 options": { 33 options: "Yes=0.5,No=0.4,NoWithVeto=0.1", 34 normalized: "VOTE_OPTION_YES=0.5,VOTE_OPTION_NO=0.4,VOTE_OPTION_NO_WITH_VETO=0.1", 35 }, 36 "zero weight option": { 37 options: "Yes=0.5,No=0.5,NoWithVeto=0", 38 normalized: "VOTE_OPTION_YES=0.5,VOTE_OPTION_NO=0.5,VOTE_OPTION_NO_WITH_VETO=0", 39 }, 40 "minus weight option": { 41 options: "Yes=0.5,No=0.6,NoWithVeto=-0.1", 42 normalized: "VOTE_OPTION_YES=0.5,VOTE_OPTION_NO=0.6,VOTE_OPTION_NO_WITH_VETO=-0.1", 43 }, 44 "empty options": { 45 options: "", 46 normalized: "=1", 47 }, 48 "not available option": { 49 options: "Yessss=1", 50 normalized: "Yessss=1", 51 }, 52 } 53 54 for _, tc := range cases { 55 normalized := utils.NormalizeWeightedVoteOptions(tc.options) 56 require.Equal(t, normalized, tc.normalized) 57 } 58 } 59 60 func TestNormalizeProposalStatus(t *testing.T) { 61 type args struct { 62 status string 63 } 64 tests := []struct { 65 name string 66 args args 67 want string 68 }{ 69 {"invalid", args{"unknown"}, "unknown"}, 70 {"deposit_period", args{"deposit_period"}, "PROPOSAL_STATUS_DEPOSIT_PERIOD"}, 71 {"DepositPeriod", args{"DepositPeriod"}, "PROPOSAL_STATUS_DEPOSIT_PERIOD"}, 72 {"voting_period", args{"deposit_period"}, "PROPOSAL_STATUS_DEPOSIT_PERIOD"}, 73 {"VotingPeriod", args{"DepositPeriod"}, "PROPOSAL_STATUS_DEPOSIT_PERIOD"}, 74 {"passed", args{"passed"}, "PROPOSAL_STATUS_PASSED"}, 75 {"Passed", args{"Passed"}, "PROPOSAL_STATUS_PASSED"}, 76 {"Rejected", args{"Rejected"}, "PROPOSAL_STATUS_REJECTED"}, 77 {"rejected", args{"rejected"}, "PROPOSAL_STATUS_REJECTED"}, 78 } 79 for _, tt := range tests { 80 t.Run(tt.name, func(t *testing.T) { 81 require.Equal(t, tt.want, utils.NormalizeProposalStatus(tt.args.status)) 82 }) 83 } 84 }