TestNode tidyups #11121

pull jnewbery wants to merge 5 commits into bitcoin:master from jnewbery:test_node_tidyups changing 83 files +380 −528
  1. jnewbery commented at 8:53 PM on August 23, 2017: member

    Some additional tidyups after the introduction of TestNode:

    • commit 1 makes TestNode use the correct rpc timeout. This should have been included in #11077
    • commit 2 separates add_node() from start_node() as originally discussed here: #10556 (review) with @kallewoof . The test writer no longer needs to assign to self.nodes when starting/stopping nodes.
    • commit 3 adds a set_test_params() method, so individual tests don't need to override __init__() and call super().__init__()
  2. jnewbery force-pushed on Aug 23, 2017
  3. fanquake added the label Tests on Aug 23, 2017
  4. in test/functional/txn_clone.py:15 in 06bde74f5e outdated
       7 | @@ -8,12 +8,6 @@
       8 |  from test_framework.util import *
       9 |  
      10 |  class TxnMallTest(BitcoinTestFramework):
      11 | -
      12 | -    def __init__(self):
      13 | -        super().__init__()
      14 | -        self.num_nodes = 4
      15 | -        self.setup_clean_chain = False
    


    MarcoFalke commented at 9:24 PM on August 23, 2017:

    I prefer to explicitly set the network topology and initial state of the chain.


    kallewoof commented at 7:55 AM on August 24, 2017:

    Faint agreement. It's easy to forget and start up 4 nodes when you only really need 2, for example. Not seeing the number of nodes makes that even harder to remember.


    jnewbery commented at 4:32 PM on August 24, 2017:

    Sounds good. I've added a new commit that makes setting self.num_nodes mandatory. I haven't done the same for self.setup_clean_chain, since I think it makes more sense for that to have a default. If people feel strongly, it can be added in a future commit.

  5. in test/functional/test_framework/test_framework.py:181 in 06bde74f5e outdated
     174 | @@ -202,51 +175,91 @@ def main(self):
     175 |              logging.shutdown()
     176 |              sys.exit(TEST_EXIT_FAILED)
     177 |  
     178 | -    # Public helper methods. These can be accessed by the subclass test scripts.
     179 | +    # Methods to override in subclass test scripts.
     180 | +    def set_test_params(self):
     181 | +        """Override this method to change default values for number of nodes, topology, etc"""
     182 | +        pass
    


    MarcoFalke commented at 9:26 PM on August 23, 2017:

    should raise RuntimeError('Not implemented') to enforce the docstring.


    jnewbery commented at 4:32 PM on August 24, 2017:

    Yes - done

  6. MarcoFalke commented at 9:27 PM on August 23, 2017: member

    Concept ACK after quick glance

  7. in test/functional/test_framework/test_framework.py:220 in 06bde74f5e outdated
     230 |  
     231 | -    def start_nodes(self, num_nodes, dirname, extra_args=None, rpchost=None, timewait=None, binary=None):
     232 | -        """Start multiple bitcoinds, return RPC connections to them"""
     233 | +    # Public helper methods. These can be accessed by the subclass test scripts.
     234 | +
     235 | +    def add_nodes(self, num_nodes, dirname, extra_args=None, rpchost=None, timewait=None, binary=None):
    


    kallewoof commented at 7:53 AM on August 24, 2017:

    Since self knows about self.options.tmpdir, and all calls to self.add_nodes passes self.options.tmpdir as dirname argument, it seems clean to just give it a default None and to set to self.options.tmpdir if None in add_nodes. Or perhaps remove it entirely and always use self.options.tmpdir. Will it ever be anything else?


    jnewbery commented at 4:32 PM on August 24, 2017:

    Good point. Thanks! Added this in a new commit.

  8. in test/functional/test_framework/test_node.py:64 in 06bde74f5e outdated
      60 | @@ -61,9 +61,13 @@ def __getattr__(self, *args, **kwargs):
      61 |          assert self.rpc_connected and self.rpc is not None, "Error: no RPC connection"
      62 |          return self.rpc.__getattr__(*args, **kwargs)
      63 |  
      64 | -    def start(self):
      65 | +    def start(self, extra_args, stderr=None):
    


    kallewoof commented at 7:53 AM on August 24, 2017:

    extra_args=None, stderr=None maybe?


    jnewbery commented at 4:33 PM on August 24, 2017:

    TestNode.start is only ever called by TestFramework.start_node, which has its own default for extra_args, so not strictly necessary, but I agree having a default here makes it clearer. Added.

  9. in test/functional/wallet.py:15 in 06bde74f5e outdated
      21 | -        self.num_nodes = 4
      22 |          self.extra_args = [['-usehd={:d}'.format(i%2==0)] for i in range(4)]
      23 |  
      24 |      def setup_network(self):
      25 | -        self.nodes = self.start_nodes(3, self.options.tmpdir, self.extra_args[:3])
      26 | +        self.add_nodes(4, self.options.tmpdir, self.extra_args)
    


    kallewoof commented at 8:00 AM on August 24, 2017:

    Why does it not just add_nodes(3, ..) here and then add/start/connect the fourth node below? That would remove a lot of necessary [self.nodes[0:3]] stuff.


    jnewbery commented at 4:35 PM on August 24, 2017:

    Because there's not currently a method to add a single node. The model after this PR is to add all nodes at the top of the test and then start/stop them as required during the test.

    We could potentially add an add_node() method to be called during the test, but lets leave that for a future PR.

  10. kallewoof commented at 8:03 AM on August 24, 2017: member

    utACK 06bde74f5ec8660975275f8594aee3a99064e327

  11. jnewbery force-pushed on Aug 24, 2017
  12. jnewbery commented at 4:36 PM on August 24, 2017: member

    @MarcoFalke @kallewoof - thanks for the review. I think I've responded to all your comments.

    New commits pushed, and rebased on master.

  13. jnewbery force-pushed on Aug 24, 2017
  14. kallewoof commented at 1:04 AM on August 25, 2017: member

    utACK df824a9

  15. in test/functional/assumevalid.py:58 in df824a9212 outdated
      53 | @@ -54,16 +54,16 @@ def send_header_for_blocks(self, new_blocks):
      54 |          self.send_message(headers_message)
      55 |  
      56 |  class AssumeValidTest(BitcoinTestFramework):
      57 | -    def __init__(self):
      58 | -        super().__init__()
      59 | +    def set_test_params(self):
      60 |          self.setup_clean_chain = True
    


    promag commented at 2:05 PM on August 25, 2017:

    It seems there are more setup_clean_chain = True so why not make it the default?


    jnewbery commented at 3:23 PM on August 25, 2017:

    I haven't made any changes to setup_clean_chain. See earlier comment:

    I haven't done the same for self.setup_clean_chain, since I think it makes more sense for that to have a default. If people feel strongly, it can be added in a future commit.

    Feel free to open a PR to change/remove the default if you think that's necessary. I don't think it's required for this PR.

  16. promag commented at 2:11 PM on August 25, 2017: member

    Have you thought of not having any node started automatically? There are some tests that start with stop_node(0)..

    So eachrun_test(self) the nodes are explicitly started, num_nodes can go away, even setup_clean_chain would be a start_node argument.

  17. jnewbery commented at 3:23 PM on August 25, 2017: member

    Thanks for the reivew @promag

    Have you thought of not having any node started automatically? There are some tests that start with stop_node(0)

    Tests that don't need their nodes to start should override the setup_network() or setup_nodes() methods. The vast majority of tests require nodes to be started at the top of the test, so that's the default.

    setup_clean_chain would be a start_node argument.

    setup_clean_chain is a property of the pre-mined chain. I don't think we should change it to be a property of the individual node (if you disagree please open a separate PR to demonstrate the change).

  18. in test/functional/bumpfee.py:45 in 1a0801dc74 outdated
      47 |          self.nodes[1].node_encrypt_wallet(WALLET_PASSPHRASE)
      48 | -        self.nodes[1] = self.start_node(1, self.options.tmpdir, extra_args[1])
      49 | +        self.start_node(1)
      50 |          self.nodes[1].walletpassphrase(WALLET_PASSPHRASE, WALLET_PASSPHRASE_TIMEOUT)
      51 |  
      52 |          connect_nodes_bi(self.nodes, 0, 1)
    


    MarcoFalke commented at 10:40 AM on August 30, 2017:

    This is already done by setup_network.

    Same for the line below.


    jnewbery commented at 2:11 PM on August 30, 2017:

    L41 stops node 1 (the encryptwallet RPC shuts down the node), so I believe all the p2p connections are lost and we need to reconnect the nodes after restarting node 1.

    I've tested removing these two lines and the test fails (the next call to sync_all() fails)


    MarcoFalke commented at 2:13 PM on August 30, 2017:

    Sorry, missed that the node shuts down.

  19. in test/functional/pruning.py:314 in 1a0801dc74 outdated
     312 | @@ -307,15 +313,15 @@ def has_block(index):
     313 |  
     314 |          # stop node, start back up with auto-prune at 550MB, make sure still runs
     315 |          self.stop_node(node_number)
     316 | -        self.nodes[node_number] = self.start_node(node_number, self.options.tmpdir, ["-prune=550"], timewait=900)
     317 | +        self.start_node(node_number, extra_args=["-prune=550"])
    


    MarcoFalke commented at 3:23 PM on September 1, 2017:

    You are removing timewait=900 from all calls but the first. I assume this does not cause issues?


    jnewbery commented at 4:19 PM on September 1, 2017:

    rpc_timeout is a property of TestNode set when instantiating the python object, not when starting up the bitcoind node.

  20. in test/functional/wallet.py:214 in 1a0801dc74 outdated
     210 | @@ -208,8 +211,10 @@ def run_test(self):
     211 |          zeroValueTxid= decRawTx['txid']
     212 |          sendResp = self.nodes[1].sendrawtransaction(signedRawTx['hex'])
     213 |  
     214 | +        # self.sync_all([self.nodes[0:3]])
    


    MarcoFalke commented at 3:40 PM on September 1, 2017:

    debug statement?


    jnewbery commented at 4:21 PM on September 1, 2017:

    derp. Fixed

  21. in test/functional/wallet.py:217 in 1a0801dc74 outdated
     210 | @@ -208,8 +211,10 @@ def run_test(self):
     211 |          zeroValueTxid= decRawTx['txid']
     212 |          sendResp = self.nodes[1].sendrawtransaction(signedRawTx['hex'])
     213 |  
     214 | +        # self.sync_all([self.nodes[0:3]])
     215 |          self.sync_all()
     216 |          self.nodes[1].generate(1) #mine a block
     217 | +        # self.sync_all([self.nodes[0:3]])
    


    MarcoFalke commented at 3:40 PM on September 1, 2017:

    debug statement?


    jnewbery commented at 4:21 PM on September 1, 2017:

    yep

  22. in test/functional/wallet.py:263 in 1a0801dc74 outdated
     260 | +        self.start_node(2)
     261 |          connect_nodes_bi(self.nodes,0,1)
     262 |          connect_nodes_bi(self.nodes,1,2)
     263 |          connect_nodes_bi(self.nodes,0,2)
     264 | -        sync_blocks(self.nodes)
     265 | +        sync_blocks(self.nodes[0:2])
    


    MarcoFalke commented at 3:42 PM on September 1, 2017:

    why not self.nodes[:3]?


    jnewbery commented at 4:32 PM on September 1, 2017:

    fixed

  23. in test/functional/wallet.py:266 in 1a0801dc74 outdated
     264 | -        sync_blocks(self.nodes)
     265 | +        sync_blocks(self.nodes[0:2])
     266 |  
     267 |          self.nodes[0].generate(1)
     268 | -        sync_blocks(self.nodes)
     269 | +        sync_blocks(self.nodes[0:2])
    


    MarcoFalke commented at 3:42 PM on September 1, 2017:

    why not self.nodes[:3]?


    jnewbery commented at 4:32 PM on September 1, 2017:

    fixed

  24. in test/functional/zapwallettxes.py:25 in 55073870db outdated
      24 | -    def __init__(self):
      25 | -        super().__init__()
      26 | +    def set_test_params(self):
      27 |          self.setup_clean_chain = True
      28 | -        self.num_nodes = 2
      29 | +        self.num_nodes = 3
    


    MarcoFalke commented at 3:56 PM on September 1, 2017:

    why is this changed in a refactoring commit?


    jnewbery commented at 4:32 PM on September 1, 2017:

    fixed

  25. MarcoFalke commented at 4:00 PM on September 1, 2017: member

    utACK df824a92121eb68849e474e87098a441d4e52926

  26. [tests] fix - use rpc_timeout as rpc timeout be2a2ab6a6
  27. [tests] TestNode: separate add_node from start_node
    Separates the act of creating a TestNode object from starting the node.
    The test_framework now keeps track of its list of TestNodes, and test
    writers can call start_node() and stop_node() without having to update
    the self.nodes list.
    36b6268670
  28. [tests] Avoid passing around member variables in test_framework 6cf094a022
  29. [tests] don't override __init__() in individual tests
    Almost all test scripts currently need to override the __init__()
    method. When they do that they need to call into super().__init__() as
    the base class does some generic initialization.
    
    This commit makes the base class __init__() call into set_test_params()
    method. Individual test cases can override set_test_params() to setup
    their test parameters.
    5448a1471d
  30. [tests] Functional tests must explicitly set num_nodes 7148b74dc3
  31. jnewbery force-pushed on Sep 1, 2017
  32. jnewbery commented at 4:32 PM on September 1, 2017: member

    Thanks @MarcoFalke . Review comments addressed.

  33. MarcoFalke commented at 4:44 PM on September 1, 2017: member

    re-utACK 7148b74dc39110f53c665b94fa9d994c6ad6dc1c

  34. MarcoFalke merged this on Sep 1, 2017
  35. MarcoFalke closed this on Sep 1, 2017

  36. MarcoFalke referenced this in commit 28f788e47e on Sep 1, 2017
  37. sipa referenced this in commit ec20f01ba0 on Sep 1, 2017
  38. MarcoFalke referenced this in commit b37cab65c6 on Sep 12, 2017
  39. MarcoFalke referenced this in commit ff4cd6075b on Sep 29, 2017
  40. MarcoFalke referenced this in commit 11a5992c90 on Oct 3, 2017
  41. MarcoFalke referenced this in commit 4d3ba18386 on Oct 3, 2017
  42. MarcoFalke referenced this in commit bb5e7cb308 on Oct 3, 2017
  43. MarcoFalke referenced this in commit 801d2ae924 on Oct 3, 2017
  44. MarcoFalke referenced this in commit 82bf6fc6d4 on Oct 3, 2017
  45. PastaPastaPasta referenced this in commit deb441726f on Sep 19, 2019
  46. PastaPastaPasta referenced this in commit 1cf5e99f0c on Sep 23, 2019
  47. PastaPastaPasta referenced this in commit 5257e28d02 on Sep 24, 2019
  48. codablock referenced this in commit 17bb230d74 on Sep 24, 2019
  49. codablock referenced this in commit b9ce8480df on Sep 24, 2019
  50. codablock referenced this in commit 797b474608 on Sep 24, 2019
  51. barrystyle referenced this in commit 4809d1d470 on Jan 22, 2020
  52. barrystyle referenced this in commit 8fc47cd5c2 on Jan 22, 2020
  53. barrystyle referenced this in commit 58b41761c4 on Jan 22, 2020
  54. MarcoFalke 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-04-13 15:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me