From a395af47fdb374ea14b6b1aff24fd065ae0ebe26 Mon Sep 17 00:00:00 2001 From: junderw Date: Fri, 23 Aug 2019 15:49:24 +0900 Subject: [PATCH] Simplify nonWitnessUtxo integration tests to not confuse learners --- test/integration/transactions-psbt.js | 87 +++------------------------ 1 file changed, 10 insertions(+), 77 deletions(-) diff --git a/test/integration/transactions-psbt.js b/test/integration/transactions-psbt.js index 9d40ed0..9040fc2 100644 --- a/test/integration/transactions-psbt.js +++ b/test/integration/transactions-psbt.js @@ -283,41 +283,27 @@ describe('bitcoinjs-lib (transactions with psbt)', () => { }); it('can create (and broadcast via 3PBP) a Transaction, w/ a P2SH(P2WPKH) input with nonWitnessUtxo', async () => { + // For learning purposes, ignore this test. + // REPEATING ABOVE BUT WITH nonWitnessUtxo by passing false to getInputData const p2sh = createPayment('p2sh-p2wpkh'); const inputData = await getInputData(5e4, p2sh.payment, false, 'p2sh'); const inputData2 = await getInputData(5e4, p2sh.payment, false, 'p2sh'); - { - const { - hash, - index, - nonWitnessUtxo, - redeemScript, - } = inputData; - assert.deepStrictEqual( - { hash, index, nonWitnessUtxo, redeemScript }, - inputData, - ); - } const keyPair = p2sh.keys[0]; const outputData = { - script: p2sh.payment.output, // sending to myself for fun + script: p2sh.payment.output, value: 2e4, }; const outputData2 = { - script: p2sh.payment.output, // sending to myself for fun + script: p2sh.payment.output, value: 7e4, }; - const tx = new bitcoin.Psbt() .addInputs([inputData, inputData2]) .addOutputs([outputData, outputData2]) .signAllInputs(keyPair) .finalizeAllInputs() .extractTransaction(); - - // build and broadcast to the Bitcoin RegTest network await regtestUtils.broadcast(tx.toHex()); - await regtestUtils.verify({ txId: tx.getId(), address: p2sh.payment.address, @@ -361,15 +347,10 @@ describe('bitcoinjs-lib (transactions with psbt)', () => { }); it('can create (and broadcast via 3PBP) a Transaction, w/ a P2WPKH input with nonWitnessUtxo', async () => { - // the only thing that changes is you don't give a redeemscript for input data - + // For learning purposes, ignore this test. + // REPEATING ABOVE BUT WITH nonWitnessUtxo by passing false to getInputData const p2wpkh = createPayment('p2wpkh'); const inputData = await getInputData(5e4, p2wpkh.payment, false, 'noredeem'); - { - const { hash, index, nonWitnessUtxo } = inputData; - assert.deepStrictEqual({ hash, index, nonWitnessUtxo }, inputData); - } - const psbt = new bitcoin.Psbt({ network: regtest }) .addInput(inputData) .addOutput({ @@ -377,15 +358,9 @@ describe('bitcoinjs-lib (transactions with psbt)', () => { value: 2e4, }) .signInput(0, p2wpkh.keys[0]); - - assert.strictEqual(psbt.validateSignaturesOfInput(0), true); psbt.finalizeAllInputs(); - const tx = psbt.extractTransaction(); - - // build and broadcast to the Bitcoin RegTest network await regtestUtils.broadcast(tx.toHex()); - await regtestUtils.verify({ txId: tx.getId(), address: regtestUtils.RANDOM_ADDRESS, @@ -435,21 +410,10 @@ describe('bitcoinjs-lib (transactions with psbt)', () => { }); it('can create (and broadcast via 3PBP) a Transaction, w/ a P2WSH(P2PK) input with nonWitnessUtxo', async () => { + // For learning purposes, ignore this test. + // REPEATING ABOVE BUT WITH nonWitnessUtxo by passing false to getInputData const p2wsh = createPayment('p2wsh-p2pk'); const inputData = await getInputData(5e4, p2wsh.payment, false, 'p2wsh'); - { - const { - hash, - index, - nonWitnessUtxo, - witnessScript, // NEW: A Buffer of the witnessScript - } = inputData; - assert.deepStrictEqual( - { hash, index, nonWitnessUtxo, witnessScript }, - inputData, - ); - } - const psbt = new bitcoin.Psbt({ network: regtest }) .addInput(inputData) .addOutput({ @@ -457,15 +421,9 @@ describe('bitcoinjs-lib (transactions with psbt)', () => { value: 2e4, }) .signInput(0, p2wsh.keys[0]); - - assert.strictEqual(psbt.validateSignaturesOfInput(0), true); psbt.finalizeAllInputs(); - const tx = psbt.extractTransaction(); - - // build and broadcast to the Bitcoin RegTest network await regtestUtils.broadcast(tx.toHex()); - await regtestUtils.verify({ txId: tx.getId(), address: regtestUtils.RANDOM_ADDRESS, @@ -525,22 +483,10 @@ describe('bitcoinjs-lib (transactions with psbt)', () => { }); it('can create (and broadcast via 3PBP) a Transaction, w/ a P2SH(P2WSH(P2MS(3 of 4))) (SegWit multisig) input with nonWitnessUtxo', async () => { + // For learning purposes, ignore this test. + // REPEATING ABOVE BUT WITH nonWitnessUtxo by passing false to getInputData const p2sh = createPayment('p2sh-p2wsh-p2ms(3 of 4)'); const inputData = await getInputData(5e4, p2sh.payment, false, 'p2sh-p2wsh'); - { - const { - hash, - index, - nonWitnessUtxo, - redeemScript, - witnessScript, - } = inputData; - assert.deepStrictEqual( - { hash, index, nonWitnessUtxo, redeemScript, witnessScript }, - inputData, - ); - } - const psbt = new bitcoin.Psbt({ network: regtest }) .addInput(inputData) .addOutput({ @@ -550,22 +496,9 @@ describe('bitcoinjs-lib (transactions with psbt)', () => { .signInput(0, p2sh.keys[0]) .signInput(0, p2sh.keys[2]) .signInput(0, p2sh.keys[3]); - - assert.strictEqual(psbt.validateSignaturesOfInput(0), true); - assert.strictEqual( - psbt.validateSignaturesOfInput(0, p2sh.keys[3].publicKey), - true, - ); - assert.throws(() => { - psbt.validateSignaturesOfInput(0, p2sh.keys[1].publicKey); - }, new RegExp('No signatures for this pubkey')); psbt.finalizeAllInputs(); - const tx = psbt.extractTransaction(); - - // build and broadcast to the Bitcoin RegTest network await regtestUtils.broadcast(tx.toHex()); - await regtestUtils.verify({ txId: tx.getId(), address: regtestUtils.RANDOM_ADDRESS,