-
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.
refactor(x/gov): swap vote alias (#19718)
- Loading branch information
1 parent
fea88d1
commit d808ef8
Showing
6 changed files
with
148 additions
and
87 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,61 @@ | ||
package v1_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
v1 "cosmossdk.io/x/gov/types/v1" | ||
|
||
codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" | ||
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" | ||
) | ||
|
||
func TestVoteAlias(t *testing.T) { | ||
cdc := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}).Codec | ||
|
||
testCases := []struct { | ||
name string | ||
input string | ||
expected v1.MsgVote | ||
expectedErrMsg string | ||
}{ | ||
{ | ||
name: "valid vote", | ||
input: `{"proposal_id":"1","voter":"cosmos1qperwt9wrnkg5k9e5gzfgjppzpqhyav5j24d66","option":"VOTE_OPTION_YES","metadata":"test"}`, | ||
expected: v1.MsgVote{ | ||
ProposalId: 1, | ||
Voter: "cosmos1qperwt9wrnkg5k9e5gzfgjppzpqhyav5j24d66", | ||
Option: v1.VoteOption_VOTE_OPTION_YES, | ||
Metadata: "test", | ||
}, | ||
}, | ||
{ | ||
name: "valid vote alias", | ||
input: `{"proposal_id":"1","voter":"cosmos1qperwt9wrnkg5k9e5gzfgjppzpqhyav5j24d66","option":"VOTE_OPTION_ONE","metadata":"test"}`, | ||
expected: v1.MsgVote{ | ||
ProposalId: 1, | ||
Voter: "cosmos1qperwt9wrnkg5k9e5gzfgjppzpqhyav5j24d66", | ||
Option: v1.VoteOption_VOTE_OPTION_ONE, | ||
Metadata: "test", | ||
}, | ||
}, | ||
{ | ||
name: "invalid vote", | ||
input: `{"proposal_id":"1","voter":"cosmos1qperwt9wrnkg5k9e5gzfgjppzpqhyav5j24d66","option":"VOTE_OPTION_HELLO","metadata":"test"}`, | ||
expectedErrMsg: "unknown value \"VOTE_OPTION_HELLO\" for enum cosmos.gov.v1.VoteOption", | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
vote := &v1.MsgVote{} | ||
err := cdc.UnmarshalJSON([]byte(tc.input), vote) | ||
if tc.expectedErrMsg != "" { | ||
require.ErrorContains(t, err, tc.expectedErrMsg) | ||
} else { | ||
require.NoError(t, err) | ||
} | ||
}) | ||
} | ||
} |