diff --git a/src/schnorr.rs b/src/schnorr.rs index e4a07a305..47f41712e 100644 --- a/src/schnorr.rs +++ b/src/schnorr.rs @@ -318,8 +318,6 @@ mod tests { #[test] fn test_pubkey_from_slice() { - assert_eq!(XOnlyPublicKey::from_slice(&[]), Err(InvalidPublicKey)); - assert_eq!(XOnlyPublicKey::from_slice(&[1, 2, 3]), Err(InvalidPublicKey)); let pk = XOnlyPublicKey::from_slice(&[ 0xB3, 0x3C, 0xC9, 0xED, 0xC0, 0x96, 0xD0, 0xA8, 0x34, 0x16, 0x96, 0x4B, 0xD3, 0xC6, 0x24, 0x7B, 0x8F, 0xEC, 0xD2, 0x56, 0xE4, 0xEF, 0xA7, 0x87, 0x0D, 0x2C, 0x85, 0x4B, @@ -328,35 +326,11 @@ mod tests { assert!(pk.is_ok()); } - #[test] - #[cfg(all(feature = "rand", feature = "std"))] - fn test_pubkey_serialize_roundtrip() { - let secp = Secp256k1::new(); - let kp = Keypair::new(&secp, &mut rand::thread_rng()); - let (pk, _parity) = kp.x_only_public_key(); - - let ser = pk.serialize(); - let pubkey2 = XOnlyPublicKey::from_slice(&ser).unwrap(); - assert_eq!(pk, pubkey2); - } - - #[test] - #[cfg(feature = "alloc")] - fn test_xonly_key_extraction() { - let secp = Secp256k1::new(); - let sk_str = "688C77BC2D5AAFF5491CF309D4753B732135470D05B7B2CD21ADD0744FE97BEF"; - let keypair = Keypair::from_seckey_str(&secp, sk_str).unwrap(); - let sk = SecretKey::from_keypair(&keypair); - assert_eq!(SecretKey::from_str(sk_str).unwrap(), sk); - let pk = crate::key::PublicKey::from_keypair(&keypair); - assert_eq!(crate::key::PublicKey::from_secret_key(&secp, &sk), pk); - let (xpk, _parity) = keypair.x_only_public_key(); - assert_eq!(XOnlyPublicKey::from(pk), xpk); - } - #[test] fn test_pubkey_from_bad_slice() { // Bad sizes + assert_eq!(XOnlyPublicKey::from_slice(&[]), Err(InvalidPublicKey)); + assert_eq!(XOnlyPublicKey::from_slice(&[1, 2, 3]), Err(InvalidPublicKey)); assert_eq!( XOnlyPublicKey::from_slice(&[0; constants::SCHNORR_PUBLIC_KEY_SIZE - 1]), Err(InvalidPublicKey) @@ -381,6 +355,32 @@ mod tests { assert_eq!(XOnlyPublicKey::from_slice(&[]), Err(InvalidPublicKey)); } + #[test] + #[cfg(all(feature = "rand", feature = "std"))] + fn test_pubkey_serialize_roundtrip() { + let secp = Secp256k1::new(); + let kp = Keypair::new(&secp, &mut rand::thread_rng()); + let (pk, _parity) = kp.x_only_public_key(); + + let ser = pk.serialize(); + let pubkey2 = XOnlyPublicKey::from_slice(&ser).unwrap(); + assert_eq!(pk, pubkey2); + } + + #[test] + #[cfg(feature = "alloc")] + fn test_xonly_key_extraction() { + let secp = Secp256k1::new(); + let sk_str = "688C77BC2D5AAFF5491CF309D4753B732135470D05B7B2CD21ADD0744FE97BEF"; + let keypair = Keypair::from_seckey_str(&secp, sk_str).unwrap(); + let sk = SecretKey::from_keypair(&keypair); + assert_eq!(SecretKey::from_str(sk_str).unwrap(), sk); + let pk = crate::key::PublicKey::from_keypair(&keypair); + assert_eq!(crate::key::PublicKey::from_secret_key(&secp, &sk), pk); + let (xpk, _parity) = keypair.x_only_public_key(); + assert_eq!(XOnlyPublicKey::from(pk), xpk); + } + #[test] #[cfg(feature = "std")] fn test_pubkey_display_output() {