From 77cf140e7ec0156cf066e82584811d7d523134f3 Mon Sep 17 00:00:00 2001 From: Antoni Spaanderman <56turtle56@gmail.com> Date: Wed, 19 Apr 2023 20:30:52 +0200 Subject: [PATCH] properly test get_zmq_notifications --- integration_test/run.sh | 4 +++- integration_test/src/main.rs | 31 +++++++++++++++++++++++++++---- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/integration_test/run.sh b/integration_test/run.sh index a442ae47..fcfa27d9 100755 --- a/integration_test/run.sh +++ b/integration_test/run.sh @@ -34,7 +34,9 @@ bitcoind -regtest $BLOCKFILTERARG $FALLBACKFEEARG \ -rpcport=12349 \ -server=1 \ -txindex=1 \ - -printtoconsole=0 & + -printtoconsole=0 \ + -zmqpubrawblock=tcp://0.0.0.0:28332 \ + -zmqpubrawtx=tcp://0.0.0.0:28333 & PID2=$! # Let it connect to the other node. diff --git a/integration_test/src/main.rs b/integration_test/src/main.rs index b5eda8cb..45836b09 100644 --- a/integration_test/src/main.rs +++ b/integration_test/src/main.rs @@ -13,6 +13,7 @@ #[macro_use] extern crate lazy_static; +use std::cmp::Ordering; use std::collections::HashMap; use std::str::FromStr; @@ -32,7 +33,7 @@ use bitcoin::{ Sequence, SignedAmount, Transaction, TxIn, TxOut, Txid, Witness, }; use bitcoincore_rpc::bitcoincore_rpc_json::{ - GetBlockTemplateModes, GetBlockTemplateRules, ScanTxOutRequest, + GetBlockTemplateModes, GetBlockTemplateRules, ScanTxOutRequest, GetZmqNotificationsResult, }; lazy_static! { @@ -1293,10 +1294,32 @@ fn test_get_index_info(cl: &Client) { } fn test_get_zmq_notifications(cl: &Client) { - let zmq_info = cl.get_zmq_notifications().unwrap(); + let mut zmq_info = cl.get_zmq_notifications().unwrap(); + + // it doesn't matter in which order Bitcoin Core returns the result, + // but checking it is easier if it has a known order + zmq_info.sort_by(|a, b| { + if a.address < b.address { + Ordering::Less + } else if a.address == b.address { + Ordering::Equal + } else { + Ordering::Greater + } + }); - // no zmq subscribers are configured - assert!(zmq_info.is_empty()); + assert!(zmq_info == vec![ + GetZmqNotificationsResult { + notification_type: "pubrawblock".to_owned(), + address: "tcp://0.0.0.0:28332".to_owned(), + hwm: 1000 + }, + GetZmqNotificationsResult { + notification_type: "pubrawtx".to_owned(), + address: "tcp://0.0.0.0:28333".to_owned(), + hwm: 1000 + }, + ]); } fn test_stop(cl: Client) {