Skip to content

Commit 98104b9

Browse files
committed
Merge #677: Fix compilation of pk()-only policies into tr() descriptors
ea3c523 Add test case for compilation of pk()-only policies (Nadav Ivgi) 169e489 Fix compilation of pk()-only policies into tr() descriptors (Nadav Ivgi) Pull request description: Before this fix, the added test failed with: `Unexpected("Empty Miniscript compilation")` ACKs for top commit: apoelstra: ACK ea3c523 successfully ran local tests; good find! Tree-SHA512: 3d19d4f23f21d4c811ddb1e0a3cc66f0bc90cffe47f4d5a0659caa44b0d80a0665e71b46b8289f1efba98ba4cf731eac8bc7d1fc7b5a3d701cf5c85b48fc5551
2 parents 286fa88 + ea3c523 commit 98104b9

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

src/policy/concrete.rs

+23-4
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,13 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
247247
.expect("compiler produces sane output");
248248
leaf_compilations.push((OrdF64(prob), compilation));
249249
}
250-
let tap_tree = with_huffman_tree::<Pk>(leaf_compilations).unwrap();
251-
Some(tap_tree)
250+
if !leaf_compilations.is_empty() {
251+
let tap_tree = with_huffman_tree::<Pk>(leaf_compilations).unwrap();
252+
Some(tap_tree)
253+
} else {
254+
// no policies remaining once the extracted key is skipped
255+
None
256+
}
252257
}
253258
},
254259
)
@@ -303,8 +308,14 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
303308
)
304309
})
305310
.collect();
306-
let tap_tree = with_huffman_tree::<Pk>(leaf_compilations).unwrap();
307-
Some(tap_tree)
311+
312+
if !leaf_compilations.is_empty() {
313+
let tap_tree = with_huffman_tree::<Pk>(leaf_compilations).unwrap();
314+
Some(tap_tree)
315+
} else {
316+
// no policies remaining once the extracted key is skipped
317+
None
318+
}
308319
}
309320
},
310321
)?;
@@ -1109,6 +1120,14 @@ mod compiler_tests {
11091120
.collect::<Vec<_>>();
11101121
assert_eq!(combinations, expected_comb);
11111122
}
1123+
1124+
#[test]
1125+
fn test_tr_pk_only() {
1126+
let policy: Policy<String> = policy_str!("pk(A)");
1127+
let desc = policy.compile_tr(None).unwrap();
1128+
// pk(A) promoted to the internal key, leaving the script tree empty
1129+
assert_eq!(desc.to_string(), "tr(A)#xyg3grex");
1130+
}
11121131
}
11131132

11141133
#[cfg(test)]

0 commit comments

Comments
 (0)