Since the main goal here is to check that the results are returned in the same order as passed in the request, I think we should check the error messages rather than wheter if it was successfull or not. The way we are currently doing it, if the descriptors that must fail get swapped with each other, the test will still pass. Checking the returned error messages would also catch that case.
The same applies to the descriptors that are expected to succeed. If those get swapped, we won't be able to detect it either. However, in that case, I don't think there is a way to solve this..
succes_cases = [
({
"desc": descsum_create(f"pkh({get_generate_key().privkey})"),
"timestamp": 1,
"label": "Valid descriptor1",
}, True),
({
"desc": descsum_create(f"pkh({get_generate_key().privkey})"),
"timestamp": "now",
"internal": True,
}, True),
]
descriptors, expected = map(list, zip(*succes_cases))
result = wallet.importdescriptors(descriptors)
assert_equal([r["success"] for r in result], expected)
whitespace_pubkey = f" {get_generate_key().pubkey}"
failed_cases = [
({
"timestamp": "now"
}, 'Descriptor not found.'),
({
"desc": descsum_create(f"pkh({get_generate_key().pubkey})"),
"timestamp": "now",
"label": "Invalid descriptor 2",
"internal": True,
}, 'Internal addresses should not have a label'),
({
"desc": descsum_create(f"pkh({whitespace_pubkey})"),
"timestamp": "now",
"internal": True,
}, f"pkh(): Key '{whitespace_pubkey}' is invalid due to whitespace"),
]
descriptors, errors = map(list, zip(*failed_cases))
result = wallet.importdescriptors(descriptors)
for r,err in zip(result, errors):
assert_equal(r["success"], False)
assert_equal(r["error"]["message"], err)