Skip to content

Commit da9deae

Browse files
committed
elementsd-tests: make bitcoind and elementsd paths configurable
1 parent f773496 commit da9deae

File tree

3 files changed

+38
-57
lines changed

3 files changed

+38
-57
lines changed

elementsd-tests/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ edition = "2018"
99
[dependencies]
1010
base64 = "0.13.0"
1111
elements = {path = "../"}
12-
elementsd = { version = "0.6.0", features = ["0_21_0", "bitcoind_22_0"] }
12+
elementsd = "0.6.0"
1313
rand = "0.8"
1414

elementsd-tests/src/lib.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,40 @@ impl Call for ElementsD {
137137

138138
#[cfg(test)]
139139
fn setup(validate_pegin: bool) -> (ElementsD, Option<BitcoinD>) {
140+
// Create env var BITCOIND_EXE_PATH to point to the ../bitcoind/bin/bitcoind binary
141+
let key = "BITCOIND_EXE";
142+
if std::env::var(key).is_err() {
143+
let mut root_path = std::env::current_dir().unwrap();
144+
while std::fs::metadata(root_path.join("LICENSE")).is_err() {
145+
if !root_path.pop() {
146+
panic!("Could not find LICENSE file; do not know where repo root is.");
147+
}
148+
}
149+
150+
let bitcoind_path = root_path
151+
.join("elementsd-tests")
152+
.join("bin")
153+
.join("bitcoind");
154+
std::env::set_var(key, bitcoind_path);
155+
}
156+
157+
// Create env var BITCOIND_EXE_PATH to point to the ../bitcoind/bin/bitcoind binary
158+
let key = "ELEMENTSD_EXE";
159+
if std::env::var(key).is_err() {
160+
let mut root_path = std::env::current_dir().unwrap();
161+
while std::fs::metadata(root_path.join("LICENSE")).is_err() {
162+
if !root_path.pop() {
163+
panic!("Could not find LICENSE file; do not know where repo root is.");
164+
}
165+
}
166+
167+
let bitcoind_path = root_path
168+
.join("elementsd-tests")
169+
.join("bin")
170+
.join("elementsd");
171+
std::env::set_var(key, bitcoind_path);
172+
}
173+
140174
let mut bitcoind = None;
141175
if validate_pegin {
142176
let bitcoind_exe = bitcoind::exe_path().unwrap();

elementsd-tests/src/pset.rs

Lines changed: 3 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
#![cfg(all(test, feature = "integration"))]
21

32
extern crate elements;
43

5-
extern crate bitcoin;
64
extern crate elementsd;
75
extern crate rand;
86

9-
use crate::setup;
7+
use crate::{setup, Call};
108

11-
use bitcoin::hashes::hex::ToHex;
12-
use bitcoin::{Address, Amount};
13-
use elements::bitcoin::hashes::hex::FromHex;
9+
use elements::bitcoin::{self, Address, Amount};
10+
use elements::bitcoin::hashes::hex::{FromHex, ToHex};
1411
use elements::bitcoin::hashes::Hash;
1512
use elements::encode::{deserialize, serialize};
1613
use elements::pset::PartiallySignedTransaction;
@@ -162,56 +159,6 @@ fn psbt_rtt(elementsd: &ElementsD, base64: &str) {
162159
}
163160
}
164161

165-
impl Call for ElementsD {
166-
fn call(&self, cmd: &str, args: &[Value]) -> Value {
167-
self.client().call::<Value>(cmd, args).unwrap()
168-
}
169-
170-
fn decode_psbt(&self, psbt: &str) -> Option<Value> {
171-
self.client()
172-
.call::<Value>("decodepsbt", &[psbt.into()])
173-
.ok()
174-
}
175-
176-
fn get_new_address(&self) -> String {
177-
self.call("getnewaddress", &[])
178-
.as_str()
179-
.unwrap()
180-
.to_string()
181-
}
182-
183-
fn generate(&self, blocks: u32) {
184-
let address = self.get_new_address();
185-
let _value = self.call("generatetoaddress", &[blocks.into(), address.into()]);
186-
}
187-
188-
189-
fn expected_next(&self, base64: &str) -> String {
190-
let value = self.call("analyzepsbt", &[base64.into()]);
191-
value.get("next").unwrap().as_str().unwrap().to_string()
192-
}
193-
194-
fn wallet_process_psbt(&self, base64: &str) -> String {
195-
let value = self.call("walletprocesspsbt", &[base64.into()]);
196-
value.get("psbt").unwrap().as_str().unwrap().to_string()
197-
}
198-
199-
fn finalize_psbt(&self, base64: &str) -> String {
200-
let value = self.call("finalizepsbt", &[base64.into()]);
201-
value.get("hex").unwrap().as_str().unwrap().to_string()
202-
}
203-
204-
fn get_balances(&self) -> Value {
205-
self.call("getbalances", &[])
206-
}
207-
208-
fn test_mempool_accept(&self, hex: &str) -> bool {
209-
let result = self.call("testmempoolaccept", &[json!([hex])]);
210-
let allowed = result.get(0).unwrap().get("allowed");
211-
allowed.unwrap().as_bool().unwrap()
212-
}
213-
}
214-
215162
fn psbt_from_base64(base64: &str) -> PartiallySignedTransaction {
216163
let bytes = base64::decode(&base64).unwrap();
217164
deserialize(&bytes).unwrap()

0 commit comments

Comments
 (0)