@@ -171,91 +171,63 @@ describe('bitcoinjs-lib (transactions)', function () {
171171 } )
172172 } )
173173
174- it ( 'can create (and broadcast via 3PBP) a Transaction, w/ a P2WPKH input (via a P2SH(P2WPKH) transaction) ' , function ( done ) {
174+ it ( 'can create (and broadcast via 3PBP) a Transaction, w/ a P2WPKH input' , function ( done ) {
175175 this . timeout ( 30000 )
176176
177177 const keyPair = bitcoin . ECPair . makeRandom ( { network : regtest } )
178178 const p2wpkh = bitcoin . payments . p2wpkh ( { pubkey : keyPair . publicKey , network : regtest } )
179179
180- // prepare a P2SH(P2WPKH) faucet transaction, as Bitcoin-core doesn't support bare P2WPKH outputs (...yet)
181- const p2sh = bitcoin . payments . p2sh ( { redeem : p2wpkh , network : regtest } )
182-
183- regtestUtils . faucet ( p2sh . address , 10e4 , function ( err , unspent ) {
180+ regtestUtils . faucetComplex ( p2wpkh . address , 5e4 , function ( err , unspent ) {
184181 if ( err ) return done ( err )
185182
186- const txvb = new bitcoin . TransactionBuilder ( regtest )
187- txvb . addInput ( unspent . txId , unspent . vout )
188- txvb . addOutput ( p2wpkh . address , 6e4 ) // funds a P2WPKH address
189- txvb . sign ( 0 , keyPair , p2sh . redeem . output , null , unspent . value )
190- const txv = txvb . build ( )
183+ // XXX: build the Transaction w/ a P2WPKH input
184+ const txb = new bitcoin . TransactionBuilder ( regtest )
185+ txb . addInput ( unspent . txId , unspent . vout , null , p2wpkh . output ) // NOTE: provide the prevOutScript!
186+ txb . addOutput ( regtestUtils . RANDOM_ADDRESS , 2e4 )
187+ txb . sign ( 0 , keyPair , null , null , unspent . value ) // NOTE: no redeem script
188+ const tx = txb . build ( )
191189
192- // build and broadcast (the via transaction) to the Bitcoin RegTest network
193- regtestUtils . broadcast ( txv . toHex ( ) , function ( err ) {
190+ // build and broadcast (the P2WPKH transaction) to the Bitcoin RegTest network
191+ regtestUtils . broadcast ( tx . toHex ( ) , function ( err ) {
194192 if ( err ) return done ( err )
195193
196- // XXX: build the Transaction w/ a P2WPKH input
197- const txb = new bitcoin . TransactionBuilder ( regtest )
198- txb . addInput ( txv . getId ( ) , 0 , null , p2wpkh . output ) // NOTE: provide the prevOutScript!
199- txb . addOutput ( regtestUtils . RANDOM_ADDRESS , 2e4 )
200- txb . sign ( 0 , keyPair , null , null , 6e4 ) // NOTE: no redeem script
201- const tx = txb . build ( )
202-
203- // build and broadcast (the P2WPKH transaction) to the Bitcoin RegTest network
204- regtestUtils . broadcast ( tx . toHex ( ) , function ( err ) {
205- if ( err ) return done ( err )
206-
207- regtestUtils . verify ( {
208- txId : tx . getId ( ) ,
209- address : regtestUtils . RANDOM_ADDRESS ,
210- vout : 0 ,
211- value : 2e4
212- } , done )
213- } )
194+ regtestUtils . verify ( {
195+ txId : tx . getId ( ) ,
196+ address : regtestUtils . RANDOM_ADDRESS ,
197+ vout : 0 ,
198+ value : 2e4
199+ } , done )
214200 } )
215201 } )
216202 } )
217203
218- it ( 'can create (and broadcast via 3PBP) a Transaction, w/ a P2WSH(P2PK) input (via a P2SH(P2PK) transaction) ' , function ( done ) {
204+ it ( 'can create (and broadcast via 3PBP) a Transaction, w/ a P2WSH(P2PK) input' , function ( done ) {
219205 this . timeout ( 30000 )
220206
221207 const keyPair = bitcoin . ECPair . makeRandom ( { network : regtest } )
222208 const p2pk = bitcoin . payments . p2pk ( { pubkey : keyPair . publicKey , network : regtest } )
223209 const p2wsh = bitcoin . payments . p2wsh ( { redeem : p2pk , network : regtest } )
224210
225- // prepare a P2SH(P2PK) faucet transaction, as Bitcoin-core doesn't support bare P2WSH outputs (...yet)
226- const p2sh = bitcoin . payments . p2sh ( { redeem : p2pk , network : regtest } )
227-
228- regtestUtils . faucet ( p2sh . address , 10e4 , function ( err , unspent ) {
211+ regtestUtils . faucetComplex ( p2wsh . address , 5e4 , function ( err , unspent ) {
229212 if ( err ) return done ( err )
230213
231- const txvb = new bitcoin . TransactionBuilder ( regtest )
232- txvb . addInput ( unspent . txId , unspent . vout )
233- txvb . addOutput ( p2wsh . address , 6e4 ) // funds a P2WPKH address
234- txvb . sign ( 0 , keyPair , p2sh . redeem . output )
235- const txv = txvb . build ( )
214+ // XXX: build the Transaction w/ a P2WSH input
215+ const txb = new bitcoin . TransactionBuilder ( regtest )
216+ txb . addInput ( unspent . txId , unspent . vout , null , p2wsh . output ) // NOTE: provide the prevOutScript!
217+ txb . addOutput ( regtestUtils . RANDOM_ADDRESS , 2e4 )
218+ txb . sign ( 0 , keyPair , null , null , 5e4 , p2wsh . redeem . output ) // NOTE: provide a witnessScript!
219+ const tx = txb . build ( )
236220
237- // build and broadcast (the via transaction) to the Bitcoin RegTest network
238- regtestUtils . broadcast ( txv . toHex ( ) , function ( err ) {
221+ // build and broadcast (the P2WSH transaction) to the Bitcoin RegTest network
222+ regtestUtils . broadcast ( tx . toHex ( ) , function ( err ) {
239223 if ( err ) return done ( err )
240224
241- // XXX: build the Transaction w/ a P2WSH input
242- const txb = new bitcoin . TransactionBuilder ( regtest )
243- txb . addInput ( txv . getId ( ) , 0 , null , p2wsh . output ) // NOTE: provide the prevOutScript!
244- txb . addOutput ( regtestUtils . RANDOM_ADDRESS , 2e4 )
245- txb . sign ( 0 , keyPair , null , null , 6e4 , p2wsh . redeem . output ) // NOTE: provide a witnessScript!
246- const tx = txb . build ( )
247-
248- // build and broadcast (the P2WSH transaction) to the Bitcoin RegTest network
249- regtestUtils . broadcast ( tx . toHex ( ) , function ( err ) {
250- if ( err ) return done ( err )
251-
252- regtestUtils . verify ( {
253- txId : tx . getId ( ) ,
254- address : regtestUtils . RANDOM_ADDRESS ,
255- vout : 0 ,
256- value : 2e4
257- } , done )
258- } )
225+ regtestUtils . verify ( {
226+ txId : tx . getId ( ) ,
227+ address : regtestUtils . RANDOM_ADDRESS ,
228+ vout : 0 ,
229+ value : 2e4
230+ } , done )
259231 } )
260232 } )
261233 } )
0 commit comments