2023-01-04 14:28:45 +00:00
|
|
|
package v4_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/evmos/ethermint/x/evm/types"
|
|
|
|
gogotypes "github.com/gogo/protobuf/types"
|
|
|
|
|
|
|
|
"github.com/cosmos/cosmos-sdk/testutil"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
"github.com/evmos/ethermint/app"
|
|
|
|
"github.com/evmos/ethermint/encoding"
|
|
|
|
v4 "github.com/evmos/ethermint/x/evm/migrations/v4"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
type mockSubspace struct {
|
2023-01-12 08:52:55 +00:00
|
|
|
ps types.Params
|
2023-01-04 14:28:45 +00:00
|
|
|
}
|
|
|
|
|
2023-01-12 08:52:55 +00:00
|
|
|
func newMockSubspace(ps types.Params) mockSubspace {
|
2023-01-04 14:28:45 +00:00
|
|
|
return mockSubspace{ps: ps}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ms mockSubspace) GetParamSetIfExists(ctx sdk.Context, ps types.LegacyParams) {
|
2023-01-12 08:52:55 +00:00
|
|
|
*ps.(*types.Params) = ms.ps
|
2023-01-04 14:28:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestMigrate(t *testing.T) {
|
|
|
|
encCfg := encoding.MakeConfig(app.ModuleBasics)
|
|
|
|
cdc := encCfg.Codec
|
|
|
|
|
|
|
|
storeKey := sdk.NewKVStoreKey(types.ModuleName)
|
|
|
|
tKey := sdk.NewTransientStoreKey("transient_test")
|
|
|
|
ctx := testutil.DefaultContext(storeKey, tKey)
|
|
|
|
kvStore := ctx.KVStore(storeKey)
|
|
|
|
|
2023-01-12 08:52:55 +00:00
|
|
|
legacySubspace := newMockSubspace(types.DefaultParams())
|
2023-01-04 14:28:45 +00:00
|
|
|
require.NoError(t, v4.MigrateStore(ctx, storeKey, legacySubspace, cdc))
|
|
|
|
|
|
|
|
// Get all the new parameters from the kvStore
|
|
|
|
var evmDenom string
|
2023-01-12 08:52:55 +00:00
|
|
|
bz := kvStore.Get(types.ParamStoreKeyEVMDenom)
|
2023-01-04 14:28:45 +00:00
|
|
|
evmDenom = string(bz)
|
|
|
|
|
|
|
|
var allowUnprotectedTx gogotypes.BoolValue
|
2023-01-12 08:52:55 +00:00
|
|
|
bz = kvStore.Get(types.ParamStoreKeyAllowUnprotectedTxs)
|
2023-01-04 14:28:45 +00:00
|
|
|
cdc.MustUnmarshal(bz, &allowUnprotectedTx)
|
|
|
|
|
2023-01-12 08:52:55 +00:00
|
|
|
enableCreate := kvStore.Has(types.ParamStoreKeyEnableCreate)
|
|
|
|
enableCall := kvStore.Has(types.ParamStoreKeyEnableCall)
|
2023-01-04 14:28:45 +00:00
|
|
|
|
2023-01-12 08:52:55 +00:00
|
|
|
var chainCfg types.ChainConfig
|
|
|
|
bz = kvStore.Get(types.ParamStoreKeyChainConfig)
|
2023-01-04 14:28:45 +00:00
|
|
|
cdc.MustUnmarshal(bz, &chainCfg)
|
|
|
|
|
2023-01-12 08:52:55 +00:00
|
|
|
var extraEIPs types.ExtraEIPs
|
|
|
|
bz = kvStore.Get(types.ParamStoreKeyExtraEIPs)
|
2023-01-04 14:28:45 +00:00
|
|
|
cdc.MustUnmarshal(bz, &extraEIPs)
|
2023-01-12 08:52:55 +00:00
|
|
|
require.Equal(t, types.AvailableExtraEIPs, extraEIPs.EIPs)
|
2023-01-04 14:28:45 +00:00
|
|
|
|
2023-01-12 08:52:55 +00:00
|
|
|
params := types.NewParams(evmDenom, allowUnprotectedTx.Value, enableCreate, enableCall, chainCfg, extraEIPs)
|
2023-01-04 14:28:45 +00:00
|
|
|
require.Equal(t, legacySubspace.ps, params)
|
|
|
|
}
|