From a09e8a88bdf4bb6dedbe4524e2a3d2a92fe8911a Mon Sep 17 00:00:00 2001 From: Niklas Date: Thu, 3 Feb 2022 12:24:43 +0100 Subject: [PATCH] get rid of needless deps --- test-runtime/Cargo.toml | 1 - test-runtime/build.rs | 23 ++++++++++++++--------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/test-runtime/Cargo.toml b/test-runtime/Cargo.toml index cfa9617bf1..8848fdcd7b 100644 --- a/test-runtime/Cargo.toml +++ b/test-runtime/Cargo.toml @@ -13,4 +13,3 @@ subxt = { path = "../subxt", version = "0.16.0" } sp-core = "4.0.0" async-std = { version = "1.9.0", features = ["attributes", "tokio1"] } which = "4.2.2" -jsonrpsee = { version = "0.8", features = ["http-client"] } diff --git a/test-runtime/build.rs b/test-runtime/build.rs index 2b3b9b2702..3d10978a97 100644 --- a/test-runtime/build.rs +++ b/test-runtime/build.rs @@ -14,10 +14,6 @@ // You should have received a copy of the GNU General Public License // along with subxt. If not, see . -use jsonrpsee::{ - core::client::ClientT, - http_client::HttpClientBuilder, -}; use std::{ env, fs, @@ -35,6 +31,10 @@ use std::{ thread, time, }; +use subxt::rpc::{ + self, + ClientT, +}; static SUBSTRATE_BIN_ENV_VAR: &str = "SUBSTRATE_NODE_PATH"; @@ -54,7 +54,7 @@ async fn run() { let cmd = Command::new(&substrate_bin) .arg("--dev") .arg("--tmp") - .arg(format!("--rpc-port={}", port)) + .arg(format!("--ws-port={}", port)) .spawn(); let mut cmd = match cmd { Ok(cmd) => KillOnDrop(cmd), @@ -67,15 +67,20 @@ async fn run() { let metadata_bytes: sp_core::Bytes = { const MAX_RETRIES: usize = 20; let mut retries = 0; - let rpc_client = HttpClientBuilder::default() - .build(&format!("http://localhost:{}", port)) - .expect("valid URL; qed"); loop { if retries >= MAX_RETRIES { panic!("Cannot connect to substrate node after {} retries", retries); } - let res = rpc_client.request("state_getMetadata", None).await; + + // It might take a while for substrate node that spin up the RPC server. + // Thus, the connection might get rejected a few times. + let res = + match rpc::build_ws_client(&format!("ws://localhost:{}", port)).await { + Ok(c) => c.request("state_getMetadata", None).await, + Err(e) => Err(e), + }; + match res { Ok(res) => { let _ = cmd.kill();