Skip to content

Commit

Permalink
[libc][cgo] refs #105 Finalized test cipher.bip32
Browse files Browse the repository at this point in the history
  • Loading branch information
Maykel Arias Torres committed Sep 5, 2019
1 parent bf5265d commit 1667a59
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 30 deletions.
4 changes: 4 additions & 0 deletions include/skyerrors.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@
#define SKY_ErrMaxDepthReached 0x02000043
#define SKY_ErrInvalidCoinType 0x02000044
#define SKY_ErrInvalidAccount 0x02000045
#define SKY_ErrPathNoMaster 0x02000046
#define SKY_ErrPathChildMaster 0x02000047
#define SKY_ErrPathNodeNotNumber 0x02000048
#define SKY_ErrPathNodeNumberTooLarge 0x02000049

// cli error codes
#define SKY_ErrTemporaryInsufficientBalance 0x03000000
Expand Down
13 changes: 13 additions & 0 deletions lib/cgo/libsky_error.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,15 @@ const (
SKY_ErrInvalidCoinType
// ErrInvalidAccount account is >= 0x80000000
SKY_ErrInvalidAccount
// bip32.path
// SKY_ErrPathNoMaster HD wallet path does not start with m
SKY_ErrPathNoMaster
// SKY_ErrPathChildMaster HD wallet path contains m in a child node
SKY_ErrPathChildMaster
// SKY_ErrPathNodeNotNumber HD wallet path node is not a valid uint32 number
SKY_ErrPathNodeNotNumber
// SKY_ErrPathNodeNumberTooLarge HD wallet path node is >= 2^31
SKY_ErrPathNodeNumberTooLarge
)

// Error codes defined in cli package
Expand Down Expand Up @@ -634,6 +643,10 @@ var (
bip32.ErrMaxDepthReached: SKY_ErrMaxDepthReached,
bip44.ErrInvalidCoinType: SKY_ErrInvalidCoinType,
bip44.ErrInvalidAccount: SKY_ErrInvalidAccount,
bip32.ErrPathNoMaster: SKY_ErrPathNoMaster,
bip32.ErrPathChildMaster: SKY_ErrPathChildMaster,
bip32.ErrPathNodeNotNumber: SKY_ErrPathNodeNotNumber,
bip32.ErrPathNodeNumberTooLarge: SKY_ErrPathNodeNumberTooLarge,
}
)

Expand Down
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 @@ -115,9 +115,9 @@ Suite* common_check_cipher_address(void)

tc = tcase_create("cipher.address.common");
tcase_add_checked_fixture(tc, setup, teardown);
// tcase_add_test(tc, TestAddressFromBytes);
// tcase_add_test(tc, TestAddressVerify);
// tcase_add_test(tc, TestAddressNull);
tcase_add_test(tc, TestAddressFromBytes);
tcase_add_test(tc, TestAddressVerify);
tcase_add_test(tc, TestAddressNull);
suite_add_tcase(s, tc);
tcase_set_timeout(tc, 150);

Expand Down
67 changes: 67 additions & 0 deletions lib/cgo/tests/check_cipher.bip32.bip32.c
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,72 @@ START_TEST(TestCantCreateHardenedPublicChild)
ck_assert_int_eq(err, SKY_ErrHardenedChildPublicKey);
}
END_TEST

typedef struct
{
GoString seed;
GoString path;
GoString key;
GoUint32 err;
} cases_Str;


START_TEST(TestNewPrivateKeyFromPath)
{
cases_Str cases[MAXBUFFER];
// 0
cases[0].seed.p = "6162636465666768696A6B6C6D6E6F707172737475767778797A";
cases[0].seed.n = 52;
cases[0].path.p = "m";
cases[0].path.n = 1;
cases[0].key.p = "xprv9s21ZrQH143K3GfuLFf1UxUB4GzmFav1hrzTG1bPorBTejryu4YfYVxZn6LNmwfvsi6uj1Wyv9vLDPsfKDuuqwEqYier1ZsbgWVd9NCieNv";
cases[0].key.n = 111;
cases[0].err = SKY_OK;
// 1
cases[1].seed.p = "6162636465666768696A6B6C6D6E6F707172737475767778797A";
cases[1].seed.n = 52;
cases[1].path.p = "m/1'";
cases[1].path.n = 4;
cases[1].key.p = "xprv9uWf8oyvCHcAUg3kSjSroz67s7M3qJRWmNcdVwYGf91GFsaAatsVVp1bjH7z3WiWevqB7WK92B415oBwcahjoMvvb4mopPyqZUDeVW4168c";
cases[1].key.n = 111;
cases[1].err = SKY_OK;
// 2
cases[2].seed.p = "6162636465666768696A6B6C6D6E6F707172737475767778797A";
cases[2].seed.n = 52;
cases[2].path.p = "m/1'/foo";
cases[2].path.n = 8;
cases[2].key.p = "";
cases[2].key.n = 0;
cases[2].err = SKY_ErrPathNodeNotNumber;
// 3
cases[3].seed.p = "6162";
cases[3].seed.n = 4;
cases[3].path.p = "m/1";
cases[3].path.n = 3;
cases[3].key.p = "";
cases[3].key.n = 0;
cases[3].err = SKY_ErrInvalidSeedLength;

for (size_t i = 0; i < 4; i++) {
cases_Str tc = cases[i];
GoUint8 bufferseed[MAXBUFFER];
GoSlice seed = {bufferseed, 0, MAXBUFFER};
GoUint32 err = SKY_base58_String2Hex(tc.seed, &seed);
ck_assert(err == SKY_OK);

PrivateKey__Handle k = 0;
err = SKY_bip32_NewPrivateKeyFromPath(seed, tc.path, &k);
ck_assert(err == tc.err);
if (err == SKY_OK) {
GoUint8 bufferk_string[MAXBUFFER];
GoString k_string = {bufferk_string, 0};
err = SKY_bip32_PrivateKey_String(k, &k_string);
ck_assert(err == SKY_OK);
ck_assert(isGoStringEq(tc.key, k_string));
}
}
}
END_TEST
Suite* cipher_bip32(void)
{
Suite* s = suite_create("Load cipher.bip32");
Expand All @@ -1056,6 +1122,7 @@ Suite* cipher_bip32(void)
tcase_add_test(tc, TestDeserializePrivateInvalidStrings);
tcase_add_test(tc, TestDeserializePublicInvalidStrings);
tcase_add_test(tc, TestCantCreateHardenedPublicChild);
tcase_add_test(tc, TestNewPrivateKeyFromPath);
suite_add_tcase(s, tc);
tcase_set_timeout(tc, 150);

Expand Down
18 changes: 9 additions & 9 deletions lib/cgo/tests/check_coin.transactions.c
Original file line number Diff line number Diff line change
Expand Up @@ -1169,15 +1169,15 @@ Suite* coin_transaction_fork(void)

tc = tcase_create("coin.transaction_fork");
tcase_add_checked_fixture(tc, setup, teardown);
// #if __linux__
// tcase_add_test_raise_signal(tc, TestTransactionPushInput, SKY_ABORT);
// tcase_add_test_raise_signal(tc, TestTransactionSignInputs, SKY_ABORT);
// tcase_add_test_raise_signal(tc, TestTransactionVerifyInput, SKY_ABORT);
// #elif __APPLE__
// tcase_add_exit_test(tc, TestTransactionPushInput, SKY_ABORT);
// tcase_add_exit_test(tc, TestTransactionSignInputs, SKY_ABORT);
// tcase_add_test_raise_signal(tc, TestTransactionVerifyInput, SKY_ABORT);
// #endif
#if __linux__
tcase_add_test_raise_signal(tc, TestTransactionPushInput, SKY_ABORT);
tcase_add_test_raise_signal(tc, TestTransactionSignInputs, SKY_ABORT);
tcase_add_test_raise_signal(tc, TestTransactionVerifyInput, SKY_ABORT);
#elif __APPLE__
tcase_add_exit_test(tc, TestTransactionPushInput, SKY_ABORT);
tcase_add_exit_test(tc, TestTransactionSignInputs, SKY_ABORT);
tcase_add_test_raise_signal(tc, TestTransactionVerifyInput, SKY_ABORT);
#endif
suite_add_tcase(s, tc);
tcase_set_timeout(tc, 150);
return s;
Expand Down
36 changes: 18 additions & 18 deletions lib/cgo/tests/test_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,25 @@ int main(void)
int number_failed_fork = 0;
SRunner* sr = srunner_create(common_check_cipher_address());
SRunner* sr_fork = srunner_create(coin_transaction_fork());
// srunner_add_suite(sr, common_check_cipher_hash());
// srunner_add_suite(sr, common_check_cipher_crypto());
// srunner_add_suite(sr, cipher_bitcoin());
// srunner_add_suite(sr, cipher_crypto());
// srunner_add_suite(sr, cipher_secp256k1());
// srunner_add_suite(sr, cipher_encrypt_scrypt_chacha20poly1305());
// srunner_add_suite(sr, cipher_hash());
// srunner_add_suite(sr, check_cipher_address());
srunner_add_suite(sr, common_check_cipher_hash());
srunner_add_suite(sr, common_check_cipher_crypto());
srunner_add_suite(sr, cipher_bitcoin());
srunner_add_suite(sr, cipher_crypto());
srunner_add_suite(sr, cipher_secp256k1());
srunner_add_suite(sr, cipher_encrypt_scrypt_chacha20poly1305());
srunner_add_suite(sr, cipher_hash());
srunner_add_suite(sr, check_cipher_address());
srunner_add_suite(sr, cipher_bip32());
// srunner_add_suite(sr, cipher_bip44());
// srunner_add_suite(sr, coin_blocks());
// srunner_add_suite(sr, coin_coin());
// srunner_add_suite(sr, coin_math());
// srunner_add_suite(sr, coin_output());
// srunner_add_suite(sr, coin_transaction());
// srunner_add_suite(sr, param_distribution());
// srunner_add_suite(sr, util_droplet());
// srunner_add_suite(sr, util_fee());
// srunner_add_suite(sr, cipher_testsuite());
srunner_add_suite(sr, cipher_bip44());
srunner_add_suite(sr, coin_blocks());
srunner_add_suite(sr, coin_coin());
srunner_add_suite(sr, coin_math());
srunner_add_suite(sr, coin_output());
srunner_add_suite(sr, coin_transaction());
srunner_add_suite(sr, param_distribution());
srunner_add_suite(sr, util_droplet());
srunner_add_suite(sr, util_fee());
srunner_add_suite(sr, cipher_testsuite());
srunner_set_fork_status(sr, CK_NOFORK);
srunner_set_fork_status(sr_fork, CK_FORK);
srunner_run_all(sr, CK_VERBOSE);
Expand Down

0 comments on commit 1667a59

Please sign in to comment.