Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(rpc-testing-utils) : implement debug_traceCall JSON-RPC method #5418

Merged
merged 3 commits into from
Nov 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 40 additions & 2 deletions crates/rpc/rpc-testing-util/src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ use futures::{Stream, StreamExt};
use jsonrpsee::core::Error as RpcError;
use reth_primitives::{BlockId, TxHash, B256};
use reth_rpc_api::{clients::DebugApiClient, EthApiClient};
use reth_rpc_types::trace::geth::{GethDebugTracerType, GethDebugTracingOptions};
use reth_rpc_types::{
trace::geth::{GethDebugTracerType, GethDebugTracingOptions},
CallRequest,
};
use std::{
pin::Pin,
task::{Context, Poll},
};

const NOOP_TRACER: &str = include_str!("../assets/noop-tracer.js");
const JS_TRACER_TEMPLATE: &str = include_str!("../assets/tracer-template.js");

Expand Down Expand Up @@ -37,6 +39,19 @@ pub trait DebugApiExt {
) -> Result<DebugTraceTransactionsStream<'_>, jsonrpsee::core::Error>
where
B: Into<BlockId> + Send;
/// method for debug_traceCall
async fn debug_trace_call_json(
&self,
request: CallRequest,
opts: GethDebugTracingOptions,
) -> Result<serde_json::Value, jsonrpsee::core::Error>;

/// method for debug_traceCall using raw JSON strings for the request and options.
async fn debug_trace_call_raw_json(
&self,
request_json: String,
opts_json: String,
) -> Result<serde_json::Value, RpcError>;
}

#[async_trait::async_trait]
Expand Down Expand Up @@ -81,6 +96,29 @@ where

Ok(DebugTraceTransactionsStream { stream: Box::pin(stream) })
}
async fn debug_trace_call_json(
&self,
request: CallRequest,
opts: GethDebugTracingOptions,
) -> Result<serde_json::Value, jsonrpsee::core::Error> {
let mut params = jsonrpsee::core::params::ArrayParams::new();
params.insert(request).unwrap();
params.insert(opts).unwrap();
self.request("debug_traceCall", params).await
}

async fn debug_trace_call_raw_json(
&self,
request_json: String,
opts_json: String,
) -> Result<serde_json::Value, RpcError> {
let request = serde_json::from_str::<CallRequest>(&request_json)
.map_err(|e| RpcError::Custom(e.to_string()))?;
let opts = serde_json::from_str::<GethDebugTracingOptions>(&opts_json)
.map_err(|e| RpcError::Custom(e.to_string()))?;

self.debug_trace_call_json(request, opts).await
}
}

/// A helper type that can be used to build a javascript tracer.
Expand Down
Loading