|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# Copyright (c) The Bitcoin Core developers |
| 3 | +# Distributed under the MIT software license, see the accompanying |
| 4 | +# file COPYING or http://www.opensource.org/licenses/mit-license.php. |
| 5 | +"""Tests for the `TestShell` submodule.""" |
| 6 | + |
| 7 | +from decimal import Decimal |
| 8 | +from pathlib import Path |
| 9 | + |
| 10 | +# Note that we need to import from functional test framework modules |
| 11 | +# *after* extending the Python path via sys.path.insert(0, ...) below, |
| 12 | +# in order to work with the full symlinked (unresolved) path within the |
| 13 | +# build directory (usually ./build/test/functional). |
| 14 | + |
| 15 | + |
| 16 | +# Test matching the minimal example from the documentation. Should be kept |
| 17 | +# in sync with the interactive shell instructions ('>>> ') in test-shell.md. |
| 18 | +def run_testshell_doc_example(functional_tests_dir): |
| 19 | + import sys |
| 20 | + sys.path.insert(0, functional_tests_dir) |
| 21 | + from test_framework.test_shell import TestShell |
| 22 | + from test_framework.util import assert_equal |
| 23 | + |
| 24 | + test = TestShell().setup(num_nodes=2, setup_clean_chain=True) |
| 25 | + assert test is not None |
| 26 | + test2 = TestShell().setup() |
| 27 | + assert test2 is None # TODO: check for "TestShell is already running!" output to stdout |
| 28 | + assert_equal(test.nodes[0].getblockchaininfo()["blocks"], 0) |
| 29 | + if test.is_wallet_compiled(): |
| 30 | + res = test.nodes[0].createwallet('default') |
| 31 | + assert_equal(res, {'name': 'default'}) |
| 32 | + address = test.nodes[0].getnewaddress() |
| 33 | + res = test.generatetoaddress(test.nodes[0], 101, address) |
| 34 | + assert_equal(len(res), 101) |
| 35 | + test.sync_blocks() |
| 36 | + assert_equal(test.nodes[1].getblockchaininfo()["blocks"], 101) |
| 37 | + assert_equal(test.nodes[0].getbalance(), Decimal('50.0')) |
| 38 | + test.nodes[0].log.info("Successfully mined regtest chain!") |
| 39 | + |
| 40 | + test.shutdown() |
| 41 | + |
| 42 | + |
| 43 | +if __name__ == "__main__": |
| 44 | + run_testshell_doc_example(str(Path(__file__).parent)) |
0 commit comments