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