Skip to content

Commit a4df8ba

Browse files
committed
test: panic on empty inputs for non-slices and vars variant
1 parent e6334ab commit a4df8ba

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/test_utils/macros.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ macro_rules! assert_event_sequence {
8282
};
8383
($stream: expr, $events: expr, timeout = $secs: expr) => {
8484
let expected_options = $events.iter().map(alloy::sol_types::SolEvent::encode_log_data).collect::<Vec<_>>();
85+
if expected_options.is_empty() {
86+
panic!("error: assert_event_sequence! called with an empty collection. Use assert_empty! macro instead to check for no pending messages.")
87+
}
8588
$crate::test_utils::macros::assert_event_sequence(&mut $stream, expected_options.iter(), $secs).await
8689
};
8790
}
@@ -164,3 +167,35 @@ macro_rules! assert_empty {
164167
tokio_stream::wrappers::ReceiverStream::new(inner)
165168
}};
166169
}
170+
171+
#[cfg(test)]
172+
mod tests {
173+
use alloy::sol;
174+
use tokio::sync::mpsc;
175+
use tokio_stream::wrappers::ReceiverStream;
176+
177+
sol! {
178+
#[derive(Debug)]
179+
event Transfer(address indexed from, address indexed to, uint256 value);
180+
}
181+
182+
#[tokio::test]
183+
#[should_panic = "error: assert_event_sequence! called with an empty collection. Use assert_empty! macro instead to check for no pending messages."]
184+
async fn assert_event_sequence_macro_with_empty_vec() {
185+
let (_tx, rx) = mpsc::channel(10);
186+
let mut stream = ReceiverStream::new(rx);
187+
188+
let empty_vec: Vec<Transfer> = Vec::new();
189+
assert_event_sequence!(stream, empty_vec);
190+
}
191+
192+
#[tokio::test]
193+
#[should_panic = "error: assert_event_sequence! called with an empty collection. Use assert_empty! macro instead to check for no pending messages."]
194+
async fn assert_event_sequence_macro_with_empty_slice() {
195+
let (_tx, rx) = mpsc::channel(10);
196+
let mut stream = ReceiverStream::new(rx);
197+
198+
let empty_vec: &[Transfer] = &[];
199+
assert_event_sequence!(stream, empty_vec);
200+
}
201+
}

0 commit comments

Comments
 (0)