|
|
@ -252,7 +252,7 @@ describe('Wallet', function() { |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
describe('processTx', function(){ |
|
|
|
describe('Process transaction', function(){ |
|
|
|
var addresses |
|
|
|
var tx |
|
|
|
|
|
|
@ -266,100 +266,105 @@ describe('Wallet', function() { |
|
|
|
tx = Transaction.fromHex(fixtureTx1Hex) |
|
|
|
}) |
|
|
|
|
|
|
|
it('does not fail on scripts with no corresponding Address', function() { |
|
|
|
var pubKey = wallet.getPrivateKey(0).pub |
|
|
|
var script = Script.createPubKeyScriptPubKey(pubKey) |
|
|
|
var tx2 = new Transaction() |
|
|
|
tx2.addInput(fakeTxHash(1), 0) |
|
|
|
|
|
|
|
// FIXME: Transaction doesn't support custom ScriptPubKeys... yet
|
|
|
|
// So for now, we hijack the script with our own, and undefine the cached address
|
|
|
|
tx2.addOutput(addresses[0], 10000) |
|
|
|
tx2.outs[0].script = script |
|
|
|
tx2.outs[0].address = undefined |
|
|
|
describe("processPendingTx", function(){ |
|
|
|
it("sets the pending flag on output", function(){ |
|
|
|
wallet.addresses = [addresses[0]] |
|
|
|
wallet.processPendingTx(tx) |
|
|
|
|
|
|
|
wallet.processTx(tx2) |
|
|
|
verifyOutputAdded(0, true) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
describe("when tx outs contains an address owned by the wallet, an 'output' gets added to wallet.outputs", function(){ |
|
|
|
it("works for receive address", function(){ |
|
|
|
var totalOuts = outputCount() |
|
|
|
describe('processConfirmedTx', function(){ |
|
|
|
|
|
|
|
wallet.addresses = [addresses[0]] |
|
|
|
wallet.processTx(tx) |
|
|
|
it('does not fail on scripts with no corresponding Address', function() { |
|
|
|
var pubKey = wallet.getPrivateKey(0).pub |
|
|
|
var script = Script.createPubKeyScriptPubKey(pubKey) |
|
|
|
var tx2 = new Transaction() |
|
|
|
tx2.addInput(fakeTxHash(1), 0) |
|
|
|
|
|
|
|
assert.equal(outputCount(), totalOuts + 1) |
|
|
|
verifyOutputAdded(0) |
|
|
|
// FIXME: Transaction doesn't support custom ScriptPubKeys... yet
|
|
|
|
// So for now, we hijack the script with our own, and undefine the cached address
|
|
|
|
tx2.addOutput(addresses[0], 10000) |
|
|
|
tx2.outs[0].script = script |
|
|
|
tx2.outs[0].address = undefined |
|
|
|
|
|
|
|
wallet.processConfirmedTx(tx2) |
|
|
|
}) |
|
|
|
|
|
|
|
it("works for change address", function(){ |
|
|
|
var totalOuts = outputCount() |
|
|
|
wallet.changeAddresses = [addresses[1]] |
|
|
|
describe("when tx outs contains an address owned by the wallet, an 'output' gets added to wallet.outputs", function(){ |
|
|
|
it("works for receive address", function(){ |
|
|
|
var totalOuts = outputCount() |
|
|
|
|
|
|
|
wallet.processTx(tx) |
|
|
|
wallet.addresses = [addresses[0]] |
|
|
|
wallet.processConfirmedTx(tx) |
|
|
|
|
|
|
|
assert.equal(outputCount(), totalOuts + 1) |
|
|
|
verifyOutputAdded(1) |
|
|
|
}) |
|
|
|
assert.equal(outputCount(), totalOuts + 1) |
|
|
|
verifyOutputAdded(0, false) |
|
|
|
}) |
|
|
|
|
|
|
|
describe("when the pending flag is set", function(){ |
|
|
|
it("sets the pending flag on output", function(){ |
|
|
|
wallet.addresses = [addresses[0]] |
|
|
|
wallet.processTx(tx, true) |
|
|
|
it("works for change address", function(){ |
|
|
|
var totalOuts = outputCount() |
|
|
|
wallet.changeAddresses = [addresses[1]] |
|
|
|
|
|
|
|
wallet.processConfirmedTx(tx) |
|
|
|
|
|
|
|
verifyOutputAdded(0, true) |
|
|
|
assert.equal(outputCount(), totalOuts + 1) |
|
|
|
verifyOutputAdded(1, false) |
|
|
|
}) |
|
|
|
|
|
|
|
function outputCount(){ |
|
|
|
return Object.keys(wallet.outputs).length |
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
function outputCount(){ |
|
|
|
return Object.keys(wallet.outputs).length |
|
|
|
} |
|
|
|
describe("when tx ins outpoint contains a known txhash:i, the corresponding 'output' gets updated", function(){ |
|
|
|
beforeEach(function(){ |
|
|
|
wallet.addresses = [addresses[0]] // the address fixtureTx2 used as input
|
|
|
|
wallet.processConfirmedTx(tx) |
|
|
|
|
|
|
|
function verifyOutputAdded(index, pending) { |
|
|
|
var txOut = tx.outs[index] |
|
|
|
var key = tx.getHash() + ":" + index |
|
|
|
var output = wallet.outputs[key] |
|
|
|
assert.equal(output.receive, key) |
|
|
|
assert.equal(output.value, txOut.value) |
|
|
|
assert.equal(output.pending, pending) |
|
|
|
tx = Transaction.fromHex(fixtureTx2Hex) |
|
|
|
}) |
|
|
|
|
|
|
|
var txOutAddress = Address.fromScriptPubKey(txOut.script).toString() |
|
|
|
assert.equal(output.address, txOutAddress) |
|
|
|
} |
|
|
|
}) |
|
|
|
it("does not add to wallet.outputs", function(){ |
|
|
|
var outputs = wallet.outputs |
|
|
|
wallet.processConfirmedTx(tx) |
|
|
|
assert.deepEqual(wallet.outputs, outputs) |
|
|
|
}) |
|
|
|
|
|
|
|
describe("when tx ins outpoint contains a known txhash:i, the corresponding 'output' gets updated", function(){ |
|
|
|
beforeEach(function(){ |
|
|
|
wallet.addresses = [addresses[0]] // the address fixtureTx2 used as input
|
|
|
|
wallet.processTx(tx) |
|
|
|
it("sets spend with the transaction hash and input index", function(){ |
|
|
|
wallet.processConfirmedTx(tx) |
|
|
|
|
|
|
|
tx = Transaction.fromHex(fixtureTx2Hex) |
|
|
|
var txIn = tx.ins[0] |
|
|
|
var key = txIn.outpoint.hash + ":" + txIn.outpoint.index |
|
|
|
var output = wallet.outputs[key] |
|
|
|
|
|
|
|
assert.equal(output.spend, tx.getHash() + ':' + 0) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
it("does not add to wallet.outputs", function(){ |
|
|
|
it("does nothing when none of the involved addresses belong to the wallet", function(){ |
|
|
|
var outputs = wallet.outputs |
|
|
|
wallet.processTx(tx) |
|
|
|
wallet.processConfirmedTx(tx) |
|
|
|
assert.deepEqual(wallet.outputs, outputs) |
|
|
|
}) |
|
|
|
|
|
|
|
it("sets spend with the transaction hash and input index", function(){ |
|
|
|
wallet.processTx(tx) |
|
|
|
|
|
|
|
var txIn = tx.ins[0] |
|
|
|
var key = txIn.outpoint.hash + ":" + txIn.outpoint.index |
|
|
|
var output = wallet.outputs[key] |
|
|
|
|
|
|
|
assert.equal(output.spend, tx.getHash() + ':' + 0) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
it("does nothing when none of the involved addresses belong to the wallet", function(){ |
|
|
|
var outputs = wallet.outputs |
|
|
|
wallet.processTx(tx) |
|
|
|
assert.deepEqual(wallet.outputs, outputs) |
|
|
|
}) |
|
|
|
function verifyOutputAdded(index, pending) { |
|
|
|
var txOut = tx.outs[index] |
|
|
|
var key = tx.getHash() + ":" + index |
|
|
|
var output = wallet.outputs[key] |
|
|
|
assert.equal(output.receive, key) |
|
|
|
assert.equal(output.value, txOut.value) |
|
|
|
assert.equal(output.pending, pending) |
|
|
|
|
|
|
|
var txOutAddress = Address.fromScriptPubKey(txOut.script).toString() |
|
|
|
assert.equal(output.address, txOutAddress) |
|
|
|
} |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
describe('createTx', function(){ |
|
|
|
var to, value |
|
|
|
var address1, address2 |
|
|
|