From 1675da892b77f49a557edda27c13cdff4347d161 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Sat, 1 Feb 2025 08:46:08 +0100 Subject: [PATCH] fix: opt-in to keep stdout (#1985) * fix: opt-in to keep stdout * docs --- crates/node-bindings/src/nodes/anvil.rs | 14 +++++++++++++- crates/node-bindings/src/nodes/reth.rs | 15 ++++++++++++++- crates/provider/src/provider/trait.rs | 2 +- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/crates/node-bindings/src/nodes/anvil.rs b/crates/node-bindings/src/nodes/anvil.rs index d1e410359cb..1247ab8c2ee 100644 --- a/crates/node-bindings/src/nodes/anvil.rs +++ b/crates/node-bindings/src/nodes/anvil.rs @@ -136,6 +136,7 @@ pub struct Anvil { fork_block_number: Option, args: Vec, timeout: Option, + keep_stdout: bool, } impl Anvil { @@ -261,6 +262,14 @@ impl Anvil { self } + /// Keep the handle to anvil's stdout in order to read from it. + /// + /// Caution: if the stdout handle isn't used, this can end up blocking. + pub const fn keep_stdout(mut self) -> Self { + self.keep_stdout = true; + self + } + /// Consumes the builder and spawns `anvil`. /// /// # Panics @@ -360,7 +369,10 @@ impl Anvil { } } - child.stdout = Some(reader.into_inner()); + if self.keep_stdout { + // re-attach the stdout handle if requested + child.stdout = Some(reader.into_inner()); + } Ok(AnvilInstance { child, diff --git a/crates/node-bindings/src/nodes/reth.rs b/crates/node-bindings/src/nodes/reth.rs index 53d393df0de..182101b7d28 100644 --- a/crates/node-bindings/src/nodes/reth.rs +++ b/crates/node-bindings/src/nodes/reth.rs @@ -162,6 +162,7 @@ pub struct Reth { chain_or_path: Option, genesis: Option, args: Vec, + keep_stdout: bool, } impl Reth { @@ -187,6 +188,7 @@ impl Reth { chain_or_path: None, genesis: None, args: Vec::new(), + keep_stdout: false, } } @@ -309,6 +311,14 @@ impl Reth { self } + /// Keep the handle to reth's stdout in order to read from it. + /// + /// Caution: if the stdout handle isn't used, this can end up blocking. + pub const fn keep_stdout(mut self) -> Self { + self.keep_stdout = true; + self + } + /// Adds an argument to pass to `reth`. /// /// Pass any arg that is not supported by the builder. @@ -510,7 +520,10 @@ impl Reth { } } - child.stdout = Some(reader.into_inner()); + if self.keep_stdout { + // re-attach the stdout handle if requested + child.stdout = Some(reader.into_inner()); + } Ok(RethInstance { pid: child, diff --git a/crates/provider/src/provider/trait.rs b/crates/provider/src/provider/trait.rs index f569483294c..eba0994d662 100644 --- a/crates/provider/src/provider/trait.rs +++ b/crates/provider/src/provider/trait.rs @@ -1956,7 +1956,7 @@ mod tests { #[tokio::test] async fn capture_anvil_logs() { - let mut anvil = Anvil::new().spawn(); + let mut anvil = Anvil::new().keep_stdout().spawn(); let provider = ProviderBuilder::new().on_http(anvil.endpoint_url());