@@ -316,6 +316,8 @@ pub fn downloaded_exe_path() -> Option<String> {
316
316
317
317
#[ cfg( test) ]
318
318
mod test {
319
+ use crate :: bitcoincore_rpc:: jsonrpc:: serde_json:: Value ;
320
+ use crate :: bitcoincore_rpc:: Client ;
319
321
use crate :: downloaded_exe_path;
320
322
use crate :: { get_available_port, BitcoinD , Conf , LOCAL_IP , P2P } ;
321
323
use bitcoincore_rpc:: RpcApi ;
@@ -367,13 +369,13 @@ mod test {
367
369
conf. p2p = P2P :: Yes ;
368
370
369
371
let bitcoind = BitcoinD :: with_conf ( & exe, & conf) . unwrap ( ) ;
370
- assert_eq ! ( bitcoind. client. get_peer_info ( ) . unwrap ( ) . len ( ) , 0 ) ;
372
+ assert_eq ! ( peers_connected ( & bitcoind. client) , 0 ) ;
371
373
let mut other_conf = Conf :: default ( ) ;
372
374
other_conf. p2p = bitcoind. p2p_connect ( false ) . unwrap ( ) ;
373
375
374
376
let other_bitcoind = BitcoinD :: with_conf ( & exe, & other_conf) . unwrap ( ) ;
375
- assert_eq ! ( bitcoind. client. get_peer_info ( ) . unwrap ( ) . len ( ) , 1 ) ;
376
- assert_eq ! ( other_bitcoind. client. get_peer_info ( ) . unwrap ( ) . len ( ) , 1 ) ;
377
+ assert_eq ! ( peers_connected ( & bitcoind. client) , 1 ) ;
378
+ assert_eq ! ( peers_connected ( & other_bitcoind. client) , 1 ) ;
377
379
}
378
380
379
381
#[ test]
@@ -393,14 +395,14 @@ mod test {
393
395
let node3 = BitcoinD :: with_conf ( exe_path ( ) , & conf_node3) . unwrap ( ) ;
394
396
395
397
// Get each nodes Peers
396
- let node1_peers = node1. client . get_peer_info ( ) . unwrap ( ) ;
397
- let node2_peers = node2. client . get_peer_info ( ) . unwrap ( ) ;
398
- let node3_peers = node3. client . get_peer_info ( ) . unwrap ( ) ;
398
+ let node1_peers = peers_connected ( & node1. client ) ;
399
+ let node2_peers = peers_connected ( & node2. client ) ;
400
+ let node3_peers = peers_connected ( & node3. client ) ;
399
401
400
402
// Peers found
401
- assert ! ( node1_peers. len ( ) >= 1 ) ;
402
- assert ! ( node2_peers. len ( ) >= 1 ) ;
403
- assert_eq ! ( node3_peers. len ( ) , 1 , "listen false but more than 1 peer" ) ;
403
+ assert ! ( node1_peers >= 1 ) ;
404
+ assert ! ( node2_peers >= 1 ) ;
405
+ assert_eq ! ( node3_peers, 1 , "listen false but more than 1 peer" ) ;
404
406
}
405
407
406
408
#[ cfg( not( any( feature = "0_17_1" , feature = "0_18_0" , feature = "0_18_1" ) ) ) ]
@@ -459,6 +461,11 @@ mod test {
459
461
) ;
460
462
}
461
463
464
+ fn peers_connected ( client : & Client ) -> usize {
465
+ let result: Vec < Value > = client. call ( "getpeerinfo" , & [ ] ) . unwrap ( ) ;
466
+ result. len ( )
467
+ }
468
+
462
469
fn exe_path ( ) -> String {
463
470
if let Some ( downloaded_exe_path) = downloaded_exe_path ( ) {
464
471
downloaded_exe_path
0 commit comments