Skip to content

Commit e6229bf

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 7e73ffe commit e6229bf

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
@@ -1224,7 +1224,7 @@ mod tests {
12241224
use super::*;
12251225

12261226
#[test]
1227-
fn for_each_key() {
1227+
fn for_each_key_count_keys() {
12281228
let liquid_pol = Policy::<String>::from_str(
12291229
"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();
12301230
let mut count = 0;
@@ -1235,6 +1235,13 @@ mod tests {
12351235
assert_eq!(count, 17);
12361236
}
12371237

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

0 commit comments

Comments
 (0)