Skip to content

Commit c0364c5

Browse files
committed
Use bitcoind for launching bitcoind, add github actions CI
1 parent a3df1c2 commit c0364c5

File tree

6 files changed

+78
-84
lines changed

6 files changed

+78
-84
lines changed

.github/workflows/test.yml

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Test
2+
3+
on: [push]
4+
5+
env:
6+
CARGO_TERM_COLOR: always
7+
8+
jobs:
9+
10+
test:
11+
runs-on: ubuntu-20.04
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
features: [ "bitcoind/0_21_1", "bitcoind/0_19_1"]
16+
17+
18+
steps:
19+
- uses: actions/checkout@v2
20+
- uses: Swatinem/[email protected]
21+
with:
22+
key: ${{ matrix.features }}
23+
- uses: actions-rs/toolchain@v1
24+
with:
25+
toolchain: stable
26+
override: true
27+
- uses: actions-rs/cargo@v1
28+
with:
29+
command: test
30+
args: --verbose --all --features ${{ matrix.features }}
31+
32+
cosmetics:
33+
runs-on: ubuntu-20.04
34+
steps:
35+
- uses: actions/checkout@v2
36+
- uses: Swatinem/[email protected]
37+
- uses: actions-rs/toolchain@v1
38+
with:
39+
toolchain: stable
40+
override: true
41+
profile: minimal
42+
components: rustfmt, clippy
43+
- name: fmt
44+
run: cargo fmt -- --check
45+
- name: clippy
46+
run: cargo clippy -- -D warnings

Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@
33
members = [
44
"json",
55
"client",
6-
"integration_test",
76
]

client/Cargo.toml

+6
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,9 @@ jsonrpc = "0.12.0"
2727
# Used for deserialization of JSON.
2828
serde = "1"
2929
serde_json = "1"
30+
31+
32+
[dev-dependencies]
33+
bitcoin = { version = "0.27.0", features = ["rand"] }
34+
bitcoind = { version = "0.18.0" }
35+
lazy_static = "1.4.0"

integration_test/src/main.rs renamed to client/tests/integration.rs

+26-23
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ extern crate bitcoin;
1414
extern crate core_rpc as bitcoincore_rpc;
1515
#[macro_use]
1616
extern crate lazy_static;
17+
extern crate bitcoind;
1718
extern crate log;
1819

1920
use bitcoincore_rpc::core_rpc_json as bitcoincore_rpc_json;
@@ -34,6 +35,7 @@ use bitcoin::{
3435
TxIn, TxOut, Txid,
3536
};
3637
use bitcoincore_rpc_json::{GetBlockTemplateModes, GetBlockTemplateRules, ScanTxOutRequest};
38+
use bitcoind::{BitcoinD, P2P};
3739

3840
lazy_static! {
3941
static ref SECP: secp256k1::Secp256k1<secp256k1::All> = secp256k1::Secp256k1::new();
@@ -108,25 +110,24 @@ fn sbtc<F: Into<f64>>(btc: F) -> SignedAmount {
108110
SignedAmount::from_btc(btc.into()).unwrap()
109111
}
110112

111-
fn get_rpc_url() -> String {
112-
return std::env::var("RPC_URL").expect("RPC_URL must be set");
113-
}
113+
#[test]
114+
fn integration_test() {
115+
log::set_logger(&LOGGER).map(|()| log::set_max_level(log::LevelFilter::max())).unwrap();
114116

115-
fn get_auth() -> bitcoincore_rpc::Auth {
116-
if let Ok(cookie) = std::env::var("RPC_COOKIE") {
117-
return Auth::CookieFile(cookie.into());
118-
} else if let Ok(user) = std::env::var("RPC_USER") {
119-
return Auth::UserPass(user, std::env::var("RPC_PASS").unwrap_or_default());
120-
} else {
121-
panic!("Either RPC_COOKIE or RPC_USER + RPC_PASS must be set.");
122-
};
123-
}
117+
let mut conf = bitcoind::Conf::default();
118+
conf.args.push("-blockfilterindex=1");
119+
conf.p2p = P2P::Yes;
120+
let bitcoind =
121+
bitcoind::BitcoinD::with_conf(bitcoind::downloaded_exe_path().unwrap(), &conf).unwrap();
124122

125-
fn main() {
126-
log::set_logger(&LOGGER).map(|()| log::set_max_level(log::LevelFilter::max())).unwrap();
123+
let mut conf2 = bitcoind::Conf::default();
124+
conf2.p2p = bitcoind.p2p_connect(true).unwrap();
125+
let _bitcoind2 =
126+
bitcoind::BitcoinD::with_conf(bitcoind::downloaded_exe_path().unwrap(), &conf2).unwrap();
127127

128-
let rpc_url = format!("{}/wallet/testwallet", get_rpc_url());
129-
let cl = Client::new(&rpc_url, get_auth()).unwrap();
128+
let rpc_url = bitcoind.rpc_url_with_wallet("testwallet");
129+
let auth = Auth::CookieFile(bitcoind.params.cookie_file.clone());
130+
let cl = Client::new(&rpc_url, auth.clone()).unwrap();
130131

131132
test_get_network_info(&cl);
132133
unsafe { VERSION = cl.version().unwrap() };
@@ -183,7 +184,7 @@ fn main() {
183184
test_ping(&cl);
184185
test_get_peer_info(&cl);
185186
test_rescan_blockchain(&cl);
186-
test_create_wallet(&cl);
187+
test_create_wallet(&cl, &bitcoind);
187188
test_get_tx_out_set_info(&cl);
188189
test_get_chain_tips(&cl);
189190
test_get_net_totals(&cl);
@@ -203,8 +204,8 @@ fn main() {
203204
//TODO unload_wallet(&self, wallet: Option<&str>) -> Result<()> {
204205
//TODO backup_wallet(&self, destination: Option<&str>) -> Result<()> {
205206

206-
let rpc_url = format!("{}/wallet/testdescriptorwallet", get_rpc_url());
207-
let desc_cl = Client::new(&rpc_url, get_auth()).unwrap();
207+
let rpc_url = bitcoind.rpc_url_with_wallet("testdescriptorwallet");
208+
let desc_cl = Client::new(&rpc_url, auth).unwrap();
208209

209210
test_descriptor_wallet(&desc_cl);
210211
test_stop(cl);
@@ -900,7 +901,7 @@ fn test_rescan_blockchain(cl: &Client) {
900901
assert_eq!(stop, Some(count - 1));
901902
}
902903

903-
fn test_create_wallet(cl: &Client) {
904+
fn test_create_wallet(cl: &Client, bitcoind: &BitcoinD) {
904905
let wallet_names = vec!["alice", "bob", "carol", "denise", "emily"];
905906

906907
struct WalletParams<'a> {
@@ -979,8 +980,10 @@ fn test_create_wallet(cl: &Client) {
979980
};
980981
assert_eq!(result.warning, expected_warning);
981982

982-
let wallet_client_url = format!("{}{}{}", get_rpc_url(), "/wallet/", wallet_param.name);
983-
let wallet_client = Client::new(&wallet_client_url, get_auth()).unwrap();
983+
let wallet_client_url = bitcoind.rpc_url_with_wallet(wallet_param.name);
984+
let auth = Auth::CookieFile(bitcoind.params.cookie_file.clone());
985+
986+
let wallet_client = Client::new(&wallet_client_url, auth).unwrap();
984987
let wallet_info = wallet_client.get_wallet_info().unwrap();
985988

986989
assert_eq!(wallet_info.wallet_name, wallet_param.name);
@@ -1006,7 +1009,7 @@ fn test_create_wallet(cl: &Client) {
10061009
wallet_list.retain(|w| w != "testwallet" && w != "");
10071010

10081011
// Created wallets
1009-
assert!(wallet_list.iter().zip(wallet_names).all(|(a, b)| a == b));
1012+
assert!(wallet_names.iter().any(|e| wallet_list.contains(&e.to_string())));
10101013
}
10111014

10121015
fn test_get_tx_out_set_info(cl: &Client) {

integration_test/Cargo.toml

-10
This file was deleted.

integration_test/run.sh

-50
This file was deleted.

0 commit comments

Comments
 (0)