Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
move TestAddressBulk from lib/cgo/tests/check_cipher.address.c to lib/cgo/tests/check_cipher.address.common.c
ref skycoin#34
  • Loading branch information
Alvaro Denis committed May 15, 2019
1 parent a16a448 commit e6596ab
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 35 deletions.
35 changes: 0 additions & 35 deletions lib/cgo/tests/check_cipher.address.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,39 +140,6 @@ START_TEST(TestAddressFromBytes)
}
END_TEST

START_TEST(TestAddressBulk)
{
unsigned char buff[50];
GoSlice slice = {buff, 0, 50};
int i;
for (i = 0; i < 1024; ++i) {
GoUint32 err;
randBytes(&slice, 32);
cipher__PubKey pubkey;
cipher__SecKey seckey;
err = SKY_cipher_GenerateDeterministicKeyPair(slice, &pubkey, &seckey);
ck_assert(err == SKY_OK);
cipher__Address addr;
err = SKY_cipher_AddressFromPubKey(&pubkey, &addr);
ck_assert(err == SKY_OK);
err = SKY_cipher_Address_Verify(&addr, &pubkey);
ck_assert(err == SKY_OK);

GoString_ tempstrAddr;
err = SKY_cipher_Address_String(&addr, &tempstrAddr);
ck_assert(err == SKY_OK);
registerMemCleanup((void*)tempstrAddr.p);
cipher__Address addr2;
GoString strAddr;
strAddr.n = tempstrAddr.n;
strAddr.p = tempstrAddr.p;
err = SKY_cipher_DecodeBase58Address(strAddr, &addr2);
ck_assert(err == SKY_OK);
ck_assert(isAddressEq(&addr, &addr2));
}
}
END_TEST

START_TEST(TestAddressNull)
{
cipher__Address a;
Expand Down Expand Up @@ -207,8 +174,6 @@ Suite* cipher_address(void)
tcase_add_checked_fixture(tc, setup, teardown);
tcase_add_test(tc, TestDecodeBase58Address);
tcase_add_test(tc, TestAddressFromBytes);
tcase_add_test(tc, TestAddressVerify);
tcase_add_test(tc, TestAddressBulk);
tcase_add_test(tc, TestAddressNull);
suite_add_tcase(s, tc);
tcase_set_timeout(tc, 150);
Expand Down
34 changes: 34 additions & 0 deletions lib/cgo/tests/check_cipher.address.common.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,39 @@ START_TEST(TestAddressString)
}
END_TEST

START_TEST(TestAddressBulk)
{
unsigned char buff[50];
GoSlice slice = {buff, 0, 50};
int i;
for (i = 0; i < 1024; ++i) {
GoUint32 err;
randBytes(&slice, 32);
cipher__PubKey pubkey;
cipher__SecKey seckey;
err = SKY_cipher_GenerateDeterministicKeyPair(slice, &pubkey, &seckey);
ck_assert(err == SKY_OK);
cipher__Address addr;
err = SKY_cipher_AddressFromPubKey(&pubkey, &addr);
ck_assert(err == SKY_OK);
err = SKY_cipher_Address_Verify(&addr, &pubkey);
ck_assert(err == SKY_OK);

GoString_ tempstrAddr;
err = SKY_cipher_Address_String(&addr, &tempstrAddr);
ck_assert(err == SKY_OK);
registerMemCleanup((void*)tempstrAddr.p);
cipher__Address addr2;
GoString strAddr;
strAddr.n = tempstrAddr.n;
strAddr.p = tempstrAddr.p;
err = SKY_cipher_DecodeBase58Address(strAddr, &addr2);
ck_assert(err == SKY_OK);
ck_assert(isAddressEq(&addr, &addr2));
}
}
END_TEST

// define test suite and cases
Suite *common_check_cipher_address(void)
{
Expand All @@ -75,6 +108,7 @@ Suite *common_check_cipher_address(void)
tc = tcase_create("check_cipher.address");
tcase_add_test(tc, TestAddressVerify);
tcase_add_test(tc, TestAddressString);
tcase_add_test(tc, TestAddressBulk);
suite_add_tcase(s, tc);
tcase_set_timeout(tc, 150);

Expand Down

0 comments on commit e6596ab

Please sign in to comment.