Skip to content

Commit 3cb37e2

Browse files
committed
test: update all relevant test assertions to assert_event_sequence
1 parent cb8577e commit 3cb37e2

File tree

6 files changed

+153
-74
lines changed

6 files changed

+153
-74
lines changed

tests/live/basic.rs

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::{
88

99
use crate::common::{TestCounter, deploy_counter, setup_live_scanner};
1010
use alloy::{primitives::U256, sol_types::SolEvent};
11-
use event_scanner::{EventFilter, Message, assert_empty, assert_next};
11+
use event_scanner::{EventFilter, Message, assert_empty, assert_event_sequence};
1212
use tokio::time::timeout;
1313
use tokio_stream::StreamExt;
1414

@@ -88,13 +88,23 @@ async fn multiple_contracts_same_event_isolate_callbacks() -> anyhow::Result<()>
8888
b.increase().send().await?.watch().await?;
8989
b.increase().send().await?.watch().await?;
9090

91-
assert_next!(a_stream, &[TestCounter::CountIncreased { newCount: U256::from(1) }]);
92-
assert_next!(a_stream, &[TestCounter::CountIncreased { newCount: U256::from(2) }]);
93-
assert_next!(a_stream, &[TestCounter::CountIncreased { newCount: U256::from(3) }]);
91+
assert_event_sequence!(
92+
a_stream,
93+
&[
94+
TestCounter::CountIncreased { newCount: U256::from(1) },
95+
TestCounter::CountIncreased { newCount: U256::from(2) },
96+
TestCounter::CountIncreased { newCount: U256::from(3) }
97+
]
98+
);
9499
assert_empty!(a_stream);
95100

96-
assert_next!(b_stream, &[TestCounter::CountIncreased { newCount: U256::from(1) }]);
97-
assert_next!(b_stream, &[TestCounter::CountIncreased { newCount: U256::from(2) }]);
101+
assert_event_sequence!(
102+
b_stream,
103+
&[
104+
TestCounter::CountIncreased { newCount: U256::from(1) },
105+
TestCounter::CountIncreased { newCount: U256::from(2) }
106+
]
107+
);
98108
assert_empty!(b_stream);
99109

100110
Ok(())
@@ -126,12 +136,22 @@ async fn multiple_events_same_contract() -> anyhow::Result<()> {
126136
contract.decrease().send().await?.watch().await?;
127137
contract.decrease().send().await?.watch().await?;
128138

129-
assert_next!(incr_stream, &[TestCounter::CountIncreased { newCount: U256::from(1) }]);
130-
assert_next!(incr_stream, &[TestCounter::CountIncreased { newCount: U256::from(2) }]);
139+
assert_event_sequence!(
140+
incr_stream,
141+
&[
142+
TestCounter::CountIncreased { newCount: U256::from(1) },
143+
TestCounter::CountIncreased { newCount: U256::from(2) }
144+
]
145+
);
131146
assert_empty!(incr_stream);
132147

133-
assert_next!(decr_stream, &[TestCounter::CountDecreased { newCount: U256::from(1) }]);
134-
assert_next!(decr_stream, &[TestCounter::CountDecreased { newCount: U256::from(0) }]);
148+
assert_event_sequence!(
149+
decr_stream,
150+
&[
151+
TestCounter::CountDecreased { newCount: U256::from(1) },
152+
TestCounter::CountDecreased { newCount: U256::from(0) }
153+
]
154+
);
135155
assert_empty!(decr_stream);
136156

137157
Ok(())

tests/live/optional_fields.rs

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::{
88

99
use crate::common::{TestCounter, deploy_counter, setup_live_scanner};
1010
use alloy::{primitives::U256, sol_types::SolEvent};
11-
use event_scanner::{EventFilter, Message, assert_empty, assert_next};
11+
use event_scanner::{EventFilter, Message, assert_empty, assert_event_sequence, assert_next};
1212
use tokio::time::timeout;
1313
use tokio_stream::StreamExt;
1414

@@ -115,9 +115,14 @@ async fn mixed_optional_and_required_filters() -> anyhow::Result<()> {
115115
contract_1.increase().send().await?.watch().await?;
116116
contract_1.increase().send().await?.watch().await?;
117117

118-
assert_next!(all_stream, &[TestCounter::CountIncreased { newCount: U256::from(1) }]);
119-
assert_next!(all_stream, &[TestCounter::CountIncreased { newCount: U256::from(2) }]);
120-
assert_next!(all_stream, &[TestCounter::CountIncreased { newCount: U256::from(3) }]);
118+
assert_event_sequence!(
119+
all_stream,
120+
&[
121+
TestCounter::CountIncreased { newCount: U256::from(1) },
122+
TestCounter::CountIncreased { newCount: U256::from(2) },
123+
TestCounter::CountIncreased { newCount: U256::from(3) }
124+
]
125+
);
121126

122127
let mut all_stream = assert_empty!(all_stream);
123128
let mut specific_stream = assert_empty!(specific_stream);
@@ -126,11 +131,21 @@ async fn mixed_optional_and_required_filters() -> anyhow::Result<()> {
126131
contract_2.increase().send().await?.watch().await?;
127132
contract_2.increase().send().await?.watch().await?;
128133

129-
assert_next!(all_stream, &[TestCounter::CountIncreased { newCount: U256::from(1) }]);
130-
assert_next!(all_stream, &[TestCounter::CountIncreased { newCount: U256::from(2) }]);
131-
132-
assert_next!(specific_stream, &[TestCounter::CountIncreased { newCount: U256::from(1) }]);
133-
assert_next!(specific_stream, &[TestCounter::CountIncreased { newCount: U256::from(2) }]);
134+
assert_event_sequence!(
135+
all_stream,
136+
&[
137+
TestCounter::CountIncreased { newCount: U256::from(1) },
138+
TestCounter::CountIncreased { newCount: U256::from(2) }
139+
]
140+
);
141+
142+
assert_event_sequence!(
143+
specific_stream,
144+
&[
145+
TestCounter::CountIncreased { newCount: U256::from(1) },
146+
TestCounter::CountIncreased { newCount: U256::from(2) }
147+
]
148+
);
134149

135150
let mut all_stream = assert_empty!(all_stream);
136151
let specific_stream = assert_empty!(specific_stream);

tests/live/performance.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use alloy::primitives::U256;
2-
use event_scanner::{assert_empty, assert_next};
2+
use event_scanner::{assert_empty, assert_event_sequence};
33

44
use crate::common::{LiveScannerSetup, TestCounter::CountIncreased, setup_live_scanner};
55

@@ -23,9 +23,9 @@ async fn high_event_volume_no_loss() -> anyhow::Result<()> {
2323
}
2424
});
2525

26-
for new_count in 1..=100 {
27-
assert_next!(stream, &[CountIncreased { newCount: U256::from(new_count) }]);
28-
}
26+
let expected =
27+
(1..=100).map(|n| CountIncreased { newCount: U256::from(n) }).collect::<Vec<_>>();
28+
assert_event_sequence!(stream, expected);
2929
assert_empty!(stream);
3030

3131
Ok(())

tests/live/reorg.rs

Lines changed: 54 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use alloy::{
66
providers::ext::AnvilApi,
77
rpc::types::anvil::{ReorgOptions, TransactionData},
88
};
9-
use event_scanner::{ScannerStatus, assert_empty, assert_next};
9+
use event_scanner::{ScannerStatus, assert_empty, assert_event_sequence, assert_next};
1010

1111
#[tokio::test]
1212
async fn reorg_rescans_events_within_same_block() -> anyhow::Result<()> {
@@ -21,11 +21,16 @@ async fn reorg_rescans_events_within_same_block() -> anyhow::Result<()> {
2121
}
2222

2323
// assert initial events are emitted as expected
24-
assert_next!(stream, &[CountIncreased { newCount: U256::from(1) }]);
25-
assert_next!(stream, &[CountIncreased { newCount: U256::from(2) }]);
26-
assert_next!(stream, &[CountIncreased { newCount: U256::from(3) }]);
27-
assert_next!(stream, &[CountIncreased { newCount: U256::from(4) }]);
28-
assert_next!(stream, &[CountIncreased { newCount: U256::from(5) }]);
24+
assert_event_sequence!(
25+
stream,
26+
&[
27+
CountIncreased { newCount: U256::from(1) },
28+
CountIncreased { newCount: U256::from(2) },
29+
CountIncreased { newCount: U256::from(3) },
30+
CountIncreased { newCount: U256::from(4) },
31+
CountIncreased { newCount: U256::from(5) }
32+
]
33+
);
2934
let mut stream = assert_empty!(stream);
3035

3136
// reorg the chain
@@ -64,11 +69,16 @@ async fn reorg_rescans_events_with_ascending_blocks() -> anyhow::Result<()> {
6469
}
6570

6671
// assert initial events are emitted as expected
67-
assert_next!(stream, &[CountIncreased { newCount: U256::from(1) }]);
68-
assert_next!(stream, &[CountIncreased { newCount: U256::from(2) }]);
69-
assert_next!(stream, &[CountIncreased { newCount: U256::from(3) }]);
70-
assert_next!(stream, &[CountIncreased { newCount: U256::from(4) }]);
71-
assert_next!(stream, &[CountIncreased { newCount: U256::from(5) }]);
72+
assert_event_sequence!(
73+
stream,
74+
&[
75+
CountIncreased { newCount: U256::from(1) },
76+
CountIncreased { newCount: U256::from(2) },
77+
CountIncreased { newCount: U256::from(3) },
78+
CountIncreased { newCount: U256::from(4) },
79+
CountIncreased { newCount: U256::from(5) }
80+
]
81+
);
7282
let mut stream = assert_empty!(stream);
7383

7484
// reorg the chain
@@ -82,9 +92,14 @@ async fn reorg_rescans_events_with_ascending_blocks() -> anyhow::Result<()> {
8292

8393
// assert expected messages post-reorg
8494
assert_next!(stream, ScannerStatus::ReorgDetected);
85-
assert_next!(stream, &[CountIncreased { newCount: U256::from(2) }]);
86-
assert_next!(stream, &[CountIncreased { newCount: U256::from(3) }]);
87-
assert_next!(stream, &[CountIncreased { newCount: U256::from(4) }]);
95+
assert_event_sequence!(
96+
stream,
97+
&[
98+
CountIncreased { newCount: U256::from(2) },
99+
CountIncreased { newCount: U256::from(3) },
100+
CountIncreased { newCount: U256::from(4) }
101+
]
102+
);
88103
assert_empty!(stream);
89104

90105
Ok(())
@@ -103,10 +118,15 @@ async fn reorg_depth_one() -> anyhow::Result<()> {
103118
}
104119

105120
// assert initial events are emitted as expected
106-
assert_next!(stream, &[CountIncreased { newCount: U256::from(1) }]);
107-
assert_next!(stream, &[CountIncreased { newCount: U256::from(2) }]);
108-
assert_next!(stream, &[CountIncreased { newCount: U256::from(3) }]);
109-
assert_next!(stream, &[CountIncreased { newCount: U256::from(4) }]);
121+
assert_event_sequence!(
122+
stream,
123+
&[
124+
CountIncreased { newCount: U256::from(1) },
125+
CountIncreased { newCount: U256::from(2) },
126+
CountIncreased { newCount: U256::from(3) },
127+
CountIncreased { newCount: U256::from(4) }
128+
]
129+
);
110130
let mut stream = assert_empty!(stream);
111131

112132
// reorg the chain
@@ -136,10 +156,15 @@ async fn reorg_depth_two() -> anyhow::Result<()> {
136156
}
137157

138158
// assert initial events are emitted as expected
139-
assert_next!(stream, &[CountIncreased { newCount: U256::from(1) }]);
140-
assert_next!(stream, &[CountIncreased { newCount: U256::from(2) }]);
141-
assert_next!(stream, &[CountIncreased { newCount: U256::from(3) }]);
142-
assert_next!(stream, &[CountIncreased { newCount: U256::from(4) }]);
159+
assert_event_sequence!(
160+
stream,
161+
&[
162+
CountIncreased { newCount: U256::from(1) },
163+
CountIncreased { newCount: U256::from(2) },
164+
CountIncreased { newCount: U256::from(3) },
165+
CountIncreased { newCount: U256::from(4) }
166+
]
167+
);
143168
let mut stream = assert_empty!(stream);
144169

145170
// reorg the chain
@@ -192,11 +217,14 @@ async fn block_confirmations_mitigate_reorgs() -> anyhow::Result<()> {
192217
provider.primary().anvil_mine(Some(10), None).await?;
193218

194219
// no `ReorgDetected` should be emitted
195-
assert_next!(stream, &[CountIncreased { newCount: U256::from(1) }]);
196-
assert_next!(stream, &[CountIncreased { newCount: U256::from(2) }]);
197-
assert_next!(
220+
assert_event_sequence!(
198221
stream,
199-
&[CountIncreased { newCount: U256::from(3) }, CountIncreased { newCount: U256::from(4) }]
222+
&[
223+
CountIncreased { newCount: U256::from(1) },
224+
CountIncreased { newCount: U256::from(2) },
225+
CountIncreased { newCount: U256::from(3) },
226+
CountIncreased { newCount: U256::from(4) }
227+
]
200228
);
201229
assert_empty!(stream);
202230

tests/sync/from_block.rs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use alloy::{
44
providers::ext::AnvilApi,
55
rpc::types::anvil::{ReorgOptions, TransactionData},
66
};
7-
use event_scanner::{ScannerStatus, assert_empty, assert_next};
7+
use event_scanner::{ScannerStatus, assert_empty, assert_event_sequence, assert_next};
88

99
use crate::common::{SyncScannerSetup, TestCounter, setup_sync_scanner};
1010

@@ -40,8 +40,13 @@ async fn replays_historical_then_switches_to_live() -> anyhow::Result<()> {
4040
assert_next!(stream, ScannerStatus::StartingLiveStream);
4141

4242
// live events
43-
assert_next!(stream, &[TestCounter::CountIncreased { newCount: U256::from(4) }]);
44-
assert_next!(stream, &[TestCounter::CountIncreased { newCount: U256::from(5) }]);
43+
assert_event_sequence!(
44+
stream,
45+
&[
46+
TestCounter::CountIncreased { newCount: U256::from(4) },
47+
TestCounter::CountIncreased { newCount: U256::from(5) }
48+
]
49+
);
4550
assert_empty!(stream);
4651

4752
Ok(())
@@ -106,8 +111,13 @@ async fn block_confirmations_mitigate_reorgs() -> anyhow::Result<()> {
106111
// switching to "live" phase
107112
assert_next!(stream, ScannerStatus::StartingLiveStream);
108113
// assert confirmed live events are streamed separately
109-
assert_next!(stream, &[TestCounter::CountIncreased { newCount: U256::from(3) }]);
110-
assert_next!(stream, &[TestCounter::CountIncreased { newCount: U256::from(4) }]);
114+
assert_event_sequence!(
115+
stream,
116+
&[
117+
TestCounter::CountIncreased { newCount: U256::from(3) },
118+
TestCounter::CountIncreased { newCount: U256::from(4) }
119+
]
120+
);
111121
let stream = assert_empty!(stream);
112122

113123
// Perform a shallow reorg on the live tail
@@ -126,14 +136,14 @@ async fn block_confirmations_mitigate_reorgs() -> anyhow::Result<()> {
126136
provider.primary().anvil_mine(Some(10), None).await?;
127137

128138
// no `ReorgDetected` should be emitted
129-
assert_next!(stream, &[TestCounter::CountIncreased { newCount: U256::from(5) }]);
130-
assert_next!(stream, &[TestCounter::CountIncreased { newCount: U256::from(6) }]);
131-
assert_next!(stream, &[TestCounter::CountIncreased { newCount: U256::from(7) }]);
132-
assert_next!(
139+
assert_event_sequence!(
133140
stream,
134141
&[
142+
TestCounter::CountIncreased { newCount: U256::from(5) },
143+
TestCounter::CountIncreased { newCount: U256::from(6) },
144+
TestCounter::CountIncreased { newCount: U256::from(7) },
135145
TestCounter::CountIncreased { newCount: U256::from(8) },
136-
TestCounter::CountIncreased { newCount: U256::from(9) }
146+
TestCounter::CountIncreased { newCount: U256::from(9) },
137147
]
138148
);
139149
assert_empty!(stream);

0 commit comments

Comments
 (0)