mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 05:51:02 +00:00
add wasm support (#700)
* get started * make it work again * make it compile again * Use async-wasm-feature of jsonrpsee from the master branch * Ensure we enable JS feature of getrandom for the wasm target * Update subxt/src/lib.rs * update jsonrpsee * fix CI * cargo fmt * fix wasm test * fix grumbles * exclude wasm-tests from workspace To avoid leaking `jsonrpsee-web` feature into the workspace Co-authored-by: Igor Matuszewski <xanewok@gmail.com>
This commit is contained in:
@@ -13,4 +13,4 @@ subxt = { path = "../../subxt" }
|
||||
sp-core = "6.0.0"
|
||||
tokio = { version = "1.8", features = ["macros", "rt-multi-thread"] }
|
||||
which = "4.2.2"
|
||||
jsonrpsee = { version = "0.15.1", features = ["async-client", "client-ws-transport"] }
|
||||
jsonrpsee = { version = "0.16.0", features = ["async-client", "client-ws-transport"] }
|
||||
|
||||
@@ -60,7 +60,7 @@ async fn run() {
|
||||
// Thus, the connection might get rejected a few times.
|
||||
use client::ClientT;
|
||||
let res = match client::build(&format!("ws://localhost:{}", port)).await {
|
||||
Ok(c) => c.request("state_getMetadata", None).await,
|
||||
Ok(c) => c.request("state_getMetadata", client::rpc_params![]).await,
|
||||
Err(e) => Err(e),
|
||||
};
|
||||
|
||||
@@ -174,7 +174,10 @@ mod client {
|
||||
},
|
||||
};
|
||||
|
||||
pub use jsonrpsee::core::client::ClientT;
|
||||
pub use jsonrpsee::core::{
|
||||
client::ClientT,
|
||||
rpc_params,
|
||||
};
|
||||
|
||||
/// Build WS RPC client from URL
|
||||
pub async fn build(url: &str) -> Result<Client, Error> {
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
[package]
|
||||
name = "wasm-test"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dev-dependencies]
|
||||
wasm-bindgen-test = "0.3.24"
|
||||
tracing-wasm = "0.2.1"
|
||||
console_error_panic_hook = "0.1.7"
|
||||
serde_json = "1.0.57"
|
||||
subxt = { path = "../../subxt", default-features = false, features = ["jsonrpsee-web"] }
|
||||
@@ -0,0 +1,26 @@
|
||||
#![cfg(target_arch = "wasm32")]
|
||||
|
||||
use subxt::config::PolkadotConfig;
|
||||
use wasm_bindgen_test::*;
|
||||
|
||||
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);
|
||||
|
||||
/// Run the tests by `$ wasm-pack test --firefox --headless`
|
||||
|
||||
fn init_tracing() {
|
||||
console_error_panic_hook::set_once();
|
||||
tracing_wasm::set_as_global_default();
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
async fn wasm_ws_transport_works() {
|
||||
init_tracing();
|
||||
|
||||
let client =
|
||||
subxt::client::OnlineClient::<PolkadotConfig>::from_url("ws://127.0.0.1:9944")
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let chain = client.rpc().system_chain().await.unwrap();
|
||||
assert_eq!(&chain, "Development");
|
||||
}
|
||||
Reference in New Issue
Block a user