From 3abff9d77ec0cd4281965823e75750b461c50570 Mon Sep 17 00:00:00 2001 From: Alvaro Denis Date: Tue, 14 May 2019 20:05:13 -0400 Subject: [PATCH] refactor move TestAddressVerify from lib/cgo/tests/check_cipher.address.c to lib/cgo/tests/check_cipher.address.common.c ref #84 --- lib/cgo/tests/check_cipher.address.c | 29 ------------ lib/cgo/tests/check_cipher.address.common.c | 52 +++++++++++++++++++++ lib/cgo/tests/test_main.c | 1 + lib/cgo/tests/test_main.h | 1 + lib/cgo/tests/test_main_common.h | 10 ++++ lib/cgo/tests/test_main_hw.c | 3 +- 6 files changed, 66 insertions(+), 30 deletions(-) create mode 100644 lib/cgo/tests/check_cipher.address.common.c create mode 100644 lib/cgo/tests/test_main_common.h diff --git a/lib/cgo/tests/check_cipher.address.c b/lib/cgo/tests/check_cipher.address.c index 619b03c00..0e8534cca 100644 --- a/lib/cgo/tests/check_cipher.address.c +++ b/lib/cgo/tests/check_cipher.address.c @@ -141,35 +141,6 @@ START_TEST(TestAddressFromBytes) } END_TEST -START_TEST(TestAddressVerify) -{ - cipher__PubKey pubkey; - cipher__SecKey seckey; - cipher__PubKey pubkey2; - cipher__SecKey seckey2; - cipher__Address addr; - - SKY_cipher_GenerateKeyPair(&pubkey, &seckey); - SKY_cipher_AddressFromPubKey(&pubkey, &addr); - - // Valid pubkey+address - ck_assert_msg(SKY_cipher_Address_Verify(&addr, &pubkey) == SKY_OK, - "Valid pubkey + address"); - - SKY_cipher_GenerateKeyPair(&pubkey, &seckey2); - // Invalid pubkey - ck_assert_msg(SKY_cipher_Address_Verify(&addr, &pubkey) == - SKY_ErrAddressInvalidPubKey, - " Invalid pubkey"); - - // Bad version - addr.Version = 0x01; - ck_assert_msg(SKY_cipher_Address_Verify(&addr, &pubkey) == - SKY_ErrAddressInvalidVersion, - " Bad version"); -} -END_TEST - START_TEST(TestAddressString) { cipher__PubKey pk; diff --git a/lib/cgo/tests/check_cipher.address.common.c b/lib/cgo/tests/check_cipher.address.common.c new file mode 100644 index 000000000..ca7033061 --- /dev/null +++ b/lib/cgo/tests/check_cipher.address.common.c @@ -0,0 +1,52 @@ +#include +#include + +#include +#include "libskycoin.h" +#include "skyerrors.h" +#include "skyassert.h" +#include "skystring.h" +#include "skytest.h" + +START_TEST(TestAddressVerify) +{ + cipher__PubKey pubkey; + cipher__SecKey seckey; + cipher__PubKey pubkey2; + cipher__SecKey seckey2; + cipher__Address addr; + + SKY_cipher_GenerateKeyPair(&pubkey, &seckey); + SKY_cipher_AddressFromPubKey(&pubkey, &addr); + + // Valid pubkey+address + ck_assert_msg(SKY_cipher_Address_Verify(&addr, &pubkey) == SKY_OK, + "Valid pubkey + address"); + + SKY_cipher_GenerateKeyPair(&pubkey, &seckey2); + Invalid pubkey + ck_assert_msg(SKY_cipher_Address_Verify(&addr, &pubkey) == + SKY_ErrAddressInvalidPubKey, + " Invalid pubkey"); + + // Bad version + addr.Version = 0x01; + ck_assert_msg(SKY_cipher_Address_Verify(&addr, &pubkey) == + SKY_ErrAddressInvalidVersion, + " Bad version"); +} +END_TEST + +// define test suite and cases +Suite *common_check_cipher_address(void) +{ + Suite *s = suite_create("Load common check_cipher.address"); + TCase *tc; + + tc = tcase_create("check_cipher.address"); + tcase_add_test(tc, TestAddressVerify); + suite_add_tcase(s, tc); + tcase_set_timeout(tc, 150); + + return s; +} diff --git a/lib/cgo/tests/test_main.c b/lib/cgo/tests/test_main.c index e77ec0746..9771f00ee 100644 --- a/lib/cgo/tests/test_main.c +++ b/lib/cgo/tests/test_main.c @@ -8,6 +8,7 @@ int main(void) SRunner* sr = srunner_create(cipher_address()); SRunner* sr_fork = srunner_create(coin_transaction_fork()); srunner_add_suite(sr, common_check_cipher_hash()); + srunner_add_suite(sr, common_check_cipher_address()); srunner_add_suite(sr, cipher_bitcoin()); srunner_add_suite(sr, cipher_crypto()); srunner_add_suite(sr, cipher_encrypt_scrypt_chacha20poly1305()); diff --git a/lib/cgo/tests/test_main.h b/lib/cgo/tests/test_main.h index bf722ddd4..a8f71f4a2 100644 --- a/lib/cgo/tests/test_main.h +++ b/lib/cgo/tests/test_main.h @@ -10,6 +10,7 @@ #include "skytest.h" #include "skytypes.h" #include "skyerrors.h" +#include "test_main_common.h" Suite *cipher_bitcoin(void); Suite *cipher_address(void); diff --git a/lib/cgo/tests/test_main_common.h b/lib/cgo/tests/test_main_common.h new file mode 100644 index 000000000..4a5ac2f84 --- /dev/null +++ b/lib/cgo/tests/test_main_common.h @@ -0,0 +1,10 @@ +#ifndef TEST_MAIN_COMMON_H +#define TEST_MAIN_COMMON_H + +#include +#include + +Suite *common_check_cipher_hash(void); +Suite *common_check_cipher_address(void); + +#endif // TEST_MAIN_COMMON_H diff --git a/lib/cgo/tests/test_main_hw.c b/lib/cgo/tests/test_main_hw.c index fcc7e3e44..ce284e064 100644 --- a/lib/cgo/tests/test_main_hw.c +++ b/lib/cgo/tests/test_main_hw.c @@ -1,7 +1,7 @@ #include #include -Suite *common_check_cipher_hash(void); +#include "test_main_common.h" // run suite int main(void) @@ -9,6 +9,7 @@ int main(void) int number_failed = 0; int number_failed_fork = 0; SRunner *sr = srunner_create(common_check_cipher_hash()); + srunner_add_suite(sr, common_check_cipher_address()); srunner_run_all(sr, CK_VERBOSE); number_failed = srunner_ntests_failed(sr); srunner_free(sr);