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.
1001"""Attempt to import the capnp package and skip the test if the import fails."""1002try:1003import capnp # type: ignore[import] # noqa: F4011004except ImportError:1005raise SkipTest("capnp module not available.")1007def skip_if_no_python_bcc(self):1008"""Attempt to import the bcc package and skip the tests if the import fails."""1009try:1010import bcc # type: ignore[import] # noqa: F4011011except ImportError:1012raise SkipTest("bcc python module not available")1014def skip_if_no_bitcoind_tracepoints(self):1015"""Skip the running test if bitcoind has not been compiled with USDT tracepoint support."""1016if not self.is_usdt_compiled():1017raise SkipTest("bitcoind has not been built with USDT tracepoints enabled.")1019def skip_if_no_bpf_permissions(self):1020"""Skip the running test if we don't have permissions to do BPF syscalls and load BPF maps."""1021# check for 'root' permissions1022if os.geteuid() != 0:1023raise SkipTest("no permissions to use BPF (please review the tests carefully before running them with higher privileges)")1025def skip_if_platform_not_linux(self):1026"""Skip the running test if we are not on a Linux platform"""1027if platform.system() != "Linux":1028raise SkipTest("not on a Linux system")1030def skip_if_no_lsof_on_nonlinux(self):1031"""Skip the running test if the lsof utility is not available on non-Linux platforms."""1032if sys.platform != "linux" and shutil.which("lsof") is None:1033raise SkipTest("lsof not available")1035def skip_if_platform_not_posix(self):1036"""Skip the running test if we are not on a POSIX platform"""1037if os.name != 'posix':1038raise SkipTest("not on a POSIX system")1040def skip_if_no_bitcoind_zmq(self):1041"""Skip the running test if bitcoind has not been compiled with zmq support."""1042if not self.is_zmq_compiled():1043raise SkipTest("bitcoind has not been built with zmq enabled.")1045def skip_if_no_wallet(self):1046"""Skip the running test if wallet has not been compiled."""1047self.uses_wallet = True1048if not self.is_wallet_compiled():1049raise SkipTest("wallet has not been compiled.")1051def skip_if_no_wallet_tool(self):1052"""Skip the running test if bitcoin-wallet has not been compiled."""1053if not self.is_wallet_tool_compiled():1054raise SkipTest("bitcoin-wallet has not been compiled")1056def skip_if_no_bitcoin_tx(self):1057"""Skip the running test if bitcoin-tx has not been compiled."""1058if not self.is_bitcoin_tx_compiled():1059raise SkipTest("bitcoin-tx has not been compiled")1061def skip_if_no_bitcoin_util(self):1062"""Skip the running test if bitcoin-util has not been compiled."""1063if not self.is_bitcoin_util_compiled():1064raise SkipTest("bitcoin-util has not been compiled")1066def skip_if_no_bitcoin_chainstate(self):1067"""Skip the running test if bitcoin-chainstate has not been compiled."""1068if not self.is_bitcoin_chainstate_compiled():1069raise SkipTest("bitcoin-chainstate has not been compiled")1071def skip_if_no_bitcoin_bench(self):1072"""Skip the running test if bench_bitcoin has not been compiled."""1073if not self.is_bench_compiled():1074raise SkipTest("bench_bitcoin has not been compiled")1076def skip_if_no_cli(self):1077"""Skip the running test if bitcoin-cli has not been compiled."""1078if not self.is_cli_compiled():1079raise SkipTest("bitcoin-cli has not been compiled.")1081def skip_if_no_ipc(self):1082"""Skip the running test if ipc is not compiled."""1083if not self.is_ipc_compiled():1084raise SkipTest("ipc has not been compiled.")1086def skip_if_no_gui(self):1087"""Skip the running test if the GUI has not been compiled."""1088if not self.is_gui_compiled():1089raise SkipTest("GUI has not been compiled.")1091def skip_if_no_previous_releases(self):1092"""Skip the running test if previous releases are not available."""1093if not self.has_previous_releases():1094raise SkipTest("previous releases not available or disabled")1096def has_resource_module(self):1097"""Checks whether the resource module is available."""1098return find_spec('resource') is not None1100@property1101def RLIM_INFINITY(self):1102if not self.has_resource_module():1103return None1104import resource1105return resource.RLIM_INFINITY1107def has_previous_releases(self):1108"""Checks whether previous releases are present and enabled."""1109if not os.path.isdir(self.options.previous_releases_path):1110if self.options.prev_releases:1111raise AssertionError(f"Force test of previous releases but releases missing: {self.options.previous_releases_path}\n"1112"Previous releases binaries can be downloaded via `test/get_previous_releases.py`.")1113return self.options.prev_releases1115def skip_if_no_external_signer(self):1116"""Skip the running test if external signer support has not been compiled."""1117if not self.is_external_signer_compiled():1118raise SkipTest("external signer support has not been compiled.")1120def skip_if_running_under_valgrind(self):1121"""Skip the running test if Valgrind is being used."""1122if self.options.valgrind:1123raise SkipTest("This test is not compatible with Valgrind.")1125def is_bench_compiled(self):1126"""Checks whether bench_bitcoin was compiled."""1127return self.config.getboolean("components", "BUILD_BENCH")1129def is_cli_compiled(self):1130"""Checks whether bitcoin-cli was compiled."""1131return self.config.getboolean("components", "ENABLE_CLI")1133def is_external_signer_compiled(self):1134"""Checks whether external signer support was compiled."""1135return self.config.getboolean("components", "ENABLE_EXTERNAL_SIGNER")1137def is_wallet_compiled(self):1138"""Checks whether the wallet module was compiled."""1139return self.config.getboolean("components", "ENABLE_WALLET")1141def is_wallet_tool_compiled(self):1142"""Checks whether bitcoin-wallet was compiled."""1143return self.config.getboolean("components", "ENABLE_WALLET_TOOL")1145def is_bitcoin_tx_compiled(self):1146"""Checks whether bitcoin-tx was compiled."""1147return self.config.getboolean("components", "BUILD_BITCOIN_TX")1149def is_bitcoin_util_compiled(self):1150"""Checks whether bitcoin-util was compiled."""1151return self.config.getboolean("components", "ENABLE_BITCOIN_UTIL")1153def is_bitcoin_chainstate_compiled(self):1154"""Checks whether bitcoin-chainstate was compiled."""1155return self.config.getboolean("components", "ENABLE_BITCOIN_CHAINSTATE")1157def is_zmq_compiled(self):1158"""Checks whether the zmq module was compiled."""1159return self.config.getboolean("components", "ENABLE_ZMQ")1161def is_embedded_asmap_compiled(self):1162"""Checks whether ASMap data was embedded during compilation."""1163return self.config.getboolean("components", "ENABLE_EMBEDDED_ASMAP")1165def is_usdt_compiled(self):1166"""Checks whether the USDT tracepoints were compiled."""1167return self.config.getboolean("components", "ENABLE_USDT_TRACEPOINTS")1169def is_ipc_compiled(self):1170"""Checks whether ipc was compiled."""1171return self.config.getboolean("components", "ENABLE_IPC")1173def is_gui_compiled(self):1174"""Checks whether the GUI was compiled."""1175return self.config.getboolean("components", "BUILD_GUI")1177def has_blockfile(self, node, filenum: str):1178return (node.blocks_path/ f"blk{filenum}.dat").is_file()1180def inspect_sqlite_db(self, path, fn, *args, **kwargs):1181try:1182import sqlite3 # type: ignore[import]1183conn = sqlite3.connect(path)1184with conn:1185result = fn(conn, *args, **kwargs)1186conn.close()1187return result1188except ImportError:1189self.log.warning("sqlite3 module not available, skipping tests that inspect the database")1191def cleanup_folder(self, _path):1192path = Path(_path)1193if not path.is_relative_to(self.options.tmpdir):1194raise AssertionError(f"Trying to delete #{path} outside of #{self.options.tmpdir}")1195shutil.rmtree(path)
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.