forked from cerc-io/laconicd-deprecated
117342b1b3
* evm, rpc: access lists, JSON-RPC and transaction updates (wip) * ante, evm, rpc: update signature verification * evm: msg server and tests updates * evm: tests (wip) * evm: fix cdc and params * evm: cleanup state transition * fix nil cases * lint
116 lines
2.7 KiB
Go
116 lines
2.7 KiB
Go
package evm_test
|
|
|
|
import (
|
|
"github.com/ethereum/go-ethereum/common"
|
|
|
|
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
|
"github.com/cosmos/ethermint/crypto/ethsecp256k1"
|
|
ethermint "github.com/cosmos/ethermint/types"
|
|
"github.com/cosmos/ethermint/x/evm"
|
|
"github.com/cosmos/ethermint/x/evm/types"
|
|
)
|
|
|
|
func (suite *EvmTestSuite) TestExportImport() {
|
|
var genState *types.GenesisState
|
|
suite.Require().NotPanics(func() {
|
|
genState = evm.ExportGenesis(suite.ctx, *suite.app.EvmKeeper, suite.app.AccountKeeper)
|
|
})
|
|
|
|
_ = evm.InitGenesis(suite.ctx, *suite.app.EvmKeeper, suite.app.AccountKeeper, suite.app.BankKeeper, *genState)
|
|
}
|
|
|
|
func (suite *EvmTestSuite) TestInitGenesis() {
|
|
privkey, err := ethsecp256k1.GenerateKey()
|
|
suite.Require().NoError(err)
|
|
|
|
address := common.HexToAddress(privkey.PubKey().Address().String())
|
|
|
|
testCases := []struct {
|
|
name string
|
|
malleate func()
|
|
genState *types.GenesisState
|
|
expPanic bool
|
|
}{
|
|
{
|
|
"default",
|
|
func() {},
|
|
types.DefaultGenesisState(),
|
|
false,
|
|
},
|
|
{
|
|
"valid account",
|
|
func() {
|
|
acc := suite.app.AccountKeeper.NewAccountWithAddress(suite.ctx, address.Bytes())
|
|
suite.Require().NotNil(acc)
|
|
|
|
err := suite.app.BankKeeper.SetBalance(suite.ctx, address.Bytes(), ethermint.NewPhotonCoinInt64(1))
|
|
suite.Require().NoError(err)
|
|
suite.app.AccountKeeper.SetAccount(suite.ctx, acc)
|
|
},
|
|
&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()},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
false,
|
|
},
|
|
{
|
|
"account not found",
|
|
func() {},
|
|
&types.GenesisState{
|
|
Params: types.DefaultParams(),
|
|
Accounts: []types.GenesisAccount{
|
|
{
|
|
Address: address.String(),
|
|
},
|
|
},
|
|
},
|
|
true,
|
|
},
|
|
{
|
|
"invalid account type",
|
|
func() {
|
|
acc := authtypes.NewBaseAccountWithAddress(address.Bytes())
|
|
suite.app.AccountKeeper.SetAccount(suite.ctx, acc)
|
|
},
|
|
&types.GenesisState{
|
|
Params: types.DefaultParams(),
|
|
Accounts: []types.GenesisAccount{
|
|
{
|
|
Address: address.String(),
|
|
},
|
|
},
|
|
},
|
|
true,
|
|
},
|
|
}
|
|
|
|
for _, tc := range testCases {
|
|
suite.Run(tc.name, func() {
|
|
suite.SetupTest() // reset values
|
|
|
|
tc.malleate()
|
|
|
|
if tc.expPanic {
|
|
suite.Require().Panics(
|
|
func() {
|
|
_ = evm.InitGenesis(suite.ctx, *suite.app.EvmKeeper, suite.app.AccountKeeper, suite.app.BankKeeper, *tc.genState)
|
|
},
|
|
)
|
|
} else {
|
|
suite.Require().NotPanics(
|
|
func() {
|
|
_ = evm.InitGenesis(suite.ctx, *suite.app.EvmKeeper, suite.app.AccountKeeper, suite.app.BankKeeper, *tc.genState)
|
|
},
|
|
)
|
|
}
|
|
})
|
|
}
|
|
}
|