github.com/cosmos/cosmos-sdk@v0.50.10/x/auth/migrations/v4/migrate_test.go (about) 1 package v4_test 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/require" 7 8 storetypes "cosmossdk.io/store/types" 9 10 "github.com/cosmos/cosmos-sdk/runtime" 11 "github.com/cosmos/cosmos-sdk/testutil" 12 sdk "github.com/cosmos/cosmos-sdk/types" 13 moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" 14 "github.com/cosmos/cosmos-sdk/x/auth" 15 "github.com/cosmos/cosmos-sdk/x/auth/exported" 16 v1 "github.com/cosmos/cosmos-sdk/x/auth/migrations/v1" 17 v4 "github.com/cosmos/cosmos-sdk/x/auth/migrations/v4" 18 "github.com/cosmos/cosmos-sdk/x/auth/types" 19 ) 20 21 type mockSubspace struct { 22 ps types.Params 23 } 24 25 func newMockSubspace(ps types.Params) mockSubspace { 26 return mockSubspace{ps: ps} 27 } 28 29 func (ms mockSubspace) GetParamSet(ctx sdk.Context, ps exported.ParamSet) { 30 *ps.(*types.Params) = ms.ps 31 } 32 33 func TestMigrate(t *testing.T) { 34 encCfg := moduletestutil.MakeTestEncodingConfig(auth.AppModuleBasic{}) 35 cdc := encCfg.Codec 36 37 storeKey := storetypes.NewKVStoreKey(v1.ModuleName) 38 tKey := storetypes.NewTransientStoreKey("transient_test") 39 ctx := testutil.DefaultContext(storeKey, tKey) 40 storeService := runtime.NewKVStoreService(storeKey) 41 42 legacySubspace := newMockSubspace(types.DefaultParams()) 43 require.NoError(t, v4.Migrate(ctx, storeService, legacySubspace, cdc)) 44 45 var res types.Params 46 bz, err := storeService.OpenKVStore(ctx).Get(v4.ParamsKey) 47 require.NoError(t, err) 48 require.NoError(t, cdc.Unmarshal(bz, &res)) 49 require.Equal(t, legacySubspace.ps, res) 50 }