From 781d9ac24003222311cda1b1213437c45b8923c7 Mon Sep 17 00:00:00 2001 From: Eduard Voiculescu Date: Wed, 16 Oct 2024 13:59:51 -0400 Subject: [PATCH] Fix outdated grpc_query tests --- go.mod | 2 +- go.sum | 4 ++-- x/evm/keeper/grpc_query_test.go | 33 +++++++++------------------ x/evm/keeper/state_transition.go | 24 +++++++++++++------ x/evm/keeper/state_transition_test.go | 18 +++++++-------- x/evm/statedb/statedb.go | 2 +- 6 files changed, 41 insertions(+), 42 deletions(-) diff --git a/go.mod b/go.mod index 4972198e46..c4aaadaeff 100644 --- a/go.mod +++ b/go.mod @@ -276,7 +276,7 @@ replace ( cosmossdk.io/x/tx => github.com/InjectiveLabs/cosmos-sdk/x/tx v0.0.0-20240904140803-b4127ecb5410 github.com/cometbft/cometbft => github.com/Injectivelabs/cometbft v0.38.11-inj-5 - github.com/cosmos/cosmos-sdk => github.com/InjectiveLabs/cosmos-sdk v0.50.10-0.20241010141128-de2b5199b23e + github.com/cosmos/cosmos-sdk => github.com/InjectiveLabs/cosmos-sdk v0.50.10-0.20241014111010-224eb95c9eb1 github.com/ethereum/go-ethereum => github.com/InjectiveLabs/go-ethereum v1.9.22-0.20240923100242-5e28e23d353e nhooyr.io/websocket => github.com/coder/websocket v1.8.10 // replaced as instructed here:https://coder.com/blog/websocket ) diff --git a/go.sum b/go.sum index 9e2e7ceb91..3d5d9f2ed5 100644 --- a/go.sum +++ b/go.sum @@ -238,8 +238,8 @@ github.com/DataDog/sketches-go v1.4.2 h1:gppNudE9d19cQ98RYABOetxIhpTCl4m7CnbRZjv github.com/DataDog/sketches-go v1.4.2/go.mod h1:xJIXldczJyyjnbDop7ZZcLxJdV3+7Kra7H1KMgpgkLk= github.com/DataDog/zstd v1.5.5 h1:oWf5W7GtOLgp6bciQYDmhHHjdhYkALu6S/5Ni9ZgSvQ= github.com/DataDog/zstd v1.5.5/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw= -github.com/InjectiveLabs/cosmos-sdk v0.50.10-0.20241010141128-de2b5199b23e h1:fFy5HkvhhCcNsnkwM2pJf7+TiIWs6nOgCct6FLMI9i4= -github.com/InjectiveLabs/cosmos-sdk v0.50.10-0.20241010141128-de2b5199b23e/go.mod h1:DAbn+xjBNvDKXf/XThMI/UADLyJi55Jo+ILfJ0NE4tQ= +github.com/InjectiveLabs/cosmos-sdk v0.50.10-0.20241014111010-224eb95c9eb1 h1:j+uBBPJZ2ibYui/pbRHNtfOxPtSNhMmNWVpKlGSLkIQ= +github.com/InjectiveLabs/cosmos-sdk v0.50.10-0.20241014111010-224eb95c9eb1/go.mod h1:tUXtOv0qMZDlPa6OQE+mPRF4RpMMoT39gR/q3+IbK7s= github.com/InjectiveLabs/cosmos-sdk/client/v2 v2.0.0-20240904140803-b4127ecb5410 h1:gUiyEHPKz+S1vOb3DhVSpUvSreUR7Z/8Hv3OXws/7LA= github.com/InjectiveLabs/cosmos-sdk/client/v2 v2.0.0-20240904140803-b4127ecb5410/go.mod h1:CZcL41HpJPOOayTCO28j8weNBQprG+SRiKX39votypo= github.com/InjectiveLabs/cosmos-sdk/store v0.0.0-20240904140803-b4127ecb5410 h1:6ai8wHEoV48EACjoGpqW8uxuwCcZfYMBU7FEoC0R0lI= diff --git a/x/evm/keeper/grpc_query_test.go b/x/evm/keeper/grpc_query_test.go index 0816ad06b6..d075fbd0c5 100644 --- a/x/evm/keeper/grpc_query_test.go +++ b/x/evm/keeper/grpc_query_test.go @@ -862,7 +862,7 @@ func (suite *GRPCServerTestSuiteSuite) TestTraceTx() { predecessors = []*types.MsgEthereumTx{} }, expPass: true, - traceResponse: "{\"gas\":34828,\"failed\":false,\"returnValue\":\"0000000000000000000000000000000000000000000000000000000000000001\",\"structLogs\":[{\"pc\":0,\"op\":\"PUSH1\",\"gas\":", + traceResponse: "{\"gas\":0,\"failed\":false,\"returnValue\":\"0000000000000000000000000000000000000000000000000000000000000001\",\"structLogs\":[{\"pc\":0,\"op\":\"PUSH1\",\"gas\":", }, { msg: "default trace with filtered response", @@ -875,7 +875,7 @@ func (suite *GRPCServerTestSuiteSuite) TestTraceTx() { predecessors = []*types.MsgEthereumTx{} }, expPass: true, - traceResponse: "{\"gas\":34828,\"failed\":false,\"returnValue\":\"0000000000000000000000000000000000000000000000000000000000000001\",\"structLogs\":[{\"pc\":0,\"op\":\"PUSH1\",\"gas\":", + traceResponse: "{\"gas\":0,\"failed\":false,\"returnValue\":\"0000000000000000000000000000000000000000000000000000000000000001\",\"structLogs\":[{\"pc\":0,\"op\":\"PUSH1\",\"gas\":", enableFeemarket: false, }, { @@ -900,7 +900,7 @@ func (suite *GRPCServerTestSuiteSuite) TestTraceTx() { predecessors = []*types.MsgEthereumTx{} }, expPass: true, - traceResponse: "{\"gas\":34828,\"failed\":false,\"returnValue\":\"0000000000000000000000000000000000000000000000000000000000000001\",\"structLogs\":[{\"pc\":0,\"op\":\"PUSH1\",\"gas\":", + traceResponse: "{\"gas\":0,\"failed\":false,\"returnValue\":\"0000000000000000000000000000000000000000000000000000000000000001\",\"structLogs\":[{\"pc\":0,\"op\":\"PUSH1\",\"gas\":", enableFeemarket: true, }, { @@ -934,7 +934,7 @@ func (suite *GRPCServerTestSuiteSuite) TestTraceTx() { predecessors = append(predecessors, firstTx) }, expPass: true, - traceResponse: "{\"gas\":34828,\"failed\":false,\"returnValue\":\"0000000000000000000000000000000000000000000000000000000000000001\",\"structLogs\":[{\"pc\":0,\"op\":\"PUSH1\",\"gas\":", + traceResponse: "{\"gas\":0,\"failed\":false,\"returnValue\":\"0000000000000000000000000000000000000000000000000000000000000001\",\"structLogs\":[{\"pc\":0,\"op\":\"PUSH1\",\"gas\":", enableFeemarket: false, }, { @@ -1005,7 +1005,7 @@ func (suite *GRPCServerTestSuiteSuite) TestTraceTx() { suite.App.EvmKeeper.SetParams(suite.Ctx, params) }, expPass: true, - traceResponse: "{\"gas\":34828,\"failed\":false,\"returnValue\":\"0000000000000000000000000000000000000000000000000000000000000001\",\"structLogs\":[{\"pc\":0,\"op\":\"PUSH1\",\"gas\":", + traceResponse: "{\"gas\":0,\"failed\":false,\"returnValue\":\"0000000000000000000000000000000000000000000000000000000000000001\",\"structLogs\":[{\"pc\":0,\"op\":\"PUSH1\",\"gas\":", }, { msg: "invalid chain id", @@ -1043,16 +1043,10 @@ func (suite *GRPCServerTestSuiteSuite) TestTraceTx() { res, err := suite.EvmQueryClient.TraceTx(suite.Ctx, &traceReq) if tc.expPass { suite.Require().NoError(err) - // if data is too big, slice the result - if len(res.Data) > 150 { - suite.Require().Equal(tc.traceResponse, string(res.Data[:150])) - } else { - suite.Require().Equal(tc.traceResponse, string(res.Data)) - } + suite.Require().Contains(string(res.Data), tc.traceResponse) if traceConfig == nil || traceConfig.Tracer == "" { var result ethlogger.ExecutionResult suite.Require().NoError(json.Unmarshal(res.Data, &result)) - suite.Require().Positive(result.Gas) } } else { suite.Require().Error(err) @@ -1085,7 +1079,7 @@ func (suite *GRPCServerTestSuiteSuite) TestTraceBlock() { traceConfig = nil }, expPass: true, - traceResponse: "[{\"result\":{\"gas\":34828,\"failed\":false,\"returnValue\":\"0000000000000000000000000000000000000000000000000000000000000001\",\"structLogs\":[{\"pc\":0,\"op\":\"PU", + traceResponse: "[{\"result\":{\"gas\":0,\"failed\":false,\"returnValue\":\"0000000000000000000000000000000000000000000000000000000000000001\",\"structLogs\":[{\"pc\":0,\"op\":\"PU", }, { msg: "filtered trace", @@ -1097,7 +1091,7 @@ func (suite *GRPCServerTestSuiteSuite) TestTraceBlock() { } }, expPass: true, - traceResponse: "[{\"result\":{\"gas\":34828,\"failed\":false,\"returnValue\":\"0000000000000000000000000000000000000000000000000000000000000001\",\"structLogs\":[{\"pc\":0,\"op\":\"PU", + traceResponse: "[{\"result\":{\"gas\":0,\"failed\":false,\"returnValue\":\"0000000000000000000000000000000000000000000000000000000000000001\",\"structLogs\":[{\"pc\":0,\"op\":\"PU", }, { msg: "javascript tracer", @@ -1119,7 +1113,7 @@ func (suite *GRPCServerTestSuiteSuite) TestTraceBlock() { } }, expPass: true, - traceResponse: "[{\"result\":{\"gas\":34828,\"failed\":false,\"returnValue\":\"0000000000000000000000000000000000000000000000000000000000000001\",\"structLogs\":[{\"pc\":0,\"op\":\"PU", + traceResponse: "[{\"result\":{\"gas\":0,\"failed\":false,\"returnValue\":\"0000000000000000000000000000000000000000000000000000000000000001\",\"structLogs\":[{\"pc\":0,\"op\":\"PU", enableFeemarket: true, }, { @@ -1152,7 +1146,7 @@ func (suite *GRPCServerTestSuiteSuite) TestTraceBlock() { txs = append([]*types.MsgEthereumTx{}, firstTx, secondTx) }, expPass: true, - traceResponse: "[{\"result\":{\"gas\":34828,\"failed\":false,\"returnValue\":\"0000000000000000000000000000000000000000000000000000000000000001\",\"structLogs\":[{\"pc\":0,\"op\":\"PU", + traceResponse: "[{\"result\":{\"gas\":0,\"failed\":false,\"returnValue\":\"0000000000000000000000000000000000000000000000000000000000000001\",\"structLogs\":[{\"pc\":0,\"op\":\"PU", enableFeemarket: false, }, { @@ -1221,12 +1215,7 @@ func (suite *GRPCServerTestSuiteSuite) TestTraceBlock() { res, err := suite.EvmQueryClient.TraceBlock(suite.Ctx, &traceReq) if tc.expPass { suite.Require().NoError(err) - // if data is too big, slice the result - if len(res.Data) > 150 { - suite.Require().Equal(tc.traceResponse, string(res.Data[:150])) - } else { - suite.Require().Contains(string(res.Data), tc.traceResponse) - } + suite.Require().Contains(string(res.Data), tc.traceResponse) } else { suite.Require().Error(err) } diff --git a/x/evm/keeper/state_transition.go b/x/evm/keeper/state_transition.go index 370db8e06d..c80107c30d 100644 --- a/x/evm/keeper/state_transition.go +++ b/x/evm/keeper/state_transition.go @@ -364,14 +364,24 @@ func (k *Keeper) ApplyMessageWithConfig( Data: msg.Data, }) - if cfg.Tracer != nil && cfg.Tracer.OnCosmosTxStart != nil { + if cfg.Tracer != nil { stateDB.SetTracer(cfg.Tracer) - cfg.Tracer.OnCosmosTxStart( - evm.GetVMContext(), - tx, - cfg.TxConfig.TxHash, - msg.From, - ) + + // If a cosmos tracer is set, the OnCosmosTxStart takes precedence over OnTxStart + if cfg.Tracer.OnCosmosTxStart != nil { + cfg.Tracer.OnCosmosTxStart( + evm.GetVMContext(), + tx, + cfg.TxConfig.TxHash, + msg.From, + ) + } else if cfg.Tracer.OnTxStart != nil { + cfg.Tracer.OnTxStart( + evm.GetVMContext(), + tx, + msg.From, + ) + } } rules := cfg.Rules diff --git a/x/evm/keeper/state_transition_test.go b/x/evm/keeper/state_transition_test.go index d0d9f154e1..5660fcbec7 100644 --- a/x/evm/keeper/state_transition_test.go +++ b/x/evm/keeper/state_transition_test.go @@ -641,7 +641,8 @@ func (suite *StateTransitionTestSuite) TestApplyMessage() { suite.Require().False(res.Failed()) } -func (suite *StateTransitionTestSuite) TestApplyMessageTracer() { +// TODO: add TestApplyTransactionWithTracer() +func (suite *StateTransitionTestSuite) TestApplyMessageWithConfigTracer() { expectedGasUsed := params.TxGas var msg *core.Message @@ -649,20 +650,19 @@ func (suite *StateTransitionTestSuite) TestApplyMessageTracer() { suite.Ctx = suite.Ctx.WithCometInfo(NewMockCometInfo()) suite.Ctx = suite.Ctx.WithConsensusParams(*testutil.DefaultConsensusParams) - _, err := suite.App.EvmKeeper.EVMConfig(suite.Ctx, big.NewInt(9000), common.Hash{}) + t, err := types.NewFirehoseCosmosLiveTracer() + require.NoError(suite.T(), err) + suite.Ctx = cosmostracing.SetCtxBlockchainTracer(suite.Ctx, t) + suite.App.EvmKeeper.SetTracer(t) + + cfgWithTracer, err := suite.App.EvmKeeper.EVMConfigWithTracer(suite.Ctx, big.NewInt(9000), common.Hash{}) suite.Require().NoError(err) keeperParams := suite.App.EvmKeeper.GetParams(suite.Ctx) chainCfg := keeperParams.ChainConfig.EthereumConfig(suite.App.EvmKeeper.ChainID()) - rules := chainCfg.Rules(big.NewInt(suite.Ctx.BlockHeight()), chainCfg.MergeNetsplitBlock != nil, uint64(suite.Ctx.BlockHeader().Time.Unix())) signer := ethtypes.LatestSignerForChainID(suite.App.EvmKeeper.ChainID()) - tracer := types.NewTracer("", msg, rules) vmdb := suite.StateDB() - t, err := types.NewFirehoseCosmosLiveTracer() - require.NoError(suite.T(), err) - suite.Ctx = cosmostracing.SetCtxBlockchainTracer(suite.Ctx, t) - onCosmosTxStartHookCalled := false onGasChangedHookCalled := false onEnterHookCalled := false @@ -714,7 +714,7 @@ func (suite *StateTransitionTestSuite) TestApplyMessageTracer() { // manually call begin block err = suite.App.EvmKeeper.BeginBlock(suite.Ctx) suite.Require().NoError(err) - res, err := suite.App.EvmKeeper.ApplyMessage(suite.Ctx, msg, tracer, true) + res, err := suite.App.EvmKeeper.ApplyMessageWithConfig(suite.Ctx, msg, cfgWithTracer, true) suite.Require().NoError(err) suite.Require().Equal(expectedGasUsed, res.GasUsed) diff --git a/x/evm/statedb/statedb.go b/x/evm/statedb/statedb.go index 17ca7495d9..2458ff3ce5 100644 --- a/x/evm/statedb/statedb.go +++ b/x/evm/statedb/statedb.go @@ -214,7 +214,7 @@ func (s *StateDB) Empty(addr common.Address) bool { // GetBalance retrieves the balance from the given address or 0 if object not found func (s *StateDB) GetBalance(addr common.Address) *uint256.Int { - bal := s.keeper.GetBalance(s.ctx, sdk.AccAddress(addr.Bytes()), s.evmDenom) + bal := s.keeper.GetBalance(s.ctx, addr.Bytes(), s.evmDenom) return uint256.MustFromBig(bal) }