Skip to content

Commit

Permalink
chore: fix migration paths (cosmos#12579)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderbez authored Jul 14, 2022
1 parent 01b4a42 commit 934b2b8
Show file tree
Hide file tree
Showing 18 changed files with 63 additions and 71 deletions.
10 changes: 4 additions & 6 deletions x/auth/keeper/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ package keeper
import (
"github.com/gogo/protobuf/grpc"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/exported"
v043 "github.com/cosmos/cosmos-sdk/x/auth/migrations/v043"
v046 "github.com/cosmos/cosmos-sdk/x/auth/migrations/v046"

"github.com/cosmos/cosmos-sdk/x/auth/exported"
v4 "github.com/cosmos/cosmos-sdk/x/auth/migrations/v4"
"github.com/cosmos/cosmos-sdk/x/auth/types"

sdk "github.com/cosmos/cosmos-sdk/types"
v2 "github.com/cosmos/cosmos-sdk/x/auth/migrations/v2"
)

// Migrator is a struct for handling in-place store migrations.
Expand Down Expand Up @@ -58,7 +56,7 @@ func (m Migrator) Migrate2to3(ctx sdk.Context) error {
// and managed by the x/params modules and stores them directly into the x/auth
// module state.
func (m Migrator) Migrate3to4(ctx sdk.Context) error {
return v2.Migrate(ctx, ctx.KVStore(m.keeper.storeKey), m.legacySubspace, m.keeper.cdc)
return v4.Migrate(ctx, ctx.KVStore(m.keeper.storeKey), m.legacySubspace, m.keeper.cdc)
}

// V45_SetAccount implements V45_SetAccount
Expand Down
9 changes: 4 additions & 5 deletions x/auth/migrations/v043/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,19 @@ import (
"github.com/stretchr/testify/require"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"

bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"

"github.com/cosmos/cosmos-sdk/testutil"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
sdk "github.com/cosmos/cosmos-sdk/types"
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
"github.com/cosmos/cosmos-sdk/x/auth"
authexported "github.com/cosmos/cosmos-sdk/x/auth/exported"
"github.com/cosmos/cosmos-sdk/x/auth/keeper"
v2 "github.com/cosmos/cosmos-sdk/x/auth/migrations/v2"
v4 "github.com/cosmos/cosmos-sdk/x/auth/migrations/v4"
authtestutil "github.com/cosmos/cosmos-sdk/x/auth/testutil"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/auth/vesting/exported"
"github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
"github.com/cosmos/cosmos-sdk/x/staking"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
Expand All @@ -43,7 +42,7 @@ func TestMigrateVestingAccounts(t *testing.T) {
encCfg := moduletestutil.MakeTestEncodingConfig(auth.AppModuleBasic{})
cdc := encCfg.Codec

storeKey := sdk.NewKVStoreKey(v2.ModuleName)
storeKey := sdk.NewKVStoreKey(v4.ModuleName)
tKey := sdk.NewTransientStoreKey("transient_test")
ctx := testutil.DefaultContext(storeKey, tKey)
store := ctx.KVStore(storeKey)
Expand All @@ -62,7 +61,7 @@ func TestMigrateVestingAccounts(t *testing.T) {
require.NoError(t, err)

legacySubspace := newMockSubspace(authtypes.DefaultParams())
require.NoError(t, v2.Migrate(ctx, store, legacySubspace, cdc))
require.NoError(t, v4.Migrate(ctx, store, legacySubspace, cdc))

ctx = app.BaseApp.NewContext(false, tmproto.Header{Time: time.Now()})
stakingKeeper.SetParams(ctx, stakingtypes.DefaultParams())
Expand Down
18 changes: 9 additions & 9 deletions x/auth/migrations/v046/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ import (
"testing"
"time"

"github.com/stretchr/testify/require"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"

"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
"github.com/cosmos/cosmos-sdk/testutil"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
sdk "github.com/cosmos/cosmos-sdk/types"
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
"github.com/cosmos/cosmos-sdk/x/auth"
authexported "github.com/cosmos/cosmos-sdk/x/auth/exported"
"github.com/cosmos/cosmos-sdk/x/auth/keeper"
v2 "github.com/cosmos/cosmos-sdk/x/auth/migrations/v2"
v4 "github.com/cosmos/cosmos-sdk/x/auth/migrations/v4"
authtestutil "github.com/cosmos/cosmos-sdk/x/auth/testutil"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"

sdk "github.com/cosmos/cosmos-sdk/types"
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
authexported "github.com/cosmos/cosmos-sdk/x/auth/exported"
"github.com/stretchr/testify/require"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
)

type mockSubspace struct {
Expand All @@ -38,7 +38,7 @@ func TestMigrateMapAccAddressToAccNumberKey(t *testing.T) {
encCfg := moduletestutil.MakeTestEncodingConfig(auth.AppModuleBasic{})
cdc := encCfg.Codec

storeKey := sdk.NewKVStoreKey(v2.ModuleName)
storeKey := sdk.NewKVStoreKey(v4.ModuleName)
tKey := sdk.NewTransientStoreKey("transient_test")
ctx := testutil.DefaultContext(storeKey, tKey)
store := ctx.KVStore(storeKey)
Expand All @@ -54,7 +54,7 @@ func TestMigrateMapAccAddressToAccNumberKey(t *testing.T) {
require.NoError(t, err)

legacySubspace := newMockSubspace(authtypes.DefaultParams())
require.NoError(t, v2.Migrate(ctx, store, legacySubspace, cdc))
require.NoError(t, v4.Migrate(ctx, store, legacySubspace, cdc))

// new base account
senderPrivKey := secp256k1.GenPrivKey()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package v2
package v4

import (
"github.com/cosmos/cosmos-sdk/codec"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package v2_test
package v4_test

import (
"testing"
Expand All @@ -7,11 +7,10 @@ import (

"github.com/cosmos/cosmos-sdk/testutil"
sdk "github.com/cosmos/cosmos-sdk/types"

moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/auth/exported"
v2 "github.com/cosmos/cosmos-sdk/x/auth/migrations/v2"
v4 "github.com/cosmos/cosmos-sdk/x/auth/migrations/v4"
"github.com/cosmos/cosmos-sdk/x/auth/types"
)

Expand All @@ -31,16 +30,16 @@ func TestMigrate(t *testing.T) {
encCfg := moduletestutil.MakeTestEncodingConfig(auth.AppModuleBasic{})
cdc := encCfg.Codec

storeKey := sdk.NewKVStoreKey(v2.ModuleName)
storeKey := sdk.NewKVStoreKey(v4.ModuleName)
tKey := sdk.NewTransientStoreKey("transient_test")
ctx := testutil.DefaultContext(storeKey, tKey)
store := ctx.KVStore(storeKey)

legacySubspace := newMockSubspace(types.DefaultParams())
require.NoError(t, v2.Migrate(ctx, store, legacySubspace, cdc))
require.NoError(t, v4.Migrate(ctx, store, legacySubspace, cdc))

var res types.Params
bz := store.Get(v2.ParamsKey)
bz := store.Get(v4.ParamsKey)
require.NoError(t, cdc.Unmarshal(bz, &res))
require.Equal(t, legacySubspace.ps, res)
}
11 changes: 4 additions & 7 deletions x/auth/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,18 @@ import (
"fmt"
"math/rand"

modulev1 "cosmossdk.io/api/cosmos/auth/module/v1"
"cosmossdk.io/core/appmodule"
"cosmossdk.io/depinject"

gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime"

"github.com/spf13/cobra"
abci "github.com/tendermint/tendermint/abci/types"

modulev1 "cosmossdk.io/api/cosmos/auth/module/v1"
"cosmossdk.io/core/appmodule"
"github.com/cosmos/cosmos-sdk/runtime"
store "github.com/cosmos/cosmos-sdk/store/types"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/runtime"
store "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
Expand Down
4 changes: 2 additions & 2 deletions x/crisis/keeper/migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package keeper
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/crisis/exported"
v046 "github.com/cosmos/cosmos-sdk/x/crisis/migrations/v046"
v2 "github.com/cosmos/cosmos-sdk/x/crisis/migrations/v2"
)

// Migrator is a struct for handling in-place state migrations.
Expand All @@ -24,5 +24,5 @@ func NewMigrator(k *Keeper, ss exported.Subspace) Migrator {
// and managed by the x/params modules and stores them directly into the x/mint
// module state.
func (m Migrator) Migrate1to2(ctx sdk.Context) error {
return v046.MigrateStore(ctx, m.keeper.storeKey, m.legacySubspace, m.keeper.cdc)
return v2.MigrateStore(ctx, m.keeper.storeKey, m.legacySubspace, m.keeper.cdc)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package v046
package v2

import (
"github.com/cosmos/cosmos-sdk/codec"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package v046_test
package v2_test

import (
"testing"

"github.com/stretchr/testify/require"

"github.com/cosmos/cosmos-sdk/testutil"
sdk "github.com/cosmos/cosmos-sdk/types"
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
v046 "github.com/cosmos/cosmos-sdk/x/crisis/migrations/v046"
v2 "github.com/cosmos/cosmos-sdk/x/crisis/migrations/v2"
"github.com/cosmos/cosmos-sdk/x/crisis/types"
"github.com/cosmos/cosmos-sdk/x/distribution"
"github.com/stretchr/testify/require"
)

type mockSubspace struct {
Expand All @@ -28,16 +29,16 @@ func TestMigrate(t *testing.T) {
encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{})
cdc := encCfg.Codec

storeKey := sdk.NewKVStoreKey(v046.ModuleName)
storeKey := sdk.NewKVStoreKey(v2.ModuleName)
tKey := sdk.NewTransientStoreKey("transient_test")
ctx := testutil.DefaultContext(storeKey, tKey)
store := ctx.KVStore(storeKey)

legacySubspace := newMockSubspace(types.DefaultGenesisState().ConstantFee)
require.NoError(t, v046.MigrateStore(ctx, storeKey, legacySubspace, cdc))
require.NoError(t, v2.MigrateStore(ctx, storeKey, legacySubspace, cdc))

var res sdk.Coin
bz := store.Get(v046.ConstantFeeKey)
bz := store.Get(v2.ConstantFeeKey)
require.NoError(t, cdc.Unmarshal(bz, &res))
require.NotNil(t, res)
require.Equal(t, legacySubspace.constantFee, res)
Expand Down
4 changes: 2 additions & 2 deletions x/crisis/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import (
"fmt"
"time"

modulev1 "cosmossdk.io/api/cosmos/crisis/module/v1"
"cosmossdk.io/core/appmodule"
"cosmossdk.io/depinject"
gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/spf13/cast"
"github.com/spf13/cobra"
abci "github.com/tendermint/tendermint/abci/types"

modulev1 "cosmossdk.io/api/cosmos/crisis/module/v1"
"cosmossdk.io/depinject"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
Expand Down
4 changes: 2 additions & 2 deletions x/distribution/keeper/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/distribution/exported"
v043 "github.com/cosmos/cosmos-sdk/x/distribution/migrations/v043"
v046 "github.com/cosmos/cosmos-sdk/x/distribution/migrations/v046"
v3 "github.com/cosmos/cosmos-sdk/x/distribution/migrations/v3"
)

// Migrator is a struct for handling in-place store migrations.
Expand All @@ -28,5 +28,5 @@ func (m Migrator) Migrate1to2(ctx sdk.Context) error {
// and managed by the x/params module and stores them directly into the x/distribution
// module state.
func (m Migrator) Migrate2to3(ctx sdk.Context) error {
return v046.MigrateStore(ctx, m.keeper.storeKey, m.legacySubspace, m.keeper.cdc)
return v3.MigrateStore(ctx, m.keeper.storeKey, m.legacySubspace, m.keeper.cdc)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package v046
package v3

import (
"github.com/cosmos/cosmos-sdk/codec"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package v046_test
package v3_test

import (
"testing"

"github.com/stretchr/testify/require"

"github.com/cosmos/cosmos-sdk/testutil"
sdk "github.com/cosmos/cosmos-sdk/types"
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
"github.com/cosmos/cosmos-sdk/x/distribution"
"github.com/cosmos/cosmos-sdk/x/distribution/exported"
v046 "github.com/cosmos/cosmos-sdk/x/distribution/migrations/v046"
v3 "github.com/cosmos/cosmos-sdk/x/distribution/migrations/v3"
"github.com/cosmos/cosmos-sdk/x/distribution/types"
"github.com/stretchr/testify/require"
)

type mockSubspace struct {
Expand All @@ -29,16 +30,16 @@ func TestMigrate(t *testing.T) {
encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{})
cdc := encCfg.Codec

storeKey := sdk.NewKVStoreKey(v046.ModuleName)
storeKey := sdk.NewKVStoreKey(v3.ModuleName)
tKey := sdk.NewTransientStoreKey("transient_test")
ctx := testutil.DefaultContext(storeKey, tKey)
store := ctx.KVStore(storeKey)

legacySubspace := newMockSubspace(types.DefaultParams())
require.NoError(t, v046.MigrateStore(ctx, storeKey, legacySubspace, cdc))
require.NoError(t, v3.MigrateStore(ctx, storeKey, legacySubspace, cdc))

var res types.Params
bz := store.Get(v046.ParamsKey)
bz := store.Get(v3.ParamsKey)
require.NoError(t, cdc.Unmarshal(bz, &res))
require.Equal(t, legacySubspace.ps, res)
}
6 changes: 3 additions & 3 deletions x/distribution/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import (
"fmt"
"math/rand"

modulev1 "cosmossdk.io/api/cosmos/distribution/module/v1"
"cosmossdk.io/core/appmodule"
"cosmossdk.io/depinject"
gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/spf13/cobra"
abci "github.com/tendermint/tendermint/abci/types"

modulev1 "cosmossdk.io/api/cosmos/distribution/module/v1"
"cosmossdk.io/core/appmodule"
"cosmossdk.io/depinject"
sdkclient "github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
Expand Down
4 changes: 2 additions & 2 deletions x/slashing/keeper/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/slashing/exported"
v043 "github.com/cosmos/cosmos-sdk/x/slashing/migrations/v043"
v2 "github.com/cosmos/cosmos-sdk/x/slashing/migrations/v2"
v3 "github.com/cosmos/cosmos-sdk/x/slashing/migrations/v3"
)

// Migrator is a struct for handling in-place store migrations.
Expand All @@ -28,5 +28,5 @@ func (m Migrator) Migrate1to2(ctx sdk.Context) error {
// and managed by the x/params modules and stores them directly into the x/slashing
// module state.
func (m Migrator) Migrate2to3(ctx sdk.Context) error {
return v2.Migrate(ctx, ctx.KVStore(m.keeper.storeKey), m.legacySubspace, m.keeper.cdc)
return v3.Migrate(ctx, ctx.KVStore(m.keeper.storeKey), m.legacySubspace, m.keeper.cdc)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package v2
package v3

import (
"github.com/cosmos/cosmos-sdk/codec"
Expand Down
Loading

0 comments on commit 934b2b8

Please sign in to comment.