test: test the result order of a multiple import request is correct
What changed, and why it matters
This commit only adds a new automated test to Bitcoin Core. It checks that when a user asks the wallet to import multiple descriptors at once, the list of results comes back in the same order as the original request, including any error messages. There is no change to production wallet code, so this cannot directly affect live users or funds.
No security action required. Treat as ordinary test coverage improvement. If reviewing the related importdescriptors RPC implementation, consider whether the new test cases exercise edge conditions (whitespace in public keys, internal descriptors with labels) that deserve additional unit tests or documentation.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff adds a single test method, test_per_item_errors_are_reported_in_order, to test/functional/wallet_importdescriptors.py. The test builds a list of five descriptor import requests (some valid, some intentionally invalid), calls wallet.importdescriptors(descriptors), and asserts that each returned result matches the expected success flag and, on failure, the expected error message in the corresponding position. The new test is then registered in the main run_test method. No C++ or Python production logic is modified.
Changed components
test/functional/wallet_importdescriptors.pyInspect captured patch +40 / −0
diff --git a/test/functional/wallet_importdescriptors.py b/test/functional/wallet_importdescriptors.py
index 4597283f..bf6326f2 100755
--- a/test/functional/wallet_importdescriptors.py
+++ b/test/functional/wallet_importdescriptors.py
@@ -126,6 +126,45 @@ class ImportDescriptorsTest(BitcoinTestFramework):
wallet=wallet)
wallet.unloadwallet()
+ def test_per_item_errors_are_reported_in_order(self):
+ self.log.info("Test that import results are in the same order as the original request")
+ self.nodes[0].createwallet(wallet_name="test_order_import", blank=True)
+ wallet = self.nodes[0].get_wallet_rpc('test_order_import')
+ whitespace_pubkey = f" {get_generate_key().pubkey}"
+ cases = [
+ ({
+ "timestamp": "now"
+ }, [False, "Descriptor not found."]),
+ ({
+ "desc": descsum_create(f"pkh({get_generate_key().privkey})"),
+ "timestamp": 1,
+ "label": "Valid descriptor 1",
+ }, [True]),
+ ({
+ "desc": descsum_create(f"pkh({get_generate_key().privkey})"),
+ "timestamp": "now",
+ "internal": True,
+ }, [True]),
+ ({
+ "desc": descsum_create(f"pkh({get_generate_key().pubkey})"),
+ "timestamp": "now",
+ "label": "Invalid descriptor 2",
+ "internal": True,
+ }, [False, "Internal addresses should not have a label"]),
+ ({
+ "desc": descsum_create(f"pkh({whitespace_pubkey})"),
+ "timestamp": "now",
+ "internal": True,
+ }, [False, f"pkh(): Key '{whitespace_pubkey}' is invalid due to whitespace"]),
+ ]
+
+ descriptors, expected = map(list, zip(*cases))
+ results = wallet.importdescriptors(descriptors)
+ for i, result in enumerate(results):
+ assert_equal(result["success"], expected[i][0])
+ if not result["success"]:
+ assert_equal(result["error"]["message"], expected[i][1])
+
def test_rescan_fails_import(self):
xpriv = "tprv8ZgxMBicQKsPeuVhWwi6wuMQGfPKi9Li5GtX35jVNknACgqe3CY4g5xgkfDDJcmtF7o1QnxWDRYw4H5P26PXq7sbcUkEqeR4fg3Kxp2tigg"
@@ -995,6 +1034,7 @@ class ImportDescriptorsTest(BitcoinTestFramework):
self.test_import_unused_key()
self.test_import_unused_key_existing()
self.test_import_unused_noprivs()
+ self.test_per_item_errors_are_reported_in_order()
self.test_rescan_fails_import()
if __name__ == '__main__':
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.