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"""Tests for the `TestShell` submodule."""7from contextlib import redirect_stdout8from decimal import Decimal9from io import StringIO10from pathlib import Path12# Note that we need to import from functional test framework modules13# *after* extending the Python path via sys.path.insert(0, ...) below,14# in order to work with the full symlinked (unresolved) path within the15# build directory (usually ./build/test/functional).18# Test matching the minimal example from the documentation. Should be kept19# in sync with the interactive shell instructions ('>>> ') in test-shell.md.20def run_testshell_doc_example(functional_tests_dir):21import sys22sys.path.insert(0, functional_tests_dir)23from test_framework.test_shell import TestShell24from test_framework.util import assert_equal26test = TestShell().setup(num_nodes=2, setup_clean_chain=True)27try:28assert test is not None29stdout_buf = StringIO()30with redirect_stdout(stdout_buf):31test2 = TestShell().setup()32assert test2 is None33assert_equal(stdout_buf.getvalue().rstrip(), "TestShell is already running!")34assert_equal(test.nodes[0].getblockchaininfo()["blocks"], 0)35if test.is_wallet_compiled():36res = test.nodes[0].createwallet('default')37assert_equal(res, {'name': 'default'})38address = test.nodes[0].getnewaddress()39res = test.generatetoaddress(test.nodes[0], 101, address)40assert_equal(len(res), 101)41test.sync_blocks()42assert_equal(test.nodes[1].getblockchaininfo()["blocks"], 101)43assert_equal(test.nodes[0].getbalance(), Decimal('50.0'))44test.nodes[0].log.info("Successfully mined regtest chain!")45finally:46test.shutdown()47test.reset()48assert test.num_nodes is None51if __name__ == "__main__":52run_testshell_doc_example(str(Path(__file__).parent))
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.