Skip to content
22 changes: 22 additions & 0 deletions src/event_scanner/scanner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@ impl EventScannerBuilder<Unspecified> {

/// Streams the latest `count` matching events per registered listener.
///
/// # Panics
///
/// If `count` is zero
///
/// # Example
///
/// ```no_run
Expand Down Expand Up @@ -322,6 +326,7 @@ impl EventScannerBuilder<Unspecified> {
/// [reorg]: crate::ScannerStatus::ReorgDetected
#[must_use]
pub fn latest(count: usize) -> EventScannerBuilder<LatestEvents> {
assert!(count != 0, "count must be greater than 0");
EventScannerBuilder::<LatestEvents>::new(count)
}
}
Expand Down Expand Up @@ -375,6 +380,10 @@ impl<M> EventScannerBuilder<M> {
///
/// * `max_block_range` - Maximum number of blocks to process per batch.
///
/// # Panics
///
/// If `max_block_range` is zero
///
/// # Example
///
/// If scanning events from blocks 1000–1099 (100 blocks total) with `max_block_range(30)`:
Expand All @@ -384,6 +393,7 @@ impl<M> EventScannerBuilder<M> {
/// - Batch 4: blocks 1090–1099 (10 blocks)
#[must_use]
pub fn max_block_range(mut self, max_block_range: u64) -> Self {
assert!(max_block_range != 0, "max block range should be greater than zero");
self.block_range_scanner.max_block_range = max_block_range;
self
}
Expand Down Expand Up @@ -484,4 +494,16 @@ mod tests {

Ok(())
}

#[test]
#[should_panic(expected = "count must be greater than 0")]
fn test_latest_panics_with_zero_count() {
let _ = EventScannerBuilder::latest(0);
}

#[test]
#[should_panic(expected = "max block range should be greater than zero")]
fn test_max_block_range_panics_with_zero() {
let _ = EventScannerBuilder::historic().max_block_range(0);
}
}