Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

switch back to use bitcoincore-rpc, remove create_wallet descriptor p… #37

Merged
merged 2 commits into from
Oct 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 20 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
//! ```
Expand All @@ -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
Expand Down Expand Up @@ -212,7 +212,7 @@ impl BitcoinD {
// the call is succesfull not in the returned value.
if client_base.call::<Value>("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();
Expand Down Expand Up @@ -266,7 +266,7 @@ impl BitcoinD {
pub fn create_wallet<T: AsRef<str>>(&self, wallet: T) -> Result<Client, Error> {
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()),
Expand Down Expand Up @@ -316,6 +316,8 @@ pub fn downloaded_exe_path() -> Option<String> {

#[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;
Expand Down Expand Up @@ -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]
Expand All @@ -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")))]
Expand Down Expand Up @@ -459,6 +461,11 @@ mod test {
);
}

fn peers_connected(client: &Client) -> usize {
let result: Vec<Value> = client.call("getpeerinfo", &[]).unwrap();
result.len()
}

fn exe_path() -> String {
if let Some(downloaded_exe_path) = downloaded_exe_path() {
downloaded_exe_path
Expand Down