[tests] Demostration/concept: Add a TestNode class to test_Framework.py #10082

pull jnewbery wants to merge 11 commits into bitcoin:master from jnewbery:refactor_utils_py changing 64 files +638 −605
  1. jnewbery commented at 4:53 AM on March 26, 2017: member

    This PR is too large for review and will need continually rebasing. This PR tracks the individual tasks to introduce a TestNode class. The individual commits are in separate PRs

    Tasks:

    • #10171 Add initialize chain / start node / stop node methods to TestFramework. Initially these are wrapper methods which call into the functions in util.py (not disruptive - only touches test_framework files)
    • #10359 Update individual test cases to call TestFramework.start_node() etc (disruptive - touches all test cases, so will require rebases for open PRs)
    • #10556 Change TestFramework start/stop methods to contain the logic and remove the functions from util.py. Also move the stateful port and coverage functions into TestFramework (not disruptive - only touches test_framework files)
    • #10711 Add the TestNode class (not disruptive - only touches test_framework files)
    • #11182 Add p2p connections into the TestNode class (not disruptive - only touches test_framework files)
    • #11182 Update individual test cases to use TestNode class (marginally disruptive - does not need to be done all at once)

    This PR adds a TestNode class to the test_framework.py module. The goals for this are:

    1. Present a clean interface to the test writer

    The test writer should be able to set up a desired network topology and not have to think too hard about how to start bitcoind instances and setup RPC/P2P connections to them.

    To create a node with an RPC and a P2P connection, tests currently look something like this:

            self.nodes = []
            self.nodes.append(start_node(0, self.options.tmpdir))
            node0 = SingleNodeConnCB()
            connections = []
            connections.append(NodeConn('127.0.0.1', p2p_port(0), self.nodes[0], node0))
            node0.add_connection(connections[0])
            NetworkThread().start()  # Start up network handling in another thread
            node0.wait_for_verack()
    

    After this PR, that should be more like this:

            self.num_nodes = 1
            self.start_nodes()
            self.nodes[0].add_p2p_connection()
    

    the tester now has a TestNode instance self.nodes[0] which he/she can use to send RPC commands, send P2P messages and register callbacks for received P2P messages.

    1. Remove global state from utils.py

    There are currently several global state variables in utils.py (COVERAGE_DIR, PortSeed and bitcoind_processes). Having global state variables in the utils module is bad practice and makes importing from utils quite brittle. It also makes it difficult to add functionality to the test framework without inadvertently breaking something.

  2. fanquake added the label Tests on Mar 26, 2017
  3. NicolasDorier commented at 1:41 PM on March 26, 2017: contributor

    Very nice, concept ACK.

  4. move initialize_chain() and initialize_chain_clean() to be methods of BitcoinTestFramework 2012ecc9cf
  5. Add stop_nodes() method to BitcoinTestFramework 490721fcfa
  6. add start_node() and start_nodes() methods to BitcoinTestFramework 52054c4d13
  7. Reorganize BitcoinTestFunction class 74b3e8b19a
  8. Use self.st{art,op}_node{,s}() method in BitcoinTestFramework 2177394abf
  9. Move global state to BitcoinTestFramework
    This commit moves functions st{art,op}_nodes{,s}() functions
    and bitcoind_processes and coverage variables into BitcoinTestFramework
    8abb09a2d3
  10. Add default values to start_node() and start_nodes()
    This commit adds default values to the num_nodes and dirname arguments
    in start_node() and start_nodes(). All calls to these methods used
    self.options.tmpdir and most used self.num_nodes for these values.
    Having those as the defaults simplifies the interface.
    
    This commit also changes sequential start_node() calls to a single
    start_nodes() call where possible. When start_nodes() is updated to
    start nodes in parallel this will make test startup faster.
    acf924c6aa
  11. Add TestNode class
    This commit adds a TestNode class to test_framework.py. This class is
    responsible for all state related to a bitcoind node under test. It
    stores local state, is responsible for tracking the bitcoind process and
    delegates unrecognised messages to the RPC connection.
    b5aa1097c9
  12. jnewbery renamed this:
    [tests] Add a TestNode class to test_Framework.py
    [tests] Demostration/concept: Add a TestNode class to test_Framework.py
    on Mar 30, 2017
  13. Add p2p connection to TestNode 606cc54915
  14. Use TestNode.p2p in assumevalid.py 75e8514922
  15. Use TestNode.p2p in maxuploadtarget.py 328763ab3d
  16. jnewbery force-pushed on Apr 8, 2017
  17. jnewbery cross-referenced this on Apr 8, 2017 from issue [tests] Add node methods to test framework by jnewbery
  18. jnewbery cross-referenced this on Apr 12, 2017 from issue [tests] Functional test warnings by jnewbery
  19. jnewbery cross-referenced this on Apr 12, 2017 from issue [tests] Remove is_network_split from functional test framework by jnewbery
  20. jnewbery cross-referenced this on Apr 12, 2017 from issue [rpc] listsinceblock should include lost transactions when parameter is a reorg'd block by kallewoof
  21. jnewbery cross-referenced this on Apr 17, 2017 from issue Tests: Order Python Tests Differently by jimmysong
  22. jnewbery cross-referenced this on Apr 18, 2017 from issue [test] Add aborttrescan tests by kallewoof
  23. jnewbery cross-referenced this on May 8, 2017 from issue [tests] functional tests should call BitcoinTestFramework start/stop node methods by jnewbery
  24. jnewbery cross-referenced this on May 9, 2017 from issue UNIX sockets support for RPC by laanwj
  25. jnewbery cross-referenced this on Jun 8, 2017 from issue [tests] various improvements to zmq_test.py by jnewbery
  26. jnewbery cross-referenced this on Jun 8, 2017 from issue Move stop/start functions from utils.py into BitcoinTestFramework by jnewbery
  27. jnewbery cross-referenced this on Jun 30, 2017 from issue [tests] Introduce TestNode by jnewbery
  28. MarcoFalke referenced this in commit 85aec87b11 on Aug 15, 2017
  29. jnewbery cross-referenced this on Aug 28, 2017 from issue [tests] Add P2P interface to TestNode by jnewbery
  30. MarcoFalke commented at 9:23 AM on September 2, 2017: member

    @jnewbery Should this be kept open?

  31. jnewbery commented at 3:01 PM on September 4, 2017: member

    Perhaps if/when #11182 is merged we can close this? (or we can close now if you feel strongly)

  32. MarcoFalke commented at 7:28 PM on September 5, 2017: member

    Going to close this. People interested should focus on reviewing the last bit, i.e. #11182.

  33. MarcoFalke closed this on Sep 5, 2017

  34. MarcoFalke referenced this in commit f7388e93d3 on Nov 8, 2017
  35. PastaPastaPasta referenced this in commit 74ab3e9dae on Sep 19, 2019
  36. PastaPastaPasta referenced this in commit ee44950e7d on Sep 23, 2019
  37. PastaPastaPasta referenced this in commit e221b458ca on Sep 24, 2019
  38. codablock referenced this in commit f55da3aa54 on Sep 24, 2019
  39. codablock referenced this in commit 65487ade38 on Sep 30, 2019
  40. codablock referenced this in commit 0f17abaa29 on Sep 30, 2019
  41. codablock referenced this in commit ec1d2b6722 on Oct 2, 2019
  42. codablock referenced this in commit 7b9dd03e27 on Oct 2, 2019
  43. UdjinM6 referenced this in commit c9a8bac497 on Oct 3, 2019
  44. codablock referenced this in commit 7c163b1ffd on Oct 3, 2019
  45. barrystyle referenced this in commit 1195059eac on Jan 22, 2020
  46. barrystyle referenced this in commit fca03b56ee on Jan 22, 2020
  47. bitcoin locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-05-20 06:55 UTC