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) 2019-present The Bitcoin Core developers3# Distributed under the MIT software license, see the accompanying4# file COPYING or http://www.opensource.org/licenses/mit-license.php.5import pathlib7from test_framework.test_framework import BitcoinTestFramework10class TestShell:11"""Wrapper Class for BitcoinTestFramework.13The TestShell class extends the BitcoinTestFramework14rpc & daemon process management functionality to external15python environments.17It is a singleton class, which ensures that users only18start a single TestShell at a time."""20class __TestShell(BitcoinTestFramework):21def set_test_params(self):22self.uses_wallet = None24def run_test(self):25pass27def setup(self, **kwargs):28if self.running:29print("TestShell is already running!")30return32# Num_nodes parameter must be set33# by BitcoinTestFramework child class.34self.num_nodes = 136# User parameters override default values.37for key, value in kwargs.items():38if hasattr(self, key):39setattr(self, key, value)40elif hasattr(self.options, key):41setattr(self.options, key, value)42else:43raise KeyError(key + " not a valid parameter key!")45super().setup()46self.running = True47return self49def shutdown(self):50if not self.running:51print("TestShell is not running!")52else:53super().shutdown()54self.running = False56def reset(self):57if self.running:58print("Shutdown TestShell before resetting!")59else:60self.num_nodes = None61dummy_testshell_file = pathlib.Path(__file__).absolute().parent.parent / "testshell_dummy.py"62super().__init__(dummy_testshell_file)64instance = None66def __new__(cls):67# This implementation enforces singleton pattern, and will return the68# previously initialized instance if available69if not TestShell.instance:70# BitcoinTestFramework instances are supposed to be constructed with the path71# of the calling test in order to find shared data like configuration and the72# cache. Since TestShell is meant for interactive use, there is no concrete73# test; passing a dummy name is fine though, as only the containing directory74# is relevant for successful initialization.75dummy_testshell_file = pathlib.Path(__file__).absolute().parent.parent / "testshell_dummy.py"76TestShell.instance = TestShell.__TestShell(dummy_testshell_file)77TestShell.instance.running = False78return TestShell.instance80def __getattr__(self, name):81return getattr(self.instance, name)83def __setattr__(self, name, value):84return setattr(self.instance, name, value)
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.