tests/integration: change tests to not use templates
This commit is contained in:
parent
a9090dc0cc
commit
4901d41fa9
4 changed files with 51 additions and 42 deletions
test/integration
|
@ -76,12 +76,10 @@ describe('bitcoinjs-lib (BIP32)', function () {
|
||||||
const path = "m/49'/1'/0'/0/0"
|
const path = "m/49'/1'/0'/0/0"
|
||||||
const child = root.derivePath(path)
|
const child = root.derivePath(path)
|
||||||
|
|
||||||
const keyhash = bitcoin.crypto.hash160(child.publicKey)
|
const { address } = bitcoin.payments.p2sh({
|
||||||
const scriptSig = bitcoin.script.witnessPubKeyHash.output.encode(keyhash)
|
redeem: bitcoin.payments.p2wpkh({ pubkey: child.publicKey, network: bitcoin.networks.testnet }),
|
||||||
const addressBytes = bitcoin.crypto.hash160(scriptSig)
|
network: bitcoin.networks.testnet
|
||||||
const outputScript = bitcoin.script.scriptHash.output.encode(addressBytes)
|
})
|
||||||
const address = bitcoin.address.fromOutputScript(outputScript, bitcoin.networks.testnet)
|
|
||||||
|
|
||||||
assert.equal(address, '2Mww8dCYPUpKHofjgcXcBCEGmniw9CoaiD2')
|
assert.equal(address, '2Mww8dCYPUpKHofjgcXcBCEGmniw9CoaiD2')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -46,8 +46,7 @@ describe('bitcoinjs-lib (transactions w/ CLTV)', function () {
|
||||||
// 3 hours ago
|
// 3 hours ago
|
||||||
const lockTime = bip65.encode({ utc: utcNow() - (3600 * 3) })
|
const lockTime = bip65.encode({ utc: utcNow() - (3600 * 3) })
|
||||||
const redeemScript = cltvCheckSigOutput(alice, bob, lockTime)
|
const redeemScript = cltvCheckSigOutput(alice, bob, lockTime)
|
||||||
const scriptPubKey = bitcoin.script.scriptHash.output.encode(bitcoin.crypto.hash160(redeemScript))
|
const { address } = bitcoin.payments.p2sh({ redeem: { output: redeemScript, network: regtest }, network: regtest })
|
||||||
const address = bitcoin.address.fromOutputScript(scriptPubKey, regtest)
|
|
||||||
|
|
||||||
// fund the P2SH(CLTV) address
|
// fund the P2SH(CLTV) address
|
||||||
regtestUtils.faucet(address, 1e5, function (err, unspent) {
|
regtestUtils.faucet(address, 1e5, function (err, unspent) {
|
||||||
|
@ -61,10 +60,15 @@ describe('bitcoinjs-lib (transactions w/ CLTV)', function () {
|
||||||
// {Alice's signature} OP_TRUE
|
// {Alice's signature} OP_TRUE
|
||||||
const tx = txb.buildIncomplete()
|
const tx = txb.buildIncomplete()
|
||||||
const signatureHash = tx.hashForSignature(0, redeemScript, hashType)
|
const signatureHash = tx.hashForSignature(0, redeemScript, hashType)
|
||||||
const redeemScriptSig = bitcoin.script.scriptHash.input.encode([
|
const redeemScriptSig = bitcoin.payments.p2sh({
|
||||||
bitcoin.script.signature.encode(alice.sign(signatureHash), hashType),
|
redeem: {
|
||||||
bitcoin.opcodes.OP_TRUE
|
input: bitcoin.script.compile([
|
||||||
], redeemScript)
|
bitcoin.script.signature.encode(alice.sign(signatureHash), hashType),
|
||||||
|
bitcoin.opcodes.OP_TRUE
|
||||||
|
]),
|
||||||
|
output: redeemScript
|
||||||
|
}
|
||||||
|
}).input
|
||||||
tx.setInputScript(0, redeemScriptSig)
|
tx.setInputScript(0, redeemScriptSig)
|
||||||
|
|
||||||
regtestUtils.broadcast(tx.toHex(), function (err) {
|
regtestUtils.broadcast(tx.toHex(), function (err) {
|
||||||
|
@ -90,8 +94,7 @@ describe('bitcoinjs-lib (transactions w/ CLTV)', function () {
|
||||||
// 5 blocks from now
|
// 5 blocks from now
|
||||||
const lockTime = bip65.encode({ blocks: height + 5 })
|
const lockTime = bip65.encode({ blocks: height + 5 })
|
||||||
const redeemScript = cltvCheckSigOutput(alice, bob, lockTime)
|
const redeemScript = cltvCheckSigOutput(alice, bob, lockTime)
|
||||||
const scriptPubKey = bitcoin.script.scriptHash.output.encode(bitcoin.crypto.hash160(redeemScript))
|
const { address } = bitcoin.payments.p2sh({ redeem: { output: redeemScript, network: regtest }, network: regtest })
|
||||||
const address = bitcoin.address.fromOutputScript(scriptPubKey, regtest)
|
|
||||||
|
|
||||||
// fund the P2SH(CLTV) address
|
// fund the P2SH(CLTV) address
|
||||||
regtestUtils.faucet(address, 1e5, function (err, unspent) {
|
regtestUtils.faucet(address, 1e5, function (err, unspent) {
|
||||||
|
@ -105,10 +108,15 @@ describe('bitcoinjs-lib (transactions w/ CLTV)', function () {
|
||||||
// {Alice's signature} OP_TRUE
|
// {Alice's signature} OP_TRUE
|
||||||
const tx = txb.buildIncomplete()
|
const tx = txb.buildIncomplete()
|
||||||
const signatureHash = tx.hashForSignature(0, redeemScript, hashType)
|
const signatureHash = tx.hashForSignature(0, redeemScript, hashType)
|
||||||
const redeemScriptSig = bitcoin.script.scriptHash.input.encode([
|
const redeemScriptSig = bitcoin.payments.p2sh({
|
||||||
bitcoin.script.signature.encode(alice.sign(signatureHash), hashType),
|
redeem: {
|
||||||
bitcoin.opcodes.OP_TRUE
|
input: bitcoin.script.compile([
|
||||||
], redeemScript)
|
bitcoin.script.signature.encode(alice.sign(signatureHash), hashType),
|
||||||
|
bitcoin.opcodes.OP_TRUE
|
||||||
|
]),
|
||||||
|
output: redeemScript
|
||||||
|
}
|
||||||
|
}).input
|
||||||
tx.setInputScript(0, redeemScriptSig)
|
tx.setInputScript(0, redeemScriptSig)
|
||||||
|
|
||||||
// TODO: test that it failures _prior_ to expiry, unfortunately, race conditions when run concurrently
|
// TODO: test that it failures _prior_ to expiry, unfortunately, race conditions when run concurrently
|
||||||
|
@ -139,8 +147,7 @@ describe('bitcoinjs-lib (transactions w/ CLTV)', function () {
|
||||||
// two hours ago
|
// two hours ago
|
||||||
const lockTime = bip65.encode({ utc: utcNow() - (3600 * 2) })
|
const lockTime = bip65.encode({ utc: utcNow() - (3600 * 2) })
|
||||||
const redeemScript = cltvCheckSigOutput(alice, bob, lockTime)
|
const redeemScript = cltvCheckSigOutput(alice, bob, lockTime)
|
||||||
const scriptPubKey = bitcoin.script.scriptHash.output.encode(bitcoin.crypto.hash160(redeemScript))
|
const { address } = bitcoin.payments.p2sh({ redeem: { output: redeemScript, network: regtest }, network: regtest })
|
||||||
const address = bitcoin.address.fromOutputScript(scriptPubKey, regtest)
|
|
||||||
|
|
||||||
// fund the P2SH(CLTV) address
|
// fund the P2SH(CLTV) address
|
||||||
regtestUtils.faucet(address, 2e5, function (err, unspent) {
|
regtestUtils.faucet(address, 2e5, function (err, unspent) {
|
||||||
|
@ -154,11 +161,16 @@ describe('bitcoinjs-lib (transactions w/ CLTV)', function () {
|
||||||
// {Alice's signature} {Bob's signature} OP_FALSE
|
// {Alice's signature} {Bob's signature} OP_FALSE
|
||||||
const tx = txb.buildIncomplete()
|
const tx = txb.buildIncomplete()
|
||||||
const signatureHash = tx.hashForSignature(0, redeemScript, hashType)
|
const signatureHash = tx.hashForSignature(0, redeemScript, hashType)
|
||||||
const redeemScriptSig = bitcoin.script.scriptHash.input.encode([
|
const redeemScriptSig = bitcoin.payments.p2sh({
|
||||||
bitcoin.script.signature.encode(alice.sign(signatureHash), hashType),
|
redeem: {
|
||||||
bitcoin.script.signature.encode(bob.sign(signatureHash), hashType),
|
input: bitcoin.script.compile([
|
||||||
bitcoin.opcodes.OP_FALSE
|
bitcoin.script.signature.encode(alice.sign(signatureHash), hashType),
|
||||||
], redeemScript)
|
bitcoin.script.signature.encode(bob.sign(signatureHash), hashType),
|
||||||
|
bitcoin.opcodes.OP_FALSE
|
||||||
|
]),
|
||||||
|
output: redeemScript
|
||||||
|
}
|
||||||
|
}).input
|
||||||
tx.setInputScript(0, redeemScriptSig)
|
tx.setInputScript(0, redeemScriptSig)
|
||||||
|
|
||||||
regtestUtils.broadcast(tx.toHex(), function (err) {
|
regtestUtils.broadcast(tx.toHex(), function (err) {
|
||||||
|
@ -181,8 +193,7 @@ describe('bitcoinjs-lib (transactions w/ CLTV)', function () {
|
||||||
// two hours from now
|
// two hours from now
|
||||||
const lockTime = bip65.encode({ utc: utcNow() + (3600 * 2) })
|
const lockTime = bip65.encode({ utc: utcNow() + (3600 * 2) })
|
||||||
const redeemScript = cltvCheckSigOutput(alice, bob, lockTime)
|
const redeemScript = cltvCheckSigOutput(alice, bob, lockTime)
|
||||||
const scriptPubKey = bitcoin.script.scriptHash.output.encode(bitcoin.crypto.hash160(redeemScript))
|
const { address } = bitcoin.payments.p2sh({ redeem: { output: redeemScript, network: regtest }, network: regtest })
|
||||||
const address = bitcoin.address.fromOutputScript(scriptPubKey, regtest)
|
|
||||||
|
|
||||||
// fund the P2SH(CLTV) address
|
// fund the P2SH(CLTV) address
|
||||||
regtestUtils.faucet(address, 2e4, function (err, unspent) {
|
regtestUtils.faucet(address, 2e4, function (err, unspent) {
|
||||||
|
@ -196,11 +207,16 @@ describe('bitcoinjs-lib (transactions w/ CLTV)', function () {
|
||||||
// {Alice's signature} OP_TRUE
|
// {Alice's signature} OP_TRUE
|
||||||
const tx = txb.buildIncomplete()
|
const tx = txb.buildIncomplete()
|
||||||
const signatureHash = tx.hashForSignature(0, redeemScript, hashType)
|
const signatureHash = tx.hashForSignature(0, redeemScript, hashType)
|
||||||
const redeemScriptSig = bitcoin.script.scriptHash.input.encode([
|
const redeemScriptSig = bitcoin.payments.p2sh({
|
||||||
bitcoin.script.signature.encode(alice.sign(signatureHash), hashType),
|
redeem: {
|
||||||
bitcoin.script.signature.encode(bob.sign(signatureHash), hashType),
|
input: bitcoin.script.compile([
|
||||||
bitcoin.opcodes.OP_TRUE
|
bitcoin.script.signature.encode(alice.sign(signatureHash), hashType),
|
||||||
], redeemScript)
|
bitcoin.script.signature.encode(bob.sign(signatureHash), hashType),
|
||||||
|
bitcoin.opcodes.OP_TRUE
|
||||||
|
]),
|
||||||
|
output: redeemScript
|
||||||
|
}
|
||||||
|
}).input
|
||||||
tx.setInputScript(0, redeemScriptSig)
|
tx.setInputScript(0, redeemScriptSig)
|
||||||
|
|
||||||
regtestUtils.broadcast(tx.toHex(), function (err) {
|
regtestUtils.broadcast(tx.toHex(), function (err) {
|
||||||
|
|
|
@ -18,16 +18,11 @@ describe('bitcoinjs-lib (crypto)', function () {
|
||||||
const tx = bitcoin.Transaction.fromHex('01000000020b668015b32a6178d8524cfef6dc6fc0a4751915c2e9b2ed2d2eab02424341c8000000006a47304402205e00298dc5265b7a914974c9d0298aa0e69a0ca932cb52a360436d6a622e5cd7022024bf5f506968f5f23f1835574d5afe0e9021b4a5b65cf9742332d5e4acb68f41012103fd089f73735129f3d798a657aaaa4aa62a00fa15c76b61fc7f1b27ed1d0f35b8ffffffffa95fa69f11dc1cbb77ef64f25a95d4b12ebda57d19d843333819d95c9172ff89000000006b48304502205e00298dc5265b7a914974c9d0298aa0e69a0ca932cb52a360436d6a622e5cd7022100832176b59e8f50c56631acbc824bcba936c9476c559c42a4468be98975d07562012103fd089f73735129f3d798a657aaaa4aa62a00fa15c76b61fc7f1b27ed1d0f35b8ffffffff02b000eb04000000001976a91472956eed9a8ecb19ae7e3ebd7b06cae4668696a788ac303db000000000001976a9146c0bd55dd2592287cd9992ce3ba3fc1208fb76da88ac00000000')
|
const tx = bitcoin.Transaction.fromHex('01000000020b668015b32a6178d8524cfef6dc6fc0a4751915c2e9b2ed2d2eab02424341c8000000006a47304402205e00298dc5265b7a914974c9d0298aa0e69a0ca932cb52a360436d6a622e5cd7022024bf5f506968f5f23f1835574d5afe0e9021b4a5b65cf9742332d5e4acb68f41012103fd089f73735129f3d798a657aaaa4aa62a00fa15c76b61fc7f1b27ed1d0f35b8ffffffffa95fa69f11dc1cbb77ef64f25a95d4b12ebda57d19d843333819d95c9172ff89000000006b48304502205e00298dc5265b7a914974c9d0298aa0e69a0ca932cb52a360436d6a622e5cd7022100832176b59e8f50c56631acbc824bcba936c9476c559c42a4468be98975d07562012103fd089f73735129f3d798a657aaaa4aa62a00fa15c76b61fc7f1b27ed1d0f35b8ffffffff02b000eb04000000001976a91472956eed9a8ecb19ae7e3ebd7b06cae4668696a788ac303db000000000001976a9146c0bd55dd2592287cd9992ce3ba3fc1208fb76da88ac00000000')
|
||||||
|
|
||||||
tx.ins.forEach(function (input, vin) {
|
tx.ins.forEach(function (input, vin) {
|
||||||
const script = input.script
|
const { output: prevOutput, pubkey, signature } = bitcoin.payments.p2pkh({ input: input.script })
|
||||||
const scriptChunks = bitcoin.script.decompile(script)
|
|
||||||
|
|
||||||
assert(bitcoin.script.pubKeyHash.input.check(scriptChunks), 'Expected pubKeyHash script')
|
const scriptSignature = bitcoin.script.signature.decode(signature)
|
||||||
const prevOutScript = bitcoin.address.toOutputScript('1ArJ9vRaQcoQ29mTWZH768AmRwzb6Zif1z')
|
const m = tx.hashForSignature(vin, prevOutput, scriptSignature.hashType)
|
||||||
const scriptSignature = bitcoin.script.signature.decode(scriptChunks[0])
|
assert(bitcoin.ECPair.fromPublicKey(pubkey).verify(m, scriptSignature.signature), 'Invalid m')
|
||||||
const publicKey = bitcoin.ECPair.fromPublicKey(scriptChunks[1])
|
|
||||||
|
|
||||||
const m = tx.hashForSignature(vin, prevOutScript, scriptSignature.hashType)
|
|
||||||
assert(publicKey.verify(m, scriptSignature.signature), 'Invalid m')
|
|
||||||
|
|
||||||
// store the required information
|
// store the required information
|
||||||
input.signature = scriptSignature.signature
|
input.signature = scriptSignature.signature
|
||||||
|
|
|
@ -91,7 +91,7 @@ describe('bitcoinjs-lib (transactions)', function () {
|
||||||
|
|
||||||
const txb = new bitcoin.TransactionBuilder(regtest)
|
const txb = new bitcoin.TransactionBuilder(regtest)
|
||||||
const data = Buffer.from('bitcoinjs-lib', 'utf8')
|
const data = Buffer.from('bitcoinjs-lib', 'utf8')
|
||||||
const dataScript = bitcoin.script.nullData.output.encode([data])
|
const dataScript = require('../../src/templates/nulldata').output.encode([data])
|
||||||
|
|
||||||
txb.addInput(unspent.txId, unspent.vout)
|
txb.addInput(unspent.txId, unspent.vout)
|
||||||
txb.addOutput(dataScript, 1000)
|
txb.addOutput(dataScript, 1000)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue