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
|
@ -18,7 +18,11 @@ describe('bitcoinjs-lib (transactions)', () => {
|
|||
txb.addOutput('1cMh228HTCiwS8ZsaakH8A8wze1JR5ZsP', 12000)
|
||||
// (in)15000 - (out)12000 = (fee)3000, this is the miner fee
|
||||
|
||||
txb.sign(0, alice)
|
||||
txb.sign({
|
||||
prevOutScriptType: 'p2pkh',
|
||||
vin: 0,
|
||||
keyPair: alice
|
||||
})
|
||||
|
||||
// prepare for broadcast to the Bitcoin network, see "can broadcast a Transaction" below
|
||||
assert.strictEqual(txb.build().toHex(), '01000000019d344070eac3fe6e394a16d06d7704a7d5c0a10eb2a2c16bc98842b7cc20d561000000006b48304502210088828c0bdfcdca68d8ae0caeb6ec62cd3fd5f9b2191848edae33feb533df35d302202e0beadd35e17e7f83a733f5277028a9b453d525553e3f5d2d7a7aa8010a81d60121029f50f51d63b345039a290c94bffd3180c99ed659ff6ea6b1242bca47eb93b59fffffffff01e02e0000000000001976a91406afd46bcdfd22ef94ac122aa11f241244a37ecc88ac00000000')
|
||||
|
@ -36,8 +40,16 @@ describe('bitcoinjs-lib (transactions)', () => {
|
|||
txb.addOutput('1JtK9CQw1syfWj1WtFMWomrYdV3W2tWBF9', 170000)
|
||||
// (in)(200000 + 300000) - (out)(180000 + 170000) = (fee)150000, this is the miner fee
|
||||
|
||||
txb.sign(1, bob) // Bob signs his input, which was the second input (1th)
|
||||
txb.sign(0, alice) // Alice signs her input, which was the first input (0th)
|
||||
txb.sign({
|
||||
prevOutScriptType: 'p2pkh',
|
||||
vin: 1,
|
||||
keyPair: bob
|
||||
}) // Bob signs his input, which was the second input (1th)
|
||||
txb.sign({
|
||||
prevOutScriptType: 'p2pkh',
|
||||
vin: 0,
|
||||
keyPair: alice
|
||||
}) // Alice signs her input, which was the first input (0th)
|
||||
|
||||
// prepare for broadcast to the Bitcoin network, see "can broadcast a Transaction" below
|
||||
assert.strictEqual(txb.build().toHex(), '01000000024c94e48a870b85f41228d33cf25213dfcc8dd796e7211ed6b1f9a014809dbbb5060000006a473044022041450c258ce7cac7da97316bf2ea1ce66d88967c4df94f3e91f4c2a30f5d08cb02203674d516e6bb2b0afd084c3551614bd9cec3c2945231245e891b145f2d6951f0012103e05ce435e462ec503143305feb6c00e06a3ad52fbf939e85c65f3a765bb7baacffffffff3077d9de049574c3af9bc9c09a7c9db80f2d94caaf63988c9166249b955e867d000000006b483045022100aeb5f1332c79c446d3f906e4499b2e678500580a3f90329edf1ba502eec9402e022072c8b863f8c8d6c26f4c691ac9a6610aa4200edc697306648ee844cfbc089d7a012103df7940ee7cddd2f97763f67e1fb13488da3fbdd7f9c68ec5ef0864074745a289ffffffff0220bf0200000000001976a9147dd65592d0ab2fe0d0257d571abf032cd9db93dc88ac10980200000000001976a914c42e7ef92fdb603af844d064faad95db9bcdfd3d88ac00000000')
|
||||
|
@ -65,8 +77,16 @@ describe('bitcoinjs-lib (transactions)', () => {
|
|||
// (in)(5e4 + 7e4) - (out)(8e4 + 1e4) = (fee)3e4 = 30000, this is the miner fee
|
||||
|
||||
// Alice signs each input with the respective private keys
|
||||
txb.sign(0, alice1)
|
||||
txb.sign(1, alice2)
|
||||
txb.sign({
|
||||
prevOutScriptType: 'p2pkh',
|
||||
vin: 0,
|
||||
keyPair: alice1
|
||||
})
|
||||
txb.sign({
|
||||
prevOutScriptType: 'p2pkh',
|
||||
vin: 1,
|
||||
keyPair: alice2
|
||||
})
|
||||
|
||||
// build and broadcast our RegTest network
|
||||
await regtestUtils.broadcast(txb.build().toHex())
|
||||
|
@ -85,7 +105,11 @@ describe('bitcoinjs-lib (transactions)', () => {
|
|||
txb.addInput(unspent.txId, unspent.vout)
|
||||
txb.addOutput(embed.output, 1000)
|
||||
txb.addOutput(regtestUtils.RANDOM_ADDRESS, 1e5)
|
||||
txb.sign(0, keyPair)
|
||||
txb.sign({
|
||||
prevOutScriptType: 'p2pkh',
|
||||
vin: 0,
|
||||
keyPair,
|
||||
})
|
||||
|
||||
// build and broadcast to the RegTest network
|
||||
await regtestUtils.broadcast(txb.build().toHex())
|
||||
|
@ -108,8 +132,18 @@ describe('bitcoinjs-lib (transactions)', () => {
|
|||
txb.addInput(unspent.txId, unspent.vout)
|
||||
txb.addOutput(regtestUtils.RANDOM_ADDRESS, 1e4)
|
||||
|
||||
txb.sign(0, keyPairs[0], p2sh.redeem.output)
|
||||
txb.sign(0, keyPairs[2], p2sh.redeem.output)
|
||||
txb.sign({
|
||||
prevOutScriptType: 'p2sh-p2ms',
|
||||
vin: 0,
|
||||
keyPair: keyPairs[0],
|
||||
redeemScript: p2sh.redeem.output,
|
||||
})
|
||||
txb.sign({
|
||||
prevOutScriptType: 'p2sh-p2ms',
|
||||
vin: 0,
|
||||
keyPair: keyPairs[2],
|
||||
redeemScript: p2sh.redeem.output,
|
||||
})
|
||||
const tx = txb.build()
|
||||
|
||||
// build and broadcast to the Bitcoin RegTest network
|
||||
|
@ -133,7 +167,13 @@ describe('bitcoinjs-lib (transactions)', () => {
|
|||
const txb = new bitcoin.TransactionBuilder(regtest)
|
||||
txb.addInput(unspent.txId, unspent.vout)
|
||||
txb.addOutput(regtestUtils.RANDOM_ADDRESS, 2e4)
|
||||
txb.sign(0, keyPair, p2sh.redeem.output, null, unspent.value)
|
||||
txb.sign({
|
||||
prevOutScriptType: 'p2sh-p2wpkh',
|
||||
vin: 0,
|
||||
keyPair: keyPair,
|
||||
redeemScript: p2sh.redeem.output,
|
||||
witnessValue: unspent.value,
|
||||
})
|
||||
|
||||
const tx = txb.build()
|
||||
|
||||
|
@ -158,7 +198,12 @@ describe('bitcoinjs-lib (transactions)', () => {
|
|||
const txb = new bitcoin.TransactionBuilder(regtest)
|
||||
txb.addInput(unspent.txId, unspent.vout, null, p2wpkh.output) // NOTE: provide the prevOutScript!
|
||||
txb.addOutput(regtestUtils.RANDOM_ADDRESS, 2e4)
|
||||
txb.sign(0, keyPair, null, null, unspent.value) // NOTE: no redeem script
|
||||
txb.sign({
|
||||
prevOutScriptType: 'p2wpkh',
|
||||
vin: 0,
|
||||
keyPair: keyPair,
|
||||
witnessValue: unspent.value,
|
||||
}) // NOTE: no redeem script
|
||||
const tx = txb.build()
|
||||
|
||||
// build and broadcast (the P2WPKH transaction) to the Bitcoin RegTest network
|
||||
|
@ -183,7 +228,13 @@ describe('bitcoinjs-lib (transactions)', () => {
|
|||
const txb = new bitcoin.TransactionBuilder(regtest)
|
||||
txb.addInput(unspent.txId, unspent.vout, null, p2wsh.output) // NOTE: provide the prevOutScript!
|
||||
txb.addOutput(regtestUtils.RANDOM_ADDRESS, 2e4)
|
||||
txb.sign(0, keyPair, null, null, 5e4, p2wsh.redeem.output) // NOTE: provide a witnessScript!
|
||||
txb.sign({
|
||||
prevOutScriptType: 'p2wsh-p2pk',
|
||||
vin: 0,
|
||||
keyPair: keyPair,
|
||||
witnessValue: 5e4,
|
||||
witnessScript: p2wsh.redeem.output,
|
||||
}) // NOTE: provide a witnessScript!
|
||||
const tx = txb.build()
|
||||
|
||||
// build and broadcast (the P2WSH transaction) to the Bitcoin RegTest network
|
||||
|
@ -215,9 +266,30 @@ describe('bitcoinjs-lib (transactions)', () => {
|
|||
const txb = new bitcoin.TransactionBuilder(regtest)
|
||||
txb.addInput(unspent.txId, unspent.vout, null, p2sh.output)
|
||||
txb.addOutput(regtestUtils.RANDOM_ADDRESS, 3e4)
|
||||
txb.sign(0, keyPairs[0], p2sh.redeem.output, null, unspent.value, p2wsh.redeem.output)
|
||||
txb.sign(0, keyPairs[2], p2sh.redeem.output, null, unspent.value, p2wsh.redeem.output)
|
||||
txb.sign(0, keyPairs[3], p2sh.redeem.output, null, unspent.value, p2wsh.redeem.output)
|
||||
txb.sign({
|
||||
prevOutScriptType: 'p2sh-p2wsh-p2ms',
|
||||
vin: 0,
|
||||
keyPair: keyPairs[0],
|
||||
redeemScript: p2sh.redeem.output,
|
||||
witnessValue: unspent.value,
|
||||
witnessScript: p2wsh.redeem.output,
|
||||
})
|
||||
txb.sign({
|
||||
prevOutScriptType: 'p2sh-p2wsh-p2ms',
|
||||
vin: 0,
|
||||
keyPair: keyPairs[2],
|
||||
redeemScript: p2sh.redeem.output,
|
||||
witnessValue: unspent.value,
|
||||
witnessScript: p2wsh.redeem.output,
|
||||
})
|
||||
txb.sign({
|
||||
prevOutScriptType: 'p2sh-p2wsh-p2ms',
|
||||
vin: 0,
|
||||
keyPair: keyPairs[3],
|
||||
redeemScript: p2sh.redeem.output,
|
||||
witnessValue: unspent.value,
|
||||
witnessScript: p2wsh.redeem.output,
|
||||
})
|
||||
|
||||
const tx = txb.build()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue