From 3ed4aa62322acface2bc1275ba3d8fd22a76e80b Mon Sep 17 00:00:00 2001 From: Enrique Ortiz Date: Mon, 5 Feb 2024 10:23:34 -0400 Subject: [PATCH 1/2] feat(providers): additional missing methods --- crates/providers/src/provider.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/crates/providers/src/provider.rs b/crates/providers/src/provider.rs index ba96982989c..fee70d5a2b1 100644 --- a/crates/providers/src/provider.rs +++ b/crates/providers/src/provider.rs @@ -78,9 +78,15 @@ pub trait TempProvider: Send + Sync { full: bool, ) -> TransportResult>; + /// Gets the client version of the chain client. + async fn get_client_version(&self) -> TransportResult; + /// Gets the chain ID. async fn get_chain_id(&self) -> TransportResult; + /// Gets the network ID. Same as `eth_chainId`. + async fn get_net_version(&self) -> TransportResult; + /// Gets the specified storage value from [Address]. async fn get_storage_at( &self, @@ -276,11 +282,20 @@ impl TempProvider for Provider { self.inner.prepare("eth_getBlockByNumber", (number, full)).await } + /// Gets the client version of the chain client. + async fn get_client_version(&self) -> TransportResult { + self.inner.prepare("web3_clientVersion", ()).await + } + /// Gets the chain ID. async fn get_chain_id(&self) -> TransportResult { self.inner.prepare("eth_chainId", ()).await } + async fn get_net_version(&self) -> TransportResult { + self.inner.prepare("net_version", ()).await + } + /// Gets the specified storage value from [Address]. async fn get_storage_at( &self, @@ -613,6 +628,14 @@ mod tests { assert_eq!(block.header.number.unwrap(), U256::from(num)); } + #[tokio::test] + async fn gets_client_version() { + let anvil = Anvil::new().spawn(); + let provider = Provider::try_from(&anvil.endpoint()).unwrap(); + let version = provider.get_client_version().await.unwrap(); + assert_eq!(version, "anvil/v0.2.0"); + } + #[tokio::test] async fn gets_chain_id() { let chain_id: u64 = 13371337; @@ -622,6 +645,15 @@ mod tests { assert_eq!(chain_id, U64::from(chain_id)); } + #[tokio::test] + async fn gets_network_id() { + let chain_id: u64 = 13371337; + let anvil = Anvil::new().args(["--chain-id", chain_id.to_string().as_str()]).spawn(); + let provider = Provider::try_from(&anvil.endpoint()).unwrap(); + let chain_id = provider.get_net_version().await.unwrap(); + assert_eq!(chain_id, U64::from(chain_id)); + } + #[tokio::test] #[cfg(feature = "anvil")] async fn gets_code_at() { From 9afa5ea6931c6ea7641b68e8214956cf6243427d Mon Sep 17 00:00:00 2001 From: Enrique Ortiz Date: Mon, 5 Feb 2024 10:40:38 -0400 Subject: [PATCH 2/2] comments --- crates/providers/src/provider.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/providers/src/provider.rs b/crates/providers/src/provider.rs index fee70d5a2b1..4192048a788 100644 --- a/crates/providers/src/provider.rs +++ b/crates/providers/src/provider.rs @@ -633,7 +633,7 @@ mod tests { let anvil = Anvil::new().spawn(); let provider = Provider::try_from(&anvil.endpoint()).unwrap(); let version = provider.get_client_version().await.unwrap(); - assert_eq!(version, "anvil/v0.2.0"); + assert!(version.contains("anvil")); } #[tokio::test]