Skip to content

Commit 29bdd74

Browse files
ryanofskySjors
andcommitted
test: Support BITCOIN_CMD environment variable
Support new BITCOIN_CMD environment variable in functional test to be able to test the new bitcoin wrapper executable and run other commands through it instead of calling them directly. Co-authored-by: Sjors Provoost <[email protected]>
1 parent 9c8c688 commit 29bdd74

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

test/functional/test_framework/test_framework.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import pdb
1414
import random
1515
import re
16+
import shlex
1617
import shutil
1718
import subprocess
1819
import sys
@@ -72,33 +73,37 @@ def __init__(self, paths, bin_dir):
7273
self.paths = paths
7374
self.bin_dir = bin_dir
7475

75-
def daemon_argv(self):
76+
def node_argv(self):
7677
"Return argv array that should be used to invoke bitcoind"
77-
return self._argv(self.paths.bitcoind)
78+
return self._argv("node", self.paths.bitcoind)
7879

7980
def rpc_argv(self):
8081
"Return argv array that should be used to invoke bitcoin-cli"
81-
return self._argv(self.paths.bitcoincli)
82+
# Add -nonamed because "bitcoin rpc" enables -named by default, but bitcoin-cli doesn't
83+
return self._argv("rpc", self.paths.bitcoincli) + ["-nonamed"]
8284

8385
def util_argv(self):
8486
"Return argv array that should be used to invoke bitcoin-util"
85-
return self._argv(self.paths.bitcoinutil)
87+
return self._argv("util", self.paths.bitcoinutil)
8688

8789
def wallet_argv(self):
8890
"Return argv array that should be used to invoke bitcoin-wallet"
89-
return self._argv(self.paths.bitcoinwallet)
91+
return self._argv("wallet", self.paths.bitcoinwallet)
9092

9193
def chainstate_argv(self):
9294
"Return argv array that should be used to invoke bitcoin-chainstate"
93-
return self._argv(self.paths.bitcoinchainstate)
94-
95-
def _argv(self, bin_path):
96-
"""Return argv array that should be used to invoke the command.
97-
Normally this will return binary paths directly from the paths object,
98-
but when bin_dir is set (by tests calling binaries from previous
99-
releases) it will return paths relative to bin_dir instead."""
95+
return self._argv("chainstate", self.paths.bitcoinchainstate)
96+
97+
def _argv(self, command, bin_path):
98+
"""Return argv array that should be used to invoke the command. It
99+
either uses the bitcoin wrapper executable (if BITCOIN_CMD is set), or
100+
the direct binary path (bitcoind, etc). When bin_dir is set (by tests
101+
calling binaries from previous releases) it always uses the direct
102+
path."""
100103
if self.bin_dir is not None:
101104
return [os.path.join(self.bin_dir, os.path.basename(bin_path))]
105+
elif self.paths.bitcoin_cmd is not None:
106+
return self.paths.bitcoin_cmd + [command]
102107
else:
103108
return [bin_path]
104109

@@ -292,6 +297,9 @@ def get_binary_paths(self):
292297
binary + self.config["environment"]["EXEEXT"],
293298
)
294299
setattr(paths, attribute_name, os.getenv(env_variable_name, default=default_filename))
300+
# BITCOIN_CMD environment variable can be specified to invoke bitcoin
301+
# wrapper binary instead of other executables.
302+
paths.bitcoin_cmd = shlex.split(os.getenv("BITCOIN_CMD", "")) or None
295303
return paths
296304

297305
def get_binaries(self, bin_dir=None):
@@ -537,7 +545,7 @@ def bin_dir_from_version(version):
537545
bins_missing = False
538546
for bin_path in (argv[0] for bin_dir in bin_dirs
539547
for binaries in (self.get_binaries(bin_dir),)
540-
for argv in (binaries.daemon_argv(), binaries.rpc_argv())):
548+
for argv in (binaries.node_argv(), binaries.rpc_argv())):
541549
if shutil.which(bin_path) is None:
542550
self.log.error(f"Binary not found: {bin_path}")
543551
bins_missing = True

test/functional/test_framework/test_node.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def __init__(self, i, datadir_path, *, chain, rpchost, timewait, timeout_factor,
108108
# Configuration for logging is set as command-line args rather than in the bitcoin.conf file.
109109
# This means that starting a bitcoind using the temp dir to debug a failed test won't
110110
# spam debug.log.
111-
self.args = self.binaries.daemon_argv() + [
111+
self.args = self.binaries.node_argv() + [
112112
f"-datadir={self.datadir_path}",
113113
"-logtimemicros",
114114
"-debug",

0 commit comments

Comments
 (0)