[tests] Change feature_block.py to use BitcoinTestFramework #11773

pull jnewbery wants to merge 5 commits into bitcoin:master from jnewbery:refactor_p2pfullblocktest changing 2 files +677 −644
  1. jnewbery commented at 4:40 pm on November 27, 2017: member

    Next step in #10603.

    • first three commits tidy up feature_block.py
    • fourth commit removes usage of ComparisonTestFramework

    Longer term, it would be better to separate net_processing testing from validation testing, but I think this is still a useful PR, since it moves us away from the comparison test framework.

  2. fanquake added the label Tests on Nov 27, 2017
  3. MarcoFalke assigned MarcoFalke on Nov 28, 2017
  4. in test/functional/invalidblockrequest.py:32 in 36cfdb9dbb outdated
    52-        '''
    53+        # Add p2p connection to node0
    54+        node = self.nodes[0]  # convenience reference to the node
    55+        node.add_p2p_connection(P2PStub())
    56+
    57+        NetworkThread().start()  # Start up network handling in another thread
    


    JohnVonNeumann commented at 6:04 am on November 29, 2017:
    Unsure if you guys adhere directly to PEP8 but this comment looks like it could be removed, seems redundant.
  5. in test/functional/invalidblockrequest.py:51 in 36cfdb9dbb outdated
    68-        block = create_block(self.tip, create_coinbase(height), self.block_time)
    69-        self.block_time += 1
    70+        block = create_block(tip, create_coinbase(height), block_time)
    71+        block_time += 1
    72         block.solve()
    73         # Save the coinbase for later
    


    JohnVonNeumann commented at 6:07 am on November 29, 2017:
    Would imagine this would be best moved inline as opposed to on it’s own line to keep convention with inline comments like on line 32 and 29.
  6. in test/functional/invalidblockrequest.py:60 in 36cfdb9dbb outdated
    108+        best_block = node.getblock(node.getbestblockhash())
    109+        tip = int("0x" + node.getbestblockhash(), 0)
    110+        height = best_block["height"] + 1
    111+        block_time = best_block["time"] + 1
    112+
    113+        # Use merkle-root malleability to generate an invalid block with
    


    JohnVonNeumann commented at 6:17 am on November 29, 2017:
    Would assume this block comment should be moved into a docstring block like in test/functional/test_framework/mininode.py P2PStub class. Seems like the standard are great in there, I’m assuming that’s down to this section being a refactor.
  7. in test/functional/invalidtxrequest.py:27 in 36cfdb9dbb outdated
    39-        test.run()
    40+        # Add p2p connection to node0
    41+        node = self.nodes[0]  # convenience reference to the node
    42+        node.add_p2p_connection(P2PStub())
    43+
    44+        NetworkThread().start()  # Start up network handling in another thread
    


    JohnVonNeumann commented at 6:18 am on November 29, 2017:
    Newly added whitespace can be removed.
  8. JohnVonNeumann commented at 6:22 am on November 29, 2017: none
    Just some basic review of code standards/conventions. Mostly applies to the refactored code, new code looks to have done the job from the get go.
  9. jnewbery commented at 1:25 pm on November 29, 2017: member

    Thanks for your input @JohnVonNeumann. Three of your nits are on comments that are already in the code, and the last is to revert a pep8 fix (pep8 states that ‘inline comments should be separated by at least two spaces from the statement. They should start with a # and a single space.’)

    the invalidtxrequest and invalidblockrequest refactors are covered by #11771 and #11772. If you have functional review of those tests, can you leave comments in those PRs?

  10. JohnVonNeumann commented at 6:48 pm on November 29, 2017: none

    Is it typically best off to leave preexisting nits for other PRs? Is that something I could fix myself and submit as a PR? Would that be the typical way to address it? I assume you look to keep the PRs clean otherwise people would just keep bringing up little things and it would be difficult to tell what was actually being added in the PR itself?

    Apologies on the last PEP8 spacing comment too! I missed that part when reading the docs!

    Will have a look at the other PRs and comment in those. Thanks for the feedback as well.

    EDIT: Also sorry for not seeing that you had asked for #11771 and #11772 to be reviewed first, I didn’t read the PR notes thoroughly, will keep an eye on them better from now on.

  11. jnewbery commented at 6:52 pm on November 29, 2017: member

    Is it typically best off to leave preexisting nits for other PRs? Is that something I could fix myself and submit as a PR? Would that be the typical way to address it? I assume you look to keep the PRs clean otherwise people would just keep bringing up little things and it would be difficult to tell what was actually being added in the PR itself?

    I usually clean up style nits as I go, and precede functional-change commits with tidy-up commits as I have in this PR.

    The nits you’ve raised are more your personal preference than following any particular style convention, so I don’t think there’s any benefit for you to open a PR for them.

  12. JohnVonNeumann commented at 6:58 pm on November 29, 2017: none

    Ok this makes sense, although I disagree that all my comments were related directly to my personal preference, for me it was just about keeping the standards throughout the code, for example with the redundant inline comment, I don’t see any of them throughout the newly written code, so it would make sense to not have them in the old code. However, you are probably right, and I’ll happily defer to your experience.

    I’ll try and make my reviews more valuable.

    Cheers

  13. jnewbery force-pushed on Nov 30, 2017
  14. jnewbery commented at 4:24 pm on December 2, 2017: member
    This requires rebase, but I’ll leave it as it is until #11771 is reviewed/merged.
  15. jnewbery force-pushed on Dec 13, 2017
  16. jnewbery force-pushed on Dec 14, 2017
  17. in test/functional/p2p-fullblocktest.py:99 in a9554710e6 outdated
     95@@ -94,228 +96,123 @@ def set_test_params(self):
     96         self.tip = None
     97         self.blocks = {}
     98 
     99-    def add_options(self, parser):
    100-        super().add_options(parser)
    101-        parser.add_option("--runbarelyexpensive", dest="runbarelyexpensive", default=True)
    


    ryanofsky commented at 8:32 pm on December 20, 2017:

    In commit “Tidy up p2pfullblocktest”

    Can you note that this option was removed in the commit message (and maybe say why it wasn’t useful?)


    jnewbery commented at 3:23 am on February 14, 2018:
    Yep. Added to commit message.
  18. ryanofsky commented at 8:44 pm on December 20, 2017: member

    Skipped first two commits which are from #11771 and not up to date. Reviewed remaining individual commits:

    • utACK 13ed1ebe08d100500a8f5311c0f91fe4d8f680db [tests] Improve assert message when wait_until() fails
    • utACK 1e5da2e20d655d602e62ed87a80df0f23bbe7a34 [tests] Change p2p-fullblocktest to use BitcoinTestFramework
    • utACK 63782cd7c7e864f73b2fb715e24513d3d3117214 [tests] Add logging to p2p-fullblocktest.py
    • utACK a9554710e65484d7973b706829be67faff53c357 [tests] Tidy up p2pfullblocktest
    • utACK 40f7f6b99698552e71537c97e76c2011ebaa5626 [tests] Fix flake8 warnings in p2p-fullblocktest
  19. jnewbery force-pushed on Feb 14, 2018
  20. jnewbery commented at 3:23 am on February 14, 2018: member
    Rebased now that #11771 has been merged.
  21. jnewbery force-pushed on Feb 14, 2018
  22. jnewbery force-pushed on Feb 14, 2018
  23. jnewbery renamed this:
    [tests] Change p2p-fullblocktest to use BitcoinTestFramework
    [tests] Change feature_blocks.py to use BitcoinTestFramework
    on Feb 14, 2018
  24. jnewbery renamed this:
    [tests] Change feature_blocks.py to use BitcoinTestFramework
    [tests] Change feature_block.py to use BitcoinTestFramework
    on Feb 14, 2018
  25. conscott commented at 6:47 pm on February 15, 2018: contributor
    ACK
  26. practicalswift commented at 6:49 pm on February 15, 2018: contributor

    utACK 061f4d8cfba58d299dd913bd96f88bddebae8276

    Thanks for a very nice cleanup! Looking forward to seeing this merged!

  27. jnewbery commented at 6:55 pm on February 15, 2018: member

    I saw Travis fail on this, but the trace wasn’t printed because of #12438.

    I reran the job and it passed. It seems that there may be an intermittent failure in the test. I’ll rebase on master to get #12438 and try kicking Travis a few times.

  28. jnewbery force-pushed on Feb 15, 2018
  29. [tests] Fix flake8 warnings in feature_block.py 5cd01d235a
  30. [tests] Tidy up feature_block.py
    - move all helper methods to the end
    - remove block, create_tx and create_and_sign_tx shortcuts
    - remove --runbarelyexpensive option, since it defaults to True and it's
    unlikely that anyone ever runs the test with this option set to false.
    3898c4f3d7
  31. [tests] Add logging to feature_block.py fc02c12ae9
  32. jnewbery force-pushed on Mar 19, 2018
  33. jnewbery commented at 1:33 pm on March 19, 2018: member
    Rebased
  34. in test/functional/feature_block.py:86 in 06d512f119 outdated
    86+        self.extra_args = [[]]
    87+
    88+    def run_test(self):
    89+        node = self.nodes[0]  # convenience reference to the node
    90+
    91+        network_thread_start()
    


    MarcoFalke commented at 5:01 pm on March 19, 2018:

    nit: Could mention in a comment that this is only needed because connect_p2p assumes the thread is already running.

    nit: Could rename connect_p2p to reconnect_p2p, since it only works when the thread is already running?


    jnewbery commented at 6:15 pm on March 19, 2018:
    Sounds good. Done both.
  35. in test/functional/feature_block.py:161 in 06d512f119 outdated
    164+        self.sync_blocks([b6], True)
    165 
    166         # Try to create a fork that double-spends
    167         #     genesis -> b1 (0) -> b2 (1) -> b5 (2) -> b6 (3)
    168-        #                                          \-> b7 (2) -> b8 (4)
    169+        #                                          \-> b7 (3) -> b8 (4)
    


    MarcoFalke commented at 5:33 pm on March 19, 2018:

    Why are you changing this comment?

    Block 7 spends the output 2 (c.f. line 165)


    jnewbery commented at 6:18 pm on March 19, 2018:
    Yes - you’re right. Fixed
  36. in test/functional/feature_block.py:204 in 06d512f119 outdated
    207-        # b14 is invalid, but the node won't know that until it tries to connect
    208-        # Tip still can't advance because b12 is missing
    209-        self.next_block(14, spend=out[5], additional_coinbase_value=1)
    210-        yield self.rejected()
    211+        b14 = self.next_block(14, spend=out[5], additional_coinbase_value=1)
    212+        self.sync_blocks([b12, b13, b14], False, 16, b'bad-cb-amount', reconnect=True)
    


    MarcoFalke commented at 5:42 pm on March 19, 2018:
    The comment above (b12 added last) is no longer true with this change.

    jnewbery commented at 6:20 pm on March 19, 2018:
    yes - removed
  37. in test/functional/feature_block.py:1199 in 06d512f119 outdated
    1201-        for i in range(89, LARGE_REORG_SIZE + 89):
    1202-            self.next_block("alt" + str(i))
    1203-            test2.blocks_and_transactions.append([self.tip, False])
    1204-        yield test2
    1205+        blocks2 = []
    1206+        for i in range(1, LARGE_REORG_SIZE + 1):
    


    MarcoFalke commented at 6:00 pm on March 19, 2018:
    Why are you changing this to 1? We are building blocks on top of block with id 88, so naming them "alt89" … seems appropriate.
  38. MarcoFalke approved
  39. MarcoFalke commented at 6:04 pm on March 19, 2018: member
    Code looks good. Just some comments need update in commit 06d512f11998d9b935edf8b032eb76e491cfb7cc it seems
  40. in test/functional/feature_block.py:580 in 06d512f119 outdated
    576@@ -598,77 +577,78 @@ def get_tests(self):
    577         self.tip = b46
    578         assert 46 not in self.blocks
    579         self.blocks[46] = b46
    580-        yield self.rejected(RejectResult(16, b'bad-blk-length'))
    581+        # s = ser_uint256(b46.hashMerkleRoot)
    


    MarcoFalke commented at 6:06 pm on March 19, 2018:

    In commit 06d512f11998d9b935edf8b032eb76e491cfb7cc:

    Why are you adding this comment? The ser_uint256 symbol is not imported and it will unsurprisingly be all zeros, since it was set to 0.


    jnewbery commented at 6:22 pm on March 19, 2018:
    removed
  41. MarcoFalke commented at 6:09 pm on March 19, 2018: member

    utACK 1f7a8662cdf2c7775942e3abc90c3745c2adaecc

    GitHub hiding my review is probably a bug on their end.

  42. [tests] Change feature_block.py to use BitcoinTestFramework ebf053ac61
  43. [tests] Improve assert message when wait_until() fails 265d7c44b1
  44. in test/functional/test_framework/util.py:222 in 1f7a8662cd outdated
    218@@ -218,8 +219,12 @@ def wait_until(predicate, *, attempts=float('inf'), timeout=float('inf'), lock=N
    219         time.sleep(0.05)
    220 
    221     # Print the cause of the timeout
    222-    assert_greater_than(attempts, attempt)
    223-    assert_greater_than(timeout, time.time())
    224+    predicate_source = inspect.getsourcelines(predicate)
    


    MarcoFalke commented at 6:15 pm on March 19, 2018:

    In the last commit:

    I think you meant inspect.getsource, since the line itself won’t help when the file name is unknown. And the Traceback already shows the line number and file name (as well as the predicate, in case it fits into a single line).


    MarcoFalke commented at 6:16 pm on March 19, 2018:
    Imo we could do without inspect, since it doesn’t seem to add information unless I am missing something.

    jnewbery commented at 6:31 pm on March 19, 2018:

    I think this provides useful information when the wait_until() fails.

    Without this change:

     02018-03-19T18:29:56.324000Z TestFramework (ERROR): Assertion failed
     1Traceback (most recent call last):
     2  File "/home/ubuntu/bitcoin/test/functional/test_framework/test_framework.py", line 126, in main
     3    self.run_test()
     4  File "./feature_block.py", line 502, in run_test
     5    self.sync_blocks([b40], False, 16, b'bad-blk-sigops', reconnect=True)
     6  File "./feature_block.py", line 1315, in sync_blocks
     7    self.nodes[0].p2p.send_blocks_and_test(blocks, self.nodes[0], success=success, reject_code=reject_code, reject_reason=reject_reason, request_block=request_block, timeout=timeout)
     8  File "/home/ubuntu/bitcoin/test/functional/test_framework/mininode.py", line 553, in send_blocks_and_test
     9    wait_until(lambda: self.reject_code_received == reject_code, lock=mininode_lock, timeout=1)
    10  File "/home/ubuntu/bitcoin/test/functional/test_framework/util.py", line 222, in wait_until
    11    assert_greater_than(timeout, time.time())
    12  File "/home/ubuntu/bitcoin/test/functional/test_framework/util.py", line 42, in assert_greater_than
    13    raise AssertionError("%s <= %s" % (str(thing1), str(thing2)))
    14AssertionError: 1521484196.279766 <= 1521484196.3246927
    

    With this change:

     02018-03-19T18:27:45.353000Z TestFramework (INFO): Reject a block with too many P2SH sigops
     12018-03-19T18:27:48.557000Z TestFramework.utils (ERROR): wait_until() failed. Predicate: (['            wait_until(lambda: self.reject_code_received == reject_code, lock=mininode_lock, timeout=1)\n'], 553)
     22018-03-19T18:27:48.557000Z TestFramework (ERROR): Assertion failed
     3Traceback (most recent call last):
     4  File "/home/ubuntu/bitcoin/test/functional/test_framework/test_framework.py", line 126, in main
     5    self.run_test()
     6  File "./feature_block.py", line 502, in run_test
     7    self.sync_blocks([b40], False, 16, b'bad-blk-sigops', reconnect=True)
     8  File "./feature_block.py", line 1315, in sync_blocks
     9    self.nodes[0].p2p.send_blocks_and_test(blocks, self.nodes[0], success=success, reject_code=reject_code, reject_reason=reject_reason, request_block=request_block, timeout=timeout)
    10  File "/home/ubuntu/bitcoin/test/functional/test_framework/mininode.py", line 553, in send_blocks_and_test
    11    wait_until(lambda: self.reject_code_received == reject_code, lock=mininode_lock, timeout=1)
    12  File "/home/ubuntu/bitcoin/test/functional/test_framework/util.py", line 227, in wait_until
    13    raise AssertionError("Predicate {} not true after {} seconds".format(predicate_source, timeout))
    14AssertionError: Predicate (['            wait_until(lambda: self.reject_code_received == reject_code, lock=mininode_lock, timeout=1)\n'], 553) not true after 1 seconds
    
  45. jnewbery force-pushed on Mar 19, 2018
  46. jnewbery commented at 6:32 pm on March 19, 2018: member
    Thanks for the review @MarcoFalke - I think I’ve addressed your comments
  47. MarcoFalke commented at 6:47 pm on March 19, 2018: member
    Thanks re-utACK 265d7c44b1aae06aee93f745a865807732218a73
  48. conscott commented at 1:27 pm on March 20, 2018: contributor
    Test re-ACK 265d7c44b1aae06aee93f745a865807732218a73
  49. jamesob commented at 1:20 pm on March 27, 2018: member
    Ready for merge?
  50. MarcoFalke commented at 2:48 pm on March 27, 2018: member

    Needs more (re) acks

    On Tue, Mar 27, 2018, 09:21 jamesob notifications@github.com wrote:

    Ready for merge?

    — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/bitcoin/bitcoin/pull/11773#issuecomment-376522188, or mute the thread https://github.com/notifications/unsubscribe-auth/AGGmv32N2D39OikZv_aEbDkLMcUm6iy6ks5tijzTgaJpZM4Qr7m3 .

  51. jnewbery commented at 2:53 pm on March 27, 2018: member
    @ryanofsky @practicalswift - care to reACK?
  52. ryanofsky commented at 6:23 pm on March 27, 2018: member
    utACK 265d7c44b1aae06aee93f745a865807732218a73. No code changes since last review except rebase and tweaks in feature_block.py commit (updating comments and reverting b89 loop change). There was also a commit message change mentioning runbarelyexpensive.
  53. in test/functional/feature_block.py:1299 in 265d7c44b1
    1401+            self.block_heights[block.sha256] = self.block_heights[old_sha256]
    1402+            del self.block_heights[old_sha256]
    1403+        self.blocks[block_number] = block
    1404+        return block
    1405+
    1406+    def reconnect_p2p(self):
    


    jamesob commented at 7:04 pm on March 27, 2018:
    I’m pretty sure this functionality gets repeated in several other tests. If so, we should move this somewhere more general and consolidate usages later on.

    jnewbery commented at 7:44 pm on March 27, 2018:
    Sure, but let’s save that for a future PR.

    jamesob commented at 8:14 pm on March 27, 2018:
    Yeah, definitely later.
  54. jamesob approved
  55. jnewbery commented at 7:45 pm on March 27, 2018: member
    4 ACKs. Ready for merge @MarcoFalke ?
  56. practicalswift commented at 8:35 pm on March 27, 2018: contributor
    utACK 265d7c44b1aae06aee93f745a865807732218a73
  57. MarcoFalke commented at 10:11 pm on March 27, 2018: member
    @laanwj Could you please merge this, since I am using my travel laptop for the next few days?
  58. MarcoFalke assigned laanwj on Mar 27, 2018
  59. laanwj merged this on Mar 29, 2018
  60. laanwj closed this on Mar 29, 2018

  61. laanwj referenced this in commit f0f9732d05 on Mar 29, 2018
  62. jnewbery deleted the branch on Mar 29, 2018
  63. ajtowns commented at 7:10 am on March 31, 2018: member
    It looks like ebf053ac6135941907ecfebccc778da34b585fac is causing feature_block.py to use about 5GB of RSS memory instead of about 1GB, haven’t had time to look into quite why yet. It’s causing MemoryError exceptions on my 4GB vm :(
  64. jnewbery commented at 7:45 pm on April 2, 2018: member
    @ajtowns - I think your memory problem is fixed in #12861
  65. MarcoFalke referenced this in commit 9a2db3b3d5 on Apr 5, 2018
  66. in test/functional/test_framework/util.py:223 in 265d7c44b1
    218@@ -218,8 +219,12 @@ def wait_until(predicate, *, attempts=float('inf'), timeout=float('inf'), lock=N
    219         time.sleep(0.05)
    220 
    221     # Print the cause of the timeout
    222-    assert_greater_than(attempts, attempt)
    223-    assert_greater_than(timeout, time.time())
    224+    predicate_source = inspect.getsourcelines(predicate)
    225+    logger.error("wait_until() failed. Predicate: {}".format(predicate_source))
    


    sdaftuar commented at 6:58 pm on May 9, 2018:
    This results in a spurious error message when wait_until is used and failure is expected, for instance in the p2p_segwit.py test where we advertise a txid from a not-NODE_WITNESS peer and ensure that a subsequence announcement from a NODE_WITNESS peer does not result in a duplicate getdata (while the first request is outstanding).

    jnewbery commented at 7:53 pm on May 9, 2018:
    Fixed here: #13205
  67. codablock referenced this in commit 22b9bfea33 on Sep 30, 2019
  68. codablock referenced this in commit c32b271410 on Sep 30, 2019
  69. codablock referenced this in commit 79d6ae2922 on Oct 2, 2019
  70. codablock referenced this in commit 4bf88d56ce on Oct 2, 2019
  71. UdjinM6 referenced this in commit 400674c412 on Oct 3, 2019
  72. codablock referenced this in commit f7d1974e3d on Oct 3, 2019
  73. UdjinM6 referenced this in commit 91b4a38398 on Jan 11, 2020
  74. ckti referenced this in commit 3170bf03b0 on Mar 28, 2021
  75. gades referenced this in commit 211cda13b3 on Jun 30, 2021
  76. 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: 2024-11-17 09:12 UTC

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