From 96a5f0aeb8d74ae211b404e80a5d78780493df40 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Wed, 30 Jul 2014 11:59:07 -0300 Subject: [PATCH] add forPath and tests --- js/models/core/PublicKeyRing.js | 9 +++++++++ test/test.PublicKeyRing.js | 23 +++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/js/models/core/PublicKeyRing.js b/js/models/core/PublicKeyRing.js index 2d626cf0e..823315ac9 100644 --- a/js/models/core/PublicKeyRing.js +++ b/js/models/core/PublicKeyRing.js @@ -298,6 +298,15 @@ PublicKeyRing.prototype.getForPaths = function(paths) { return paths.map(this.getForPath.bind(this)); }; + +PublicKeyRing.prototype.forPaths = function(paths) { + return { + pubKeys: paths.map(this.getForPath.bind(this)), + copayerIds: this.copayerIds, + } +}; + + // TODO this could be cached PublicKeyRing.prototype._addScriptMap = function(map, path) { var p = HDPath.indexesForPath(path); diff --git a/test/test.PublicKeyRing.js b/test/test.PublicKeyRing.js index 41d874676..fcf179691 100644 --- a/test/test.PublicKeyRing.js +++ b/test/test.PublicKeyRing.js @@ -489,4 +489,27 @@ describe('PublicKeyRing model', function() { }); }); + it('#getForPath should return 5 pubkeys', function() { + var w = getCachedW().w; + var pubkeys = w.getForPath('m/45\'/2147483647/1/0'); + pubkeys.length.should.equal(5); + }); + + it('#getForPaths should return 2 arrays of 5 pubkey ', function() { + var w = getCachedW().w; + var pubkeys = w.getForPaths([ 'm/45\'/2147483647/1/0', 'm/45\'/2147483647/1/1'] ); + pubkeys.length.should.equal(2); + pubkeys[0].length.should.equal(5); + pubkeys[1].length.should.equal(5); + }); + + it('#forPaths should return copayers and pubkeys ', function() { + var w = getCachedW().w; + var ret = w.forPaths([ 'm/45\'/2147483647/1/0', 'm/45\'/2147483647/1/1'] ); + ret.copayerIds.length.should.equal(5); + ret.pubKeys.length.should.equal(2); + ret.pubKeys[0].length.should.equal(5); + ret.pubKeys[1].length.should.equal(5); + }); + });