Skip to content

Commit 3282193

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 c81389f commit 3282193

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/policy/concrete.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,6 +1205,30 @@ mod tests {
12051205
assert!(!policy.for_each_key(|k| k.starts_with("key")));
12061206
}
12071207

1208+
#[test]
1209+
fn tranaslate_pk() {
1210+
pub struct TestTranslator;
1211+
impl Translator<String, String, ()> for TestTranslator {
1212+
fn pk(&mut self, pk: &String) -> Result<String, ()> {
1213+
let new = format!("NEW-{}", pk);
1214+
Ok(new.to_string())
1215+
}
1216+
fn sha256(&mut self, hash: &String) -> Result<String, ()> { Ok(hash.to_string()) }
1217+
fn hash256(&mut self, hash: &String) -> Result<String, ()> { Ok(hash.to_string()) }
1218+
fn ripemd160(&mut self, hash: &String) -> Result<String, ()> { Ok(hash.to_string()) }
1219+
fn hash160(&mut self, hash: &String) -> Result<String, ()> { Ok(hash.to_string()) }
1220+
}
1221+
let policy = Policy::<String>::from_str("or(and(pk(A),pk(B)),pk(C))").unwrap();
1222+
let mut t = TestTranslator;
1223+
1224+
let want = Policy::<String>::from_str("or(and(pk(NEW-A),pk(NEW-B)),pk(NEW-C))").unwrap();
1225+
let got = policy
1226+
.translate_pk(&mut t)
1227+
.expect("failed to translate keys");
1228+
1229+
assert_eq!(got, want);
1230+
}
1231+
12081232
#[test]
12091233
fn translate_unsatisfiable_pk() {
12101234
let policy = Policy::<String>::from_str("or(and(pk(A),pk(B)),pk(C))").unwrap();

0 commit comments

Comments
 (0)