## Description Closes: #12495 --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/main/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable)
126 lines
3.1 KiB
Go
126 lines
3.1 KiB
Go
package v2_test
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/cosmos/cosmos-sdk/client"
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
|
|
v2 "github.com/cosmos/cosmos-sdk/x/gov/migrations/v2"
|
|
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
|
)
|
|
|
|
func TestMigrateJSON(t *testing.T) {
|
|
encodingConfig := moduletestutil.MakeTestEncodingConfig()
|
|
clientCtx := client.Context{}.
|
|
WithInterfaceRegistry(encodingConfig.InterfaceRegistry).
|
|
WithTxConfig(encodingConfig.TxConfig).
|
|
WithCodec(encodingConfig.Codec)
|
|
|
|
voter, err := sdk.AccAddressFromBech32("cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh")
|
|
require.NoError(t, err)
|
|
govGenState := &v1beta1.GenesisState{
|
|
Votes: v1beta1.Votes{
|
|
v1beta1.Vote{ProposalId: 1, Voter: voter.String(), Option: v1beta1.OptionAbstain},
|
|
v1beta1.Vote{ProposalId: 2, Voter: voter.String(), Option: v1beta1.OptionEmpty},
|
|
v1beta1.Vote{ProposalId: 3, Voter: voter.String(), Option: v1beta1.OptionNo},
|
|
v1beta1.Vote{ProposalId: 4, Voter: voter.String(), Option: v1beta1.OptionNoWithVeto},
|
|
v1beta1.Vote{ProposalId: 5, Voter: voter.String(), Option: v1beta1.OptionYes},
|
|
},
|
|
}
|
|
|
|
migrated := v2.MigrateJSON(govGenState)
|
|
|
|
bz, err := clientCtx.Codec.MarshalJSON(migrated)
|
|
require.NoError(t, err)
|
|
|
|
// Indent the JSON bz correctly.
|
|
var jsonObj map[string]interface{}
|
|
err = json.Unmarshal(bz, &jsonObj)
|
|
require.NoError(t, err)
|
|
indentedBz, err := json.MarshalIndent(jsonObj, "", "\t")
|
|
require.NoError(t, err)
|
|
|
|
// Make sure about:
|
|
// - Votes are all ADR-037 weighted votes with weight 1.
|
|
expected := `{
|
|
"deposit_params": {
|
|
"max_deposit_period": "0s",
|
|
"min_deposit": []
|
|
},
|
|
"deposits": [],
|
|
"proposals": [],
|
|
"starting_proposal_id": "0",
|
|
"tally_params": {
|
|
"quorum": "0",
|
|
"threshold": "0",
|
|
"veto_threshold": "0"
|
|
},
|
|
"votes": [
|
|
{
|
|
"option": "VOTE_OPTION_UNSPECIFIED",
|
|
"options": [
|
|
{
|
|
"option": "VOTE_OPTION_ABSTAIN",
|
|
"weight": "1.000000000000000000"
|
|
}
|
|
],
|
|
"proposal_id": "1",
|
|
"voter": "cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh"
|
|
},
|
|
{
|
|
"option": "VOTE_OPTION_UNSPECIFIED",
|
|
"options": [
|
|
{
|
|
"option": "VOTE_OPTION_UNSPECIFIED",
|
|
"weight": "1.000000000000000000"
|
|
}
|
|
],
|
|
"proposal_id": "2",
|
|
"voter": "cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh"
|
|
},
|
|
{
|
|
"option": "VOTE_OPTION_UNSPECIFIED",
|
|
"options": [
|
|
{
|
|
"option": "VOTE_OPTION_NO",
|
|
"weight": "1.000000000000000000"
|
|
}
|
|
],
|
|
"proposal_id": "3",
|
|
"voter": "cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh"
|
|
},
|
|
{
|
|
"option": "VOTE_OPTION_UNSPECIFIED",
|
|
"options": [
|
|
{
|
|
"option": "VOTE_OPTION_NO_WITH_VETO",
|
|
"weight": "1.000000000000000000"
|
|
}
|
|
],
|
|
"proposal_id": "4",
|
|
"voter": "cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh"
|
|
},
|
|
{
|
|
"option": "VOTE_OPTION_UNSPECIFIED",
|
|
"options": [
|
|
{
|
|
"option": "VOTE_OPTION_YES",
|
|
"weight": "1.000000000000000000"
|
|
}
|
|
],
|
|
"proposal_id": "5",
|
|
"voter": "cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh"
|
|
}
|
|
],
|
|
"voting_params": {
|
|
"voting_period": "0s"
|
|
}
|
|
}`
|
|
|
|
require.Equal(t, expected, string(indentedBz))
|
|
}
|