2020-05-18 19:21:12 +00:00
|
|
|
package evm_test
|
|
|
|
|
|
|
|
import (
|
2020-11-27 18:42:04 +00:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
2020-05-29 15:50:22 +00:00
|
|
|
|
2020-10-06 18:57:55 +00:00
|
|
|
"github.com/cosmos/ethermint/crypto/ethsecp256k1"
|
2020-11-27 18:42:04 +00:00
|
|
|
ethermint "github.com/cosmos/ethermint/types"
|
2020-05-18 19:21:12 +00:00
|
|
|
"github.com/cosmos/ethermint/x/evm"
|
|
|
|
"github.com/cosmos/ethermint/x/evm/types"
|
2020-05-29 15:50:22 +00:00
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
2020-11-27 18:42:04 +00:00
|
|
|
ethcmn "github.com/ethereum/go-ethereum/common"
|
2020-05-18 19:21:12 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func (suite *EvmTestSuite) TestExportImport() {
|
|
|
|
var genState types.GenesisState
|
|
|
|
suite.Require().NotPanics(func() {
|
2021-01-07 11:55:01 +00:00
|
|
|
genState = evm.ExportGenesis(suite.ctx, *suite.app.EvmKeeper, suite.app.AccountKeeper)
|
2020-05-18 19:21:12 +00:00
|
|
|
})
|
|
|
|
|
2021-01-07 11:55:01 +00:00
|
|
|
_ = evm.InitGenesis(suite.ctx, *suite.app.EvmKeeper, suite.app.AccountKeeper, genState)
|
2020-05-18 19:21:12 +00:00
|
|
|
}
|
2020-05-29 15:50:22 +00:00
|
|
|
|
2020-11-27 18:42:04 +00:00
|
|
|
func (suite *EvmTestSuite) TestInitGenesis() {
|
|
|
|
privkey, err := ethsecp256k1.GenerateKey()
|
|
|
|
suite.Require().NoError(err)
|
2020-05-29 15:50:22 +00:00
|
|
|
|
2020-11-27 18:42:04 +00:00
|
|
|
address := ethcmn.HexToAddress(privkey.PubKey().Address().String())
|
2020-05-29 15:50:22 +00:00
|
|
|
|
2020-11-27 18:42:04 +00:00
|
|
|
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 := acc.SetCoins(sdk.NewCoins(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{
|
2021-01-06 20:56:40 +00:00
|
|
|
{Key: common.BytesToHash([]byte("key")).String(), Value: common.BytesToHash([]byte("value")).String()},
|
2020-11-27 18:42:04 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
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,
|
|
|
|
},
|
|
|
|
}
|
2020-05-29 15:50:22 +00:00
|
|
|
|
2020-11-27 18:42:04 +00:00
|
|
|
for _, tc := range testCases {
|
|
|
|
suite.Run(tc.name, func() {
|
|
|
|
suite.SetupTest() // reset values
|
2020-05-29 15:50:22 +00:00
|
|
|
|
2020-11-27 18:42:04 +00:00
|
|
|
tc.malleate()
|
2020-05-29 15:50:22 +00:00
|
|
|
|
2020-11-27 18:42:04 +00:00
|
|
|
if tc.expPanic {
|
|
|
|
suite.Require().Panics(
|
|
|
|
func() {
|
2021-01-07 11:55:01 +00:00
|
|
|
_ = evm.InitGenesis(suite.ctx, *suite.app.EvmKeeper, suite.app.AccountKeeper, tc.genState)
|
2020-11-27 18:42:04 +00:00
|
|
|
},
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
suite.Require().NotPanics(
|
|
|
|
func() {
|
2021-01-07 11:55:01 +00:00
|
|
|
_ = evm.InitGenesis(suite.ctx, *suite.app.EvmKeeper, suite.app.AccountKeeper, tc.genState)
|
2020-11-27 18:42:04 +00:00
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2020-05-29 15:50:22 +00:00
|
|
|
}
|