Skip to content

Commit

Permalink
properly test get_zmq_notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
antonilol committed Jun 22, 2023
1 parent 4778897 commit 8d99fbd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
4 changes: 3 additions & 1 deletion integration_test/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
31 changes: 27 additions & 4 deletions integration_test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#[macro_use]
extern crate lazy_static;

use std::cmp::Ordering;
use std::collections::HashMap;
use std::str::FromStr;

Expand All @@ -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! {
Expand Down Expand Up @@ -1424,10 +1425,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) {
Expand Down

0 comments on commit 8d99fbd

Please sign in to comment.