dash/test/functional/test_framework
MarcoFalke ba73a3360a
Merge #17288: Added TestShell class for interactive Python environments.
19139ee034d20ebab1b91d3ac13a8eee70b59374 Add documentation for test_shell submodule (JamesC)
f5112369cf91451d2d0bf574a9bfdaea04696939 Add TestShell class (James Chiang)
5155602a636c323424f75272ccec38588b3d71cd Move argparse() to init() (JamesC)
2ab01462f48b2d4e0d03ba842c3af8851c67c6f1 Move assert num_nodes is set into main() (JamesC)
614c645643e86c4255b98c663c10f2c227158d4b Clear TestNode objects after shutdown (JamesC)
6f40820757d25ff1ccfdfcbdf2b45b8b65308010 Add closing and flushing of logging handlers (JamesC)
6b71241291a184c9ee197bf5f0c7e1414417a0a0 Refactor TestFramework main() into setup/shutdown (JamesC)
ede8b7608e115364b5bb12e7f39d662145733de6 Remove network_event_loop instance in close() (JamesC)

Pull request description:

  This PR refactors BitcoinTestFramework to encapsulate setup and shutdown logic into dedicated methods, and adds a  ~~TestWrapper~~ TestShell child class. This wrapper allows the underlying BitcoinTestFramework to run _between user inputs_ in a REPL environment, such as a Jupyter notebook or any interactive Python3 interpreter.

  The ~~TestWrapper~~ TestShell is motivated by the opportunity to expose the test-framework as a prototyping and educational toolkit. Examples of code prototypes enabled by  ~~TestWrapper~~ TestShell can be found in the Optech [Taproot/Schnorr](https://github.com/bitcoinops/taproot-workshop) workshop repository.

  Usage example:
  ```
  >>> import sys
  >>> sys.path.insert(0, "/path/to/bitcoin/test/functional")
  ```
  ```
  >>> from test_framework.test_wrapper import TestShell
  >>> test = TestShell()
  >>> test.setup(num_nodes=2)
  20XX-XX-XXTXX:XX:XX.XXXXXXX TestFramework (INFO): Initializing test directory /path/to/bitcoin_func_test_XXXXXXX
  ```
  ```
  >>> test.nodes[0].generate(101)
  >>> test.nodes[0].getblockchaininfo()["blocks"]
  101
  ```
  ```
  >>> test.shutdown()
  20XX-XX-XXTXX:XX:XX.XXXXXXX TestFramework (INFO): Stopping nodes
  20XX-XX-XXTXX:XX:XX.XXXXXXX TestFramework (INFO): Cleaning up /path/to/bitcoin_func_test_XXXXXXX on exit
  20XX-XX-XXTXX:XX:XX.XXXXXXX TestFramework (INFO): Tests successful
  ```

  **Overview of changes to BitcoinTestFramework:**

  - Code moved to `setup()/shutdown()` methods.
  - Argument parsing logic encapsulated by `parse_args` method.
  - Success state moved to `BitcoinTestFramework.success`.

  _During Shutdown_

  - `BitcoinTestFramework` logging handlers are flushed and removed.
  - `BitcoinTestFrameowork.nodes` list is cleared.
  - `NetworkThread.network_event_loop` is reset. (NetworkThread class).

  **Behavioural changes:**
  - Test parameters can now also be set when overriding BitcoinTestFramework.setup() in addition to overriding `set_test_params` method.
  - Potential exceptions raised in BitcoinTestFramework.setup() will be handled in main().

  **Added files:**
  - ~~test_wrapper.py~~ `test_shell.py`
  - ~~test-wrapper.md~~ `test-shell.md`

ACKs for top commit:
  jamesob:
    ACK 19139ee034
  jonatack:
    ACK 19139ee034d20ebab1b91d3ac13a8eee70b59374
  jnewbery:
    Rather than invalidate the three ACKs for a minor nit, can you force push back to 19139ee034d20ebab1b91d3ac13a8eee70b59374 please? I think this PR was ready to merge before your last force push.
  jachiang:
    > Rather than invalidate the three ACKs for a minor nit, can you force push back to [19139ee](19139ee034) please? I think this PR was ready to merge before your last force push.
  jnewbery:
    ACK 19139ee034d20ebab1b91d3ac13a8eee70b59374

Tree-SHA512: 0c24f405f295a8580a9c8f1b9e0182b5d753eb08cc331424616dd50a062fb773d3719db4d08943365b1f42ccb965cc363b4bcc5beae27ac90b3460b349ed46b2
2022-09-07 21:45:31 +03:00
..
__init__.py
address.py merge bitcoin#16943: Add generatetodescriptor RPC 2022-04-20 00:25:14 +05:30
authproxy.py Merge #18596: test: Try once more when RPC connection fails on Windows 2021-09-28 14:46:44 -04:00
blocktools.py Merge #13928: qa: blocktools enforce named args for amount 2022-04-26 13:39:19 -04:00
coverage.py
descriptors.py merge bitcoin#15368: Descriptor checksums 2021-10-28 14:01:02 +05:30
key.py merge bitcoin#19105: Add Muhash3072 implementation in Python 2022-04-27 20:05:13 +05:30
messages.py dashification: Introduce ADDRV2_PROTO_VERSION and bump PROTOCOL_VERSION to avoid conflicts with previous v18.x rcs 2022-06-08 02:53:55 +03:00
mininode.py Merge #17288: Added TestShell class for interactive Python environments. 2022-09-07 21:45:31 +03:00
muhash.py partial bitcoin#19055: Add MuHash3072 implementation 2022-04-27 20:05:13 +05:30
netutil.py Merge bitcoin/bitcoin#24342: test: remove import socket in test_ipv6_local 2022-04-11 09:46:40 -07:00
ripemd160.py docs/build: Kubuntu 22.04 build fix (#4843) 2022-05-28 23:27:04 -05:00
script_util.py Merge #17108: test: fix "tx-size-small" errors after default address change 2022-05-17 01:20:21 -04:00
script.py docs/build: Kubuntu 22.04 build fix (#4843) 2022-05-28 23:27:04 -05:00
siphash.py
socks5.py merge #14954: Require python 3.5 2021-08-31 11:16:12 +05:30
test_framework.py Merge #17288: Added TestShell class for interactive Python environments. 2022-09-07 21:45:31 +03:00
test_node.py Merge #16042: test: Bump MAX_NODES to 12 2022-09-07 20:15:52 +03:00
test_shell.py Merge #17288: Added TestShell class for interactive Python environments. 2022-09-07 21:45:31 +03:00
util.py Merge #17705: test: re-enable CLI test support by using EncodeDecimal in json.dumps() 2022-06-08 12:35:12 +07:00
wallet_util.py Merge #15108: [tests] tidy up wallet_importmulti.py 2022-03-08 22:53:13 -05:00