Skip to content

Commit

Permalink
refactor: Rename STTC to STATIC_CTX in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
real-or-random committed Jan 10, 2023
1 parent 3385a26 commit 9a93f48
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 35 deletions.
8 changes: 4 additions & 4 deletions src/modules/extrakeys/tests_impl.h
Expand Up @@ -338,7 +338,7 @@ void test_keypair(void) {
int ecount;

set_counting_callbacks(CTX, &ecount);
set_counting_callbacks(STTC, &ecount);
set_counting_callbacks(STATIC_CTX, &ecount);

CHECK(sizeof(zeros96) == sizeof(keypair));
memset(overflows, 0xFF, sizeof(overflows));
Expand All @@ -359,7 +359,7 @@ void test_keypair(void) {
CHECK(ecount == 2);
CHECK(secp256k1_keypair_create(CTX, &keypair, sk) == 1);
CHECK(ecount == 2);
CHECK(secp256k1_keypair_create(STTC, &keypair, sk) == 0);
CHECK(secp256k1_keypair_create(STATIC_CTX, &keypair, sk) == 0);
CHECK(secp256k1_memcmp_var(zeros96, &keypair, sizeof(keypair)) == 0);
CHECK(ecount == 3);

Expand Down Expand Up @@ -440,8 +440,8 @@ void test_keypair(void) {
CHECK(secp256k1_keypair_sec(CTX, sk_tmp, &keypair) == 1);
CHECK(secp256k1_memcmp_var(zeros96, sk_tmp, sizeof(sk_tmp)) == 0);

secp256k1_context_set_error_callback(STTC, NULL, NULL);
secp256k1_context_set_illegal_callback(STTC, NULL, NULL);
secp256k1_context_set_error_callback(STATIC_CTX, NULL, NULL);
secp256k1_context_set_illegal_callback(STATIC_CTX, NULL, NULL);
}

void test_keypair_add(void) {
Expand Down
10 changes: 5 additions & 5 deletions src/modules/recovery/tests_impl.h
Expand Up @@ -47,8 +47,8 @@ void test_ecdsa_recovery_api(void) {

secp256k1_context_set_error_callback(CTX, counting_illegal_callback_fn, &ecount);
secp256k1_context_set_illegal_callback(CTX, counting_illegal_callback_fn, &ecount);
secp256k1_context_set_error_callback(STTC, counting_illegal_callback_fn, &ecount);
secp256k1_context_set_illegal_callback(STTC, counting_illegal_callback_fn, &ecount);
secp256k1_context_set_error_callback(STATIC_CTX, counting_illegal_callback_fn, &ecount);
secp256k1_context_set_illegal_callback(STATIC_CTX, counting_illegal_callback_fn, &ecount);

/* Construct and verify corresponding public key. */
CHECK(secp256k1_ec_seckey_verify(CTX, privkey) == 1);
Expand All @@ -64,7 +64,7 @@ void test_ecdsa_recovery_api(void) {
CHECK(ecount == 2);
CHECK(secp256k1_ecdsa_sign_recoverable(CTX, &recsig, message, NULL, NULL, NULL) == 0);
CHECK(ecount == 3);
CHECK(secp256k1_ecdsa_sign_recoverable(STTC, &recsig, message, privkey, NULL, NULL) == 0);
CHECK(secp256k1_ecdsa_sign_recoverable(STATIC_CTX, &recsig, message, privkey, NULL, NULL) == 0);
CHECK(ecount == 4);
/* This will fail or succeed randomly, and in either case will not ARG_CHECK failure */
secp256k1_ecdsa_sign_recoverable(CTX, &recsig, message, privkey, recovery_test_nonce_function, NULL);
Expand Down Expand Up @@ -123,8 +123,8 @@ void test_ecdsa_recovery_api(void) {
CHECK(ecount == 7);

/* cleanup */
secp256k1_context_set_error_callback(STTC, NULL, NULL);
secp256k1_context_set_illegal_callback(STTC, NULL, NULL);
secp256k1_context_set_error_callback(STATIC_CTX, NULL, NULL);
secp256k1_context_set_illegal_callback(STATIC_CTX, NULL, NULL);
}

void test_ecdsa_recovery_end_to_end(void) {
Expand Down
12 changes: 6 additions & 6 deletions src/modules/schnorrsig/tests_impl.h
Expand Up @@ -132,8 +132,8 @@ void test_schnorrsig_api(void) {

secp256k1_context_set_error_callback(CTX, counting_illegal_callback_fn, &ecount);
secp256k1_context_set_illegal_callback(CTX, counting_illegal_callback_fn, &ecount);
secp256k1_context_set_error_callback(STTC, counting_illegal_callback_fn, &ecount);
secp256k1_context_set_illegal_callback(STTC, counting_illegal_callback_fn, &ecount);
secp256k1_context_set_error_callback(STATIC_CTX, counting_illegal_callback_fn, &ecount);
secp256k1_context_set_illegal_callback(STATIC_CTX, counting_illegal_callback_fn, &ecount);

secp256k1_testrand256(sk1);
secp256k1_testrand256(sk2);
Expand All @@ -159,7 +159,7 @@ void test_schnorrsig_api(void) {
CHECK(ecount == 3);
CHECK(secp256k1_schnorrsig_sign32(CTX, sig, msg, &invalid_keypair, NULL) == 0);
CHECK(ecount == 4);
CHECK(secp256k1_schnorrsig_sign32(STTC, sig, msg, &keypairs[0], NULL) == 0);
CHECK(secp256k1_schnorrsig_sign32(STATIC_CTX, sig, msg, &keypairs[0], NULL) == 0);
CHECK(ecount == 5);

ecount = 0;
Expand All @@ -179,7 +179,7 @@ void test_schnorrsig_api(void) {
CHECK(ecount == 4);
CHECK(secp256k1_schnorrsig_sign_custom(CTX, sig, msg, sizeof(msg), &keypairs[0], &invalid_extraparams) == 0);
CHECK(ecount == 5);
CHECK(secp256k1_schnorrsig_sign_custom(STTC, sig, msg, sizeof(msg), &keypairs[0], &extraparams) == 0);
CHECK(secp256k1_schnorrsig_sign_custom(STATIC_CTX, sig, msg, sizeof(msg), &keypairs[0], &extraparams) == 0);
CHECK(ecount == 6);

ecount = 0;
Expand All @@ -197,8 +197,8 @@ void test_schnorrsig_api(void) {
CHECK(secp256k1_schnorrsig_verify(CTX, sig, msg, sizeof(msg), &zero_pk) == 0);
CHECK(ecount == 4);

secp256k1_context_set_error_callback(STTC, NULL, NULL);
secp256k1_context_set_illegal_callback(STTC, NULL, NULL);
secp256k1_context_set_error_callback(STATIC_CTX, NULL, NULL);
secp256k1_context_set_illegal_callback(STATIC_CTX, NULL, NULL);
}

/* Checks that hash initialized by secp256k1_schnorrsig_sha256_tagged has the
Expand Down
40 changes: 20 additions & 20 deletions src/tests.c
Expand Up @@ -29,7 +29,7 @@

static int COUNT = 64;
static secp256k1_context *CTX = NULL;
static secp256k1_context *STTC = NULL;
static secp256k1_context *STATIC_CTX = NULL;

static void counting_illegal_callback_fn(const char* str, void* data) {
/* Dummy callback function that just counts. */
Expand Down Expand Up @@ -185,46 +185,46 @@ void run_ec_illegal_argument_tests(void) {
unsigned char ctmp[32];

/* Setup */
secp256k1_context_set_illegal_callback(STTC, counting_illegal_callback_fn, &ecount);
secp256k1_context_set_illegal_callback(STATIC_CTX, counting_illegal_callback_fn, &ecount);
secp256k1_context_set_illegal_callback(CTX, counting_illegal_callback_fn, &ecount2);
memset(ctmp, 1, 32);
memset(&zero_pubkey, 0, sizeof(zero_pubkey));

/* Verify context-type checking illegal-argument errors. */
CHECK(secp256k1_ec_pubkey_create(STTC, &pubkey, ctmp) == 0);
CHECK(secp256k1_ec_pubkey_create(STATIC_CTX, &pubkey, ctmp) == 0);
CHECK(ecount == 1);
VG_UNDEF(&pubkey, sizeof(pubkey));
CHECK(secp256k1_ec_pubkey_create(CTX, &pubkey, ctmp) == 1);
VG_CHECK(&pubkey, sizeof(pubkey));
CHECK(secp256k1_ecdsa_sign(STTC, &sig, ctmp, ctmp, NULL, NULL) == 0);
CHECK(secp256k1_ecdsa_sign(STATIC_CTX, &sig, ctmp, ctmp, NULL, NULL) == 0);
CHECK(ecount == 2);
VG_UNDEF(&sig, sizeof(sig));
CHECK(secp256k1_ecdsa_sign(CTX, &sig, ctmp, ctmp, NULL, NULL) == 1);
VG_CHECK(&sig, sizeof(sig));
CHECK(ecount2 == 10);
CHECK(secp256k1_ecdsa_verify(CTX, &sig, ctmp, &pubkey) == 1);
CHECK(ecount2 == 10);
CHECK(secp256k1_ecdsa_verify(STTC, &sig, ctmp, &pubkey) == 1);
CHECK(secp256k1_ecdsa_verify(STATIC_CTX, &sig, ctmp, &pubkey) == 1);
CHECK(ecount == 2);
CHECK(secp256k1_ec_pubkey_tweak_add(CTX, &pubkey, ctmp) == 1);
CHECK(ecount2 == 10);
CHECK(secp256k1_ec_pubkey_tweak_add(STTC, &pubkey, ctmp) == 1);
CHECK(secp256k1_ec_pubkey_tweak_add(STATIC_CTX, &pubkey, ctmp) == 1);
CHECK(ecount == 2);
CHECK(secp256k1_ec_pubkey_tweak_mul(CTX, &pubkey, ctmp) == 1);
CHECK(ecount2 == 10);
CHECK(secp256k1_ec_pubkey_negate(STTC, &pubkey) == 1);
CHECK(secp256k1_ec_pubkey_negate(STATIC_CTX, &pubkey) == 1);
CHECK(ecount == 2);
CHECK(secp256k1_ec_pubkey_negate(CTX, &pubkey) == 1);
CHECK(ecount == 2);
CHECK(secp256k1_ec_pubkey_negate(STTC, &zero_pubkey) == 0);
CHECK(secp256k1_ec_pubkey_negate(STATIC_CTX, &zero_pubkey) == 0);
CHECK(ecount == 3);
CHECK(secp256k1_ec_pubkey_negate(CTX, NULL) == 0);
CHECK(ecount2 == 11);
CHECK(secp256k1_ec_pubkey_tweak_mul(STTC, &pubkey, ctmp) == 1);
CHECK(secp256k1_ec_pubkey_tweak_mul(STATIC_CTX, &pubkey, ctmp) == 1);
CHECK(ecount == 3);

/* Clean up */
secp256k1_context_set_illegal_callback(STTC, NULL, NULL);
secp256k1_context_set_illegal_callback(STATIC_CTX, NULL, NULL);
secp256k1_context_set_illegal_callback(CTX, NULL, NULL);
}

Expand All @@ -235,13 +235,13 @@ void run_static_context_tests(void) {
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));
CHECK(secp256k1_context_preallocated_clone_size(STATIC_CTX) >= 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);
secp256k1_context_set_illegal_callback(STATIC_CTX, counting_illegal_callback_fn, &dummy);
CHECK(STATIC_CTX->illegal_callback.fn == counting_illegal_callback_fn);
secp256k1_context_set_illegal_callback(STATIC_CTX, NULL, NULL);
CHECK(STATIC_CTX->illegal_callback.fn == secp256k1_default_illegal_callback_fn);
}

void run_proper_context_tests(int use_prealloc) {
Expand Down Expand Up @@ -7379,10 +7379,10 @@ int main(int argc, char **argv) {
that write to the context. The API does not support cloning the static context, so we use
memcpy instead. The user is not supposed to copy a context but we should still ensure that
the API functions handle copies of the static context gracefully. */
STTC = malloc(sizeof(*secp256k1_context_static));
CHECK(STTC != NULL);
memcpy(STTC, secp256k1_context_static, sizeof(secp256k1_context));
CHECK(!secp256k1_context_is_proper(STTC));
STATIC_CTX = malloc(sizeof(*secp256k1_context_static));
CHECK(STATIC_CTX != NULL);
memcpy(STATIC_CTX, secp256k1_context_static, sizeof(secp256k1_context));
CHECK(!secp256k1_context_is_proper(STATIC_CTX));

/*** Run actual tests ***/

Expand Down Expand Up @@ -7491,7 +7491,7 @@ int main(int argc, char **argv) {
run_cmov_tests();

/*** Tear down test environment ***/
free(STTC);
free(STATIC_CTX);
secp256k1_context_destroy(CTX);

secp256k1_testrand_finish();
Expand Down

0 comments on commit 9a93f48

Please sign in to comment.