laconicd-deprecated/x/feemarket/migrations/v4/migrate_test.go

52 lines
1.3 KiB
Go
Raw Normal View History

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"
"github.com/cosmos/cosmos-sdk/testutil"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"
)
type mockSubspace struct {
ps types.Params
}
func newMockSubspaceEmpty() mockSubspace {
return mockSubspace{}
}
func newMockSubspace(ps types.Params) mockSubspace {
return mockSubspace{ps: ps}
}
func (ms mockSubspace) GetParamSetIfExists(ctx sdk.Context, ps types.LegacyParams) {
*ps.(*types.Params) = ms.ps
}
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))
legacySubspace := newMockSubspace(types.DefaultParams())
require.NoError(t, v4.MigrateStore(ctx, storeKey, legacySubspace, cdc))
paramsBz := kvStore.Get(types.ParamsKey)
var params types.Params
cdc.MustUnmarshal(paramsBz, &params)
require.Equal(t, params, legacySubspace.ps)
}