mirror of
https://github.com/bitcoin/bips.git
synced 2026-03-30 16:06:44 +00:00
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.
This commit is contained in:
@@ -422,7 +422,7 @@ A [[bip-0352/send_and_receive_test_vectors.json|collection of test vectors in JS
|
|||||||
},
|
},
|
||||||
"expected": {
|
"expected": {
|
||||||
"addresses": [<array of bech32m strings, one for the silent payment address and each labeled address (if used)>],
|
"addresses": [<array of bech32m strings, one for the silent payment address and each labeled address (if used)>],
|
||||||
"outputs": [<array of outputs with tweak and signature; contains all possible output sets, tester must match a subset of size `n_outputs`>
|
"outputs": [<optional array of outputs with tweak and signature, tester must match this set (alternatively, "n_outputs" can be specified)>
|
||||||
{
|
{
|
||||||
"priv_key_tweak": <hex encoded private key tweak data>,
|
"priv_key_tweak": <hex encoded private key tweak data>,
|
||||||
"pub_key": <hex encoded X-only public key>,
|
"pub_key": <hex encoded X-only public key>,
|
||||||
@@ -430,7 +430,7 @@ A [[bip-0352/send_and_receive_test_vectors.json|collection of test vectors in JS
|
|||||||
},
|
},
|
||||||
...
|
...
|
||||||
],
|
],
|
||||||
"n_outputs": <integer for the exact number of expected outputs>
|
"n_outputs": <optional integer for the number of expected found outputs (alternative to "outputs")>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -367,9 +367,14 @@ if __name__ == "__main__":
|
|||||||
# same sender but with different labels. Because of this, expected["outputs"] contains all possible valid output sets,
|
# 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
|
# based on all possible permutations of recipient address orderings. Must match exactly one of the possible found output
|
||||||
# sets in expected["outputs"]
|
# sets in expected["outputs"]
|
||||||
generated_set = {frozenset(d.items()) for d in add_to_wallet}
|
if "outputs" in expected: # detailed check against expected outputs
|
||||||
expected_set = {frozenset(d.items()) for d in expected["outputs"]}
|
generated_set = {frozenset(d.items()) for d in add_to_wallet}
|
||||||
assert generated_set == expected_set, "Receive test failed"
|
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")
|
print("All tests passed")
|
||||||
|
|||||||
Reference in New Issue
Block a user