Finalize should chain this as well.

This commit is contained in:
junderw 2019-07-09 15:45:56 +09:00
parent ba33f0317f
commit b8c341dea0
No known key found for this signature in database
GPG key ID: B256185D3A971908
4 changed files with 51 additions and 48 deletions
test/integration

View file

@ -225,26 +225,25 @@ describe('bitcoinjs-lib (transactions with psbt)', () => {
} = inputData
assert.deepStrictEqual({ hash, index, witnessUtxo, redeemScript }, inputData)
}
const keyPair = p2sh.keys[0]
const outputData = {
script: p2sh.payment.output, // sending to myself for fun
value: 2e4
}
const psbt = new bitcoin.Psbt({ network: regtest })
const tx = new bitcoin.Psbt()
.addInput(inputData)
.addOutput({
address: regtestUtils.RANDOM_ADDRESS,
value: 2e4
})
.signInput(0, p2sh.keys[0])
assert.strictEqual(psbt.validateSignatures(0), true)
psbt.finalizeAllInputs()
const tx = psbt.extractTransaction()
.addOutput(outputData)
.sign(keyPair)
.finalizeAllInputs()
.extractTransaction()
// build and broadcast to the Bitcoin RegTest network
await regtestUtils.broadcast(tx.toHex())
await regtestUtils.verify({
txId: tx.getId(),
address: regtestUtils.RANDOM_ADDRESS,
address: p2sh.payment.address,
vout: 0,
value: 2e4
})