forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: x/gov migrations (cosmos#13045)
* fix migration tests * add change log * Update CHANGELOG.md * review changes * review changes
- Loading branch information
Showing
6 changed files
with
124 additions
and
19 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,25 @@ | ||
package v4 | ||
|
||
import ( | ||
v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" | ||
) | ||
|
||
func MigrateJSON(oldState *v1.GenesisState) (*v1.GenesisState, error) { | ||
params := v1.NewParams( | ||
oldState.DepositParams.MinDeposit, | ||
*oldState.DepositParams.MaxDepositPeriod, | ||
*oldState.VotingParams.VotingPeriod, | ||
oldState.TallyParams.Quorum, | ||
oldState.TallyParams.Threshold, | ||
oldState.TallyParams.VetoThreshold, | ||
v1.DefaultParams().MinInitialDepositRatio, | ||
) | ||
|
||
return &v1.GenesisState{ | ||
StartingProposalId: oldState.StartingProposalId, | ||
Deposits: oldState.Deposits, | ||
Votes: oldState.Votes, | ||
Proposals: oldState.Proposals, | ||
Params: ¶ms, | ||
}, nil | ||
} |
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,64 @@ | ||
package v4_test | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/cosmos/cosmos-sdk/client" | ||
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" | ||
"github.com/cosmos/cosmos-sdk/x/gov" | ||
v4 "github.com/cosmos/cosmos-sdk/x/gov/migrations/v4" | ||
v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestMigrateJSON(t *testing.T) { | ||
encodingConfig := moduletestutil.MakeTestEncodingConfig(gov.AppModuleBasic{}) | ||
clientCtx := client.Context{}. | ||
WithInterfaceRegistry(encodingConfig.InterfaceRegistry). | ||
WithTxConfig(encodingConfig.TxConfig). | ||
WithCodec(encodingConfig.Codec) | ||
|
||
govGenState := v1.DefaultGenesisState() | ||
|
||
migrated, err := v4.MigrateJSON(govGenState) | ||
require.NoError(t, err) | ||
|
||
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: | ||
// - Proposals use MsgExecLegacyContent | ||
expected := `{ | ||
"deposit_params": null, | ||
"deposits": [], | ||
"params": { | ||
"max_deposit_period": "172800s", | ||
"min_deposit": [ | ||
{ | ||
"amount": "10000000", | ||
"denom": "stake" | ||
} | ||
], | ||
"min_initial_deposit_ratio": "0.000000000000000000", | ||
"quorum": "0.334000000000000000", | ||
"threshold": "0.500000000000000000", | ||
"veto_threshold": "0.334000000000000000", | ||
"voting_period": "172800s" | ||
}, | ||
"proposals": [], | ||
"starting_proposal_id": "1", | ||
"tally_params": null, | ||
"votes": [], | ||
"voting_params": null | ||
}` | ||
|
||
require.Equal(t, expected, string(indentedBz)) | ||
} |