diff --git a/lib/cgo/coin.transactions.go b/lib/cgo/coin.transactions.go index 08cd47040..742a45bd5 100644 --- a/lib/cgo/coin.transactions.go +++ b/lib/cgo/coin.transactions.go @@ -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 { @@ -756,4 +761,4 @@ func SKY_coin_GetTransactionObject(handle C.Transaction__Handle, _pptx **C.coin_ *_pptx = (*C.coin__Transaction)(unsafe.Pointer(ptx)) } return -} \ No newline at end of file +} diff --git a/lib/cgo/tests/check_cipher.address.c b/lib/cgo/tests/check_cipher.address.c index a5cae3fae..3929d8618 100644 --- a/lib/cgo/tests/check_cipher.address.c +++ b/lib/cgo/tests/check_cipher.address.c @@ -5,8 +5,8 @@ #include #include "libskycoin.h" -#include "skyerrors.h" #include "skyassert.h" +#include "skyerrors.h" #include "skystring.h" #include "skytest.h" diff --git a/lib/cgo/tests/check_cipher.bip32.bip32.c b/lib/cgo/tests/check_cipher.bip32.bip32.c index 1ecfd1ede..2997624f5 100755 --- a/lib/cgo/tests/check_cipher.bip32.bip32.c +++ b/lib/cgo/tests/check_cipher.bip32.bip32.c @@ -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); @@ -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; @@ -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)); @@ -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 @@ -256,10 +275,12 @@ 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); @@ -267,10 +288,10 @@ void testVectorKeyPairs(testMasterKey vector) 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); @@ -278,21 +299,25 @@ void testVectorKeyPairs(testMasterKey vector) 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); @@ -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); diff --git a/lib/cgo/tests/check_cipher.crypto.common.c b/lib/cgo/tests/check_cipher.crypto.common.c index 21b788288..250fb064f 100644 --- a/lib/cgo/tests/check_cipher.crypto.common.c +++ b/lib/cgo/tests/check_cipher.crypto.common.c @@ -1,12 +1,12 @@ #include #include -#include #include "libskycoin.h" -#include "skyerrors.h" #include "skyassert.h" +#include "skyerrors.h" #include "skystring.h" #include "skytest.h" +#include START_TEST(TestNewPubKey) { @@ -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; } - diff --git a/lib/cgo/tests/check_cipher.hash.c b/lib/cgo/tests/check_cipher.hash.c index 03aeb2bf5..ca51d2948 100644 --- a/lib/cgo/tests/check_cipher.hash.c +++ b/lib/cgo/tests/check_cipher.hash.c @@ -11,7 +11,6 @@ extern void freshSumSHA256(GoSlice bytes, cipher__SHA256* sha256); - START_TEST(TestSumSHA256) { GoUint8 bbuff[257]; diff --git a/lib/cgo/tests/check_cipher.hash.common.c b/lib/cgo/tests/check_cipher.hash.common.c index 1aa9f87a7..126abe115 100644 --- a/lib/cgo/tests/check_cipher.hash.common.c +++ b/lib/cgo/tests/check_cipher.hash.common.c @@ -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); diff --git a/lib/cgo/tests/check_params.distribution.c b/lib/cgo/tests/check_params.distribution.c index 51f16001c..7aa2c262c 100644 --- a/lib/cgo/tests/check_params.distribution.c +++ b/lib/cgo/tests/check_params.distribution.c @@ -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); diff --git a/lib/cgo/tests/check_util.droplet.c b/lib/cgo/tests/check_util.droplet.c index 675164e44..b17f21e41 100644 --- a/lib/cgo/tests/check_util.droplet.c +++ b/lib/cgo/tests/check_util.droplet.c @@ -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}, @@ -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]; @@ -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); } diff --git a/lib/cgo/tests/cipher.testsuite.c b/lib/cgo/tests/cipher.testsuite.c index 6f2d7bda5..d4b59d10d 100644 --- a/lib/cgo/tests/cipher.testsuite.c +++ b/lib/cgo/tests/cipher.testsuite.c @@ -387,7 +387,7 @@ void ValidateSeedData(SeedTestData* seedData, InputTestData* inputData) { cipher__PubKey pubkey; cipher__SecKey seckey; - GoSlice keys; + GoSlice_ keys; // Force allocation of memory for slice buffer keys.len = keys.cap = 0;