Skip to content

Commit 4c0173f

Browse files
committed
Add test for function level trace
commit-id:14569926
1 parent b329d45 commit 4c0173f

File tree

2 files changed

+97
-9
lines changed

2 files changed

+97
-9
lines changed

crates/forge-runner/src/debugging/component.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ pub enum Component {
1919
CallType,
2020
/// The result of the call, transformed for display.
2121
CallResult,
22+
/// The function trace, will be only shown if the contract is not a fork.
23+
FunctionTrace,
2224
}
2325
impl Component {
2426
/// Returns minimal [`TraceVerbosity`] for the component.
@@ -30,7 +32,8 @@ impl Component {
3032
Component::ContractAddress
3133
| Component::CallerAddress
3234
| Component::EntryPointType
33-
| Component::CallType => TraceVerbosity::Detailed,
35+
| Component::CallType
36+
| Component::FunctionTrace => TraceVerbosity::Detailed,
3437
}
3538
}
3639
}
@@ -45,6 +48,7 @@ impl From<&Component> for debugging::Component {
4548
Component::CallerAddress => debugging::Component::CallerAddress,
4649
Component::CallType => debugging::Component::CallType,
4750
Component::CallResult => debugging::Component::CallResult,
51+
Component::FunctionTrace => debugging::Component::FunctionTrace,
4852
}
4953
}
5054
}

crates/forge/tests/e2e/debugging.rs

Lines changed: 92 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ fn test_output(trace_message_fn: fn(&str) -> String) -> String {
143143
}
144144
}
145145

146+
#[expect(clippy::too_many_lines)]
146147
fn detailed_debugging_trace_message(test_name: &str) -> String {
147148
formatdoc! {r"
148149
[test name] trace_info_integrationtest::test_trace::test_debugging_trace_{test_name}
@@ -154,6 +155,40 @@ fn detailed_debugging_trace_message(test_name: &str) -> String {
154155
│ ├─ [caller address] [..]
155156
│ ├─ [call type] Call
156157
│ ├─ [call result] success: array![RecursiveCall {{ contract_address: ContractAddress([..]), payload: array![RecursiveCall {{ contract_address: ContractAddress([..]), payload: array![] }}, RecursiveCall {{ contract_address: ContractAddress([..]), payload: array![] }}] }}, RecursiveCall {{ contract_address: ContractAddress([..]), payload: array![] }}]
158+
│ ├─ [function call tree]
159+
│ │ └─ [non inlined] trace_info::SimpleContract::__wrapper__RecursiveCallerImpl__execute_calls
160+
│ │ ├─ [non inlined] core::array::ArraySerde::deserialize
161+
│ │ │ └─ [non inlined] core::array::deserialize_array_helper
162+
│ │ │ └─ [non inlined] trace_info::RecursiveCallSerde::deserialize
163+
│ │ │ └─ [non inlined] core::array::ArraySerde::deserialize
164+
│ │ │ └─ [non inlined] core::array::deserialize_array_helper
165+
│ │ │ └─ [non inlined] trace_info::RecursiveCallSerde::deserialize
166+
│ │ │ └─ [non inlined] core::array::ArraySerde::deserialize
167+
│ │ │ └─ [non inlined] core::array::deserialize_array_helper
168+
│ │ ├─ [non inlined] trace_info::SimpleContract::RecursiveCallerImpl::execute_calls[182-514]
169+
│ │ │ ├─ [non inlined] core::array::ArrayTCloneImpl::clone
170+
│ │ │ │ └─ [non inlined] core::array::ArrayTCloneImpl::clone[120-295]
171+
│ │ │ │ └─ [non inlined] trace_info::RecursiveCallClone::clone
172+
│ │ │ │ └─ [non inlined] core::array::ArrayTCloneImpl::clone
173+
│ │ │ │ └─ [non inlined] core::array::ArrayTCloneImpl::clone[120-295]
174+
│ │ │ ├─ [non inlined] core::array::ArraySerde::serialize
175+
│ │ │ │ └─ [non inlined] core::array::serialize_array_helper
176+
│ │ │ │ └─ [non inlined] trace_info::RecursiveCallSerde::serialize
177+
│ │ │ │ └─ [non inlined] core::array::ArraySerde::serialize
178+
│ │ │ │ └─ [non inlined] core::array::serialize_array_helper
179+
│ │ │ └─ [non inlined] core::array::ArraySerde::deserialize
180+
│ │ │ └─ [non inlined] core::array::deserialize_array_helper
181+
│ │ │ └─ [non inlined] trace_info::RecursiveCallSerde::deserialize
182+
│ │ │ └─ [non inlined] core::array::ArraySerde::deserialize
183+
│ │ │ └─ [non inlined] core::array::deserialize_array_helper
184+
│ │ └─ [non inlined] core::array::ArraySerde::serialize
185+
│ │ └─ [non inlined] core::array::serialize_array_helper
186+
│ │ └─ [non inlined] trace_info::RecursiveCallSerde::serialize
187+
│ │ └─ [non inlined] core::array::ArraySerde::serialize
188+
│ │ └─ [non inlined] core::array::serialize_array_helper
189+
│ │ └─ [non inlined] trace_info::RecursiveCallSerde::serialize
190+
│ │ └─ [non inlined] core::array::ArraySerde::serialize
191+
│ │ └─ [non inlined] core::array::serialize_array_helper
157192
│ ├─ [selector] execute_calls
158193
│ │ ├─ [contract name] SimpleContract
159194
│ │ ├─ [entry point type] External
@@ -162,38 +197,81 @@ fn detailed_debugging_trace_message(test_name: &str) -> String {
162197
│ │ ├─ [caller address] [..]
163198
│ │ ├─ [call type] Call
164199
│ │ ├─ [call result] success: array![RecursiveCall {{ contract_address: ContractAddress([..]), payload: array![] }}, RecursiveCall {{ contract_address: ContractAddress([..]), payload: array![] }}]
200+
│ │ ├─ [function call tree]
201+
│ │ │ └─ [non inlined] trace_info::SimpleContract::__wrapper__RecursiveCallerImpl__execute_calls
202+
│ │ │ ├─ [non inlined] core::array::ArraySerde::deserialize
203+
│ │ │ │ └─ [non inlined] core::array::deserialize_array_helper
204+
│ │ │ │ └─ [non inlined] trace_info::RecursiveCallSerde::deserialize
205+
│ │ │ │ └─ [non inlined] core::array::ArraySerde::deserialize
206+
│ │ │ │ └─ [non inlined] core::array::deserialize_array_helper
207+
│ │ │ ├─ [non inlined] trace_info::SimpleContract::RecursiveCallerImpl::execute_calls[182-514]
208+
│ │ │ │ ├─ [non inlined] core::array::ArrayTCloneImpl::clone
209+
│ │ │ │ │ └─ [non inlined] core::array::ArrayTCloneImpl::clone[120-295]
210+
│ │ │ │ ├─ [non inlined] core::array::ArraySerde::serialize
211+
│ │ │ │ │ └─ [non inlined] core::array::serialize_array_helper
212+
│ │ │ │ └─ [non inlined] core::array::ArraySerde::deserialize
213+
│ │ │ │ └─ [non inlined] core::array::deserialize_array_helper
214+
│ │ │ └─ [non inlined] core::array::ArraySerde::serialize
215+
│ │ │ └─ [non inlined] core::array::serialize_array_helper
216+
│ │ │ └─ [non inlined] trace_info::RecursiveCallSerde::serialize
217+
│ │ │ └─ [non inlined] core::array::ArraySerde::serialize
218+
│ │ │ └─ [non inlined] core::array::serialize_array_helper
165219
│ │ ├─ [selector] execute_calls
166220
│ │ │ ├─ [contract name] SimpleContract
167221
│ │ │ ├─ [entry point type] External
168222
│ │ │ ├─ [calldata] array![]
169223
│ │ │ ├─ [contract address] [..]
170224
│ │ │ ├─ [caller address] [..]
171225
│ │ │ ├─ [call type] Call
172-
│ │ │ └─ [call result] success: array![]
226+
│ │ │ ├─ [call result] success: array![]
227+
│ │ │ └─ [function call tree]
228+
│ │ │ └─ [non inlined] trace_info::SimpleContract::__wrapper__RecursiveCallerImpl__execute_calls
229+
│ │ │ ├─ [non inlined] core::array::ArraySerde::deserialize
230+
│ │ │ │ └─ [non inlined] core::array::deserialize_array_helper
231+
│ │ │ ├─ [non inlined] trace_info::SimpleContract::RecursiveCallerImpl::execute_calls[182-514]
232+
│ │ │ └─ [non inlined] core::array::ArraySerde::serialize
233+
│ │ │ └─ [non inlined] core::array::serialize_array_helper
173234
│ │ └─ [selector] execute_calls
174235
│ │ ├─ [contract name] SimpleContract
175236
│ │ ├─ [entry point type] External
176237
│ │ ├─ [calldata] array![]
177238
│ │ ├─ [contract address] [..]
178239
│ │ ├─ [caller address] [..]
179240
│ │ ├─ [call type] Call
180-
│ │ └─ [call result] success: array![]
241+
│ │ ├─ [call result] success: array![]
242+
│ │ └─ [function call tree]
243+
│ │ └─ [non inlined] trace_info::SimpleContract::__wrapper__RecursiveCallerImpl__execute_calls
244+
│ │ ├─ [non inlined] core::array::ArraySerde::deserialize
245+
│ │ │ └─ [non inlined] core::array::deserialize_array_helper
246+
│ │ ├─ [non inlined] trace_info::SimpleContract::RecursiveCallerImpl::execute_calls[182-514]
247+
│ │ └─ [non inlined] core::array::ArraySerde::serialize
248+
│ │ └─ [non inlined] core::array::serialize_array_helper
181249
│ └─ [selector] execute_calls
182250
│ ├─ [contract name] SimpleContract
183251
│ ├─ [entry point type] External
184252
│ ├─ [calldata] array![]
185253
│ ├─ [contract address] [..]
186254
│ ├─ [caller address] [..]
187255
│ ├─ [call type] Call
188-
│ └─ [call result] success: array![]
256+
│ ├─ [call result] success: array![]
257+
│ └─ [function call tree]
258+
│ └─ [non inlined] trace_info::SimpleContract::__wrapper__RecursiveCallerImpl__execute_calls
259+
│ ├─ [non inlined] core::array::ArraySerde::deserialize
260+
│ │ └─ [non inlined] core::array::deserialize_array_helper
261+
│ ├─ [non inlined] trace_info::SimpleContract::RecursiveCallerImpl::execute_calls[182-514]
262+
│ └─ [non inlined] core::array::ArraySerde::serialize
263+
│ └─ [non inlined] core::array::serialize_array_helper
189264
└─ [selector] fail
190265
├─ [contract name] SimpleContract
191266
├─ [entry point type] External
192267
├─ [calldata] array![0x1, 0x2, 0x3, 0x4, 0x5]
193268
├─ [contract address] [..]
194269
├─ [caller address] [..]
195270
├─ [call type] Call
196-
└─ [call result] panic: (0x1, 0x2, 0x3, 0x4, 0x5)
271+
├─ [call result] panic: (0x1, 0x2, 0x3, 0x4, 0x5)
272+
└─ [function call tree]
273+
└─ [non inlined] trace_info::SimpleContract::__wrapper__FailingImpl__fail
274+
└─ [non inlined] core::array::deserialize_array_helper
197275
"}
198276
}
199277

@@ -208,6 +286,7 @@ fn detailed_debugging_trace_message_fork(test_name: &str) -> String {
208286
│ ├─ [caller address] [..]
209287
│ ├─ [call type] Call
210288
│ ├─ [call result] success: array![RecursiveCall {{ contract_address: ContractAddress([..]), payload: array![RecursiveCall {{ contract_address: ContractAddress([..]), payload: array![] }}, RecursiveCall {{ contract_address: ContractAddress([..]), payload: array![] }}] }}, RecursiveCall {{ contract_address: ContractAddress([..]), payload: array![] }}]
289+
│ ├─ [function trace error] function trace is not supported for forked contracts
211290
│ ├─ [selector] execute_calls
212291
│ │ ├─ [contract name] forked contract
213292
│ │ ├─ [entry point type] External
@@ -216,38 +295,43 @@ fn detailed_debugging_trace_message_fork(test_name: &str) -> String {
216295
│ │ ├─ [caller address] [..]
217296
│ │ ├─ [call type] Call
218297
│ │ ├─ [call result] success: array![RecursiveCall {{ contract_address: ContractAddress([..]), payload: array![] }}, RecursiveCall {{ contract_address: ContractAddress([..]), payload: array![] }}]
298+
│ │ ├─ [function trace error] function trace is not supported for forked contracts
219299
│ │ ├─ [selector] execute_calls
220300
│ │ │ ├─ [contract name] forked contract
221301
│ │ │ ├─ [entry point type] External
222302
│ │ │ ├─ [calldata] array![]
223303
│ │ │ ├─ [contract address] [..]
224304
│ │ │ ├─ [caller address] [..]
225305
│ │ │ ├─ [call type] Call
226-
│ │ │ └─ [call result] success: array![]
306+
│ │ │ ├─ [call result] success: array![]
307+
│ │ │ └─ [function trace error] function trace is not supported for forked contracts
227308
│ │ └─ [selector] execute_calls
228309
│ │ ├─ [contract name] forked contract
229310
│ │ ├─ [entry point type] External
230311
│ │ ├─ [calldata] array![]
231312
│ │ ├─ [contract address] [..]
232313
│ │ ├─ [caller address] [..]
233314
│ │ ├─ [call type] Call
234-
│ │ └─ [call result] success: array![]
315+
│ │ ├─ [call result] success: array![]
316+
│ │ └─ [function trace error] function trace is not supported for forked contracts
235317
│ └─ [selector] execute_calls
236318
│ ├─ [contract name] forked contract
237319
│ ├─ [entry point type] External
238320
│ ├─ [calldata] array![]
239321
│ ├─ [contract address] [..]
240322
│ ├─ [caller address] [..]
241323
│ ├─ [call type] Call
242-
│ └─ [call result] success: array![]
324+
│ ├─ [call result] success: array![]
325+
│ └─ [function trace error] function trace is not supported for forked contracts
243326
└─ [selector] fail
244327
├─ [contract name] forked contract
245328
├─ [entry point type] External
246329
├─ [calldata] array![0x1, 0x2, 0x3, 0x4, 0x5]
247330
├─ [contract address] [..]
248331
├─ [caller address] [..]
249332
├─ [call type] Call
250-
└─ [call result] panic: (0x1, 0x2, 0x3, 0x4, 0x5)
333+
├─ [call result] panic: (0x1, 0x2, 0x3, 0x4, 0x5)
334+
└─ [function trace error] function trace is not supported for forked contracts
251335
"}
252336
}
253337

0 commit comments

Comments
 (0)