Changeset View
Changeset View
Standalone View
Standalone View
src/test/bip32_tests.cpp
Show First 20 Lines • Show All 100 Lines • ▼ Show 20 Lines | void RunTest(const TestVector &test) { | ||||
key.SetMaster(&seed[0], seed.size()); | key.SetMaster(&seed[0], seed.size()); | ||||
pubkey = key.Neuter(); | pubkey = key.Neuter(); | ||||
for (const TestDerivation &derive : test.vDerive) { | for (const TestDerivation &derive : test.vDerive) { | ||||
uint8_t data[74]; | uint8_t data[74]; | ||||
key.Encode(data); | key.Encode(data); | ||||
pubkey.Encode(data); | pubkey.Encode(data); | ||||
// Test private key | // Test private key | ||||
CBitcoinExtKey b58key; | BOOST_CHECK(EncodeExtKey(key) == derive.prv); | ||||
b58key.SetKey(key); | // Ensure a base58 decoded key also matches | ||||
BOOST_CHECK(b58key.ToString() == derive.prv); | BOOST_CHECK(DecodeExtKey(derive.prv) == key); | ||||
CBitcoinExtKey b58keyDecodeCheck(derive.prv); | |||||
CExtKey checkKey = b58keyDecodeCheck.GetKey(); | |||||
// ensure a base58 decoded key also matches | |||||
assert(checkKey == key); | |||||
// Test public key | // Test public key | ||||
CBitcoinExtPubKey b58pubkey; | BOOST_CHECK(EncodeExtPubKey(pubkey) == derive.pub); | ||||
b58pubkey.SetKey(pubkey); | // Ensure a base58 decoded pubkey also matches | ||||
BOOST_CHECK(b58pubkey.ToString() == derive.pub); | BOOST_CHECK(DecodeExtPubKey(derive.pub) == pubkey); | ||||
CBitcoinExtPubKey b58PubkeyDecodeCheck(derive.pub); | |||||
CExtPubKey checkPubKey = b58PubkeyDecodeCheck.GetKey(); | |||||
// ensure a base58 decoded pubkey also matches | |||||
assert(checkPubKey == pubkey); | |||||
// Derive new keys | // Derive new keys | ||||
CExtKey keyNew; | CExtKey keyNew; | ||||
BOOST_CHECK(key.Derive(keyNew, derive.nChild)); | BOOST_CHECK(key.Derive(keyNew, derive.nChild)); | ||||
CExtPubKey pubkeyNew = keyNew.Neuter(); | CExtPubKey pubkeyNew = keyNew.Neuter(); | ||||
if (!(derive.nChild & 0x80000000)) { | if (!(derive.nChild & 0x80000000)) { | ||||
// Compare with public derivation | // Compare with public derivation | ||||
CExtPubKey pubkeyNew2; | CExtPubKey pubkeyNew2; | ||||
▲ Show 20 Lines • Show All 176 Lines • Show Last 20 Lines |