test for dust amount

This commit is contained in:
Ivan Socolsky 2015-02-16 14:41:12 -03:00
parent 787a3376be
commit 8cf28b2200
2 changed files with 18 additions and 1 deletions

View File

@ -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);

View File

@ -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) {