Skip to content

Commit 5da250a

Browse files
committed
miniscript: add unit test for repeated pubkeys
1 parent 7bb9b04 commit 5da250a

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/miniscript/mod.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,6 +1408,23 @@ mod tests {
14081408
ms.translate_pk(&mut t).unwrap_err();
14091409
}
14101410

1411+
#[test]
1412+
fn duplicate_keys() {
1413+
// You cannot parse a Miniscript that has duplicate keys
1414+
let err = Miniscript::<String, Segwitv0>::from_str("and_v(v:pk(A),pk(A))").unwrap_err();
1415+
assert_eq!(err, Error::AnalysisError(crate::AnalysisError::RepeatedPubkeys));
1416+
1417+
// ...though you can parse one with from_str_insane
1418+
let ok_insane =
1419+
Miniscript::<String, Segwitv0>::from_str_insane("and_v(v:pk(A),pk(A))").unwrap();
1420+
// ...but this cannot be sanity checked.
1421+
assert_eq!(ok_insane.sanity_check().unwrap_err(), crate::AnalysisError::RepeatedPubkeys);
1422+
// ...it can be lifted, though it's unclear whether this is a deliberate
1423+
// choice or just an accident. It seems weird given that duplicate public
1424+
// keys are forbidden in several other places.
1425+
ok_insane.lift().unwrap();
1426+
}
1427+
14111428
#[test]
14121429
fn mixed_timelocks() {
14131430
// You cannot parse a Miniscript that mixes timelocks.

0 commit comments

Comments
 (0)