tests: add leading zero test fixture

This commit is contained in:
Daniel Cousens 2016-10-21 13:25:25 +11:00 committed by Daniel Cousens
parent b03ce64698
commit 5e2e72dd7a
2 changed files with 42 additions and 16 deletions

View file

@ -190,7 +190,21 @@
"fingerprint": "1a87677b",
"address": "KyDarNhq8WK8rSU36UY7bDv9MAwdpKFZYKPN89Geh2dUwHjTqVh5"
},
"children": []
"children": [
{
"description": "m/44'/0'/0'/0/0'",
"wif": "L3z3MSqZtDQ1FPHKi7oWf1nc9rMEGFtZUDCoFa7n4F695g5qZiSu",
"pubKey": "027c3591221e28939e45f8ea297d62c3640ebb09d7058b01d09c963d984a40ad49",
"chainCode": "ca27553aa89617e982e621637d6478f564b32738f8bbe2e48d0a58a8e0f6da40",
"base58": "xpub6GcBnm7FfDg5ERWACCvtuotN6Tdoc37r3SZ1asBHvCWzPkqWn3MVKPWKzy6GsfmdMUGanR3D12dH1cp5tJauuubwc4FAJDn67SH2uUjwAT1",
"base58Priv": "xprvA3cqPFaMpr7n1wRh6BPtYfwdYRoKCaPzgDdQnUmgMrz1WxWNEW3EmbBr9ieh9BJAsRGKFPLvotb4p4Aq79jddUVKPVJt7exVzLHcv777JVf",
"identifier": "e371d69b5dae6eacee832a130ee9f55545275a09",
"fingerprint": "e371d69b",
"address": "1MjcmArHeqorgm9uJi4kPNQ6CbsrmCtASH",
"index": 2147483648,
"depth": 5
}
]
},
{
"network": "litecoin",

View file

@ -247,6 +247,16 @@ describe('HDNode', function () {
describe('derive', function () {
function verifyVector (hd, v, depth) {
if (hd.isNeutered()) {
assert.strictEqual(hd.toBase58(), v.base58)
} else {
assert.strictEqual(hd.neutered().toBase58(), v.base58)
assert.strictEqual(hd.toBase58(), v.base58Priv)
}
assert.strictEqual(hd.getFingerprint().toString('hex'), v.fingerprint)
assert.strictEqual(hd.getIdentifier().toString('hex'), v.identifier)
assert.strictEqual(hd.getAddress(), v.address)
assert.strictEqual(hd.keyPair.toWIF(), v.wif)
assert.strictEqual(hd.keyPair.getPublicKeyBuffer().toString('hex'), v.pubKey)
assert.strictEqual(hd.chainCode.toString('hex'), v.chainCode)
@ -259,19 +269,6 @@ describe('HDNode', function () {
var hd = HDNode.fromSeedHex(f.master.seed, network)
var master = hd
// FIXME: test data is only testing Private -> private for now
f.children.forEach(function (c, i) {
it(c.description + ' from ' + f.master.fingerprint, function () {
if (c.hardened) {
hd = hd.deriveHardened(c.m)
} else {
hd = hd.derive(c.m)
}
verifyVector(hd, c, i + 1)
})
})
// testing deriving path from master
f.children.forEach(function (c) {
it(c.description + ' from ' + f.master.fingerprint + ' by path', function () {
@ -279,8 +276,8 @@ describe('HDNode', function () {
var child = master.derivePath(path)
var pathSplit = path.split('/').slice(1)
var pathNotM = pathSplit.join('/')
var childNotM = master.derivePath(pathNotM)
var pathNoM = pathSplit.join('/')
var childNotM = master.derivePath(pathNoM)
verifyVector(child, c, pathSplit.length)
verifyVector(childNotM, c, pathSplit.length)
@ -307,6 +304,21 @@ describe('HDNode', function () {
})
})
})
// FIXME: test data is only testing Private -> private for now
f.children.forEach(function (c, i) {
if (c.m === undefined) return
it(c.description + ' from ' + f.master.fingerprint, function () {
if (c.hardened) {
hd = hd.deriveHardened(c.m)
} else {
hd = hd.derive(c.m)
}
verifyVector(hd, c, i + 1)
})
})
})
it('works for Private -> public (neutered)', function () {