Skip to content

Commit

Permalink
miniscript: add unit test for repeated pubkeys
Browse files Browse the repository at this point in the history
  • Loading branch information
apoelstra committed Aug 20, 2024
1 parent 7bb9b04 commit 5da250a
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/miniscript/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1408,6 +1408,23 @@ mod tests {
ms.translate_pk(&mut t).unwrap_err();
}

#[test]
fn duplicate_keys() {
// You cannot parse a Miniscript that has duplicate keys
let err = Miniscript::<String, Segwitv0>::from_str("and_v(v:pk(A),pk(A))").unwrap_err();
assert_eq!(err, Error::AnalysisError(crate::AnalysisError::RepeatedPubkeys));

// ...though you can parse one with from_str_insane
let ok_insane =
Miniscript::<String, Segwitv0>::from_str_insane("and_v(v:pk(A),pk(A))").unwrap();
// ...but this cannot be sanity checked.
assert_eq!(ok_insane.sanity_check().unwrap_err(), crate::AnalysisError::RepeatedPubkeys);
// ...it can be lifted, though it's unclear whether this is a deliberate
// choice or just an accident. It seems weird given that duplicate public
// keys are forbidden in several other places.
ok_insane.lift().unwrap();
}

#[test]
fn mixed_timelocks() {
// You cannot parse a Miniscript that mixes timelocks.
Expand Down

0 comments on commit 5da250a

Please sign in to comment.