From 4f582382bc201545e7a998ba8264981dacb79425 Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Wed, 29 Jul 2015 18:19:53 -0300 Subject: [PATCH] fix invalid fee on legacy txs --- lib/server.js | 13 ++++++++----- test/integration/server.js | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/lib/server.js b/lib/server.js index d4cdb3f..6db5ecc 100644 --- a/lib/server.js +++ b/lib/server.js @@ -865,6 +865,13 @@ WalletService.prototype._selectTxInputs = function(txp, cb) { var inputs = sortUtxos(utxos); var bitcoreTx, bitcoreError; + var serializationOpts = { + disableIsFullySigned: true, + }; + if (!_.startsWith(txp.version, '1.')) { + serializationOpts.disableSmallFees = true; + serializationOpts.disableLargeFees = true; + } while (i < inputs.length) { selected.push(inputs[i]); @@ -876,11 +883,7 @@ WalletService.prototype._selectTxInputs = function(txp, cb) { txp.setInputs(selected); txp.estimateFee(); bitcoreTx = txp.getBitcoreTx(); - bitcoreError = bitcoreTx.getSerializationError({ - disableIsFullySigned: true, - disableSmallFees: true, - disableLargeFees: true, - }); + bitcoreError = bitcoreTx.getSerializationError(serializationOpts); if (!bitcoreError) { txp.fee = bitcoreTx.getFee(); return cb(); diff --git a/test/integration/server.js b/test/integration/server.js index 83a1cac..e255205 100644 --- a/test/integration/server.js +++ b/test/integration/server.js @@ -4350,6 +4350,44 @@ describe('Wallet service', function() { }); }); }); + it('should fail with insufficient fee when invoked from legacy (bwc-0.0.*) client', function(done) { + helpers.stubUtxos(server, wallet, 1, function() { + var verifyStub = sinon.stub(WalletService.prototype, '_verifySignature'); + verifyStub.returns(true); + WalletService.getInstanceWithAuth({ + copayerId: wallet.copayers[0].id, + message: 'dummy', + signature: 'dummy', + clientVersion: 'bwc-0.0.40', + }, function(err, server) { + should.not.exist(err); + should.exist(server); + verifyStub.restore(); + var txOpts = helpers.createSimpleProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 0.99995, null, TestData.copayers[0].privKey_1H_0); + + server.createTx(txOpts, function(err, tx) { + should.exist(err); + err.code.should.equal('INSUFFICIENTFUNDS'); + var txOpts = helpers.createSimpleProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 0.99995, null, TestData.copayers[0].privKey_1H_0, 5000); + server.createTx(txOpts, function(err, tx) { + should.not.exist(err); + tx.fee.should.equal(5000); + + // Sign it to make sure Bitcore doesn't complain about the fees + var signatures = helpers.clientSign(tx, TestData.copayers[0].xPrivKey); + server.signTx({ + txProposalId: tx.id, + signatures: signatures, + }, function(err) { + should.not.exist(err); + done(); + }); + }); + }); + }); + }); + }); + }); }); });