Skip to content

Commit 39e8f0e

Browse files
refactor: Separate run_context_tests into static vs proper contexts
1 parent a4a0937 commit 39e8f0e

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

src/tests.c

+20-13
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,23 @@ void run_ec_illegal_argument_tests(void) {
228228
secp256k1_context_set_illegal_callback(ctx, NULL, NULL);
229229
}
230230

231-
void run_context_tests(int use_prealloc) {
231+
void run_static_context_tests(void) {
232+
int32_t dummy = 0;
233+
234+
/* Check that deprecated secp256k1_context_no_precomp is an alias to secp256k1_context_static. */
235+
CHECK(secp256k1_context_no_precomp == secp256k1_context_static);
236+
237+
/* check if sizes for cloning are consistent */
238+
CHECK(secp256k1_context_preallocated_clone_size(sttc) >= sizeof(secp256k1_context));
239+
240+
/* Verify that setting and resetting illegal callback works */
241+
secp256k1_context_set_illegal_callback(sttc, counting_illegal_callback_fn, &dummy);
242+
CHECK(sttc->illegal_callback.fn == counting_illegal_callback_fn);
243+
secp256k1_context_set_illegal_callback(sttc, NULL, NULL);
244+
CHECK(sttc->illegal_callback.fn == secp256k1_default_illegal_callback_fn);
245+
}
246+
247+
void run_proper_context_tests(int use_prealloc) {
232248
int32_t dummy = 0;
233249
secp256k1_context *my_ctx;
234250
void *my_ctx_prealloc = NULL;
@@ -237,10 +253,6 @@ void run_context_tests(int use_prealloc) {
237253
secp256k1_ge pub;
238254
secp256k1_scalar msg, key, nonce;
239255
secp256k1_scalar sigr, sigs;
240-
241-
/* Check that deprecated secp256k1_context_no_precomp is an alias to secp256k1_context_static. */
242-
CHECK(secp256k1_context_no_precomp == secp256k1_context_static);
243-
244256
if (use_prealloc) {
245257
my_ctx_prealloc = malloc(secp256k1_context_preallocated_size(SECP256K1_CONTEXT_NONE));
246258
CHECK(my_ctx_prealloc != NULL);
@@ -256,7 +268,6 @@ void run_context_tests(int use_prealloc) {
256268

257269
/* check if sizes for cloning are consistent */
258270
CHECK(secp256k1_context_preallocated_clone_size(my_ctx) == secp256k1_context_preallocated_size(SECP256K1_CONTEXT_NONE));
259-
CHECK(secp256k1_context_preallocated_clone_size(sttc) >= sizeof(secp256k1_context));
260271

261272
/*** clone and destroy all of them to make sure cloning was complete ***/
262273
{
@@ -286,11 +297,6 @@ void run_context_tests(int use_prealloc) {
286297
CHECK(my_ctx->error_callback.fn == secp256k1_default_error_callback_fn);
287298

288299
/* Verify that setting and resetting illegal callback works */
289-
secp256k1_context_set_illegal_callback(sttc, counting_illegal_callback_fn, &dummy);
290-
CHECK(sttc->illegal_callback.fn == counting_illegal_callback_fn);
291-
secp256k1_context_set_illegal_callback(sttc, NULL, NULL);
292-
CHECK(sttc->illegal_callback.fn == secp256k1_default_illegal_callback_fn);
293-
294300
secp256k1_context_set_illegal_callback(my_ctx, counting_illegal_callback_fn, &dummy);
295301
CHECK(my_ctx->illegal_callback.fn == counting_illegal_callback_fn);
296302
secp256k1_context_set_illegal_callback(my_ctx, NULL, NULL);
@@ -7384,8 +7390,9 @@ int main(int argc, char **argv) {
73847390
run_selftest_tests();
73857391

73867392
/* context tests */
7387-
run_context_tests(0);
7388-
run_context_tests(1);
7393+
run_proper_context_tests(0);
7394+
run_proper_context_tests(1);
7395+
run_static_context_tests();
73897396
run_deprecated_context_flags_test();
73907397

73917398
/* scratch tests */

0 commit comments

Comments
 (0)