test: added test coverage to loadtxoutset could not open file #30053

pull kevkevinpal wants to merge 1 commits into bitcoin:master from kevkevinpal:loadtxoutsetInvalidDumpPath changing 1 files +7 −0
  1. kevkevinpal commented at 9:32 PM on May 6, 2024: contributor

    The functional test coverage did not cover the rpc error of "Couldn't open file..." for loadtxoutset and this test adds coverage for it

    This adds coverage to this line https://github.com/bitcoin/bitcoin/blob/master/src/rpc/blockchain.cpp#L2777

  2. DrahtBot commented at 9:32 PM on May 6, 2024: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--006a51241073e994b41acfe9ec718e94-->

    Code Coverage

    For detailed information about the code coverage, see the test coverage report.

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK maflcko, rkrux, alfonsoromanz, tdb3, davidgumberg

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

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #29996 (test: Assumeutxo: import snapshot in a node with a divergent chain by alfonsoromanz)
    • #29428 (test: Assumeutxo: snapshots with less work should not be loaded by hernanmarino)

    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.

  3. DrahtBot added the label Tests on May 6, 2024
  4. test: added test coverage to loadtxoutset
    The functional test coverage did not cover the rpc error of Couldn't
    open file for loadtxoutset and this test adds coverage for it
    ee67bba76c
  5. kevkevinpal force-pushed on May 6, 2024
  6. maflcko commented at 5:18 AM on May 7, 2024: member

    ACK ee67bba76cca2355541f99bb731f58479981b29e

  7. in test/functional/feature_assumeutxo.py:158 in ee67bba76c
     151 | @@ -152,6 +152,12 @@ def test_invalid_mempool_state(self, dump_output_path):
     152 |  
     153 |          self.restart_node(2, extra_args=self.extra_args[2])
     154 |  
     155 | +    def test_invalid_file_path(self):
     156 | +        self.log.info("Test bitcoind should fail when file path is invalid.")
     157 | +        node = self.nodes[0]
     158 | +        path = node.datadir_path / node.chain / "invalid" / "path"
    


    rkrux commented at 10:34 AM on May 7, 2024:

    Got to learn about the functionality of the slash operator in case of Pathlib.Path! https://docs.python.org/3/library/pathlib.html#operators

  8. rkrux approved
  9. rkrux commented at 10:41 AM on May 7, 2024: contributor

    ACK ee67bba

    Make successful, unit and functional tests successful. Short and sweet!

  10. alfonsoromanz approved
  11. alfonsoromanz commented at 3:13 PM on May 7, 2024: contributor

    ACK ee67bba76cca2355541f99bb731f58479981b29e. Code looks good to me. I also ran test/functional/feature_assumeutxo.py to make sure all tests passes, including this one.

    <img width="471" alt="Screenshot 2024-05-07 at 12 07 04" src="https://github.com/bitcoin/bitcoin/assets/19962151/bbe9ced1-443d-43cc-9111-0e61e35fc7d6"> <img width="438" alt="Screenshot 2024-05-07 at 12 07 18" src="https://github.com/bitcoin/bitcoin/assets/19962151/36e2e6fb-39fa-4ec1-b25d-5247d7ded24d">

  12. in test/functional/feature_assumeutxo.py:159 in ee67bba76c
     151 | @@ -152,6 +152,12 @@ def test_invalid_mempool_state(self, dump_output_path):
     152 |  
     153 |          self.restart_node(2, extra_args=self.extra_args[2])
     154 |  
     155 | +    def test_invalid_file_path(self):
     156 | +        self.log.info("Test bitcoind should fail when file path is invalid.")
     157 | +        node = self.nodes[0]
     158 | +        path = node.datadir_path / node.chain / "invalid" / "path"
     159 | +        assert_raises_rpc_error(-8, "Couldn't open file {} for reading.".format(path), node.loadtxoutset, path)
    


    tdb3 commented at 2:26 AM on May 8, 2024:

    Minor nit: Style guidelines prefer f'{}'. (https://github.com/bitcoin/bitcoin/blob/master/test/functional/README.md#style-guidelines)

    e.g.

    diff --git a/test/functional/feature_assumeutxo.py b/test/functional/feature_assumeutxo.py
    index a65a11a9b5..47f87297f3 100755
    --- a/test/functional/feature_assumeutxo.py
    +++ b/test/functional/feature_assumeutxo.py
    @@ -156,7 +156,7 @@ class AssumeutxoTest(BitcoinTestFramework):
             self.log.info("Test bitcoind should fail when file path is invalid.")
             node = self.nodes[0]
             path = node.datadir_path / node.chain / "invalid" / "path"
    -        assert_raises_rpc_error(-8, "Couldn't open file {} for reading.".format(path), node.loadtxoutset, path)
    +        assert_raises_rpc_error(-8, f"Couldn't open file {path} for reading.", node.loadtxoutset, path)
     
         def run_test(self):
             """
    

    maflcko commented at 7:27 AM on May 8, 2024:

    With 5 ACKs this nit does not seem worth it to address at this point. Can do in one of the other pulls that touch this file, in a follow-up?

  13. tdb3 commented at 2:31 AM on May 8, 2024: contributor

    ACK for ee67bba76cca2355541f99bb731f58479981b29e

    Thank you for increasing test coverage. Ran a sanity check that created the .../invalid/path file from dumptxoutset and the test failed (as expected). Left a minor nit.

  14. davidgumberg commented at 3:03 AM on May 8, 2024: contributor

    LGTM ACK https://github.com/bitcoin/bitcoin/pull/30053/commits/ee67bba76cca2355541f99bb731f58479981b29e

    This PR improves coverage of the loadtxoutset rpc, I tested by removing the error throw from blockchain.cpp and verifying that the test complains:

     FILE* file{fsbridge::fopen(path, "rb")};
     AutoFile afile{file};
     if (afile.IsNull()) {
    -    throw JSONRPCError(
    -        RPC_INVALID_PARAMETER,
    -        "Couldn't open file " + path.utf8string() + " for reading.");
     }
    

    +1 to @tdb3 style nit above

    I thought for a bit about whether or not we should also check files with invalid path names or bad permissions, but I think this check sufficiently demonstrates that if a file passed to loadtxoutset cannot be opened for any reason at all, an error will be thrown.

  15. fanquake merged this on May 8, 2024
  16. fanquake closed this on May 8, 2024

  17. Fabcien referenced this in commit dc73f741fa on Apr 17, 2025
  18. bitcoin locked this on May 8, 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-04-15 15:13 UTC

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