From 25064829e06d45bcdacf14f105d080a739a8b0ec Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Wed, 27 Aug 2014 16:42:52 -0300 Subject: [PATCH] Tests --- test/test.Wallet.js | 49 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/test/test.Wallet.js b/test/test.Wallet.js index 09dc4afe5..cf8a0e26c 100644 --- a/test/test.Wallet.js +++ b/test/test.Wallet.js @@ -802,6 +802,55 @@ describe('Wallet model', function() { }); }); + describe('removeTxWithSpentInputs', function () { + it('should remove TxProposal with spent inputs', 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([]); + w.removeTxWithSpentInputs(); + chai.expect(w.getTxProposals().length).to.equal(0); + + done(); + }); + }); + + it('should remove TxProposal with at least 1 spent input', function(done) { + var w = cachedCreateW2(); + var utxo = [createUTXO(w)[0], createUTXO(w)[0]]; + utxo[0].amount = 80000; + utxo[1].amount = 80000; + utxo[1].vout = 1; + chai.expect(w.getTxProposals().length).to.equal(0); + w.blockchain.fixUnspent(utxo); + w.createTx(toAddress, '100000', 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 1 input spent. txp should be removed from txps list + w.blockchain.fixUnspent([utxo[0]]); + w.removeTxWithSpentInputs(); + chai.expect(w.getTxProposals().length).to.equal(0); + + done(); + }); + }); + }); + describe('#send', function() { it('should call this.network.send', function() { var w = cachedCreateW2();