mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-25 23:27:56 +00:00
testing: Wait for more blocks for the lightclient init
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
This commit is contained in:
@@ -10,4 +10,4 @@ mod wait_for_blocks;
|
||||
pub use context::*;
|
||||
pub use node_proc::TestNodeProcess;
|
||||
pub use tx_retries::*;
|
||||
pub use wait_for_blocks::wait_for_blocks;
|
||||
pub use wait_for_blocks::*;
|
||||
|
||||
@@ -241,7 +241,10 @@ async fn build_light_client<T: Config>(proc: &SubstrateNode) -> Result<LightClie
|
||||
.await
|
||||
.map_err(|err| format!("Failed to connect to node rpc at {ws_url}: {err}"))?;
|
||||
|
||||
super::wait_for_blocks(&client).await;
|
||||
// Wait for at least 3 blocks before starting the light client.
|
||||
// Otherwise, the lightclient might error with
|
||||
// `"Error when retrieving the call proof: No node available for call proof query"`.
|
||||
super::wait_for_number_of_blocks(&client, 3).await;
|
||||
|
||||
// Step 2. Construct the light client.
|
||||
// P2p bootnode.
|
||||
|
||||
@@ -8,9 +8,18 @@ use subxt::{client::OnlineClientT, Config};
|
||||
/// wait for one more finalized block to be produced, which is important because
|
||||
/// the first finalized block doesn't have much state etc associated with it.
|
||||
pub async fn wait_for_blocks<C: Config>(api: &impl OnlineClientT<C>) {
|
||||
let mut sub = api.blocks().subscribe_finalized().await.unwrap();
|
||||
// The current finalized block:
|
||||
sub.next().await;
|
||||
// The next one:
|
||||
sub.next().await;
|
||||
// The current finalized block and the next block.
|
||||
wait_for_number_of_blocks(api, 2).await;
|
||||
}
|
||||
|
||||
/// Wait for a number of blocks to be produced.
|
||||
pub async fn wait_for_number_of_blocks<C: Config>(
|
||||
api: &impl OnlineClientT<C>,
|
||||
number_of_blocks: usize,
|
||||
) {
|
||||
let mut sub = api.blocks().subscribe_finalized().await.unwrap();
|
||||
|
||||
for _ in 0..number_of_blocks {
|
||||
sub.next().await;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user