@@ -297,9 +297,6 @@ async fn test_deletion_and_clearing_of_database() {
297297
298298 // Clear the database
299299 db_client. clear ( ) . await . unwrap ( ) ;
300-
301- // Check the database is empty
302- // assert!(db_client.is_empty().await.unwrap());
303300 } )
304301 . await ;
305302}
@@ -357,6 +354,138 @@ async fn test_check_if_same_block_hash() {
357354 . await ;
358355}
359356
357+ #[ tokio:: test]
358+ async fn test_insertion_of_blocks_with_no_txs_and_no_receipts ( ) {
359+ test_with_clients ( |db_client| async move {
360+ db_client. init ( None , false ) . await . unwrap ( ) ;
361+
362+ let dummy_block: Block < H256 > = Block {
363+ number : ethers_core:: types:: U64 :: from ( 1 ) . into ( ) ,
364+ hash : ethers_core:: types:: H256 :: random ( ) . into ( ) ,
365+ ..Default :: default ( )
366+ } ;
367+
368+ db_client
369+ . insert_block_data ( & [ dummy_block. clone ( ) ] , & [ ] , & [ ] )
370+ . await
371+ . unwrap ( ) ;
372+
373+ let block = db_client. get_block_by_number ( 1 ) . await . unwrap ( ) ;
374+
375+ assert_eq ! ( block. number. 0 . as_u64( ) , 1 ) ;
376+ assert_eq ! ( block. hash, dummy_block. hash) ;
377+ } )
378+ . await ;
379+ }
380+
381+ #[ tokio:: test]
382+ async fn test_insertion_of_blocks_with_txs_and_no_receipts ( ) {
383+ test_with_clients ( |db_client| async move {
384+ db_client. init ( None , false ) . await . unwrap ( ) ;
385+
386+ let dummy_block: Block < H256 > = Block {
387+ number : ethers_core:: types:: U64 :: from ( 1 ) . into ( ) ,
388+ hash : ethers_core:: types:: H256 :: random ( ) . into ( ) ,
389+ ..Default :: default ( )
390+ } ;
391+
392+ let dummy_txn = Transaction {
393+ hash : ethers_core:: types:: H256 :: random ( ) . into ( ) ,
394+ block_number : Some ( 1_u64 . into ( ) ) ,
395+ ..Default :: default ( )
396+ } ;
397+
398+ db_client
399+ . insert_block_data ( & [ dummy_block. clone ( ) ] , & [ ] , & [ dummy_txn. clone ( ) ] )
400+ . await
401+ . unwrap ( ) ;
402+
403+ let block = db_client. get_full_block_by_number ( 1 ) . await . unwrap ( ) ;
404+
405+ assert_eq ! ( block. number. 0 . as_u64( ) , 1 ) ;
406+ assert_eq ! ( block. hash, dummy_block. hash) ;
407+
408+ assert_eq ! ( block. transactions. len( ) , 1 ) ;
409+ assert_eq ! ( block. transactions[ 0 ] . hash, dummy_txn. hash) ;
410+ } )
411+ . await ;
412+ }
413+
414+ #[ tokio:: test]
415+ async fn test_insertion_of_blocks_with_no_txs_and_receipts ( ) {
416+ test_with_clients ( |db_client| async move {
417+ db_client. init ( None , false ) . await . unwrap ( ) ;
418+
419+ let dummy_block: Block < H256 > = Block {
420+ number : ethers_core:: types:: U64 :: from ( 1 ) . into ( ) ,
421+ hash : ethers_core:: types:: H256 :: random ( ) . into ( ) ,
422+ ..Default :: default ( )
423+ } ;
424+
425+ let dummy_receipt = new_storable_execution_result (
426+ ethers_core:: types:: H256 :: random ( ) . into ( ) ,
427+ dummy_block. hash . clone ( ) ,
428+ 1_u64 . into ( ) ,
429+ ) ;
430+
431+ db_client
432+ . insert_block_data ( & [ dummy_block. clone ( ) ] , & [ dummy_receipt. clone ( ) ] , & [ ] )
433+ . await
434+ . unwrap ( ) ;
435+
436+ let block = db_client. get_block_by_number ( 1 ) . await . unwrap ( ) ;
437+
438+ assert_eq ! ( block. number. 0 . as_u64( ) , 1 ) ;
439+ assert_eq ! ( block. hash, dummy_block. hash) ;
440+
441+ assert_eq ! ( block. transactions. len( ) , 0 ) ;
442+
443+ let receipt = db_client
444+ . get_transaction_receipt ( dummy_receipt. transaction_hash . clone ( ) )
445+ . await
446+ . unwrap ( ) ;
447+
448+ assert_eq ! ( receipt. transaction_hash, dummy_receipt. transaction_hash) ;
449+ } )
450+ . await ;
451+ }
452+
453+ #[ tokio:: test]
454+ async fn test_insertion_of_txs_and_receipts_with_no_blocks ( ) {
455+ test_with_clients ( |db_client| async move {
456+ db_client. init ( None , false ) . await . unwrap ( ) ;
457+
458+ let dummy_txn = Transaction {
459+ hash : ethers_core:: types:: H256 :: random ( ) . into ( ) ,
460+ block_number : Some ( 1_u64 . into ( ) ) ,
461+ ..Default :: default ( )
462+ } ;
463+
464+ let dummy_receipt = new_storable_execution_result (
465+ ethers_core:: types:: H256 :: random ( ) . into ( ) ,
466+ ethers_core:: types:: H256 :: random ( ) . into ( ) ,
467+ 1_u64 . into ( ) ,
468+ ) ;
469+
470+ db_client
471+ . insert_block_data ( & [ ] , & [ dummy_receipt] , & [ dummy_txn. clone ( ) ] )
472+ . await
473+ . unwrap ( ) ;
474+
475+ let receipt = db_client
476+ . get_transaction_receipt ( dummy_txn. hash . clone ( ) )
477+ . await
478+ . unwrap ( ) ;
479+
480+ assert_eq ! ( receipt. transaction_hash, dummy_txn. hash) ;
481+
482+ let block = db_client. get_block_by_number ( 1 ) . await ;
483+
484+ assert ! ( block. is_err( ) ) ;
485+ } )
486+ . await ;
487+ }
488+
360489fn new_storable_execution_result (
361490 transaction_hash : H256 ,
362491 block_hash : H256 ,
0 commit comments