Merge 27d7b11e8c into merged_master (Bitcoin PR bitcoin/bitcoin#25106)

This commit is contained in:
James Dorfman 2024-08-09 17:48:02 +00:00
commit 3eb8d9b89e
2 changed files with 11 additions and 1 deletions

View file

@ -2531,6 +2531,12 @@ static RPCHelpMan dumptxoutset()
FILE* file{fsbridge::fopen(temppath, "wb")};
CAutoFile afile{file, SER_DISK, CLIENT_VERSION};
if (afile.IsNull()) {
throw JSONRPCError(
RPC_INVALID_PARAMETER,
"Couldn't open file " + temppath.u8string() + " for writing.");
}
NodeContext& node = EnsureAnyNodeContext(request.context);
UniValue result = CreateUTXOSnapshot(
node, node.chainman->ActiveChainstate(), afile, path, temppath);

View file

@ -49,9 +49,13 @@ class DumptxoutsetTest(BitcoinTestFramework):
out['txoutset_hash'], 'd01f8e9fd78d25418c071d592b207d09dbdf462a11963850ae80d387a414b235')
assert_equal(out['nchaintx'], 101)
# Specifying a path to an existing file will fail.
# Specifying a path to an existing or invalid file will fail.
assert_raises_rpc_error(
-8, '{} already exists'.format(FILENAME), node.dumptxoutset, FILENAME)
invalid_path = str(Path(node.datadir) / "invalid" / "path")
assert_raises_rpc_error(
-8, "Couldn't open file {}.incomplete for writing".format(invalid_path), node.dumptxoutset, invalid_path)
if __name__ == '__main__':
DumptxoutsetTest().main()