2024-02-02 18:21:11 +00:00
|
|
|
package v2_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
|
|
"github.com/cosmos/cosmos-sdk/testutil"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2024-02-06 22:54:10 +00:00
|
|
|
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
|
2024-02-02 18:21:11 +00:00
|
|
|
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
|
|
|
|
|
|
|
|
v2cdp "github.com/kava-labs/kava/x/cdp/migrations/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestStoreMigrationAddsKeyTableIncludingNewParam(t *testing.T) {
|
2024-02-06 22:54:10 +00:00
|
|
|
encCfg := moduletestutil.MakeTestEncodingConfig()
|
2024-02-02 18:21:11 +00:00
|
|
|
cdpKey := sdk.NewKVStoreKey(types.ModuleName)
|
|
|
|
tcdpKey := sdk.NewTransientStoreKey("transient_test")
|
|
|
|
ctx := testutil.DefaultContext(cdpKey, tcdpKey)
|
|
|
|
paramstore := paramtypes.NewSubspace(encCfg.Codec, encCfg.Amino, cdpKey, tcdpKey, types.ModuleName)
|
|
|
|
|
|
|
|
// Check param doesn't exist before
|
|
|
|
require.False(t, paramstore.Has(ctx, types.KeyBeginBlockerExecutionBlockInterval))
|
|
|
|
|
|
|
|
// Run migrations.
|
|
|
|
err := v2cdp.MigrateStore(ctx, paramstore)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// Make sure the new params are set.
|
|
|
|
require.True(t, paramstore.Has(ctx, types.KeyBeginBlockerExecutionBlockInterval))
|
|
|
|
// Assert the value is what we expect
|
|
|
|
result := types.DefaultBeginBlockerExecutionBlockInterval
|
|
|
|
paramstore.Get(ctx, types.KeyBeginBlockerExecutionBlockInterval, &result)
|
|
|
|
require.Equal(t, result, types.DefaultBeginBlockerExecutionBlockInterval)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStoreMigrationSetsNewParamOnExistingKeyTable(t *testing.T) {
|
2024-02-06 22:54:10 +00:00
|
|
|
encCfg := moduletestutil.MakeTestEncodingConfig()
|
2024-02-02 18:21:11 +00:00
|
|
|
cdpKey := sdk.NewKVStoreKey(types.ModuleName)
|
|
|
|
tcdpKey := sdk.NewTransientStoreKey("transient_test")
|
|
|
|
ctx := testutil.DefaultContext(cdpKey, tcdpKey)
|
|
|
|
paramstore := paramtypes.NewSubspace(encCfg.Codec, encCfg.Amino, cdpKey, tcdpKey, types.ModuleName)
|
|
|
|
paramstore.WithKeyTable(types.ParamKeyTable())
|
|
|
|
|
|
|
|
// expect it to have key table
|
|
|
|
require.True(t, paramstore.HasKeyTable())
|
|
|
|
// expect it to not have new param
|
|
|
|
require.False(t, paramstore.Has(ctx, types.KeyBeginBlockerExecutionBlockInterval))
|
|
|
|
|
|
|
|
// Run migrations.
|
|
|
|
err := v2cdp.MigrateStore(ctx, paramstore)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// Make sure the new params are set.
|
|
|
|
require.True(t, paramstore.Has(ctx, types.KeyBeginBlockerExecutionBlockInterval))
|
|
|
|
|
|
|
|
// Assert the value is what we expect
|
|
|
|
result := types.DefaultBeginBlockerExecutionBlockInterval
|
|
|
|
paramstore.Get(ctx, types.KeyBeginBlockerExecutionBlockInterval, &result)
|
|
|
|
require.Equal(t, result, types.DefaultBeginBlockerExecutionBlockInterval)
|
|
|
|
}
|