File tree Expand file tree Collapse file tree 1 file changed +55
-0
lines changed Expand file tree Collapse file tree 1 file changed +55
-0
lines changed Original file line number Diff line number Diff line change @@ -786,3 +786,58 @@ fn hex_script(s: &str) -> bitcoin::Script {
786786 let v: Vec < u8 > = bitcoin:: hashes:: hex:: FromHex :: from_hex ( s) . unwrap ( ) ;
787787 bitcoin:: Script :: from ( v)
788788}
789+
790+ #[ cfg( test) ]
791+ mod tests {
792+ use super :: * ;
793+
794+ #[ test]
795+ fn regression_bitcoin_key_hash ( ) {
796+ use bitcoin:: PublicKey ;
797+
798+ // Uncompressed key.
799+ let pk = PublicKey :: from_str (
800+ "042e58afe51f9ed8ad3cc7897f634d881fdbe49a81564629ded8156bebd2ffd1af191923a2964c177f5b5923ae500fca49e99492d534aa3759d6b25a8bc971b133"
801+ ) . unwrap ( ) ;
802+
803+ let want = hash160:: Hash :: from_str ( "ac2e7daf42d2c97418fd9f78af2de552bb9c6a7a" ) . unwrap ( ) ;
804+ let got = pk. to_pubkeyhash ( ) ;
805+ assert_eq ! ( got, want)
806+ }
807+
808+ #[ test]
809+ fn regression_secp256k1_key_hash ( ) {
810+ use bitcoin:: secp256k1:: PublicKey ;
811+
812+ // Compressed key.
813+ let pk = PublicKey :: from_str (
814+ "032e58afe51f9ed8ad3cc7897f634d881fdbe49a81564629ded8156bebd2ffd1af" ,
815+ )
816+ . unwrap ( ) ;
817+
818+ let want = hash160:: Hash :: from_str ( "9511aa27ef39bbfa4e4f3dd15f4d66ea57f475b4" ) . unwrap ( ) ;
819+ let got = pk. to_pubkeyhash ( ) ;
820+ assert_eq ! ( got, want)
821+ }
822+
823+ #[ test]
824+ fn regression_xonly_key_hash ( ) {
825+ use bitcoin:: secp256k1:: XOnlyPublicKey ;
826+
827+ let pk = XOnlyPublicKey :: from_str (
828+ "cc8a4bc64d897bddc5fbc2f670f7a8ba0b386779106cf1223c6fc5d7cd6fc115" ,
829+ )
830+ . unwrap ( ) ;
831+
832+ let want = hash160:: Hash :: from_str ( "eb8ac65f971ae688a94aeabf223506865e7e08f2" ) . unwrap ( ) ;
833+ let got = pk. to_pubkeyhash ( ) ;
834+ assert_eq ! ( got, want)
835+ }
836+
837+ #[ test]
838+ fn regression_string_key_hash ( ) {
839+ let pk = String :: from ( "some-key-hash-string" ) ;
840+ let hash = pk. to_pubkeyhash ( ) ;
841+ assert_eq ! ( hash, pk)
842+ }
843+ }
You can’t perform that action at this time.
0 commit comments