MCPcopy Create free account
hub / github.com/ChainSafe/Delorean-Protocol / run_ws

Function run_ws

fendermint/eth/api/examples/ethers.rs:726–765  ·  view source on GitHub ↗

The WebSocket interface provides JSON-RPC request/response interactions as well as subscriptions, both using messages over the socket. We subscribe to notifications first, then run the same suite of request/responses as the HTTP case, finally check that we have collected events over the subscriptions.

(mut provider: Provider<Ws>, opts: &Options)

Source from the content-addressed store, hash-verified

724/// We subscribe to notifications first, then run the same suite of request/responses
725/// as the HTTP case, finally check that we have collected events over the subscriptions.
726async fn run_ws(mut provider: Provider<Ws>, opts: &Options) -> anyhow::Result<()> {
727 tracing::info!("Running the tests over WS...");
728 adjust_provider(&mut provider);
729
730 // Subscriptions as well.
731 let subs = if FILTERS_ENABLED {
732 let block_sub = provider.subscribe_blocks().await?;
733 let txs_sub = provider.subscribe_pending_txs().await?;
734 let log_sub = provider.subscribe_logs(&Filter::default()).await?;
735 Some((block_sub, txs_sub, log_sub))
736 } else {
737 None
738 };
739
740 run(&provider, opts).await?;
741
742 if let Some((mut block_sub, mut txs_sub, mut log_sub)) = subs {
743 assert!(block_sub.next().await.is_some(), "blocks should arrive");
744 assert!(txs_sub.next().await.is_some(), "transactions should arrive");
745 assert!(log_sub.next().await.is_some(), "logs should arrive");
746
747 block_sub
748 .unsubscribe()
749 .await
750 .context("failed to unsubscribe blocks")?;
751
752 txs_sub
753 .unsubscribe()
754 .await
755 .context("failed to unsubscribe txs")?;
756
757 log_sub
758 .unsubscribe()
759 .await
760 .context("failed to unsubscribe logs")?;
761 }
762
763 tracing::info!("WS tests finished.");
764 Ok(())
765}
766
767async fn make_transfer<C>(
768 mw: &TestMiddleware<C>,

Callers 1

mainFunction · 0.85

Calls 4

adjust_providerFunction · 0.85
contextMethod · 0.80
runFunction · 0.70
unsubscribeMethod · 0.45

Tested by

no test coverage detected