From 9f4ef16bba1afb40667309bf89d423d130fca555 Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Wed, 10 Jun 2015 17:57:48 -0300 Subject: [PATCH] test fee behavior --- lib/server.js | 2 ++ test/integration/server.js | 20 ++++++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/server.js b/lib/server.js index bdad5ba..cfa7903 100644 --- a/lib/server.js +++ b/lib/server.js @@ -693,6 +693,8 @@ WalletService.prototype.getBalance = function(opts, cb) { WalletService.prototype._selectTxInputs = function(txp, cb) { var self = this; + Bitcore.Transaction.FEE_SECURITY_MARGIN = 1; + self._getUtxos(function(err, utxos) { if (err) return cb(err); diff --git a/test/integration/server.js b/test/integration/server.js index c1ef9d4..c17f4f4 100644 --- a/test/integration/server.js +++ b/test/integration/server.js @@ -1407,9 +1407,9 @@ describe('Wallet service', function() { }); }); - it.only('should fail to create tx when insufficient funds for fee', function(done) { - helpers.stubUtxos(server, wallet, 0.04822200, function() { - var txOpts = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 0.04820000, null, TestData.copayers[0].privKey_1H_0); + it('should fail to create tx when insufficient funds for fee', function(done) { + helpers.stubUtxos(server, wallet, 0.048222, function() { + var txOpts = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 0.048200, null, TestData.copayers[0].privKey_1H_0); server.createTx(txOpts, function(err, tx) { should.exist(err); err.code.should.equal('INSUFFICIENTFUNDS'); @@ -1419,6 +1419,18 @@ describe('Wallet service', function() { }); }); + it('should scale fees according to tx size', function(done) { + helpers.stubUtxos(server, wallet, [1, 1, 1, 1], function() { + var txOpts = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 3.5, null, TestData.copayers[0].privKey_1H_0); + server.createTx(txOpts, function(err, tx) { + should.not.exist(err); + tx.getBitcoreTx()._estimateSize().should.be.within(1001, 1999); + tx.fee.should.equal(20000); + done(); + }); + }); + }); + it('should fail to create tx for dust amount', function(done) { helpers.stubUtxos(server, wallet, [1], function() { var txOpts = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 0.00000001, null, TestData.copayers[0].privKey_1H_0); @@ -2445,7 +2457,7 @@ describe('Wallet service', function() { helpers.createAndJoinWallet(1, 1, function(s, w) { server = s; wallet = w; - helpers.stubUtxos(server, wallet, helpers.toSatoshi(_.range(4)), function() { + helpers.stubUtxos(server, wallet, _.range(4), function() { var txOpts = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 0.01, null, TestData.copayers[0].privKey_1H_0); async.eachSeries(_.range(3), function(i, next) { server.createTx(txOpts, function(err, tx) {