Skip to content

Commit c2ced8a

Browse files
committed
Add basic unit test for translate_pk
In preparation for modifying the `translate_pk` function add a basic unit test.
1 parent 37f3796 commit c2ced8a

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/policy/concrete.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,6 +1230,38 @@ mod tests {
12301230
assert!(!policy.for_each_key(|k| k.starts_with("key")));
12311231
}
12321232

1233+
#[test]
1234+
fn tranaslate_pk() {
1235+
pub struct TestTranslator;
1236+
impl Translator<String, String, ()> for TestTranslator {
1237+
fn pk(&mut self, pk: &String) -> Result<String, ()> {
1238+
let new = format!("NEW-{}", pk);
1239+
Ok(new.to_string())
1240+
}
1241+
fn sha256(&mut self, hash: &String) -> Result<String, ()> {
1242+
Ok(hash.to_string())
1243+
}
1244+
fn hash256(&mut self, hash: &String) -> Result<String, ()> {
1245+
Ok(hash.to_string())
1246+
}
1247+
fn ripemd160(&mut self, hash: &String) -> Result<String, ()> {
1248+
Ok(hash.to_string())
1249+
}
1250+
fn hash160(&mut self, hash: &String) -> Result<String, ()> {
1251+
Ok(hash.to_string())
1252+
}
1253+
}
1254+
let policy = Policy::<String>::from_str("or(and(pk(A),pk(B)),pk(C))").unwrap();
1255+
let mut t = TestTranslator;
1256+
1257+
let want = Policy::<String>::from_str("or(and(pk(NEW-A),pk(NEW-B)),pk(NEW-C))").unwrap();
1258+
let got = policy
1259+
.translate_pk(&mut t)
1260+
.expect("failed to translate keys");
1261+
1262+
assert_eq!(got, want);
1263+
}
1264+
12331265
#[test]
12341266
fn translate_unsatisfiable_pk() {
12351267
let policy = Policy::<String>::from_str("or(and(pk(A),pk(B)),pk(C))").unwrap();

0 commit comments

Comments
 (0)