@@ -30,11 +30,16 @@ impl EventScannerBuilder<LatestEvents> {
3030 ///
3131 /// # Errors
3232 ///
33- /// Returns an error if the provider connection fails.
33+ /// Returns an error if:
34+ /// * The provider connection fails
35+ /// * The event count is zero
3436 pub async fn connect < N : Network > (
3537 self ,
3638 provider : impl IntoRobustProvider < N > ,
3739 ) -> Result < EventScanner < LatestEvents , N > , ScannerError > {
40+ if self . config . count == 0 {
41+ return Err ( ScannerError :: InvalidEventCount ) ;
42+ }
3843 self . build ( provider) . await
3944 }
4045}
@@ -76,6 +81,12 @@ impl<N: Network> EventScanner<LatestEvents, N> {
7681
7782#[ cfg( test) ]
7883mod tests {
84+ use alloy:: {
85+ network:: Ethereum ,
86+ providers:: { RootProvider , mock:: Asserter } ,
87+ rpc:: client:: RpcClient ,
88+ } ;
89+
7990 use super :: * ;
8091
8192 #[ test]
@@ -124,4 +135,15 @@ mod tests {
124135 assert_eq ! ( builder. config. block_confirmations, 7 ) ;
125136 assert_eq ! ( builder. block_range_scanner. max_block_range, 60 ) ;
126137 }
138+
139+ #[ tokio:: test]
140+ async fn test_latest_returns_error_with_zero_count ( ) {
141+ let provider = RootProvider :: < Ethereum > :: new ( RpcClient :: mocked ( Asserter :: new ( ) ) ) ;
142+ let result = EventScannerBuilder :: latest ( 0 ) . connect ( provider) . await ;
143+
144+ match result {
145+ Err ( ScannerError :: InvalidEventCount ) => { }
146+ _ => panic ! ( "Expected InvalidEventCount error" ) ,
147+ }
148+ }
127149}
0 commit comments