Skip to content

Commit 560daa1

Browse files
committed
Add unit test coverage for_each_key
In preparation for modifying the `for_each_key` add an additional unit test that checks we correctly handle a failing predicate. While we are at it rename the existing test.
1 parent 1612c37 commit 560daa1

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/policy/concrete.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1223,7 +1223,7 @@ mod tests {
12231223
use super::*;
12241224

12251225
#[test]
1226-
fn for_each_key() {
1226+
fn for_each_key_count_keys() {
12271227
let liquid_pol = Policy::<String>::from_str(
12281228
"or(and(older(4096),thresh(2,pk(A),pk(B),pk(C))),thresh(11,pk(F1),pk(F2),pk(F3),pk(F4),pk(F5),pk(F6),pk(F7),pk(F8),pk(F9),pk(F10),pk(F11),pk(F12),pk(F13),pk(F14)))").unwrap();
12291229
let mut count = 0;
@@ -1234,6 +1234,13 @@ mod tests {
12341234
assert_eq!(count, 17);
12351235
}
12361236

1237+
#[test]
1238+
fn for_each_key_fails_predicate() {
1239+
let policy =
1240+
Policy::<String>::from_str("or(and(pk(key0),pk(key1)),pk(oddnamedkey))").unwrap();
1241+
assert!(!policy.for_each_key(|k| k.starts_with("key")));
1242+
}
1243+
12371244
#[test]
12381245
fn translate_unsatisfiable_pk() {
12391246
let policy = Policy::<String>::from_str("or(and(pk(A),pk(B)),pk(C))").unwrap();

0 commit comments

Comments
 (0)