File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -1225,6 +1225,38 @@ mod tests {
1225
1225
assert ! ( !policy. for_each_key( |k| k. starts_with( "key" ) ) ) ;
1226
1226
}
1227
1227
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
+
1228
1260
#[ test]
1229
1261
fn translate_unsatisfiable_pk ( ) {
1230
1262
let policy = Policy :: < String > :: from_str ( "or(and(pk(A),pk(B)),pk(C))" ) . unwrap ( ) ;
You can’t perform that action at this time.
0 commit comments