2022-05-31 16:28:46 +00:00
|
|
|
package v011_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
|
|
"github.com/cosmos/cosmos-sdk/testutil"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
|
|
|
|
|
2022-06-19 09:43:41 +00:00
|
|
|
"github.com/evmos/ethermint/encoding"
|
2022-05-31 16:28:46 +00:00
|
|
|
|
2022-06-19 09:43:41 +00:00
|
|
|
"github.com/evmos/ethermint/app"
|
|
|
|
v010types "github.com/evmos/ethermint/x/feemarket/migrations/v010/types"
|
|
|
|
v011 "github.com/evmos/ethermint/x/feemarket/migrations/v011"
|
|
|
|
"github.com/evmos/ethermint/x/feemarket/types"
|
|
|
|
feemarkettypes "github.com/evmos/ethermint/x/feemarket/types"
|
2022-05-31 16:28:46 +00:00
|
|
|
)
|
|
|
|
|
2022-06-05 09:22:33 +00:00
|
|
|
func init() {
|
|
|
|
// modify defaults through global
|
|
|
|
types.DefaultMinGasPrice = sdk.NewDecWithPrec(25, 3)
|
|
|
|
}
|
|
|
|
|
2022-05-31 16:28:46 +00:00
|
|
|
func TestMigrateStore(t *testing.T) {
|
|
|
|
encCfg := encoding.MakeConfig(app.ModuleBasics)
|
|
|
|
feemarketKey := sdk.NewKVStoreKey(feemarkettypes.StoreKey)
|
|
|
|
tFeeMarketKey := sdk.NewTransientStoreKey(fmt.Sprintf("%s_test", feemarkettypes.StoreKey))
|
|
|
|
ctx := testutil.DefaultContext(feemarketKey, tFeeMarketKey)
|
|
|
|
paramstore := paramtypes.NewSubspace(
|
|
|
|
encCfg.Marshaler, encCfg.Amino, feemarketKey, tFeeMarketKey, "feemarket",
|
|
|
|
)
|
|
|
|
|
|
|
|
paramstore = paramstore.WithKeyTable(feemarkettypes.ParamKeyTable())
|
|
|
|
require.True(t, paramstore.HasKeyTable())
|
|
|
|
|
|
|
|
// check no MinGasPrice param
|
|
|
|
require.False(t, paramstore.Has(ctx, feemarkettypes.ParamStoreKeyMinGasPrice))
|
2022-06-05 09:22:33 +00:00
|
|
|
require.False(t, paramstore.Has(ctx, feemarkettypes.ParamStoreKeyMinGasMultiplier))
|
2022-05-31 16:28:46 +00:00
|
|
|
|
|
|
|
// Run migrations
|
|
|
|
err := v011.MigrateStore(ctx, ¶mstore)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// Make sure the params are set
|
|
|
|
require.True(t, paramstore.Has(ctx, feemarkettypes.ParamStoreKeyMinGasPrice))
|
2022-06-05 09:22:33 +00:00
|
|
|
require.True(t, paramstore.Has(ctx, feemarkettypes.ParamStoreKeyMinGasMultiplier))
|
2022-05-31 16:28:46 +00:00
|
|
|
|
2022-06-05 09:22:33 +00:00
|
|
|
var (
|
|
|
|
minGasPrice sdk.Dec
|
|
|
|
minGasMultiplier sdk.Dec
|
|
|
|
)
|
2022-05-31 16:28:46 +00:00
|
|
|
|
|
|
|
// Make sure the new params are set
|
|
|
|
require.NotPanics(t, func() {
|
|
|
|
paramstore.Get(ctx, feemarkettypes.ParamStoreKeyMinGasPrice, &minGasPrice)
|
2022-06-05 09:22:33 +00:00
|
|
|
paramstore.Get(ctx, feemarkettypes.ParamStoreKeyMinGasMultiplier, &minGasMultiplier)
|
2022-05-31 16:28:46 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
// check the params are updated
|
2022-06-05 09:22:33 +00:00
|
|
|
require.Equal(t, types.DefaultMinGasPrice.String(), minGasPrice.String())
|
|
|
|
require.False(t, minGasPrice.IsZero())
|
|
|
|
require.Equal(t, types.DefaultMinGasMultiplier.String(), minGasMultiplier.String())
|
2022-05-31 16:28:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestMigrateJSON(t *testing.T) {
|
|
|
|
rawJson := `{
|
|
|
|
"block_gas": "0",
|
|
|
|
"params": {
|
|
|
|
"base_fee_change_denominator": 8,
|
|
|
|
"elasticity_multiplier": 2,
|
|
|
|
"enable_height": "0",
|
|
|
|
"base_fee": "1000000000",
|
|
|
|
"no_base_fee": false
|
|
|
|
}
|
|
|
|
}`
|
|
|
|
encCfg := encoding.MakeConfig(app.ModuleBasics)
|
|
|
|
var genState v010types.GenesisState
|
|
|
|
err := encCfg.Marshaler.UnmarshalJSON([]byte(rawJson), &genState)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
migratedGenState := v011.MigrateJSON(genState)
|
|
|
|
|
2022-06-05 09:22:33 +00:00
|
|
|
require.Equal(t, types.DefaultMinGasPrice, migratedGenState.Params.MinGasPrice)
|
|
|
|
require.Equal(t, types.DefaultMinGasMultiplier, migratedGenState.Params.MinGasMultiplier)
|
2022-05-31 16:28:46 +00:00
|
|
|
}
|