github.com/cosmos/cosmos-sdk@v0.50.10/x/slashing/migrations/v3/migrator_test.go (about) 1 package v3_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/testutil" 11 sdk "github.com/cosmos/cosmos-sdk/types" 12 moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" 13 "github.com/cosmos/cosmos-sdk/x/slashing" 14 "github.com/cosmos/cosmos-sdk/x/slashing/exported" 15 v3 "github.com/cosmos/cosmos-sdk/x/slashing/migrations/v3" 16 "github.com/cosmos/cosmos-sdk/x/slashing/types" 17 ) 18 19 type mockSubspace struct { 20 ps types.Params 21 } 22 23 func newMockSubspace(ps types.Params) mockSubspace { 24 return mockSubspace{ps: ps} 25 } 26 27 func (ms mockSubspace) GetParamSet(ctx sdk.Context, ps exported.ParamSet) { 28 *ps.(*types.Params) = ms.ps 29 } 30 31 func TestMigrate(t *testing.T) { 32 cdc := moduletestutil.MakeTestEncodingConfig(slashing.AppModuleBasic{}).Codec 33 storeKey := storetypes.NewKVStoreKey(v3.ModuleName) 34 tKey := storetypes.NewTransientStoreKey("transient_test") 35 ctx := testutil.DefaultContext(storeKey, tKey) 36 store := ctx.KVStore(storeKey) 37 38 legacySubspace := newMockSubspace(types.DefaultParams()) 39 require.NoError(t, v3.Migrate(ctx, store, legacySubspace, cdc)) 40 41 var res types.Params 42 bz := store.Get(v3.ParamsKey) 43 require.NoError(t, cdc.Unmarshal(bz, &res)) 44 require.Equal(t, legacySubspace.ps, res) 45 }