Fix tests to use new sign method
This commit is contained in:
parent
17f5f35569
commit
969b3a5e18
9 changed files with 744 additions and 164 deletions
test/integration
|
@ -15,12 +15,29 @@ async function buildAndSign (depends, prevOutput, redeemScript, witnessScript) {
|
|||
txb.addInput(unspent.txId, unspent.vout, null, prevOutput)
|
||||
txb.addOutput(regtestUtils.RANDOM_ADDRESS, 2e4)
|
||||
|
||||
const posType = depends.prevOutScriptType
|
||||
const needsValue = !!witnessScript || posType.slice(-6) === 'p2wpkh'
|
||||
|
||||
if (depends.signatures) {
|
||||
keyPairs.forEach(keyPair => {
|
||||
txb.sign(0, keyPair, redeemScript, null, unspent.value, witnessScript)
|
||||
txb.sign({
|
||||
prevOutScriptType: posType,
|
||||
vin: 0,
|
||||
keyPair,
|
||||
redeemScript,
|
||||
witnessValue: needsValue ? unspent.value : undefined,
|
||||
witnessScript,
|
||||
})
|
||||
})
|
||||
} else if (depends.signature) {
|
||||
txb.sign(0, keyPairs[0], redeemScript, null, unspent.value, witnessScript)
|
||||
txb.sign({
|
||||
prevOutScriptType: posType,
|
||||
vin: 0,
|
||||
keyPair: keyPairs[0],
|
||||
redeemScript,
|
||||
witnessValue: needsValue ? unspent.value : undefined,
|
||||
witnessScript,
|
||||
})
|
||||
}
|
||||
|
||||
return regtestUtils.broadcast(txb.build().toHex())
|
||||
|
@ -41,12 +58,14 @@ async function buildAndSign (depends, prevOutput, redeemScript, witnessScript) {
|
|||
|
||||
describe('bitcoinjs-lib (payments - ' + k + ')', () => {
|
||||
it('can broadcast as an output, and be spent as an input', async () => {
|
||||
await buildAndSign(depends, output, null, null)
|
||||
Object.assign(depends, { prevOutScriptType: k })
|
||||
await buildAndSign(depends, output, undefined, undefined)
|
||||
})
|
||||
|
||||
it('can (as P2SH(' + k + ')) broadcast as an output, and be spent as an input', async () => {
|
||||
const p2sh = bitcoin.payments.p2sh({ redeem: { output }, network: NETWORK })
|
||||
await buildAndSign(depends, p2sh.output, p2sh.redeem.output, null)
|
||||
Object.assign(depends, { prevOutScriptType: 'p2sh-' + k })
|
||||
await buildAndSign(depends, p2sh.output, p2sh.redeem.output, undefined)
|
||||
})
|
||||
|
||||
// NOTE: P2WPKH cannot be wrapped in P2WSH, consensus fail
|
||||
|
@ -54,13 +73,15 @@ async function buildAndSign (depends, prevOutput, redeemScript, witnessScript) {
|
|||
|
||||
it('can (as P2WSH(' + k + ')) broadcast as an output, and be spent as an input', async () => {
|
||||
const p2wsh = bitcoin.payments.p2wsh({ redeem: { output }, network: NETWORK })
|
||||
await buildAndSign(depends, p2wsh.output, null, p2wsh.redeem.output)
|
||||
Object.assign(depends, { prevOutScriptType: 'p2wsh-' + k })
|
||||
await buildAndSign(depends, p2wsh.output, undefined, p2wsh.redeem.output)
|
||||
})
|
||||
|
||||
it('can (as P2SH(P2WSH(' + k + '))) broadcast as an output, and be spent as an input', async () => {
|
||||
const p2wsh = bitcoin.payments.p2wsh({ redeem: { output }, network: NETWORK })
|
||||
const p2sh = bitcoin.payments.p2sh({ redeem: { output: p2wsh.output }, network: NETWORK })
|
||||
|
||||
Object.assign(depends, { prevOutScriptType: 'p2sh-p2wsh-' + k })
|
||||
await buildAndSign(depends, p2sh.output, p2sh.redeem.output, p2wsh.redeem.output)
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue