Add Huffman Encoding Test

This commit is contained in:
Jeremy Rubin 2021-11-14 18:39:42 -08:00
parent 5286d0ab0c
commit 3b968e482c
1 changed files with 26 additions and 1 deletions

View File

@ -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();