test: fix TestShell initialization and reset() #31415

pull BrandonOdiwuor wants to merge 1 commits into bitcoin:master from BrandonOdiwuor:testshell-fix changing 2 files +13 −9
  1. BrandonOdiwuor commented at 5:03 PM on December 3, 2024: contributor

    Fixes TestShell initialization issues caused by resolving symlinks and looking for config.ini in the source path instead of the build path after migration to CMake (see #31131 (comment))

    https://github.com/bitcoin/bitcoin/blob/ebe4cac38bf6c510b00b8e080acab079c54016d6/test/functional/test_framework/test_shell.py#L77 also fixes #31131

    How to test:

    $ python3
    >>> import sys
    >>> sys.path.insert(0, "./path/to/bitcoin/build/test/functional")
    >>> from test_framework.test_shell import TestShell
    >>> TestShell().setup(num_nodes=2, setup_clean_chain=True)
    >>> TestShell().shutdown()
    >>> TestShell.reset()
    
  2. pinheadmz approved
  3. pinheadmz commented at 4:41 PM on December 16, 2024: member

    ACK 20d46f30232ddeb92b6158aa1240be065fb2f8c4

    Confirmed the issue and the fix.

    Tested with:

    #!/usr/bin/env python3
    
    # USAGE: shell.py /path/to/bitcoin/repo
    
    from pathlib import Path
    import sys
    REPO = Path(sys.argv.pop())
    sys.path.insert(0, f"{REPO / 'build' / 'test' / 'functional'}")
    from test_framework.test_shell import TestShell
    
    TestShell().setup(num_nodes=1, setup_clean_chain=True)
    TestShell().shutdown()
    

    <details><summary>Show Signature</summary>

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA256
    
    ACK 20d46f30232ddeb92b6158aa1240be065fb2f8c4
    -----BEGIN PGP SIGNATURE-----
    
    iQIzBAEBCAAdFiEE5hdzzW4BBA4vG9eM5+KYS2KJyToFAmdgWAMACgkQ5+KYS2KJ
    yTrzgQ//fY//TeYh+OmwVlUQqdaQm15OyCwnBYVbIS0INzIgzQ36pXWVPDmRuThC
    cCRZTPRFlCklqYnuDEEtTTxrUbTWdAiXbbQI7fYiY+ZtwIHss+I/jlK8DuEHrWqP
    mp+R7nVn4zWjYlli6Aytqg0vfkSRVMH/gzCSnL5qvt+bBAyworeWjYhG6WrdlOr5
    ViPP6uHR/KOLgVewZvIv5h+BSgBOhWhy5eQzU8lL2rS9NpBlEmlzgExnMRmdTQzQ
    azwQ2UyXvkvkjq430dQxZblL0Zcyxu4xzU3I11FR61QV9yloxomCQGJr8XAI90/g
    M8fJ07CO6TKVc4AYfyPogh+cPEN4VAeMvmbTrY2TF+LxCY4qFuKdXgafaRGPdHsk
    A3cDmKgn81Ys/zVdUXQ0k74r6Q2Ysaq2hf2dDghRlY5eWwZn3JWesfwIJRd/wQBj
    mu9uLiq2Ju0o1g2mLgejPe68GFMipyIExWHxlqsOogSkBOOZOZUdKIUjndn1YXZ4
    UtX9ttXASkRLizCHYcAlCG9K6Wzx/TmN6oRCBJJI11cqM1C/dV6GnA8+1PZmHLO1
    3H0zSa4wUDbqMiHuzJMEht8jawu+Hx1lUSJCc3lSAlwzBAL47B5eMkOTJxKz0sfs
    8Q5E8Nutwol+HLrcqWwUZ8UcgRADQX3KOF0HYWH2huw5rz6FWrc=
    =LVv/
    -----END PGP SIGNATURE-----
    

    pinheadmz's public key is on keybase

    </details>

  4. DrahtBot commented at 4:41 PM on December 16, 2024: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--006a51241073e994b41acfe9ec718e94-->

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/31415.

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK pinheadmz, theStack, pablomartin4btc

    If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

  5. pinheadmz commented at 4:46 PM on December 16, 2024: member

    You also might want to include a note in the docs like I did in #31510 since there are two test_framework directories after building now

  6. BrandonOdiwuor force-pushed on Dec 18, 2024
  7. BrandonOdiwuor requested review from pinheadmz on Dec 18, 2024
  8. BrandonOdiwuor commented at 4:59 AM on December 18, 2024: contributor

    @pinheadmz updated the test-shell doc

  9. pinheadmz approved
  10. pinheadmz commented at 3:47 PM on December 18, 2024: member

    re-ACK 318b2a2f90dfd8ae20beca58e55e6d240a7f3d27

    Docs updated since last ack, good improvement thank you!

    <details><summary>Show Signature</summary>

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA256
    
    ACK 318b2a2f90dfd8ae20beca58e55e6d240a7f3d27
    -----BEGIN PGP SIGNATURE-----
    
    iQIzBAEBCAAdFiEE5hdzzW4BBA4vG9eM5+KYS2KJyToFAmdi7l8ACgkQ5+KYS2KJ
    yTpK9A/+NJ4FSYMIQ313zWaQddHHYt2bcEY6veHmP0jeFhLOTi7Wx/sLIQSr9qN6
    y8LjMXUu1+1P7PEAjQWVj+TYMapEb5SizZsDLD42J3YWz4648cUap+kgfqTQxoi2
    aO+FMfjhwND6V7Cjo4lgKdHG7HYQRg8hLzGMMnOktKs2q2+DPv423fJQnh6q8F+F
    m81dX/4ftiGYzRrffjY8zMC2NIqZlZYQ6eEmdPmtL8pmVVvFm7OKtNKqUgXbnlYj
    ZCc0d9CjEXkPjvq5EfUWJtCBaZ7DfGyGO1UeK0kw/zKLAaAmjmS+S3wSAEGdOI5T
    w5WiiDzX/lkdHtPD6YoQ2JiEyQ3mabcL0AuHEQs7MIPNMh2VQlQriEYDA7hlRssi
    MvYEZwIQp9XmdG1YAQKYhGExqR8QPyTegX5vgeXc2xfKQsX01ioOFxCY8BdQgc2Y
    SRZZVx/T1xRM1Z7hSE0skI25VE/W3L6xeVozBIKpsZWubfMYjT1bbFG4eBohmpGU
    +9hIYQ1PHmF675Y3jlwSzRT0GVqJ2hiZo42aeA4LodOOLJwQJZYGSvg5+i7AzkE5
    dL5cpq178dUjsTONtAQuKgbLtWWiJqS+hzB1ZkVNjHCoAjpIlFXewcS3X1o3Os61
    c8Zs7lrs+P3dMZ2a85Shg6oYBE3/nPzwEI+Gq/8ZnFRkQA2yHS8=
    =Je0g
    -----END PGP SIGNATURE-----
    

    pinheadmz's public key is on keybase

    </details>

  11. in test/functional/test-shell.md:36 in 318b2a2f90 outdated
      34 | +must be used.
      35 |  
      36 |  ```
      37 |  >>> import sys
      38 | ->>> sys.path.insert(0, "/path/to/bitcoin/test/functional")
      39 | +>>> sys.path.insert(0, "/path/to/bitcoin/build/test/functional")
    


    l0rinc commented at 3:21 PM on December 20, 2024:

    there are many other instances of bitcoin/test in the doc, could you please adjust the rest as well?


    BrandonOdiwuor commented at 12:27 PM on February 20, 2025:

    fixed the remaining instances

  12. in test/functional/test_framework/test_shell.py:12 in 318b2a2f90 outdated
       6 | @@ -7,6 +7,14 @@
       7 |  from test_framework.test_framework import BitcoinTestFramework
       8 |  
       9 |  
      10 | +# BitcoinTestFramework instances are supposed to be constructed with the path
      11 | +# of the calling test in order to find shared data like configuration and the
      12 | +# cache. Since TestShell is meant for interactive use, there is no concrete
    


    l0rinc commented at 3:29 PM on December 20, 2024:

    Now that it's moved out of TestShell this (slightly awkward) comment should likely be updated.


    BrandonOdiwuor commented at 12:30 PM on February 20, 2025:

    reverted the extraction of dummy_testshell_file to avoid global variables

  13. in test/functional/test_framework/test_shell.py:16 in 318b2a2f90 outdated
      11 | +# of the calling test in order to find shared data like configuration and the
      12 | +# cache. Since TestShell is meant for interactive use, there is no concrete
      13 | +# test; passing a dummy name is fine though, as only the containing directory
      14 | +# is relevant for successful initialization.
      15 | +tests_directory = pathlib.Path(__file__).absolute().parent.parent
      16 | +dummy_testshell_file = tests_directory / "testshell_dummy.py"
    


    l0rinc commented at 3:30 PM on December 20, 2024:

    Q: I'm not sure I understand the reason for extraction, can you please clarify that?

    Nit: We're adding another global here which pollutes the namespace, can we rather inline it?

    dummy_testshell_file = pathlib.Path(__file__).absolute().parent.parent / "testshell_dummy.py"
    

    BrandonOdiwuor commented at 12:32 PM on February 20, 2025:

    The reason for the extraction was to share the variable with the reset function, I have however reverted the extraction to avoid using global variables

  14. in test/functional/test_framework/test_shell.py:71 in 318b2a2f90 outdated
      74 |  
      75 |      instance = None
      76 |  
      77 |      def __new__(cls):
      78 |          # This implementation enforces singleton pattern, and will return the
      79 |          # previously initialized instance if available
    


    l0rinc commented at 3:35 PM on December 20, 2024:

    useless comment, the code already makes this obvious


    BrandonOdiwuor commented at 12:34 PM on February 20, 2025:

    I have reverted the extraction, is this still worth removing?

  15. l0rinc commented at 3:38 PM on December 20, 2024: contributor

    I wanted to see what the π pull request contains, ended up reviewing it. Could you please specify in the description of how the reviewers should test the code and why the extraction was necessary besides the absolute file computation?

  16. pablomartin4btc commented at 4:42 PM on February 19, 2025: member

    tACK 318b2a2f90dfd8ae20beca58e55e6d240a7f3d27

    <details> <summary>I've managed to reproduce the issue in <code>master</code> and this PR fixes it.</summary>

    • script:
    cat shell.py 
    from pathlib import Path
    import sys
    REPO = Path(sys.argv.pop())
    sys.path.insert(0, f"{REPO / 'build' / 'test' / 'functional'}")
    from test_framework.test_shell import TestShell
    
    TestShell().setup(num_nodes=1, setup_clean_chain=True)
    TestShell().shutdown()
    
    • master run:
    
    python3 shell.py .
    Traceback (most recent call last):
      File "/home/pablo/workspace/bitcoin/shell.py", line 7, in <module>
        TestShell().setup(num_nodes=1, setup_clean_chain=True)
      File "/home/pablo/workspace/bitcoin/build/test/functional/test_framework/test_shell.py", line 78, in __new__
        TestShell.instance = TestShell.__TestShell(tests_directory / "testshell_dummy.py")
      File "/home/pablo/workspace/bitcoin/build/test/functional/test_framework/test_framework.py", line 106, in __init__
        self.parse_args(test_file)
      File "/home/pablo/workspace/bitcoin/build/test/functional/test_framework/test_framework.py", line 221, in parse_args
        config.read_file(open(self.options.configfile))
    FileNotFoundError: [Errno 2] No such file or directory: '/home/pablo/workspace/bitcoin/test/config.ini'
    
    • BrandonOdiwuor:testshell-fix run:
    
    python3 shell.py .
    2025-02-19T16:24:08.067000Z TestFramework (INFO): PRNG seed is: 5076166937161550343
    2025-02-19T16:24:08.067000Z TestFramework (INFO): Initializing test directory /tmp/bitcoin_func_test_9e2y3t09
    2025-02-19T16:24:08.374000Z TestFramework (INFO): Stopping nodes
    2025-02-19T16:24:08.525000Z TestFramework (INFO): Cleaning up /tmp/bitcoin_func_test_9e2y3t09 on exit
    2025-02-19T16:24:08.525000Z TestFramework (INFO): Tests successful
    

    </details> [@BrandonOdiwuor](/bitcoin-bitcoin/contributor/brandonodiwuor/) please address pending feedback when's possible. Thanks!

  17. BrandonOdiwuor force-pushed on Feb 20, 2025
  18. DrahtBot added the label Tests on Feb 20, 2025
  19. test: fix TestShell initialization and reset() 303f8cca05
  20. BrandonOdiwuor force-pushed on Feb 20, 2025
  21. BrandonOdiwuor commented at 12:38 PM on February 20, 2025: contributor

    @l0rinc I have added instructions on how to test on the PR description

    The reason for the extraction of the dummy_testshell_file initially was to share it with the reset() function to fix #31131, I have however reverted the change to avoid using global variable

  22. BrandonOdiwuor requested review from l0rinc on Feb 20, 2025
  23. BrandonOdiwuor requested review from pinheadmz on Feb 20, 2025
  24. BrandonOdiwuor requested review from pablomartin4btc on Feb 20, 2025
  25. pinheadmz approved
  26. pinheadmz commented at 4:25 PM on February 20, 2025: member

    ACK 303f8cca0568d2ca77189c4eccdfc7a6913c958d

    Reviewed changes since last ACK, re-reviewed all changes, tested locally by creating a TestShell and sending RPC commands

    <details><summary>Show Signature</summary>

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA256
    
    ACK 303f8cca0568d2ca77189c4eccdfc7a6913c958d
    -----BEGIN PGP SIGNATURE-----
    
    iQIzBAEBCAAdFiEE5hdzzW4BBA4vG9eM5+KYS2KJyToFAme3V0wACgkQ5+KYS2KJ
    yTqd1xAA1DppfrHcaHcdKp/HnsicUqMslnuQ6sKFoQK76EYEsQFTyjJi2QDno8iB
    g4LI7wpfse3f6hYDuMn13joXmQ26wdlG/cV3r8RsquWMnxSoNoyJ2R8a8lZRehym
    KxwDPivyfgOJPcU+iFERHBLy9eVKZH4n0n8nYtRElVncYoUbnMGvxDJ56aOmh6zw
    VI6NOpbgm0XBcokzvvThNR9zvU5PCJnzWKVR8YT8q7+fKN58EzMgu4M+54XFpMUS
    eX0ObFQl4zURKLCdSxfm3rtwLDCdsUplxNixEJZ2qRHk5yYD6cqTQrbW8M3EpRrI
    8d8NNFYWb5ELDnHU+jVwaK1J9DSydoVmf33pwo9Mlj7/vTIM04d6HA+P7HF4x5vs
    Li+RRssSonSCM+gWwkS47J1dq1rkSp5YhK+3s9PZ49tLA4NI3QTONdzbdCZY9VDu
    x2Ccu9bHKombfwo+gbWYm6nv6bVXNZ8ocyTMuWi20xSUVJxQ0KPerGPCSEWQSBOC
    mv+kUQ2m7KJRWdh1Bf6V2muLELI9q/fRzAkVvetX9zG3M6QSEBJIXA/QHKvtC2gw
    MZWZe8rraNBLDQSukQsrxrPJ51SIvE1EoP9A/BND570b+vcC/aE62nzBGf2K+GJv
    rxign/38TrWNSVBCu0gVbHc4Wb2wW5936pOKI0VDMs/wSvBxvv8=
    =BuD1
    -----END PGP SIGNATURE-----
    

    pinheadmz's public key is on openpgp.org

    </details>

  27. fanquake commented at 7:48 PM on February 20, 2025: member

    @willcl-ark want to take a look here?

  28. theStack approved
  29. theStack commented at 10:16 PM on February 21, 2025: contributor

    Tested ACK 303f8cca0568d2ca77189c4eccdfc7a6913c958d

  30. pablomartin4btc approved
  31. pablomartin4btc commented at 5:01 PM on February 24, 2025: member

    re-ACK 303f8cca0568d2ca77189c4eccdfc7a6913c958d

    (reviewed changes since last ACK: update to build/test paths & reverted global var move)

  32. fanquake merged this on Feb 25, 2025
  33. fanquake closed this on Feb 25, 2025


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-05-02 21:12 UTC

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