From f14132fc770227dde52ad2d812b1efe84b59a89e Mon Sep 17 00:00:00 2001 From: Sebastian Falbesoner Date: Thu, 26 Feb 2026 20:40:33 +0100 Subject: [PATCH] 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. --- bip-0352.mediawiki | 4 ++-- bip-0352/reference.py | 11 ++++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/bip-0352.mediawiki b/bip-0352.mediawiki index 508b801a..856a23d9 100644 --- a/bip-0352.mediawiki +++ b/bip-0352.mediawiki @@ -422,7 +422,7 @@ A [[bip-0352/send_and_receive_test_vectors.json|collection of test vectors in JS }, "expected": { "addresses": [], - "outputs": [ + "outputs": [ { "priv_key_tweak": , "pub_key": , @@ -430,7 +430,7 @@ A [[bip-0352/send_and_receive_test_vectors.json|collection of test vectors in JS }, ... ], - "n_outputs": + "n_outputs": } } diff --git a/bip-0352/reference.py b/bip-0352/reference.py index cab3972f..394fcc4d 100755 --- a/bip-0352/reference.py +++ b/bip-0352/reference.py @@ -367,9 +367,14 @@ if __name__ == "__main__": # same sender but with different labels. Because of this, expected["outputs"] contains all possible valid output sets, # based on all possible permutations of recipient address orderings. Must match exactly one of the possible found output # sets in expected["outputs"] - generated_set = {frozenset(d.items()) for d in add_to_wallet} - expected_set = {frozenset(d.items()) for d in expected["outputs"]} - assert generated_set == expected_set, "Receive test failed" + if "outputs" in expected: # detailed check against expected outputs + generated_set = {frozenset(d.items()) for d in add_to_wallet} + expected_set = {frozenset(d.items()) for d in expected["outputs"]} + assert generated_set == expected_set, "Receive test failed" + elif "n_outputs" in expected: # only check the number of found outputs + assert len(add_to_wallet) == expected["n_outputs"], "Receive test failed" + else: + assert False, "either 'outputs' or 'n_outputs' must be specified in 'expected' field of receiving test vector" print("All tests passed")