diff --git a/evmrpc/tracers.go b/evmrpc/tracers.go index 0f46916b84..32645d6908 100644 --- a/evmrpc/tracers.go +++ b/evmrpc/tracers.go @@ -8,6 +8,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/eth/tracers" _ "github.com/ethereum/go-ethereum/eth/tracers/native" // run init()s to register native tracers + "github.com/ethereum/go-ethereum/lib/ethapi" "github.com/ethereum/go-ethereum/rpc" "github.com/sei-protocol/sei-chain/x/evm/keeper" rpcclient "github.com/tendermint/tendermint/rpc/client" @@ -28,20 +29,30 @@ func NewDebugAPI(tmClient rpcclient.Client, k *keeper.Keeper, ctxProvider func(i return &DebugAPI{tracersAPI: tracersAPI, tmClient: tmClient, keeper: k, ctxProvider: ctxProvider, txDecoder: txDecoder, connectionType: connectionType} } -func (api *DebugAPI) TraceTransaction(ctx context.Context, hash common.Hash, config *tracers.TraceConfig) (interface{}, error) { +func (api *DebugAPI) TraceTransaction(ctx context.Context, hash common.Hash, config *tracers.TraceConfig) (result interface{}, returnErr error) { startTime := time.Now() - defer recordMetrics("debug_traceTransaction", api.connectionType, startTime, true) - return api.tracersAPI.TraceTransaction(ctx, hash, config) + defer recordMetrics("debug_traceTransaction", api.connectionType, startTime, returnErr == nil) + result, returnErr = api.tracersAPI.TraceTransaction(ctx, hash, config) + return } -func (api *DebugAPI) TraceBlockByNumber(ctx context.Context, number rpc.BlockNumber, config *tracers.TraceConfig) (interface{}, error) { +func (api *DebugAPI) TraceBlockByNumber(ctx context.Context, number rpc.BlockNumber, config *tracers.TraceConfig) (result interface{}, returnErr error) { startTime := time.Now() - defer recordMetrics("debug_traceBlockByNumber", api.connectionType, startTime, true) - return api.tracersAPI.TraceBlockByNumber(ctx, number, config) + defer recordMetrics("debug_traceBlockByNumber", api.connectionType, startTime, returnErr == nil) + result, returnErr = api.tracersAPI.TraceBlockByNumber(ctx, number, config) + return } -func (api *DebugAPI) TraceBlockByHash(ctx context.Context, hash common.Hash, config *tracers.TraceConfig) (interface{}, error) { +func (api *DebugAPI) TraceBlockByHash(ctx context.Context, hash common.Hash, config *tracers.TraceConfig) (result interface{}, returnErr error) { startTime := time.Now() - defer recordMetrics("debug_traceBlockByHash", api.connectionType, startTime, true) - return api.tracersAPI.TraceBlockByHash(ctx, hash, config) + defer recordMetrics("debug_traceBlockByHash", api.connectionType, startTime, returnErr == nil) + result, returnErr = api.tracersAPI.TraceBlockByHash(ctx, hash, config) + return +} + +func (api *DebugAPI) TraceCall(ctx context.Context, args ethapi.TransactionArgs, blockNrOrHash rpc.BlockNumberOrHash, config *tracers.TraceCallConfig) (result interface{}, returnErr error) { + startTime := time.Now() + defer recordMetrics("debug_traceCall", api.connectionType, startTime, returnErr == nil) + result, returnErr = api.tracersAPI.TraceCall(ctx, args, blockNrOrHash, config) + return } diff --git a/evmrpc/tracers_test.go b/evmrpc/tracers_test.go index d3f2584605..9667758de8 100644 --- a/evmrpc/tracers_test.go +++ b/evmrpc/tracers_test.go @@ -1,8 +1,10 @@ package evmrpc_test import ( + "fmt" "testing" + testkeeper "github.com/sei-protocol/sei-chain/testutil/keeper" "github.com/stretchr/testify/require" ) @@ -69,3 +71,18 @@ func TestTraceBlockByHash(t *testing.T) { result = resObj["result"].([]interface{})[0].(map[string]interface{})["result"].(map[string]interface{}) require.Equal(t, 3, len(result)) } + +func TestTraceCall(t *testing.T) { + _, from := testkeeper.MockAddressPair() + _, contractAddr := testkeeper.MockAddressPair() + txArgs := map[string]interface{}{ + "from": from.Hex(), + "to": contractAddr.Hex(), + "chainId": fmt.Sprintf("%#x", EVMKeeper.ChainID(Ctx)), + } + + resObj := sendRequestGoodWithNamespace(t, "debug", "traceCall", txArgs, "0x65") + result := resObj["result"].(map[string]interface{}) + require.Equal(t, float64(21000), result["gas"]) + require.Equal(t, false, result["failed"]) +}