|
14 | 14 | import pdb |
15 | 15 | import random |
16 | 16 | import re |
17 | | -import shlex |
18 | 17 | import shutil |
19 | 18 | import subprocess |
20 | 19 | import sys |
21 | 20 | import tempfile |
22 | 21 | import time |
23 | | -import types |
24 | 22 |
|
25 | 23 | from .address import create_deterministic_address_bcrt1_p2tr_op_true |
26 | 24 | from .authproxy import JSONRPCException |
27 | 25 | from . import coverage |
28 | 26 | from .p2p import NetworkThread |
29 | 27 | from .test_node import TestNode |
30 | 28 | from .util import ( |
| 29 | + Binaries, |
31 | 30 | MAX_NODES, |
32 | 31 | PortSeed, |
33 | 32 | assert_equal, |
34 | 33 | check_json_precision, |
35 | 34 | find_vout_for_address, |
| 35 | + get_binary_paths, |
36 | 36 | get_datadir_path, |
37 | 37 | initialize_datadir, |
38 | 38 | p2p_port, |
@@ -60,63 +60,6 @@ def __init__(self, message): |
60 | 60 | self.message = message |
61 | 61 |
|
62 | 62 |
|
63 | | -class Binaries: |
64 | | - """Helper class to provide information about bitcoin binaries |
65 | | -
|
66 | | - Attributes: |
67 | | - paths: Object returned from get_binary_paths() containing information |
68 | | - which binaries and command lines to use from environment variables and |
69 | | - the config file. |
70 | | - bin_dir: An optional string containing a directory path to look for |
71 | | - binaries, which takes precedence over the paths above, if specified. |
72 | | - This is used by tests calling binaries from previous releases. |
73 | | - """ |
74 | | - def __init__(self, paths, bin_dir): |
75 | | - self.paths = paths |
76 | | - self.bin_dir = bin_dir |
77 | | - |
78 | | - def node_argv(self, **kwargs): |
79 | | - "Return argv array that should be used to invoke bitcoind" |
80 | | - return self._argv("node", self.paths.bitcoind, **kwargs) |
81 | | - |
82 | | - def rpc_argv(self): |
83 | | - "Return argv array that should be used to invoke bitcoin-cli" |
84 | | - # Add -nonamed because "bitcoin rpc" enables -named by default, but bitcoin-cli doesn't |
85 | | - return self._argv("rpc", self.paths.bitcoincli) + ["-nonamed"] |
86 | | - |
87 | | - def tx_argv(self): |
88 | | - "Return argv array that should be used to invoke bitcoin-tx" |
89 | | - return self._argv("tx", self.paths.bitcointx) |
90 | | - |
91 | | - def util_argv(self): |
92 | | - "Return argv array that should be used to invoke bitcoin-util" |
93 | | - return self._argv("util", self.paths.bitcoinutil) |
94 | | - |
95 | | - def wallet_argv(self): |
96 | | - "Return argv array that should be used to invoke bitcoin-wallet" |
97 | | - return self._argv("wallet", self.paths.bitcoinwallet) |
98 | | - |
99 | | - def chainstate_argv(self): |
100 | | - "Return argv array that should be used to invoke bitcoin-chainstate" |
101 | | - return self._argv("chainstate", self.paths.bitcoinchainstate) |
102 | | - |
103 | | - def _argv(self, command, bin_path, need_ipc=False): |
104 | | - """Return argv array that should be used to invoke the command. It |
105 | | - either uses the bitcoin wrapper executable (if BITCOIN_CMD is set or |
106 | | - need_ipc is True), or the direct binary path (bitcoind, etc). When |
107 | | - bin_dir is set (by tests calling binaries from previous releases) it |
108 | | - always uses the direct path.""" |
109 | | - if self.bin_dir is not None: |
110 | | - return [os.path.join(self.bin_dir, os.path.basename(bin_path))] |
111 | | - elif self.paths.bitcoin_cmd is not None or need_ipc: |
112 | | - # If the current test needs IPC functionality, use the bitcoin |
113 | | - # wrapper binary and append -m so it calls multiprocess binaries. |
114 | | - bitcoin_cmd = self.paths.bitcoin_cmd or [self.paths.bitcoin_bin] |
115 | | - return bitcoin_cmd + (["-m"] if need_ipc else []) + [command] |
116 | | - else: |
117 | | - return [bin_path] |
118 | | - |
119 | | - |
120 | 63 | class BitcoinTestMetaClass(type): |
121 | 64 | """Metaclass for BitcoinTestFramework. |
122 | 65 |
|
@@ -270,39 +213,12 @@ def parse_args(self, test_file): |
270 | 213 |
|
271 | 214 | self.config = configparser.ConfigParser() |
272 | 215 | self.config.read_file(open(self.options.configfile)) |
273 | | - self.binary_paths = self.get_binary_paths() |
| 216 | + self.binary_paths = get_binary_paths(self.config) |
274 | 217 | if self.options.v1transport: |
275 | 218 | self.options.v2transport=False |
276 | 219 |
|
277 | 220 | PortSeed.n = self.options.port_seed |
278 | 221 |
|
279 | | - def get_binary_paths(self): |
280 | | - """Get paths of all binaries from environment variables or their default values""" |
281 | | - |
282 | | - paths = types.SimpleNamespace() |
283 | | - binaries = { |
284 | | - "bitcoin": "BITCOIN_BIN", |
285 | | - "bitcoind": "BITCOIND", |
286 | | - "bitcoin-cli": "BITCOINCLI", |
287 | | - "bitcoin-util": "BITCOINUTIL", |
288 | | - "bitcoin-tx": "BITCOINTX", |
289 | | - "bitcoin-chainstate": "BITCOINCHAINSTATE", |
290 | | - "bitcoin-wallet": "BITCOINWALLET", |
291 | | - } |
292 | | - # Set paths to bitcoin core binaries allowing overrides with environment |
293 | | - # variables. |
294 | | - for binary, env_variable_name in binaries.items(): |
295 | | - default_filename = os.path.join( |
296 | | - self.config["environment"]["BUILDDIR"], |
297 | | - "bin", |
298 | | - binary + self.config["environment"]["EXEEXT"], |
299 | | - ) |
300 | | - setattr(paths, env_variable_name.lower(), os.getenv(env_variable_name, default=default_filename)) |
301 | | - # BITCOIN_CMD environment variable can be specified to invoke bitcoin |
302 | | - # wrapper binary instead of other executables. |
303 | | - paths.bitcoin_cmd = shlex.split(os.getenv("BITCOIN_CMD", "")) or None |
304 | | - return paths |
305 | | - |
306 | 222 | def get_binaries(self, bin_dir=None): |
307 | 223 | return Binaries(self.binary_paths, bin_dir) |
308 | 224 |
|
|
0 commit comments