Skip to content

Commit fb2ed7e

Browse files
committed
test: add new chain live mode test
1 parent c38e10a commit fb2ed7e

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

src/block_range_scanner.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,6 +1155,48 @@ mod tests {
11551155
Ok(())
11561156
}
11571157

1158+
#[tokio::test]
1159+
async fn live_mode_respects_block_confirmations_on_new_chain() -> anyhow::Result<()> {
1160+
let anvil = Anvil::new().try_spawn()?;
1161+
1162+
let provider = ProviderBuilder::new().connect(anvil.endpoint().as_str()).await?;
1163+
1164+
let block_confirmations = 5;
1165+
1166+
let client = BlockRangeScanner::new()
1167+
.with_block_confirmations(block_confirmations)
1168+
.connect_ws::<Ethereum>(anvil.ws_endpoint_url())
1169+
.await?
1170+
.run()?;
1171+
1172+
let mut receiver = client.stream_live().await?;
1173+
1174+
provider.anvil_mine(Option::Some(6), Option::None).await?;
1175+
1176+
let next = receiver.next().await;
1177+
if let Some(BlockRangeMessage::Data(range)) = next {
1178+
assert_eq!(0, *range.start());
1179+
assert_eq!(0, *range.end());
1180+
} else {
1181+
panic!("expected range, got: {next:?}");
1182+
}
1183+
1184+
let next = receiver.next().await;
1185+
if let Some(BlockRangeMessage::Data(range)) = next {
1186+
assert_eq!(1, *range.start());
1187+
assert_eq!(1, *range.end());
1188+
} else {
1189+
panic!("expected range, got: {next:?}");
1190+
}
1191+
1192+
// assert no new pending confirmed block ranges
1193+
assert!(
1194+
timeout(Duration::from_secs(1), async move { receiver.next().await }).await.is_err()
1195+
);
1196+
1197+
Ok(())
1198+
}
1199+
11581200
#[tokio::test]
11591201
async fn continuous_blocks_if_reorg_less_than_block_confirmation() -> anyhow::Result<()> {
11601202
let anvil = Anvil::new().try_spawn()?;

0 commit comments

Comments
 (0)