tests: Use test framework utils where possible #23127

pull vincenzopalazzo wants to merge 35 commits into bitcoin:master from vincenzopalazzo:tests/use_testutils changing 29 files +197 −146
  1. vincenzopalazzo commented at 7:36 am on September 29, 2021: none

    This PR removes when it is possible the native python assert, and use the test utils function, like assert_equal, assert_greater_than, assert_greater_than_or_equal.

    Update

    In addition, this PR includes a new operator assert_not_equal, which IMO it is useful to test other conditions and add the error message as a parameter of the function to give more flexibility.

    Fixes #23119

    Edit laanwj: removed HTML comment from post

  2. fanquake added the label Tests on Sep 29, 2021
  3. in test/functional/feature_backwards_compatibility.py:127 in d1c6861d60 outdated
    123@@ -123,52 +124,52 @@ def run_test(self):
    124         wallet = node_v18.get_wallet_rpc("w1_v18")
    125         info = wallet.getwalletinfo()
    126         assert info['private_keys_enabled']
    127-        assert info['keypoolsize'] > 0
    128+        assert_greater_than(info['keypoolsize'] > 0)
    


    meshcollider commented at 10:04 am on September 29, 2021:
    error here, , instead of >

    vincenzopalazzo commented at 10:12 am on September 29, 2021:
    Ops, thanks to catch my error @meshcollider!
  4. meshcollider commented at 10:06 am on September 29, 2021: contributor
    Thanks for contributing and helping out @vincenzopalazzo!
  5. vincenzopalazzo force-pushed on Sep 29, 2021
  6. brunoerg commented at 11:05 am on September 29, 2021: contributor
    Concept ACK
  7. brunoerg commented at 11:47 am on September 29, 2021: contributor
    Will it be created new PRs to update other tests or should we concentrate all the changes here?
  8. vincenzopalazzo commented at 11:54 am on September 29, 2021: none

    Will it be created new PRs to update other tests or should we concentrate all the changes here?

    The plan is to divide the work into small chunks to make the price of PR review easy and fast.

  9. MarcoFalke renamed this:
    tests: Use test utils each time that it is possible
    tests: Use assert_equal* utils where possible
    on Sep 29, 2021
  10. brunoerg commented at 12:04 pm on September 29, 2021: contributor

    Will it be created new PRs to update other tests or should we concentrate all the changes here?

    The plan is to divide the work into small chunks to make the price of PR review easy and fast.

    Cool, thanks!

  11. brunoerg commented at 12:22 pm on September 29, 2021: contributor
    I just created #23135 to help on it
  12. vincenzopalazzo commented at 12:48 pm on September 29, 2021: none

    I just created #23135 to help on it

    Thanks, the important think it that we don’t make the double work :-)

  13. vincenzopalazzo force-pushed on Sep 29, 2021
  14. vincenzopalazzo force-pushed on Sep 29, 2021
  15. vincenzopalazzo requested review from meshcollider on Sep 29, 2021
  16. DrahtBot commented at 5:29 pm on September 29, 2021: contributor

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #25732 (tests: Use test utils each time that it is possible by vincenzopalazzo)
    • #25291 (test: Refactor rpc_fundrawtransaction.py by akankshakashyap)
    • #23502 (wallet: Avoid underpaying transaction fees when signing taproot spends by achow101)
    • #20892 (tests: Run both descriptor and legacy tests within a single test invocation by achow101)
    • #17794 (test: Use assert_greater_than_or_equal helper method to aid debugging. by jbampton)
    • #16545 (refactor: Implement missing error checking for ArgsManager flags by ryanofsky)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  17. vincenzopalazzo force-pushed on Sep 29, 2021
  18. vincenzopalazzo force-pushed on Sep 30, 2021
  19. vincenzopalazzo force-pushed on Oct 2, 2021
  20. vincenzopalazzo force-pushed on Oct 3, 2021
  21. michaelfolkson commented at 10:02 am on October 4, 2021: contributor

    Concept ACK

    I think generally splitting across multiple pull requests works best for the monster sub-projects (AssumeUTXO, deglobalizing ChainstateManager, Process Separation etc).

    In this case splitting across multiple commits within the same PR would probably have been sufficient to make it easily reviewable but not a big deal and if it encourages multiple contributors to self-organize around completing it then that’s great.

  22. in test/functional/test_framework/util.py:54 in 80c593f4ec outdated
    49@@ -50,6 +50,11 @@ def assert_equal(thing1, thing2, *args):
    50         raise AssertionError("not(%s)" % " == ".join(str(arg) for arg in (thing1, thing2) + args))
    51 
    52 
    53+def assert_not_equal(thing1, thing2, *args):
    54+    if thing1 == thing2 or any(thing1 != arg for arg in args):
    


    kiminuo commented at 3:12 pm on October 4, 2021:

    Should it possibly be:

    0    if thing1 == thing2 or any(thing1 == arg for arg in args):
    

    ?


    vincenzopalazzo commented at 9:40 am on October 5, 2021:
    Good catch @kiminuo thanks you!
  23. vincenzopalazzo force-pushed on Oct 5, 2021
  24. vincenzopalazzo force-pushed on Oct 5, 2021
  25. vincenzopalazzo commented at 9:41 am on October 5, 2021: none

    Thanks @michaelfolkson,

    In this case splitting across multiple commits within the same PR would probably have been sufficient to make it easily reviewable but not a big deal and if it encourages multiple contributors to self-organize around completing it then that’s great.

    It sounds great to me, I will go with this solution. Thansk!

  26. vincenzopalazzo force-pushed on Oct 5, 2021
  27. vincenzopalazzo force-pushed on Oct 5, 2021
  28. vincenzopalazzo force-pushed on Oct 10, 2021
  29. vincenzopalazzo force-pushed on Oct 10, 2021
  30. dougEfresh commented at 11:52 am on October 22, 2021: contributor
    @vincenzopalazzo Added assert_less* #23337.
  31. in test/functional/feature_segwit.py:215 in 6fd680e239 outdated
    214+            assert_equal(self.nodes[1].getrawtransaction(tx_id, False, blockhash), self.nodes[2].getrawtransaction(tx_id, False, blockhash))
    215             assert self.nodes[0].getrawtransaction(tx_id, False, blockhash) != self.nodes[2].gettransaction(tx_id)["hex"]
    216-            assert self.nodes[1].getrawtransaction(tx_id, False, blockhash) == self.nodes[2].gettransaction(tx_id)["hex"]
    217-            assert self.nodes[0].getrawtransaction(tx_id, False, blockhash) == tx.serialize_without_witness().hex()
    218+            assert_equal(self.nodes[1].getrawtransaction(tx_id, False, blockhash), self.nodes[2].gettransaction(tx_id)["hex"])
    219+            assert_equal( elf.nodes[0].getrawtransaction(tx_id, False, blockhash), tx.serialize_without_witness().hex())
    


    stratospher commented at 6:36 pm on October 27, 2021:
    It’d be nice if the typo is fixed in this commit itself since each commit should compile and work independently.
  32. vincenzopalazzo force-pushed on Oct 28, 2021
  33. vincenzopalazzo force-pushed on Oct 28, 2021
  34. brunoerg commented at 12:31 pm on October 29, 2021: contributor
    Ready for review?
  35. vincenzopalazzo commented at 12:56 pm on October 29, 2021: none

    Ready for review?

    All the commit for the moment yes, I need to finish other files in the next week, but until now yes, it is ready

  36. vincenzopalazzo force-pushed on Nov 2, 2021
  37. vincenzopalazzo force-pushed on Nov 2, 2021
  38. vincenzopalazzo force-pushed on Nov 2, 2021
  39. vincenzopalazzo force-pushed on Nov 2, 2021
  40. vincenzopalazzo force-pushed on Nov 2, 2021
  41. vincenzopalazzo renamed this:
    tests: Use assert_equal* utils where possible
    tests: Use test framework utils where possible
    on Nov 2, 2021
  42. vincenzopalazzo force-pushed on Nov 2, 2021
  43. vincenzopalazzo force-pushed on Nov 2, 2021
  44. vincenzopalazzo force-pushed on Nov 2, 2021
  45. vincenzopalazzo force-pushed on Nov 2, 2021
  46. vincenzopalazzo force-pushed on Nov 2, 2021
  47. vincenzopalazzo force-pushed on Nov 2, 2021
  48. vincenzopalazzo force-pushed on Nov 2, 2021
  49. vincenzopalazzo force-pushed on Nov 2, 2021
  50. vincenzopalazzo force-pushed on Nov 4, 2021
  51. vincenzopalazzo force-pushed on Nov 5, 2021
  52. vincenzopalazzo force-pushed on Nov 5, 2021
  53. vincenzopalazzo force-pushed on Nov 6, 2021
  54. vincenzopalazzo force-pushed on Nov 6, 2021
  55. vincenzopalazzo force-pushed on Nov 6, 2021
  56. vincenzopalazzo force-pushed on Nov 6, 2021
  57. vincenzopalazzo force-pushed on Nov 8, 2021
  58. vincenzopalazzo force-pushed on Nov 9, 2021
  59. DrahtBot added the label Needs rebase on Nov 15, 2021
  60. vincenzopalazzo force-pushed on Nov 15, 2021
  61. DrahtBot removed the label Needs rebase on Nov 15, 2021
  62. vincenzopalazzo force-pushed on Nov 15, 2021
  63. DrahtBot added the label Needs rebase on Nov 16, 2021
  64. vincenzopalazzo force-pushed on Nov 16, 2021
  65. DrahtBot removed the label Needs rebase on Nov 16, 2021
  66. DrahtBot added the label Needs rebase on Nov 17, 2021
  67. vincenzopalazzo force-pushed on Nov 27, 2021
  68. DrahtBot removed the label Needs rebase on Nov 27, 2021
  69. vincenzopalazzo force-pushed on Dec 6, 2021
  70. laanwj commented at 3:28 pm on December 13, 2021: member

    Concept ACK 9edb3cc5d08caaf61ff00c49a698956f4ddaba08, looked over the commits briefly and a) didn’t find any mistakes b) checked the changes are contained to where they should be

    though I haven’t reviewed the huge list of changes in detail so can’t warrant calling it a full code review ACK.

  71. vincenzopalazzo commented at 3:38 pm on December 13, 2021: none

    though I haven’t reviewed the huge list of changes in detail so can’t warrant calling it a full code review ACK.

    Sorry about that, I should add some tips on the PR. However, there is only a critical change in the test utils framework, now all the assert support the error message as the parameter this only because we can support also custom message defined with assert False, "always false"

  72. laanwj commented at 3:52 pm on December 13, 2021: member

    Sorry about that, I should add some tips on the PR.

    I think you misunderstood: It was not a comment on your work. I meant that I can’t call what I did a full code review. I should look in more detail, though generally getting the type of assert wrong will usually just result in the tests failing, so I’m reasonably confident in the correctness of the changes.

  73. michaelfolkson commented at 4:14 pm on December 13, 2021: contributor

    I think generally splitting across multiple pull requests works best for the monster sub-projects (AssumeUTXO, deglobalizing ChainstateManager, Process Separation etc).

    I know I’ve previously said this (so apologies if this wasn’t helpful at the time) but I think the PR has got sufficiently big that a PR or two could maybe be spun out of this one to make it easier to review.

    I also think the structure of commits could be improved, having a separate commit for each file doesn’t make much sense to me. Also the commit messages aren’t particularly informative for reviewers.

    Commit messages such as “Define new assert functions in test utils”, “Replace assert with assert_equal across functional test suite” and “Use assert_greater_than instead of greater than asserts” would be more helpful than “filename.py: Use test framework”.

    Reviewers can see what files are changed without looking at commit messages, what they want to see with the commit messages is what the commit is doing.

  74. vincenzopalazzo force-pushed on Dec 21, 2021
  75. DrahtBot added the label Needs rebase on Dec 28, 2021
  76. vincenzopalazzo force-pushed on Dec 28, 2021
  77. DrahtBot removed the label Needs rebase on Dec 28, 2021
  78. elmarsan commented at 5:16 pm on December 29, 2021: none

    I think generally splitting across multiple pull requests works best for the monster sub-projects (AssumeUTXO, deglobalizing ChainstateManager, Process Separation etc).

    I know I’ve previously said this (so apologies if this wasn’t helpful at the time) but I think the PR has got sufficiently big that a PR or two could maybe be spun out of this one to make it easier to review.

    I also think the structure of commits could be improved, having a separate commit for each file doesn’t make much sense to me. Also the commit messages aren’t particularly informative for reviewers.

    Commit messages such as “Define new assert functions in test utils”, “Replace assert with assert_equal across functional test suite” and “Use assert_greater_than instead of greater than asserts” would be more helpful than “filename.py: Use test framework”.

    Reviewers can see what files are changed without looking at commit messages, what they want to see with the commit messages is what the commit is doing.

    Hey, I agree with you.

    Maybe this pull request could be splitted into three different ones. For example: one pull request per each assertion type to refactor assert_equal, assert_greater_than and assert_greater_than_or_equal

    I’d would like to help with the reviews!

  79. vincenzopalazzo commented at 6:58 pm on December 29, 2021: none

    Maybe this pull request could be splitted into three different ones. For example: one pull request per each assertion type to refactor assert_equal, assert_greater_than and

    Each following step required the same trade-off with only personal preference, if you split the PR in more PRs, you have more work to do, and so on.

    The change is not only in the change of the assert tp assert_* but this PR includes also some change inside the test framework, now the method accepts also an optional parameter err_msg

    This required a big pr that include this change too.

    In conclusion, I agree that small PR can be useful for other people, but at the end of the day, there is no real improvement inside the velocity of review.

    This takes time, as with all types of refactoring. This time is chosen this way but the next time we can do in another way that we can set up before finish the work. Back in October, I chatted on IRC to choose which method is the best, so this is not my own choice.

  80. vincenzopalazzo force-pushed on Dec 30, 2021
  81. vincenzopalazzo force-pushed on Jan 9, 2022
  82. in test/functional/feature_segwit.py:48 in 38fe1453d4 outdated
    43@@ -44,6 +44,7 @@
    44 from test_framework.test_framework import BitcoinTestFramework
    45 from test_framework.util import (
    46     assert_equal,
    47+    assert_not_equal,
    48     assert_greater_than_or_equal,
    49     assert_is_hex_string,
    


    niVelion commented at 4:31 pm on January 13, 2022:

    Nit. Maintain alphabetical import ordering within this file.

    0    assert_greater_than_or_equal,
    1    assert_is_hex_string,
    2    assert_not_equal,
    
  83. in test/functional/feature_taproot.py:102 in 38fe1453d4 outdated
     97+    assert_equal,
     98+    assert_not_equal,
     99+    assert_true,
    100+    assert_greater_than,
    101+    assert_greater_than_or_equal,
    102+)
    


    niVelion commented at 4:36 pm on January 13, 2022:

    Nit.

    0from test_framework.util import (
    1    assert_equal,
    2    assert_greater_than,
    3    assert_greater_than_or_equal,
    4    assert_not_equal,
    5    assert_raises_rpc_error,
    6    assert_true,
    7)
    
  84. in test/functional/interface_zmq.py:525 in 38fe1453d4 outdated
    523+                assert_true(hash_str not in mempool_view)
    524                 mempool_view.add(hash_str)
    525                 expected_sequence = mempool_sequence + 1
    526             elif label == "R":
    527-                assert hash_str in mempool_view
    528+                assert_true(hash_str in mempool_view)
    


    MarcoFalke commented at 4:39 pm on January 13, 2022:
    what is the motivation to change this?

    vincenzopalazzo commented at 0:04 am on January 15, 2022:
    The only reason is to maintain consistency between error code format and code style. I usually try to avoid mixing different types of assert (from library and native assert) in the tests

    MarcoFalke commented at 7:08 am on January 15, 2022:
    It is fine if you do this personally in your own projects, but for bitcoin-core this is impossible to maintain. Someone is going to break the consistency at some point. We can’t handle this if there are floods of follow-up pull requests. Also, if there is a linter to make lib assert illegal, it puts an unnecessary burden on developers for style reasons.

    vincenzopalazzo commented at 8:28 am on January 15, 2022:
    Mh I agree with the difficulty to add a change of style at this point on Bitcoin core, I only propose one way here and I’m super happy to revert the change and to have this great exchange of idea
  85. in test/functional/wallet_txn_doublespend.py:49 in 38fe1453d4 outdated
    45@@ -46,7 +46,7 @@ def run_test(self):
    46         # blockchain sync later in the test when nodes are connected, due to
    47         # timing issues.
    48         for n in self.nodes:
    49-            assert n.getblockchaininfo()["initialblockdownload"] == False
    50+            assert_equal(n.getblockchaininfo()["initialblockdownload"], False)
    


    MarcoFalke commented at 4:42 pm on January 13, 2022:

    Seems there are too many ways to say the same thing. I think we shouldn’t be adding even more.

    For boolean values, if the assertion fails, it is clear what value the bool was. There is no need to print the value and a constant.


    vincenzopalazzo commented at 0:03 am on January 15, 2022:

    Seems there are too many ways to say the same thing. I think we shouldn’t be adding even more.

    Right, in this case, I use the assert_equal but I could use assert_true, and the reason that I used this is only for consistency across error messages and source code. However, if you like I can restore the pure assert


    michaelfolkson commented at 3:28 pm on March 24, 2022:
    @MarcoFalke: What is your preference for what @vincenzopalazzo does here?

    stickies-v commented at 11:05 am on August 2, 2022:

    For boolean values, if the assertion fails, it is clear what value the bool was. There is no need to print the value and a constant.

    I’d agree in a statically typed environment, but in Python that doesn’t really hold? I think there’s merit in always printing the value, to more quickly debug cases where e.g. the type of a response changes or becomes None/empty string?

  86. in test/functional/feature_taproot.py:581 in 38fe1453d4 outdated
    591@@ -585,7 +592,7 @@ def bitflipper(expr):
    592     """Return a callable that evaluates expr and returns it with a random bitflip."""
    593     def fn(ctx):
    594         sub = deep_eval(ctx, expr)
    595-        assert isinstance(sub, bytes)
    596+        assert_true(isinstance(sub, bytes), err_msg="It is not a bytes instance")
    


    niVelion commented at 4:43 pm on January 13, 2022:
    :eyes: The subject “it” here seems ambiguous, though I haven’t tried making this test fail to see whether it is.

    vincenzopalazzo commented at 0:06 am on January 15, 2022:
    You have right! I will change the error message, but here I really have no idea what is the correct error message to add. Any suggestion?

    laanwj commented at 5:53 pm on March 24, 2022:
    Asserting prints the line where the error happens, right? The expression isinstance(sub, bytes) says it all, I don’t think any more information needs to be added here.
  87. in test/functional/feature_taproot.py:1295 in 38fe1453d4 outdated
    1290@@ -1284,15 +1291,16 @@ def block_submit(self, node, txs, msg, err_msg, cb_pubkey=None, fees=0, sigops_w
    1291         block.solve()
    1292         block_response = node.submitblock(block.serialize().hex())
    1293         if err_msg is not None:
    1294-            assert block_response is not None and err_msg in block_response, "Missing error message '%s' from block response '%s': %s" % (err_msg, "(None)" if block_response is None else block_response, msg)
    1295+            assert_true(block_response is not None and err_msg in block_response,
    1296+                        err_msg= "Missing error message '%s' from block response '%s': %s" % (err_msg, "(None)" if block_response is None else block_response, msg))
    


    niVelion commented at 4:44 pm on January 13, 2022:

    Nit.

    0                        err_msg="Missing error message '%s' from block response '%s': %s" % (err_msg, "(None)" if block_response is None else block_response, msg))
    
  88. in test/functional/feature_taproot.py:1401 in 38fe1453d4 outdated
    1434@@ -1427,7 +1435,9 @@ def test_spenders(self, node, spenders, input_counts):
    1435             for i in range(len(input_utxos)):
    1436                 if input_utxos[i].spender.need_vin_vout_mismatch:
    1437                     first_mismatch_input = i
    1438-            assert first_mismatch_input is None or first_mismatch_input > 0
    1439+
    1440+            if first_mismatch_input is not None:
    1441+                assert_greater_than(first_mismatch_input, 0)
    


    niVelion commented at 4:52 pm on January 13, 2022:
    :+1: in keeping with the line revised here, the first condition is tested for truthiness and then only if it is not true is the second condition tested.
  89. in test/functional/interface_zmq.py:27 in 38fe1453d4 outdated
    20@@ -21,6 +21,8 @@
    21 )
    22 from test_framework.util import (
    23     assert_equal,
    24+    assert_true,
    25+    assert_greater_than,
    26     assert_raises_rpc_error,
    27 )
    


    niVelion commented at 4:57 pm on January 13, 2022:

    Nit. Sort imports.

    0from test_framework.util import (
    1    assert_equal,
    2    assert_greater_than,
    3    assert_raises_rpc_error,
    4    assert_true,
    5)
    
  90. in test/functional/interface_zmq.py:72 in 38fe1453d4 outdated
    68@@ -67,9 +69,9 @@ def receive_sequence(self):
    69         label = chr(body[32])
    70         mempool_sequence = None if len(body) != 32+1+8 else struct.unpack("<Q", body[32+1:])[0]
    71         if mempool_sequence is not None:
    72-            assert label == "A" or label == "R"
    73+            assert_true(label == "A" or label == "R", err_msg="{} different from A or C".format(label))
    


    niVelion commented at 5:02 pm on January 13, 2022:

    Error message fix.

    0            assert_true(label == "A" or label == "R", err_msg="{} different from A or R".format(label))
    
  91. in test/functional/mining_getblocktemplate_longpoll.py:13 in 38fe1453d4 outdated
     9@@ -10,7 +10,7 @@
    10 
    11 from test_framework.blocktools import COINBASE_MATURITY
    12 from test_framework.test_framework import BitcoinTestFramework
    13-from test_framework.util import get_rpc_proxy
    14+from test_framework.util import get_rpc_proxy, assert_equal
    


    niVelion commented at 5:05 pm on January 13, 2022:

    Nit. Sort imports (decided to point out each instance to save you the time).

    0from test_framework.util import assert_equal, get_rpc_proxy
    
  92. in test/functional/p2p_compactblocks.py:61 in 38fe1453d4 outdated
    62@@ -63,6 +63,8 @@
    63 from test_framework.test_framework import BitcoinTestFramework
    64 from test_framework.util import (
    65     assert_equal,
    66+    assert_true,
    67+    assert_greater_than_or_equal,
    


    niVelion commented at 5:06 pm on January 13, 2022:

    Nit. Sort imports.

    0    assert_greater_than_or_equal,
    1    assert_true,
    
  93. in test/functional/p2p_compactblocks.py:699 in 38fe1453d4 outdated
    730@@ -729,7 +731,7 @@ def test_end_to_end_block_relay(self, listeners):
    731     # but invalid transactions.
    732     def test_invalid_tx_in_compactblock(self, test_node, use_segwit=True):
    733         node = self.nodes[0]
    734-        assert len(self.utxos)
    735+        assert_true(len(self.utxos) > 0)
    


    niVelion commented at 5:16 pm on January 13, 2022:
    If the original predicate was already truthy, I assume the addition of > 0 is to improve readability? The original reads better imo. Same comment L768.

    vincenzopalazzo commented at 0:20 am on January 15, 2022:

    I make this choice for consistency, across error messages and assert convention. I usually try to avoid missing pure assert and assert that came from utils code like the bitcoin test framework.

    But I admit that in this case, it would be better assert_not_empity(self.utxos)

    However, if you disagree I would restore the previous status with the pure assert

  94. in test/functional/wallet_disable.py:15 in 38fe1453d4 outdated
     8@@ -9,7 +9,10 @@
     9 """
    10 
    11 from test_framework.test_framework import BitcoinTestFramework
    12-from test_framework.util import assert_raises_rpc_error
    13+from test_framework.util import (
    14+    assert_raises_rpc_error,
    15+    assert_equal,
    16+)
    


    niVelion commented at 5:27 pm on January 13, 2022:

    Nit. Sort imports.

    0from test_framework.util import (
    1    assert_equal,
    2    assert_raises_rpc_error,
    3)
    
  95. in test/functional/rpc_createmultisig.py:20 in 38fe1453d4 outdated
    15@@ -16,6 +16,7 @@
    16 from test_framework.util import (
    17     assert_raises_rpc_error,
    18     assert_equal,
    19+    assert_true,
    20 )
    


    niVelion commented at 5:42 pm on January 13, 2022:

    Nit. I can see this files imports aren’t alphabetical but may as well since touching these LOC.

    0from test_framework.util import (
    1    assert_equal,
    2    assert_raises_rpc_error,
    3    assert_true,
    4)
    
  96. in test/functional/rpc_fundrawtransaction.py:28 in 38fe1453d4 outdated
    16@@ -17,6 +17,8 @@
    17     assert_greater_than,
    18     assert_greater_than_or_equal,
    19     assert_raises_rpc_error,
    20+    assert_true,
    21+    fail,
    22     count_bytes,
    23     find_vout_for_address,
    


    niVelion commented at 5:44 pm on January 13, 2022:

    Nit.

    0    count_bytes,
    1    fail,
    2    find_vout_for_address,
    
  97. in test/functional/test_framework/util.py:83 in 38fe1453d4 outdated
    94+def assert_true(thing, err_msg=None):
    95+    if thing is not True:
    96+        msg = "%s it is not True" % str(thing)
    97+        if err_msg is not None:
    98+            msg = err_msg
    99+        raise AssertionError(msg)
    


    niVelion commented at 6:09 pm on January 13, 2022:

    Minor: avoid initializing a default message when an err_msg is provided.

    0def assert_true(thing, err_msg=None):
    1    if thing is not True:
    2        msg = err_msg or "%s it is not True" % str(thing)
    3        raise AssertionError(msg)
    
  98. in test/functional/test_framework/util.py:50 in 38fe1453d4 outdated
    44@@ -45,19 +45,52 @@ def assert_fee_amount(fee, tx_size, feerate_BTC_kvB):
    45         raise AssertionError("Fee of %s BTC too high! (Should be %s BTC)" % (str(fee), str(target_fee)))
    46 
    47 
    48-def assert_equal(thing1, thing2, *args):
    49+def assert_equal(thing1, thing2, *args, err_msg=None):
    50     if thing1 != thing2 or any(thing1 != arg for arg in args):
    51-        raise AssertionError("not(%s)" % " == ".join(str(arg) for arg in (thing1, thing2) + args))
    52+        msg = "not(%s)" % " == ".join(str(arg) for arg in (thing1, thing2) + args)
    


    niVelion commented at 6:19 pm on January 13, 2022:

    LGTM:

    0>>> thing1 = "foo"
    1>>> thing2 = "bar"
    2>>> args = ("baz", "qux")
    3>>> msg = "not(%s)" % " == ".join(str(arg) for arg in (thing1, thing2) + args)
    4>>> msg
    5'not(foo == bar == baz == qux)'
    
  99. in test/functional/test_framework/util.py:71 in 38fe1453d4 outdated
    76+def assert_less_than(thing1, thing2, err_msg=None):
    77+    if thing1 >= thing2:
    78+        msg = "%s >= %s" % (str(thing1), str(thing2))
    79+        if err_msg is not None:
    80+            msg = err_msg
    81+        raise AssertionError(msg)
    


    niVelion commented at 6:41 pm on January 13, 2022:

    Minor, you could avoid initializing msg when an err_msg is provided.

    0def assert_true(thing, err_msg=None):
    1    if thing is not True:
    2        msg = err_msg or "%s it is not True" % str(thing)
    3        raise AssertionError(msg)
    
    0def assert_less_than(thing1, thing2, err_msg=None):
    1    if thing1 >= thing2:
    2        msg = err_msg or %s >= %s" % (str(thing1), str(thing2))
    3        raise AssertionError(msg)
    
  100. in test/functional/wallet_address_types.py:209 in 38fe1453d4 outdated
    206@@ -206,7 +207,7 @@ def test_desc(self, node, address, multisig, typ, utxo):
    207             assert_equal(info['desc'], descsum_create("wsh(multi(2,%s,%s))" % (key_descs[info['pubkeys'][0]], key_descs[info['pubkeys'][1]])))
    208         else:
    209             # Unknown type
    210-            assert False
    211+            fail("Unknown type")
    


    niVelion commented at 8:59 pm on January 13, 2022:
    Comment # Unknown type likely redundant now.
  101. niVelion commented at 9:05 pm on January 13, 2022: none
    Thoroughly reviewed and just for good measure, checked out compiled and ran test/functional/test_runner.py --extended.
  102. vincenzopalazzo force-pushed on Jan 15, 2022
  103. kallewoof commented at 7:36 am on January 15, 2022: member
    I don’t see why splitting into one commit per file does anything to help review. The contrary, I’d say. The UI already splits per file for you.
  104. vincenzopalazzo commented at 8:11 am on January 15, 2022: none

    I don’t see why splitting into one commit per file does anything to help review. The contrary, I’d say. The UI already splits per file for you.

    When I start to work on that I had the opposite advice, I think this could be a personal choice, I’m sorry if it makes things worse for you.

    I’m fine with this splitting because each commit has only a personal portion of all the change, and usually, the UI starts to be very slow for a lot of changes. In addition, for disability reason, I don’t use the UI to review PR, but only to leave a comment, so I considered this approach more accessible too

  105. vincenzopalazzo force-pushed on Jan 15, 2022
  106. DrahtBot added the label Needs rebase on Feb 24, 2022
  107. vincenzopalazzo force-pushed on Mar 23, 2022
  108. DrahtBot removed the label Needs rebase on Mar 23, 2022
  109. vincenzopalazzo force-pushed on Mar 23, 2022
  110. DrahtBot added the label Needs rebase on Mar 24, 2022
  111. vincenzopalazzo force-pushed on Mar 24, 2022
  112. DrahtBot removed the label Needs rebase on Mar 24, 2022
  113. michaelfolkson commented at 3:38 pm on March 24, 2022: contributor

    I don’t see why splitting into one commit per file does anything to help review. The contrary, I’d say. The UI already splits per file for you.

    When I start to work on that I had the opposite advice, I think this could be a personal choice, I’m sorry if it makes things worse for you.

    I don’t think anyone suggested that it should be one commit per file right? I suggested splitting across commits rather than different PRs but not giving each file a separate commit.

    I suggested this:

    I also think the structure of commits could be improved, having a separate commit for each file doesn’t make much sense to me. Also the commit messages aren’t particularly informative for reviewers.

    Commit messages such as “Define new assert functions in test utils”, “Replace assert with assert_equal across functional test suite” and “Use assert_greater_than instead of greater than asserts” would be more helpful than “filename.py: Use test framework”.

    Reviewers can see what files are changed without looking at commit messages, what they want to see with the commit messages is what the commit is doing.

    I personally think this isn’t serious enough (others can assess) that it means it is not yet in a merge-able state but yeah I agree with Kalle that splitting into one commit per file isn’t optimal.

  114. vincenzopalazzo force-pushed on Mar 24, 2022
  115. vincenzopalazzo commented at 5:25 pm on March 24, 2022: none

    I don’t think anyone suggested that it should be one commit per file right? I suggested splitting across commits rather than different PRs but not giving each file a separate commit.

    Splitting between commits is a too general definition because splitting between commits brings the following problems:

    • 1: What do we need to insert inside one commit? How do you define a good commit for this PR?
    • 2: The commit should be independent of other changes, this means the following things
    • 2.1: improve the test unit should have a separate PR
    • 2.1: moving the test assert in a way that is independent testable.

    This is the reason that I choose to divide the file change each one in a separate commit because you can fetch one commit and test in a clean env only on the functional test that you need.

    IMHO this is the more clean way to help the reviewer and avoid introducing regression

    This is also a good PR definition because to make small PRs you need just to cherry-pick the commits!

    I don’t see any drawback with my solution, right?

    P.S: In addition, this solution helps also to rebase the PRs and make the tests only on the file changed, that in this case is the single commit

  116. in test/functional/test_framework/util.py:71 in 4a993641db outdated
    65@@ -66,6 +66,11 @@ def assert_greater_than_or_equal(thing1, thing2):
    66         raise AssertionError("%s < %s" % (str(thing1), str(thing2)))
    67 
    68 
    69+def assert_true(thing, message = None):
    70+    if thing is not True:
    71+        msg = "%s it is not True" if message is None else message
    


    laanwj commented at 5:57 pm on March 24, 2022:
    it needs to be removed from this sentence, also % str(thing) needs to be used to perform formatting so that the value of thing ends up in the message.

    vincenzopalazzo commented at 6:25 pm on March 24, 2022:

    Good catch, thanks!

    I move the following test framework to the following convention

    0def assert_true(thing, err_msg=None):
    1    if thing is not True:
    2        msg = err_msg or "%s is not True" % str(thing)
    3        raise AssertionError(msg)
    

    I just removed it,

  117. vincenzopalazzo commented at 6:26 pm on March 24, 2022: none
    Trivial rebase!
  118. DrahtBot added the label Needs rebase on Mar 24, 2022
  119. vincenzopalazzo force-pushed on Mar 24, 2022
  120. DrahtBot removed the label Needs rebase on Mar 24, 2022
  121. vincenzopalazzo requested review from MarcoFalke on Mar 25, 2022
  122. vincenzopalazzo requested review from laanwj on Mar 25, 2022
  123. vincenzopalazzo force-pushed on Mar 25, 2022
  124. vincenzopalazzo force-pushed on Apr 4, 2022
  125. vincenzopalazzo force-pushed on Apr 26, 2022
  126. DrahtBot added the label Needs rebase on May 16, 2022
  127. vincenzopalazzo force-pushed on May 17, 2022
  128. DrahtBot removed the label Needs rebase on May 17, 2022
  129. vincenzopalazzo force-pushed on May 28, 2022
  130. DrahtBot added the label Needs rebase on Jun 8, 2022
  131. vincenzopalazzo force-pushed on Jun 10, 2022
  132. DrahtBot removed the label Needs rebase on Jun 10, 2022
  133. DrahtBot added the label Needs rebase on Jun 10, 2022
  134. vincenzopalazzo force-pushed on Jun 10, 2022
  135. DrahtBot removed the label Needs rebase on Jun 10, 2022
  136. DrahtBot added the label Needs rebase on Jun 17, 2022
  137. vincenzopalazzo force-pushed on Jul 2, 2022
  138. DrahtBot removed the label Needs rebase on Jul 2, 2022
  139. vincenzopalazzo force-pushed on Jul 3, 2022
  140. vincenzopalazzo force-pushed on Jul 5, 2022
  141. DrahtBot added the label Needs rebase on Jul 20, 2022
  142. tests: Use test utils each time that it is possible
    Also this commit introduce another utils function to tests assert_not_equal
    
    Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
    c42d3f912e
  143. feature_taproot: Introduce another assert called assert_true.
    Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
    cdf33588e5
  144. interface_zmq.py: Remove assert in favor of test utils functions
    Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
    e78b48e642
  145. feature_taproot: Fixed imports
    Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
    
    # Title: 
    
    Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
    
    # Title: 
    
    Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
    a570d2aff0
  146. mining_getblocktemplate_longpoll.py: Replace assert with assert_equal
    Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
    ad78974227
  147. p2p_addrfetch.py: Replace assert with assert_equal
    Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
    81e6f26881
  148. p2p_blockfilters.py: Replace assert with test utils function
    Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
    36cd2dc29e
  149. test framework: Adding possibility to specify messages in the assert functions
    Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
    a21ae03f12
  150. feature_taproot.py: Use the err_msg introduced in the assert framework.
    Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
    d6bc606366
  151. feature_taproot.py: Use the err_msg introduced in the assert framework.
    Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
    331816d5a8
  152. feature_taproot.py: Use the err_msg introduced in the assert framework.
    Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
    c5e4b28649
  153. interface_zmq.py: Refactoring message parameter with err_msg
    Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
    39dc7746a2
  154. p2p_compactblocks.py: Using test framework
    Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
    f968cfcb66
  155. p2p_getaddr_caching.py: Using test framework utils
    Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
    de2bf9999f
  156. p2p_disconnect_ban.py: Use test framework
    Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
    59bcf80e19
  157. p2p_invalid_messages.py: Use test framwork
    Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
    451785d524
  158. p2p_segwit.py: Including Test Framework
    Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
    59e5b11179
  159. p2p_tx_download.py: Use test framework.
    Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
    
    # Title: 
    
    Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
    5b8eb0aed6
  160. rpc_createmultisig.py: Use test framework
    Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
    0f1f81d3b3
  161. rpc_fundrawtransaction.py: Use test framework
    Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
    435a8d6d1f
  162. rpc_help.py: Use test framework
    Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
    f02998f6f9
  163. rpc_net.py: Using test frameowork
    Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
    cf9df57af7
  164. tool_wallet.py: Using test framework
    Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
    ca60e882e7
  165. wallet_address_types.py: using test framework
    Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
    3f585d248f
  166. wallet_disable.py: Use test framework
    Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
    92769d0fd2
  167. wallet_dump.py: Use test framework
    Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
    1d4e9c4021
  168. wallet_keypool.py: Use test framework
    Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
    d2bfd3d18d
  169. wallet_listdescriptors.py: Use test framework
    Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
    a85b6bc0e2
  170. wallet_listsinceblock.py: Use test framework
    Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
    75a122ec42
  171. wallet_listtransactions.py: Use test framework
    Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
    b0d26d5757
  172. wallet_txn_doublespend.py: Use test framwork
    Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
    1131437e95
  173. tests: fixed import order and improve python style
    Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
    9150da4791
  174. test_framework: improve error messages
    Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
    6229a1be2a
  175. interface_zmq.py: fixed `unexpected indent` introduced by rebase
    Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
    e5a6a54938
  176. fixed monkey rebase error
    Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
    62ed9fff45
  177. vincenzopalazzo force-pushed on Jul 28, 2022
  178. DrahtBot removed the label Needs rebase on Jul 28, 2022
  179. fanquake commented at 1:19 pm on October 3, 2022: member
    @vincenzopalazzo Given #25732, did you want to leave this one open as well, or close for now?
  180. vincenzopalazzo closed this on Oct 3, 2022

  181. vincenzopalazzo commented at 1:53 pm on October 3, 2022: none
    better close this and hope that someone will finish the job :)
  182. bitcoin locked this on Oct 3, 2023

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-12-23 00:13 UTC

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