From 2f990f42a8cf1b7b4a8fcab8b90f93537d6dc44f Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Tue, 27 Oct 2015 15:38:11 -0300 Subject: [PATCH] test --- lib/errors/errordefinitions.js | 1 + lib/server.js | 4 +++- test/integration/server.js | 26 ++++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/lib/errors/errordefinitions.js b/lib/errors/errordefinitions.js index 93fc6e3..b701509 100644 --- a/lib/errors/errordefinitions.js +++ b/lib/errors/errordefinitions.js @@ -17,6 +17,7 @@ var errors = { INVALID_ADDRESS: 'Invalid address', KEY_IN_COPAYER: 'Key already registered', LOCKED_FUNDS: 'Funds are locked by pending transaction proposals', + MAIN_ADDRESS_GAP_REACHED: 'Maximum number of consecutive addresses without activity reached', NOT_AUTHORIZED: 'Not authorized', TOO_MANY_KEYS: 'Too many keys registered', TX_ALREADY_BROADCASTED: 'The transaction proposal is already broadcasted', diff --git a/lib/server.js b/lib/server.js index 909cb81..622afdd 100644 --- a/lib/server.js +++ b/lib/server.js @@ -63,9 +63,11 @@ WalletService.BACKOFF_OFFSET = 3; // Time a copayer need to wait to create a new TX after her tx previous proposal we rejected. (incremental). in Minutes. WalletService.BACKOFF_TIME = 2; +WalletService.MAX_MAIN_ADDRESS_GAP = 20; + // Fund scanning parameters WalletService.SCAN_CONFIG = { - maxGap: 20, + maxGap: WalletService.MAX_MAIN_ADDRESS_GAP, }; WalletService.FEE_LEVELS = [{ diff --git a/test/integration/server.js b/test/integration/server.js index 9deb40d..93b2331 100644 --- a/test/integration/server.js +++ b/test/integration/server.js @@ -1667,6 +1667,32 @@ describe('Wallet service', function() { }); }); }); + + it.only('should fail to create more consecutive addresses with no activity than allowed', function(done) { + var MAX_MAIN_ADDRESS_GAP_old = WalletService.MAX_MAIN_ADDRESS_GAP; + var n = WalletService.MAX_MAIN_ADDRESS_GAP = 2; + helpers.stubAddressActivity([]); + async.map(_.range(n), function(i, next) { + server.createAddress({}, next); + }, function(err, addresses) { + addresses.length.should.equal(n); + + server.createAddress({}, function(err, address) { + should.exist(err); + should.not.exist(address); + err.code.should.equal('MAIN_ADDRESS_GAP_REACHED'); + server.createAddress({ + ignoreMaxGap: true + }, function(err, address) { + should.not.exist(err); + should.exist(address); + address.path.should.equal('m/0/' + n); + WalletService.MAX_MAIN_ADDRESS_GAP = MAX_MAIN_ADDRESS_GAP_old; + done(); + }); + }); + }); + }); }); describe('1-of-1 (BIP44 & P2PKH)', function() {