2020-05-18 19:21:12 +00:00
|
|
|
package evm_test
|
|
|
|
|
|
|
|
import (
|
2021-06-29 17:02:21 +00:00
|
|
|
"math/big"
|
|
|
|
|
2021-04-18 15:54:18 +00:00
|
|
|
"github.com/ethereum/go-ethereum/common"
|
2020-05-29 15:50:22 +00:00
|
|
|
|
2021-04-18 15:54:18 +00:00
|
|
|
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
2021-06-22 10:49:18 +00:00
|
|
|
"github.com/tharsis/ethermint/crypto/ethsecp256k1"
|
|
|
|
"github.com/tharsis/ethermint/x/evm"
|
|
|
|
"github.com/tharsis/ethermint/x/evm/types"
|
2020-05-18 19:21:12 +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
|
|
|
|
2021-04-18 15:54:18 +00:00
|
|
|
address := common.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()
|
2021-04-17 10:00:07 +00:00
|
|
|
genState *types.GenesisState
|
2020-11-27 18:42:04 +00:00
|
|
|
expPanic bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
"default",
|
|
|
|
func() {},
|
|
|
|
types.DefaultGenesisState(),
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"valid account",
|
|
|
|
func() {
|
|
|
|
acc := suite.app.AccountKeeper.NewAccountWithAddress(suite.ctx, address.Bytes())
|
|
|
|
suite.Require().NotNil(acc)
|
2021-04-17 10:00:07 +00:00
|
|
|
|
2021-06-29 17:02:21 +00:00
|
|
|
suite.app.EvmKeeper.AddBalance(address, big.NewInt(1))
|
2020-11-27 18:42:04 +00:00
|
|
|
suite.app.AccountKeeper.SetAccount(suite.ctx, acc)
|
|
|
|
},
|
2021-04-17 10:00:07 +00:00
|
|
|
&types.GenesisState{
|
2020-11-27 18:42:04 +00:00
|
|
|
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() {},
|
2021-04-17 10:00:07 +00:00
|
|
|
&types.GenesisState{
|
2020-11-27 18:42:04 +00:00
|
|
|
Params: types.DefaultParams(),
|
|
|
|
Accounts: []types.GenesisAccount{
|
|
|
|
{
|
|
|
|
Address: address.String(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"invalid account type",
|
|
|
|
func() {
|
|
|
|
acc := authtypes.NewBaseAccountWithAddress(address.Bytes())
|
2021-04-17 10:00:07 +00:00
|
|
|
suite.app.AccountKeeper.SetAccount(suite.ctx, acc)
|
2020-11-27 18:42:04 +00:00
|
|
|
},
|
2021-04-17 10:00:07 +00:00
|
|
|
&types.GenesisState{
|
2020-11-27 18:42:04 +00:00
|
|
|
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-06-08 17:10:29 +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-06-08 17:10:29 +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
|
|
|
}
|