0g-chain/x/cdp/migrations/v2/store_test.go
0g-wh 822e374be6 rebase to kava cosmos 0.47 upgrade
rename

rename

tidy

clean code
2024-09-25 15:18:12 +00:00

63 lines
2.3 KiB
Go

package v2_test
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/cosmos/cosmos-sdk/testutil"
sdk "github.com/cosmos/cosmos-sdk/types"
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
v2cdp "github.com/kava-labs/kava/x/cdp/migrations/v2"
)
func TestStoreMigrationAddsKeyTableIncludingNewParam(t *testing.T) {
encCfg := moduletestutil.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 := moduletestutil.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)
}