Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Danil <[email protected]>
  • Loading branch information
Deniallugo committed Sep 23, 2024
1 parent df636c9 commit 8476a21
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 49 deletions.
12 changes: 6 additions & 6 deletions core/lib/types/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ pub struct GetLogsFilter {
#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct ResultDebugCall {
pub result: CallTracerResult,
pub result: DebugCall,
}

#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
Expand Down Expand Up @@ -734,18 +734,18 @@ pub enum BlockStatus {

/// FlatTracer is always more than one trace, so when we have to trace one transaction it also appeared as many traces
#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase", untagged)]
#[serde(untagged)]
pub enum CallTracerResult {
CallTrace(DebugCall),
FlattCallTrace(Box<Vec<DebugCallFlat>>),
CallTrace(ResultDebugCall),
FlattCallTrace(Vec<DebugCallFlat>),
}

/// For tracing blocks we need to have all traces being combined all together without separation.
#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase", untagged)]
#[serde(untagged)]
pub enum CallTracerOption {
CallTrace(DebugCall),
FlattCallTrace(Box<DebugCallFlat>),
FlattCallTrace(Vec<DebugCallFlat>),
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down
8 changes: 4 additions & 4 deletions core/lib/web3_decl/src/namespaces/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,27 @@ pub trait DebugNamespace {
&self,
block: BlockNumber,
options: Option<TracerConfig>,
) -> RpcResult<Vec<CallTracerOption>>;
) -> RpcResult<Vec<CallTracerResult>>;

#[method(name = "traceBlockByHash")]
async fn trace_block_by_hash(
&self,
hash: H256,
options: Option<TracerConfig>,
) -> RpcResult<Vec<CallTracerOption>>;
) -> RpcResult<Vec<CallTracerResult>>;

#[method(name = "traceCall")]
async fn trace_call(
&self,
request: CallRequest,
block: Option<BlockId>,
options: Option<TracerConfig>,
) -> RpcResult<CallTracerResult>;
) -> RpcResult<CallTracerOption>;

#[method(name = "traceTransaction")]
async fn trace_transaction(
&self,
tx_hash: H256,
options: Option<TracerConfig>,
) -> RpcResult<Option<CallTracerResult>>;
) -> RpcResult<Option<CallTracerOption>>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl DebugNamespaceServer for DebugNamespace {
&self,
block: BlockNumber,
options: Option<TracerConfig>,
) -> RpcResult<Vec<CallTracerOption>> {
) -> RpcResult<Vec<CallTracerResult>> {
self.debug_trace_block_impl(BlockId::Number(block), options)
.await
.map_err(|err| self.current_method().map_err(err))
Expand All @@ -26,7 +26,7 @@ impl DebugNamespaceServer for DebugNamespace {
&self,
hash: H256,
options: Option<TracerConfig>,
) -> RpcResult<Vec<CallTracerOption>> {
) -> RpcResult<Vec<CallTracerResult>> {
self.debug_trace_block_impl(BlockId::Hash(hash), options)
.await
.map_err(|err| self.current_method().map_err(err))
Expand All @@ -37,7 +37,7 @@ impl DebugNamespaceServer for DebugNamespace {
request: CallRequest,
block: Option<BlockId>,
options: Option<TracerConfig>,
) -> RpcResult<CallTracerResult> {
) -> RpcResult<CallTracerOption> {
self.debug_trace_call_impl(request, block, options)
.await
.map_err(|err| self.current_method().map_err(err))
Expand All @@ -47,7 +47,7 @@ impl DebugNamespaceServer for DebugNamespace {
&self,
tx_hash: H256,
options: Option<TracerConfig>,
) -> RpcResult<Option<CallTracerResult>> {
) -> RpcResult<Option<CallTracerOption>> {
self.debug_trace_transaction_impl(tx_hash, options)
.await
.map_err(|err| self.current_method().map_err(err))
Expand Down
45 changes: 23 additions & 22 deletions core/node/api_server/src/web3/namespaces/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use zksync_system_constants::MAX_ENCODED_TX_SIZE;
use zksync_types::{
api::{
BlockId, BlockNumber, CallTracerOption, CallTracerResult, DebugCall, DebugCallType,
SupportedTracers, TracerConfig,
ResultDebugCall, SupportedTracers, TracerConfig,
},
debug_flat_call::{Action, CallResult, DebugCallFlat},
fee_model::BatchFeeInput,
Expand Down Expand Up @@ -58,7 +58,7 @@ impl DebugNamespace {
index: usize,
transaction_hash: H256,
tracer_option: Option<TracerConfig>,
) -> CallTracerResult {
) -> CallTracerOption {
let (only_top_call, flatten) = tracer_option
.map(|options| {
(
Expand All @@ -78,9 +78,9 @@ impl DebugNamespace {
index,
transaction_hash,
);
CallTracerResult::FlattCallTrace(Box::new(calls))
CallTracerOption::FlattCallTrace(calls)
} else {
CallTracerResult::CallTrace(Self::map_default_call(call, only_top_call))
CallTracerOption::CallTrace(Self::map_default_call(call, only_top_call))
}
}
pub(crate) fn map_default_call(call: Call, only_top_call: bool) -> DebugCall {
Expand Down Expand Up @@ -183,7 +183,7 @@ impl DebugNamespace {
&self,
block_id: BlockId,
options: Option<TracerConfig>,
) -> Result<Vec<CallTracerOption>, Web3Error> {
) -> Result<Vec<CallTracerResult>, Web3Error> {
self.current_method().set_block_id(block_id);
if matches!(block_id, BlockId::Number(BlockNumber::Pending)) {
// See `EthNamespace::get_block_impl()` for an explanation why this check is needed.
Expand All @@ -200,30 +200,31 @@ impl DebugNamespace {
.get_traces_for_l2_block(block_number)
.await
.map_err(DalError::generalize)?;
let call_trace = call_traces
.into_iter()
.flat_map(|(call_trace, hash, index)| {
match Self::map_call(call_trace, index, hash, options) {
CallTracerResult::CallTrace(call) => {
vec![CallTracerOption::CallTrace(call)]
}
CallTracerResult::FlattCallTrace(call) => call
.into_iter()
.map(Box::new)
.map(CallTracerOption::FlattCallTrace)
.collect(),

let mut calls = vec![];
let mut flat_calls = vec![];
for (call_trace, hash, index) in call_traces {
match Self::map_call(call_trace, index, hash, options) {
CallTracerOption::CallTrace(call) => {
calls.push(CallTracerResult::CallTrace(ResultDebugCall {
result: call,
}))
}
})
.collect();
CallTracerOption::FlattCallTrace(mut call) => flat_calls.append(&mut call),
}
}
if calls.is_empty() && !flat_calls.is_empty() {
calls.push(CallTracerResult::FlattCallTrace(flat_calls))
}

Ok(call_trace)
Ok(calls)
}

pub async fn debug_trace_transaction_impl(
&self,
tx_hash: H256,
options: Option<TracerConfig>,
) -> Result<Option<CallTracerResult>, Web3Error> {
) -> Result<Option<CallTracerOption>, Web3Error> {
let mut connection = self.state.acquire_connection().await?;
let call_trace = connection
.transactions_dal()
Expand All @@ -239,7 +240,7 @@ impl DebugNamespace {
mut request: CallRequest,
block_id: Option<BlockId>,
options: Option<TracerConfig>,
) -> Result<CallTracerResult, Web3Error> {
) -> Result<CallTracerOption, Web3Error> {
let block_id = block_id.unwrap_or(BlockId::Number(BlockNumber::Pending));
self.current_method().set_block_id(block_id);

Expand Down
12 changes: 8 additions & 4 deletions core/node/api_server/src/web3/tests/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
use zksync_multivm::interface::{Call, TransactionExecutionResult};
use zksync_types::{
api::{CallTracerConfig, CallTracerOption, CallTracerResult, SupportedTracers, TracerConfig},
api::{
CallTracerConfig, CallTracerOption, CallTracerResult, ResultDebugCall, SupportedTracers,
TracerConfig,
},
BOOTLOADER_ADDRESS,
};
use zksync_web3_decl::{
Expand Down Expand Up @@ -65,7 +68,7 @@ impl HttpTest for TraceBlockTest {

assert_eq!(block_traces.len(), tx_results.len()); // equals to the number of transactions in the block
for (trace, tx_result) in block_traces.iter().zip(&tx_results) {
let CallTracerOption::CallTrace(result) = trace else {
let CallTracerResult::CallTrace(ResultDebugCall { result }) = trace else {
unreachable!()
};
assert_eq!(result.from, Address::zero());
Expand Down Expand Up @@ -159,9 +162,10 @@ impl HttpTest for TraceBlockFlatTest {
.map(|&i| block_traces[i].clone());

for (top_level_trace, tx_result) in top_level_traces.zip(&tx_results) {
let CallTracerOption::FlattCallTrace(top_level_trace) = top_level_trace else {
let CallTracerResult::FlattCallTrace(top_level_trace) = top_level_trace else {
unreachable!()
};
let top_level_trace = top_level_trace.first().unwrap();
assert_eq!(top_level_trace.action.from, Address::zero());
assert_eq!(top_level_trace.action.to, BOOTLOADER_ADDRESS);
assert_eq!(
Expand Down Expand Up @@ -227,7 +231,7 @@ impl HttpTest for TraceTransactionTest {
.map(|call| DebugNamespace::map_default_call(call.clone(), false))
.collect();

let CallTracerResult::CallTrace(result) = client
let CallTracerOption::CallTrace(result) = client
.trace_transaction(tx_results[0].hash, None)
.await?
.context("no transaction traces")?
Expand Down
14 changes: 7 additions & 7 deletions core/node/api_server/src/web3/tests/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use zksync_multivm::interface::{
ExecutionResult, VmExecutionLogs, VmExecutionResultAndLogs, VmRevertReason,
};
use zksync_types::{
api::{ApiStorageLog, CallTracerResult},
api::{ApiStorageLog, CallTracerOption},
get_intrinsic_constants,
transaction_request::CallRequest,
K256PrivateKey, L2ChainId, PackedEthSignature, StorageLogKind, StorageLogWithPreviousValue,
Expand Down Expand Up @@ -430,14 +430,14 @@ impl HttpTest for TraceCallTest {
drop(connection);

let call_request = CallTest::call_request(b"pending");
let CallTracerResult::CallTrace(call_result) =
let CallTracerOption::CallTrace(call_result) =
client.trace_call(call_request.clone(), None, None).await?
else {
unreachable!()
};
Self::assert_debug_call(&call_request, &call_result);
let pending_block_number = api::BlockId::Number(api::BlockNumber::Pending);
let CallTracerResult::CallTrace(call_result) = client
let CallTracerOption::CallTrace(call_result) = client
.trace_call(call_request.clone(), Some(pending_block_number), None)
.await?
else {
Expand All @@ -448,7 +448,7 @@ impl HttpTest for TraceCallTest {
let latest_block_numbers = [api::BlockNumber::Latest, 1.into()];
let call_request = CallTest::call_request(b"latest");
for number in latest_block_numbers {
let CallTracerResult::CallTrace(call_result) = client
let CallTracerOption::CallTrace(call_result) = client
.trace_call(
call_request.clone(),
Some(api::BlockId::Number(number)),
Expand Down Expand Up @@ -505,14 +505,14 @@ impl HttpTest for TraceCallTestAfterSnapshotRecovery {
_pool: &ConnectionPool<Core>,
) -> anyhow::Result<()> {
let call_request = CallTest::call_request(b"pending");
let CallTracerResult::CallTrace(call_result) =
let CallTracerOption::CallTrace(call_result) =
client.trace_call(call_request.clone(), None, None).await?
else {
unreachable!()
};
TraceCallTest::assert_debug_call(&call_request, &call_result);
let pending_block_number = api::BlockId::Number(api::BlockNumber::Pending);
let CallTracerResult::CallTrace(call_result) = client
let CallTracerOption::CallTrace(call_result) = client
.trace_call(call_request.clone(), Some(pending_block_number), None)
.await?
else {
Expand All @@ -535,7 +535,7 @@ impl HttpTest for TraceCallTestAfterSnapshotRecovery {
let first_l2_block_numbers = [api::BlockNumber::Latest, first_local_l2_block.0.into()];
for number in first_l2_block_numbers {
let number = api::BlockId::Number(number);
let CallTracerResult::CallTrace(call_result) = client
let CallTracerOption::CallTrace(call_result) = client
.trace_call(call_request.clone(), Some(number), None)
.await?
else {
Expand Down
4 changes: 2 additions & 2 deletions core/tests/ts-integration/tests/api/debug.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ describe('Debug methods', () => {
input: expect.any(String),
output: '0x',
to: BOOTLOADER_FORMAL_ADDRESS,
type: 'Call',
type: 'call',
value: expect.any(String),
calls: expect.any(Array)
// We intentionally skip `error` and `revertReason` fields: the block may contain failing txs
Expand All @@ -99,7 +99,7 @@ describe('Debug methods', () => {
output: '0x',
revertReason: null,
to: BOOTLOADER_FORMAL_ADDRESS,
type: 'Call',
type: 'call',
value: '0x0',
calls: expect.any(Array)
};
Expand Down

0 comments on commit 8476a21

Please sign in to comment.