Skip to content

Commit

Permalink
Merge pull request #2 from simelo/stdevAlDen_t108_refactor_libskycoin…
Browse files Browse the repository at this point in the history
…_assert

Refactor libskycoin assert ref #t108
  • Loading branch information
stdevMac authored Sep 17, 2019
2 parents b08948a + ca974af commit fd700e0
Show file tree
Hide file tree
Showing 6 changed files with 346 additions and 340 deletions.
6 changes: 3 additions & 3 deletions lib/cgo/tests/check_cipher.address.common.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ START_TEST(TestAddressFromBytes)
cipher__SecKey sk;
cipher__PubKey pk;
GoSlice bytes;
GoSlice_ tempBytes;
GoSlice tempBytes;
GoUint8 buff[1024];
GoUint32 err = SKY_cipher_GenerateKeyPair(&pk, &sk);
ck_assert(err == SKY_OK);
Expand All @@ -80,7 +80,7 @@ START_TEST(TestAddressFromBytes)

SKY_cipher_Address_Bytes(&addr, &tempBytes);
ck_assert_msg(tempBytes.len > 0, "address bytes written");
copyGoSlice_toGoSlice(&bytes, &tempBytes, tempBytes.len);
copyGoSlice_toGoSlice(&bytes, (GoSlice_*)&tempBytes, tempBytes.len);
err = SKY_cipher_AddressFromBytes(bytes, &addr2);
ck_assert_msg(err == SKY_OK, "convert bytes to SKY address");

Expand All @@ -101,7 +101,7 @@ START_TEST(TestAddressFromBytes)

addr.Version = 2;
SKY_cipher_Address_Bytes(&addr, &tempBytes);
copyGoSlice_toGoSlice(&bytes, &tempBytes, tempBytes.len);
copyGoSlice_toGoSlice(&bytes, (GoSlice_*)&tempBytes, tempBytes.len);
err = SKY_cipher_AddressFromBytes(bytes, &addr2);
ck_assert_msg(err == SKY_ErrAddressInvalidVersion, "Invalid version");
}
Expand Down
6 changes: 3 additions & 3 deletions lib/cgo/tests/check_cipher.crypto.common.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ START_TEST(TestPubKeyHex)

GoUint32 err = SKY_cipher_GenerateKeyPair(&p, &sk);
ck_assert(err == SKY_OK);
GoString_ tmp_s3 = {buff_s3, 0};
GoString tmp_s3 = {buff_s3, 0};
err = SKY_cipher_PubKey_Hex(&p, &tmp_s3);
ck_assert(err == SKY_OK);
s3.n = tmp_s3.n;
Expand All @@ -115,7 +115,7 @@ START_TEST(TestPubKeyHex)
ck_assert(isPubKeyEq(&p, &p2));

unsigned char s4_buff[50];
GoString_ tmp_s4 = {s4_buff, 0};
GoString tmp_s4 = {s4_buff, 0};
err = SKY_cipher_PubKey_Hex(&p2, &tmp_s4);
ck_assert(err == SKY_OK);
s4.n = s4.n;
Expand Down Expand Up @@ -263,7 +263,7 @@ START_TEST(TestSigHex)

ck_assert(errorcode == SKY_OK);
char buffer[100];
GoString_ tmp_str = {buffer, 0};
GoString tmp_str = {buffer, 0};
SKY_cipher_Sig_Hex(&s, &tmp_str);
str.p = tmp_str.p;
str.n = tmp_str.n;
Expand Down
25 changes: 25 additions & 0 deletions lib/cgo/tests/check_cipher.hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,30 @@

extern void freshSumSHA256(GoSlice bytes, cipher__SHA256* sha256);



START_TEST(TestSumSHA256)
{
GoUint8 bbuff[257];
GoUint8 cbuff[257];
GoSlice b = {bbuff, 0, 257};
cipher__SHA256 h1;
// randBytes(&b, 256);
SKY_cipher_RandByte(256, &b);
SKY_cipher_SumSHA256(b, &h1);
cipher__SHA256 tmp = "";
ck_assert_int_eq(isU8Eq(h1, tmp, 32), 0);
GoSlice c = {cbuff, 0, 257};
randBytes(&c, 256);
cipher__SHA256 h2;
SKY_cipher_SumSHA256(c, &h2);
ck_assert_int_eq(isU8Eq(h1, tmp, 32), 0);
cipher__SHA256 tmp_h2;
freshSumSHA256(c, &tmp_h2);
ck_assert(isU8Eq(h2, tmp_h2, 32));
}
END_TEST

START_TEST(TestRipemd160Set)
{
cipher__Ripemd160 h;
Expand Down Expand Up @@ -144,6 +168,7 @@ Suite* cipher_hash(void)

tc = tcase_create("cipher.hash");
tcase_add_checked_fixture(tc, setup, teardown);
tcase_add_test(tc, TestSumSHA256);
tcase_add_test(tc, TestRipemd160Set);
tcase_add_test(tc, TestDoubleSHA256);
tcase_add_test(tc, TestXorSHA256);
Expand Down
27 changes: 2 additions & 25 deletions lib/cgo/tests/check_cipher.hash.common.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ START_TEST(TestSHA256KnownValue)

SKY_cipher_SumSHA256(slice_input, &sha);

GoString_ tmp_output;
GoString tmp_output;

SKY_cipher_SHA256_Hex(&sha, &tmp_output);
registerMemCleanup((void*)tmp_output.p);
Expand All @@ -111,28 +111,6 @@ START_TEST(TestSHA256KnownValue)
}
END_TEST

START_TEST(TestSumSHA256)
{
GoUint8 bbuff[257];
GoUint8 cbuff[257];
GoSlice b = {bbuff, 0, 257};
cipher__SHA256 h1;
// randBytes(&b, 256);
SKY_cipher_RandByte(256, &b);
SKY_cipher_SumSHA256(b, &h1);
cipher__SHA256 tmp = "";
ck_assert_int_eq(isU8Eq(h1, tmp, 32), 0);
GoSlice c = {cbuff, 0, 257};
randBytes(&c, 256);
cipher__SHA256 h2;
SKY_cipher_SumSHA256(c, &h2);
ck_assert_int_eq(isU8Eq(h1, tmp, 32), 0);
cipher__SHA256 tmp_h2;
freshSumSHA256(c, &tmp_h2);
ck_assert(isU8Eq(h2, tmp_h2, 32));
}
END_TEST

START_TEST(TestSHA256Hex)
{
cipher__SHA256 h;
Expand Down Expand Up @@ -210,7 +188,7 @@ START_TEST(TestSHA256FromHex)
ck_assert(error == SKY_ErrInvalidHexLength);

// Valid hex hash
GoString_ s2;
GoString s2;
memset(&s2, 0, sizeof(GoString_));
SKY_cipher_SHA256_Hex(&h, &s2);
registerMemCleanup((void*)s2.p);
Expand Down Expand Up @@ -250,7 +228,6 @@ Suite* common_check_cipher_hash(void)
tcase_add_test(tc, TestAddSHA256);
tcase_add_test(tc, TestHashRipemd160);
tcase_add_test(tc, TestSHA256KnownValue);
tcase_add_test(tc, TestSumSHA256);
tcase_add_test(tc, TestSHA256Hex);
tcase_add_test(tc, TestSHA256FromHex);
tcase_add_test(tc, TestSHA256Null);
Expand Down
Loading

0 comments on commit fd700e0

Please sign in to comment.