|
|
@ -356,15 +356,6 @@ describe('Wallet', function() { |
|
|
|
} |
|
|
|
] |
|
|
|
wallet.setUnspentOutputs(utxo) |
|
|
|
|
|
|
|
function scriptPubKeyFor(address, value){ |
|
|
|
var txOut = new TransactionOut({ |
|
|
|
value: value, |
|
|
|
script: Script.createOutputScript(address) |
|
|
|
}) |
|
|
|
|
|
|
|
return txOut.scriptPubKey() |
|
|
|
} |
|
|
|
}) |
|
|
|
|
|
|
|
describe('choosing utxo', function(){ |
|
|
@ -383,6 +374,25 @@ describe('Wallet', function() { |
|
|
|
assert.deepEqual(tx.ins[0].outpoint, { hash: fakeTxHash(3), index: 0 }) |
|
|
|
assert.deepEqual(tx.ins[1].outpoint, { hash: fakeTxHash(2), index: 1 }) |
|
|
|
}) |
|
|
|
|
|
|
|
it('ignores spent outputs', function(){ |
|
|
|
utxo.push( |
|
|
|
{ |
|
|
|
"hash": fakeTxHash(4), |
|
|
|
"outputIndex": 0, |
|
|
|
"scriptPubKey": scriptPubKeyFor(address2, 520000), |
|
|
|
"address" : address2, |
|
|
|
"value": 530000 // enough but spent before createTx
|
|
|
|
} |
|
|
|
) |
|
|
|
wallet.setUnspentOutputs(utxo) |
|
|
|
wallet.outputs[fakeTxHash(4) + ":" + 0].spend = fakeTxHash(5) + ":" + 0 |
|
|
|
|
|
|
|
var tx = wallet.createTx(to, value) |
|
|
|
|
|
|
|
assert.equal(tx.ins.length, 1) |
|
|
|
assert.deepEqual(tx.ins[0].outpoint, { hash: fakeTxHash(3), index: 0 }) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
describe('transaction outputs', function(){ |
|
|
@ -467,6 +477,15 @@ describe('Wallet', function() { |
|
|
|
function fakeTxHash(i) { |
|
|
|
return "txtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtx" + i |
|
|
|
} |
|
|
|
|
|
|
|
function scriptPubKeyFor(address, value){ |
|
|
|
var txOut = new TransactionOut({ |
|
|
|
value: value, |
|
|
|
script: Script.createOutputScript(address) |
|
|
|
}) |
|
|
|
|
|
|
|
return txOut.scriptPubKey() |
|
|
|
} |
|
|
|
}) |
|
|
|
|
|
|
|
function assertEqual(obj1, obj2){ |
|
|
|