Skip to content

Commit d31a601

Browse files
committed
test: add functional test for TestShell (matching doc example)
1 parent 5ea4bb1 commit d31a601

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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 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 docmentation. 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
28+
assert_equal(test.nodes[0].getblockchaininfo()["blocks"], 0)
29+
res = test.nodes[0].createwallet('default')
30+
assert_equal(res, {'name': 'default'})
31+
address = test.nodes[0].getnewaddress()
32+
res = test.generatetoaddress(test.nodes[0], 101, address)
33+
assert_equal(len(res), 101)
34+
assert_equal(test.nodes[0].getblockchaininfo()["blocks"], 101)
35+
assert_equal(test.nodes[0].getbalance(), Decimal('50.0'))
36+
test.nodes[0].log.info("Successfully mined regtest chain!")
37+
38+
test.shutdown()
39+
40+
41+
if __name__ == "__main__":
42+
run_testshell_doc_example(str(Path(__file__).parent))

test/functional/test_runner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@
360360
'rpc_getdescriptorinfo.py',
361361
'rpc_mempool_info.py',
362362
'rpc_help.py',
363+
'feature_framework_testshell.py',
363364
'tool_rpcauth.py',
364365
'p2p_handshake.py',
365366
'p2p_handshake.py --v2transport',

0 commit comments

Comments
 (0)