From 8cf28b220084bad8931c09db569a13656a090b99 Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Mon, 16 Feb 2015 14:41:12 -0300 Subject: [PATCH] test for dust amount --- lib/server.js | 6 ++++++ test/integration.js | 13 ++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/server.js b/lib/server.js index a7755d5..839f4f0 100644 --- a/lib/server.js +++ b/lib/server.js @@ -26,6 +26,7 @@ var TxProposal = require('./model/txproposal'); var Notification = require('./model/Notification'); var MINIMUM_FEE_SAT = 10000; +var DUST_THRESHOLD = 5430; var initialized = false; var storage; @@ -434,6 +435,8 @@ CopayServer.prototype._selectUtxos = function(txp, utxos) { return; } catch (ex) { //if (ex.name != 'bitcore.ErrorTransactionFeeError') {} + //if (ex.name != 'bitcore.ErrorTransactionDustOutputs') {} + console.log(ex); } } i++; @@ -477,6 +480,9 @@ CopayServer.prototype.createTx = function(opts, cb) { if (toAddress.network != wallet.getNetworkName()) return cb(new ClientError('INVALIDADDRESS', 'Incorrect address network')); + if (opts.amount < DUST_THRESHOLD) + return cb(new ClientError('DUSTAMOUNT', 'Amount below dust threshold')); + self._getUtxos(function(err, utxos) { if (err) return cb(err); diff --git a/test/integration.js b/test/integration.js index 40c117c..c525c2b 100644 --- a/test/integration.js +++ b/test/integration.js @@ -771,7 +771,18 @@ describe('Copay server', function() { }); }); - it.skip('should fail to create tx for dust amount', function(done) {}); + it('should fail to create tx for dust amount', function(done) { + helpers.createUtxos(server, wallet, [1], function(utxos) { + helpers.stubBlockExplorer(server, utxos); + var txOpts = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 0.00000001, null, TestData.copayers[0].privKey); + server.createTx(txOpts, function(err, tx) { + should.exist(err); + err.code.should.equal('DUSTAMOUNT'); + err.message.should.equal('Amount below dust threshold'); + done(); + }); + }); + }); it('should create tx when there is a pending tx and enough UTXOs', function(done) { helpers.createUtxos(server, wallet, [10.1, 10.2, 10.3], function(utxos) {