Skip to content

Commit 8c22315

Browse files
committed
node(test): Hack around the bitcoind exe path error
1 parent 79d7f8c commit 8c22315

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

node/src/command/test/mod.rs

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,39 @@ fn default_args_for_user(user_pk: UserPk) -> StartArgs {
5555
}
5656
}
5757

58+
/// Hacks around the recurring 'No such file or directory' error when trying to
59+
/// locate the local bitcoind executable.
60+
///
61+
/// https://github.com/RCasatta/bitcoind/issues/77
62+
fn bitcoind_exe_path() -> String {
63+
use std::env;
64+
// "/Users/fang/lexe/client/target/debug/build/bitcoind-65c3b20abafd4893/out/bitcoin/bitcoin-22.0/bin/bitcoind"
65+
// The path prior to `target` is wrong, everything after is correct
66+
let bitcoind_path = bitcoind::downloaded_exe_path()
67+
.expect("Didn't specify bitcoind version in feature flags");
68+
69+
// Construct the workspace path based on env::current_dir()
70+
// "/Users/fang/lexe/dev/client/node"
71+
let crate_dir = env::current_dir().unwrap();
72+
// "/Users/fang/lexe/dev/client"
73+
let workspace_dir = crate_dir.parent().unwrap().to_str().unwrap();
74+
75+
// Split on `target` to grab the correct half of the bitcoind_path string
76+
let mut path_halves = bitcoind_path.split("target");
77+
let _wrong_half = path_halves.next();
78+
// "/debug/build/bitcoind-65c3b20abafd4893/out/bitcoin/bitcoin-22.0/bin/bitcoind"
79+
let right_half = path_halves.next().unwrap();
80+
81+
let exe_path = format!("{workspace_dir}/target{right_half}");
82+
83+
dbg!(&bitcoind_path);
84+
dbg!(&crate_dir);
85+
dbg!(&workspace_dir);
86+
dbg!(&exe_path);
87+
88+
exe_path
89+
}
90+
5891
struct CommandTestHarness {
5992
bitcoind: BitcoinD,
6093
node: LexeNode,
@@ -69,8 +102,7 @@ impl CommandTestHarness {
69102
conf.args.push("-rpcauth=kek:b6c15926aee7ebfbd3669ec8a6515c79$2dba596a7d651187021b1f56d339f0fe465c2ab1b81c37b05e07a320b07822d7");
70103

71104
// Init bitcoind
72-
let exe_path = bitcoind::downloaded_exe_path()
73-
.expect("Didn't specify bitcoind version in feature flags");
105+
let exe_path = bitcoind_exe_path();
74106
let bitcoind = BitcoinD::with_conf(exe_path, &conf)
75107
.expect("Failed to init bitcoind");
76108
let host = bitcoind.params.rpc_socket.ip().to_string();

0 commit comments

Comments
 (0)