Skip to content

Commit

Permalink
refactor: Separate run_context_tests into static vs proper contexts
Browse files Browse the repository at this point in the history
  • Loading branch information
real-or-random committed Jan 5, 2023
1 parent a4a0937 commit 39e8f0e
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions src/tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,23 @@ void run_ec_illegal_argument_tests(void) {
secp256k1_context_set_illegal_callback(ctx, NULL, NULL);
}

void run_context_tests(int use_prealloc) {
void run_static_context_tests(void) {
int32_t dummy = 0;

/* Check that deprecated secp256k1_context_no_precomp is an alias to secp256k1_context_static. */
CHECK(secp256k1_context_no_precomp == secp256k1_context_static);

/* check if sizes for cloning are consistent */
CHECK(secp256k1_context_preallocated_clone_size(sttc) >= sizeof(secp256k1_context));

/* Verify that setting and resetting illegal callback works */
secp256k1_context_set_illegal_callback(sttc, counting_illegal_callback_fn, &dummy);
CHECK(sttc->illegal_callback.fn == counting_illegal_callback_fn);
secp256k1_context_set_illegal_callback(sttc, NULL, NULL);
CHECK(sttc->illegal_callback.fn == secp256k1_default_illegal_callback_fn);
}

void run_proper_context_tests(int use_prealloc) {
int32_t dummy = 0;
secp256k1_context *my_ctx;
void *my_ctx_prealloc = NULL;
Expand All @@ -237,10 +253,6 @@ void run_context_tests(int use_prealloc) {
secp256k1_ge pub;
secp256k1_scalar msg, key, nonce;
secp256k1_scalar sigr, sigs;

/* Check that deprecated secp256k1_context_no_precomp is an alias to secp256k1_context_static. */
CHECK(secp256k1_context_no_precomp == secp256k1_context_static);

if (use_prealloc) {
my_ctx_prealloc = malloc(secp256k1_context_preallocated_size(SECP256K1_CONTEXT_NONE));
CHECK(my_ctx_prealloc != NULL);
Expand All @@ -256,7 +268,6 @@ void run_context_tests(int use_prealloc) {

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

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

/* Verify that setting and resetting illegal callback works */
secp256k1_context_set_illegal_callback(sttc, counting_illegal_callback_fn, &dummy);
CHECK(sttc->illegal_callback.fn == counting_illegal_callback_fn);
secp256k1_context_set_illegal_callback(sttc, NULL, NULL);
CHECK(sttc->illegal_callback.fn == secp256k1_default_illegal_callback_fn);

secp256k1_context_set_illegal_callback(my_ctx, counting_illegal_callback_fn, &dummy);
CHECK(my_ctx->illegal_callback.fn == counting_illegal_callback_fn);
secp256k1_context_set_illegal_callback(my_ctx, NULL, NULL);
Expand Down Expand Up @@ -7384,8 +7390,9 @@ int main(int argc, char **argv) {
run_selftest_tests();

/* context tests */
run_context_tests(0);
run_context_tests(1);
run_proper_context_tests(0);
run_proper_context_tests(1);
run_static_context_tests();
run_deprecated_context_flags_test();

/* scratch tests */
Expand Down

0 comments on commit 39e8f0e

Please sign in to comment.