mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-11-10 18:15:19 +00:00
64 lines
2.3 KiB
Go
64 lines
2.3 KiB
Go
|
package v2_test
|
||
|
|
||
|
import (
|
||
|
"testing"
|
||
|
|
||
|
"github.com/stretchr/testify/require"
|
||
|
|
||
|
"github.com/cosmos/cosmos-sdk/simapp"
|
||
|
"github.com/cosmos/cosmos-sdk/testutil"
|
||
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||
|
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
|
||
|
|
||
|
v2cdp "github.com/kava-labs/kava/x/cdp/migrations/v2"
|
||
|
"github.com/kava-labs/kava/x/cdp/types"
|
||
|
)
|
||
|
|
||
|
func TestStoreMigrationAddsKeyTableIncludingNewParam(t *testing.T) {
|
||
|
encCfg := simapp.MakeTestEncodingConfig()
|
||
|
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) {
|
||
|
encCfg := simapp.MakeTestEncodingConfig()
|
||
|
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)
|
||
|
}
|