|
| 1 | +package v3_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/stretchr/testify/require" |
| 7 | + |
| 8 | + "cosmossdk.io/collections" |
| 9 | + storetypes "cosmossdk.io/store/types" |
| 10 | + |
| 11 | + "github.com/cosmos/cosmos-sdk/codec" |
| 12 | + "github.com/cosmos/cosmos-sdk/runtime" |
| 13 | + "github.com/cosmos/cosmos-sdk/testutil" |
| 14 | + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" |
| 15 | + "github.com/cosmos/cosmos-sdk/x/mint" |
| 16 | + v3 "github.com/cosmos/cosmos-sdk/x/mint/migrations/v3" |
| 17 | + "github.com/cosmos/cosmos-sdk/x/mint/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 TestMigrate(t *testing.T) { |
| 29 | + encCfg := moduletestutil.MakeTestEncodingConfig(mint.AppModuleBasic{}) |
| 30 | + cdc := encCfg.Codec |
| 31 | + |
| 32 | + storeKey := storetypes.NewKVStoreKey(v3.ModuleName) |
| 33 | + tKey := storetypes.NewTransientStoreKey("transient_test") |
| 34 | + ctx := testutil.DefaultContext(storeKey, tKey) |
| 35 | + kvStoreService := runtime.NewKVStoreService(storeKey) |
| 36 | + store := kvStoreService.OpenKVStore(ctx) |
| 37 | + |
| 38 | + sb := collections.NewSchemaBuilder(kvStoreService) |
| 39 | + params := collections.NewItem(sb, v3.ParamsKey, "params", codec.CollValue[types.Params](cdc)) |
| 40 | + |
| 41 | + dp := newMockSubspace(types.DefaultParams()) |
| 42 | + require.NoError(t, params.Set(ctx, dp.ps)) |
| 43 | + require.NoError(t, v3.Migrate(ctx, store, cdc, params)) |
| 44 | + |
| 45 | + var res types.Params |
| 46 | + bz, err := store.Get(v3.ParamsKey) |
| 47 | + require.NoError(t, err) |
| 48 | + require.NoError(t, cdc.Unmarshal(bz, &res)) |
| 49 | + require.Equal(t, dp.ps, res) |
| 50 | +} |
0 commit comments