diff --git a/crates/node-bindings/Cargo.toml b/crates/node-bindings/Cargo.toml index 88c9610e9f1..535223ec3ad 100644 --- a/crates/node-bindings/Cargo.toml +++ b/crates/node-bindings/Cargo.toml @@ -19,6 +19,7 @@ serde_json.workspace = true tempfile.workspace = true thiserror.workspace = true tracing.workspace = true +url.workspace = true [dev-dependencies] rand.workspace = true diff --git a/crates/node-bindings/src/anvil.rs b/crates/node-bindings/src/anvil.rs index d239e522419..a1e9a8d3950 100644 --- a/crates/node-bindings/src/anvil.rs +++ b/crates/node-bindings/src/anvil.rs @@ -11,6 +11,7 @@ use std::{ time::{Duration, Instant}, }; use thiserror::Error; +use url::Url; /// How long we will wait for anvil to indicate that it is ready. const ANVIL_STARTUP_TIMEOUT_MILLIS: u64 = 10_000; @@ -68,6 +69,16 @@ impl AnvilInstance { pub fn ws_endpoint(&self) -> String { format!("ws://localhost:{}", self.port) } + + /// Returns the HTTP endpoint url of this instance + pub fn endpoint_url(&self) -> Url { + Url::parse(&self.endpoint()).unwrap() + } + + /// Returns the Websocket endpoint url of this instance + pub fn ws_endpoint_url(&self) -> Url { + Url::parse(&self.ws_endpoint()).unwrap() + } } impl Drop for AnvilInstance { diff --git a/crates/node-bindings/src/geth.rs b/crates/node-bindings/src/geth.rs index 183092098e2..f9fb479e08a 100644 --- a/crates/node-bindings/src/geth.rs +++ b/crates/node-bindings/src/geth.rs @@ -15,6 +15,7 @@ use std::{ }; use tempfile::tempdir; use thiserror::Error; +use url::Url; /// How long we will wait for geth to indicate that it is ready. const GETH_STARTUP_TIMEOUT: Duration = Duration::from_secs(10); @@ -76,6 +77,16 @@ impl GethInstance { format!("ws://localhost:{}", self.port) } + /// Returns the HTTP endpoint url of this instance + pub fn endpoint_url(&self) -> Url { + Url::parse(&self.endpoint()).unwrap() + } + + /// Returns the Websocket endpoint url of this instance + pub fn ws_endpoint_url(&self) -> Url { + Url::parse(&self.ws_endpoint()).unwrap() + } + /// Returns the path to this instances' IPC socket pub fn ipc_path(&self) -> &Option { &self.ipc