|
| 1 | +package migrations_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/cosmos/cosmos-sdk/codec" |
| 7 | + codectypes "github.com/cosmos/cosmos-sdk/codec/types" |
| 8 | + "github.com/cosmos/cosmos-sdk/store" |
| 9 | + storetypes "github.com/cosmos/cosmos-sdk/store/types" |
| 10 | + sdk "github.com/cosmos/cosmos-sdk/types" |
| 11 | + typesparams "github.com/cosmos/cosmos-sdk/x/params/types" |
| 12 | + "github.com/sei-protocol/sei-chain/x/dex/migrations" |
| 13 | + "github.com/sei-protocol/sei-chain/x/dex/types" |
| 14 | + "github.com/stretchr/testify/require" |
| 15 | + "github.com/tendermint/tendermint/libs/log" |
| 16 | + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" |
| 17 | + tmdb "github.com/tendermint/tm-db" |
| 18 | +) |
| 19 | + |
| 20 | +func TestMigrate3to4(t *testing.T) { |
| 21 | + storeKey := sdk.NewKVStoreKey(types.StoreKey) |
| 22 | + memStoreKey := storetypes.NewMemoryStoreKey(types.MemStoreKey) |
| 23 | + |
| 24 | + db := tmdb.NewMemDB() |
| 25 | + stateStore := store.NewCommitMultiStore(db) |
| 26 | + stateStore.MountStoreWithDB(storeKey, sdk.StoreTypeIAVL, db) |
| 27 | + stateStore.MountStoreWithDB(memStoreKey, sdk.StoreTypeMemory, nil) |
| 28 | + require.NoError(t, stateStore.LoadLatestVersion()) |
| 29 | + |
| 30 | + registry := codectypes.NewInterfaceRegistry() |
| 31 | + cdc := codec.NewProtoCodec(registry) |
| 32 | + |
| 33 | + paramsSubspace := typesparams.NewSubspace(cdc, |
| 34 | + types.Amino, |
| 35 | + storeKey, |
| 36 | + memStoreKey, |
| 37 | + "DexParams", |
| 38 | + ) |
| 39 | + ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger()) |
| 40 | + if !paramsSubspace.HasKeyTable() { |
| 41 | + paramsSubspace = paramsSubspace.WithKeyTable(types.ParamKeyTable()) |
| 42 | + } |
| 43 | + migrations.PriceSnapshotUpdate(ctx, paramsSubspace) |
| 44 | + |
| 45 | + params := types.Params{} |
| 46 | + paramsSubspace.GetParamSet(ctx, ¶ms) |
| 47 | + require.Equal(t, uint64(types.DefaultPriceSnapshotRetention), params.PriceSnapshotRetention) |
| 48 | +} |
0 commit comments