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 <sjors@sprovoost.nl>
This commit is contained in:
Ryan OfskyandSjors Provoost committed 2025-05-12 13:49:17 -05:00
1 parent 9c8c68891b
commit 29bdd743bb
2 files changed
+21 -13

No files matched your search

@@ -13,6 +13,7 @@ import platform
import pdb import pdb
import random import random
import re import re
import shlex
import shutil import shutil
import subprocess import subprocess
import sys import sys
@@ -72,33 +73,37 @@ class Binaries:
self.paths = paths self.paths = paths
self.bin_dir = bin_dir self.bin_dir = bin_dir
def daemon_argv(self): def node_argv(self):
"Return argv array that should be used to invoke bitcoind" "Return argv array that should be used to invoke bitcoind"
return self._argv(self.paths.bitcoind) return self._argv("node", self.paths.bitcoind)
def rpc_argv(self): def rpc_argv(self):
"Return argv array that should be used to invoke bitcoin-cli" "Return argv array that should be used to invoke bitcoin-cli"
return self._argv(self.paths.bitcoincli) # Add -nonamed because "bitcoin rpc" enables -named by default, but bitcoin-cli doesn't
return self._argv("rpc", self.paths.bitcoincli) + ["-nonamed"]
def util_argv(self): def util_argv(self):
"Return argv array that should be used to invoke bitcoin-util" "Return argv array that should be used to invoke bitcoin-util"
return self._argv(self.paths.bitcoinutil) return self._argv("util", self.paths.bitcoinutil)
def wallet_argv(self): def wallet_argv(self):
"Return argv array that should be used to invoke bitcoin-wallet" "Return argv array that should be used to invoke bitcoin-wallet"
return self._argv(self.paths.bitcoinwallet) return self._argv("wallet", self.paths.bitcoinwallet)
def chainstate_argv(self): def chainstate_argv(self):
"Return argv array that should be used to invoke bitcoin-chainstate" "Return argv array that should be used to invoke bitcoin-chainstate"
return self._argv(self.paths.bitcoinchainstate) return self._argv("chainstate", self.paths.bitcoinchainstate)
def _argv(self, bin_path): def _argv(self, command, bin_path):
"""Return argv array that should be used to invoke the command. """Return argv array that should be used to invoke the command. It
Normally this will return binary paths directly from the paths object, either uses the bitcoin wrapper executable (if BITCOIN_CMD is set), or
but when bin_dir is set (by tests calling binaries from previous the direct binary path (bitcoind, etc). When bin_dir is set (by tests
releases) it will return paths relative to bin_dir instead.""" calling binaries from previous releases) it always uses the direct
path."""
if self.bin_dir is not None: if self.bin_dir is not None:
return [os.path.join(self.bin_dir, os.path.basename(bin_path))] return [os.path.join(self.bin_dir, os.path.basename(bin_path))]
elif self.paths.bitcoin_cmd is not None:
return self.paths.bitcoin_cmd + [command]
else: else:
return [bin_path] return [bin_path]
@@ -292,6 +297,9 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass):
binary + self.config["environment"]["EXEEXT"], binary + self.config["environment"]["EXEEXT"],
) )
setattr(paths, attribute_name, os.getenv(env_variable_name, default=default_filename)) setattr(paths, attribute_name, os.getenv(env_variable_name, default=default_filename))
# BITCOIN_CMD environment variable can be specified to invoke bitcoin
# wrapper binary instead of other executables.
paths.bitcoin_cmd = shlex.split(os.getenv("BITCOIN_CMD", "")) or None
return paths return paths
def get_binaries(self, bin_dir=None): def get_binaries(self, bin_dir=None):
@@ -537,7 +545,7 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass):
bins_missing = False bins_missing = False
for bin_path in (argv[0] for bin_dir in bin_dirs for bin_path in (argv[0] for bin_dir in bin_dirs
for binaries in (self.get_binaries(bin_dir),) for binaries in (self.get_binaries(bin_dir),)
for argv in (binaries.daemon_argv(), binaries.rpc_argv())): for argv in (binaries.node_argv(), binaries.rpc_argv())):
if shutil.which(bin_path) is None: if shutil.which(bin_path) is None:
self.log.error(f"Binary not found: {bin_path}") self.log.error(f"Binary not found: {bin_path}")
bins_missing = True bins_missing = True
+1 -1
View File
@@ -108,7 +108,7 @@ class TestNode():
# Configuration for logging is set as command-line args rather than in the bitcoin.conf file. # Configuration for logging is set as command-line args rather than in the bitcoin.conf file.
# This means that starting a bitcoind using the temp dir to debug a failed test won't # This means that starting a bitcoind using the temp dir to debug a failed test won't
# spam debug.log. # spam debug.log.
self.args = self.binaries.daemon_argv() + [ self.args = self.binaries.node_argv() + [
f"-datadir={self.datadir_path}", f"-datadir={self.datadir_path}",
"-logtimemicros", "-logtimemicros",
"-debug", "-debug",