diff --git a/Cargo.toml b/Cargo.toml index feada78..d66f761 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ documentation = "https://docs.rs/bitcoind/" edition = "2018" [dependencies] -core-rpc = "0.15" +bitcoincore-rpc = "0.14.0" tempfile = "3.1" log = "0.4" home = "0.5.3" # use same ver in build-dep diff --git a/src/lib.rs b/src/lib.rs index 1772a81..c0e1bb5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,7 +6,7 @@ //! Utility to run a regtest bitcoind process, useful in integration testing environment //! //! ```no_run -//! use core_rpc::RpcApi; +//! use bitcoincore_rpc::RpcApi; //! let bitcoind = bitcoind::BitcoinD::new("/usr/local/bin/bitcoind").unwrap(); //! assert_eq!(0, bitcoind.client.get_blockchain_info().unwrap().blocks); //! ``` @@ -24,7 +24,7 @@ use std::time::Duration; use std::{env, thread}; use tempfile::TempDir; -pub extern crate core_rpc as bitcoincore_rpc; +pub extern crate bitcoincore_rpc; pub extern crate tempfile; /// Struct representing the bitcoind process with related information @@ -212,7 +212,7 @@ impl BitcoinD { // the call is succesfull not in the returned value. if client_base.call::("getblockchaininfo", &[]).is_ok() { client_base - .create_wallet("default", None, None, None, None, None) + .create_wallet("default", None, None, None, None) .unwrap(); break Client::new(&node_url_default, Auth::CookieFile(cookie_file.clone())) .unwrap(); @@ -266,7 +266,7 @@ impl BitcoinD { pub fn create_wallet>(&self, wallet: T) -> Result { let _ = self .client - .create_wallet(wallet.as_ref(), None, None, None, None, None)?; + .create_wallet(wallet.as_ref(), None, None, None, None)?; Ok(Client::new( &self.rpc_url_with_wallet(wallet), Auth::CookieFile(self.params.cookie_file.clone()), @@ -316,6 +316,8 @@ pub fn downloaded_exe_path() -> Option { #[cfg(test)] mod test { + use crate::bitcoincore_rpc::jsonrpc::serde_json::Value; + use crate::bitcoincore_rpc::Client; use crate::downloaded_exe_path; use crate::{get_available_port, BitcoinD, Conf, LOCAL_IP, P2P}; use bitcoincore_rpc::RpcApi; @@ -367,13 +369,13 @@ mod test { conf.p2p = P2P::Yes; let bitcoind = BitcoinD::with_conf(&exe, &conf).unwrap(); - assert_eq!(bitcoind.client.get_peer_info().unwrap().len(), 0); + assert_eq!(peers_connected(&bitcoind.client), 0); let mut other_conf = Conf::default(); other_conf.p2p = bitcoind.p2p_connect(false).unwrap(); let other_bitcoind = BitcoinD::with_conf(&exe, &other_conf).unwrap(); - assert_eq!(bitcoind.client.get_peer_info().unwrap().len(), 1); - assert_eq!(other_bitcoind.client.get_peer_info().unwrap().len(), 1); + assert_eq!(peers_connected(&bitcoind.client), 1); + assert_eq!(peers_connected(&other_bitcoind.client), 1); } #[test] @@ -393,14 +395,14 @@ mod test { let node3 = BitcoinD::with_conf(exe_path(), &conf_node3).unwrap(); // Get each nodes Peers - let node1_peers = node1.client.get_peer_info().unwrap(); - let node2_peers = node2.client.get_peer_info().unwrap(); - let node3_peers = node3.client.get_peer_info().unwrap(); + let node1_peers = peers_connected(&node1.client); + let node2_peers = peers_connected(&node2.client); + let node3_peers = peers_connected(&node3.client); // Peers found - assert!(node1_peers.len() >= 1); - assert!(node2_peers.len() >= 1); - assert_eq!(node3_peers.len(), 1, "listen false but more than 1 peer"); + assert!(node1_peers >= 1); + assert!(node2_peers >= 1); + assert_eq!(node3_peers, 1, "listen false but more than 1 peer"); } #[cfg(not(any(feature = "0_17_1", feature = "0_18_0", feature = "0_18_1")))] @@ -459,6 +461,11 @@ mod test { ); } + fn peers_connected(client: &Client) -> usize { + let result: Vec = client.call("getpeerinfo", &[]).unwrap(); + result.len() + } + fn exe_path() -> String { if let Some(downloaded_exe_path) = downloaded_exe_path() { downloaded_exe_path