@@ -32,7 +32,7 @@ use bitcoin::{
3232 Transaction , TxIn , TxOut , Txid , Witness ,
3333} ;
3434use bitcoincore_rpc:: bitcoincore_rpc_json:: {
35- GetBlockTemplateModes , GetBlockTemplateRules , ScanTxOutRequest ,
35+ GetBlockTemplateModes , GetBlockTemplateRules , GetZmqNotificationsResult , ScanTxOutRequest ,
3636} ;
3737
3838lazy_static ! {
@@ -226,6 +226,7 @@ fn main() {
226226 test_add_ban ( & cl) ;
227227 test_set_network_active ( & cl) ;
228228 test_get_index_info ( & cl) ;
229+ test_get_zmq_notifications ( & cl) ;
229230 test_stop ( cl) ;
230231}
231232
@@ -1426,6 +1427,36 @@ fn test_get_index_info(cl: &Client) {
14261427 }
14271428}
14281429
1430+ fn test_get_zmq_notifications ( cl : & Client ) {
1431+ let mut zmq_info = cl. get_zmq_notifications ( ) . unwrap ( ) ;
1432+
1433+ // it doesn't matter in which order Bitcoin Core returns the result,
1434+ // but checking it is easier if it has a known order
1435+
1436+ // sort_by_key does not allow returning references to parameters of the compare function
1437+ // (removing the lifetime from the return type mimics this behavior, but we don't want it)
1438+ fn compare_fn ( result : & GetZmqNotificationsResult ) -> impl Ord + ' _ {
1439+ ( & result. address , & result. notification_type , result. hwm )
1440+ }
1441+ zmq_info. sort_by ( |a, b| compare_fn ( a) . cmp ( & compare_fn ( b) ) ) ;
1442+
1443+ assert ! (
1444+ zmq_info
1445+ == [
1446+ GetZmqNotificationsResult {
1447+ notification_type: "pubrawblock" . to_owned( ) ,
1448+ address: "tcp://0.0.0.0:28332" . to_owned( ) ,
1449+ hwm: 1000
1450+ } ,
1451+ GetZmqNotificationsResult {
1452+ notification_type: "pubrawtx" . to_owned( ) ,
1453+ address: "tcp://0.0.0.0:28333" . to_owned( ) ,
1454+ hwm: 1000
1455+ } ,
1456+ ]
1457+ ) ;
1458+ }
1459+
14291460fn test_stop ( cl : Client ) {
14301461 println ! ( "Stopping: '{}'" , cl. stop( ) . unwrap( ) ) ;
14311462}
0 commit comments