Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor endpoint #178

Merged
merged 4 commits into from
May 14, 2024
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
51 changes: 45 additions & 6 deletions src/extensions/api/tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use jsonrpsee::server::ServerHandle;
use serde_json::json;
use std::{net::SocketAddr, sync::Arc};
use std::{net::SocketAddr, sync::Arc, time::Duration};
use tokio::sync::mpsc;

use super::eth::EthApi;
Expand Down Expand Up @@ -61,7 +61,14 @@ async fn create_client() -> (
) {
let (addr, server, head_rx, finalized_head_rx, block_hash_rx) = create_server().await;

let client = Client::with_endpoints([format!("ws://{addr}")]).unwrap();
let client = Client::new(
[format!("ws://{addr}")],
Duration::from_secs(1),
Duration::from_secs(1),
None,
None,
)
.unwrap();

(client, server, head_rx, finalized_head_rx, block_hash_rx)
}
Expand Down Expand Up @@ -168,7 +175,14 @@ async fn rotate_endpoint_on_stale() {
let (addr, server, mut head_rx, _, mut block_rx) = create_server().await;
let (addr2, server2, mut head_rx2, _, mut block_rx2) = create_server().await;

let client = Client::with_endpoints([format!("ws://{addr}"), format!("ws://{addr2}")]).unwrap();
let client = Client::new(
[format!("ws://{addr}"), format!("ws://{addr2}")],
Duration::from_secs(1),
Duration::from_secs(1),
None,
None,
)
.unwrap();
let api = SubstrateApi::new(Arc::new(client), std::time::Duration::from_millis(100));

let head = api.get_head();
Expand Down Expand Up @@ -231,7 +245,14 @@ async fn rotate_endpoint_on_head_mismatch() {
let (addr1, server1, mut head_rx1, mut finalized_head_rx1, mut block_rx1) = create_server().await;
let (addr2, server2, mut head_rx2, mut finalized_head_rx2, mut block_rx2) = create_server().await;

let client = Client::with_endpoints([format!("ws://{addr1}"), format!("ws://{addr2}")]).unwrap();
let client = Client::new(
[format!("ws://{addr1}"), format!("ws://{addr2}")],
Duration::from_secs(1),
Duration::from_secs(1),
None,
None,
)
.unwrap();

let client = Arc::new(client);
let api = SubstrateApi::new(client.clone(), std::time::Duration::from_millis(100));
Expand Down Expand Up @@ -332,7 +353,16 @@ async fn rotate_endpoint_on_head_mismatch() {
#[tokio::test]
async fn substrate_background_tasks_abort_on_drop() {
let (addr, _server, mut head_rx, mut finalized_head_rx, _) = create_server().await;
let client = Arc::new(Client::with_endpoints([format!("ws://{addr}")]).unwrap());
let client = Arc::new(
Client::new(
[format!("ws://{addr}")],
Duration::from_secs(1),
Duration::from_secs(1),
None,
None,
)
.unwrap(),
);
let api = SubstrateApi::new(client, std::time::Duration::from_millis(100));

// background tasks started
Expand All @@ -352,7 +382,16 @@ async fn substrate_background_tasks_abort_on_drop() {
#[tokio::test]
async fn eth_background_tasks_abort_on_drop() {
let (addr, _server, mut subscription_rx, mut block_rx) = create_eth_server().await;
let client = Arc::new(Client::with_endpoints([format!("ws://{addr}")]).unwrap());
let client = Arc::new(
Client::new(
[format!("ws://{addr}")],
Duration::from_secs(1),
Duration::from_secs(1),
None,
None,
)
.unwrap(),
);

let api = EthApi::new(client, std::time::Duration::from_millis(100));

Expand Down
Loading
Loading