diff --git a/ethers-providers/src/transports/common.rs b/ethers-providers/src/transports/common.rs index 483114cdf..ad8fa6655 100644 --- a/ethers-providers/src/transports/common.rs +++ b/ethers-providers/src/transports/common.rs @@ -212,6 +212,8 @@ impl fmt::Display for Authorization { #[cfg(test)] mod tests { + use ethers_core::types::U64; + use super::*; #[test] @@ -247,10 +249,28 @@ mod tests { } _ => panic!("expected `Error` response"), } + + let response: Response<'_> = + serde_json::from_str(r#"{"jsonrpc":"2.0","result":"0xfa","id":0}"#).unwrap(); + + match response { + Response::Success { id, result } => { + assert_eq!(id, 0); + let result: U64 = serde_json::from_str(result.get()).unwrap(); + assert_eq!(result.as_u64(), 250); + } + _ => panic!("expected `Success` response"), + } } #[test] fn ser_request() { + let request: Request<()> = Request::new(0, "eth_chainId", ()); + assert_eq!( + &serde_json::to_string(&request).unwrap(), + r#"{"id":0,"jsonrpc":"2.0","method":"eth_chainId"}"# + ); + let request: Request<()> = Request::new(300, "method_name", ()); assert_eq!( &serde_json::to_string(&request).unwrap(), diff --git a/ethers-providers/src/transports/http.rs b/ethers-providers/src/transports/http.rs index 56bdf8512..242126d86 100644 --- a/ethers-providers/src/transports/http.rs +++ b/ethers-providers/src/transports/http.rs @@ -149,7 +149,7 @@ impl Provider { /// let provider = Http::new_with_client(url, client); /// ``` pub fn new_with_client(url: impl Into, client: reqwest::Client) -> Self { - Self { id: AtomicU64::new(0), client, url: url.into() } + Self { id: AtomicU64::new(1), client, url: url.into() } } } @@ -164,7 +164,7 @@ impl FromStr for Provider { impl Clone for Provider { fn clone(&self) -> Self { - Self { id: AtomicU64::new(0), client: self.client.clone(), url: self.url.clone() } + Self { id: AtomicU64::new(1), client: self.client.clone(), url: self.url.clone() } } } diff --git a/ethers-providers/src/transports/ws.rs b/ethers-providers/src/transports/ws.rs index 53039b6a4..99e4a4060 100644 --- a/ethers-providers/src/transports/ws.rs +++ b/ethers-providers/src/transports/ws.rs @@ -114,7 +114,7 @@ impl Ws { // Spawn the server WsServer::new(ws, stream).spawn(); - Self { id: Arc::new(AtomicU64::new(0)), instructions: sink } + Self { id: Arc::new(AtomicU64::new(1)), instructions: sink } } /// Returns true if the WS connection is active, false otherwise