@@ -311,3 +311,108 @@ impl<P: Platform> CheckpointExt<P> for Checkpoint<P> {
311311 self . root ( ) . created_at ( )
312312 }
313313}
314+
315+ #[ cfg( test) ]
316+ mod tests {
317+ use {
318+ crate :: alloy:: primitives:: Address ,
319+ alloy_origin:: primitives:: { TxHash , U256 } ,
320+ rblib:: { prelude:: * , test_utils:: BlockContextMocked } ,
321+ std:: {
322+ thread,
323+ time:: { Duration , Instant } ,
324+ } ,
325+ } ;
326+
327+ #[ test]
328+ fn test_is_empty_and_root ( ) {
329+ let ( block, _) = BlockContext :: < Ethereum > :: mocked ( ) ;
330+ let root = block. start ( ) ;
331+ let mid = root. barrier ( ) ;
332+ let leaf = mid. barrier ( ) ;
333+
334+ assert ! ( root. is_empty( ) ) ;
335+ assert_eq ! ( leaf. root( ) , root) ;
336+ }
337+
338+ #[ test]
339+ fn test_gas_used_and_cumulative_gas_used ( ) {
340+ let ( block, _) = BlockContext :: < Ethereum > :: mocked ( ) ;
341+ let cp = block. start ( ) ;
342+ assert_eq ! ( cp. gas_used( ) , 0 ) ;
343+ assert_eq ! ( cp. cumulative_gas_used( ) , 0 ) ;
344+ }
345+
346+ #[ test]
347+ fn test_effective_tip_and_blob_gas ( ) {
348+ let ( block, _) = BlockContext :: < Ethereum > :: mocked ( ) ;
349+ let cp = block. start ( ) ;
350+ assert_eq ! ( cp. effective_tip_per_gas( ) , 0 ) ;
351+ assert ! ( !cp. has_blobs( ) ) ;
352+ assert_eq ! ( cp. blob_gas_used( ) , Some ( 0 ) ) ;
353+ assert_eq ! ( cp. cumulative_blob_gas_used( ) , 0 ) ;
354+ }
355+
356+ #[ test]
357+ fn test_to_between_linear_history ( ) {
358+ let ( block, _) = BlockContext :: < Ethereum > :: mocked ( ) ;
359+ let a = block. start ( ) ;
360+ let b = a. barrier ( ) ;
361+ let c = b. barrier ( ) ;
362+
363+ let span1 = c. to ( & a) . unwrap ( ) ;
364+ let span2 = a. to ( & c) . unwrap ( ) ;
365+
366+ assert_eq ! ( span1. len( ) , 3 ) ;
367+ assert_eq ! ( span2. len( ) , 3 ) ;
368+ }
369+
370+ #[ test]
371+ fn test_balance_and_nonce_defaults ( ) {
372+ let ( block, _) = BlockContext :: < Ethereum > :: mocked ( ) ;
373+ let cp = block. start ( ) ;
374+
375+ let addr = Address :: ZERO ;
376+ assert_eq ! ( cp. balance_of( addr) . unwrap( ) , U256 :: ZERO ) ;
377+ assert_eq ! ( cp. nonce_of( addr) . unwrap( ) , 0 ) ;
378+ }
379+
380+ #[ test]
381+ fn test_signers_and_nonces_are_empty ( ) {
382+ let ( block, _) = BlockContext :: < Ethereum > :: mocked ( ) ;
383+ let cp = block. start ( ) ;
384+
385+ assert ! ( cp. signers( ) . is_empty( ) ) ;
386+ assert ! ( cp. nonces( ) . is_empty( ) ) ;
387+ }
388+
389+ #[ test]
390+ fn test_hash_and_is_bundle_and_has_failures_defaults ( ) {
391+ let ( block, _) = BlockContext :: < Ethereum > :: mocked ( ) ;
392+ let cp = block. start ( ) ;
393+
394+ assert_eq ! ( cp. hash( ) , None ) ;
395+ assert ! ( !cp. is_bundle( ) ) ;
396+ assert ! ( !cp. has_failures( ) ) ;
397+ assert_eq ! ( cp. failed_txs( ) . count( ) , 0 ) ;
398+ }
399+
400+ #[ test]
401+ fn test_contains_is_false_without_txs ( ) {
402+ let ( block, _) = BlockContext :: < Ethereum > :: mocked ( ) ;
403+ let cp = block. start ( ) ;
404+
405+ let fake_hash = TxHash :: repeat_byte ( 0x42 ) ;
406+ assert ! ( !cp. contains( fake_hash) ) ;
407+ }
408+
409+ #[ test]
410+ fn test_history_timestamps ( ) {
411+ let ( block, _) = BlockContext :: < Ethereum > :: mocked ( ) ;
412+ let cp1 = block. start ( ) ;
413+ thread:: sleep ( Duration :: from_millis ( 5 ) ) ;
414+ let cp2 = cp1. barrier ( ) ;
415+ assert ! ( cp2. building_since( ) <= Instant :: now( ) ) ;
416+ assert ! ( cp2. building_since( ) >= cp1. created_at( ) ) ;
417+ }
418+ }
0 commit comments