From a587955c5f387e9bcf0bc0f85db239f2ef3f07c0 Mon Sep 17 00:00:00 2001 From: yihuang Date: Fri, 23 Feb 2024 10:10:40 +0800 Subject: [PATCH] fix test build --- app/ante/eth_test.go | 8 +-- app/ante/utils_test.go | 6 +-- app/app.go | 2 +- app/simulation_test.go | 8 +-- app/utils.go | 2 +- tests/importer/importer_test.go | 6 +-- x/evm/handler_test.go | 52 ++++++------------- x/evm/keeper/abci_test.go | 2 +- x/evm/keeper/grpc_query_test.go | 2 +- x/evm/keeper/hooks_test.go | 2 +- x/evm/keeper/integration_test.go | 32 +++++++----- x/evm/keeper/keeper_test.go | 25 +++++---- .../keeper/state_transition_benchmark_test.go | 3 +- x/evm/keeper/state_transition_test.go | 7 +-- x/evm/keeper/statedb_test.go | 4 +- x/evm/statedb/statedb_test.go | 38 ++++++++------ x/evm/types/msg_test.go | 1 - x/feemarket/keeper/abci_test.go | 2 +- x/feemarket/keeper/keeper_test.go | 17 +++--- 19 files changed, 105 insertions(+), 114 deletions(-) diff --git a/app/ante/eth_test.go b/app/ante/eth_test.go index 1c87e34ad8..6eb6ce0bdc 100644 --- a/app/ante/eth_test.go +++ b/app/ante/eth_test.go @@ -254,7 +254,7 @@ func (suite AnteTestSuite) TestEthGasConsumeDecorator() { 0, func() { vmdb.AddBalance(addr, big.NewInt(1000000)) - suite.ctx = suite.ctx.WithBlockGasMeter(sdk.NewGasMeter(1)) + suite.ctx = suite.ctx.WithBlockGasMeter(storetypes.NewGasMeter(1)) }, false, true, 0, @@ -265,7 +265,7 @@ func (suite AnteTestSuite) TestEthGasConsumeDecorator() { tx2GasLimit, // it's capped func() { vmdb.AddBalance(addr, big.NewInt(1001000000000000)) - suite.ctx = suite.ctx.WithBlockGasMeter(sdk.NewGasMeter(10000000000000000000)) + suite.ctx = suite.ctx.WithBlockGasMeter(storetypes.NewGasMeter(10000000000000000000)) }, true, false, tx2Priority, @@ -276,7 +276,7 @@ func (suite AnteTestSuite) TestEthGasConsumeDecorator() { tx2GasLimit, // it's capped func() { vmdb.AddBalance(addr, big.NewInt(1001000000000000)) - suite.ctx = suite.ctx.WithBlockGasMeter(sdk.NewGasMeter(10000000000000000000)) + suite.ctx = suite.ctx.WithBlockGasMeter(storetypes.NewGasMeter(10000000000000000000)) }, true, false, dynamicFeeTxPriority, @@ -302,7 +302,7 @@ func (suite AnteTestSuite) TestEthGasConsumeDecorator() { if tc.expPanic { suite.Require().Panics(func() { - _, _ = dec.AnteHandle(suite.ctx.WithIsCheckTx(true).WithGasMeter(sdk.NewGasMeter(1)), tc.tx, false, NextFn) + _, _ = dec.AnteHandle(suite.ctx.WithIsCheckTx(true).WithGasMeter(storetypes.NewGasMeter(1)), tc.tx, false, NextFn) }) return } diff --git a/app/ante/utils_test.go b/app/ante/utils_test.go index 90edcc1be7..b0b587a259 100644 --- a/app/ante/utils_test.go +++ b/app/ante/utils_test.go @@ -74,7 +74,7 @@ type AnteTestSuite struct { const TestGasLimit uint64 = 100000 func (suite *AnteTestSuite) StateDB() *statedb.StateDB { - return statedb.New(suite.ctx, suite.app.EvmKeeper, statedb.NewEmptyTxConfig(common.BytesToHash(suite.ctx.HeaderHash().Bytes()))) + return statedb.New(suite.ctx, suite.app.EvmKeeper, statedb.NewEmptyTxConfig(common.BytesToHash(suite.ctx.HeaderHash()))) } func (suite *AnteTestSuite) SetupTest() { @@ -111,9 +111,9 @@ func (suite *AnteTestSuite) SetupTest() { return genesis }) - suite.ctx = suite.app.BaseApp.NewContext(checkTx, tmproto.Header{Height: 2, ChainID: testutil.TestnetChainID + "-1", Time: time.Now().UTC()}) + suite.ctx = suite.app.BaseApp.NewContext(checkTx).WithBlockHeader(tmproto.Header{Height: 2, ChainID: testutil.TestnetChainID + "-1", Time: time.Now().UTC()}) suite.ctx = suite.ctx.WithMinGasPrices(sdk.NewDecCoins(sdk.NewDecCoin(evmtypes.DefaultEVMDenom, sdkmath.OneInt()))) - suite.ctx = suite.ctx.WithBlockGasMeter(sdk.NewGasMeter(1000000000000000000)) + suite.ctx = suite.ctx.WithBlockGasMeter(storetypes.NewGasMeter(1000000000000000000)) suite.app.EvmKeeper.WithChainID(suite.ctx) infCtx := suite.ctx.WithGasMeter(sdk.NewInfiniteGasMeter()) diff --git a/app/app.go b/app/app.go index ff756ef739..e9d4b0da36 100644 --- a/app/app.go +++ b/app/app.go @@ -385,8 +385,8 @@ func NewEthermintApp( app.AccountKeeper, app.BankKeeper, authAddr, + address.NewBech32Codec(sdk.GetConfig().GetBech32ValidatorAddrPrefix()), address.NewBech32Codec(sdk.GetConfig().GetBech32ConsensusAddrPrefix()), - address.NewBech32Codec(sdk.GetConfig().GetBech32AccountAddrPrefix()), ) app.MintKeeper = mintkeeper.NewKeeper( appCodec, diff --git a/app/simulation_test.go b/app/simulation_test.go index 06ff5fc0a7..079cdcee22 100644 --- a/app/simulation_test.go +++ b/app/simulation_test.go @@ -16,13 +16,13 @@ import ( simcli "github.com/cosmos/cosmos-sdk/x/simulation/client/cli" + "cosmossdk.io/log" "cosmossdk.io/store" storetypes "cosmossdk.io/store/types" evidencetypes "cosmossdk.io/x/evidence/types" - dbm "github.com/cosmos/cosmos-db" abci "github.com/cometbft/cometbft/abci/types" - "cosmossdk.io/log" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" + dbm "github.com/cosmos/cosmos-db" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" @@ -229,8 +229,8 @@ func TestAppImportExport(t *testing.T) { } }() - ctxA := app.NewContext(true, tmproto.Header{Height: app.LastBlockHeight(), ChainID: SimAppChainID}) - ctxB := newApp.NewContext(true, tmproto.Header{Height: app.LastBlockHeight(), ChainID: SimAppChainID}) + ctxA := app.NewContext(true).WithBlockHeader(tmproto.Header{Height: app.LastBlockHeight(), ChainID: SimAppChainID}) + ctxB := newApp.NewContext(true).WithBlockHeader(tmproto.Header{Height: app.LastBlockHeight(), ChainID: SimAppChainID}) newApp.mm.InitGenesis(ctxB, app.AppCodec(), genesisState) newApp.StoreConsensusParams(ctxB, exported.ConsensusParams) diff --git a/app/utils.go b/app/utils.go index faa56d67cb..3ff766a3e0 100644 --- a/app/utils.go +++ b/app/utils.go @@ -252,7 +252,7 @@ func genesisStateWithValSet(codec codec.Codec, genesisState GenesisState, MinSelfDelegation: sdkmath.ZeroInt(), } validators = append(validators, validator) - delegations = append(delegations, stakingtypes.NewDelegation(genAccs[0].GetAddress().String(), val.Address.String(), sdkmath.LegacyOneDec())) + delegations = append(delegations, stakingtypes.NewDelegation(genAccs[0].GetAddress().String(), sdk.ValAddress(val.Address).String(), sdkmath.LegacyOneDec())) } // set validators and delegations stakingGenesis := stakingtypes.NewGenesisState(stakingtypes.DefaultParams(), validators, delegations) diff --git a/tests/importer/importer_test.go b/tests/importer/importer_test.go index f3fbdc9800..a25129f7a3 100644 --- a/tests/importer/importer_test.go +++ b/tests/importer/importer_test.go @@ -65,7 +65,7 @@ func (suite *ImporterTestSuite) DoSetupTest(t require.TestingT) { priv, err := ethsecp256k1.GenerateKey() require.NoError(t, err) consAddress := sdk.ConsAddress(priv.PubKey().Address()) - suite.ctx = suite.app.BaseApp.NewContext(checkTx, tmproto.Header{ + suite.ctx = suite.app.BaseApp.NewContext(checkTx).WithBlockHeader(tmproto.Header{ Height: 1, ChainID: "ethermint_9000-1", Time: time.Now().UTC(), @@ -139,9 +139,9 @@ func (suite *ImporterTestSuite) TestImportBlocks() { suite.app.BeginBlock(types.RequestBeginBlock{ Header: tmheader, }) - ctx := suite.app.NewContext(false, tmheader) + ctx := suite.app.NewContext(false).WithBlockHeader(tmheader) ctx = ctx.WithBlockHeight(tmheader.Height) - vmdb := statedb.New(ctx, suite.app.EvmKeeper, statedb.NewEmptyTxConfig(common.BytesToHash(ctx.HeaderHash().Bytes()))) + vmdb := statedb.New(ctx, suite.app.EvmKeeper, statedb.NewEmptyTxConfig(common.BytesToHash(ctx.HeaderHash()))) if chainConfig.DAOForkSupport && chainConfig.DAOForkBlock != nil && chainConfig.DAOForkBlock.Cmp(block.Number()) == 0 { applyDAOHardFork(vmdb) diff --git a/x/evm/handler_test.go b/x/evm/handler_test.go index 153e249ebf..e6ab8211f6 100644 --- a/x/evm/handler_test.go +++ b/x/evm/handler_test.go @@ -9,7 +9,7 @@ import ( "github.com/evmos/ethermint/x/evm/keeper" sdkmath "cosmossdk.io/math" - "github.com/cosmos/gogoproto/proto" + storetypes "cosmossdk.io/store/types" abci "github.com/cometbft/cometbft/abci/types" tmjson "github.com/cometbft/cometbft/libs/json" @@ -36,7 +36,6 @@ import ( "github.com/evmos/ethermint/crypto/ethsecp256k1" "github.com/evmos/ethermint/tests" ethermint "github.com/evmos/ethermint/types" - "github.com/evmos/ethermint/x/evm" "github.com/evmos/ethermint/x/evm/statedb" "github.com/evmos/ethermint/x/evm/types" @@ -51,7 +50,7 @@ type EvmTestSuite struct { suite.Suite ctx sdk.Context - handler sdk.Handler + server types.MsgServer app *app.EthermintApp codec codec.Codec chainID *big.Int @@ -114,7 +113,7 @@ func (suite *EvmTestSuite) DoSetupTest(t require.TestingT) { // Initialize the chain suite.app.InitChain( - abci.RequestInitChain{ + &abci.RequestInitChain{ ChainId: "ethermint_9000-1", Validators: []abci.ValidatorUpdate{}, ConsensusParams: app.DefaultConsensusParams, @@ -122,7 +121,7 @@ func (suite *EvmTestSuite) DoSetupTest(t require.TestingT) { }, ) - suite.ctx = suite.app.BaseApp.NewContext(checkTx, tmproto.Header{ + suite.ctx = suite.app.BaseApp.NewContext(checkTx).WithBlockHeader(tmproto.Header{ Height: 1, ChainID: "ethermint_9000-1", Time: time.Now().UTC(), @@ -157,7 +156,7 @@ func (suite *EvmTestSuite) DoSetupTest(t require.TestingT) { suite.app.AccountKeeper.SetAccount(suite.ctx, acc) valAddr := sdk.ValAddress(address.Bytes()) - validator, err := stakingtypes.NewValidator(valAddr, priv.PubKey(), stakingtypes.Description{}) + validator, err := stakingtypes.NewValidator(valAddr.String(), priv.PubKey(), stakingtypes.Description{}) require.NoError(t, err) err = suite.app.StakingKeeper.SetValidatorByConsAddr(suite.ctx, validator) @@ -167,7 +166,6 @@ func (suite *EvmTestSuite) DoSetupTest(t require.TestingT) { suite.app.StakingKeeper.SetValidator(suite.ctx, validator) suite.ethSigner = ethtypes.LatestSignerForChainID(suite.app.EvmKeeper.ChainID()) - suite.handler = evm.NewHandler(suite.app.EvmKeeper) } func (suite *EvmTestSuite) SetupTest() { @@ -181,7 +179,7 @@ func (suite *EvmTestSuite) SignTx(tx *types.MsgEthereumTx) { } func (suite *EvmTestSuite) StateDB() *statedb.StateDB { - return statedb.New(suite.ctx, suite.app.EvmKeeper, statedb.NewEmptyTxConfig(common.BytesToHash(suite.ctx.HeaderHash().Bytes()))) + return statedb.New(suite.ctx, suite.app.EvmKeeper, statedb.NewEmptyTxConfig(common.BytesToHash(suite.ctx.HeaderHash()))) } func TestEvmTestSuite(t *testing.T) { @@ -241,7 +239,7 @@ func (suite *EvmTestSuite) TestHandleMsgEthereumTx() { suite.SetupTest() // reset //nolint tc.malleate() - res, err := suite.handler(suite.ctx, tx) + res, err := suite.server.EthereumTx(suite.ctx, tx) //nolint if tc.expPass { @@ -282,14 +280,9 @@ func (suite *EvmTestSuite) TestHandlerLogs() { tx := types.NewTx(suite.chainID, 1, nil, big.NewInt(0), gasLimit, gasPrice, nil, nil, bytecode, nil) suite.SignTx(tx) - result, err := suite.handler(suite.ctx, tx) + txResponse, err := suite.server.EthereumTx(suite.ctx, tx) suite.Require().NoError(err, "failed to handle eth tx msg") - var txResponse types.MsgEthereumTxResponse - - err = proto.Unmarshal(result.Data, &txResponse) - suite.Require().NoError(err, "failed to decode result data") - suite.Require().Equal(len(txResponse.Logs), 1) suite.Require().Equal(len(txResponse.Logs[0].Topics), 2) } @@ -357,13 +350,8 @@ func (suite *EvmTestSuite) TestDeployAndCallContract() { tx := types.NewTx(suite.chainID, 1, nil, big.NewInt(0), gasLimit, gasPrice, nil, nil, bytecode, nil) suite.SignTx(tx) - result, err := suite.handler(suite.ctx, tx) + res, err := suite.server.EthereumTx(suite.ctx, tx) suite.Require().NoError(err, "failed to handle eth tx msg") - - var res types.MsgEthereumTxResponse - - err = proto.Unmarshal(result.Data, &res) - suite.Require().NoError(err, "failed to decode result data") suite.Require().Equal(res.VmError, "", "failed to handle eth tx msg") // store - changeOwner @@ -376,11 +364,8 @@ func (suite *EvmTestSuite) TestDeployAndCallContract() { tx = types.NewTx(suite.chainID, 2, &receiver, big.NewInt(0), gasLimit, gasPrice, nil, nil, bytecode, nil) suite.SignTx(tx) - result, err = suite.handler(suite.ctx, tx) + res, err = suite.server.EthereumTx(suite.ctx, tx) suite.Require().NoError(err, "failed to handle eth tx msg") - - err = proto.Unmarshal(result.Data, &res) - suite.Require().NoError(err, "failed to decode result data") suite.Require().Equal(res.VmError, "", "failed to handle eth tx msg") // query - getOwner @@ -388,11 +373,8 @@ func (suite *EvmTestSuite) TestDeployAndCallContract() { tx = types.NewTx(suite.chainID, 2, &receiver, big.NewInt(0), gasLimit, gasPrice, nil, nil, bytecode, nil) suite.SignTx(tx) - result, err = suite.handler(suite.ctx, tx) + res, err = suite.server.EthereumTx(suite.ctx, tx) suite.Require().NoError(err, "failed to handle eth tx msg") - - err = proto.Unmarshal(result.Data, &res) - suite.Require().NoError(err, "failed to decode result data") suite.Require().Equal(res.VmError, "", "failed to handle eth tx msg") // FIXME: correct owner? @@ -408,7 +390,7 @@ func (suite *EvmTestSuite) TestSendTransaction() { tx := types.NewTx(suite.chainID, 1, &common.Address{0x1}, big.NewInt(1), gasLimit, gasPrice, nil, nil, nil, nil) suite.SignTx(tx) - result, err := suite.handler(suite.ctx, tx) + result, err := suite.server.EthereumTx(suite.ctx, tx) suite.Require().NoError(err) suite.Require().NotNil(result) } @@ -470,7 +452,7 @@ func (suite *EvmTestSuite) TestOutOfGasWhenDeployContract() { // Deploy contract - Owner.sol gasLimit := uint64(1) - suite.ctx = suite.ctx.WithGasMeter(sdk.NewGasMeter(gasLimit)) + suite.ctx = suite.ctx.WithGasMeter(storetypes.NewGasMeter(gasLimit)) gasPrice := big.NewInt(10000) bytecode := common.FromHex("0x608060405234801561001057600080fd5b50336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16600073ffffffffffffffffffffffffffffffffffffffff167f342827c97908e5e2f71151c08502a66d44b6f758e3ac2f1de95f02eb95f0a73560405160405180910390a36102c4806100dc6000396000f3fe608060405234801561001057600080fd5b5060043610610053576000357c010000000000000000000000000000000000000000000000000000000090048063893d20e814610058578063a6f9dae1146100a2575b600080fd5b6100606100e6565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6100e4600480360360208110156100b857600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061010f565b005b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146101d1576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260138152602001807f43616c6c6572206973206e6f74206f776e65720000000000000000000000000081525060200191505060405180910390fd5b8073ffffffffffffffffffffffffffffffffffffffff166000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f342827c97908e5e2f71151c08502a66d44b6f758e3ac2f1de95f02eb95f0a73560405160405180910390a3806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505056fea265627a7a72315820f397f2733a89198bc7fed0764083694c5b828791f39ebcbc9e414bccef14b48064736f6c63430005100032") @@ -485,7 +467,7 @@ func (suite *EvmTestSuite) TestOutOfGasWhenDeployContract() { } }() - suite.handler(suite.ctx, tx) + suite.server.EthereumTx(suite.ctx, tx) suite.Require().Fail("panic did not happen") } @@ -498,11 +480,7 @@ func (suite *EvmTestSuite) TestErrorWhenDeployContract() { tx := types.NewTx(suite.chainID, 1, nil, big.NewInt(0), gasLimit, gasPrice, nil, nil, bytecode, nil) suite.SignTx(tx) - result, _ := suite.handler(suite.ctx, tx) - var res types.MsgEthereumTxResponse - - _ = proto.Unmarshal(result.Data, &res) - + res, _ := suite.server.EthereumTx(suite.ctx, tx) suite.Require().Equal("invalid opcode: opcode 0xa6 not defined", res.VmError, "correct evm error") // TODO: snapshot checking diff --git a/x/evm/keeper/abci_test.go b/x/evm/keeper/abci_test.go index cb37ec08a1..42c3a1148b 100644 --- a/x/evm/keeper/abci_test.go +++ b/x/evm/keeper/abci_test.go @@ -9,7 +9,7 @@ func (suite *KeeperTestSuite) TestEndBlock() { em := suite.ctx.EventManager() suite.Require().Equal(0, len(em.Events())) - res := suite.app.EvmKeeper.EndBlock(suite.ctx, types.RequestEndBlock{}) + res := suite.app.EvmKeeper.EndBlock(suite.ctx) suite.Require().Equal([]types.ValidatorUpdate{}, res) // should emit 1 EventTypeBlockBloom event on EndBlock diff --git a/x/evm/keeper/grpc_query_test.go b/x/evm/keeper/grpc_query_test.go index 126f82fdee..f4429adaf0 100644 --- a/x/evm/keeper/grpc_query_test.go +++ b/x/evm/keeper/grpc_query_test.go @@ -392,7 +392,7 @@ func (suite *KeeperTestSuite) TestQueryTxLogs() { suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { suite.SetupTest() // reset - vmdb := statedb.New(suite.ctx, suite.app.EvmKeeper, statedb.NewTxConfig(common.BytesToHash(suite.ctx.HeaderHash().Bytes()), txHash, txIndex, logIndex)) + vmdb := statedb.New(suite.ctx, suite.app.EvmKeeper, statedb.NewTxConfig(common.BytesToHash(suite.ctx.HeaderHash()), txHash, txIndex, logIndex)) tc.malleate(vmdb) suite.Require().NoError(vmdb.Commit()) diff --git a/x/evm/keeper/hooks_test.go b/x/evm/keeper/hooks_test.go index 959de0c3de..fe57524192 100644 --- a/x/evm/keeper/hooks_test.go +++ b/x/evm/keeper/hooks_test.go @@ -67,7 +67,7 @@ func (suite *KeeperTestSuite) TestEvmHooks() { ctx := suite.ctx txHash := common.BigToHash(big.NewInt(1)) vmdb := statedb.New(ctx, k, statedb.NewTxConfig( - common.BytesToHash(ctx.HeaderHash().Bytes()), + common.BytesToHash(ctx.HeaderHash()), txHash, 0, 0, diff --git a/x/evm/keeper/integration_test.go b/x/evm/keeper/integration_test.go index d2a3187caa..9d156fcd50 100644 --- a/x/evm/keeper/integration_test.go +++ b/x/evm/keeper/integration_test.go @@ -21,9 +21,9 @@ import ( "github.com/evmos/ethermint/testutil" "github.com/evmos/ethermint/x/feemarket/types" - dbm "github.com/cosmos/cosmos-db" - abci "github.com/cometbft/cometbft/abci/types" "cosmossdk.io/log" + abci "github.com/cometbft/cometbft/abci/types" + dbm "github.com/cosmos/cosmos-db" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" evmtypes "github.com/evmos/ethermint/x/evm/types" @@ -98,8 +98,8 @@ var _ = Describe("Feemarket", func() { p := malleate() to := tests.GenerateAddress() msgEthereumTx := buildEthTx(privKey, &to, p.gasLimit, p.gasPrice, p.gasFeeCap, p.gasTipCap, p.accesses) - res := deliverEthTx(privKey, msgEthereumTx) - Expect(res.IsOK()).To(Equal(true), "transaction should have succeeded", res.GetLog()) + _, err := deliverEthTx(privKey, msgEthereumTx) + Expect(err).To(BeNil(), "transaction should have succeeded") }, Entry("legacy tx", func() txParams { return txParams{100000, big.NewInt(baseFee), nil, nil, nil} @@ -191,7 +191,7 @@ func setupChain(localMinGasPricesStr string) { // Initialize the chain newapp.InitChain( - abci.RequestInitChain{ + &abci.RequestInitChain{ ChainId: app.ChainID, Validators: []abci.ValidatorUpdate{}, AppStateBytes: stateBytes, @@ -278,13 +278,21 @@ func prepareEthTx(priv *ethsecp256k1.PrivKey, msgEthereumTx *evmtypes.MsgEthereu func checkEthTx(priv *ethsecp256k1.PrivKey, msgEthereumTx *evmtypes.MsgEthereumTx) abci.ResponseCheckTx { bz := prepareEthTx(priv, msgEthereumTx) req := abci.RequestCheckTx{Tx: bz} - res := s.app.BaseApp.CheckTx(req) - return res + res, err := s.app.BaseApp.CheckTx(&req) + if err != nil { + panic(err) + } + + return *res } -func deliverEthTx(priv *ethsecp256k1.PrivKey, msgEthereumTx *evmtypes.MsgEthereumTx) abci.ExecTxResult { - bz := prepareEthTx(priv, msgEthereumTx) - req := abci.RequestDeliverTx{Tx: bz} - res := s.app.BaseApp.DeliverTx(req) - return res +func deliverEthTx(priv *ethsecp256k1.PrivKey, msgEthereumTx *evmtypes.MsgEthereumTx) (*evmtypes.MsgEthereumTxResponse, error) { + //bz := prepareEthTx(priv, msgEthereumTx) + //req := abci.RequestDeliverTx{Tx: bz} + ctx := sdk.WrapSDKContext(s.app.NewContext(false)) + res, err := s.app.EvmKeeper.EthereumTx(ctx, msgEthereumTx) + if err != nil { + return nil, err + } + return res, nil } diff --git a/x/evm/keeper/keeper_test.go b/x/evm/keeper/keeper_test.go index 4bd1ea4f93..77c6ba9c8e 100644 --- a/x/evm/keeper/keeper_test.go +++ b/x/evm/keeper/keeper_test.go @@ -167,7 +167,7 @@ func (suite *KeeperTestSuite) SetupAppWithT(checkTx bool, t require.TestingT) { // Initialize the chain suite.app.InitChain( - abci.RequestInitChain{ + &abci.RequestInitChain{ ChainId: "ethermint_9000-1", Validators: []abci.ValidatorUpdate{}, ConsensusParams: app.DefaultConsensusParams, @@ -176,7 +176,7 @@ func (suite *KeeperTestSuite) SetupAppWithT(checkTx bool, t require.TestingT) { ) } - suite.ctx = suite.app.BaseApp.NewContext(checkTx, tmproto.Header{ + suite.ctx = suite.app.BaseApp.NewContext(checkTx).WithBlockHeader(tmproto.Header{ Height: 1, ChainID: "ethermint_9000-1", Time: time.Now().UTC(), @@ -204,15 +204,13 @@ func (suite *KeeperTestSuite) SetupAppWithT(checkTx bool, t require.TestingT) { types.RegisterQueryServer(queryHelper, suite.app.EvmKeeper) suite.queryClient = types.NewQueryClient(queryHelper) - acc := ðermint.EthAccount{ - BaseAccount: authtypes.NewBaseAccount(sdk.AccAddress(suite.address.Bytes()), nil, 0, 0), - CodeHash: common.BytesToHash(crypto.Keccak256(nil)).String(), - } + acc := suite.app.AccountKeeper.NewAccountWithAddress(suite.ctx, sdk.AccAddress(suite.address.Bytes())).(*ethermint.EthAccount) + acc.CodeHash = common.BytesToHash(crypto.Keccak256(nil)).String() suite.app.AccountKeeper.SetAccount(suite.ctx, acc) valAddr := sdk.ValAddress(suite.address.Bytes()) - validator, err := stakingtypes.NewValidator(valAddr, priv.PubKey(), stakingtypes.Description{}) + validator, err := stakingtypes.NewValidator(valAddr.String(), priv.PubKey(), stakingtypes.Description{}) require.NoError(t, err) err = suite.app.StakingKeeper.SetValidatorByConsAddr(suite.ctx, validator) require.NoError(t, err) @@ -235,15 +233,16 @@ func (suite *KeeperTestSuite) EvmDenom() string { // Commit and begin new block func (suite *KeeperTestSuite) Commit() { - _ = suite.app.Commit() + _, err := suite.app.Commit() + suite.Require().NoError(err) header := suite.ctx.BlockHeader() header.Height += 1 - suite.app.BeginBlock(abci.RequestBeginBlock{ - Header: header, + suite.app.FinalizeBlock(&abci.RequestFinalizeBlock{ + Height: header.Height, }) // update ctx - suite.ctx = suite.app.BaseApp.NewContext(false, header) + suite.ctx = suite.app.BaseApp.NewContext(false).WithBlockHeader(header) queryHelper := baseapp.NewQueryServerTestHelper(suite.ctx, suite.app.InterfaceRegistry()) types.RegisterQueryServer(queryHelper, suite.app.EvmKeeper) @@ -251,7 +250,7 @@ func (suite *KeeperTestSuite) Commit() { } func (suite *KeeperTestSuite) StateDB() *statedb.StateDB { - return statedb.New(suite.ctx, suite.app.EvmKeeper, statedb.NewEmptyTxConfig(common.BytesToHash(suite.ctx.HeaderHash().Bytes()))) + return statedb.New(suite.ctx, suite.app.EvmKeeper, statedb.NewEmptyTxConfig(common.BytesToHash(suite.ctx.HeaderHash()))) } // DeployTestContract deploy a test erc20 contract and returns the contract address @@ -440,7 +439,7 @@ func (suite *KeeperTestSuite) TestBaseFee() { suite.enableFeemarket = tc.enableFeemarket suite.enableLondonHF = tc.enableLondonHF suite.SetupTest() - suite.app.EvmKeeper.BeginBlock(suite.ctx, abci.RequestBeginBlock{}) + suite.app.EvmKeeper.BeginBlock(suite.ctx) params := suite.app.EvmKeeper.GetParams(suite.ctx) ethCfg := params.ChainConfig.EthereumConfig(suite.app.EvmKeeper.ChainID()) baseFee := suite.app.EvmKeeper.GetBaseFee(suite.ctx, ethCfg) diff --git a/x/evm/keeper/state_transition_benchmark_test.go b/x/evm/keeper/state_transition_benchmark_test.go index 9edfdb928c..680e3062dc 100644 --- a/x/evm/keeper/state_transition_benchmark_test.go +++ b/x/evm/keeper/state_transition_benchmark_test.go @@ -7,6 +7,7 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/keyring" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/tx/signing" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core" ethtypes "github.com/ethereum/go-ethereum/core/types" @@ -62,7 +63,7 @@ func newSignedEthTx( return nil, errors.New("unknown transaction type!") } - sig, _, err := krSigner.SignByAddress(addr, ethTx.Hash().Bytes()) + sig, _, err := krSigner.SignByAddress(addr, ethTx.Hash().Bytes(), signing.SignMode_SIGN_MODE_TEXTUAL) if err != nil { return nil, err } diff --git a/x/evm/keeper/state_transition_test.go b/x/evm/keeper/state_transition_test.go index 2f8925613d..e743bf7835 100644 --- a/x/evm/keeper/state_transition_test.go +++ b/x/evm/keeper/state_transition_test.go @@ -5,6 +5,7 @@ import ( "math" "math/big" + storetypes "cosmossdk.io/store/types" "github.com/cometbft/cometbft/crypto/tmhash" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" tmtypes "github.com/cometbft/cometbft/types" @@ -145,8 +146,8 @@ func (suite *KeeperTestSuite) TestGetCoinbaseAddress() { header.ProposerAddress = valConsAddr.Bytes() suite.ctx = suite.ctx.WithBlockHeader(header) - _, found := suite.app.StakingKeeper.GetValidatorByConsAddr(suite.ctx, valConsAddr.Bytes()) - suite.Require().True(found) + _, err = suite.app.StakingKeeper.GetValidatorByConsAddr(suite.ctx, valConsAddr.Bytes()) + suite.Require().NoError(err) suite.Require().NotEmpty(suite.ctx.BlockHeader().ProposerAddress) }, @@ -509,7 +510,7 @@ func (suite *KeeperTestSuite) TestResetGasMeterAndConsumeGas() { suite.SetupTest() // reset panicF := func() { - gm := sdk.NewGasMeter(10) + gm := storetypes.NewGasMeter(10) gm.ConsumeGas(tc.gasConsumed, "") ctx := suite.ctx.WithGasMeter(gm) suite.app.EvmKeeper.ResetGasMeterAndConsumeGas(ctx, tc.gasUsed) diff --git a/x/evm/keeper/statedb_test.go b/x/evm/keeper/statedb_test.go index f700fdfc7e..9689640e48 100644 --- a/x/evm/keeper/statedb_test.go +++ b/x/evm/keeper/statedb_test.go @@ -4,9 +4,9 @@ import ( "fmt" "math/big" + "cosmossdk.io/store/prefix" codectypes "github.com/cosmos/cosmos-sdk/codec/types" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" - "cosmossdk.io/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing" authtx "github.com/cosmos/cosmos-sdk/x/auth/tx" @@ -690,7 +690,7 @@ func (suite *KeeperTestSuite) TestAddLog() { suite.Run(tc.name, func() { suite.SetupTest() vmdb := statedb.New(suite.ctx, suite.app.EvmKeeper, statedb.NewTxConfig( - common.BytesToHash(suite.ctx.HeaderHash().Bytes()), + common.BytesToHash(suite.ctx.HeaderHash()), tc.hash, 0, 0, )) diff --git a/x/evm/statedb/statedb_test.go b/x/evm/statedb/statedb_test.go index bac0645bfa..32feb4af94 100644 --- a/x/evm/statedb/statedb_test.go +++ b/x/evm/statedb/statedb_test.go @@ -5,19 +5,22 @@ import ( "math/big" "testing" - dbm "github.com/cosmos/cosmos-db" "cosmossdk.io/log" - tmproto "github.com/cometbft/cometbft/proto/tendermint/types" + "cosmossdk.io/store/metrics" "cosmossdk.io/store/rootmulti" storetypes "cosmossdk.io/store/types" + tmproto "github.com/cometbft/cometbft/proto/tendermint/types" + dbm "github.com/cosmos/cosmos-db" + sdkaddress "github.com/cosmos/cosmos-sdk/codec/address" + "github.com/cosmos/cosmos-sdk/runtime" sdk "github.com/cosmos/cosmos-sdk/types" authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" + capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" "github.com/ethereum/go-ethereum/common" ethtypes "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/vm" @@ -54,9 +57,9 @@ func (suite *StateDBTestSuite) TestAccount() { txConfig.TxHash = common.BigToHash(big.NewInt(100)) testCases := []struct { name string - malleate func(*statedb.StateDB, sdk.MultiStore) + malleate func(*statedb.StateDB, storetypes.MultiStore) }{ - {"non-exist account", func(db *statedb.StateDB, cms sdk.MultiStore) { + {"non-exist account", func(db *statedb.StateDB, cms storetypes.MultiStore) { suite.Require().Equal(false, db.Exist(address)) suite.Require().Equal(true, db.Empty(address)) suite.Require().Equal(big.NewInt(0), db.GetBalance(address)) @@ -64,7 +67,7 @@ func (suite *StateDBTestSuite) TestAccount() { suite.Require().Equal(common.Hash{}, db.GetCodeHash(address)) suite.Require().Equal(uint64(0), db.GetNonce(address)) }}, - {"empty account", func(db *statedb.StateDB, cms sdk.MultiStore) { + {"empty account", func(db *statedb.StateDB, cms storetypes.MultiStore) { db.CreateAccount(address) suite.Require().NoError(db.Commit()) @@ -81,7 +84,7 @@ func (suite *StateDBTestSuite) TestAccount() { suite.Require().Equal(common.BytesToHash(emptyCodeHash), db.GetCodeHash(address)) suite.Require().Equal(uint64(0), db.GetNonce(address)) }}, - {"suicide", func(db *statedb.StateDB, cms sdk.MultiStore) { + {"suicide", func(db *statedb.StateDB, cms storetypes.MultiStore) { // non-exist account. suite.Require().False(db.Suicide(address)) suite.Require().False(db.HasSuicided(address)) @@ -766,12 +769,12 @@ func CollectContractStorage(db vm.StateDB, address common.Address) statedb.Stora } var ( - testStoreKeys = sdk.NewKVStoreKeys(authtypes.StoreKey, banktypes.StoreKey, evmtypes.StoreKey, "testnative") - testTransientKeys = sdk.NewTransientStoreKeys(evmtypes.TransientKey) - testMemKeys = sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey) + testStoreKeys = storetypes.NewKVStoreKeys(authtypes.StoreKey, banktypes.StoreKey, evmtypes.StoreKey, "testnative") + testTransientKeys = storetypes.NewTransientStoreKeys(evmtypes.TransientKey) + testMemKeys = storetypes.NewMemoryStoreKeys(capabilitytypes.MemStoreKey) ) -func cloneRawState(t *testing.T, cms sdk.MultiStore) map[string]map[string][]byte { +func cloneRawState(t *testing.T, cms storetypes.MultiStore) map[string]map[string][]byte { result := make(map[string]map[string][]byte) for name, key := range testStoreKeys { @@ -790,24 +793,27 @@ func cloneRawState(t *testing.T, cms sdk.MultiStore) map[string]map[string][]byt return result } -func newTestKeeper(t *testing.T, cms sdk.MultiStore) (sdk.Context, *evmkeeper.Keeper) { +func newTestKeeper(t *testing.T, cms storetypes.MultiStore) (sdk.Context, *evmkeeper.Keeper) { appCodec := encoding.MakeConfig(app.ModuleBasics).Codec authAddr := authtypes.NewModuleAddress(govtypes.ModuleName).String() accountKeeper := authkeeper.NewAccountKeeper( - appCodec, testStoreKeys[authtypes.StoreKey], + appCodec, + runtime.NewKVStoreService(testStoreKeys[authtypes.StoreKey]), ethermint.ProtoAccount, map[string][]string{ evmtypes.ModuleName: {authtypes.Minter, authtypes.Burner}, }, + sdkaddress.NewBech32Codec(sdk.GetConfig().GetBech32AccountAddrPrefix()), sdk.GetConfig().GetBech32AccountAddrPrefix(), authAddr, ) bankKeeper := bankkeeper.NewBaseKeeper( appCodec, - testStoreKeys[banktypes.StoreKey], + runtime.NewKVStoreService(testStoreKeys[banktypes.StoreKey]), accountKeeper, map[string]bool{}, authAddr, + log.NewNopLogger(), ) allKeys := make(map[string]storetypes.StoreKey, len(testStoreKeys)+len(testTransientKeys)+len(testMemKeys)) for k, v := range testStoreKeys { @@ -831,9 +837,9 @@ func newTestKeeper(t *testing.T, cms sdk.MultiStore) (sdk.Context, *evmkeeper.Ke return ctx, evmKeeper } -func setupTestEnv(t *testing.T) (sdk.MultiStore, sdk.Context, *evmkeeper.Keeper) { +func setupTestEnv(t *testing.T) (storetypes.MultiStore, sdk.Context, *evmkeeper.Keeper) { db := dbm.NewMemDB() - cms := rootmulti.NewStore(db, log.NewNopLogger()) + cms := rootmulti.NewStore(db, log.NewNopLogger(), metrics.NewNoOpMetrics()) for _, key := range testStoreKeys { cms.MountStoreWithDB(key, storetypes.StoreTypeIAVL, nil) } diff --git a/x/evm/types/msg_test.go b/x/evm/types/msg_test.go index f6dd866dc3..16edf34180 100644 --- a/x/evm/types/msg_test.go +++ b/x/evm/types/msg_test.go @@ -64,7 +64,6 @@ func (suite *MsgsTestSuite) TestMsgEthereumTx_Constructor() { suite.Require().Equal(msg.Type(), types.TypeMsgEthereumTx) // suite.Require().NotNil(msg.To()) suite.Require().Equal(msg.GetMsgs(), []sdk.Msg{msg}) - suite.Require().Empty(msg.GetSigners()) suite.Require().Panics(func() { msg.GetSignBytes() }) msg = types.NewTxContract(nil, 0, nil, 100000, nil, nil, nil, []byte("test"), nil) diff --git a/x/feemarket/keeper/abci_test.go b/x/feemarket/keeper/abci_test.go index 1b9bb25cf9..21271fbf4e 100644 --- a/x/feemarket/keeper/abci_test.go +++ b/x/feemarket/keeper/abci_test.go @@ -24,7 +24,7 @@ func (suite *KeeperTestSuite) TestEndBlock() { "pass", false, func() { - meter := sdk.NewGasMeter(uint64(1000000000)) + meter := storetypes.NewGasMeter(uint64(1000000000)) suite.ctx = suite.ctx.WithBlockGasMeter(meter) suite.app.FeeMarketKeeper.SetTransientBlockGasWanted(suite.ctx, 5000000) }, diff --git a/x/feemarket/keeper/keeper_test.go b/x/feemarket/keeper/keeper_test.go index e1c4d4ce5f..eb06cc6494 100644 --- a/x/feemarket/keeper/keeper_test.go +++ b/x/feemarket/keeper/keeper_test.go @@ -18,7 +18,6 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/crypto/keyring" sdk "github.com/cosmos/cosmos-sdk/types" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" @@ -90,7 +89,7 @@ func (suite *KeeperTestSuite) SetupApp(checkTx bool) { require.NoError(t, err) suite.consAddress = sdk.ConsAddress(priv.PubKey().Address()) - suite.ctx = suite.app.BaseApp.NewContext(checkTx, tmproto.Header{ + suite.ctx = suite.app.BaseApp.NewContext(checkTx).WithBlockHeader(tmproto.Header{ Height: 1, ChainID: "ethermint_9000-1", Time: time.Now().UTC(), @@ -118,18 +117,18 @@ func (suite *KeeperTestSuite) SetupApp(checkTx bool) { types.RegisterQueryServer(queryHelper, suite.app.FeeMarketKeeper) suite.queryClient = types.NewQueryClient(queryHelper) - acc := ðermint.EthAccount{ - BaseAccount: authtypes.NewBaseAccount(sdk.AccAddress(suite.address.Bytes()), nil, 0, 0), - CodeHash: common.BytesToHash(crypto.Keccak256(nil)).String(), - } + acc := suite.app.AccountKeeper.NewAccountWithAddress(suite.ctx, sdk.AccAddress(suite.address.Bytes())).(*ethermint.EthAccount) + acc.CodeHash = common.BytesToHash(crypto.Keccak256(nil)).String() suite.app.AccountKeeper.SetAccount(suite.ctx, acc) valAddr := sdk.ValAddress(suite.address.Bytes()) - validator, err := stakingtypes.NewValidator(valAddr, priv.PubKey(), stakingtypes.Description{}) + validator, err := stakingtypes.NewValidator(valAddr.String(), priv.PubKey(), stakingtypes.Description{}) require.NoError(t, err) validator = stakingkeeper.TestingUpdateValidator(suite.app.StakingKeeper, suite.ctx, validator, true) - err = suite.app.StakingKeeper.Hooks().AfterValidatorCreated(suite.ctx, validator.GetOperator()) + valBz, err := suite.app.StakingKeeper.ValidatorAddressCodec().StringToBytes(validator.GetOperator()) + require.NoError(t, err) + err = suite.app.StakingKeeper.Hooks().AfterValidatorCreated(suite.ctx, valBz) require.NoError(t, err) err = suite.app.StakingKeeper.SetValidatorByConsAddr(suite.ctx, validator) @@ -161,7 +160,7 @@ func (suite *KeeperTestSuite) CommitAfter(t time.Duration) { }) // update ctx - suite.ctx = suite.app.BaseApp.NewContext(false, header) + suite.ctx = suite.app.BaseApp.NewContext(false).WithBlockHeader(header) queryHelper := baseapp.NewQueryServerTestHelper(suite.ctx, suite.app.InterfaceRegistry()) types.RegisterQueryServer(queryHelper, suite.app.FeeMarketKeeper)