Skip to content

Commit 6870d6f

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 1ad88d1 commit 6870d6f

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
@@ -1225,6 +1225,38 @@ mod tests {
12251225
assert!(!policy.for_each_key(|k| k.starts_with("key")));
12261226
}
12271227

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

0 commit comments

Comments
 (0)