File tree 1 file changed +32
-0
lines changed
1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -1230,6 +1230,38 @@ mod tests {
1230
1230
assert ! ( !policy. for_each_key( |k| k. starts_with( "key" ) ) ) ;
1231
1231
}
1232
1232
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
+
1233
1265
#[ test]
1234
1266
fn translate_unsatisfiable_pk ( ) {
1235
1267
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