Merge rust-bitcoin/rust-bitcoin#700: Huffman Encoding Bug Test
3b968e482c
Add Huffman Encoding Test (Jeremy Rubin) Pull request description: ACKs for top commit: sanket1729: ACK3b968e482c
dr-orlovsky: utACK3b968e482c
Tree-SHA512: d6d5ed31ae228bb635c27d18a99259911b0378c44c6622fd0fc27d58f41fb25f6e008bf35d929918208a9f62e7ef47d2f11691470f177160b15542a63ff6df1b
This commit is contained in:
commit
a84aba19dc
|
@ -1032,10 +1032,35 @@ mod test {
|
||||||
(20, Script::from_hex("52").unwrap()),
|
(20, Script::from_hex("52").unwrap()),
|
||||||
(20, Script::from_hex("53").unwrap()),
|
(20, Script::from_hex("53").unwrap()),
|
||||||
(30, Script::from_hex("54").unwrap()),
|
(30, Script::from_hex("54").unwrap()),
|
||||||
(20, Script::from_hex("55").unwrap()),
|
(19, Script::from_hex("55").unwrap()),
|
||||||
];
|
];
|
||||||
let tree_info = TaprootSpendInfo::with_huffman_tree(&secp, internal_key, script_weights.clone()).unwrap();
|
let tree_info = TaprootSpendInfo::with_huffman_tree(&secp, internal_key, script_weights.clone()).unwrap();
|
||||||
|
|
||||||
|
/* The resulting tree should put the scripts into a tree similar
|
||||||
|
* to the following:
|
||||||
|
*
|
||||||
|
* 1 __/\__
|
||||||
|
* / \
|
||||||
|
* /\ / \
|
||||||
|
* 2 54 52 53 /\
|
||||||
|
* 3 55 51
|
||||||
|
*/
|
||||||
|
|
||||||
|
for (script, length) in vec![("51", 3), ("52", 2), ("53", 2), ("54", 2), ("55", 3)] {
|
||||||
|
assert_eq!(
|
||||||
|
length,
|
||||||
|
tree_info
|
||||||
|
.script_map
|
||||||
|
.get(&(Script::from_hex(script).unwrap(), LeafVersion::default()))
|
||||||
|
.expect("Present Key")
|
||||||
|
.iter()
|
||||||
|
.next()
|
||||||
|
.expect("Present Path")
|
||||||
|
.0
|
||||||
|
.len()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// Obtain the output key
|
// Obtain the output key
|
||||||
let output_key = tree_info.output_key();
|
let output_key = tree_info.output_key();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue