test: Use COINBASE_MATURITY in functional tests #21989

pull kiminuo wants to merge 2 commits into bitcoin:master from kiminuo:feature/2021-05-COINBASE_MATURE-in-functional-tests changing 47 files +135 −68
  1. kiminuo commented at 5:47 AM on May 18, 2021: contributor

    COINBASE_MATURITY constant was added to feature_nulldummy test in #21373. This PR moves the constant to blocktools.py file and uses the constant in more tests as suggested here.

    Edit: Goal of this PR is to replace integer constants with COINBASE_MATURITY but not necessarily in all cases because that would mean to read and fully understand all tests. That's out of my time constraints. Any reports where COINBASE_MATURITY should be used are welcome though!

  2. kiminuo renamed this:
    Feature/2021 05 coinbase mature in functional tests
    test: Use COINBASE_MATURITY in functional tests
    on May 18, 2021
  3. fanquake added the label Tests on May 18, 2021
  4. in test/functional/test_framework/blocktools.py:55 in b5e3de6de0 outdated
      51 | @@ -52,6 +52,9 @@
      52 |  # Genesis block time (regtest)
      53 |  TIME_GENESIS_BLOCK = 1296688602
      54 |  
      55 | +# Coinbase transaction outputs can only be spent after this number of new blocks (network rule)
    


    jonatack commented at 6:15 AM on May 18, 2021:

    If you like, there is a definition you can borrow elements from in test/functional/interface_bitcoin_cli.py:

    # The block reward of coinbaseoutput.nValue (50) BTC/block matures after
    # COINBASE_MATURITY (100) blocks. Therefore, after mining 101 blocks we expect
    # node 0 to have a balance of (BLOCKS - COINBASE_MATURITY) * 50 BTC/block.
    

    kiminuo commented at 8:39 PM on May 18, 2021:

    Thank you for bringing my attention to this file - I like the comment. Anyway, I think the current comment is reasonably good. If you think it can/should be improved, please suggest a better comment and I'll (most likely) accept it :)

  5. in test/functional/test_framework/blocktools.py:56 in b5e3de6de0 outdated
      51 | @@ -52,6 +52,9 @@
      52 |  # Genesis block time (regtest)
      53 |  TIME_GENESIS_BLOCK = 1296688602
      54 |  
      55 | +# Coinbase transaction outputs can only be spent after this number of new blocks (network rule)
      56 | +COINBASE_MATURITY = 100
    


    jonatack commented at 6:16 AM on May 18, 2021:

    The commit messages are written with COINBASE_MATURE instead of maturity


    kiminuo commented at 7:17 AM on May 18, 2021:

    You are right. Will fix.

  6. jonatack commented at 6:17 AM on May 18, 2021: member

    Maybe use a scripted diff for the second commit. I'm not sure you changed all the instances.

  7. kiminuo commented at 7:22 AM on May 18, 2021: contributor

    Maybe use a scripted diff for the second commit. I'm not sure you changed all the instances.

    My understanding of a scripted diff commit feature is that one does his changes, commits the changes using git and modifies the commit message to include a script that corresponds 1:1 with the changes in the commit. If this is correct, then I'm not really sure how to add Python imports in an automated way.

    Could you elaborate how would you add the scripted diff here? I have some ideas but none seems too appealing.

  8. jonatack commented at 7:28 AM on May 18, 2021: member
  9. jonatack commented at 7:31 AM on May 18, 2021: member

    Oh, you're right, adding the imports with a scripted diff would be complicated (at least for me it would). Feel free to ignore.

  10. theStack commented at 8:21 AM on May 18, 2021: member

    Concept ACK

  11. DrahtBot commented at 1:39 PM on May 18, 2021: member

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #21832 (cli: Improve -getinfo return format by klementtan)
    • #21178 (test: run mempool_reorg.py even with wallet disabled by DariusParvin)
    • #20892 (tests: Run both descriptor and legacy tests within a single test invocation by achow101)
    • #19888 (rpc, test: Improve getblockstats for unspendables by fjahr)

    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.

  12. kiminuo force-pushed on May 18, 2021
  13. kiminuo force-pushed on May 19, 2021
  14. kiminuo force-pushed on May 19, 2021
  15. in test/functional/feature_nulldummy.py:17 in 062016c8ab outdated
      13 | @@ -14,13 +14,12 @@
      14 |  """
      15 |  import time
      16 |  
      17 | -from test_framework.blocktools import NORMAL_GBT_REQUEST_PARAMS, create_block, create_transaction, add_witness_commitment
      18 | +from test_framework.blocktools import COINBASE_MATURITY, NORMAL_GBT_REQUEST_PARAMS, create_block, create_transaction, add_witness_commitment
    


    theStack commented at 10:01 AM on May 21, 2021:

    You could use the chance to change all lines that import the introduced constant to a lexicographically sorted multi-line import, which is now used in most functional tests (to avoid potential merge conflicts):

    from test_framework.blocktools import (
        COINBASE_MATURITY,
        NORMAL_GBT_REQUEST_PARAMS,
        add_witness_commitment,
        create_block,
        create_transaction,
    )
    

    (Note also the comma in the last line)


    kiminuo commented at 11:51 AM on May 21, 2021:

    I use VSCode. Can it do this for me? (or possibly PyCharm?) Or is it necessary to do this sorting by hand in general?


    theStack commented at 12:22 PM on May 21, 2021:

    Personally I don't have any experience with Python IDEs or code formatting tools (I'm using vim for both C++ and Python code) and also guess most other contributors do it by hand. In this specific PR, as far as I can see there is only a single instance where this is relevant anyway.


    kiminuo commented at 12:30 PM on May 21, 2021:

    I see. I was asking not because of the manual effort but to get some insight how others work to align my workflow. Thanks


    jonatack commented at 12:40 PM on May 21, 2021:

    I use VSCode. Can it do this for me? (or possibly PyCharm?) Or is it necessary to do this sorting by hand in general?

    IIRC black (the python liner) does it automatically for you.

    (I believe most contributors are using vim or non-IDEs. Suggest clang-format for the c++ and black/pycodestyle for the python)

  16. in test/functional/feature_assumevalid.py:35 in d539c897f8 outdated
      29 | @@ -30,6 +30,7 @@
      30 |        isn't buried by at least two weeks' work.
      31 |  """
      32 |  
      33 | +from test_framework.blocktools import COINBASE_MATURITY
      34 |  from test_framework.blocktools import (
      35 |      create_block,
    


    theStack commented at 11:42 AM on May 21, 2021:

    These two imports should be joined into one.


    kiminuo commented at 8:36 PM on May 27, 2021:

    Done, thank you.

  17. theStack commented at 11:45 AM on May 21, 2021: member

    Looks good to me, almost-ACK, left two small nit review comments.

  18. Move COINBASE_MATURITY from `feature_nulldummy` test to `blocktools`. 525448df9d
  19. kiminuo force-pushed on May 21, 2021
  20. mjdietzx commented at 4:49 PM on May 21, 2021: contributor

    Concept ACK

  21. sipa commented at 5:39 PM on May 21, 2021: member

    Concept ACK

  22. klementtan commented at 12:38 PM on May 24, 2021: contributor

    A search for 100 and 101 shows the following places that could also be possibly refactored to COINBASE_MATURITY:

    1. p2p_compactblocks.py#L118
    2. mempool_reorg.py#L47
    3. wallet_balance.py#L75
    4. p2p_eviction.py#L48
    5. wallet_address_types.py#L261
    6. wallet_importdescriptors.py#L76
    7. wallet_multiwallet.py#L232
    8. wallet_labels.py#L35

    I am still very new to the code base and might be wrong about them being related to coinbase maturity.

  23. kiminuo commented at 1:00 PM on May 24, 2021: contributor

    A search for 100 and 101 shows the following places that could also be possibly refactored to COINBASE_MATURITY:

    Thank you for researching this! I believe you are correct but I need to check those one by one. I will address this in coming days.

  24. kiminuo force-pushed on May 27, 2021
  25. in test/functional/p2p_compactblocks.py:17 in 15280a9743 outdated
      13 | +from test_framework.blocktools import (
      14 | +    COINBASE_MATURITY,
      15 | +    create_block,
      16 | +    NORMAL_GBT_REQUEST_PARAMS,
      17 | +    add_witness_commitment,
      18 | +)
    


    theStack commented at 9:25 PM on May 30, 2021:

    nit: import order

    from test_framework.blocktools import (
        COINBASE_MATURITY,
        NORMAL_GBT_REQUEST_PARAMS,
        add_witness_commitment,
        create_block,
    )
    

    kiminuo commented at 5:32 AM on May 31, 2021:

    Thank you

  26. Use COINBASE_MATURITY constant in functional tests. bfa9309ad6
  27. kiminuo force-pushed on May 31, 2021
  28. theStack approved
  29. theStack commented at 7:45 AM on May 31, 2021: member

    ACK bfa9309ad606102f24c9bd3c33dfe78949f09418 🌇

  30. MarcoFalke merged this on May 31, 2021
  31. MarcoFalke closed this on May 31, 2021

  32. kiminuo deleted the branch on May 31, 2021
  33. sidhujag referenced this in commit 7e95636c46 on Jun 1, 2021
  34. gwillen referenced this in commit 01b1d5f844 on Jun 1, 2022
  35. DrahtBot locked this on Aug 16, 2022

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-14 21:14 UTC

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