From ace301d1f82e2e900dacb7f91acddbf3b9b00879 Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Thu, 4 Sep 2014 17:37:38 -0300 Subject: [PATCH] Only remove pending txps --- js/models/core/Wallet.js | 11 ++++++++++- test/test.Wallet.js | 30 +++++++++++++++++++++++++++--- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/js/models/core/Wallet.js b/js/models/core/Wallet.js index a4d5e3380..91123d20a 100644 --- a/js/models/core/Wallet.js +++ b/js/models/core/Wallet.js @@ -1529,7 +1529,16 @@ Wallet.prototype.removeTxWithSpentInputs = function(cb) { var self = this; cb = cb || function () {}; - var txps = this.getTxProposals(); + + var txps = []; + var maxRejectCount = this.maxRejectCount(); + for (var ntxid in this.txProposals.txps) { + var txp = this.txProposals.txps[ntxid]; + txp.ntxid = ntxid; + if (txp.isPending(maxRejectCount)) { + txps.push(txp); + } + } var inputs = []; txps.forEach(function (txp) { diff --git a/test/test.Wallet.js b/test/test.Wallet.js index cf8a0e26c..222296a76 100644 --- a/test/test.Wallet.js +++ b/test/test.Wallet.js @@ -802,8 +802,8 @@ describe('Wallet model', function() { }); }); - describe('removeTxWithSpentInputs', function () { - it('should remove TxProposal with spent inputs', function(done) { + describe.only('removeTxWithSpentInputs', function () { + it('should remove pending TxProposal with spent inputs', function(done) { var w = cachedCreateW2(); var utxo = createUTXO(w); chai.expect(w.getTxProposals().length).to.equal(0); @@ -825,7 +825,7 @@ describe('Wallet model', function() { }); }); - it('should remove TxProposal with at least 1 spent input', function(done) { + it('should remove pending TxProposal with at least 1 spent input', function(done) { var w = cachedCreateW2(); var utxo = [createUTXO(w)[0], createUTXO(w)[0]]; utxo[0].amount = 80000; @@ -849,6 +849,30 @@ describe('Wallet model', function() { done(); }); }); + + it('should not remove complete TxProposal', function(done) { + var w = cachedCreateW2(); + var utxo = createUTXO(w); + chai.expect(w.getTxProposals().length).to.equal(0); + w.blockchain.fixUnspent(utxo); + w.createTx(toAddress, amountSatStr, null, function(ntxid) { + w.sendTxProposal(ntxid); + chai.expect(w.getTxProposals().length).to.equal(1); + + // Inputs are still available, txp still valid + w.removeTxWithSpentInputs(); + chai.expect(w.getTxProposals().length).to.equal(1); + + // Simulate input spent. txp should be removed from txps list + w.blockchain.fixUnspent([]); + var txp = w.txProposals.get(ntxid); + sinon.stub(txp, 'isPending', function () { return false; }) + w.removeTxWithSpentInputs(); + chai.expect(w.getTxProposals().length).to.equal(1); + + done(); + }); + }); }); describe('#send', function() {