Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
move TestPubKeyToAddress2 from lib/cgo/tests/check_cipher.crypto.c to lib/cgo/tests/check_cipher.crypto.common.c
ref #34
  • Loading branch information
Alvaro Denis committed May 16, 2019
1 parent 80c1c02 commit df99fa2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 29 deletions.
29 changes: 0 additions & 29 deletions lib/cgo/tests/check_cipher.crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,34 +59,6 @@ START_TEST(TestPubKeyToAddress)
}
END_TEST

START_TEST(TestPubKeyToAddress2)
{
cipher__PubKey p;
cipher__SecKey s;
cipher__Address addr;
GoString_ addrStr;
int i;
GoUint32 errorcode;

for (i = 0; i < 1024; i++) {
SKY_cipher_GenerateKeyPair(&p, &s);
SKY_cipher_AddressFromPubKey(&p, &addr);
//func (self Address) Verify(key PubKey) error
errorcode = SKY_cipher_Address_Verify(&addr, &p);
ck_assert(errorcode == SKY_OK);
SKY_cipher_Address_String(&addr, &addrStr);
unsigned char buff[50];
GoString addrStr_tmp = {buff, 0};
addrStr_tmp.p = addrStr.p;
addrStr_tmp.n = addrStr.n;
registerMemCleanup((void*)addrStr.p);
errorcode = SKY_cipher_DecodeBase58Address(addrStr_tmp, &addr);
//func DecodeBase58Address(addr string) (Address, error)
ck_assert(errorcode == SKY_OK);
}
}
END_TEST

START_TEST(TestSecKeyFromHex)
{
unsigned char buff[50];
Expand Down Expand Up @@ -698,7 +670,6 @@ Suite* cipher_crypto(void)
tc = tcase_create("cipher.crypto");
tcase_add_checked_fixture(tc, setup, teardown);
tcase_add_test(tc, TestPubKeyRipemd160);
tcase_add_test(tc, TestPubKeyToAddress2);
tcase_add_test(tc, TestSecKeyFromHex);
tcase_add_test(tc, TestMustSecKeyFromHex);
tcase_add_test(tc, TestSecKeyVerify);
Expand Down
29 changes: 29 additions & 0 deletions lib/cgo/tests/check_cipher.crypto.common.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,34 @@ START_TEST(TestPubKeyVerifyDefault1)
}
END_TEST

START_TEST(TestPubKeyToAddress2)
{
cipher__PubKey p;
cipher__SecKey s;
cipher__Address addr;
GoString_ addrStr;
int i;
GoUint32 errorcode;

for (i = 0; i < 1024; i++) {
SKY_cipher_GenerateKeyPair(&p, &s);
SKY_cipher_AddressFromPubKey(&p, &addr);
//func (self Address) Verify(key PubKey) error
errorcode = SKY_cipher_Address_Verify(&addr, &p);
ck_assert(errorcode == SKY_OK);
SKY_cipher_Address_String(&addr, &addrStr);
unsigned char buff[50];
GoString addrStr_tmp = {buff, 0};
addrStr_tmp.p = addrStr.p;
addrStr_tmp.n = addrStr.n;
registerMemCleanup((void*)addrStr.p);
errorcode = SKY_cipher_DecodeBase58Address(addrStr_tmp, &addr);
//func DecodeBase58Address(addr string) (Address, error)
ck_assert(errorcode == SKY_OK);
}
}
END_TEST

// define test suite and cases
Suite *common_check_cipher_crypto(void)
{
Expand All @@ -182,6 +210,7 @@ Suite *common_check_cipher_crypto(void)
tcase_add_test(tc, TestPubKeyVerify);
tcase_add_test(tc, TestPubKeyVerifyNil);
tcase_add_test(tc, TestPubKeyVerifyDefault1);
tcase_add_test(tc, TestPubKeyToAddress2);
suite_add_tcase(s, tc);
tcase_set_timeout(tc, 150);

Expand Down

0 comments on commit df99fa2

Please sign in to comment.