Skip to content

Commit 630e60e

Browse files
committed
Add unit test for combine_threshold
Add a simple unit test showing how `combine_threshold` works. Test asserts that multiple timelocks of the same type result in unspendable paths if threshold is 2.
1 parent b6887d6 commit 630e60e

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/miniscript/types/extra_props.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,3 +1034,29 @@ fn opt_max<T: Ord>(a: Option<T>, b: Option<T>) -> Option<T> {
10341034
fn opt_add(a: Option<usize>, b: Option<usize>) -> Option<usize> {
10351035
a.and_then(|x| b.map(|y| x + y))
10361036
}
1037+
1038+
#[cfg(test)]
1039+
mod tests {
1040+
use super::*;
1041+
1042+
#[test]
1043+
fn combine_threshold() {
1044+
let mut time1 = TimelockInfo::default();
1045+
let mut time2 = TimelockInfo::default();
1046+
let mut height = TimelockInfo::default();
1047+
1048+
time1.csv_with_time = true;
1049+
time2.csv_with_time = true;
1050+
height.csv_with_height = true;
1051+
1052+
// For threshold of 1, multiple absolute timelocks do not effect spendable path.
1053+
let v = vec![time1, time2, height];
1054+
let combined = TimelockInfo::combine_threshold(1, v);
1055+
assert!(!combined.contains_unspendable_path());
1056+
1057+
// For threshold of 2, multiple absolute timelocks cannot be spent in a single path.
1058+
let v = vec![time1, time2, height];
1059+
let combined = TimelockInfo::combine_threshold(2, v);
1060+
assert!(combined.contains_unspendable_path())
1061+
}
1062+
}

0 commit comments

Comments
 (0)