Skip to content

Commit 5f65fe1

Browse files
committed
test: add deep reorg test
1 parent d4816f3 commit 5f65fe1

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

tests/block_range_scanner.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,35 @@ async fn rewind_reorg_emits_notification_and_rescans_affected_range() -> anyhow:
537537
Ok(())
538538
}
539539

540+
#[tokio::test]
541+
#[ignore = "rewind reorg tests require ack-channels to reliably halt processing: https://github.com/OpenZeppelin/Event-Scanner/issues/218"]
542+
async fn rewind_reorg_deep_emits_notification_and_rescans_affected_range() -> anyhow::Result<()> {
543+
let anvil = Anvil::new().try_spawn()?;
544+
let provider = ProviderBuilder::new().connect(anvil.ws_endpoint_url().as_str()).await?;
545+
provider.anvil_mine(Some(20), None).await?;
546+
let client =
547+
BlockRangeScanner::new().max_block_range(5).connect(provider.clone()).await?.run()?;
548+
let mut stream = client.rewind(5, 20).await?;
549+
assert_next!(stream, 16..=20);
550+
let mut stream = assert_empty!(stream);
551+
552+
// NOTE: Pause here
553+
// Deep reorg: >= max_block_range * 2
554+
let depth = 10;
555+
_ = provider.anvil_reorg(ReorgOptions { depth, tx_block_pairs: vec![] }).await;
556+
assert_next!(stream, Notification::ReorgDetected { common_ancestor_block: 20 - depth });
557+
558+
// Rescan range from common_ancestor (11) to tip (20)
559+
assert_next!(stream, 11..=15);
560+
assert_next!(stream, 16..=20);
561+
562+
// Rewind continues from where it left off (batch_from = 15)
563+
assert_next!(stream, 10..=15);
564+
assert_next!(stream, 5..=9);
565+
assert_closed!(stream);
566+
Ok(())
567+
}
568+
540569
#[tokio::test]
541570
#[ignore = "rewind reorg tests require ack-channels to reliably halt processing: https://github.com/OpenZeppelin/Event-Scanner/issues/218"]
542571
async fn rewind_skips_reorg_check_when_tip_below_finalized() -> anyhow::Result<()> {

0 commit comments

Comments
 (0)