Skip to content

Commit 8aaf7bf

Browse files
committed
docs: explain the macro
1 parent f70a878 commit 8aaf7bf

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

src/test_utils/macros.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,39 @@ macro_rules! assert_next {
2525

2626
// TODO: implement assert_range_coverage
2727

28+
/// Asserts that the stream emits the given events in order.
29+
///
30+
/// The macro asserts that all of the provided events are emitted in the order they are provided, no
31+
/// matter how many stream batches are necessary to emit them, that no other events are emitted in
32+
/// between, and that the final event is the last event in the last batch of the stream.
33+
///
34+
/// The provided events can be of any type that implements [`SolEvent`](alloy::sol_types::SolEvent).
35+
///
36+
/// # Examples
37+
///
38+
/// ```
39+
/// let mut stream = scanner.subscribe(EventFilter::new().contract_address(contract_address));
40+
/// assert_event_sequence!(
41+
/// stream,
42+
/// &[CountIncreased { newCount: U256::from(1) }, CountIncreased { newCount: U256::from(2) },]
43+
/// );
44+
/// ```
45+
///
46+
/// The above assertion will pass if next stream batches are any of the following:
47+
///
48+
/// 1. Each event separate:
49+
/// - Batch 1: `[CountIncreased { newCount: U256::from(1) }]`
50+
/// - Batch 2: `[CountIncreased { newCount: U256::from(2) }]`
51+
/// 2. Events in the same batch:
52+
/// - Batch 1: `[CountIncreased { newCount: U256::from(1) }, CountIncreased { newCount:
53+
/// U256::from(2) }]`
54+
///
55+
/// # Panics
56+
///
57+
/// * If the stream emits a different event than the next expected one
58+
/// * If the stream is closed before all of the expected events are emitted
59+
/// * If the stream emits more events than expected
60+
/// * If the stream times out before all of the expected events are emitted
2861
#[macro_export]
2962
macro_rules! assert_event_sequence {
3063
// owned slices just pass to the borrowed slices variant

0 commit comments

Comments
 (0)