-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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(traces
): show state changes in cast run
and forge test
on -vvvvv
#9013
Changes from 26 commits
9bf8320
dceddb0
5546575
28ef6a9
99a6914
c6ca2b6
68f5887
7bad232
4b6af4f
16da772
8b7807c
5d66616
a0143fe
e041926
b52f8c8
73b0323
4511b2a
e9b1e3e
5420f26
d45b1b8
0f983d9
9aa2894
cb48139
f45e4cc
af9ee80
0e11203
44fbe73
ca94656
85f9571
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,10 @@ extern crate foundry_common; | |
#[macro_use] | ||
extern crate tracing; | ||
|
||
use foundry_common::contracts::{ContractsByAddress, ContractsByArtifact}; | ||
use foundry_common::{ | ||
contracts::{ContractsByAddress, ContractsByArtifact}, | ||
shell, | ||
}; | ||
use revm::interpreter::OpCode; | ||
use revm_inspectors::tracing::{ | ||
types::{DecodedTraceStep, TraceMemberOrder}, | ||
|
@@ -183,15 +186,23 @@ pub async fn decode_trace_arena( | |
|
||
/// Render a collection of call traces to a string. | ||
pub fn render_trace_arena(arena: &SparsedTraceArena) -> String { | ||
render_trace_arena_with_bytecodes(arena, false) | ||
render_trace_arena_inner(arena, false, false) | ||
} | ||
|
||
/// Render a collection of call traces to a string optionally including contract creation bytecodes. | ||
pub fn render_trace_arena_with_bytecodes( | ||
/// Render a collection of call traces to a string optionally including contract creation bytecodes | ||
/// and in JSON format. | ||
pub fn render_trace_arena_inner( | ||
arena: &SparsedTraceArena, | ||
with_bytecodes: bool, | ||
with_storage_changes: bool, | ||
) -> String { | ||
let mut w = TraceWriter::new(Vec::<u8>::new()).write_bytecodes(with_bytecodes); | ||
if shell::is_json() { | ||
return serde_json::to_string(&arena.resolve_arena()).expect("Failed to write traces"); | ||
} | ||
|
||
let mut w = TraceWriter::new(Vec::<u8>::new()) | ||
.write_bytecodes(with_bytecodes) | ||
.with_storage_changes(with_storage_changes); | ||
w.write_arena(&arena.resolve_arena()).expect("Failed to write traces"); | ||
String::from_utf8(w.into_writer()).expect("trace writer wrote invalid UTF-8") | ||
} | ||
|
@@ -289,6 +300,8 @@ pub enum TraceMode { | |
/// | ||
/// Used by debugger. | ||
Debug, | ||
/// Debug trace with storage changes. | ||
RecordStateDiff, | ||
} | ||
|
||
impl TraceMode { | ||
|
@@ -308,6 +321,10 @@ impl TraceMode { | |
matches!(self, Self::Jump) | ||
} | ||
|
||
pub const fn record_state_diff(self) -> bool { | ||
matches!(self, Self::RecordStateDiff) | ||
} | ||
|
||
pub const fn is_debug(self) -> bool { | ||
matches!(self, Self::Debug) | ||
} | ||
|
@@ -324,6 +341,14 @@ impl TraceMode { | |
std::cmp::max(self, mode.into()) | ||
} | ||
|
||
pub fn with_state_changes(self, yes: bool) -> Self { | ||
if yes { | ||
std::cmp::max(self, Self::RecordStateDiff) | ||
} else { | ||
self | ||
} | ||
} | ||
|
||
pub fn with_verbosity(self, verbosiy: u8) -> Self { | ||
if verbosiy >= 3 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. one suggestion for separate improvement @zerosnacks There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added a ticket for it here: #9426 |
||
std::cmp::max(self, Self::Call) | ||
|
@@ -345,7 +370,7 @@ impl TraceMode { | |
StackSnapshotType::None | ||
}, | ||
record_logs: true, | ||
record_state_diff: false, | ||
record_state_diff: self.record_state_diff(), | ||
record_returndata_snapshots: self.is_debug(), | ||
record_opcodes_filter: (self.is_jump() || self.is_jump_simple()) | ||
.then(|| OpcodeFilter::new().enabled(OpCode::JUMP).enabled(OpCode::JUMPDEST)), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of introducing a new arg I would prefer we use the global verbosity (
-vvv
) flag hereIt is accessible through
shell::verbosity()