Skip to content

Commit b3c0955

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 9280db2 commit b3c0955

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
@@ -1203,7 +1203,7 @@ mod tests {
12031203
use super::*;
12041204

12051205
#[test]
1206-
fn for_each_key() {
1206+
fn for_each_key_count_keys() {
12071207
let liquid_pol = Policy::<String>::from_str(
12081208
"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();
12091209
let mut count = 0;
@@ -1214,6 +1214,13 @@ mod tests {
12141214
assert_eq!(count, 17);
12151215
}
12161216

1217+
#[test]
1218+
fn for_each_key_fails_predicate() {
1219+
let policy =
1220+
Policy::<String>::from_str("or(and(pk(key0),pk(key1)),pk(oddnamedkey))").unwrap();
1221+
assert!(!policy.for_each_key(|k| k.starts_with("key")));
1222+
}
1223+
12171224
#[test]
12181225
fn translate_unsatisfiable_pk() {
12191226
let policy = Policy::<String>::from_str("or(and(pk(A),pk(B)),pk(C))").unwrap();

0 commit comments

Comments
 (0)