[tests] Add messages.py #11648

pull jnewbery wants to merge 2 commits into bitcoin:master from jnewbery:add_primitives_py changing 2 files +1412 −1383
  1. jnewbery commented at 8:52 pm on November 9, 2017: member

    Second part of #11518.

    Moves the primitive Bitcoin datastructures and message classes into their own module, and tidies up the mininode.py module.

    • First commit is almost entirely move-only
    • Second commit is mostly move-only, but also does a little tidying.
  2. fanquake added the label Tests on Nov 9, 2017
  3. fanquake commented at 1:23 am on November 10, 2017: member

    One travis failure in net.py:

     02017-11-10 01:10:17.553000 TestFramework.node0 (DEBUG): RPC successfully started
     12017-11-10 01:10:17.555000 TestFramework.node1 (DEBUG): RPC successfully started
     22017-11-10 01:10:18.043000 TestFramework (ERROR): Assertion failed
     3Traceback (most recent call last):
     4  File "/home/travis/build/bitcoin/bitcoin/build/bitcoin-x86_64-unknown-linux-gnu/test/functional/test_framework/test_framework.py", line 120, in main
     5    self.run_test()
     6  File "/home/travis/build/bitcoin/bitcoin/build/bitcoin-x86_64-unknown-linux-gnu/test/functional/net.py", line 27, in run_test
     7    self._test_getnettotals()
     8  File "/home/travis/build/bitcoin/bitcoin/build/bitcoin-x86_64-unknown-linux-gnu/test/functional/net.py", line 54, in _test_getnettotals
     9    assert_equal(before['bytesrecv_per_msg']['pong'] + 32, after['bytesrecv_per_msg']['pong'])
    10  File "/home/travis/build/bitcoin/bitcoin/build/bitcoin-x86_64-unknown-linux-gnu/test/functional/test_framework/util.py", line 38, in assert_equal
    11    raise AssertionError("not(%s)" % " == ".join(str(arg) for arg in (thing1, thing2) + args))
    12AssertionError: not(64 == 32)
    132017-11-10 01:10:18.044000 TestFramework (INFO): Stopping nodes
    142017-11-10 01:10:18.044000 TestFramework.node0 (DEBUG): Stopping node
    
  4. meshcollider commented at 6:50 am on November 10, 2017: contributor
    @fanquake looks unrelated, restarted
  5. laanwj commented at 10:11 am on November 10, 2017: member
    Thanks for trying to clean things up, but I think we need more categorization here; bitcoin P2P message types are clearly a different kind of primitives than consensus data structures such as CTransaction CTXin etc. Only the second group is called “primitives” in the C++ code.
  6. ryanofsky commented at 11:35 am on November 10, 2017: member
    Maybe just call it something like serialize.py or messages.py.
  7. jnewbery force-pushed on Nov 10, 2017
  8. [tests] Move test_framework Bitcoin primitives into separate module
    mininode.py wildcard imports all names from primitives.py. This is
    to avoid having to change all test scripts that import from mininode.py.
    f9cd9b1bfa
  9. [tests] Tidy up mininode.py module
    Mostly move only. Adds a few extra comments.
    1135c796a0
  10. jnewbery force-pushed on Nov 10, 2017
  11. jnewbery commented at 5:00 pm on November 10, 2017: member

    I think we need more categorization here; bitcoin P2P message types are clearly a different kind of primitives than consensus data structures

    I tried splitting this further into primitives.py (for the primitive consensus data structures) and messages.py (for the p2p message data structures), but the resulting layout didn’t make much sense to me so I reverted it. The main motivation for this PR was to split out the mininode functionality from the underlying data structures. I’ve renamed the new module messages.py as suggested by @ryanofsky.

    If you think it’s worth splitting further into consensus primitives and p2p message data structures, I can look at doing that in a future PR. It would end up looking something like https://github.com/jnewbery/bitcoin/tree/pr11648.2.

  12. jnewbery renamed this:
    [tests] Add primitives.py
    [tests] Add messages.py
    on Nov 10, 2017
  13. laanwj commented at 7:37 am on November 11, 2017: member
    @jnewbery Thanks. Calling it messages.py is enough. I don’t think they need to be split further unless they’re used seperately, which they’re not. It was just that having two concepts of “primitives” between the tests and code was confusing to me.
  14. practicalswift commented at 9:26 pm on November 14, 2017: contributor
    utACK 1135c796a0e1151b03933f2cd36ce95a8e136b7a
  15. laanwj requested review from MarcoFalke on Nov 16, 2017
  16. MarcoFalke added the label Refactoring on Nov 16, 2017
  17. in test/functional/test_framework/messages.py:37 in 1135c796a0
    32+MY_RELAY = 1 # from version 70001 onwards, fRelay should be appended to version messages (BIP37)
    33+
    34+MAX_INV_SZ = 50000
    35+MAX_BLOCK_BASE_SIZE = 1000000
    36+
    37+COIN = 100000000 # 1 btc in satoshis
    


    MarcoFalke commented at 6:39 pm on November 16, 2017:
    nit: This is a conversion helper constant not used by any of the primitives or messages.

    laanwj commented at 12:13 pm on November 17, 2017:

    It’s used in:

    • CTxOut.__repr__
    • CTransaction.is_valid

    It’s arguable where this belongs, the ideal place might be some bitcoin-specific constants header, but for now it makes sense to have it here.


    MarcoFalke commented at 2:50 pm on November 17, 2017:
    You are right, I missed those. Looks fine now.
  18. MarcoFalke commented at 6:44 pm on November 16, 2017: member

    utACK 1135c796a0e1151b03933f2cd36ce95a8e136b7a

    Verified that it is indeed move-only and/or fixups due to rename. I am neutral on the overall change. Some prefer a huge file where it is easy to jump back and forth, others prefer multiple files that bundle into smaller sets of related classes and functions.

    I think there is no single true way of organizing the files, but if the refactoring helps some greater goal, I am happy with the changes.

  19. laanwj commented at 12:17 pm on November 17, 2017: member
    utACK 1135c79
  20. laanwj merged this on Nov 17, 2017
  21. laanwj closed this on Nov 17, 2017

  22. laanwj referenced this in commit ccc70a295f on Nov 17, 2017
  23. in test/functional/test_framework/messages.py:57 in 1135c796a0
    52+
    53+def hash256(s):
    54+    return sha256(sha256(s))
    55+
    56+def ser_compact_size(l):
    57+    r = b""
    


    promag commented at 3:13 pm on November 17, 2017:
    Unnecessary?

    MarcoFalke commented at 3:20 pm on November 17, 2017:
    Generally, it is easier to verify move-only-ness when no code changes are made. We’ve had pull requests in the past that did “all the refactoring” in one go and introduced bugs.

    laanwj commented at 3:40 pm on November 17, 2017:

    IMO both ways are acceptable, as long as the commits that move code are separate from those that make changes.

    In any case, moving code around doesn’t obligate someone to also fix all the problems it has, in style or other things. Can be done later.


    MarcoFalke commented at 3:57 pm on November 17, 2017:
    Yes, happy to see this fixed up when you touch that function for other reasons. Not sure if this change warrants a pull request on itself.
  24. jnewbery deleted the branch on Nov 17, 2017
  25. PastaPastaPasta referenced this in commit 7bd99943ae on Sep 11, 2019
  26. PastaPastaPasta referenced this in commit 414025035d on Mar 22, 2020
  27. PastaPastaPasta referenced this in commit d4fb23448e on Mar 27, 2020
  28. UdjinM6 referenced this in commit 975f73be7a on Mar 30, 2020
  29. ckti referenced this in commit 631d531c28 on Mar 28, 2021
  30. gades referenced this in commit 053f5370f4 on Jun 30, 2021
  31. DrahtBot 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-10-06 19:12 UTC

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