Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
exeokan committed Dec 19, 2024
1 parent ee196ec commit 529ec3e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 11 deletions.
44 changes: 38 additions & 6 deletions bin/citrea/tests/evm/tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use alloy_primitives::Address;
use alloy_rpc_types_trace::geth::GethTrace::{self, CallTracer, FourByteTracer};
use alloy_rpc_types_trace::geth::{
CallConfig, CallFrame, FourByteFrame, GethDebugBuiltInTracerType, GethDebugTracerType,
GethDebugTracingOptions,
GethDebugTracingOptions, TraceResult,
};
use citrea_common::SequencerConfig;
use citrea_evm::smart_contracts::{CallerContract, SimpleStorageContract};
Expand Down Expand Up @@ -222,7 +222,14 @@ async fn tracing_tests() -> Result<(), Box<dyn std::error::Error>> {
GethDebugTracerType::BuiltInTracer(GethDebugBuiltInTracerType::CallTracer),
)),
)
.await;
.await
.into_iter()
.map(|trace| match trace {
TraceResult::Success { result, .. } => Ok(result),
_ => anyhow::bail!("Unexpected trace result"),
})
.collect::<Result<Vec<_>, _>>()?;

assert_eq!(traces.len(), 2);
assert_eq!(traces[1], CallTracer(expected_send_eth_trace.clone()));
assert_eq!(traces[0], CallTracer(expected_call_get_trace.clone()));
Expand All @@ -240,7 +247,13 @@ async fn tracing_tests() -> Result<(), Box<dyn std::error::Error>> {
GethDebugTracerType::BuiltInTracer(GethDebugBuiltInTracerType::CallTracer),
)),
)
.await;
.await
.into_iter()
.map(|trace| match trace {
TraceResult::Success { result, .. } => Ok(result),
_ => anyhow::bail!("Unexpected trace result"),
})
.collect::<Result<Vec<_>, _>>()?;

assert_eq!(traces.len(), 2);
assert_eq!(traces[1], CallTracer(expected_send_eth_trace.clone()));
Expand All @@ -253,7 +266,13 @@ async fn tracing_tests() -> Result<(), Box<dyn std::error::Error>> {
GethDebugTracerType::BuiltInTracer(GethDebugBuiltInTracerType::FourByteTracer),
)),
)
.await;
.await
.into_iter()
.map(|trace| match trace {
TraceResult::Success { result, .. } => Ok(result),
_ => anyhow::bail!("Unexpected trace result"),
})
.collect::<Result<Vec<_>, _>>()?;

let expected_call_get_4byte_trace =
serde_json::from_value::<FourByteFrame>(json![{"35c152bd-32": 1, "6d4ce63c-0": 1}])
Expand Down Expand Up @@ -285,7 +304,13 @@ async fn tracing_tests() -> Result<(), Box<dyn std::error::Error>> {
}),
),
)
.await;
.await
.into_iter()
.map(|trace| match trace {
TraceResult::Success { result, .. } => Ok(result),
_ => anyhow::bail!("Unexpected trace result"),
})
.collect::<Result<Vec<_>, _>>()?;

let expected_top_call_only_call_get_trace = serde_json::from_value::<CallFrame>(
json![{"from":"0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266","gas":"0x1886","gasUsed":"0x6b64","to":"0xe7f1725e7734ce288f8367e1bb143e90bb3f0512",
Expand Down Expand Up @@ -313,7 +338,14 @@ async fn tracing_tests() -> Result<(), Box<dyn std::error::Error>> {
GethDebugTracerType::BuiltInTracer(GethDebugBuiltInTracerType::CallTracer),
)),
)
.await;
.await
.into_iter()
.map(|trace| match trace {
TraceResult::Success { result, .. } => Ok(result),
_ => anyhow::bail!("Unexpected trace result"),
})
.collect::<Result<Vec<_>, _>>()?;

assert_eq!(traces.len(), 8);
assert_eq!(traces[5], CallTracer(reth_json));
assert_eq!(traces[6], CallTracer(expected_call_get_trace));
Expand Down
10 changes: 5 additions & 5 deletions bin/citrea/tests/test_client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use alloy::transports::http::{Http, HyperClient};
use alloy_primitives::{Address, Bytes, TxHash, TxKind, B256, U256, U64};
// use reth_rpc_types::TransactionReceipt;
use alloy_rpc_types::AnyNetworkBlock;
use alloy_rpc_types_trace::geth::{GethDebugTracingOptions, GethTrace};
use alloy_rpc_types_trace::geth::{GethDebugTracingOptions, GethTrace, TraceResult};
use citrea_batch_prover::GroupCommitments;
use citrea_evm::{Filter, LogResponse};
use ethereum_rpc::SyncStatus;
Expand Down Expand Up @@ -608,7 +608,7 @@ impl TestClient {
&self,
block_number: BlockNumberOrTag,
opts: Option<GethDebugTracingOptions>,
) -> Vec<GethTrace> {
) -> Vec<TraceResult> {
self.http_client
.request("debug_traceBlockByNumber", rpc_params![block_number, opts])
.await
Expand All @@ -619,7 +619,7 @@ impl TestClient {
&self,
block_hash: B256,
opts: Option<GethDebugTracingOptions>,
) -> Vec<GethTrace> {
) -> Vec<TraceResult> {
self.http_client
.request("debug_traceBlockByHash", rpc_params![block_hash, opts])
.await
Expand All @@ -631,7 +631,7 @@ impl TestClient {
start_block: BlockNumberOrTag,
end_block: BlockNumberOrTag,
opts: Option<GethDebugTracingOptions>,
) -> Vec<GethTrace> {
) -> Vec<TraceResult> {
let mut subscription = self
.ws_client
.subscribe(
Expand All @@ -650,7 +650,7 @@ impl TestClient {
BlockNumberOrTag::Latest => self.eth_block_number().await,
_ => panic!("Only number and latest"),
};
let mut traces: Vec<Vec<GethTrace>> = vec![];
let mut traces: Vec<Vec<TraceResult>> = vec![];
for _ in start_block..end_block {
let block_traces = subscription.next().await.unwrap().unwrap();
traces.push(block_traces);
Expand Down

0 comments on commit 529ec3e

Please sign in to comment.