@@ -318,8 +318,6 @@ mod tests {
318
318
319
319
#[ test]
320
320
fn test_pubkey_from_slice ( ) {
321
- assert_eq ! ( XOnlyPublicKey :: from_slice( & [ ] ) , Err ( InvalidPublicKey ) ) ;
322
- assert_eq ! ( XOnlyPublicKey :: from_slice( & [ 1 , 2 , 3 ] ) , Err ( InvalidPublicKey ) ) ;
323
321
let pk = XOnlyPublicKey :: from_slice ( & [
324
322
0xB3 , 0x3C , 0xC9 , 0xED , 0xC0 , 0x96 , 0xD0 , 0xA8 , 0x34 , 0x16 , 0x96 , 0x4B , 0xD3 , 0xC6 ,
325
323
0x24 , 0x7B , 0x8F , 0xEC , 0xD2 , 0x56 , 0xE4 , 0xEF , 0xA7 , 0x87 , 0x0D , 0x2C , 0x85 , 0x4B ,
@@ -328,35 +326,11 @@ mod tests {
328
326
assert ! ( pk. is_ok( ) ) ;
329
327
}
330
328
331
- #[ test]
332
- #[ cfg( all( feature = "rand" , feature = "std" ) ) ]
333
- fn test_pubkey_serialize_roundtrip ( ) {
334
- let secp = Secp256k1 :: new ( ) ;
335
- let kp = Keypair :: new ( & secp, & mut rand:: thread_rng ( ) ) ;
336
- let ( pk, _parity) = kp. x_only_public_key ( ) ;
337
-
338
- let ser = pk. serialize ( ) ;
339
- let pubkey2 = XOnlyPublicKey :: from_slice ( & ser) . unwrap ( ) ;
340
- assert_eq ! ( pk, pubkey2) ;
341
- }
342
-
343
- #[ test]
344
- #[ cfg( feature = "alloc" ) ]
345
- fn test_xonly_key_extraction ( ) {
346
- let secp = Secp256k1 :: new ( ) ;
347
- let sk_str = "688C77BC2D5AAFF5491CF309D4753B732135470D05B7B2CD21ADD0744FE97BEF" ;
348
- let keypair = Keypair :: from_seckey_str ( & secp, sk_str) . unwrap ( ) ;
349
- let sk = SecretKey :: from_keypair ( & keypair) ;
350
- assert_eq ! ( SecretKey :: from_str( sk_str) . unwrap( ) , sk) ;
351
- let pk = crate :: key:: PublicKey :: from_keypair ( & keypair) ;
352
- assert_eq ! ( crate :: key:: PublicKey :: from_secret_key( & secp, & sk) , pk) ;
353
- let ( xpk, _parity) = keypair. x_only_public_key ( ) ;
354
- assert_eq ! ( XOnlyPublicKey :: from( pk) , xpk) ;
355
- }
356
-
357
329
#[ test]
358
330
fn test_pubkey_from_bad_slice ( ) {
359
331
// Bad sizes
332
+ assert_eq ! ( XOnlyPublicKey :: from_slice( & [ ] ) , Err ( InvalidPublicKey ) ) ;
333
+ assert_eq ! ( XOnlyPublicKey :: from_slice( & [ 1 , 2 , 3 ] ) , Err ( InvalidPublicKey ) ) ;
360
334
assert_eq ! (
361
335
XOnlyPublicKey :: from_slice( & [ 0 ; constants:: SCHNORR_PUBLIC_KEY_SIZE - 1 ] ) ,
362
336
Err ( InvalidPublicKey )
@@ -381,6 +355,32 @@ mod tests {
381
355
assert_eq ! ( XOnlyPublicKey :: from_slice( & [ ] ) , Err ( InvalidPublicKey ) ) ;
382
356
}
383
357
358
+ #[ test]
359
+ #[ cfg( all( feature = "rand" , feature = "std" ) ) ]
360
+ fn test_pubkey_serialize_roundtrip ( ) {
361
+ let secp = Secp256k1 :: new ( ) ;
362
+ let kp = Keypair :: new ( & secp, & mut rand:: thread_rng ( ) ) ;
363
+ let ( pk, _parity) = kp. x_only_public_key ( ) ;
364
+
365
+ let ser = pk. serialize ( ) ;
366
+ let pubkey2 = XOnlyPublicKey :: from_slice ( & ser) . unwrap ( ) ;
367
+ assert_eq ! ( pk, pubkey2) ;
368
+ }
369
+
370
+ #[ test]
371
+ #[ cfg( feature = "alloc" ) ]
372
+ fn test_xonly_key_extraction ( ) {
373
+ let secp = Secp256k1 :: new ( ) ;
374
+ let sk_str = "688C77BC2D5AAFF5491CF309D4753B732135470D05B7B2CD21ADD0744FE97BEF" ;
375
+ let keypair = Keypair :: from_seckey_str ( & secp, sk_str) . unwrap ( ) ;
376
+ let sk = SecretKey :: from_keypair ( & keypair) ;
377
+ assert_eq ! ( SecretKey :: from_str( sk_str) . unwrap( ) , sk) ;
378
+ let pk = crate :: key:: PublicKey :: from_keypair ( & keypair) ;
379
+ assert_eq ! ( crate :: key:: PublicKey :: from_secret_key( & secp, & sk) , pk) ;
380
+ let ( xpk, _parity) = keypair. x_only_public_key ( ) ;
381
+ assert_eq ! ( XOnlyPublicKey :: from( pk) , xpk) ;
382
+ }
383
+
384
384
#[ test]
385
385
#[ cfg( feature = "std" ) ]
386
386
fn test_pubkey_display_output ( ) {
0 commit comments