mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-25 17:37:56 +00:00
2fe7b5c14c
* Remove 1 explicit bootnode; I think it stopped working so our tests did too * Remove comment Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com> --------- Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com>
54 lines
1.7 KiB
Rust
54 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() {
|
|
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}");
|
|
}
|
|
}
|