From c7d04418b0213fba5e692bdaa717a54635d2d204 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Mon, 18 Aug 2014 18:11:30 -0400 Subject: [PATCH] fix backup restore + tests --- js/models/core/Wallet.js | 17 ++++++++++------- test/test.Wallet.js | 5 +++++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/js/models/core/Wallet.js b/js/models/core/Wallet.js index 545ae4b55..bcce3a6b4 100644 --- a/js/models/core/Wallet.js +++ b/js/models/core/Wallet.js @@ -1611,12 +1611,12 @@ Wallet.prototype.updateIndexes = function(callback) { Wallet.prototype.updateIndex = function(index, callback) { var self = this; var SCANN_WINDOW = 20; - self.indexDiscovery(index.changeIndex, true, index.cosigner, SCANN_WINDOW, function(err, changeIndex) { + self.indexDiscovery(index.changeIndex, true, index.copayerIndex, SCANN_WINDOW, function(err, changeIndex) { if (err) return callback(err); if (changeIndex != -1) index.changeIndex = changeIndex + 1; - self.indexDiscovery(index.receiveIndex, false, index.cosigner, SCANN_WINDOW, function(err, receiveIndex) { + self.indexDiscovery(index.receiveIndex, false, index.copayerIndex, SCANN_WINDOW, function(err, receiveIndex) { if (err) return callback(err); if (receiveIndex != -1) index.receiveIndex = receiveIndex + 1; @@ -1625,12 +1625,13 @@ Wallet.prototype.updateIndex = function(index, callback) { }); } -Wallet.prototype.deriveAddresses = function(index, amount, isChange, cosigner) { - preconditions.checkArgument(cosigner); +Wallet.prototype.deriveAddresses = function(index, amount, isChange, copayerIndex) { + preconditions.checkArgument(amount); + preconditions.shouldBeDefined(copayerIndex); var ret = new Array(amount); for (var i = 0; i < amount; i++) { - ret[i] = this.publicKeyRing.getAddress(index + i, isChange, cosigner).toString(); + ret[i] = this.publicKeyRing.getAddress(index + i, isChange, copayerIndex).toString(); } return ret; } @@ -1638,7 +1639,9 @@ Wallet.prototype.deriveAddresses = function(index, amount, isChange, cosigner) { // This function scans the publicKeyRing branch starting at index @start and reports the index with last activity, // using a scan window of @gap. The argument @change defines the branch to scan: internal or external. // Returns -1 if no activity is found in range. -Wallet.prototype.indexDiscovery = function(start, change, cosigner, gap, cb) { +Wallet.prototype.indexDiscovery = function(start, change, copayerIndex, gap, cb) { + preconditions.shouldBeDefined(copayerIndex); + preconditions.checkArgument(gap); var scanIndex = start; var lastActive = -1; var hasActivity = false; @@ -1648,7 +1651,7 @@ Wallet.prototype.indexDiscovery = function(start, change, cosigner, gap, cb) { function _do(next) { // Optimize window to minimize the derivations. var scanWindow = (lastActive == -1) ? gap : gap - (scanIndex - lastActive) + 1; - var addresses = self.deriveAddresses(scanIndex, scanWindow, change, cosigner); + var addresses = self.deriveAddresses(scanIndex, scanWindow, change, copayerIndex); self.blockchain.checkActivity(addresses, function(err, actives) { if (err) throw err; diff --git a/test/test.Wallet.js b/test/test.Wallet.js index 52cb41297..dae8de607 100644 --- a/test/test.Wallet.js +++ b/test/test.Wallet.js @@ -814,6 +814,9 @@ describe('Wallet model', function() { }); sinon.assert.callCount(updateIndex, 4); + sinon.assert.calledWith(updateIndex, w.publicKeyRing.indexes[0] ); + sinon.assert.calledWith(updateIndex, w.publicKeyRing.indexes[1] ); + sinon.assert.calledWith(updateIndex, w.publicKeyRing.indexes[2] ); w.updateIndex.restore(); done(); }); @@ -837,6 +840,8 @@ describe('Wallet model', function() { index.receiveIndex.should.equal(9); index.changeIndex.should.equal(9); indexDiscovery.callCount.should.equal(2); + sinon.assert.calledWith(indexDiscovery, 1, true, 2, 20 ); + sinon.assert.calledWith(indexDiscovery, 2, false, 2, 20 ); w.indexDiscovery.restore(); done(); });