Skip to content

Commit 59be080

Browse files
committed
Merge commit '51d66d1eab3930fbe053a33816d9f80f8ad57255' into update_2022_10
51d66d1 Merge rust-bitcoin/rust-miniscript#418: Tr compiler v3 - Incremental Enumerative Compiler
2 parents 1e927fa + 51d66d1 commit 59be080

File tree

4 files changed

+559
-5
lines changed

4 files changed

+559
-5
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ rand = ["bitcoin/rand"]
1818
[dependencies]
1919
bitcoin = "0.29.1"
2020
elements = "0.21.0"
21-
bitcoin-miniscript = {package = "miniscript", git = "https://github.com/rust-bitcoin/rust-miniscript", rev = "b6daa9786a9e0479df9f7abd4570e319b0a6637e"}
21+
bitcoin-miniscript = {package = "miniscript", git = "https://github.com/rust-bitcoin/rust-miniscript", rev = "51d66d1eab3930fbe053a33816d9f80f8ad57255"}
2222

2323
# Do NOT use this as a feature! Use the `serde` feature instead.
2424
actual-serde = { package = "serde", version = "1.0", optional = true }

src/lib.rs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,3 +632,62 @@ fn hex_script(s: &str) -> elements::Script {
632632
let v: Vec<u8> = elements::hashes::hex::FromHex::from_hex(s).unwrap();
633633
elements::Script::from(v)
634634
}
635+
636+
#[cfg(test)]
637+
mod tests {
638+
use std::str::FromStr;
639+
640+
use bitcoin::hashes::hash160;
641+
642+
use super::*;
643+
644+
#[test]
645+
fn regression_bitcoin_key_hash() {
646+
use bitcoin::PublicKey;
647+
648+
// Uncompressed key.
649+
let pk = PublicKey::from_str(
650+
"042e58afe51f9ed8ad3cc7897f634d881fdbe49a81564629ded8156bebd2ffd1af191923a2964c177f5b5923ae500fca49e99492d534aa3759d6b25a8bc971b133"
651+
).unwrap();
652+
653+
let want = hash160::Hash::from_str("ac2e7daf42d2c97418fd9f78af2de552bb9c6a7a").unwrap();
654+
let got = pk.to_pubkeyhash();
655+
assert_eq!(got, want)
656+
}
657+
658+
#[test]
659+
fn regression_secp256k1_key_hash() {
660+
use bitcoin::secp256k1::PublicKey;
661+
662+
// Compressed key.
663+
let pk = PublicKey::from_str(
664+
"032e58afe51f9ed8ad3cc7897f634d881fdbe49a81564629ded8156bebd2ffd1af",
665+
)
666+
.unwrap();
667+
668+
let want = hash160::Hash::from_str("9511aa27ef39bbfa4e4f3dd15f4d66ea57f475b4").unwrap();
669+
let got = pk.to_pubkeyhash();
670+
assert_eq!(got, want)
671+
}
672+
673+
#[test]
674+
fn regression_xonly_key_hash() {
675+
use bitcoin::secp256k1::XOnlyPublicKey;
676+
677+
let pk = XOnlyPublicKey::from_str(
678+
"cc8a4bc64d897bddc5fbc2f670f7a8ba0b386779106cf1223c6fc5d7cd6fc115",
679+
)
680+
.unwrap();
681+
682+
let want = hash160::Hash::from_str("eb8ac65f971ae688a94aeabf223506865e7e08f2").unwrap();
683+
let got = pk.to_pubkeyhash();
684+
assert_eq!(got, want)
685+
}
686+
687+
#[test]
688+
fn regression_string_key_hash() {
689+
let pk = String::from("some-key-hash-string");
690+
let hash = pk.to_pubkeyhash();
691+
assert_eq!(hash, pk)
692+
}
693+
}

0 commit comments

Comments
 (0)