Skip to content

Commit

Permalink
[libc] refs fibercrypto#105 Finalized suite test cipher.bip32
Browse files Browse the repository at this point in the history
  • Loading branch information
Maykel Arias Torres committed Sep 28, 2019
1 parent 2030f0c commit c1cbcd9
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 92 deletions.
7 changes: 6 additions & 1 deletion lib/cgo/coin.transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,11 @@ func SKY_coin_Transaction_Serialize(handle C.Transaction__Handle, _arg0 *C.GoSli
//export SKY_coin_TransactionDeserialize
func SKY_coin_TransactionDeserialize(_b []byte, _arg1 *C.Transaction__Handle) (____error_code uint32) {
b := *(*[]byte)(unsafe.Pointer(&_b))

if b == nil {
____error_code = SKY_BAD_HANDLE
return
}
__arg1, ____return_err := coin.DeserializeTransaction(b)
____error_code = libErrorCode(____return_err)
if ____return_err == nil {
Expand Down Expand Up @@ -756,4 +761,4 @@ func SKY_coin_GetTransactionObject(handle C.Transaction__Handle, _pptx **C.coin_
*_pptx = (*C.coin__Transaction)(unsafe.Pointer(ptx))
}
return
}
}
2 changes: 1 addition & 1 deletion lib/cgo/tests/check_cipher.address.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#include <string.h>

#include "libskycoin.h"
#include "skyerrors.h"
#include "skyassert.h"
#include "skyerrors.h"
#include "skystring.h"
#include "skytest.h"

Expand Down
139 changes: 82 additions & 57 deletions lib/cgo/tests/check_cipher.bip32.bip32.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ void testVectorKeyPairs(testMasterKey vector)
{
// Decode master seed into hex
GoUint8 bufferseed[MAXBUFFER];
GoSlice seed = {bufferseed, 0, MAXBUFFER};
GoSlice_ seed = {bufferseed, 0, MAXBUFFER};
GoUint32 err = SKY_base58_String2Hex(vector.seed, &seed);
ck_assert_int_eq(err, SKY_OK);

Expand Down Expand Up @@ -120,89 +120,106 @@ void testVectorKeyPairs(testMasterKey vector)

GoUint8 bufferstringPrivKey[1024];
GoUint8 bufferstringPubKey[1024];
GoString stringPrivKey = {bufferstringPrivKey, 0};
GoString stringPubKey = {bufferstringPubKey, 0};
GoString_ stringPrivKey = {bufferstringPrivKey, 0};
GoString_ stringPubKey = {bufferstringPubKey, 0};
err = SKY_bip32_PrivateKey_String(privkey, &stringPrivKey);
ck_assert_int_eq(err, SKY_OK);
ck_assert(isGoStringEq(stringPrivKey, vector.privkey));
ck_assert(isGoString_toGoStringEq(stringPrivKey, vector.privkey));
err = SKY_bip32_PublicKey_String(pubkey, &stringPubKey);
ck_assert_int_eq(err, SKY_OK);
ck_assert(isGoStringEq(stringPubKey, vector.pubKey));
ck_assert(isGoString_toGoStringEq(stringPubKey, vector.pubKey));

GoUint8 bufferhexPubKey[1024];
GoString hexPubKey = {bufferhexPubKey, 0};
GoString_ hexPubKey = {bufferhexPubKey, 0};
GoUint8 bufferpubkey[MAXBUFFER];
GoSlice slicepubkey = {bufferpubkey, 0, MAXBUFFER};
err = SKY_bip32_PublicKey_GetKey(pubkey, &slicepubkey);
GoSlice_ slicepubkey_tmp = {bufferpubkey, 0, MAXBUFFER};
err = SKY_bip32_PublicKey_GetKey(pubkey, &slicepubkey_tmp);
ck_assert_int_eq(err, SKY_OK);
GoSlice slicepubkey;
copyGoSlice_toGoSlice(&slicepubkey, &slicepubkey_tmp, slicepubkey_tmp.len);
err = SKY_base58_Hex2String(slicepubkey, &hexPubKey);
ck_assert_int_eq(err, SKY_OK);
ck_assert(isGoStringEq(vector.hexPubKey, hexPubKey));
ck_assert(isGoString_toGoStringEq(hexPubKey, vector.hexPubKey));

cipher__SecKey tempSec;
GoUint8 bufferprivkey[MAXBUFFER];
GoSlice sliceprivkey = {bufferprivkey, 0, MAXBUFFER};
err = SKY_bip32_PrivateKey_GetKey(privkey, &sliceprivkey);
GoSlice_ sliceprivkey_tmp = {bufferprivkey, 0, MAXBUFFER};
err = SKY_bip32_PrivateKey_GetKey(privkey, &sliceprivkey_tmp);
ck_assert_int_eq(err, SKY_OK);
GoSlice sliceprivkey;
copyGoSlice_toGoSlice(&sliceprivkey, &sliceprivkey_tmp, sliceprivkey_tmp.len);
err = SKY_cipher_NewSecKey(sliceprivkey, &tempSec);
ck_assert_int_eq(err, SKY_OK);
GoUint8 bufferwif[1024];
GoString wif = {bufferwif, 0};
GoString_ wif = {bufferwif, 0};
SKY_cipher_BitcoinWalletImportFormatFromSeckey(&tempSec, &wif);
ck_assert(isGoStringEq(wif, vector.wifPrivKey));
ck_assert(isGoString_toGoStringEq(wif, vector.wifPrivKey));

GoUint8 bufferprivChainCode[MAXBUFFER];
GoUint8 bufferpubChainCode[MAXBUFFER];
GoSlice privChainCode = {bufferprivChainCode, 0, MAXBUFFER};
GoSlice pubChainCode = {bufferpubChainCode, 0, MAXBUFFER};
err = SKY_bip32_PrivateKey_GetChainCode(privkey, &privChainCode);
GoSlice_ privChainCode_tmp = {bufferprivChainCode, 0, MAXBUFFER};
GoSlice_ pubChainCode_tmp = {bufferpubChainCode, 0, MAXBUFFER};
err = SKY_bip32_PrivateKey_GetChainCode(privkey, &privChainCode_tmp);
ck_assert_int_eq(SKY_OK, err);
err = SKY_bip32_PublicKey_GetChainCode(pubkey, &pubChainCode);
err = SKY_bip32_PublicKey_GetChainCode(pubkey, &pubChainCode_tmp);
ck_assert_int_eq(SKY_OK, err);
GoString priv_ChainCode = {bufferprivChainCode, 0};
GoString pub_ChainCode = {bufferpubChainCode, 0};
GoString_ priv_ChainCode = {bufferprivChainCode, 0};
GoString_ pub_ChainCode = {bufferpubChainCode, 0};
GoSlice privChainCode;
GoSlice pubChainCode;
copyGoSlice_toGoSlice(&privChainCode, &privChainCode_tmp, privChainCode_tmp.len);
err = SKY_base58_Hex2String(privChainCode, &priv_ChainCode);
ck_assert_int_eq(SKY_OK, err);
ck_assert(isGoStringEq(vector.chainCode, priv_ChainCode));
ck_assert(isGoString_toGoStringEq(priv_ChainCode, vector.chainCode));
copyGoSlice_toGoSlice(&pubChainCode, &pubChainCode_tmp, pubChainCode_tmp.len);
err = SKY_base58_Hex2String(pubChainCode, &pub_ChainCode);
ck_assert_int_eq(SKY_OK, err);
ck_assert(isGoStringEq(vector.chainCode, pub_ChainCode));
ck_assert(isGoString_toGoStringEq(pub_ChainCode, vector.chainCode));

GoUint8 bufferprivFringerprint[MAXBUFFER];
GoUint8 bufferpubFringerprint[MAXBUFFER];
GoSlice privFringerprint = {bufferprivFringerprint, 0, MAXBUFFER};
GoSlice pubFringerprint = {bufferpubFringerprint, 0, MAXBUFFER};
GoSlice_ privFringerprint_tmp = {bufferprivFringerprint, 0, MAXBUFFER};
GoSlice_ pubFringerprint_tmp = {bufferpubFringerprint, 0, MAXBUFFER};
GoUint8 bufferpriv_Fringerprint[MAXBUFFER];
GoString priv_Fringerprint = {bufferpriv_Fringerprint, 0};
GoUint8 bufferpub_Fringerprint[MAXBUFFER];
GoString pub_Fringerprint = {bufferpub_Fringerprint, 0};
err = SKY_bip32_PrivateKey_Fingerprint(privkey, &privFringerprint);
err = SKY_bip32_PrivateKey_Fingerprint(privkey, &privFringerprint_tmp);
ck_assert_int_eq(SKY_OK, err);
err = SKY_bip32_PublicKey_Fingerprint(pubkey, &pubFringerprint);
err = SKY_bip32_PublicKey_Fingerprint(pubkey, &pubFringerprint_tmp);
ck_assert_int_eq(SKY_OK, err);
err = SKY_base58_Hex2String(privFringerprint, &priv_Fringerprint);
GoSlice privFringerprint;
copyGoSlice_toGoSlice(&privFringerprint, &privFringerprint_tmp, privFringerprint_tmp.len);
GoSlice pubFringerprint;

GoString_ priv_Fringerprint_tmp;
GoString_ pub_Fringerprint_tmp;
err = SKY_base58_Hex2String(privFringerprint, &priv_Fringerprint_tmp);
ck_assert_int_eq(SKY_OK, err);
err = SKY_base58_Hex2String(pubFringerprint, &pub_Fringerprint);
copyGoSlice_toGoSlice(&pubFringerprint, &pubFringerprint_tmp, pubFringerprint_tmp.len);
err = SKY_base58_Hex2String(pubFringerprint, &pub_Fringerprint_tmp);
ck_assert_int_eq(SKY_OK, err);
ck_assert(isGoStringEq(vector.fingerprint, priv_Fringerprint));
ck_assert(isGoStringEq(vector.fingerprint, pub_Fringerprint));

GoUint8 bufferprivIdentifier[1024];
GoUint8 bufferpubIdentifier[1024];
GoSlice privIdentifier = {bufferprivIdentifier, 0, 1024};
GoSlice pubIdentifier = {bufferpubIdentifier, 0, 1024};
GoString priv_Identifier = {bufferprivIdentifier, 0};
GoString pub_Identifier = {bufferpubIdentifier, 0};
err = SKY_bip32_PrivateKey_Identifier(privkey, &privIdentifier);
ck_assert(isGoString_toGoStringEq(priv_Fringerprint_tmp, vector.fingerprint));
ck_assert(isGoString_toGoStringEq(pub_Fringerprint_tmp, vector.fingerprint));

GoSlice_ privIdentifier_tmp;
GoSlice_ pubIdentifier_tmp;
GoString_ priv_Identifier;
GoString_ pub_Identifier;
err = SKY_bip32_PrivateKey_Identifier(privkey, &privIdentifier_tmp);
ck_assert_int_eq(SKY_OK, err);
err = SKY_bip32_PublicKey_Identifier(pubkey, &pubIdentifier);
err = SKY_bip32_PublicKey_Identifier(pubkey, &pubIdentifier_tmp);
ck_assert_int_eq(SKY_OK, err);
GoSlice privIdentifier;
GoSlice pubIdentifier;
copyGoSlice_toGoSlice(&privIdentifier, &privIdentifier_tmp, privIdentifier_tmp.len);
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);
ck_assert_int_eq(SKY_OK, err);
ck_assert(isGoStringEq(vector.identifier, priv_Identifier));
ck_assert(isGoStringEq(vector.identifier, pub_Identifier));
ck_assert(isGoString_toGoStringEq(priv_Identifier, vector.identifier));
ck_assert(isGoString_toGoStringEq(pub_Identifier, vector.identifier));

GoUint8 privDepth;
GoUint8 pubDepth;
Expand All @@ -226,10 +243,12 @@ void testVectorKeyPairs(testMasterKey vector)
assertPrivateKeySerialization(privkey, vector.privkey);
assertPublicKeySerialization(pubkey, vector.pubKey);

GoSlice b58pk;
err = SKY_base58_Decode(vector.privkey, &b58pk);
GoSlice_ b58pk_tmp;
err = SKY_base58_Decode(vector.privkey, &b58pk_tmp);
ck_assert_int_eq(SKY_OK, err);
PrivateKey__Handle privKey2 = 0;
GoSlice b58pk;
copyGoSlice_toGoSlice(&b58pk, &b58pk_tmp, b58pk_tmp.len);
err = SKY_bip32_DeserializePrivateKey(b58pk, &privKey2);
ck_assert_int_eq(SKY_OK, err);
ck_assert(isPrivateKeyEq(privkey, privKey2));
Expand All @@ -246,7 +265,7 @@ void testVectorKeyPairs(testMasterKey vector)
printf("Iter %d\n", i);
testChildKey tck = vector.children[i];
privkey = 0;
err = SKY_bip32_NewPrivateKeyFromPath(seed, tck.path, &privkey);
err = SKY_bip32_NewPrivateKeyFromPath(sliceseed, tck.path, &privkey);
ck_assert_int_eq(SKY_OK, err);

// Get this private key's public key
Expand All @@ -256,43 +275,49 @@ void testVectorKeyPairs(testMasterKey vector)

// Test DeserializePrivateKey
GoUint8 bufferppk[MAXBUFFER];
GoSlice ppk = {bufferppk, 0, MAXBUFFER};
err = SKY_base58_Decode(tck.privKey, &ppk);
GoSlice_ ppk_tmp = {bufferppk, 0, MAXBUFFER};
err = SKY_base58_Decode(tck.privKey, &ppk_tmp);
ck_assert_int_eq(SKY_OK, err);
PrivateKey__Handle xx = 0;
GoSlice ppk;
copyGoSlice_toGoSlice(&ppk, &ppk_tmp, ppk_tmp.len);
err = SKY_bip32_DeserializePrivateKey(ppk, &xx);
ck_assert_int_eq(SKY_OK, err);

ck_assert(isPrivateKeyEq(xx, privkey));

err = SKY_bip32_PrivateKey_String(privkey, &stringPrivKey);
ck_assert_int_eq(err, SKY_OK);
ck_assert(isGoStringEq(stringPrivKey, tck.privKey));
ck_assert(isGoString_toGoStringEq(stringPrivKey, tck.privKey));
err = SKY_bip32_PublicKey_String(pubkey, &stringPubKey);
ck_assert_int_eq(err, SKY_OK);
ck_assert(isGoStringEq(stringPubKey, tck.pubKey));
ck_assert(isGoString_toGoStringEq(stringPubKey, tck.pubKey));

err = SKY_bip32_PrivateKey_GetChainCode(privkey, &privChainCode);
ck_assert_int_eq(SKY_OK, err);
err = SKY_bip32_PublicKey_GetChainCode(pubkey, &pubChainCode);
ck_assert_int_eq(SKY_OK, err);
err = SKY_base58_Hex2String(privChainCode, &priv_ChainCode);
ck_assert_int_eq(SKY_OK, err);
ck_assert(isGoStringEq(tck.chainCode, priv_ChainCode));
ck_assert(isGoString_toGoStringEq(priv_ChainCode, tck.chainCode));
err = SKY_base58_Hex2String(pubChainCode, &pub_ChainCode);
ck_assert_int_eq(SKY_OK, err);
ck_assert(isGoStringEq(tck.chainCode, pub_ChainCode));
ck_assert(isGoString_toGoStringEq(pub_ChainCode, tck.chainCode));

err = SKY_bip32_PrivateKey_Fingerprint(privkey, &privFringerprint);
GoSlice_ privFringerprint_tmp;
err = SKY_bip32_PrivateKey_Fingerprint(privkey, &privFringerprint_tmp);
ck_assert_int_eq(SKY_OK, err);
err = SKY_bip32_PublicKey_Fingerprint(pubkey, &pubFringerprint);
GoSlice_ pubFringerprint_tmp;
err = SKY_bip32_PublicKey_Fingerprint(pubkey, &pubFringerprint_tmp);
ck_assert_int_eq(SKY_OK, err);
err = SKY_base58_Hex2String(privFringerprint, &priv_Fringerprint);
copyGoSlice_toGoSlice(&privFringerprint, &privFringerprint_tmp, privFringerprint_tmp.len);
err = SKY_base58_Hex2String(privFringerprint, &priv_Fringerprint_tmp);
ck_assert_int_eq(SKY_OK, err);
err = SKY_base58_Hex2String(pubFringerprint, &pub_Fringerprint);
copyGoSlice_toGoSlice(&pubFringerprint, &pubFringerprint_tmp, pubFringerprint_tmp.len);
err = SKY_base58_Hex2String(pubFringerprint, &pub_Fringerprint_tmp);
ck_assert_int_eq(SKY_OK, err);
ck_assert(isGoStringEq(tck.fingerprint, priv_Fringerprint));
ck_assert(isGoStringEq(tck.fingerprint, pub_Fringerprint));
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);
ck_assert_int_eq(SKY_OK, err);
Expand All @@ -302,8 +327,8 @@ void testVectorKeyPairs(testMasterKey vector)
ck_assert_int_eq(SKY_OK, err);
err = SKY_base58_Hex2String(pubIdentifier, &pub_Identifier);
ck_assert_int_eq(SKY_OK, err);
ck_assert(isGoStringEq(tck.identifier, priv_Identifier));
ck_assert(isGoStringEq(tck.identifier, pub_Identifier));
ck_assert(isGoString_toGoStringEq(priv_Identifier, tck.identifier));
ck_assert(isGoString_toGoStringEq(pub_Identifier, tck.identifier));

err = SKY_bip32_PrivateKey_GetDepth(privkey, &privDepth);
ck_assert_int_eq(SKY_OK, err);
Expand Down
43 changes: 21 additions & 22 deletions lib/cgo/tests/check_cipher.crypto.common.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#include <stdio.h>
#include <stdlib.h>

#include <check.h>
#include "libskycoin.h"
#include "skyerrors.h"
#include "skyassert.h"
#include "skyerrors.h"
#include "skystring.h"
#include "skytest.h"
#include <check.h>

START_TEST(TestNewPubKey)
{
Expand Down Expand Up @@ -312,25 +312,24 @@ START_TEST(TestPubKeyFromSecKey)
END_TEST

// define test suite and cases
Suite *common_check_cipher_crypto(void)
Suite* common_check_cipher_crypto(void)
{
Suite *s = suite_create("Load common check_cipher.crypto");
TCase *tc;

tc = tcase_create("check_cipher.crypto");
tcase_add_test(tc, TestNewPubKey);
tcase_add_test(tc, TestPubKeyFromHex);
tcase_add_test(tc, TestPubKeyHex);
tcase_add_test(tc, TestPubKeyVerify);
tcase_add_test(tc, TestPubKeyVerifyNil);
tcase_add_test(tc, TestPubKeyVerifyDefault1);
tcase_add_test(tc, TestNewSig);
tcase_add_test(tc, TestMustSigFromHex);
tcase_add_test(tc, TestSigHex);
tcase_add_test(tc, TestPubKeyFromSecKey);
suite_add_tcase(s, tc);
tcase_set_timeout(tc, 150);

return s;
Suite* s = suite_create("Load common check_cipher.crypto");
TCase* tc;

tc = tcase_create("check_cipher.crypto");
tcase_add_test(tc, TestNewPubKey);
tcase_add_test(tc, TestPubKeyFromHex);
tcase_add_test(tc, TestPubKeyHex);
tcase_add_test(tc, TestPubKeyVerify);
tcase_add_test(tc, TestPubKeyVerifyNil);
tcase_add_test(tc, TestPubKeyVerifyDefault1);
tcase_add_test(tc, TestNewSig);
tcase_add_test(tc, TestMustSigFromHex);
tcase_add_test(tc, TestSigHex);
tcase_add_test(tc, TestPubKeyFromSecKey);
suite_add_tcase(s, tc);
tcase_set_timeout(tc, 150);

return s;
}

1 change: 0 additions & 1 deletion lib/cgo/tests/check_cipher.hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
extern void freshSumSHA256(GoSlice bytes, cipher__SHA256* sha256);



START_TEST(TestSumSHA256)
{
GoUint8 bbuff[257];
Expand Down
4 changes: 1 addition & 3 deletions lib/cgo/tests/check_cipher.hash.common.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,8 @@ START_TEST(TestSHA256FromHex)
ck_assert(error == SKY_ErrInvalidHexLength);

// Valid hex hash
GoString s2;
memset(&s2, 0, sizeof(GoString_));
GoString_ s2;
SKY_cipher_SHA256_Hex(&h, &s2);
registerMemCleanup((void*)s2.p);
cipher__SHA256 h2;
GoString tmps2 = {s2.p, s2.n};
error = SKY_cipher_SHA256FromHex(tmps2, &h2);
Expand Down
6 changes: 3 additions & 3 deletions lib/cgo/tests/check_params.distribution.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

START_TEST(TestDistributionAddressArrays)
{
GoSlice all = {NULL, 0, 0};
GoSlice unlocked = {NULL, 0, 0};
GoSlice locked = {NULL, 0, 0};
GoSlice_ all = {NULL, 0, 0};
GoSlice_ unlocked = {NULL, 0, 0};
GoSlice_ locked = {NULL, 0, 0};
Distribution__Handle dist = 0;
GoUint32 err = SKY_params_Distribution_GetMainNetDistribution(&dist);
ck_assert_int_eq(err, SKY_OK);
Expand Down
5 changes: 2 additions & 3 deletions lib/cgo/tests/check_util.droplet.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ START_TEST(TestToString)
{
char buffer[BUFFER_SIZE];
char bufferNull[BUFFER_SIZE];
GoString s = {buffer, 0};
GoString_ s = {buffer, 0};
tmpstruct cases[] = {
{.s = {"0.000000", 8}, .n = 0, .e = SKY_OK},
{.s = {"0.000001", 8}, .n = 1, .e = SKY_OK},
Expand All @@ -207,7 +207,6 @@ START_TEST(TestToString)
};
int len = (sizeof(cases) / sizeof(tmpstruct));

GoString nullStr = {bufferNull, 0};
int i;
for (i = 0; i < len; i++) {
tmpstruct tc = cases[i];
Expand All @@ -216,7 +215,7 @@ START_TEST(TestToString)

if (tc.e == SKY_OK) {
ck_assert(err == SKY_OK);
ck_assert(isGoStringEq(tc.s, s));
ck_assert(isGoString_toGoStringEq(s, tc.s));
} else {
ck_assert(err == tc.e);
}
Expand Down
Loading

0 comments on commit c1cbcd9

Please sign in to comment.