add forPath and tests

This commit is contained in:
Matias Alejo Garcia 2014-07-30 11:59:07 -03:00
parent a10e6f4908
commit 96a5f0aeb8
2 changed files with 32 additions and 0 deletions

View File

@ -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);

View File

@ -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);
});
});