Skip to content

Commit

Permalink
[test-libsky] refs fibercrypto#116 Finalized cipher.bip44
Browse files Browse the repository at this point in the history
  • Loading branch information
Maykel Arias Torres committed Jan 31, 2020
1 parent 14a0870 commit b9ab52f
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions lib/cgo/tests/check_cipher.bip44.bip44.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,24 @@ START_TEST(TestNewCoin)
GoSlice tmp = {bufferTmp, 0, 1024};
randBytes(&tmp, 3);
Coin__Handle coin = 0;
GoUint32 err = SKY_bip44_NewCoin(tmp, CoinTypeBitcoin, &coin);
GoUint32 err = SKY_bip44_NewCoin(tmp, &CoinTypeBitcoin, &coin);
ck_assert_int_eq(err, SKY_ErrInvalidSeedLength);
// bad coin_type
GoUint8 bufferBad[1024];
GoSlice Bad = {bufferBad, 0, 1024};
mustDefaultSeed(&Bad);
err = SKY_bip44_NewCoin(Bad, FirstHardenedChild, &coin);
err = SKY_bip44_NewCoin(Bad, &FirstHardenedChild, &coin);
ck_assert_int_eq(err, SKY_ErrInvalidCoinType);
err = SKY_bip44_NewCoin(Bad, (FirstHardenedChild + 1), &coin);
GoUint32_ FirstHardenedChild_tmp = FirstHardenedChild + 1;
err = SKY_bip44_NewCoin(Bad, &FirstHardenedChild_tmp, &coin);
ck_assert_int_eq(err, SKY_ErrInvalidCoinType);

Coin__Handle c = 0;
err = SKY_bip44_NewCoin(Bad, CoinTypeBitcoin, &c);
err = SKY_bip44_NewCoin(Bad, &CoinTypeBitcoin, &c);
ck_assert_int_eq(err, SKY_OK);

Account__Handle account = 0;
err = SKY_bip44_Coin_Account(c, 0, &account);
err = SKY_bip44_Coin_Account(&c, 0, &account);
ck_assert_int_eq(err, SKY_OK);
GoUint8 bufferAccStr[1024];
GoString acc_string = {bufferAccStr, 0};
Expand All @@ -68,11 +69,11 @@ START_TEST(TestNewCoin)
ck_assert_int_eq(err, SKY_OK);
GoUint8 bufferPubKStr[1024];
GoString pubk_string = {bufferPubKStr, 0};
err = SKY_bip32_PublicKey_String(pubk, &pubk_string);
err = SKY_bip32_PublicKey_String(&pubk, &pubk_string);
ck_assert_int_eq(err, SKY_OK);
ck_assert_str_eq(pubk_string.p, "xpub6CJWevR9X57jrYr8jrAqctxF4o78p4GCYHH34rajeL8J9D1bWSHKBht4yzwiTQ4FP4HyQpx99iLxvU54rbEbcxBUgxzTGGudBVXb1N2gcHF");

err = SKY_bip44_Coin_Account(c, 1, &account);
err = SKY_bip44_Coin_Account(&c, 1, &account);
ck_assert_int_eq(err, SKY_OK);
err = SKY_bip44_Account_String(account, &acc_string);
ck_assert_int_eq(err, SKY_OK);
Expand All @@ -83,33 +84,33 @@ START_TEST(TestNewCoin)
ck_assert_int_eq(err, SKY_OK);
err = SKY_bip32_PrivateKey_Publickey(privk, &pubk);
ck_assert_int_eq(err, SKY_OK);
err = SKY_bip32_PublicKey_String(pubk, &pubk_string);
err = SKY_bip32_PublicKey_String(&pubk, &pubk_string);
ck_assert_int_eq(err, SKY_OK);
ck_assert_str_eq(pubk_string.p, "xpub6CJWevR9X57jtvmjdnVJEgMPocfrPNcWQwvPUXJ6coJnzV3mx1hRgYXPmQJh5vLQvrVCY8LtJB5xLLiPJVmpSwBe2yhonQLoQuSsCF8YPLN");

Account__Handle account_temp = 0;
err = SKY_bip44_Coin_Account(c, 0x80000000, &account_temp);
err = SKY_bip44_Coin_Account(&c, 0x80000000, &account_temp);
ck_assert_int_eq(err, SKY_ErrInvalidAccount);
err = SKY_bip44_Coin_Account(c, 0x80000001, &account_temp);
err = SKY_bip44_Coin_Account(&c, 0x80000001, &account_temp);
ck_assert_int_eq(err, SKY_ErrInvalidAccount);

PrivateKey__Handle external = 0;
err = SKY_bip44_Account_External(account, &external);
err = SKY_bip44_Account_External(&account, &external);
ck_assert_int_eq(err, SKY_OK);
GoUint8 bufferPrivKStr[1024];
GoString privk_string = {bufferPrivKStr, 0};
err = SKY_bip32_PrivateKey_String(external, &privk_string);
err = SKY_bip32_PrivateKey_String(&external, &privk_string);
ck_assert_int_eq(err, SKY_OK);
ck_assert_str_eq(privk_string.p, "xprv9zjsvjLiqSerDzbeRXPeXwz8tuQ7eRUABkgFAgLPHw1KzGKkgBhJhGaMYHM8j2KDXBZTCv4m19qjxrrD7gusrtdpZ7xzJywdXHaMZEjf3Uv");
pubk = 0;
err = SKY_bip32_PrivateKey_Publickey(external, &pubk);
ck_assert_int_eq(err, SKY_OK);
err = SKY_bip32_PublicKey_String(pubk, &pubk_string);
err = SKY_bip32_PublicKey_String(&pubk, &pubk_string);
ck_assert_int_eq(err, SKY_OK);
ck_assert_str_eq(pubk_string.p, "xpub6DjELEscfpD9SUg7XYveu5vsSwEc3tC1Yybqy4jzrGYJs4euDj1ZF4tqPZYvViMn9cvBobHyubuuh69PZ1szaBBx5oxPiQzD492B6C4QDHe");

PublicKey__Handle external0 = 0;
err = SKY_bip32_PrivateKey_NewPublicChildKey(external, 0, &external0);
err = SKY_bip32_PrivateKey_NewPublicChildKey(&external, 0, &external0);
ck_assert_int_eq(err, SKY_OK);
GoUint8 bufferKey[1024];
GoUint8 bufferKeyStr[1024];
Expand All @@ -124,7 +125,7 @@ START_TEST(TestNewCoin)
ck_assert_str_eq(KeyStr.p, "034d36f3bcd74e19204e75b81b9c0726e41b799858b92bab73f4cd7498308c5c8b");

PublicKey__Handle external1 = 0;
err = SKY_bip32_PrivateKey_NewPublicChildKey(external, 1, &external1);
err = SKY_bip32_PrivateKey_NewPublicChildKey(&external, 1, &external1);
ck_assert_int_eq(err, SKY_OK);
GoUint8 bufferKey1[1024];
GoUint8 bufferKey1Str[1024];
Expand All @@ -139,20 +140,20 @@ START_TEST(TestNewCoin)
ck_assert(strncmp(Key1Str.p, "02f7309e9f559d847ee9cc9ee144cfa490791e33e908fdbde2dade50a389408b01", 66) == 0);

PrivateKey__Handle change = 0;
err = SKY_bip44_Account_Change(account, &change);
err = SKY_bip44_Account_Change(&account, &change);
ck_assert_int_eq(err, SKY_OK);
err = SKY_bip32_PrivateKey_String(change, &privk_string);
err = SKY_bip32_PrivateKey_String(&change, &privk_string);
ck_assert_int_eq(err, SKY_OK);
ck_assert(strncmp(privk_string.p, "xprv9zjsvjLiqSerGzJyBrpZgCaGpQCeFDnZEuAV714WigmFyHT4nFLhZLeuHzLNE19PgkZeQ5Uf2pjFZjQTHbkugDbmw5TAPAvgo2jsaTnZo2A", 66) == 0);
pubk = 0;
err = SKY_bip32_PrivateKey_Publickey(change, &pubk);
ck_assert_int_eq(err, SKY_OK);
err = SKY_bip32_PublicKey_String(pubk, &pubk_string);
err = SKY_bip32_PublicKey_String(&pubk, &pubk_string);
ck_assert_int_eq(err, SKY_OK);
ck_assert(strncmp(pubk_string.p, "xpub6DjELEscfpD9VUPSHtMa3LX1NS38egWQc865uPU8H2JEr5nDKnex78yP9GxhFr5cnCRgiQF1dkv7aR7moraPrv73KHwSkDaXdWookR1Sh9p", 66) == 0);

PublicKey__Handle change0 = 0;
err = SKY_bip32_PrivateKey_NewPublicChildKey(change, 0, &change0);
err = SKY_bip32_PrivateKey_NewPublicChildKey(&change, 0, &change0);
ck_assert_int_eq(err, SKY_OK);
err = SKY_bip32_PublicKey_GetKey(change0, &Key);
ck_assert_int_eq(err, SKY_OK);
Expand All @@ -161,7 +162,7 @@ START_TEST(TestNewCoin)
ck_assert(strncmp(KeyStr.p, "026d3eb891e81ecabedfa8560166af383457aedaf172af9d57d00508faa5f57c4c", 66) == 0);

PublicKey__Handle change1 = 0;
err = SKY_bip32_PrivateKey_NewPublicChildKey(change, 1, &change1);
err = SKY_bip32_PrivateKey_NewPublicChildKey(&change, 1, &change1);
ck_assert_int_eq(err, SKY_OK);
err = SKY_bip32_PublicKey_GetKey(change1, &Key1);
ck_assert_int_eq(err, SKY_OK);
Expand Down

0 comments on commit b9ab52f

Please sign in to comment.