Tests to arrow functions, use strict asserts, travis uses docker instead of regtest server
This commit is contained in:
parent
16823e9013
commit
dc1ef5958b
24 changed files with 505 additions and 498 deletions
|
@ -47,7 +47,7 @@ async function faucet (address, value) {
|
|||
let _unspents = []
|
||||
const sleep = ms => new Promise((resolve, reject) => setTimeout(resolve, ms))
|
||||
const randInt = (min, max) => min + Math.floor((max - min + 1) * Math.random())
|
||||
do {
|
||||
while (_unspents.length === 0) {
|
||||
if (count > 0) {
|
||||
if (count >= 5) throw new Error('Missing Inputs')
|
||||
console.log('Missing Inputs, retry #' + count)
|
||||
|
@ -78,7 +78,7 @@ async function faucet (address, value) {
|
|||
_unspents = results.filter(x => x.txId === txId)
|
||||
|
||||
count++
|
||||
} while (_unspents.length === 0)
|
||||
}
|
||||
|
||||
return _unspents.pop()
|
||||
}
|
||||
|
|
|
@ -4,8 +4,8 @@ const bitcoin = require('../../')
|
|||
const dhttp = require('./_regtest').dhttp
|
||||
const TESTNET = bitcoin.networks.testnet
|
||||
|
||||
describe('bitcoinjs-lib (addresses)', function () {
|
||||
it('can generate a random address [and support the retrieval of transactions for that address (via 3PBP)', async function () {
|
||||
describe('bitcoinjs-lib (addresses)', () => {
|
||||
it('can generate a random address [and support the retrieval of transactions for that address (via 3PBP)', async () => {
|
||||
const keyPair = bitcoin.ECPair.makeRandom()
|
||||
const { address } = bitcoin.payments.p2pkh({ pubkey: keyPair.publicKey })
|
||||
|
||||
|
@ -23,14 +23,14 @@ describe('bitcoinjs-lib (addresses)', function () {
|
|||
assert.strictEqual(result.total_sent, 0)
|
||||
})
|
||||
|
||||
it('can import an address via WIF', function () {
|
||||
it('can import an address via WIF', () => {
|
||||
const keyPair = bitcoin.ECPair.fromWIF('KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M7rFU73sVHnoWn')
|
||||
const { address } = bitcoin.payments.p2pkh({ pubkey: keyPair.publicKey })
|
||||
|
||||
assert.strictEqual(address, '1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH')
|
||||
})
|
||||
|
||||
it('can generate a P2SH, pay-to-multisig (2-of-3) address', function () {
|
||||
it('can generate a P2SH, pay-to-multisig (2-of-3) address', () => {
|
||||
const pubkeys = [
|
||||
'026477115981fe981a6918a6297d9803c4dc04f328f22041bedff886bbc2962e01',
|
||||
'02c96db2302d19b43d4c69368babace7854cc84eb9e061cde51cfa77ca4a22b8b9',
|
||||
|
@ -43,14 +43,14 @@ describe('bitcoinjs-lib (addresses)', function () {
|
|||
assert.strictEqual(address, '36NUkt6FWUi3LAWBqWRdDmdTWbt91Yvfu7')
|
||||
})
|
||||
|
||||
it('can generate a SegWit address', function () {
|
||||
it('can generate a SegWit address', () => {
|
||||
const keyPair = bitcoin.ECPair.fromWIF('KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M7rFU73sVHnoWn')
|
||||
const { address } = bitcoin.payments.p2wpkh({ pubkey: keyPair.publicKey })
|
||||
|
||||
assert.strictEqual(address, 'bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4')
|
||||
})
|
||||
|
||||
it('can generate a SegWit address (via P2SH)', function () {
|
||||
it('can generate a SegWit address (via P2SH)', () => {
|
||||
const keyPair = bitcoin.ECPair.fromWIF('KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M7rFU73sVHnoWn')
|
||||
const { address } = bitcoin.payments.p2sh({
|
||||
redeem: bitcoin.payments.p2wpkh({ pubkey: keyPair.publicKey })
|
||||
|
@ -59,7 +59,7 @@ describe('bitcoinjs-lib (addresses)', function () {
|
|||
assert.strictEqual(address, '3JvL6Ymt8MVWiCNHC7oWU6nLeHNJKLZGLN')
|
||||
})
|
||||
|
||||
it('can generate a P2WSH (SegWit), pay-to-multisig (3-of-4) address', function () {
|
||||
it('can generate a P2WSH (SegWit), pay-to-multisig (3-of-4) address', () => {
|
||||
const pubkeys = [
|
||||
'026477115981fe981a6918a6297d9803c4dc04f328f22041bedff886bbc2962e01',
|
||||
'02c96db2302d19b43d4c69368babace7854cc84eb9e061cde51cfa77ca4a22b8b9',
|
||||
|
@ -73,7 +73,7 @@ describe('bitcoinjs-lib (addresses)', function () {
|
|||
assert.strictEqual(address, 'bc1q75f6dv4q8ug7zhujrsp5t0hzf33lllnr3fe7e2pra3v24mzl8rrqtp3qul')
|
||||
})
|
||||
|
||||
it('can generate a P2SH(P2WSH(...)), pay-to-multisig (2-of-2) address', function () {
|
||||
it('can generate a P2SH(P2WSH(...)), pay-to-multisig (2-of-2) address', () => {
|
||||
const pubkeys = [
|
||||
'026477115981fe981a6918a6297d9803c4dc04f328f22041bedff886bbc2962e01',
|
||||
'02c96db2302d19b43d4c69368babace7854cc84eb9e061cde51cfa77ca4a22b8b9'
|
||||
|
@ -88,7 +88,7 @@ describe('bitcoinjs-lib (addresses)', function () {
|
|||
})
|
||||
|
||||
// examples using other network information
|
||||
it('can generate a Testnet address', function () {
|
||||
it('can generate a Testnet address', () => {
|
||||
const keyPair = bitcoin.ECPair.makeRandom({ network: TESTNET })
|
||||
const { address } = bitcoin.payments.p2pkh({ pubkey: keyPair.publicKey, network: TESTNET })
|
||||
|
||||
|
@ -96,7 +96,7 @@ describe('bitcoinjs-lib (addresses)', function () {
|
|||
assert.strictEqual(address.startsWith('m') || address.startsWith('n'), true)
|
||||
})
|
||||
|
||||
it('can generate a Litecoin address', function () {
|
||||
it('can generate a Litecoin address', () => {
|
||||
// WARNING: although possible, bitcoinjs is NOT necessarily compatible with Litecoin
|
||||
const LITECOIN = {
|
||||
messagePrefix: '\x19Litecoin Signed Message:\n',
|
||||
|
|
|
@ -8,15 +8,15 @@ function getAddress (node, network) {
|
|||
return bitcoin.payments.p2pkh({ pubkey: node.publicKey, network }).address
|
||||
}
|
||||
|
||||
describe('bitcoinjs-lib (BIP32)', function () {
|
||||
it('can import a BIP32 testnet xpriv and export to WIF', function () {
|
||||
describe('bitcoinjs-lib (BIP32)', () => {
|
||||
it('can import a BIP32 testnet xpriv and export to WIF', () => {
|
||||
const xpriv = 'tprv8ZgxMBicQKsPd7Uf69XL1XwhmjHopUGep8GuEiJDZmbQz6o58LninorQAfcKZWARbtRtfnLcJ5MQ2AtHcQJCCRUcMRvmDUjyEmNUWwx8UbK'
|
||||
const node = bip32.fromBase58(xpriv, bitcoin.networks.testnet)
|
||||
|
||||
assert.strictEqual(node.toWIF(), 'cQfoY67cetFNunmBUX5wJiw3VNoYx3gG9U9CAofKE6BfiV1fSRw7')
|
||||
})
|
||||
|
||||
it('can export a BIP32 xpriv, then import it', function () {
|
||||
it('can export a BIP32 xpriv, then import it', () => {
|
||||
const mnemonic = 'praise you muffin lion enable neck grocery crumble super myself license ghost'
|
||||
const seed = bip39.mnemonicToSeed(mnemonic)
|
||||
const node = bip32.fromSeed(seed)
|
||||
|
@ -27,7 +27,7 @@ describe('bitcoinjs-lib (BIP32)', function () {
|
|||
assert.strictEqual(node.toWIF(), restored.toWIF()) // same private key
|
||||
})
|
||||
|
||||
it('can export a BIP32 xpub', function () {
|
||||
it('can export a BIP32 xpub', () => {
|
||||
const mnemonic = 'praise you muffin lion enable neck grocery crumble super myself license ghost'
|
||||
const seed = bip39.mnemonicToSeed(mnemonic)
|
||||
const node = bip32.fromSeed(seed)
|
||||
|
@ -36,7 +36,7 @@ describe('bitcoinjs-lib (BIP32)', function () {
|
|||
assert.strictEqual(string, 'xpub661MyMwAqRbcGhVeaVfEBA25e3cP9DsJQZoE8iep5fZSxy3TnPBNBgWnMZx56oreNc48ZoTkQfatNJ9VWnQ7ZcLZcVStpaXLTeG8bGrzX3n')
|
||||
})
|
||||
|
||||
it('can create a BIP32, bitcoin, account 0, external address', function () {
|
||||
it('can create a BIP32, bitcoin, account 0, external address', () => {
|
||||
const path = "m/0'/0/0"
|
||||
const root = bip32.fromSeed(Buffer.from('dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd', 'hex'))
|
||||
|
||||
|
@ -51,7 +51,7 @@ describe('bitcoinjs-lib (BIP32)', function () {
|
|||
assert.strictEqual(getAddress(child1b), '1JHyB1oPXufr4FXkfitsjgNB5yRY9jAaa7')
|
||||
})
|
||||
|
||||
it('can create a BIP44, bitcoin, account 0, external address', function () {
|
||||
it('can create a BIP44, bitcoin, account 0, external address', () => {
|
||||
const root = bip32.fromSeed(Buffer.from('dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd', 'hex'))
|
||||
|
||||
const child1 = root.derivePath("m/44'/0'/0'/0/0")
|
||||
|
@ -67,7 +67,7 @@ describe('bitcoinjs-lib (BIP32)', function () {
|
|||
assert.strictEqual(getAddress(child1b), '12Tyvr1U8A3ped6zwMEU5M8cx3G38sP5Au')
|
||||
})
|
||||
|
||||
it('can create a BIP49, bitcoin testnet, account 0, external address', function () {
|
||||
it('can create a BIP49, bitcoin testnet, account 0, external address', () => {
|
||||
const mnemonic = 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about'
|
||||
const seed = bip39.mnemonicToSeed(mnemonic)
|
||||
const root = bip32.fromSeed(seed)
|
||||
|
@ -82,7 +82,7 @@ describe('bitcoinjs-lib (BIP32)', function () {
|
|||
assert.strictEqual(address, '2Mww8dCYPUpKHofjgcXcBCEGmniw9CoaiD2')
|
||||
})
|
||||
|
||||
it('can use BIP39 to generate BIP32 addresses', function () {
|
||||
it('can use BIP39 to generate BIP32 addresses', () => {
|
||||
// var mnemonic = bip39.generateMnemonic()
|
||||
const mnemonic = 'praise you muffin lion enable neck grocery crumble super myself license ghost'
|
||||
assert(bip39.validateMnemonic(mnemonic))
|
||||
|
|
|
@ -4,8 +4,8 @@ const { describe, it } = require('mocha')
|
|||
const assert = require('assert')
|
||||
const bitcoin = require('../../')
|
||||
|
||||
describe('bitcoinjs-lib (blocks)', function () {
|
||||
it('can extract a height from a CoinBase transaction', function () {
|
||||
describe('bitcoinjs-lib (blocks)', () => {
|
||||
it('can extract a height from a CoinBase transaction', () => {
|
||||
// from 00000000000000000097669cdca131f24d40c4cc7d80eaa65967a2d09acf6ce6
|
||||
const txHex = '010000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff50037f9a07174d696e656420627920416e74506f6f6c685b205a2b1f7bfabe6d6d36afe1910eca9405b66f97750940a656e38e2c0312958190ff8e98fd16761d220400000000000000aa340000d49f0000ffffffff02b07fc366000000001976a9148349212dc27ce3ab4c5b29b85c4dec643d764b1788ac0000000000000000266a24aa21a9ed72d9432948505e3d3062f1307a3f027a5dea846ff85e47159680919c12bf1e400120000000000000000000000000000000000000000000000000000000000000000000000000'
|
||||
const tx = bitcoin.Transaction.fromHex(txHex)
|
||||
|
|
|
@ -8,9 +8,9 @@ const bip65 = require('bip65')
|
|||
const alice = bitcoin.ECPair.fromWIF('cScfkGjbzzoeewVWmU2hYPUHeVGJRDdFt7WhmrVVGkxpmPP8BHWe', regtest)
|
||||
const bob = bitcoin.ECPair.fromWIF('cMkopUXKWsEzAjfa1zApksGRwjVpJRB3831qM9W4gKZsLwjHXA9x', regtest)
|
||||
|
||||
describe('bitcoinjs-lib (transactions w/ CLTV)', function () {
|
||||
describe('bitcoinjs-lib (transactions w/ CLTV)', () => {
|
||||
// force update MTP
|
||||
before(async function () {
|
||||
before(async () => {
|
||||
await regtestUtils.mine(11)
|
||||
})
|
||||
|
||||
|
@ -38,7 +38,7 @@ describe('bitcoinjs-lib (transactions w/ CLTV)', function () {
|
|||
}
|
||||
|
||||
// expiry past, {Alice's signature} OP_TRUE
|
||||
it('can create (and broadcast via 3PBP) a Transaction where Alice can redeem the output after the expiry (in the past)', async function () {
|
||||
it('can create (and broadcast via 3PBP) a Transaction where Alice can redeem the output after the expiry (in the past)', async () => {
|
||||
// 3 hours ago
|
||||
const lockTime = bip65.encode({ utc: utcNow() - (3600 * 3) })
|
||||
const redeemScript = cltvCheckSigOutput(alice, bob, lockTime)
|
||||
|
@ -77,7 +77,7 @@ describe('bitcoinjs-lib (transactions w/ CLTV)', function () {
|
|||
})
|
||||
|
||||
// expiry will pass, {Alice's signature} OP_TRUE
|
||||
it('can create (and broadcast via 3PBP) a Transaction where Alice can redeem the output after the expiry (in the future)', async function () {
|
||||
it('can create (and broadcast via 3PBP) a Transaction where Alice can redeem the output after the expiry (in the future)', async () => {
|
||||
const height = await regtestUtils.height()
|
||||
// 5 blocks from now
|
||||
const lockTime = bip65.encode({ blocks: height + 5 })
|
||||
|
@ -120,7 +120,7 @@ describe('bitcoinjs-lib (transactions w/ CLTV)', function () {
|
|||
})
|
||||
|
||||
// expiry ignored, {Bob's signature} {Alice's signature} OP_FALSE
|
||||
it('can create (and broadcast via 3PBP) a Transaction where Alice and Bob can redeem the output at any time', async function () {
|
||||
it('can create (and broadcast via 3PBP) a Transaction where Alice and Bob can redeem the output at any time', async () => {
|
||||
// two hours ago
|
||||
const lockTime = bip65.encode({ utc: utcNow() - (3600 * 2) })
|
||||
const redeemScript = cltvCheckSigOutput(alice, bob, lockTime)
|
||||
|
@ -159,7 +159,7 @@ describe('bitcoinjs-lib (transactions w/ CLTV)', function () {
|
|||
})
|
||||
|
||||
// expiry in the future, {Alice's signature} OP_TRUE
|
||||
it('can create (but fail to broadcast via 3PBP) a Transaction where Alice attempts to redeem before the expiry', async function () {
|
||||
it('can create (but fail to broadcast via 3PBP) a Transaction where Alice attempts to redeem before the expiry', async () => {
|
||||
// two hours from now
|
||||
const lockTime = bip65.encode({ utc: utcNow() + (3600 * 2) })
|
||||
const redeemScript = cltvCheckSigOutput(alice, bob, lockTime)
|
||||
|
@ -189,7 +189,7 @@ describe('bitcoinjs-lib (transactions w/ CLTV)', function () {
|
|||
tx.setInputScript(0, redeemScriptSig)
|
||||
|
||||
await regtestUtils.broadcast(tx.toHex()).catch(err => {
|
||||
assert.throws(function () {
|
||||
assert.throws(() => {
|
||||
if (err) throw err
|
||||
}, /Error: non-final \(code 64\)/)
|
||||
})
|
||||
|
|
|
@ -8,9 +8,9 @@ const bip68 = require('bip68')
|
|||
const alice = bitcoin.ECPair.fromWIF('cScfkGjbzzoeewVWmU2hYPUHeVGJRDdFt7WhmrVVGkxpmPP8BHWe', regtest)
|
||||
const bob = bitcoin.ECPair.fromWIF('cMkopUXKWsEzAjfa1zApksGRwjVpJRB3831qM9W4gKZsLwjHXA9x', regtest)
|
||||
|
||||
describe('bitcoinjs-lib (transactions w/ CSV)', function () {
|
||||
describe('bitcoinjs-lib (transactions w/ CSV)', () => {
|
||||
// force update MTP
|
||||
before(async function () {
|
||||
before(async () => {
|
||||
await regtestUtils.mine(11)
|
||||
})
|
||||
|
||||
|
@ -35,7 +35,7 @@ describe('bitcoinjs-lib (transactions w/ CSV)', function () {
|
|||
}
|
||||
|
||||
// expiry will pass, {Alice's signature} OP_TRUE
|
||||
it('can create (and broadcast via 3PBP) a Transaction where Alice can redeem the output after the expiry (in the future)', async function () {
|
||||
it('can create (and broadcast via 3PBP) a Transaction where Alice can redeem the output after the expiry (in the future)', async () => {
|
||||
// 5 blocks from now
|
||||
const sequence = bip68.encode({ blocks: 5 })
|
||||
const p2sh = bitcoin.payments.p2sh({
|
||||
|
@ -84,7 +84,7 @@ describe('bitcoinjs-lib (transactions w/ CSV)', function () {
|
|||
})
|
||||
|
||||
// expiry in the future, {Alice's signature} OP_TRUE
|
||||
it('can create (but fail to broadcast via 3PBP) a Transaction where Alice attempts to redeem before the expiry', async function () {
|
||||
it('can create (but fail to broadcast via 3PBP) a Transaction where Alice attempts to redeem before the expiry', async () => {
|
||||
// two hours after confirmation
|
||||
const sequence = bip68.encode({ seconds: 7168 })
|
||||
const p2sh = bitcoin.payments.p2sh({
|
||||
|
@ -119,7 +119,7 @@ describe('bitcoinjs-lib (transactions w/ CSV)', function () {
|
|||
tx.setInputScript(0, redeemScriptSig)
|
||||
|
||||
await regtestUtils.broadcast(tx.toHex()).catch(err => {
|
||||
assert.throws(function () {
|
||||
assert.throws(() => {
|
||||
if (err) throw err
|
||||
}, /Error: non-BIP68-final \(code 64\)/)
|
||||
})
|
||||
|
|
|
@ -16,7 +16,7 @@ async function buildAndSign (depends, prevOutput, redeemScript, witnessScript) {
|
|||
txb.addOutput(regtestUtils.RANDOM_ADDRESS, 2e4)
|
||||
|
||||
if (depends.signatures) {
|
||||
keyPairs.forEach((keyPair) => {
|
||||
keyPairs.forEach(keyPair => {
|
||||
txb.sign(0, keyPair, redeemScript, null, unspent.value, witnessScript)
|
||||
})
|
||||
} else if (depends.signature) {
|
||||
|
@ -26,7 +26,7 @@ async function buildAndSign (depends, prevOutput, redeemScript, witnessScript) {
|
|||
return regtestUtils.broadcast(txb.build().toHex())
|
||||
}
|
||||
|
||||
;['p2ms', 'p2pk', 'p2pkh', 'p2wpkh'].forEach((k) => {
|
||||
;['p2ms', 'p2pk', 'p2pkh', 'p2wpkh'].forEach(k => {
|
||||
const fixtures = require('../fixtures/' + k)
|
||||
const { depends } = fixtures.dynamic
|
||||
const fn = bitcoin.payments[k]
|
||||
|
@ -39,7 +39,7 @@ async function buildAndSign (depends, prevOutput, redeemScript, witnessScript) {
|
|||
const { output } = fn(base)
|
||||
if (!output) throw new TypeError('Missing output')
|
||||
|
||||
describe('bitcoinjs-lib (payments - ' + k + ')', function () {
|
||||
describe('bitcoinjs-lib (payments - ' + k + ')', () => {
|
||||
it('can broadcast as an output, and be spent as an input', async () => {
|
||||
await buildAndSign(depends, output, null, null)
|
||||
})
|
||||
|
|
|
@ -8,8 +8,8 @@ function rng () {
|
|||
return Buffer.from('YT8dAtK4d16A3P1z+TpwB2jJ4aFH3g9M1EioIBkLEV4=', 'base64')
|
||||
}
|
||||
|
||||
describe('bitcoinjs-lib (transactions)', function () {
|
||||
it('can create a 1-to-1 Transaction', function () {
|
||||
describe('bitcoinjs-lib (transactions)', () => {
|
||||
it('can create a 1-to-1 Transaction', () => {
|
||||
const alice = bitcoin.ECPair.fromWIF('L1uyy5qTuGrVXrmrsvHWHgVzW9kKdrp27wBC7Vs6nZDTF2BRUVwy')
|
||||
const txb = new bitcoin.TransactionBuilder()
|
||||
|
||||
|
@ -24,7 +24,7 @@ describe('bitcoinjs-lib (transactions)', function () {
|
|||
assert.strictEqual(txb.build().toHex(), '01000000019d344070eac3fe6e394a16d06d7704a7d5c0a10eb2a2c16bc98842b7cc20d561000000006b48304502210088828c0bdfcdca68d8ae0caeb6ec62cd3fd5f9b2191848edae33feb533df35d302202e0beadd35e17e7f83a733f5277028a9b453d525553e3f5d2d7a7aa8010a81d60121029f50f51d63b345039a290c94bffd3180c99ed659ff6ea6b1242bca47eb93b59fffffffff01e02e0000000000001976a91406afd46bcdfd22ef94ac122aa11f241244a37ecc88ac00000000')
|
||||
})
|
||||
|
||||
it('can create a 2-to-2 Transaction', function () {
|
||||
it('can create a 2-to-2 Transaction', () => {
|
||||
const alice = bitcoin.ECPair.fromWIF('L1Knwj9W3qK3qMKdTvmg3VfzUs3ij2LETTFhxza9LfD5dngnoLG1')
|
||||
const bob = bitcoin.ECPair.fromWIF('KwcN2pT3wnRAurhy7qMczzbkpY5nXMW2ubh696UBc1bcwctTx26z')
|
||||
|
||||
|
@ -232,17 +232,17 @@ describe('bitcoinjs-lib (transactions)', function () {
|
|||
})
|
||||
})
|
||||
|
||||
it('can verify Transaction (P2PKH) signatures', function () {
|
||||
it('can verify Transaction (P2PKH) signatures', () => {
|
||||
const txHex = '010000000321c5f7e7bc98b3feda84aad36a5c99a02bcb8823a2f3eccbcd5da209698b5c20000000006b48304502210099e021772830207cf7c55b69948d3b16b4dcbf1f55a9cd80ebf8221a169735f9022064d33f11d62cd28240b3862afc0b901adc9f231c7124dd19bdb30367b61964c50121032b4c06c06c3ec0b7fa29519dfa5aae193ee2cc35ca127f29f14ec605d62fb63dffffffff8a75ce85441ddb3f342708ee33cc8ed418b07d9ba9e0e7c4e1cccfe9f52d8a88000000006946304302207916c23dae212c95a920423902fa44e939fb3d542f4478a7b46e9cde53705800021f0d74e9504146e404c1b8f9cba4dff2d4782e3075491c9ed07ce4a7d1c4461a01210216c92abe433106491bdeb4a261226f20f5a4ac86220cc6e37655aac6bf3c1f2affffffffdfef93f69fe32e944fad79fa8f882b3a155d80383252348caba1a77a5abbf7ef000000006b483045022100faa6e9ca289b46c64764a624c59ac30d9abcf1d4a04c4de9089e67cbe0d300a502206930afa683f6807502de5c2431bf9a1fd333c8a2910a76304df0f3d23d83443f0121039e05da8b8ea4f9868ecebb25998c7701542986233f4401799551fbecf316b18fffffffff01ff4b0000000000001976a9146c86476d1d85cd60116cd122a274e6a570a5a35c88acc96d0700'
|
||||
const keyPairs = [
|
||||
'032b4c06c06c3ec0b7fa29519dfa5aae193ee2cc35ca127f29f14ec605d62fb63d',
|
||||
'0216c92abe433106491bdeb4a261226f20f5a4ac86220cc6e37655aac6bf3c1f2a',
|
||||
'039e05da8b8ea4f9868ecebb25998c7701542986233f4401799551fbecf316b18f'
|
||||
].map(function (q) { return bitcoin.ECPair.fromPublicKey(Buffer.from(q, 'hex')) })
|
||||
].map(q => { return bitcoin.ECPair.fromPublicKey(Buffer.from(q, 'hex')) })
|
||||
|
||||
const tx = bitcoin.Transaction.fromHex(txHex)
|
||||
|
||||
tx.ins.forEach(function (input, i) {
|
||||
tx.ins.forEach((input, i) => {
|
||||
const keyPair = keyPairs[i]
|
||||
const p2pkh = bitcoin.payments.p2pkh({
|
||||
pubkey: keyPair.publicKey,
|
||||
|
@ -256,7 +256,7 @@ describe('bitcoinjs-lib (transactions)', function () {
|
|||
})
|
||||
})
|
||||
|
||||
it('can verify Transaction (P2SH(P2WPKH)) signatures', function () {
|
||||
it('can verify Transaction (P2SH(P2WPKH)) signatures', () => {
|
||||
const utxos = {
|
||||
'f72d1d83ac40fcedd01415751556a905844ab5f44bbb7728565ebb91b1590109:0': {
|
||||
value: 50000
|
||||
|
@ -266,7 +266,7 @@ describe('bitcoinjs-lib (transactions)', function () {
|
|||
const txHex = '02000000000101090159b191bb5e562877bb4bf4b54a8405a95615751514d0edfc40ac831d2df7000000001716001435a179e5516947a39ae9c8a25e9fe62c0fc598edffffffff01204e0000000000001976a91431d43308d3c886d53e9ae8a45728370571ff456988ac0247304402206ec41f685b997a51f325b07ee852e82a535f6b52ef54485cc133e05168aa052a022070bafa86108acb51c77b2b259ae8fb7fd1efa10fef804fcfe9b13c2db719acf5012103fb03e9d0a9af86cbed94225dbb8bb70f6b82109bce0a61ddcf41dab6cbb4871100000000'
|
||||
const tx = bitcoin.Transaction.fromHex(txHex)
|
||||
|
||||
tx.ins.forEach(function (input, i) {
|
||||
tx.ins.forEach((input, i) => {
|
||||
const txId = Buffer.from(input.hash).reverse().toString('hex')
|
||||
const utxo = utxos[`${txId}:${i}`]
|
||||
if (!utxo) throw new Error('Missing utxo')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue