Browse Source

wallet: do not delete pending incoming tx from outputs

hk-custom-address
Wei Lu 10 years ago
parent
commit
82b1d8fbdc
  1. 8
      src/wallet.js
  2. 25
      test/wallet.js

8
src/wallet.js

@ -175,7 +175,13 @@ function Wallet(seed, network) {
var output = txinId + ':' + txIn.index var output = txinId + ':' + txIn.index
if(me.outputs[output]) delete me.outputs[output] if (!(output in me.outputs)) return
if (isPending) {
return me.outputs[output].pending = true
}
delete me.outputs[output]
}) })
} }

25
test/wallet.js

@ -264,12 +264,35 @@ describe('Wallet', function() {
}) })
describe("processPendingTx", function(){ describe("processPendingTx", function(){
it("sets the pending flag on output", function(){ it("incoming: sets the pending flag on output", function(){
wallet.addresses = [addresses[0]] wallet.addresses = [addresses[0]]
wallet.processPendingTx(tx) wallet.processPendingTx(tx)
verifyOutputAdded(0, true) verifyOutputAdded(0, true)
}) })
describe("when tx ins outpoint contains a known txhash:i", function(){
var spendTx
beforeEach(function(){
wallet.addresses = [addresses[0]]
wallet.processConfirmedTx(tx)
spendTx = Transaction.fromHex(fixtureTx2Hex)
})
it("outgoing: sets the pending flag on output instead of deleting it", function(){
var txIn = spendTx.ins[0]
var txInId = new Buffer(txIn.hash)
Array.prototype.reverse.call(txInId)
txInId = txInId.toString('hex')
var key = txInId + ':' + txIn.index
assert(!wallet.outputs[key].pending)
wallet.processPendingTx(spendTx)
assert(wallet.outputs[key].pending)
})
})
}) })
describe('processConfirmedTx', function(){ describe('processConfirmedTx', function(){

Loading…
Cancel
Save