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) 2025 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 IPC with bitcoin-cli"""7from test_framework.test_framework import BitcoinTestFramework8from test_framework.util import (9assert_equal,10rpc_port11)13import subprocess15class TestBitcoinIpcCli(BitcoinTestFramework):16def set_test_params(self):17self.setup_clean_chain = True18self.num_nodes = 120def skip_test_if_missing_module(self):21self.skip_if_no_ipc()23def setup_nodes(self):24self.extra_init = [{"ipcbind": True}]25super().setup_nodes()27def test_cli(self, args, error=None):28# Intentionally set wrong RPC password so only IPC not HTTP connections work29args = [self.binary_paths.bitcoincli, f"-datadir={self.nodes[0].datadir_path}", "-rpcpassword=wrong"] + args + ["echo", "foo"]30result = subprocess.run(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)31if error is None:32assert_equal(result.stdout, '[\n "foo"\n]\n')33else:34assert result.stdout.startswith(error), f"Output didn't start with the expected error {error!r}:\n{result.stdout}"35assert_equal(result.stderr, None)36assert_equal(result.returncode, 0 if error is None else 1)38def run_test(self):39node = self.nodes[0]40if node.ipc_tmp_dir:41self.log.info("Skipping a few checks because temporary directory path is too long")43http_auth_error = "error: Authorization failed: Incorrect rpcuser or rpcpassword were specified."44http_connect_error = f"error: Error while attempting to communicate with server 127.0.0.1:{rpc_port(node.index)} (Could not connect to the server)\n\nMake sure the bitcoind server is running and that you are connecting to the correct RPC port.\nUse \"bitcoin-cli -help\" for more info.\n"45ipc_connect_error = "error: Connection refused\n\nProbably bitcoin-node is not running or not listening on a unix socket. Can be started with:\n\n bitcoin-node -chain=regtest -ipcbind=unix\n"46ipc_http_conflict = "error: -rpcconnect and -ipcconnect options cannot both be enabled\n"48for started in (True, False):49auto_error = None if started else http_connect_error50http_error = http_auth_error if started else http_connect_error51ipc_error = None if started else ipc_connect_error53if not node.ipc_tmp_dir:54self.test_cli([], auto_error)55self.test_cli(["-rpcconnect=127.0.0.1"], http_error)56self.test_cli(["-ipcconnect=auto"], auto_error)57self.test_cli(["-ipcconnect=auto", "-rpcconnect=127.0.0.1"], http_error)58self.test_cli(["-ipcconnect=unix"], ipc_error)60self.test_cli([f"-ipcconnect=unix:{node.ipc_socket_path}"], ipc_error)61self.test_cli(["-noipcconnect"], http_error)62self.test_cli(["-ipcconnect=unix", "-rpcconnect=127.0.0.1"], ipc_http_conflict)64self.stop_node(0)67if __name__ == '__main__':68TestBitcoinIpcCli(__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.