From 7a61526705a26199fc3121f2e3e6cf0a2cf3b43f Mon Sep 17 00:00:00 2001 From: Karel Bilek Date: Sat, 6 Feb 2016 02:02:39 +0100 Subject: [PATCH] Testing path derivation I am taking description field for the path. --- test/fixtures/hdnode.json | 4 ++-- test/hdnode.js | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/test/fixtures/hdnode.json b/test/fixtures/hdnode.json index 93530d2..5de3c0e 100644 --- a/test/fixtures/hdnode.json +++ b/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", diff --git a/test/hdnode.js b/test/hdnode.js index 4e9f1cf..0eaed4d 100644 --- a/test/hdnode.js +++ b/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 () {