Skip to content

Commit 00a4ad7

Browse files
committed
properly test get_zmq_notifications
1 parent bcb61e6 commit 00a4ad7

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

integration_test/run.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ bitcoind -regtest $BLOCKFILTERARG $FALLBACKFEEARG \
3434
-rpcport=12349 \
3535
-server=1 \
3636
-txindex=1 \
37-
-printtoconsole=0 &
37+
-printtoconsole=0 \
38+
-zmqpubrawblock=tcp://0.0.0.0:28332 \
39+
-zmqpubrawtx=tcp://0.0.0.0:28333 &
3840
PID2=$!
3941

4042
# Let it connect to the other node.

integration_test/src/main.rs

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#[macro_use]
1414
extern crate lazy_static;
1515

16+
use std::cmp::Ordering;
1617
use std::collections::HashMap;
1718
use std::str::FromStr;
1819

@@ -32,7 +33,7 @@ use bitcoin::{
3233
Sequence, SignedAmount, Transaction, TxIn, TxOut, Txid, Witness,
3334
};
3435
use bitcoincore_rpc::bitcoincore_rpc_json::{
35-
GetBlockTemplateModes, GetBlockTemplateRules, ScanTxOutRequest,
36+
GetBlockTemplateModes, GetBlockTemplateRules, ScanTxOutRequest, GetZmqNotificationsResult,
3637
};
3738

3839
lazy_static! {
@@ -1322,10 +1323,32 @@ fn test_get_index_info(cl: &Client) {
13221323
}
13231324

13241325
fn test_get_zmq_notifications(cl: &Client) {
1325-
let zmq_info = cl.get_zmq_notifications().unwrap();
1326+
let mut zmq_info = cl.get_zmq_notifications().unwrap();
1327+
1328+
// it doesn't matter in which order Bitcoin Core returns the result,
1329+
// but checking it is easier if it has a known order
1330+
zmq_info.sort_by(|a, b| {
1331+
if a.address < b.address {
1332+
Ordering::Less
1333+
} else if a.address == b.address {
1334+
Ordering::Equal
1335+
} else {
1336+
Ordering::Greater
1337+
}
1338+
});
13261339

1327-
// no zmq subscribers are configured
1328-
assert!(zmq_info.is_empty());
1340+
assert!(zmq_info == vec![
1341+
GetZmqNotificationsResult {
1342+
notification_type: "pubrawblock".to_owned(),
1343+
address: "tcp://0.0.0.0:28332".to_owned(),
1344+
hwm: 1000
1345+
},
1346+
GetZmqNotificationsResult {
1347+
notification_type: "pubrawtx".to_owned(),
1348+
address: "tcp://0.0.0.0:28333".to_owned(),
1349+
hwm: 1000
1350+
},
1351+
]);
13291352
}
13301353

13311354
fn test_stop(cl: Client) {

0 commit comments

Comments
 (0)