tests/integration: rm use of templates
This commit is contained in:
parent
0d0f1d0847
commit
4454e2925a
1 changed files with 40 additions and 19 deletions
|
@ -12,6 +12,7 @@ const bob = bitcoin.ECPair.fromWIF('cMkopUXKWsEzAjfa1zApksGRwjVpJRB3831qM9W4gKZs
|
||||||
describe('bitcoinjs-lib (transactions w/ CSV)', function () {
|
describe('bitcoinjs-lib (transactions w/ CSV)', function () {
|
||||||
// force update MTP
|
// force update MTP
|
||||||
before(function (done) {
|
before(function (done) {
|
||||||
|
this.timeout(30000)
|
||||||
regtestUtils.mine(11, done)
|
regtestUtils.mine(11, done)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -44,12 +45,15 @@ describe('bitcoinjs-lib (transactions w/ CSV)', function () {
|
||||||
|
|
||||||
// 5 blocks from now
|
// 5 blocks from now
|
||||||
const sequence = bip68.encode({ blocks: 5 })
|
const sequence = bip68.encode({ blocks: 5 })
|
||||||
const redeemScript = csvCheckSigOutput(alice, bob, sequence)
|
const p2sh = bitcoin.payments.p2sh({
|
||||||
const scriptPubKey = bitcoin.script.scriptHash.output.encode(bitcoin.crypto.hash160(redeemScript))
|
redeem: {
|
||||||
const address = bitcoin.address.fromOutputScript(scriptPubKey, regtest)
|
output: csvCheckSigOutput(alice, bob, sequence)
|
||||||
|
},
|
||||||
|
network: regtest
|
||||||
|
})
|
||||||
|
|
||||||
// fund the P2SH(CSV) address
|
// fund the P2SH(CSV) address
|
||||||
regtestUtils.faucet(address, 1e5, function (err, unspent) {
|
regtestUtils.faucet(p2sh.address, 1e5, function (err, unspent) {
|
||||||
if (err) return done(err)
|
if (err) return done(err)
|
||||||
|
|
||||||
const txb = new bitcoin.TransactionBuilder(regtest)
|
const txb = new bitcoin.TransactionBuilder(regtest)
|
||||||
|
@ -58,11 +62,18 @@ describe('bitcoinjs-lib (transactions w/ CSV)', 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, p2sh.redeem.output, hashType)
|
||||||
const redeemScriptSig = bitcoin.script.scriptHash.input.encode([
|
const redeemScriptSig = bitcoin.payments.p2sh({
|
||||||
bitcoin.script.signature.encode(alice.sign(signatureHash), hashType),
|
network: regtest,
|
||||||
bitcoin.opcodes.OP_TRUE
|
redeem: {
|
||||||
], redeemScript)
|
network: regtest,
|
||||||
|
output: p2sh.redeem.output,
|
||||||
|
input: bitcoin.script.compile([
|
||||||
|
bitcoin.script.signature.encode(alice.sign(signatureHash), hashType),
|
||||||
|
bitcoin.opcodes.OP_TRUE
|
||||||
|
])
|
||||||
|
}
|
||||||
|
}).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
|
||||||
|
@ -92,12 +103,15 @@ describe('bitcoinjs-lib (transactions w/ CSV)', function () {
|
||||||
|
|
||||||
// two hours after confirmation
|
// two hours after confirmation
|
||||||
const sequence = bip68.encode({ seconds: 7168 })
|
const sequence = bip68.encode({ seconds: 7168 })
|
||||||
const redeemScript = csvCheckSigOutput(alice, bob, sequence)
|
const p2sh = bitcoin.payments.p2sh({
|
||||||
const scriptPubKey = bitcoin.script.scriptHash.output.encode(bitcoin.crypto.hash160(redeemScript))
|
network: regtest,
|
||||||
const address = bitcoin.address.fromOutputScript(scriptPubKey, regtest)
|
redeem: {
|
||||||
|
output: csvCheckSigOutput(alice, bob, sequence)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
// fund the P2SH(CSV) address
|
// fund the P2SH(CSV) address
|
||||||
regtestUtils.faucet(address, 2e4, function (err, unspent) {
|
regtestUtils.faucet(p2sh.address, 2e4, function (err, unspent) {
|
||||||
if (err) return done(err)
|
if (err) return done(err)
|
||||||
|
|
||||||
const txb = new bitcoin.TransactionBuilder(regtest)
|
const txb = new bitcoin.TransactionBuilder(regtest)
|
||||||
|
@ -106,12 +120,19 @@ describe('bitcoinjs-lib (transactions w/ CSV)', 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, p2sh.redeem.output, hashType)
|
||||||
const redeemScriptSig = bitcoin.script.scriptHash.input.encode([
|
const redeemScriptSig = bitcoin.payments.p2sh({
|
||||||
bitcoin.script.signature.encode(alice.sign(signatureHash), hashType),
|
network: regtest,
|
||||||
bitcoin.script.signature.encode(bob.sign(signatureHash), hashType),
|
redeem: {
|
||||||
bitcoin.opcodes.OP_TRUE
|
network: regtest,
|
||||||
], redeemScript)
|
output: p2sh.redeem.output,
|
||||||
|
input: bitcoin.script.compile([
|
||||||
|
bitcoin.script.signature.encode(alice.sign(signatureHash), hashType),
|
||||||
|
bitcoin.script.signature.encode(bob.sign(signatureHash), hashType),
|
||||||
|
bitcoin.opcodes.OP_TRUE
|
||||||
|
])
|
||||||
|
}
|
||||||
|
}).input
|
||||||
tx.setInputScript(0, redeemScriptSig)
|
tx.setInputScript(0, redeemScriptSig)
|
||||||
|
|
||||||
regtestUtils.broadcast(tx.toHex(), function (err) {
|
regtestUtils.broadcast(tx.toHex(), function (err) {
|
||||||
|
|
Loading…
Reference in a new issue