@@ -283,41 +283,27 @@ describe('bitcoinjs-lib (transactions with psbt)', () => {
283
283
} ) ;
284
284
285
285
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
286
288
const p2sh = createPayment ( 'p2sh-p2wpkh' ) ;
287
289
const inputData = await getInputData ( 5e4 , p2sh . payment , false , 'p2sh' ) ;
288
290
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
- }
301
291
const keyPair = p2sh . keys [ 0 ] ;
302
292
const outputData = {
303
- script : p2sh . payment . output , // sending to myself for fun
293
+ script : p2sh . payment . output ,
304
294
value : 2e4 ,
305
295
} ;
306
296
const outputData2 = {
307
- script : p2sh . payment . output , // sending to myself for fun
297
+ script : p2sh . payment . output ,
308
298
value : 7e4 ,
309
299
} ;
310
-
311
300
const tx = new bitcoin . Psbt ( )
312
301
. addInputs ( [ inputData , inputData2 ] )
313
302
. addOutputs ( [ outputData , outputData2 ] )
314
303
. signAllInputs ( keyPair )
315
304
. finalizeAllInputs ( )
316
305
. extractTransaction ( ) ;
317
-
318
- // build and broadcast to the Bitcoin RegTest network
319
306
await regtestUtils . broadcast ( tx . toHex ( ) ) ;
320
-
321
307
await regtestUtils . verify ( {
322
308
txId : tx . getId ( ) ,
323
309
address : p2sh . payment . address ,
@@ -361,31 +347,20 @@ describe('bitcoinjs-lib (transactions with psbt)', () => {
361
347
} ) ;
362
348
363
349
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
366
352
const p2wpkh = createPayment ( 'p2wpkh' ) ;
367
353
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
-
373
354
const psbt = new bitcoin . Psbt ( { network : regtest } )
374
355
. addInput ( inputData )
375
356
. addOutput ( {
376
357
address : regtestUtils . RANDOM_ADDRESS ,
377
358
value : 2e4 ,
378
359
} )
379
360
. signInput ( 0 , p2wpkh . keys [ 0 ] ) ;
380
-
381
- assert . strictEqual ( psbt . validateSignaturesOfInput ( 0 ) , true ) ;
382
361
psbt . finalizeAllInputs ( ) ;
383
-
384
362
const tx = psbt . extractTransaction ( ) ;
385
-
386
- // build and broadcast to the Bitcoin RegTest network
387
363
await regtestUtils . broadcast ( tx . toHex ( ) ) ;
388
-
389
364
await regtestUtils . verify ( {
390
365
txId : tx . getId ( ) ,
391
366
address : regtestUtils . RANDOM_ADDRESS ,
@@ -435,37 +410,20 @@ describe('bitcoinjs-lib (transactions with psbt)', () => {
435
410
} ) ;
436
411
437
412
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
438
415
const p2wsh = createPayment ( 'p2wsh-p2pk' ) ;
439
416
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
-
453
417
const psbt = new bitcoin . Psbt ( { network : regtest } )
454
418
. addInput ( inputData )
455
419
. addOutput ( {
456
420
address : regtestUtils . RANDOM_ADDRESS ,
457
421
value : 2e4 ,
458
422
} )
459
423
. signInput ( 0 , p2wsh . keys [ 0 ] ) ;
460
-
461
- assert . strictEqual ( psbt . validateSignaturesOfInput ( 0 ) , true ) ;
462
424
psbt . finalizeAllInputs ( ) ;
463
-
464
425
const tx = psbt . extractTransaction ( ) ;
465
-
466
- // build and broadcast to the Bitcoin RegTest network
467
426
await regtestUtils . broadcast ( tx . toHex ( ) ) ;
468
-
469
427
await regtestUtils . verify ( {
470
428
txId : tx . getId ( ) ,
471
429
address : regtestUtils . RANDOM_ADDRESS ,
@@ -525,22 +483,10 @@ describe('bitcoinjs-lib (transactions with psbt)', () => {
525
483
} ) ;
526
484
527
485
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
528
488
const p2sh = createPayment ( 'p2sh-p2wsh-p2ms(3 of 4)' ) ;
529
489
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
-
544
490
const psbt = new bitcoin . Psbt ( { network : regtest } )
545
491
. addInput ( inputData )
546
492
. addOutput ( {
@@ -550,22 +496,9 @@ describe('bitcoinjs-lib (transactions with psbt)', () => {
550
496
. signInput ( 0 , p2sh . keys [ 0 ] )
551
497
. signInput ( 0 , p2sh . keys [ 2 ] )
552
498
. 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' ) ) ;
562
499
psbt . finalizeAllInputs ( ) ;
563
-
564
500
const tx = psbt . extractTransaction ( ) ;
565
-
566
- // build and broadcast to the Bitcoin RegTest network
567
501
await regtestUtils . broadcast ( tx . toHex ( ) ) ;
568
-
569
502
await regtestUtils . verify ( {
570
503
txId : tx . getId ( ) ,
571
504
address : regtestUtils . RANDOM_ADDRESS ,
0 commit comments