-
Notifications
You must be signed in to change notification settings - Fork 37.7k
test: added test coverage to loadtxoutset could not open file #30053
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: added test coverage to loadtxoutset could not open file #30053
Conversation
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code CoverageFor detailed information about the code coverage, see the test coverage report. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. ConflictsReviewers, this pull request conflicts with the following ones:
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. |
The functional test coverage did not cover the rpc error of Couldn't open file for loadtxoutset and this test adds coverage for it
4693e5e
to
ee67bba
Compare
ACK ee67bba |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK ee67bba
Make successful, unit and functional tests successful.
Short and sweet!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK ee67bba. Code looks good to me. I also ran test/functional/feature_assumeutxo.py
to make sure all tests passes, including this one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK for ee67bba
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.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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):
"""
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
LGTM ACK ee67bba This PR improves coverage of the 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.");
} 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 |
Summary: This is a partial backport of [[bitcoin/bitcoin#27596 | core#27596]], [[bitcoin/bitcoin#28652 | core#28652]], [[bitcoin/bitcoin#29345 | core#29345]], [[bitcoin/bitcoin#28589 | core#28589]], [[bitcoin/bitcoin#28590 | core#28590]], [[bitcoin/bitcoin#28625 | core#28625]], [[bitcoin/bitcoin#28639 | core#28639]], [[bitcoin/bitcoin#28647 | core#28647]], [[bitcoin/bitcoin#28562 | core#28562]], [[bitcoin/bitcoin#28666 | core#28666]], [[bitcoin/bitcoin#28669 | core#28669]], [[bitcoin/bitcoin#28685 | core#28685]], [[bitcoin/bitcoin#29215 | core#29215]], [[bitcoin/bitcoin#29726 | core#29726]], [[bitcoin/bitcoin#29354 | core#29354]], [[bitcoin/bitcoin#29394 | core#29394]], [[bitcoin/bitcoin#29478 | core#29478]], [[bitcoin/bitcoin#29370 | core#29370]], [[bitcoin/bitcoin#29617 | core#29617]], [[bitcoin/bitcoin#28685 | core#28685]], [[bitcoin/bitcoin#30053 | core#30053]], [[bitcoin/bitcoin#29973 | core#29973]], [[bitcoin/bitcoin#28838 | core#28838]], [[bitcoin/bitcoin#29354 | core#29354]], [[bitcoin/bitcoin#29478 | core#29478]], [[bitcoin/bitcoin#30678 | core#30678]], [[bitcoin/bitcoin#31556 | core#31556]] and [[bitcoin/bitcoin#30909 | core#30909]] Depends on D17945 ------ rpc: add loadtxoutset Co-authored-by: Sebastian Falbesoner <sebastian.falbesoner@gmail.com> bitcoin/bitcoin@ce585a9 [[bitcoin/bitcoin#28652 | core#28652]] [[bitcoin/bitcoin#29345 | core#29345]] ------ rpc: add getchainstates Co-authored-by: Ryan Ofsky <ryan@ofsky.org> bitcoin/bitcoin@0f64bac bitcoin/bitcoin@a9ef702 ---- test: add feature_assumeutxo functional test Initial commit: bitcoin/bitcoin@42cae39 [[bitcoin/bitcoin#28589 | core#28589]] (race fixes) [[bitcoin/bitcoin#28590 | core#28590]] (getchainstates return a list of chainstates) [[bitcoin/bitcoin#28625 | core#28625]] ( check that loading snapshot not matching AssumeUTXO parameters fails) bitcoin/bitcoin@fafde92 [[bitcoin/bitcoin#28647 | core#28647]] (Add assumeutxo test for wrong hash) [[bitcoin/bitcoin#28652 | core#28652]] (fail early if snapshot block hash doesn't match AssumeUTXO parameters) [[bitcoin/bitcoin#28562 | core#28562]] (`self.no_op`, `self.wait_until`) [[bitcoin/bitcoin#28666 | core#28666]] (assumeutxo file with unknown block hash) [[bitcoin/bitcoin#28669 | core#28669]] (check au file with changed outpoint index) [[bitcoin/bitcoin#28685 | core#28685]] (add tests for coin maleation) [[bitcoin/bitcoin#29215 | core#29215]] (spend coin from snapshot chainstate after loading) bitcoin/bitcoin@b7ba60f (add coverage for -reindex and assumeutxo) [[bitcoin/bitcoin#29354 | core#29354]] (Assumeutxo with more than just coinbase transactions) [[bitcoin/bitcoin#29394 | core#29394]] (Add test to ensure failure when mempool not empty) bitcoin/bitcoin@2bc1ecf (Remove unnecessary sync_blocks in assumeutxo tests) [[bitcoin/bitcoin#29478 | core#29478]] (Add test for loadtxoutset when headers are not synced) [[bitcoin/bitcoin#29370 | core#29370]] (RPC test for fake nTx and nChainTX values, stale block CheckBlockIndex crash test & assumeutxo snapshot block CheckBlockIndex crash test) [[bitcoin/bitcoin#29617 | core#29617]] (test for coin_height > base_height & amount > money_supply) bitcoin/bitcoin@f621392 (Check deserialized coins for out of range values) [[bitcoin/bitcoin#30053 | core#30053]] (coverage for "Couldn't open file..." error) [[bitcoin/bitcoin#29973 | core#29973]] (ensure failure when importing a snapshot twice) ------ test: add assumeutxo wallet test initial commit: [[bitcoin/bitcoin#28838 | core#28838]] bitcoin/bitcoin@fa5cd66 (Assumeutxo with more than just coinbase transactions) bitcoin/bitcoin@2bc1ecf (Remove unnecessary sync_blocks in assumeutxo tests) bitcoin/bitcoin@7e3dbe4 (functional test only) bitcoin/bitcoin@f20fe33 (Add basic balance coverage) bitcoin/bitcoin@bc43eca (test for balance after snapshot completion) bitcoin/bitcoin@595edee (import descriptors during background sync) Test Plan: `ninja all check-all` Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Subscribers: Fabien Differential Revision: https://reviews.bitcoinabc.org/D17931
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