From c64790f014891f50395d5dbadc9c5283ff60fe68 Mon Sep 17 00:00:00 2001 From: Gregg Zigler Date: Mon, 22 Jun 2015 15:02:28 -0400 Subject: [PATCH] lodash each needs return-false to break out of loop, travis timeout debug --- lib/server.js | 31 +++++++++++++++++++------------ test/integration/server.js | 1 + 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/lib/server.js b/lib/server.js index b33acea..40a44d1 100644 --- a/lib/server.js +++ b/lib/server.js @@ -878,23 +878,30 @@ WalletService.prototype.createTx = function(opts, cb) { var outputs = (opts.type == Model.TxProposal.Types.MULTIPLEOUTPUTS) ? opts.outputs : [ { toAddress: opts.toAddress, amount: opts.amount } ]; - // _.each(outputs) fails here, causes multiple callbacks to be executed - // use for-loop instead - for (var i = 0; i < outputs.length; i++) { - var output = outputs[i]; + _.each(outputs, function(output) { + output.valid = false; var toAddress = {}; try { toAddress = new Bitcore.Address(output.toAddress); } catch (ex) { - return cb(new ClientError('INVALIDADDRESS', 'Invalid address')); + cb(new ClientError('INVALIDADDRESS', 'Invalid address')); + return false; } - if (toAddress.network != wallet.getNetworkName()) - return cb(new ClientError('INVALIDADDRESS', 'Incorrect address network')); - if (output.amount <= 0) - return cb(new ClientError('Invalid amount')); - if (output.amount < Bitcore.Transaction.DUST_AMOUNT) - return cb(new ClientError('DUSTAMOUNT', 'Amount below dust threshold')); - } + if (toAddress.network != wallet.getNetworkName()) { + cb(new ClientError('INVALIDADDRESS', 'Incorrect address network')); + return false; + } + if (output.amount <= 0) { + cb(new ClientError('Invalid amount')); + return false; + } + if (output.amount < Bitcore.Transaction.DUST_AMOUNT) { + cb(new ClientError('DUSTAMOUNT', 'Amount below dust threshold')); + return false; + } + output.valid = true; + }); + if (_.any(outputs, 'valid', false)) return; var changeAddress = wallet.createAddress(true); diff --git a/test/integration/server.js b/test/integration/server.js index 7d19661..0aec2fd 100644 --- a/test/integration/server.js +++ b/test/integration/server.js @@ -1770,6 +1770,7 @@ describe('Wallet service', function() { }); it('should follow backoff time after consecutive rejections', function(done) { + this.timeout(10000); // find out why travis is timing out async.series([ function(next) {