Skip to content

Commit 4341120

Browse files
committed
Merge #321: Fix tr for each key bug
92e504c Add breaking test case (sanket1729) 8c07952 Fix tr for each key bug (sanket1729) Pull request description: You can re-order commits to see that this is fixed. ACKs for top commit: dr-orlovsky: tACK 92e504c apoelstra: ACK 92e504c Tree-SHA512: 14f9c045f24ad3147a2220e1a8d5cb3ae5416760993890675d5e1c46101113a991ba43effc11967776c0018f78816d3fb93c8e244e048305213a106c74a85701
2 parents 75ff627 + 92e504c commit 4341120

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

src/descriptor/tr.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ impl<Pk: MiniscriptKey> ForEachKey<Pk> for Tr<Pk> {
650650
{
651651
let script_keys_res = self
652652
.iter_scripts()
653-
.all(|(_d, ms)| ms.for_any_key(&mut pred));
653+
.all(|(_d, ms)| ms.for_each_key(&mut pred));
654654
script_keys_res && pred(ForEach::Key(&self.internal_key))
655655
}
656656
}
@@ -745,3 +745,32 @@ where
745745
}
746746
}
747747
}
748+
749+
#[cfg(test)]
750+
mod tests {
751+
use super::*;
752+
use ForEachKey;
753+
754+
#[test]
755+
fn test_for_each() {
756+
let desc = "tr(acc0, {
757+
multi_a(3, acc10, acc11, acc12), {
758+
and_v(
759+
v:multi_a(2, acc10, acc11, acc12),
760+
after(10)
761+
),
762+
and_v(
763+
v:multi_a(1, acc10, acc11, ac12),
764+
after(100)
765+
)
766+
}
767+
})";
768+
let desc = desc.replace(&[' ', '\n'][..], "");
769+
let tr = Tr::<String>::from_str(&desc).unwrap();
770+
// Note the last ac12 only has ac and fails the predicate
771+
assert!(!tr.for_each_key(|k| match k {
772+
ForEach::Key(k) => k.starts_with("acc"),
773+
ForEach::Hash(_h) => unreachable!(),
774+
}));
775+
}
776+
}

0 commit comments

Comments
 (0)