test: test the result order of a multiple import request is correct

Co-Authored-By: Bicaru20 <bicaru2@gmail.com>
This commit is contained in:
Pol Espinasa
2026-07-01 13:25:15 +02:00
parent e4732bf018
commit 3ac8b806a6

View File

@@ -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__':