package evm_test
import (
"math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/cerc-io/laconicd/crypto/ethsecp256k1"
etherminttypes "github.com/cerc-io/laconicd/types"
"github.com/cerc-io/laconicd/x/evm"
"github.com/cerc-io/laconicd/x/evm/statedb"
"github.com/cerc-io/laconicd/x/evm/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
)
func (suite *EvmTestSuite) TestInitGenesis() {
privkey, err := ethsecp256k1.GenerateKey()
suite.Require().NoError(err)
address := common.HexToAddress(privkey.PubKey().Address().String())
var vmdb *statedb.StateDB
testCases := []struct {
name string
malleate func()
genState *types.GenesisState
expPanic bool
}{
{
"default",
func() {},
types.DefaultGenesisState(),
false,
},
"valid account",
func() {
vmdb.AddBalance(address, big.NewInt(1))
&types.GenesisState{
Params: types.DefaultParams(),
Accounts: []types.GenesisAccount{
Address: address.String(),
Storage: types.Storage{
{Key: common.BytesToHash([]byte("key")).String(), Value: common.BytesToHash([]byte("value")).String()},
"account not found",
true,
"invalid account type",
acc := authtypes.NewBaseAccountWithAddress(address.Bytes())
suite.app.AccountKeeper.SetAccount(suite.ctx, acc)
"invalid code hash",
acc := suite.app.AccountKeeper.NewAccountWithAddress(suite.ctx, address.Bytes())
Code: "ffffffff",
"ignore empty account code checking",
Code: "",
"ignore empty account code checking with non-empty codehash",
ethAcc := ðerminttypes.EthAccount{
BaseAccount: authtypes.NewBaseAccount(address.Bytes(), nil, 0, 0),
CodeHash: common.BytesToHash([]byte{1, 2, 3}).Hex(),
}
suite.app.AccountKeeper.SetAccount(suite.ctx, ethAcc)
for _, tc := range testCases {
suite.Run(tc.name, func() {
suite.SetupTest() // reset values
vmdb = suite.StateDB()
tc.malleate()
vmdb.Commit()
if tc.expPanic {
suite.Require().Panics(
_ = evm.InitGenesis(suite.ctx, suite.app.EvmKeeper, suite.app.AccountKeeper, *tc.genState)
} else {
suite.Require().NotPanics(
})