mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-23 06:08:01 +00:00
372c36c2b9
* lightclient: Close wasm socket while dropping from connecting state Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * lightclient: Construct one time only closures Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * testing: Enable console logs for lightclient WASM testing Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * lightclient: Separate wakes and check connectivity on poll_read Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * lightclient: Close the socket depending on internal state Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * Revert "lightclient: Separate wakes and check connectivity on poll_read" This reverts commit 866094001d4c0b119a80ed681a74b323f74eae1b. * lightclient: Return pending if socket is opening from poll_read Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * lightclient: Close the socket on `poll_close` Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * lightclient: Reset closures on Drop to avoid recursive invokation Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * lightclient: Close the socket if not already closing Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> --------- Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
56 lines
1.7 KiB
Rust
56 lines
1.7 KiB
Rust
#![cfg(target_arch = "wasm32")]
|
|
|
|
use subxt::{
|
|
config::PolkadotConfig,
|
|
client::{LightClient, LightClientBuilder},
|
|
};
|
|
use futures_util::StreamExt;
|
|
use wasm_bindgen_test::*;
|
|
|
|
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);
|
|
|
|
// Run the tests by calling:
|
|
//
|
|
// ```text
|
|
// wasm-pack test --firefox --headless`
|
|
// ```
|
|
//
|
|
// You'll need to have a substrate/polkadot node running:
|
|
//
|
|
// ```bash
|
|
// # Polkadot does not accept by default WebSocket connections to the P2P network.
|
|
// # Ensure `--listen-addr` is provided with valid ws address endpoint.
|
|
// # The `--node-key` provides a deterministic p2p address for the node.
|
|
// ./polkadot --dev --node-key 0000000000000000000000000000000000000000000000000000000000000001 --listen-addr /ip4/0.0.0.0/tcp/30333/ws
|
|
// ```
|
|
//
|
|
// Use the following to enable logs:
|
|
// ```
|
|
// console_error_panic_hook::set_once();
|
|
// tracing_wasm::set_as_global_default();
|
|
// ```
|
|
|
|
#[wasm_bindgen_test]
|
|
async fn light_client_works() {
|
|
console_error_panic_hook::set_once();
|
|
|
|
let api: LightClient<PolkadotConfig> = LightClientBuilder::new()
|
|
.build_from_url("wss://rpc.polkadot.io:443")
|
|
.await
|
|
.expect("Cannot construct light client");
|
|
|
|
tracing::info!("Subscribe to latest finalized blocks: ");
|
|
|
|
let mut blocks_sub = api.blocks().subscribe_finalized().await.expect("Cannot subscribe to finalized hashes").take(3);
|
|
// For each block, print a bunch of information about it:
|
|
while let Some(block) = blocks_sub.next().await {
|
|
let block = block.expect("Block not valid");
|
|
|
|
let block_number = block.header().number;
|
|
let block_hash = block.hash();
|
|
|
|
tracing::info!("Block #{block_number}:");
|
|
tracing::info!(" Hash: {block_hash}");
|
|
}
|
|
}
|