Skip to content

Commit ddbddc8

Browse files
committed
BIP-352: test vectors: allow to check found output count for receiving
Introduce an optional "n_outputs" field as alternative to the detailed "outputs" objects (the field was already specified, but not used so far). Also update the documentation of the fields.
1 parent 8f7adfd commit ddbddc8

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

bip-0352.mediawiki

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,15 +422,15 @@ A [[bip-0352/send_and_receive_test_vectors.json|collection of test vectors in JS
422422
},
423423
"expected": {
424424
"addresses": [<array of bech32m strings, one for the silent payment address and each labeled address (if used)>],
425-
"outputs": [<array of outputs with tweak and signature; contains all possible output sets, tester must match a subset of size `n_outputs`>
425+
"outputs": [<optional array of outputs with tweak and signature, tester must match this set (alternatively, "n_outputs" can be specified)>
426426
{
427427
"priv_key_tweak": <hex encoded private key tweak data>,
428428
"pub_key": <hex encoded X-only public key>,
429429
"signature": <hex encoded signature for the output (produced with spend_priv_key + priv_key_tweak)>
430430
},
431431
...
432432
],
433-
"n_outputs": <integer for the exact number of expected outputs>
433+
"n_outputs": <optional integer for the number of expected found outputs (alternative to "outputs")>
434434
}
435435
}
436436

bip-0352/reference.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,9 +367,14 @@ def scanning(b_scan: ECKey, B_spend: ECPubKey, A_sum: ECPubKey, input_hash: byte
367367
# same sender but with different labels. Because of this, expected["outputs"] contains all possible valid output sets,
368368
# based on all possible permutations of recipient address orderings. Must match exactly one of the possible found output
369369
# sets in expected["outputs"]
370-
generated_set = {frozenset(d.items()) for d in add_to_wallet}
371-
expected_set = {frozenset(d.items()) for d in expected["outputs"]}
372-
assert generated_set == expected_set, "Receive test failed"
370+
if "outputs" in expected: # detailed check against expected outputs
371+
generated_set = {frozenset(d.items()) for d in add_to_wallet}
372+
expected_set = {frozenset(d.items()) for d in expected["outputs"]}
373+
assert generated_set == expected_set, "Receive test failed"
374+
elif "n_outputs" in expected: # only check the number of found outputs
375+
assert len(add_to_wallet) == expected["n_outputs"], "Receive test failed"
376+
else:
377+
assert False, "either 'outputs' or 'n_outputs' must be specified in 'expected' field of receiving test vector"
373378

374379

375380
print("All tests passed")

0 commit comments

Comments
 (0)