Skip to content

Commit 8e8a1a3

Browse files
committed
Add satisfaction tests
1 parent 69f7891 commit 8e8a1a3

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

src/miniscript/mod.rs

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,9 @@ serde_string_impl_pk!(Miniscript, "a miniscript", Ctx; ScriptContext);
449449
#[cfg(test)]
450450
mod tests {
451451

452+
use miniscript::satisfy::BitcoinSchnorrSig;
453+
use {Satisfier, SchnorrSigHashType, ToPublicKey};
454+
452455
use super::{Miniscript, ScriptContext};
453456
use super::{Segwitv0, Tap};
454457
use hex_script;
@@ -1031,16 +1034,22 @@ mod tests {
10311034
assert_eq!(tap_ms.encode().len(), tap_ms.script_size());
10321035

10331036
// Test satisfaction code
1034-
// struct SimpleSatisfier(secp256k1::schnorrsig::Signature);
1035-
1036-
// impl Satisfier<bitcoin::PublicKey> for SimpleSatisfier {
1037-
// fn lookup_sig(&self, pk: &bitcoin::PublicKey) -> Option<BitcoinSig> {
1038-
// if *pk == self.0 {
1039-
// Some((self.sig, bitcoin::SigHashType::All))
1040-
// } else {
1041-
// None
1042-
// }
1043-
// }
1044-
// }
1037+
struct SimpleSatisfier(secp256k1::schnorrsig::Signature);
1038+
1039+
// a simple satisfier that always outputs the same signature
1040+
impl<Pk: ToPublicKey> Satisfier<Pk> for SimpleSatisfier {
1041+
fn lookup_schnorr_sig(&self, _pk: &Pk) -> Option<BitcoinSchnorrSig> {
1042+
Some(BitcoinSchnorrSig {
1043+
sig: self.0,
1044+
hash_ty: SchnorrSigHashType::Default,
1045+
})
1046+
}
1047+
}
1048+
1049+
let schnorr_sig = secp256k1::schnorrsig::Signature::from_str("84526253c27c7aef56c7b71a5cd25bebb66dddda437826defc5b2568bde81f0784526253c27c7aef56c7b71a5cd25bebb66dddda437826defc5b2568bde81f07").unwrap();
1050+
let s = SimpleSatisfier(schnorr_sig);
1051+
1052+
let wit = tap_ms.satisfy(s).unwrap();
1053+
assert_eq!(wit, vec![schnorr_sig.as_ref().to_vec(), vec![], vec![]]);
10451054
}
10461055
}

0 commit comments

Comments
 (0)