Browse Source

Testing path derivation

I am taking description field for the path.
hk-custom-address
Karel Bilek 9 years ago
parent
commit
7a61526705
  1. 4
      test/fixtures/hdnode.json
  2. 36
      test/hdnode.js

4
test/fixtures/hdnode.json

@ -109,7 +109,7 @@
"address": "19EuDJdgfRkwCmRzbzVBHZWQG9QNWhftbZ"
},
{
"description": "m/0/2147483647",
"description": "m/0/2147483647'",
"m": 2147483647,
"hardened": true,
"wif": "L1m5VpbXmMp57P3knskwhoMTLdhAAaXiHvnGLMribbfwzVRpz2Sr",
@ -134,7 +134,7 @@
"address": "1BxrAr2pHpeBheusmd6fHDP2tSLAUa3qsW"
},
{
"description": "m/0/2147483647'/1/2147483646",
"description": "m/0/2147483647'/1/2147483646'",
"m": 2147483646,
"hardened": true,
"wif": "L5KhaMvPYRW1ZoFmRjUtxxPypQ94m6BcDrPhqArhggdaTbbAFJEF",

36
test/hdnode.js

@ -272,6 +272,7 @@ describe('HDNode', function () {
fixtures.valid.forEach(function (f) {
var network = NETWORKS[f.network]
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) {
@ -285,6 +286,41 @@ describe('HDNode', function () {
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 () {
var path = c.description
var child = master.derivePath(path)
var pathSplit = path.split('/').slice(1)
var pathNotM = pathSplit.join('/')
var childNotM = master.derivePath(pathNotM)
verifyVector(child, c, pathSplit.length)
verifyVector(childNotM, c, pathSplit.length)
})
})
// testing deriving path from the first child
var firstChild = master.derivePath(f.children[0].description)
f.children.slice(1).forEach(function (c) {
it(c.description + ' from ' + f.children[0].fingerprint + ' by path', function () {
var path = c.description
var pathSplit = path.split('/').slice(2)
var pathEnd = pathSplit.join('/')
var pathEndM = 'm/' + path
var child = firstChild.derivePath(pathEnd)
verifyVector(child, c, pathSplit.length + 1)
assert.throws(function () {
firstChild.derivePath(pathEndM)
}, /Not a master node/)
})
})
})
it('works for Private -> public (neutered)', function () {

Loading…
Cancel
Save