@@ -1011,6 +1011,145 @@ mod test {
10111011 assert_eq ! ( address_stats_async. chain_stats. funded_txo_sum, 1000 ) ;
10121012 }
10131013
1014+ #[ cfg( all( feature = "blocking" , feature = "async" ) ) ]
1015+ #[ tokio:: test]
1016+ async fn test_get_scripthash_stats ( ) {
1017+ let ( blocking_client, async_client) = setup_clients ( ) . await ;
1018+
1019+ // Create an address of each type.
1020+ let address_legacy = BITCOIND
1021+ . client
1022+ . new_address_with_type ( AddressType :: Legacy )
1023+ . unwrap ( ) ;
1024+ let address_p2sh_segwit = BITCOIND
1025+ . client
1026+ . new_address_with_type ( AddressType :: P2shSegwit )
1027+ . unwrap ( ) ;
1028+ let address_bech32 = BITCOIND
1029+ . client
1030+ . new_address_with_type ( AddressType :: Bech32 )
1031+ . unwrap ( ) ;
1032+ let address_bech32m = BITCOIND
1033+ . client
1034+ . new_address_with_type ( AddressType :: Bech32m )
1035+ . unwrap ( ) ;
1036+
1037+ // Send a transaction to each address.
1038+ let _txid = BITCOIND
1039+ . client
1040+ . send_to_address ( & address_legacy, Amount :: from_sat ( 1000 ) )
1041+ . unwrap ( )
1042+ . txid ( )
1043+ . unwrap ( ) ;
1044+ let _txid = BITCOIND
1045+ . client
1046+ . send_to_address ( & address_p2sh_segwit, Amount :: from_sat ( 1000 ) )
1047+ . unwrap ( )
1048+ . txid ( )
1049+ . unwrap ( ) ;
1050+ let _txid = BITCOIND
1051+ . client
1052+ . send_to_address ( & address_bech32, Amount :: from_sat ( 1000 ) )
1053+ . unwrap ( )
1054+ . txid ( )
1055+ . unwrap ( ) ;
1056+ let _txid = BITCOIND
1057+ . client
1058+ . send_to_address ( & address_bech32m, Amount :: from_sat ( 1000 ) )
1059+ . unwrap ( )
1060+ . txid ( )
1061+ . unwrap ( ) ;
1062+
1063+ let _miner = MINER . lock ( ) . await ;
1064+ generate_blocks_and_wait ( 1 ) ;
1065+
1066+ // Derive each addresses script.
1067+ let script_legacy = address_legacy. script_pubkey ( ) ;
1068+ let script_p2sh_segwit = address_p2sh_segwit. script_pubkey ( ) ;
1069+ let script_bech32 = address_bech32. script_pubkey ( ) ;
1070+ let script_bech32m = address_bech32m. script_pubkey ( ) ;
1071+
1072+ let scripthash_stats_blocking_legacy = blocking_client. get_scripthash_stats ( & script_legacy) ;
1073+ println ! ( "{:?}" , scripthash_stats_blocking_legacy) ;
1074+
1075+ // P2PKH
1076+ let scripthash_stats_blocking_legacy = blocking_client
1077+ . get_scripthash_stats ( & script_legacy)
1078+ . unwrap ( ) ;
1079+ let scripthash_stats_async_legacy = async_client
1080+ . get_scripthash_stats ( & script_legacy)
1081+ . await
1082+ . unwrap ( ) ;
1083+ assert_eq ! (
1084+ scripthash_stats_blocking_legacy,
1085+ scripthash_stats_async_legacy
1086+ ) ;
1087+ assert_eq ! (
1088+ scripthash_stats_blocking_legacy. chain_stats. funded_txo_sum,
1089+ 1000
1090+ ) ;
1091+ assert_eq ! ( scripthash_stats_blocking_legacy. chain_stats. tx_count, 1 ) ;
1092+
1093+ // P2SH-P2WSH
1094+ let scripthash_stats_blocking_p2sh_segwit = blocking_client
1095+ . get_scripthash_stats ( & script_p2sh_segwit)
1096+ . unwrap ( ) ;
1097+ let scripthash_stats_async_p2sh_segwit = async_client
1098+ . get_scripthash_stats ( & script_p2sh_segwit)
1099+ . await
1100+ . unwrap ( ) ;
1101+ assert_eq ! (
1102+ scripthash_stats_blocking_p2sh_segwit,
1103+ scripthash_stats_async_p2sh_segwit
1104+ ) ;
1105+ assert_eq ! (
1106+ scripthash_stats_blocking_p2sh_segwit
1107+ . chain_stats
1108+ . funded_txo_sum,
1109+ 1000
1110+ ) ;
1111+ assert_eq ! (
1112+ scripthash_stats_blocking_p2sh_segwit. chain_stats. tx_count,
1113+ 1
1114+ ) ;
1115+
1116+ // P2WPKH / P2WSH
1117+ let scripthash_stats_blocking_bech32 = blocking_client
1118+ . get_scripthash_stats ( & script_bech32)
1119+ . unwrap ( ) ;
1120+ let scripthash_stats_async_bech32 = async_client
1121+ . get_scripthash_stats ( & script_bech32)
1122+ . await
1123+ . unwrap ( ) ;
1124+ assert_eq ! (
1125+ scripthash_stats_blocking_bech32,
1126+ scripthash_stats_async_bech32
1127+ ) ;
1128+ assert_eq ! (
1129+ scripthash_stats_blocking_bech32. chain_stats. funded_txo_sum,
1130+ 1000
1131+ ) ;
1132+ assert_eq ! ( scripthash_stats_blocking_bech32. chain_stats. tx_count, 1 ) ;
1133+
1134+ // P2TR
1135+ let scripthash_stats_blocking_bech32m = blocking_client
1136+ . get_scripthash_stats ( & script_bech32m)
1137+ . unwrap ( ) ;
1138+ let scripthash_stats_async_bech32m = async_client
1139+ . get_scripthash_stats ( & script_bech32m)
1140+ . await
1141+ . unwrap ( ) ;
1142+ assert_eq ! (
1143+ scripthash_stats_blocking_bech32m,
1144+ scripthash_stats_async_bech32m
1145+ ) ;
1146+ assert_eq ! (
1147+ scripthash_stats_blocking_bech32m. chain_stats. funded_txo_sum,
1148+ 1000
1149+ ) ;
1150+ assert_eq ! ( scripthash_stats_blocking_bech32m. chain_stats. tx_count, 1 ) ;
1151+ }
1152+
10141153 #[ cfg( all( feature = "blocking" , feature = "async" ) ) ]
10151154 #[ tokio:: test]
10161155 async fn test_get_address_txs ( ) {
0 commit comments