Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1#!/usr/bin/env python32# Copyright (c) The Bitcoin Core developers3# Distributed under the MIT software license, see the accompanying4# file COPYING or http://www.opensource.org/licenses/mit-license.php.5"""Test the bitcoin wrapper tool."""6from test_framework.test_framework import (7BitcoinTestFramework,8SkipTest,9)10from test_framework.util import (11append_config,12assert_equal,13)15import platform16import re19class ToolBitcoinTest(BitcoinTestFramework):20def set_test_params(self):21self.setup_clean_chain = True22self.num_nodes = 124def skip_test_if_missing_module(self):25# Skip test on windows because currently when `bitcoin node -version` is26# run on windows, python doesn't capture output from the child27# `bitcoind` and `bitcoin-node` process started with _wexecvp, and28# stdout/stderr are always empty. See29# https://github.com/bitcoin/bitcoin/pull/33229#issuecomment-326552490830if platform.system() == "Windows":31raise SkipTest("Test does not currently work on windows")33def setup_network(self):34"""Set up nodes normally, but save a copy of their arguments before starting them."""35self.add_nodes(self.num_nodes, self.extra_args)36node_argv = self.get_binaries().node_argv()37self.node_options = [node.args[len(node_argv):] for node in self.nodes]38for node in self.nodes:39assert_equal(node.args[:len(node_argv)], node_argv)41def set_cmd_args(self, node, args):42"""Set up node so it will be started through bitcoin wrapper command with specified arguments."""43# Manually construct the `bitcoin node` command, similar to Binaries::node_argv()44bitcoin_cmd = node.binaries.valgrind_cmd + [node.binaries.paths.bitcoin_bin]45node.args = bitcoin_cmd + args + ["node"] + self.node_options[node.index]47def test_args(self, cmd_args, node_args, expect_exe=None, expect_error=None):48node = self.nodes[0]49self.set_cmd_args(node, cmd_args)50extra_args = node_args + ["-version"]51if expect_error is not None:52node.assert_start_raises_init_error(expected_msg=expect_error, extra_args=extra_args)53else:54assert expect_exe55node.start(extra_args=extra_args)56ret, out, err = get_node_output(node)57try:58assert_equal(get_exe_name(out), expect_exe.encode())59assert_equal(err, b"")60except Exception as e:61raise RuntimeError(f"Unexpected output from {node.args + extra_args}: {out=!r} {err=!r} {ret=!r}") from e63def run_test(self):64node = self.nodes[0]66self.log.info("Ensure bitcoin node command invokes bitcoind by default")67self.test_args([], [], expect_exe="bitcoind")69self.log.info("Ensure bitcoin -M invokes bitcoind")70self.test_args(["-M"], [], expect_exe="bitcoind")72self.log.info("Ensure bitcoin -M does not accept -ipcbind")73self.test_args(["-M"], ["-ipcbind=unix"], expect_error='Error: Error parsing command line arguments: Invalid parameter -ipcbind=unix')75if self.is_ipc_compiled():76self.log.info("Ensure bitcoin -m invokes bitcoin-node")77self.test_args(["-m"], [], expect_exe="bitcoin-node")79self.log.info("Ensure bitcoin -m does accept -ipcbind")80self.test_args(["-m"], ["-ipcbind=unix"], expect_exe="bitcoin-node")82self.log.info("Ensure bitcoin accepts -ipcbind by default")83self.test_args([], ["-ipcbind=unix"], expect_exe="bitcoin-node")85self.log.info("Ensure bitcoin recognizes -ipcbind in config file")86append_config(node.datadir_path, ["ipcbind=unix"])87self.test_args([], [], expect_exe="bitcoin-node")90def get_node_output(node):91ret = node.process.wait(timeout=60)92node.stdout.seek(0)93node.stderr.seek(0)94out = node.stdout.read()95err = node.stderr.read()96node.stdout.close()97node.stderr.close()99# Clean up TestNode state100node.running = False101node.process = None102node.rpc_connected = False103node.rpc = None105return ret, out, err108def get_exe_name(version_str):109"""Get exe name from last word of first line of version string."""110return re.match(rb".*?(\S+)\s*?(?:\n|$)", version_str.strip()).group(1)113if __name__ == '__main__':114ToolBitcoinTest(__file__).main()
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.