Skip to content

Commit acf9ac1

Browse files
apoelstraDavidson-Souza
authored andcommitted
delete test_manual_create_destroy test
This is just a bad test. It constructs a preallocated context object by starting from a non-preallocated context object, in a way that can't be done by users (since it directly constructs a `Secp256k1` struct) and a way that is very difficult to unwind, because you wind up with two pointers to the same underlying context object, one a "preallocated" one and one a normal one. If you then drop the preallocated one, it will call `secp256k1_context_destroy`, forcing you to manually deallocate the other one. If you drop the normally-allocated one, you need to mem::forget the preallocated one to avoid calling `secp256k1_context_destroy` twice. The whole thing is pretty fragile. There is another unit test, `test_raw_ctx`, which gets into the same situation but using the public API, and demonstrates a few ways to get out of it.
1 parent 04ce508 commit acf9ac1

File tree

1 file changed

+0
-34
lines changed

1 file changed

+0
-34
lines changed

src/lib.rs

-34
Original file line numberDiff line numberDiff line change
@@ -555,40 +555,6 @@ mod tests {
555555
}};
556556
}
557557

558-
#[test]
559-
#[cfg(feature = "rand-std")]
560-
fn test_manual_create_destroy() {
561-
use std::marker::PhantomData;
562-
563-
let ctx_full = unsafe { ffi::secp256k1_context_create(AllPreallocated::FLAGS) };
564-
let ctx_sign = unsafe { ffi::secp256k1_context_create(SignOnlyPreallocated::FLAGS) };
565-
let ctx_vrfy = unsafe { ffi::secp256k1_context_create(VerifyOnlyPreallocated::FLAGS) };
566-
567-
let full: Secp256k1<AllPreallocated> = Secp256k1 { ctx: ctx_full, phantom: PhantomData };
568-
let sign: Secp256k1<SignOnlyPreallocated> =
569-
Secp256k1 { ctx: ctx_sign, phantom: PhantomData };
570-
let vrfy: Secp256k1<VerifyOnlyPreallocated> =
571-
Secp256k1 { ctx: ctx_vrfy, phantom: PhantomData };
572-
573-
let (sk, pk) = full.generate_keypair(&mut rand::thread_rng());
574-
let msg = Message::from_digest_slice(&[2u8; 32]).unwrap();
575-
// Try signing
576-
assert_eq!(sign.sign_ecdsa(&msg, &sk), full.sign_ecdsa(&msg, &sk));
577-
let sig = full.sign_ecdsa(&msg, &sk);
578-
579-
// Try verifying
580-
assert!(vrfy.verify_ecdsa(&msg, &sig, &pk).is_ok());
581-
assert!(full.verify_ecdsa(&msg, &sig, &pk).is_ok());
582-
583-
drop(full);
584-
drop(sign);
585-
drop(vrfy);
586-
587-
unsafe { ffi::secp256k1_context_destroy(ctx_vrfy) };
588-
unsafe { ffi::secp256k1_context_destroy(ctx_sign) };
589-
unsafe { ffi::secp256k1_context_destroy(ctx_full) };
590-
}
591-
592558
#[test]
593559
#[cfg(feature = "rand-std")]
594560
// In rustc 1.72 this Clippy lint was pulled out of clippy and into rustc, and

0 commit comments

Comments
 (0)