Skip to content

Commit b2f6ef0

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 a36f608 commit b2f6ef0

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
@@ -1087,3 +1087,29 @@ fn opt_add(a: Option<usize>, b: Option<usize>) -> Option<usize> {
10871087
fn opt_tuple_add(a: Option<(usize, usize)>, b: Option<(usize, usize)>) -> Option<(usize, usize)> {
10881088
a.and_then(|x| b.map(|(w, s)| (w + x.0, s + x.1)))
10891089
}
1090+
1091+
#[cfg(test)]
1092+
mod tests {
1093+
use super::*;
1094+
1095+
#[test]
1096+
fn combine_threshold() {
1097+
let mut time1 = TimelockInfo::default();
1098+
let mut time2 = TimelockInfo::default();
1099+
let mut height = TimelockInfo::default();
1100+
1101+
time1.csv_with_time = true;
1102+
time2.csv_with_time = true;
1103+
height.csv_with_height = true;
1104+
1105+
// For threshold of 1, multiple absolute timelocks do not effect spendable path.
1106+
let v = vec![time1, time2, height];
1107+
let combined = TimelockInfo::combine_threshold(1, v);
1108+
assert!(!combined.contains_unspendable_path());
1109+
1110+
// For threshold of 2, multiple absolute timelocks cannot be spent in a single path.
1111+
let v = vec![time1, time2, height];
1112+
let combined = TimelockInfo::combine_threshold(2, v);
1113+
assert!(combined.contains_unspendable_path())
1114+
}
1115+
}

0 commit comments

Comments
 (0)