-
Notifications
You must be signed in to change notification settings - Fork 150
/
Copy pathmod.rs
41 lines (35 loc) · 1.3 KB
/
mod.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
extern crate miniscript;
use bitcoind::client::bitcoin;
pub mod test_util;
// Launch an instance of bitcoind with
pub fn setup() -> bitcoind::Node {
// Create env var BITCOIND_EXE_PATH to point to the ../bitcoind/bin/bitcoind binary
let key = "BITCOIND_EXE";
if std::env::var(key).is_err() {
let mut root_path = std::env::current_dir().unwrap();
while std::fs::metadata(root_path.join("LICENSE")).is_err() {
if !root_path.pop() {
panic!("Could not find LICENSE file; do not know where repo root is.");
}
}
let bitcoind_path = root_path
.join("bitcoind-tests")
.join("bin")
.join("bitcoind");
std::env::set_var(key, bitcoind_path);
}
let exe_path = bitcoind::exe_path().unwrap();
let bitcoind = bitcoind::Node::new(exe_path).unwrap();
let cl = &bitcoind.client;
// generate to an address by the wallet. And wait for funds to mature
let addr = cl.new_address().unwrap();
let blks = cl.generate_to_address(101, &addr).unwrap();
assert_eq!(blks.0.len(), 101);
let balance = cl
.get_balance()
.expect("failed to get balance")
.balance()
.unwrap();
assert_eq!(balance, bitcoin::Amount::from_sat(100_000_000 * 50));
bitcoind
}