2023-01-05 16:59:46 +00:00
|
|
|
package v4_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2023-03-13 07:04:10 +00:00
|
|
|
"github.com/cerc-io/laconicd/app"
|
|
|
|
"github.com/cerc-io/laconicd/encoding"
|
|
|
|
v4 "github.com/cerc-io/laconicd/x/feemarket/migrations/v4"
|
|
|
|
"github.com/cerc-io/laconicd/x/feemarket/types"
|
2023-01-05 16:59:46 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/testutil"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
type mockSubspace struct {
|
2023-01-12 08:52:55 +00:00
|
|
|
ps types.Params
|
2023-01-05 16:59:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func newMockSubspaceEmpty() mockSubspace {
|
|
|
|
return mockSubspace{}
|
|
|
|
}
|
|
|
|
|
2023-01-12 08:52:55 +00:00
|
|
|
func newMockSubspace(ps types.Params) mockSubspace {
|
2023-01-05 16:59:46 +00:00
|
|
|
return mockSubspace{ps: ps}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ms mockSubspace) GetParamSetIfExists(ctx sdk.Context, ps types.LegacyParams) {
|
2023-01-12 08:52:55 +00:00
|
|
|
*ps.(*types.Params) = ms.ps
|
2023-01-05 16:59:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestMigrate(t *testing.T) {
|
|
|
|
encCfg := encoding.MakeConfig(app.ModuleBasics)
|
|
|
|
cdc := encCfg.Codec
|
|
|
|
|
|
|
|
storeKey := sdk.NewKVStoreKey(types.ModuleName)
|
|
|
|
tKey := sdk.NewTransientStoreKey("transient_test")
|
|
|
|
ctx := testutil.DefaultContext(storeKey, tKey)
|
|
|
|
kvStore := ctx.KVStore(storeKey)
|
|
|
|
|
|
|
|
legacySubspaceEmpty := newMockSubspaceEmpty()
|
|
|
|
require.Error(t, v4.MigrateStore(ctx, storeKey, legacySubspaceEmpty, cdc))
|
|
|
|
|
2023-01-12 08:52:55 +00:00
|
|
|
legacySubspace := newMockSubspace(types.DefaultParams())
|
2023-01-05 16:59:46 +00:00
|
|
|
require.NoError(t, v4.MigrateStore(ctx, storeKey, legacySubspace, cdc))
|
|
|
|
|
2023-01-12 08:52:55 +00:00
|
|
|
paramsBz := kvStore.Get(types.ParamsKey)
|
|
|
|
var params types.Params
|
2023-01-05 16:59:46 +00:00
|
|
|
cdc.MustUnmarshal(paramsBz, ¶ms)
|
|
|
|
|
|
|
|
require.Equal(t, params, legacySubspace.ps)
|
|
|
|
}
|