|
1 | | -use std::time::Duration; |
2 | | - |
3 | 1 | use crate::common::{TestCounter, deploy_counter, setup_live_scanner}; |
4 | 2 | use alloy::{primitives::U256, sol_types::SolEvent}; |
5 | 3 | use event_scanner::{EventFilter, assert_empty, assert_event_sequence}; |
6 | | -use tokio::time::timeout; |
7 | | -use tokio_stream::StreamExt; |
8 | 4 |
|
9 | 5 | #[tokio::test] |
10 | 6 | async fn basic_single_event_scanning() -> anyhow::Result<()> { |
@@ -124,63 +120,41 @@ async fn multiple_events_same_contract() -> anyhow::Result<()> { |
124 | 120 | #[tokio::test] |
125 | 121 | async fn signature_matching_ignores_irrelevant_events() -> anyhow::Result<()> { |
126 | 122 | let setup = setup_live_scanner(Some(0.1), None, 0).await?; |
127 | | - let contract = setup.contract.clone(); |
| 123 | + let contract = setup.contract; |
| 124 | + let mut scanner = setup.scanner; |
128 | 125 |
|
129 | 126 | // Subscribe to CountDecreased but only emit CountIncreased |
130 | 127 | let filter = EventFilter::new() |
131 | 128 | .contract_address(*contract.address()) |
132 | 129 | .event(TestCounter::CountDecreased::SIGNATURE.to_owned()); |
133 | 130 |
|
134 | | - let num_of_events = 3; |
135 | | - |
136 | | - let mut scanner = setup.scanner; |
137 | | - |
138 | | - let mut stream = scanner.subscribe(filter).take(num_of_events); |
| 131 | + let stream = scanner.subscribe(filter); |
139 | 132 |
|
140 | 133 | scanner.start().await?; |
141 | 134 |
|
142 | | - for _ in 0..num_of_events { |
143 | | - contract.increase().send().await?.watch().await?; |
144 | | - } |
145 | | - |
146 | | - let event_counting = async move { |
147 | | - _ = stream.next().await; |
148 | | - }; |
| 135 | + contract.increase().send().await?.watch().await?; |
149 | 136 |
|
150 | | - if timeout(Duration::from_secs(1), event_counting).await.is_ok() { |
151 | | - anyhow::bail!("scanner should have ignored all of the emitted events"); |
152 | | - } |
| 137 | + assert_empty!(stream); |
153 | 138 |
|
154 | 139 | Ok(()) |
155 | 140 | } |
156 | 141 |
|
157 | 142 | #[tokio::test] |
158 | 143 | async fn filters_malformed_signature_graceful() -> anyhow::Result<()> { |
159 | 144 | let setup = setup_live_scanner(Some(0.1), None, 0).await?; |
160 | | - let contract = setup.contract.clone(); |
| 145 | + let contract = setup.contract; |
| 146 | + let mut scanner = setup.scanner; |
161 | 147 |
|
162 | 148 | let filter = |
163 | 149 | EventFilter::new().contract_address(*contract.address()).event("invalid-sig".to_string()); |
164 | 150 |
|
165 | | - let num_of_events = 3; |
166 | | - |
167 | | - let mut scanner = setup.scanner; |
168 | | - |
169 | | - let mut stream = scanner.subscribe(filter).take(num_of_events); |
| 151 | + let stream = scanner.subscribe(filter); |
170 | 152 |
|
171 | 153 | scanner.start().await?; |
172 | 154 |
|
173 | | - for _ in 0..num_of_events { |
174 | | - contract.increase().send().await?.watch().await?; |
175 | | - } |
176 | | - |
177 | | - let event_counting = async move { |
178 | | - _ = stream.next().await; |
179 | | - }; |
| 155 | + contract.increase().send().await?.watch().await?; |
180 | 156 |
|
181 | | - if timeout(Duration::from_secs(1), event_counting).await.is_ok() { |
182 | | - anyhow::bail!("scanner should have ignored all of the emitted events"); |
183 | | - } |
| 157 | + assert_empty!(stream); |
184 | 158 |
|
185 | 159 | Ok(()) |
186 | 160 | } |
0 commit comments