-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
txscript: add unit tests and test vectors for miniscript
This commit adds test vectors taken from https://github.com/rust-bitcoin/rust-miniscript/blob/a0648b3a4d63abbe53f621308614f97f04a04096/src/miniscript/ms_tests.rs to the miniscript implementation. Co-authored-by: Oliver Gugger <[email protected]>
- Loading branch information
Showing
9 changed files
with
30,112 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Test vectors taken from: | ||
|
||
https://github.com/rust-bitcoin/rust-miniscript/blob/a0648b3a4d63abbe53f621308614f97f04a04096/src/miniscript/ms_tests.rs |
1,773 changes: 1,773 additions & 0 deletions
1,773
txscript/miniscript/testdata/conflict_from_alloy.txt
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
5,574 changes: 5,574 additions & 0 deletions
5,574
txscript/miniscript/testdata/invalid_from_alloy.txt
Large diffs are not rendered by default.
Oops, something went wrong.
7,024 changes: 7,024 additions & 0 deletions
7,024
txscript/miniscript/testdata/malleable_from_alloy.txt
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,297 @@ | ||
{ | ||
"identifiers": { | ||
"pk_1": "22a47fa09a223f2aa079edf85a7c2d4f8720ee63e502ee2869afab7de234b80c", | ||
"key_1": "02a673638cb9587cb68ea08dbef685c6f2d2a751a8b3c6f2a7e9a4999e6e4bfaf5", | ||
"pk_2": "9106e8d2191b58e6c12f10b70d86ba54396db99ecedffd3c150e72960bd11305", | ||
"key_2": "034a3f8cebf79df4dbaf67db66b4b20d115a1003c1d8863f977d027600b4db175b", | ||
"pk_3": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", | ||
"key_3": "026a04ab98d9e4774ad806e302dddeb63bea16b5cb5f223ee77478e861bb583eb3", | ||
"preimage_1": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", | ||
"h256_1": "e0e77a507412b120f6ede61f62295b1a7b2ff19d3dcc8f7253e51663470c888e", | ||
"h160_1": "b3256e789b42b4e73b0954beb516ec7dfc032dd3", | ||
"h256_2": "926a54995ca48600920a19bf7bc502ca5f2f7d07e6f804c4f00ebf0325084dbc" | ||
}, | ||
"test_cases": [ | ||
{ | ||
"miniscript": "pk(key_1)", | ||
"script_description": "A single key.", | ||
"comment": "key_1 signs.", | ||
"valid": true, | ||
"can_sign_1": true | ||
}, | ||
{ | ||
"miniscript": "pk(key_1)", | ||
"comment": "No satisfaction (key_1 missing).", | ||
"valid": false | ||
}, | ||
{ | ||
"miniscript": "or_b(pk(key_1),s:pk(key_2))", | ||
"script_description": "One of two keys (equally likely).", | ||
"comment": "No satisfaction (keys missing).", | ||
"valid": false | ||
}, | ||
{ | ||
"miniscript": "or_b(pk(key_1),s:pk(key_2))", | ||
"comment": "key_1 signs.", | ||
"valid": true, | ||
"can_sign_1": true | ||
}, | ||
{ | ||
"miniscript": "or_b(pk(key_1),s:pk(key_2))", | ||
"comment": "key_2 signs.", | ||
"valid": true, | ||
"can_sign_2": true | ||
}, | ||
{ | ||
"miniscript": "and_v(v:pk(key_1),or_d(pk(key_2),older(12960)))", | ||
"script_description": "A user and a 2FA service need to sign off, but after 90 days the user alone is enough.", | ||
"comment": "No satisfaction (keys missing).", | ||
"valid": false | ||
}, | ||
{ | ||
"miniscript": "and_v(v:pk(key_1),or_d(pk(key_2),older(12960)))", | ||
"comment": "key_1 signs alone before 12960.", | ||
"valid": false, | ||
"sequence": 12959, | ||
"can_sign_1": true | ||
}, | ||
{ | ||
"miniscript": "and_v(v:pk(key_1),or_d(pk(key_2),older(12960)))", | ||
"comment": "key_1 signs alone, utxo older than 12960.", | ||
"valid": true, | ||
"sequence": 12960, | ||
"can_sign_1": true | ||
}, | ||
{ | ||
"miniscript": "and_v(v:pk(key_1),or_d(pk(key_2),older(12960)))", | ||
"comment": "key_2 signs alone before 12960.", | ||
"valid": false, | ||
"sequence": 12959, | ||
"can_sign_2": true | ||
}, | ||
{ | ||
"miniscript": "and_v(v:pk(key_1),or_d(pk(key_2),older(12960)))", | ||
"comment": "key_2 signs alone after 12960.", | ||
"valid": false, | ||
"sequence": 12960, | ||
"can_sign_2": true | ||
}, | ||
{ | ||
"miniscript": "and_v(v:pk(key_1),or_d(pk(key_2),older(12960)))", | ||
"comment": "Both sign before 12960.", | ||
"valid": true, | ||
"can_sign_1": true, | ||
"can_sign_2": true | ||
}, | ||
{ | ||
"miniscript": "thresh(3,pk(key_1),s:pk(key_2),s:pk(key_3),sln:older(12960))", | ||
"script_description": "A 3-of-3 that turns into a 2-of-3 after 90 days.", | ||
"comment": "No satisfaction (keys missing).", | ||
"valid": false | ||
}, | ||
{ | ||
"miniscript": "thresh(3,pk(key_1),s:pk(key_2),s:pk(key_3),sln:older(12960))", | ||
"comment": "All three sign before 12960.", | ||
"valid": true, | ||
"can_sign_1": true, | ||
"can_sign_2": true, | ||
"can_sign_3": true | ||
}, | ||
{ | ||
"miniscript": "thresh(3,pk(key_1),s:pk(key_2),s:pk(key_3),sln:older(12960))", | ||
"comment": "Only one signs before 12960.", | ||
"valid": false, | ||
"can_sign_1": true | ||
}, | ||
{ | ||
"miniscript": "thresh(3,pk(key_1),s:pk(key_2),s:pk(key_3),sln:older(12960))", | ||
"comment": "Only two sign before 12960.", | ||
"valid": false, | ||
"can_sign_1": true, | ||
"can_sign_2": true | ||
}, | ||
{ | ||
"miniscript": "thresh(3,pk(key_1),s:pk(key_2),s:pk(key_3),sln:older(12960))", | ||
"comment": "Only two sign before 12960.", | ||
"valid": false, | ||
"can_sign_1": true, | ||
"can_sign_3": true | ||
}, | ||
{ | ||
"miniscript": "thresh(3,pk(key_1),s:pk(key_2),s:pk(key_3),sln:older(12960))", | ||
"comment": "Only two sign before 12960.", | ||
"valid": false, | ||
"can_sign_2": true, | ||
"can_sign_3": true | ||
}, | ||
{ | ||
"miniscript": "thresh(3,pk(key_1),s:pk(key_2),s:pk(key_3),sln:older(12960))", | ||
"comment": "Two sign after 12960.", | ||
"valid": true, | ||
"sequence": 12960, | ||
"can_sign_1": true, | ||
"can_sign_2": true | ||
}, | ||
{ | ||
"miniscript": "thresh(3,pk(key_1),s:pk(key_2),s:pk(key_3),sln:older(12960))", | ||
"comment": "Two sign after 12960.", | ||
"valid": true, | ||
"sequence": 12960, | ||
"can_sign_1": true, | ||
"can_sign_3": true | ||
}, | ||
{ | ||
"miniscript": "thresh(3,pk(key_1),s:pk(key_2),s:pk(key_3),sln:older(12960))", | ||
"comment": "One signs after 12960.", | ||
"valid": false, | ||
"sequence": 12960, | ||
"can_sign_1": true | ||
}, | ||
{ | ||
"miniscript": "thresh(3,pk(key_1),s:pk(key_2),s:pk(key_3),sln:older(12960))", | ||
"comment": "No one signs after 12960.", | ||
"valid": false, | ||
"sequence": 12960 | ||
}, | ||
{ | ||
"miniscript": "andor(pk(key_1),older(1008),pk(key_2))", | ||
"script_description": "The BOLT #3 to_local policy.", | ||
"comment": "No satisfaction (keys missing).", | ||
"valid": false | ||
}, | ||
{ | ||
"miniscript": "andor(pk(key_1),older(1008),pk(key_2))", | ||
"comment": "key_1 signs before 1008.", | ||
"valid": false, | ||
"can_sign_1": true | ||
}, | ||
{ | ||
"miniscript": "andor(pk(key_1),older(1008),pk(key_2))", | ||
"comment": "key_1 signs after 1008.", | ||
"valid": true, | ||
"sequence": 1008, | ||
"can_sign_1": true | ||
}, | ||
{ | ||
"miniscript": "andor(pk(key_1),older(1008),pk(key_2))", | ||
"comment": "key_2 signs before 1008.", | ||
"valid": true, | ||
"can_sign_2": true | ||
}, | ||
{ | ||
"miniscript": "t:or_c(pk(key_1),and_v(v:pk(key_2),or_c(pk(key_3),v:hash160(h160_1))))", | ||
"script_description": "The BOLT #3 offered HTLC policy", | ||
"comment": "No satisfaction (keys missing).", | ||
"valid": false | ||
}, | ||
{ | ||
"miniscript": "and_v(v:pk(key_1),sha256(h256_1))", | ||
"script_description": "A key and a preimage.", | ||
"comment": "No satisfaction (keys missing).", | ||
"valid": false | ||
}, | ||
{ | ||
"miniscript": "and_v(v:pk(key_1),sha256(h256_1))", | ||
"comment": "key_1 but no preimage.", | ||
"valid": false, | ||
"can_sign_1": true | ||
}, | ||
{ | ||
"miniscript": "and_v(v:pk(key_1),sha256(h256_1))", | ||
"comment": "Preimage but no key_1.", | ||
"valid": false, | ||
"has_preimage": true | ||
}, | ||
{ | ||
"miniscript": "and_v(v:pk(key_1),sha256(h256_1))", | ||
"comment": "Both key_1 and preimage.", | ||
"valid": true, | ||
"can_sign_1": true, | ||
"has_preimage": true | ||
}, | ||
{ | ||
"miniscript": "and_v(v:pk(key_1),pk(key_2))", | ||
"script_description": "A 2-of-2 multisig.", | ||
"comment": "No satisfaction (keys missing).", | ||
"valid": false | ||
}, | ||
{ | ||
"miniscript": "and_b(c:pk_k(key_1),s:pk(key_2))", | ||
"script_description": "a 2-of-2 multisig with boolean logic.", | ||
"comment": "No satisfaction (keys missing).", | ||
"valid": false | ||
}, | ||
{ | ||
"miniscript": "or_b(pk(key_1),s:pk(key_2))", | ||
"script_description": "A 1-of-2 multisig with boolean logic.", | ||
"comment": "No satisfaction (keys missing).", | ||
"valid": false | ||
}, | ||
{ | ||
"miniscript": "multi(2,key_1,key_2,key_3)", | ||
"script_description": "A 2-of-3 multisig.", | ||
"comment": "No satisfaction (keys missing).", | ||
"valid": false | ||
}, | ||
{ | ||
"miniscript": "thresh(1,thresh(2,sha256(h256_2),sc:pk_k(key_2),sc:pk_k(key_3)),sc:pk_k(key_4),sc:pk_k(key_5))", | ||
"script_description": "Nested threshold with preimage and 4 keys.", | ||
"comment": "No satisfaction (keys missing).", | ||
"valid": false | ||
}, | ||
{ | ||
"miniscript": "and_v(or_c(multi(2,key_1,key_2,key_3),v:sha256(h256_2)),1)", | ||
"script_description": "A 2-of-3 multisig or hash lock with superfluous boolean AND.", | ||
"comment": "No satisfaction (keys missing).", | ||
"valid": false | ||
}, | ||
{ | ||
"miniscript": "and_v(v:sha256(h256_1),c:pk_k(key_1))", | ||
"script_description": "A hash lock and single key.", | ||
"comment": "No satisfaction (keys missing).", | ||
"valid": false | ||
}, | ||
{ | ||
"miniscript": "or_d(multi(2,key_1,key_2,key_3),multi(2,key_4,key_5))", | ||
"script_description": "A 2-of-3 multisig or a 2-of-2 multisig.", | ||
"comment": "No satisfaction (keys missing).", | ||
"valid": false | ||
}, | ||
{ | ||
"miniscript": "or_i(multi(2,key_1,key_2,key_3),multi(2,key_4,key_5))", | ||
"script_description": "A 2-of-3 multisig or a 2-of-2 multisig with IF.", | ||
"comment": "No satisfaction (keys missing).", | ||
"valid": false | ||
}, | ||
{ | ||
"miniscript": "and_v(v:pk(key_1),or_d(pk(key_2),after(12960)))", | ||
"comment": "No satisfaction (keys missing).", | ||
"valid": false | ||
}, | ||
{ | ||
"miniscript": "or_d(pk(key_1),and_v(v:pk(key_2),older(0)))", | ||
"comment": "No satisfaction (keys missing).", | ||
"valid": false | ||
}, | ||
{ | ||
"miniscript": "or_b(pk(key_1),s:pk(key_2))", | ||
"comment": "No satisfaction (keys missing).", | ||
"valid": false | ||
}, | ||
{ | ||
"miniscript": "andor(pk(key_1),pk(key_2),and_v(v:multi(2,key_3,key_4,key_5),older(2)))", | ||
"comment": "No satisfaction (keys missing).", | ||
"valid": false | ||
}, | ||
{ | ||
"miniscript": "or_b(and_b(pk(key_1),s:pk(key_2)),s:pk(key_3))", | ||
"comment": "No satisfaction (keys missing).", | ||
"valid": false | ||
}, | ||
{ | ||
"miniscript": "or_b(and_b(sha256(h256_1),s:pk(key_2)),s:pk(key_3))", | ||
"comment": "No satisfaction (keys missing).", | ||
"valid": false | ||
} | ||
] | ||
} |
Oops, something went wrong.