Skip to content

Commit

Permalink
feat: write instruction result when displaying call traces (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes authored Mar 21, 2024
1 parent 2b48b65 commit 0843f73
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
20 changes: 13 additions & 7 deletions src/tracing/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,19 +210,25 @@ impl<W: Write> TraceWriter<W> {
}

fn write_trace_footer(&mut self, trace: &CallTrace) -> io::Result<()> {
write!(self.writer, "{style}{RETURN}{style:#}", style = self.trace_style(trace))?;
write!(
self.writer,
"{style}{RETURN}[{status:?}] {style:#}",
style = self.trace_style(trace),
status = trace.status,
)?;

// TODO:
// if let Some(decoded) = trace.decoded_return_data {
// return self.writer.write_all(decoded.as_bytes());
// }

if trace.kind.is_any_create() {
write!(self.writer, "{} bytes of code", trace.output.len())
} else if trace.output.is_empty() {
self.writer.write_all(b"()")
} else {
write!(self.writer, "{}", trace.output)
write!(self.writer, "{} bytes of code", trace.output.len())?;
} else if !trace.output.is_empty() {
write!(self.writer, "{}", trace.output)?;
}
// TODO: Write `trace.status`?

Ok(())
}

fn write_indentation(&mut self) -> io::Result<()> {
Expand Down
18 changes: 9 additions & 9 deletions tests/it/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn basic_trace_printing() {
patch_output(&mut s);
expect![[r#"
. [147802] → new <unknown>@0xBd770416a3345F91E4B34576cb804a576fa48EB1
└─ ← 738 bytes of code
└─ ← [Return] 738 bytes of code
"#]]
.assert_eq(&s);

Expand All @@ -33,39 +33,39 @@ fn basic_trace_printing() {
patch_output(&mut s);
expect![[r#"
. [2277] 0xBd770416a3345F91E4B34576cb804a576fa48EB1::8381f58a()
└─ ← 0x0000000000000000000000000000000000000000000000000000000000000000
└─ ← [Return] 0x0000000000000000000000000000000000000000000000000000000000000000
"#]]
.assert_eq(&s);

let mut s = call(Counter::incrementCall {}.abi_encode());
patch_output(&mut s);
expect![[r#"
. [22390] 0xBd770416a3345F91E4B34576cb804a576fa48EB1::d09de08a()
└─ ← ()
└─ ← [Return]
"#]]
.assert_eq(&s);

let mut s = call(Counter::numberCall {}.abi_encode());
patch_output(&mut s);
expect![[r#"
. [2277] 0xBd770416a3345F91E4B34576cb804a576fa48EB1::8381f58a()
└─ ← 0x0000000000000000000000000000000000000000000000000000000000000001
└─ ← [Return] 0x0000000000000000000000000000000000000000000000000000000000000001
"#]]
.assert_eq(&s);

let mut s = call(Counter::setNumberCall { newNumber: U256::from(69) }.abi_encode());
patch_output(&mut s);
expect![[r#"
. [5144] 0xBd770416a3345F91E4B34576cb804a576fa48EB1::3fb5c1cb(0000000000000000000000000000000000000000000000000000000000000045)
└─ ← ()
└─ ← [Stop]
"#]]
.assert_eq(&s);

let mut s = call(Counter::numberCall {}.abi_encode());
patch_output(&mut s);
expect![[r#"
. [2277] 0xBd770416a3345F91E4B34576cb804a576fa48EB1::8381f58a()
└─ ← 0x0000000000000000000000000000000000000000000000000000000000000045
└─ ← [Return] 0x0000000000000000000000000000000000000000000000000000000000000045
"#]]
.assert_eq(&s);

Expand All @@ -81,12 +81,12 @@ fn basic_trace_printing() {
│ │ ├─ emit topic 0: 0x4ada34a03bac92ee05461fb68ac194ed75b2b3ac9c428a50c1240505512954d5
│ │ │ topic 1: 0x0000000000000000000000000000000000000000000000000000000000000046
│ │ │ data: 0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000968692066726f6d20330000000000000000000000000000000000000000000000
│ │ └─ ← ()
│ │ └─ ← [Return]
│ ├─ emit topic 0: 0x4544f35949a681d9e47cca4aa47bb4add2aad7bf475fac397d0eddc4efe69eda
│ │ topic 1: 0x0000000000000000000000000000000000000000000000000000000000000046
│ │ data: 0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000968692066726f6d20320000000000000000000000000000000000000000000000
│ └─ ← ()
└─ ← ()
│ └─ ← [Return]
└─ ← [Return]
"#]]
.assert_eq(&s);
}
Expand Down

0 comments on commit 0843f73

Please sign in to comment.