From bc3c949e39d2d114834d21982ac7f9ba61bb5bfd Mon Sep 17 00:00:00 2001 From: Alvaro Denis Date: Wed, 15 May 2019 13:29:18 -0400 Subject: [PATCH] refactor move TestAddressString from lib/cgo/tests/check_cipher.address.c to lib/cgo/tests/check_cipher.address.common.c ref #34 --- lib/cgo/tests/check_cipher.address.c | 34 ++------------------- lib/cgo/tests/check_cipher.address.common.c | 32 ++++++++++++++++++- 2 files changed, 34 insertions(+), 32 deletions(-) diff --git a/lib/cgo/tests/check_cipher.address.c b/lib/cgo/tests/check_cipher.address.c index 0e8534cca..7b66a762c 100644 --- a/lib/cgo/tests/check_cipher.address.c +++ b/lib/cgo/tests/check_cipher.address.c @@ -10,10 +10,9 @@ #define SKYCOIN_ADDRESS_VALID "2GgFvqoyk9RjwVzj8tqfcXVXB4orBwoc9qv" // TestSuite(cipher_address, .init = setup, .fini = teardown); -// -// buffer big enough to hold all kind of data needed by test cases -unsigned char buff[1024]; -// + +extern unsigned char buff[1024]; + START_TEST(TestDecodeBase58Address) { GoString strAddr = {SKYCOIN_ADDRESS_VALID, 35}; @@ -141,32 +140,6 @@ START_TEST(TestAddressFromBytes) } END_TEST -START_TEST(TestAddressString) -{ - cipher__PubKey pk; - cipher__SecKey sk; - cipher__Address addr, addr2, addr3; - GoString str = {buff, 0}; - - GoUint32 err = SKY_cipher_GenerateKeyPair(&pk, &sk); - ck_assert(err == SKY_OK); - err = SKY_cipher_AddressFromPubKey(&pk, &addr); - ck_assert(err == SKY_OK); - GoString_ tmpstr = {str.p, str.n}; - - err = SKY_cipher_Address_String(&addr, &tmpstr); - ck_assert(err == SKY_OK); - str.n = tmpstr.n; - str.p = tmpstr.p; - ck_assert(SKY_cipher_DecodeBase58Address(str, &addr2) == SKY_OK); - ck_assert(isAddressEq(&addr, &addr2)); - - SKY_cipher_Address_String(&addr2, (GoString_*)&str); - ck_assert(SKY_cipher_DecodeBase58Address(str, &addr3) == SKY_OK); - ck_assert(isAddressEq(&addr, &addr2)); -} -END_TEST - START_TEST(TestAddressBulk) { unsigned char buff[50]; @@ -235,7 +208,6 @@ Suite* cipher_address(void) tcase_add_test(tc, TestDecodeBase58Address); tcase_add_test(tc, TestAddressFromBytes); tcase_add_test(tc, TestAddressVerify); - tcase_add_test(tc, TestAddressString); tcase_add_test(tc, TestAddressBulk); tcase_add_test(tc, TestAddressNull); suite_add_tcase(s, tc); diff --git a/lib/cgo/tests/check_cipher.address.common.c b/lib/cgo/tests/check_cipher.address.common.c index ca7033061..511bebac8 100644 --- a/lib/cgo/tests/check_cipher.address.common.c +++ b/lib/cgo/tests/check_cipher.address.common.c @@ -8,6 +8,9 @@ #include "skystring.h" #include "skytest.h" +// buffer big enough to hold all kind of data needed by test cases +unsigned char buff[1024]; + START_TEST(TestAddressVerify) { cipher__PubKey pubkey; @@ -24,7 +27,7 @@ START_TEST(TestAddressVerify) "Valid pubkey + address"); SKY_cipher_GenerateKeyPair(&pubkey, &seckey2); - Invalid pubkey + // Invalid pubkey ck_assert_msg(SKY_cipher_Address_Verify(&addr, &pubkey) == SKY_ErrAddressInvalidPubKey, " Invalid pubkey"); @@ -37,6 +40,32 @@ START_TEST(TestAddressVerify) } END_TEST +START_TEST(TestAddressString) +{ + cipher__PubKey pk; + cipher__SecKey sk; + cipher__Address addr, addr2, addr3; + GoString str = {buff, 0}; + + GoUint32 err = SKY_cipher_GenerateKeyPair(&pk, &sk); + ck_assert(err == SKY_OK); + err = SKY_cipher_AddressFromPubKey(&pk, &addr); + ck_assert(err == SKY_OK); + GoString_ tmpstr = {str.p, str.n}; + + err = SKY_cipher_Address_String(&addr, &tmpstr); + ck_assert(err == SKY_OK); + str.n = tmpstr.n; + str.p = tmpstr.p; + ck_assert(SKY_cipher_DecodeBase58Address(str, &addr2) == SKY_OK); + ck_assert(isAddressEq(&addr, &addr2)); + + SKY_cipher_Address_String(&addr2, (GoString_*)&str); + ck_assert(SKY_cipher_DecodeBase58Address(str, &addr3) == SKY_OK); + ck_assert(isAddressEq(&addr, &addr2)); +} +END_TEST + // define test suite and cases Suite *common_check_cipher_address(void) { @@ -45,6 +74,7 @@ Suite *common_check_cipher_address(void) tc = tcase_create("check_cipher.address"); tcase_add_test(tc, TestAddressVerify); + tcase_add_test(tc, TestAddressString); suite_add_tcase(s, tc); tcase_set_timeout(tc, 150);