@@ -201,6 +201,7 @@ mod test {
201
201
use electrsd:: { bitcoind, bitcoind:: BitcoinD , ElectrsD } ;
202
202
use lazy_static:: lazy_static;
203
203
use std:: env;
204
+ use std:: str:: FromStr ;
204
205
use tokio:: sync:: Mutex ;
205
206
#[ cfg( all( feature = "blocking" , any( feature = "async" , feature = "async-https" ) ) ) ]
206
207
use {
@@ -460,6 +461,53 @@ mod test {
460
461
assert_eq ! ( block_header, block_header_async) ;
461
462
}
462
463
464
+ #[ cfg( all( feature = "blocking" , any( feature = "async" , feature = "async-https" ) ) ) ]
465
+ #[ tokio:: test]
466
+ async fn test_get_block_status ( ) {
467
+ let ( blocking_client, async_client) = setup_clients ( ) . await ;
468
+
469
+ let block_hash = BITCOIND . client . get_block_hash ( 21 ) . unwrap ( ) ;
470
+ let next_block_hash = BITCOIND . client . get_block_hash ( 22 ) . unwrap ( ) ;
471
+
472
+ let expected = BlockStatus {
473
+ in_best_chain : true ,
474
+ height : Some ( 21 ) ,
475
+ next_best : Some ( next_block_hash) ,
476
+ } ;
477
+
478
+ let block_status = blocking_client. get_block_status ( & block_hash) . unwrap ( ) ;
479
+ let block_status_async = async_client. get_block_status ( & block_hash) . await . unwrap ( ) ;
480
+ assert_eq ! ( expected, block_status) ;
481
+ assert_eq ! ( expected, block_status_async) ;
482
+ }
483
+
484
+ #[ cfg( all( feature = "blocking" , any( feature = "async" , feature = "async-https" ) ) ) ]
485
+ #[ tokio:: test]
486
+ async fn test_get_non_existing_block_status ( ) {
487
+ // Esplora returns the same status for orphaned blocks as for non-existing blocks:
488
+ // non-existing: https://blockstream.info/api/block/0000000000000000000000000000000000000000000000000000000000000000/status
489
+ // orphaned: https://blockstream.info/api/block/000000000000000000181b1a2354620f66868a723c0c4d5b24e4be8bdfc35a7f/status
490
+ // (Here the block is cited as orphaned: https://bitcoinchain.com/block_explorer/block/000000000000000000181b1a2354620f66868a723c0c4d5b24e4be8bdfc35a7f/ )
491
+ // For this reason, we only test for the non-existing case here.
492
+
493
+ let ( blocking_client, async_client) = setup_clients ( ) . await ;
494
+
495
+ let block_hash =
496
+ BlockHash :: from_str ( "0000000000000000000000000000000000000000000000000000000000000000" )
497
+ . unwrap ( ) ;
498
+
499
+ let expected = BlockStatus {
500
+ in_best_chain : false ,
501
+ height : None ,
502
+ next_best : None ,
503
+ } ;
504
+
505
+ let block_status = blocking_client. get_block_status ( & block_hash) . unwrap ( ) ;
506
+ let block_status_async = async_client. get_block_status ( & block_hash) . await . unwrap ( ) ;
507
+ assert_eq ! ( expected, block_status) ;
508
+ assert_eq ! ( expected, block_status_async) ;
509
+ }
510
+
463
511
#[ cfg( all( feature = "blocking" , any( feature = "async" , feature = "async-https" ) ) ) ]
464
512
#[ tokio:: test]
465
513
async fn test_get_merkle_proof ( ) {
0 commit comments