@@ -191,3 +191,80 @@ impl<N: Network> LatestEventScanner<N> {
191191 unimplemented ! ( )
192192 }
193193}
194+
195+ #[ cfg( test) ]
196+ mod tests {
197+ use super :: * ;
198+
199+ #[ test]
200+ fn test_latest_scanner_config_defaults ( ) {
201+ let config = LatestScannerConfig :: new ( ) ;
202+
203+ assert_eq ! ( config. count, 1 ) ;
204+ assert ! ( matches!( config. from_block, BlockNumberOrTag :: Earliest ) ) ;
205+ assert ! ( matches!( config. to_block, BlockNumberOrTag :: Latest ) ) ;
206+ assert_eq ! ( config. block_confirmations, DEFAULT_BLOCK_CONFIRMATIONS ) ;
207+ assert ! ( !config. switch_to_live) ;
208+ }
209+
210+ #[ test]
211+ fn test_latest_scanner_builder_pattern ( ) {
212+ let config = LatestScannerConfig :: new ( )
213+ . count ( 5 )
214+ . from_block ( 100 )
215+ . to_block ( 200 )
216+ . block_confirmations ( 10 )
217+ . then_live ( )
218+ . max_reads ( 50 ) ;
219+
220+ assert_eq ! ( config. count, 5 ) ;
221+ assert ! ( matches!( config. from_block, BlockNumberOrTag :: Number ( 100 ) ) ) ;
222+ assert ! ( matches!( config. to_block, BlockNumberOrTag :: Number ( 200 ) ) ) ;
223+ assert_eq ! ( config. block_confirmations, 10 ) ;
224+ assert ! ( config. switch_to_live) ;
225+ assert_eq ! ( config. base. block_range_scanner. max_read_per_epoch, 50 ) ;
226+ }
227+
228+ #[ test]
229+ fn test_latest_scanner_builder_pattern_chaining ( ) {
230+ let config = LatestScannerConfig :: new ( )
231+ . max_reads ( 25 )
232+ . block_confirmations ( 5 )
233+ . count ( 3 )
234+ . from_block ( BlockNumberOrTag :: Number ( 50 ) )
235+ . to_block ( BlockNumberOrTag :: Number ( 150 ) )
236+ . then_live ( ) ;
237+
238+ assert_eq ! ( config. base. block_range_scanner. max_read_per_epoch, 25 ) ;
239+ assert_eq ! ( config. block_confirmations, 5 ) ;
240+ assert_eq ! ( config. count, 3 ) ;
241+ assert ! ( matches!( config. from_block, BlockNumberOrTag :: Number ( 50 ) ) ) ;
242+ assert ! ( matches!( config. to_block, BlockNumberOrTag :: Number ( 150 ) ) ) ;
243+ assert ! ( config. switch_to_live) ;
244+ }
245+
246+ #[ test]
247+ fn test_latest_scanner_builder_with_different_block_types ( ) {
248+ let config = LatestScannerConfig :: new ( )
249+ . from_block ( BlockNumberOrTag :: Earliest )
250+ . to_block ( BlockNumberOrTag :: Latest )
251+ . count ( 10 )
252+ . block_confirmations ( 20 ) ;
253+
254+ assert ! ( matches!( config. from_block, BlockNumberOrTag :: Earliest ) ) ;
255+ assert ! ( matches!( config. to_block, BlockNumberOrTag :: Latest ) ) ;
256+ assert_eq ! ( config. count, 10 ) ;
257+ assert_eq ! ( config. block_confirmations, 20 ) ;
258+ assert ! ( !config. switch_to_live) ;
259+ }
260+
261+ #[ test]
262+ fn test_latest_scanner_then_live_method ( ) {
263+ let config = LatestScannerConfig :: new ( ) . then_live ( ) ;
264+ assert ! ( config. switch_to_live) ;
265+
266+ let config_without_live = LatestScannerConfig :: new ( ) ;
267+ assert ! ( !config_without_live. switch_to_live) ;
268+ }
269+ }
270+
0 commit comments