Skip to content

Commit a395af4

Browse files
committed
Simplify nonWitnessUtxo integration tests to not confuse learners
1 parent 4264bd6 commit a395af4

File tree

1 file changed

+10
-77
lines changed

1 file changed

+10
-77
lines changed

test/integration/transactions-psbt.js

Lines changed: 10 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -283,41 +283,27 @@ describe('bitcoinjs-lib (transactions with psbt)', () => {
283283
});
284284

285285
it('can create (and broadcast via 3PBP) a Transaction, w/ a P2SH(P2WPKH) input with nonWitnessUtxo', async () => {
286+
// For learning purposes, ignore this test.
287+
// REPEATING ABOVE BUT WITH nonWitnessUtxo by passing false to getInputData
286288
const p2sh = createPayment('p2sh-p2wpkh');
287289
const inputData = await getInputData(5e4, p2sh.payment, false, 'p2sh');
288290
const inputData2 = await getInputData(5e4, p2sh.payment, false, 'p2sh');
289-
{
290-
const {
291-
hash,
292-
index,
293-
nonWitnessUtxo,
294-
redeemScript,
295-
} = inputData;
296-
assert.deepStrictEqual(
297-
{ hash, index, nonWitnessUtxo, redeemScript },
298-
inputData,
299-
);
300-
}
301291
const keyPair = p2sh.keys[0];
302292
const outputData = {
303-
script: p2sh.payment.output, // sending to myself for fun
293+
script: p2sh.payment.output,
304294
value: 2e4,
305295
};
306296
const outputData2 = {
307-
script: p2sh.payment.output, // sending to myself for fun
297+
script: p2sh.payment.output,
308298
value: 7e4,
309299
};
310-
311300
const tx = new bitcoin.Psbt()
312301
.addInputs([inputData, inputData2])
313302
.addOutputs([outputData, outputData2])
314303
.signAllInputs(keyPair)
315304
.finalizeAllInputs()
316305
.extractTransaction();
317-
318-
// build and broadcast to the Bitcoin RegTest network
319306
await regtestUtils.broadcast(tx.toHex());
320-
321307
await regtestUtils.verify({
322308
txId: tx.getId(),
323309
address: p2sh.payment.address,
@@ -361,31 +347,20 @@ describe('bitcoinjs-lib (transactions with psbt)', () => {
361347
});
362348

363349
it('can create (and broadcast via 3PBP) a Transaction, w/ a P2WPKH input with nonWitnessUtxo', async () => {
364-
// the only thing that changes is you don't give a redeemscript for input data
365-
350+
// For learning purposes, ignore this test.
351+
// REPEATING ABOVE BUT WITH nonWitnessUtxo by passing false to getInputData
366352
const p2wpkh = createPayment('p2wpkh');
367353
const inputData = await getInputData(5e4, p2wpkh.payment, false, 'noredeem');
368-
{
369-
const { hash, index, nonWitnessUtxo } = inputData;
370-
assert.deepStrictEqual({ hash, index, nonWitnessUtxo }, inputData);
371-
}
372-
373354
const psbt = new bitcoin.Psbt({ network: regtest })
374355
.addInput(inputData)
375356
.addOutput({
376357
address: regtestUtils.RANDOM_ADDRESS,
377358
value: 2e4,
378359
})
379360
.signInput(0, p2wpkh.keys[0]);
380-
381-
assert.strictEqual(psbt.validateSignaturesOfInput(0), true);
382361
psbt.finalizeAllInputs();
383-
384362
const tx = psbt.extractTransaction();
385-
386-
// build and broadcast to the Bitcoin RegTest network
387363
await regtestUtils.broadcast(tx.toHex());
388-
389364
await regtestUtils.verify({
390365
txId: tx.getId(),
391366
address: regtestUtils.RANDOM_ADDRESS,
@@ -435,37 +410,20 @@ describe('bitcoinjs-lib (transactions with psbt)', () => {
435410
});
436411

437412
it('can create (and broadcast via 3PBP) a Transaction, w/ a P2WSH(P2PK) input with nonWitnessUtxo', async () => {
413+
// For learning purposes, ignore this test.
414+
// REPEATING ABOVE BUT WITH nonWitnessUtxo by passing false to getInputData
438415
const p2wsh = createPayment('p2wsh-p2pk');
439416
const inputData = await getInputData(5e4, p2wsh.payment, false, 'p2wsh');
440-
{
441-
const {
442-
hash,
443-
index,
444-
nonWitnessUtxo,
445-
witnessScript, // NEW: A Buffer of the witnessScript
446-
} = inputData;
447-
assert.deepStrictEqual(
448-
{ hash, index, nonWitnessUtxo, witnessScript },
449-
inputData,
450-
);
451-
}
452-
453417
const psbt = new bitcoin.Psbt({ network: regtest })
454418
.addInput(inputData)
455419
.addOutput({
456420
address: regtestUtils.RANDOM_ADDRESS,
457421
value: 2e4,
458422
})
459423
.signInput(0, p2wsh.keys[0]);
460-
461-
assert.strictEqual(psbt.validateSignaturesOfInput(0), true);
462424
psbt.finalizeAllInputs();
463-
464425
const tx = psbt.extractTransaction();
465-
466-
// build and broadcast to the Bitcoin RegTest network
467426
await regtestUtils.broadcast(tx.toHex());
468-
469427
await regtestUtils.verify({
470428
txId: tx.getId(),
471429
address: regtestUtils.RANDOM_ADDRESS,
@@ -525,22 +483,10 @@ describe('bitcoinjs-lib (transactions with psbt)', () => {
525483
});
526484

527485
it('can create (and broadcast via 3PBP) a Transaction, w/ a P2SH(P2WSH(P2MS(3 of 4))) (SegWit multisig) input with nonWitnessUtxo', async () => {
486+
// For learning purposes, ignore this test.
487+
// REPEATING ABOVE BUT WITH nonWitnessUtxo by passing false to getInputData
528488
const p2sh = createPayment('p2sh-p2wsh-p2ms(3 of 4)');
529489
const inputData = await getInputData(5e4, p2sh.payment, false, 'p2sh-p2wsh');
530-
{
531-
const {
532-
hash,
533-
index,
534-
nonWitnessUtxo,
535-
redeemScript,
536-
witnessScript,
537-
} = inputData;
538-
assert.deepStrictEqual(
539-
{ hash, index, nonWitnessUtxo, redeemScript, witnessScript },
540-
inputData,
541-
);
542-
}
543-
544490
const psbt = new bitcoin.Psbt({ network: regtest })
545491
.addInput(inputData)
546492
.addOutput({
@@ -550,22 +496,9 @@ describe('bitcoinjs-lib (transactions with psbt)', () => {
550496
.signInput(0, p2sh.keys[0])
551497
.signInput(0, p2sh.keys[2])
552498
.signInput(0, p2sh.keys[3]);
553-
554-
assert.strictEqual(psbt.validateSignaturesOfInput(0), true);
555-
assert.strictEqual(
556-
psbt.validateSignaturesOfInput(0, p2sh.keys[3].publicKey),
557-
true,
558-
);
559-
assert.throws(() => {
560-
psbt.validateSignaturesOfInput(0, p2sh.keys[1].publicKey);
561-
}, new RegExp('No signatures for this pubkey'));
562499
psbt.finalizeAllInputs();
563-
564500
const tx = psbt.extractTransaction();
565-
566-
// build and broadcast to the Bitcoin RegTest network
567501
await regtestUtils.broadcast(tx.toHex());
568-
569502
await regtestUtils.verify({
570503
txId: tx.getId(),
571504
address: regtestUtils.RANDOM_ADDRESS,

0 commit comments

Comments
 (0)