@@ -556,4 +556,35 @@ mod tests {
556556 #[ cfg( feature = "std" ) ]
557557 println ! ( "{}" , _s) ;
558558 }
559+
560+ #[ test]
561+ #[ cfg( feature = "alloc" ) ]
562+ fn descriptor ( ) {
563+ // This magic constant came from Bitcoin Core, src/script/descriptor.cpp.
564+ //
565+ // Note that this generator polynomial has degree 8, not 6, reflected
566+ // in the initial range being (0..8).
567+ let unpacked_poly = ( 0 ..8 )
568+ . rev ( ) // Note .rev() to convert from BE integer literal to LE polynomial!
569+ . map ( |i| 0xf5dee51989u64 . unpack ( i) )
570+ . map ( |u| Fe32 :: try_from ( u) . unwrap ( ) )
571+ . collect :: < Vec < _ > > ( ) ;
572+ assert_eq ! (
573+ unpacked_poly,
574+ [ Fe32 :: _7, Fe32 :: H , Fe32 :: _0, Fe32 :: W , Fe32 :: _2, Fe32 :: X , Fe32 :: V , Fe32 :: F ] ,
575+ ) ;
576+
577+ // Run with -- --nocapture to see the output of this. This unit test
578+ // does not check the exact output because it is not deterministic,
579+ // and cannot check the code semantics because Rust does not have
580+ // any sort of `eval`, but you can manually check the output works.
581+ let _s = PrintImpl :: < crate :: Fe32768 > :: new (
582+ "DescriptorChecksum" ,
583+ & [ Fe32 :: _7, Fe32 :: H , Fe32 :: _0, Fe32 :: W , Fe32 :: _2, Fe32 :: X , Fe32 :: V , Fe32 :: F ] ,
584+ & [ Fe32 :: Q , Fe32 :: Q , Fe32 :: Q , Fe32 :: Q , Fe32 :: Q , Fe32 :: Q , Fe32 :: Q , Fe32 :: P ] ,
585+ )
586+ . to_string ( ) ;
587+ #[ cfg( feature = "std" ) ]
588+ println ! ( "{}" , _s) ;
589+ }
559590}
0 commit comments