From fdabdc64feb5c70c970a88f965fec36f74bbb99b Mon Sep 17 00:00:00 2001 From: Yemel Jardi Date: Thu, 31 Jul 2014 16:13:27 -0300 Subject: [PATCH] Add a pre-generated address to the shared branch --- js/models/core/HDParams.js | 2 +- js/services/controllerUtils.js | 3 ++- test/mocks/FakeWallet.js | 4 ++++ test/test.PublicKeyRing.js | 14 ++++++++++---- test/test.Wallet.js | 2 +- 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/js/models/core/HDParams.js b/js/models/core/HDParams.js index 9c84108b9..6f045e679 100644 --- a/js/models/core/HDParams.js +++ b/js/models/core/HDParams.js @@ -18,7 +18,7 @@ function HDParams(opts) { HDParams.init = function(totalCopayers) { preconditions.shouldBeNumber(totalCopayers); - var ret = [new HDParams()]; + var ret = [new HDParams({receiveIndex: 1})]; for (var i = 0 ; i < totalCopayers ; i++) { ret.push(new HDParams({copayerIndex: i})); } diff --git a/js/services/controllerUtils.js b/js/services/controllerUtils.js index 7bae6bdce..f6f5fb272 100644 --- a/js/services/controllerUtils.js +++ b/js/services/controllerUtils.js @@ -185,13 +185,14 @@ angular.module('copayApp.services') root.updateAddressList = function() { var w = $rootScope.wallet; - if (w) + if (w && w.isReady()) $rootScope.addrInfos = w.getAddressesInfo(); }; root.updateBalance = function(cb) { var w = $rootScope.wallet; if (!w) return root.onErrorDigest(); + if (!w.isReady()) return; $rootScope.balanceByAddr = {}; $rootScope.updatingBalance = true; diff --git a/test/mocks/FakeWallet.js b/test/mocks/FakeWallet.js index 4c043395e..945e584e9 100644 --- a/test/mocks/FakeWallet.js +++ b/test/mocks/FakeWallet.js @@ -46,6 +46,10 @@ FakeWallet.prototype.getAddressesInfo = function() { return ret; }; +FakeWallet.prototype.isReady = function() { + return true; +} + FakeWallet.prototype.getBalance = function(cb) { return cb(null, this.balance, this.balanceByAddr, this.safeBalance); diff --git a/test/test.PublicKeyRing.js b/test/test.PublicKeyRing.js index 088c1f819..41d874676 100644 --- a/test/test.PublicKeyRing.js +++ b/test/test.PublicKeyRing.js @@ -145,9 +145,8 @@ describe('PublicKeyRing model', function() { var k = createW(); var w = k.w; - var a = w.getAddresses(); - a.length.should.equal(0); + a.length.should.equal(1); [true, false].forEach(function(isChange){ for (var i = 0; i < 2; i++) { @@ -156,15 +155,22 @@ describe('PublicKeyRing model', function() { }); var as = w.getAddressesInfo(); - as.length.should.equal(4); + as.length.should.equal(5); // include pre-generated shared one for (var j in as) { var a = as[j]; a.address.isValid().should.equal(true); a.addressStr.should.equal(a.address.toString()); - a.isChange.should.equal([false, false, true, true][j]); + a.isChange.should.equal([false, false, false, true, true][j]); } }); + + it('should start with one shared address', function() { + var k = createW(); + var a = k.w.getAddresses(); + a.length.should.equal(1); + }); + it('should count generation indexes', function() { var k = createW(); var w = k.w; diff --git a/test/test.Wallet.js b/test/test.Wallet.js index 46cc15cd8..04b1626de 100644 --- a/test/test.Wallet.js +++ b/test/test.Wallet.js @@ -594,7 +594,7 @@ describe('Wallet model', function() { it('should get balance', function(done) { - var w = createW(); + var w = createW2(); var spy = sinon.spy(w.blockchain, 'getUnspent'); w.blockchain.fixUnspent([]); w.getBalance(function(err, balance, balanceByAddr, safeBalance) {