2022-07-08 10:58:04 +00:00
|
|
|
package v3_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
2022-07-28 13:43:49 +00:00
|
|
|
v3 "github.com/evmos/ethermint/x/evm/migrations/v3"
|
|
|
|
|
2022-07-08 10:58:04 +00:00
|
|
|
"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"
|
|
|
|
|
|
|
|
"github.com/evmos/ethermint/encoding"
|
|
|
|
|
|
|
|
"github.com/evmos/ethermint/app"
|
|
|
|
v3types "github.com/evmos/ethermint/x/evm/migrations/v3/types"
|
|
|
|
"github.com/evmos/ethermint/x/evm/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestMigrateStore(t *testing.T) {
|
|
|
|
encCfg := encoding.MakeConfig(app.ModuleBasics)
|
|
|
|
evmKey := sdk.NewKVStoreKey(types.StoreKey)
|
|
|
|
tEvmKey := sdk.NewTransientStoreKey(fmt.Sprintf("%s_test", types.StoreKey))
|
|
|
|
ctx := testutil.DefaultContext(evmKey, tEvmKey)
|
|
|
|
paramstore := paramtypes.NewSubspace(
|
2022-07-28 13:43:49 +00:00
|
|
|
encCfg.Codec, encCfg.Amino, evmKey, tEvmKey, "evm",
|
2022-07-08 10:58:04 +00:00
|
|
|
).WithKeyTable(v3types.ParamKeyTable())
|
|
|
|
|
|
|
|
params := v3types.DefaultParams()
|
|
|
|
paramstore.SetParamSet(ctx, ¶ms)
|
|
|
|
|
|
|
|
require.Panics(t, func() {
|
|
|
|
var preMigrationConfig types.ChainConfig
|
|
|
|
paramstore.Get(ctx, types.ParamStoreKeyChainConfig, &preMigrationConfig)
|
|
|
|
})
|
|
|
|
var preMigrationConfig v3types.ChainConfig
|
|
|
|
paramstore.Get(ctx, types.ParamStoreKeyChainConfig, &preMigrationConfig)
|
|
|
|
require.NotNil(t, preMigrationConfig.MergeForkBlock)
|
|
|
|
|
|
|
|
paramstore = paramtypes.NewSubspace(
|
2022-07-28 13:43:49 +00:00
|
|
|
encCfg.Codec, encCfg.Amino, evmKey, tEvmKey, "evm",
|
2022-07-08 10:58:04 +00:00
|
|
|
).WithKeyTable(types.ParamKeyTable())
|
|
|
|
err := v3.MigrateStore(ctx, ¶mstore)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
updatedDefaultConfig := types.DefaultChainConfig()
|
|
|
|
|
|
|
|
var postMigrationConfig types.ChainConfig
|
|
|
|
paramstore.Get(ctx, types.ParamStoreKeyChainConfig, &postMigrationConfig)
|
|
|
|
require.Equal(t, postMigrationConfig.GrayGlacierBlock, updatedDefaultConfig.GrayGlacierBlock)
|
|
|
|
require.Equal(t, postMigrationConfig.MergeNetsplitBlock, updatedDefaultConfig.MergeNetsplitBlock)
|
|
|
|
require.Panics(t, func() {
|
|
|
|
var preMigrationConfig v3types.ChainConfig
|
|
|
|
paramstore.Get(ctx, types.ParamStoreKeyChainConfig, &preMigrationConfig)
|
|
|
|
})
|
|
|
|
}
|