Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
move TestAddressString from lib/cgo/tests/check_cipher.address.c to lib/cgo/tests/check_cipher.address.common.c
ref #34
  • Loading branch information
stdevAlDen committed May 15, 2019
1 parent 907ee1a commit bc3c949
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 32 deletions.
34 changes: 3 additions & 31 deletions lib/cgo/tests/check_cipher.address.c
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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);
Expand Down
32 changes: 31 additions & 1 deletion lib/cgo/tests/check_cipher.address.common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");
Expand All @@ -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)
{
Expand All @@ -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);

Expand Down

0 comments on commit bc3c949

Please sign in to comment.