From 9bba37b7a9f979f05a38594bf89e57f52aee294c Mon Sep 17 00:00:00 2001 From: xermicus Date: Mon, 24 Mar 2025 09:42:51 +0100 Subject: [PATCH] the geth version Signed-off-by: xermicus --- crates/node/src/geth.rs | 21 +++++++++++++++++++++ crates/node/src/lib.rs | 3 +++ 2 files changed, 24 insertions(+) diff --git a/crates/node/src/geth.rs b/crates/node/src/geth.rs index 4866d29..7000633 100644 --- a/crates/node/src/geth.rs +++ b/crates/node/src/geth.rs @@ -207,6 +207,18 @@ impl Node for Instance { _ => anyhow::bail!("expected a diff mode trace"), } } + + fn version(&self) -> anyhow::Result { + let output = Command::new(&self.geth) + .arg("--version") + .stdin(Stdio::null()) + .stdout(Stdio::piped()) + .stderr(Stdio::null()) + .spawn()? + .wait_with_output()? + .stdout; + Ok(String::from_utf8_lossy(&output).into()) + } } impl Drop for Instance { @@ -252,4 +264,13 @@ mod tests { .spawn(GENESIS_JSON.to_string()) .unwrap(); } + + #[test] + fn version_works() { + let version = Instance::new(&test_config().0).unwrap().version().unwrap(); + assert!( + version.starts_with("geth version"), + "expected version string, got: '{version}'" + ); + } } diff --git a/crates/node/src/lib.rs b/crates/node/src/lib.rs index ca52c04..a98e995 100644 --- a/crates/node/src/lib.rs +++ b/crates/node/src/lib.rs @@ -25,4 +25,7 @@ pub trait Node: EthereumNode { /// Returns the state diff of the transaction hash in the [TransactionReceipt]. fn state_diff(&self, transaction: TransactionReceipt) -> anyhow::Result; + + /// Returns the node version. + fn version(&self) -> anyhow::Result; }