Skip to content

Commit

Permalink
test-utils: Fix wait_for_blocks in presence of reorgs (paritytech#14215)
Browse files Browse the repository at this point in the history
In the cases where a reorg happens we might receive notifications
for different blocks at the same level, so instead of the chain having
count new blocks it has less and that will break the tests which use this
function.

So, use the block number to identify that `count` blocks have been built in the
chain.

Examples where this issue was hit:
  paritytech/polkadot#7267

Signed-off-by: Alexandru Gheorghe <[email protected]>
  • Loading branch information
alexggh authored May 26, 2023
1 parent c470fc2 commit 8b1af50
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions test-utils/client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ use sc_client_api::BlockchainEvents;
use sc_service::client::{ClientConfig, LocalCallExecutor};
use serde::Deserialize;
use sp_core::{storage::ChildInfo, testing::TaskExecutor};
use sp_runtime::{codec::Encode, traits::Block as BlockT, OpaqueExtrinsic};
use sp_runtime::{
codec::Encode,
traits::{Block as BlockT, Header},
OpaqueExtrinsic,
};
use std::{
collections::{HashMap, HashSet},
pin::Pin,
Expand Down Expand Up @@ -410,7 +414,7 @@ where
Box::pin(async move {
while let Some(notification) = import_notification_stream.next().await {
if notification.is_new_best {
blocks.insert(notification.hash);
blocks.insert(*notification.header.number());
if blocks.len() == count {
break
}
Expand Down

0 comments on commit 8b1af50

Please sign in to comment.