Skip to content

Commit

Permalink
[test-libsky] refs fibercrypto#116 Correcting parse and declare type …
Browse files Browse the repository at this point in the history
…data
  • Loading branch information
Maykel Arias Torres committed Jan 31, 2020
1 parent 98382c3 commit 5d2efdb
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 32 deletions.
1 change: 0 additions & 1 deletion include/coin.outputs.go.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,4 @@ typedef struct {
void* data;
GoInt_ len;
GoInt_ cap;
GoInt_ a;
} coin__UxArray;
8 changes: 6 additions & 2 deletions lib/cgo/coin.block.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,12 @@ func SKY_coin_NewBlockHeader(_prev *C.coin__BlockHeader, _uxHash *C.cipher__SHA2
}

//export SKY_coin_BlockHeader_Hash
func SKY_coin_BlockHeader_Hash(_bh *C.coin__BlockHeader, _arg0 *C.cipher__SHA256) (____error_code uint32) {
bh := (*coin.BlockHeader)(unsafe.Pointer(_bh))
func SKY_coin_BlockHeader_Hash(_bh C.BlockHeader__Handle, _arg0 *C.cipher__SHA256) (____error_code uint32) {
bh, ok := lookupBlockHeaderHandle(_bh)
if !ok {
____error_code = SKY_BAD_HANDLE
return
}
__arg0 := bh.Hash()
*_arg0 = *(*C.cipher__SHA256)(unsafe.Pointer(&__arg0))
return
Expand Down
11 changes: 7 additions & 4 deletions lib/cgo/tests/check_cipher.bip32.bip32.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,12 @@ void testVectorKeyPairs(testMasterKey vector)
ck_assert(isGoString_toGoStringEq(pub_Fringerprint_tmp, tck.fingerprint));
ck_assert(isGoString_toGoStringEq(pub_Fringerprint_tmp, tck.fingerprint));

err = SKY_bip32_PrivateKey_Identifier(&privkey, &privIdentifier);
err = SKY_bip32_PrivateKey_Identifier(&privkey, &privIdentifier_tmp);
ck_assert_int_eq(SKY_OK, err);
err = SKY_bip32_PublicKey_Identifier(&pubkey, &pubIdentifier);
copyGoSlice_toGoSlice(&privIdentifier, &privIdentifier_tmp, privIdentifier_tmp.len);
err = SKY_bip32_PublicKey_Identifier(&pubkey, &pubIdentifier_tmp);
ck_assert_int_eq(SKY_OK, err);
copyGoSlice_toGoSlice(&pubIdentifier, &pubIdentifier_tmp, pubIdentifier_tmp.len);
err = SKY_base58_Hex2String(privIdentifier, &priv_Identifier);
ck_assert_int_eq(SKY_OK, err);
err = SKY_base58_Hex2String(pubIdentifier, &pub_Identifier);
Expand Down Expand Up @@ -986,13 +988,14 @@ START_TEST(TestDeserializePrivateInvalidStrings)

for (size_t i = 0; i < 12; i++) {
tests_Struct test = tests[i];
GoUint8 bufferb_tmp[MAXBUFFER];
GoUint8 bufferb[MAXBUFFER];
GoSlice_ b_tmp = {bufferb, 0, MAXBUFFER};
GoSlice_ b_tmp = {bufferb_tmp, 0, MAXBUFFER};
GoUint32 err = SKY_base58_Decode(test.base58, &b_tmp);
ck_assert_int_eq(err, SKY_OK);

PrivateKey__Handle rest_priv = 0;
GoSlice b;
GoSlice b = {bufferb, 0, MAXBUFFER};
copyGoSlice_toGoSlice(&b, &b_tmp, b_tmp.len);
err = SKY_bip32_DeserializePrivateKey(b, &rest_priv);
ck_assert_int_eq(err, test.err);
Expand Down
6 changes: 3 additions & 3 deletions lib/cgo/tests/check_cipher.bip44.bip44.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ START_TEST(TestNewCoin)
err = SKY_bip44_Coin_Account(&c, 0, &account);
ck_assert_int_eq(err, SKY_OK);
GoUint8 bufferAccStr[1024];
GoString acc_string = {bufferAccStr, 0};
GoString_ acc_string = {bufferAccStr, 0};
err = SKY_bip44_Account_String(account, &acc_string);
ck_assert_int_eq(err, SKY_OK);
ck_assert_str_eq(acc_string.p, "xprv9yKAFQtFghZSe4mfdpdqFm1WWmGeQbYMB4MSGUB85zbKGQgSxty4duZb8k6hNoHVd2UR7Y3QhWU3rS9wox9ewgVG7gDLyYTL4yzEuqUCjvF");
Expand All @@ -68,7 +68,7 @@ START_TEST(TestNewCoin)
err = SKY_bip32_PrivateKey_Publickey(privk, &pubk);
ck_assert_int_eq(err, SKY_OK);
GoUint8 bufferPubKStr[1024];
GoString pubk_string = {bufferPubKStr, 0};
GoString_ pubk_string = {bufferPubKStr, 0};
err = SKY_bip32_PublicKey_String(&pubk, &pubk_string);
ck_assert_int_eq(err, SKY_OK);
ck_assert_str_eq(pubk_string.p, "xpub6CJWevR9X57jrYr8jrAqctxF4o78p4GCYHH34rajeL8J9D1bWSHKBht4yzwiTQ4FP4HyQpx99iLxvU54rbEbcxBUgxzTGGudBVXb1N2gcHF");
Expand Down Expand Up @@ -98,7 +98,7 @@ START_TEST(TestNewCoin)
err = SKY_bip44_Account_External(&account, &external);
ck_assert_int_eq(err, SKY_OK);
GoUint8 bufferPrivKStr[1024];
GoString privk_string = {bufferPrivKStr, 0};
GoString_ privk_string = {bufferPrivKStr, 0};
err = SKY_bip32_PrivateKey_String(&external, &privk_string);
ck_assert_int_eq(err, SKY_OK);
ck_assert_str_eq(privk_string.p, "xprv9zjsvjLiqSerDzbeRXPeXwz8tuQ7eRUABkgFAgLPHw1KzGKkgBhJhGaMYHM8j2KDXBZTCv4m19qjxrrD7gusrtdpZ7xzJywdXHaMZEjf3Uv");
Expand Down
24 changes: 13 additions & 11 deletions lib/cgo/tests/check_cipher.bitcoin.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ START_TEST(TestBitcoinAddress)
error = SKY_cipher_PubKeyFromHex(*pubKeyStr, &pubkey);
ck_assert_msg(error == SKY_OK, "Create PubKey from Hex");

GoString str = {NULL, 0};
GoString_ str = {buff, 0};
SKY_cipher_BitcoinAddressFromPubKey(&pubkey, &btcAddr);
SKY_cipher_BitcoinAddress_String(&btcAddr, &str);
ck_assert(isGoStringEq(*addrStr, str));
ck_assert_str_eq(addrStr->p, str.p);

error = SKY_cipher_BitcoinAddressFromSecKey(&seckey, &btcAddr);
ck_assert(error == SKY_OK);
GoString_ tmpstr = {buff, 0};

SKY_cipher_BitcoinAddress_String(&btcAddr, &str);
ck_assert(isGoStringEq(*addrStr, str));
ck_assert_str_eq(addrStr->p, str.p);
}
}
END_TEST
Expand Down Expand Up @@ -234,22 +234,24 @@ START_TEST(TestBitcoinWIFRoundTrip)
SKY_cipher_GenerateKeyPair(&pubkey, &seckey);
GoUint8 wip1_buff[50];
GoUint8 wip2_buff[50];
GoString wip1 = {wip1_buff, 0};
SKY_cipher_BitcoinWalletImportFormatFromSeckey(&seckey, &wip1);
GoString_ wip1_tmp = {wip1_buff, 0};
SKY_cipher_BitcoinWalletImportFormatFromSeckey(&seckey, &wip1_tmp);
cipher__SecKey seckey2;
GoUint32 err;
GoString wip1 = {wip1_buff, 0};
copyGoStringtoGoString_(&wip1, &wip1_tmp);
err = SKY_cipher_SecKeyFromBitcoinWalletImportFormat(wip1, &seckey2);
ck_assert(err == SKY_OK);
GoString wip2 = {wip2_buff, 0};
GoString_ wip2 = {wip2_buff, 0};
SKY_cipher_BitcoinWalletImportFormatFromSeckey(&seckey2, &wip2);
ck_assert(isSecKeyEq(&seckey, &seckey2));

GoString seckeyhex1;
GoString seckeyhex2;
GoString_ seckeyhex1;
GoString_ seckeyhex2;
SKY_cipher_SecKey_Hex(&seckey, &seckeyhex1);
SKY_cipher_SecKey_Hex(&seckey2, &seckeyhex2);
ck_assert(isGoStringEq(seckeyhex1, seckeyhex2));
ck_assert(isGoStringEq(wip1, wip2));
ck_assert_str_eq(seckeyhex1.p, seckeyhex2.p);
ck_assert_str_eq(wip1_tmp.p, wip2.p);
}
END_TEST

Expand Down
10 changes: 5 additions & 5 deletions lib/cgo/tests/check_coin.block.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ GoUint32 makeNewBlock(cipher__SHA256* uxHash, Block__Handle* newBlock)
BlockBody__Handle body = 0;
result = SKY_coin_GetBlockBody(block, &body);
ck_assert_msg(result == SKY_OK, "SKY_coin_Get_Block_Body failed");
result = SKY_coin_BlockBody_Hash(&body, &bodyhash);
result = SKY_coin_BlockBody_Hash(body, &bodyhash);
ck_assert_msg(result == SKY_OK, "SKY_coin_BlockBody_Hash failed");
FeeCalculator zf = {zeroFeeCalculator, NULL};
result = SKY_coin_NewBlock(&block, 100 + 200, uxHash, &transactions, &zf, newBlock);
Expand Down Expand Up @@ -162,7 +162,7 @@ START_TEST(TestBlockHashHeader)
coin__BlockHeader* pblockheader = NULL;
result = SKY_coin_Block_GetBlockHeader(block, &blockheader);
ck_assert_msg(result == SKY_OK, "SKY_coin_Block_GetBlockHeader failed");
result = SKY_coin_BlockHeader_Hash(&blockheader, &hash2);
result = SKY_coin_BlockHeader_Hash(blockheader, &hash2);
ck_assert_msg(result == SKY_OK, "SKY_coin_BlockHeader_Hash failed");
ck_assert(isU8Eq(hash1, hash2, sizeof(cipher__SHA256)));
strcpy(hash2, "");
Expand Down Expand Up @@ -192,7 +192,7 @@ START_TEST(TestBlockHashBody)
BlockBody__Handle blockbody = 0;
result = SKY_coin_GetBlockBody(block, &blockbody);
ck_assert_msg(result == SKY_OK, "SKY_coin_GetBlockBody failed");
result = SKY_coin_BlockBody_Hash(&blockbody, &hash2);
result = SKY_coin_BlockBody_Hash(blockbody, &hash2);
ck_assert_msg(result == SKY_OK, "SKY_coin_BlockBody_Hash failed");
ck_assert(isU8Eq(hash1, hash2, sizeof(cipher__SHA256)));
}
Expand Down Expand Up @@ -351,8 +351,8 @@ START_TEST(TestCreateUnspents)
bh.Time = time(0);
bh.BkSeq = 1;

// GoUint8_ bufferuxs[1024];
// coin__UxArray uxs = {bufferuxs, 0, sizeof(bufferuxs)};
GoUint8_ bufferuxs[1024];
coin__UxArray uxs = {bufferuxs, 0, sizeof(bufferuxs)};
// result = SKY_coin_CreateUnspents(&bh, &handle, &uxs);
// ck_assert_msg(result == SKY_OK, "SKY_coin_CreateUnspents failed");
// registerMemCleanup(uxs.data);
Expand Down
24 changes: 21 additions & 3 deletions lib/cgo/tests/check_coin.outputs.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

START_TEST(TestUxBodyHash)
{
printf("TestUxBodyHash\n");
GoUint32 result;
coin__UxBody uxbody;
result = makeUxBody(&uxbody);
Expand All @@ -26,6 +27,7 @@ END_TEST

START_TEST(TestUxOutHash)
{
printf("TestUxOutHash\n");
int result;
coin__UxBody uxbody;
result = makeUxBody(&uxbody);
Expand Down Expand Up @@ -53,6 +55,7 @@ END_TEST

START_TEST(TestUxOutSnapshotHash)
{
printf("TestUxOutSnapshotHash\n");
GoUint32 result;
coin__UxOut uxout, uxout2;
result = makeUxOut(&uxout);
Expand Down Expand Up @@ -100,6 +103,7 @@ END_TEST

START_TEST(TestUxOutCoinHours)
{
printf("TestUxOutCoinHours\n");
GoUint64 _genCoins = 1000000000;
GoUint64 _genCoinHours = 1000 * 1000;

Expand Down Expand Up @@ -214,6 +218,7 @@ END_TEST

START_TEST(TestUxArrayCoins)
{
printf("TestUxArrayCoins\n");
coin__UxArray uxs;
int result = makeUxArray(&uxs, 4);
ck_assert_msg(result == SKY_OK, "makeUxArray failed");
Expand All @@ -231,6 +236,7 @@ END_TEST

START_TEST(TestUxArrayCoinHours)
{
printf("TestUxArrayCoinHours\n");
coin__UxArray uxs;
int result = makeUxArray(&uxs, 4);
ck_assert_msg(result == SKY_OK, "makeUxArray failed");
Expand Down Expand Up @@ -260,6 +266,7 @@ END_TEST

START_TEST(TestUxArrayHashArray)
{
printf("TestUxArrayHashArray\n");
coin__UxArray uxs;
int result = makeUxArray(&uxs, 4);
ck_assert_msg(result == SKY_OK, "makeUxArray failed");
Expand All @@ -286,6 +293,7 @@ END_TEST

START_TEST(TestUxArrayHasDupes)
{
printf("TestUxArrayHasDupes\n");
coin__UxArray uxs;
int result = makeUxArray(&uxs, 4);
ck_assert_msg(result == SKY_OK, "makeUxArray failed");
Expand All @@ -304,6 +312,7 @@ END_TEST

START_TEST(TestUxArraySub)
{
printf("TestUxArraySub\n");
int result, equal;
coin__UxArray uxa, uxb, uxc, uxd;
coin__UxArray t1, t2, t3, t4;
Expand Down Expand Up @@ -396,6 +405,7 @@ int isUxArraySorted(coin__UxArray* uxa)

START_TEST(TestUxArraySorting)
{
printf("TestUxArraySorting\n");
int result;
coin__UxArray uxa;
result = makeUxArray(&uxa, 4);
Expand All @@ -419,6 +429,7 @@ END_TEST

START_TEST(TestUxArrayLen)
{
printf("TestUxArrayLen\n");
int result;
coin__UxArray uxa;
result = makeUxArray(&uxa, 4);
Expand All @@ -433,6 +444,7 @@ END_TEST

START_TEST(TestUxArrayLess)
{
printf("TestUxArrayLess\n");
int result;
coin__UxArray uxa;
result = makeUxArray(&uxa, 2);
Expand Down Expand Up @@ -461,6 +473,7 @@ END_TEST

START_TEST(TestUxArraySwap)
{
printf("TestUxArraySwap\n");
int result;
coin__UxArray uxa;
result = makeUxArray(&uxa, 2);
Expand Down Expand Up @@ -489,6 +502,7 @@ END_TEST

START_TEST(TestAddressUxOutsKeys)
{
printf("TestAddressUxOutsKeys\n");
int result;
int test_count = 3;
coin__UxOut uxs[test_count];
Expand All @@ -502,7 +516,7 @@ START_TEST(TestAddressUxOutsKeys)
result = SKY_coin_NewAddressUxOuts(&uxa, &uxOutsHandle);
ck_assert_msg(result == SKY_OK, "SKY_coin_NewAddressUxOuts failed");
GoSlice_ keys = {NULL, 0, 0};
result = SKY_coin_AddressUxOuts_Keys(uxOutsHandle, &keys);
result = SKY_coin_AddressUxOuts_Keys(&uxOutsHandle, &keys);
ck_assert_msg(result == SKY_OK, "SKY_coin_AddressUxOuts_Keys failed");
registerMemCleanup(keys.data);
ck_assert(keys.len == test_count);
Expand Down Expand Up @@ -534,6 +548,7 @@ END_TEST

START_TEST(TestAddressUxOutsSub)
{
printf("TestAddressUxOutsSub\n");
int result;
coin__UxArray uxa, empty;
makeUxArray(&uxa, 4);
Expand Down Expand Up @@ -565,7 +580,7 @@ START_TEST(TestAddressUxOutsSub)
result = SKY_coin_AddressUxOuts_Set(h2, &(pData + 2)->Body.Address, &ux6);
ck_assert_msg(result == SKY_OK, "SKY_coin_AddressUxOut_Set failed");

result = SKY_coin_AddressUxOuts_Sub(h1, h2, &h3);
result = SKY_coin_AddressUxOuts_Sub(&h1, &h2, &h3);
ck_assert_msg(result == SKY_OK, "SKY_coin_AddressUxOut_Sub failed");
registerHandleClose(h3);

Expand Down Expand Up @@ -623,6 +638,7 @@ END_TEST

START_TEST(TestAddressUxOutsAdd)
{
printf("TestAddressUxOutsAdd\n");
int result;
coin__UxArray uxa, empty;
makeUxArray(&uxa, 4);
Expand Down Expand Up @@ -729,6 +745,7 @@ END_TEST

START_TEST(TestAddressUxOutsFlatten)
{
printf("TestAddressUxOutsFlatten\n");
int result;
coin__UxArray uxa, emptyArray;
makeUxArray(&uxa, 3);
Expand All @@ -752,7 +769,7 @@ START_TEST(TestAddressUxOutsFlatten)

coin__UxArray flatArray;
memset(&flatArray, 0, sizeof(coin__UxArray));
result = SKY_coin_AddressUxOuts_Flatten(h, &flatArray);
result = SKY_coin_AddressUxOuts_Flatten(&h, &flatArray);
ck_assert_msg(result == SKY_OK, "SKY_coin_AddressUxOuts_Flatten failed");
registerMemCleanup(flatArray.data);
ck_assert(flatArray.len == 3);
Expand Down Expand Up @@ -785,6 +802,7 @@ END_TEST

START_TEST(TestNewAddressUxOuts)
{
printf("TestNewAddressUxOuts\n");
int result;
coin__UxArray uxa, ux2;
makeUxArray(&uxa, 6);
Expand Down
6 changes: 3 additions & 3 deletions lib/cgo/tests/check_coin.transactions.c
Original file line number Diff line number Diff line change
Expand Up @@ -619,12 +619,12 @@ START_TEST(TestTransactionSerialization)
makeTransaction(&handle);
unsigned char buffer[1024];
unsigned char buffer_tmp[1024];
GoSlice d = {buffer, 0, 1024};
coin__UxArray d_tmp = {buffer_tmp, 0, 1024};
GoSlice_ d_tmp = {buffer_tmp, 0, 1024};
result = SKY_coin_Transaction_Serialize(&handle, &d_tmp);
ck_assert(result == SKY_OK);
Transaction__Handle handle2 = 0;
copycoin_UxArraytoGoSlice(&d, &d_tmp, sizeof(d_tmp));
GoSlice d = {buffer, 0, 1024};
copyGoSlice_toGoSlice(&d, &d_tmp, sizeof(d_tmp));
result = SKY_coin_DeserializeTransaction(d, &handle2);
ck_assert(result == SKY_OK);
ck_assert(isTransactionHandleEq(&handle, &handle2));
Expand Down

0 comments on commit 5d2efdb

Please sign in to comment.