Skip to content

Commit

Permalink
Merge commit '51d66d1eab3930fbe053a33816d9f80f8ad57255' into update_2…
Browse files Browse the repository at this point in the history
…022_10

51d66d1 Merge rust-bitcoin/rust-miniscript#418: Tr compiler v3 - Incremental Enumerative Compiler
  • Loading branch information
sanket1729 committed Oct 20, 2022
2 parents 1e927fa + 51d66d1 commit 59be080
Show file tree
Hide file tree
Showing 4 changed files with 559 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ rand = ["bitcoin/rand"]
[dependencies]
bitcoin = "0.29.1"
elements = "0.21.0"
bitcoin-miniscript = {package = "miniscript", git = "https://github.com/rust-bitcoin/rust-miniscript", rev = "b6daa9786a9e0479df9f7abd4570e319b0a6637e"}
bitcoin-miniscript = {package = "miniscript", git = "https://github.com/rust-bitcoin/rust-miniscript", rev = "51d66d1eab3930fbe053a33816d9f80f8ad57255"}

# Do NOT use this as a feature! Use the `serde` feature instead.
actual-serde = { package = "serde", version = "1.0", optional = true }
Expand Down
59 changes: 59 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -632,3 +632,62 @@ fn hex_script(s: &str) -> elements::Script {
let v: Vec<u8> = elements::hashes::hex::FromHex::from_hex(s).unwrap();
elements::Script::from(v)
}

#[cfg(test)]
mod tests {
use std::str::FromStr;

use bitcoin::hashes::hash160;

use super::*;

#[test]
fn regression_bitcoin_key_hash() {
use bitcoin::PublicKey;

// Uncompressed key.
let pk = PublicKey::from_str(
"042e58afe51f9ed8ad3cc7897f634d881fdbe49a81564629ded8156bebd2ffd1af191923a2964c177f5b5923ae500fca49e99492d534aa3759d6b25a8bc971b133"
).unwrap();

let want = hash160::Hash::from_str("ac2e7daf42d2c97418fd9f78af2de552bb9c6a7a").unwrap();
let got = pk.to_pubkeyhash();
assert_eq!(got, want)
}

#[test]
fn regression_secp256k1_key_hash() {
use bitcoin::secp256k1::PublicKey;

// Compressed key.
let pk = PublicKey::from_str(
"032e58afe51f9ed8ad3cc7897f634d881fdbe49a81564629ded8156bebd2ffd1af",
)
.unwrap();

let want = hash160::Hash::from_str("9511aa27ef39bbfa4e4f3dd15f4d66ea57f475b4").unwrap();
let got = pk.to_pubkeyhash();
assert_eq!(got, want)
}

#[test]
fn regression_xonly_key_hash() {
use bitcoin::secp256k1::XOnlyPublicKey;

let pk = XOnlyPublicKey::from_str(
"cc8a4bc64d897bddc5fbc2f670f7a8ba0b386779106cf1223c6fc5d7cd6fc115",
)
.unwrap();

let want = hash160::Hash::from_str("eb8ac65f971ae688a94aeabf223506865e7e08f2").unwrap();
let got = pk.to_pubkeyhash();
assert_eq!(got, want)
}

#[test]
fn regression_string_key_hash() {
let pk = String::from("some-key-hash-string");
let hash = pk.to_pubkeyhash();
assert_eq!(hash, pk)
}
}
Loading

0 comments on commit 59be080

Please sign in to comment.