From 0843f7363d043a4ce32125d172b607a5bf36ad3b Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Thu, 21 Mar 2024 12:54:49 +0100 Subject: [PATCH] feat: write instruction result when displaying call traces (#75) See https://github.com/foundry-rs/foundry/pull/7465 --- src/tracing/writer.rs | 20 +++++++++++++------- tests/it/writer.rs | 18 +++++++++--------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/tracing/writer.rs b/src/tracing/writer.rs index a29e5999..09789ad3 100644 --- a/src/tracing/writer.rs +++ b/src/tracing/writer.rs @@ -210,19 +210,25 @@ impl TraceWriter { } 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<()> { diff --git a/tests/it/writer.rs b/tests/it/writer.rs index 7a76cfa6..fc27cf8f 100644 --- a/tests/it/writer.rs +++ b/tests/it/writer.rs @@ -18,7 +18,7 @@ fn basic_trace_printing() { patch_output(&mut s); expect![[r#" . [147802] → new @0xBd770416a3345F91E4B34576cb804a576fa48EB1 - └─ ← 738 bytes of code + └─ ← [Return] 738 bytes of code "#]] .assert_eq(&s); @@ -33,7 +33,7 @@ fn basic_trace_printing() { patch_output(&mut s); expect![[r#" . [2277] 0xBd770416a3345F91E4B34576cb804a576fa48EB1::8381f58a() - └─ ← 0x0000000000000000000000000000000000000000000000000000000000000000 + └─ ← [Return] 0x0000000000000000000000000000000000000000000000000000000000000000 "#]] .assert_eq(&s); @@ -41,7 +41,7 @@ fn basic_trace_printing() { patch_output(&mut s); expect![[r#" . [22390] 0xBd770416a3345F91E4B34576cb804a576fa48EB1::d09de08a() - └─ ← () + └─ ← [Return] "#]] .assert_eq(&s); @@ -49,7 +49,7 @@ fn basic_trace_printing() { patch_output(&mut s); expect![[r#" . [2277] 0xBd770416a3345F91E4B34576cb804a576fa48EB1::8381f58a() - └─ ← 0x0000000000000000000000000000000000000000000000000000000000000001 + └─ ← [Return] 0x0000000000000000000000000000000000000000000000000000000000000001 "#]] .assert_eq(&s); @@ -57,7 +57,7 @@ fn basic_trace_printing() { patch_output(&mut s); expect![[r#" . [5144] 0xBd770416a3345F91E4B34576cb804a576fa48EB1::3fb5c1cb(0000000000000000000000000000000000000000000000000000000000000045) - └─ ← () + └─ ← [Stop] "#]] .assert_eq(&s); @@ -65,7 +65,7 @@ fn basic_trace_printing() { patch_output(&mut s); expect![[r#" . [2277] 0xBd770416a3345F91E4B34576cb804a576fa48EB1::8381f58a() - └─ ← 0x0000000000000000000000000000000000000000000000000000000000000045 + └─ ← [Return] 0x0000000000000000000000000000000000000000000000000000000000000045 "#]] .assert_eq(&s); @@ -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); }