From 82bd5888340f7a8a7dbbc1b60b98286008c0e106 Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Thu, 11 Aug 2016 13:57:51 -0300 Subject: [PATCH] more robust validation of createTx params --- lib/server.js | 4 ++-- test/integration/server.js | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/server.js b/lib/server.js index 6a3a367..beba84d 100644 --- a/lib/server.js +++ b/lib/server.js @@ -1645,6 +1645,8 @@ WalletService.prototype._canCreateTx = function(cb) { WalletService.prototype._validateOutputs = function(opts, wallet, cb) { var dustThreshold = Math.max(Defaults.MIN_OUTPUT_AMOUNT, Bitcore.Transaction.DUST_AMOUNT); + if (_.isEmpty(opts.outputs)) return new ClientError('No outputs were specified'); + for (var i = 0; i < opts.outputs.length; i++) { var output = opts.outputs[i]; output.valid = false; @@ -1753,8 +1755,6 @@ WalletService.prototype.createTx = function(opts, cb) { opts = opts || {}; - if (!checkRequired(opts, ['outputs'], cb)) return; - function getChangeAddress(wallet, cb) { if (wallet.singleAddress) { self.storage.fetchAddresses(self.walletId, function(err, addresses) { diff --git a/test/integration/server.js b/test/integration/server.js index 75b98c3..10c055b 100644 --- a/test/integration/server.js +++ b/test/integration/server.js @@ -2294,17 +2294,16 @@ describe('Wallet service', function() { }); }); }); - it('should fail to create a tx without outputs param', function(done) { + it('should fail to create a tx without outputs', function(done) { helpers.stubUtxos(server, wallet, [1, 2], function() { var txOpts = { - toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', - amount: 0.8 * 1e8, - message: 'some message', + outputs: [], feePerKb: 123e2, }; server.createTx(txOpts, function(err, tx) { should.exist(err); should.not.exist(tx); + err.message.should.equal('No outputs were specified'); done(); }); });