Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

fix: all request ids start at 1 #1265

Merged
merged 1 commit into from
May 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions ethers-providers/src/transports/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ impl fmt::Display for Authorization {

#[cfg(test)]
mod tests {
use ethers_core::types::U64;

use super::*;

#[test]
Expand Down Expand Up @@ -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(),
Expand Down
4 changes: 2 additions & 2 deletions ethers-providers/src/transports/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl Provider {
/// let provider = Http::new_with_client(url, client);
/// ```
pub fn new_with_client(url: impl Into<Url>, client: reqwest::Client) -> Self {
Self { id: AtomicU64::new(0), client, url: url.into() }
Self { id: AtomicU64::new(1), client, url: url.into() }
}
}

Expand All @@ -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() }
}
}

Expand Down
2 changes: 1 addition & 1 deletion ethers-providers/src/transports/ws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down