Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 0.43 CLI JSON migrate command #8880

Merged
merged 8 commits into from
Mar 22, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions x/genutil/client/cli/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
v038 "github.com/cosmos/cosmos-sdk/x/genutil/legacy/v038"
v039 "github.com/cosmos/cosmos-sdk/x/genutil/legacy/v039"
v040 "github.com/cosmos/cosmos-sdk/x/genutil/legacy/v040"
v043 "github.com/cosmos/cosmos-sdk/x/genutil/legacy/v043"
"github.com/cosmos/cosmos-sdk/x/genutil/types"
)

Expand All @@ -28,9 +29,10 @@ const flagGenesisTime = "genesis-time"
// Ref: https://github.com/cosmos/cosmos-sdk/issues/5041
var migrationMap = types.MigrationMap{
"v0.36": v036.Migrate,
"v0.38": v038.Migrate, // NOTE: v0.37 and v0.38 are genesis compatible
"v0.38": v038.Migrate, // NOTE: v0.37 and v0.38 are genesis compatible.
"v0.39": v039.Migrate,
"v0.40": v040.Migrate,
"v0.40": v040.Migrate, // NOTE: v0.40, v0.41 and v0.42 are genesis compatible.
amaury1093 marked this conversation as resolved.
Show resolved Hide resolved
"v0.43": v043.Migrate,
}

// GetMigrationCallback returns a MigrationCallback for a given version.
Expand Down Expand Up @@ -131,7 +133,7 @@ $ %s migrate v0.36 /path/to/genesis.json --chain-id=cosmoshub-3 --genesis-time=2
return errors.Wrap(err, "failed to sort JSON genesis doc")
}

fmt.Println(string(sortedBz))
cmd.Println(string(sortedBz))
return nil
},
}
Expand Down
20 changes: 13 additions & 7 deletions x/genutil/client/cli/migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,35 +25,41 @@ func (s *IntegrationTestSuite) TestMigrateGenesis() {
target string
expErr bool
expErrMsg string
posttests func(jsonOut string)
amaury1093 marked this conversation as resolved.
Show resolved Hide resolved
}{
{
"migrate to 0.36",
"migrate 0.34 to 0.36",
`{"chain_id":"test","app_state":{}}`,
"v0.36",
false, "",
false, "", func(_ string) {},
},
{
"exported 0.37 genesis file",
"migrate 0.37 to 0.40",
v037Exported,
"v0.40",
true, "Make sure that you have correctly migrated all Tendermint consensus params",
true, "Make sure that you have correctly migrated all Tendermint consensus params", func(_ string) {},
},
{
"valid 0.40 genesis file",
"migrate 0.40 to 0.43",
v040Valid,
"v0.40",
"v0.43",
false, "",
func(jsonOut string) {
// Make sure the json output contains the ADR-037 gov weighted votes.
s.Require().Contains(jsonOut, "\"weight\":\"1.000000000000000000\"")
},
},
}

for _, tc := range testCases {
s.Run(tc.name, func() {
genesisFile := testutil.WriteToNewTempFile(s.T(), tc.genesis)
_, err := clitestutil.ExecTestCLICmd(val0.ClientCtx, cli.MigrateGenesisCmd(), []string{tc.target, genesisFile.Name()})
jsonOutput, err := clitestutil.ExecTestCLICmd(val0.ClientCtx, cli.MigrateGenesisCmd(), []string{tc.target, genesisFile.Name()})
if tc.expErr {
s.Require().Contains(err.Error(), tc.expErrMsg)
} else {
s.Require().NoError(err)
tc.posttests(jsonOutput.String())
}
})
}
Expand Down
18 changes: 17 additions & 1 deletion x/genutil/client/cli/validate_genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,23 @@ var v037Exported = `{
// An example exported genesis file that's 0.40 compatible.
var v040Valid = `{
"app_hash": "",
"app_state": {},
"app_state": {
"gov": {
"starting_proposal_id": "0",
"deposits": [],
"votes": [
{
"proposal_id": "5",
"voter": "cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh",
"option": "VOTE_OPTION_YES"
}
],
"proposals": [],
"deposit_params": { "min_deposit": [], "max_deposit_period": "0s" },
"voting_params": { "voting_period": "0s" },
"tally_params": { "quorum": "0", "threshold": "0", "veto_threshold": "0" }
}
},
"chain_id": "test",
"consensus_params": {
"block": {
Expand Down
27 changes: 27 additions & 0 deletions x/genutil/legacy/v043/migrate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package v043

import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/x/genutil/types"
v040gov "github.com/cosmos/cosmos-sdk/x/gov/legacy/v040"
v043gov "github.com/cosmos/cosmos-sdk/x/gov/legacy/v043"
)

// Migrate migrates exported state from v0.40 to a v0.43 genesis state.
func Migrate(appState types.AppMap, clientCtx client.Context) types.AppMap {
// Migrate x/gov.
if appState[v040gov.ModuleName] != nil {
// unmarshal relative source genesis application state
var oldGovState v040gov.GenesisState
amaury1093 marked this conversation as resolved.
Show resolved Hide resolved
clientCtx.JSONMarshaler.MustUnmarshalJSON(appState[v040gov.ModuleName], &oldGovState)

// delete deprecated x/gov genesis state
delete(appState, v040gov.ModuleName)

// Migrate relative source genesis application state and marshal it into
// the respective key.
appState[v043gov.ModuleName] = clientCtx.JSONMarshaler.MustMarshalJSON(v043gov.MigrateJSON(&oldGovState))
}

return appState
}
Loading