From b267a9e6063478f7736536e9acbd0c9ac808b3c9 Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Tue, 22 May 2018 14:05:23 +1000 Subject: [PATCH] rm potential race conditions in non-final mixed test --- test/integration/cltv.js | 49 ++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/test/integration/cltv.js b/test/integration/cltv.js index 82c629e..547ac79 100644 --- a/test/integration/cltv.js +++ b/test/integration/cltv.js @@ -105,28 +105,29 @@ describe('bitcoinjs-lib (transactions w/ CLTV)', function () { ], redeemScript) tx.setInputScript(0, redeemScriptSig) - regtestUtils.broadcast(tx.toHex(), function (err) { - // fails before the expiry - assert.throws(function () { - if (err) throw err - }, /Error: 64: non-final/) - - // into the future! - regtestUtils.mine(51, function (err) { + // TODO: test that it failures _prior_ to expiry, unfortunately, race conditions when run concurrently +// regtestUtils.broadcast(tx.toHex(), function (err) { +// // fails before the expiry +// assert.throws(function () { +// if (err) throw err +// }, /Error: 64: non-final/) + + // into the future! + regtestUtils.mine(51, function (err) { + if (err) return done(err) + + regtestUtils.broadcast(tx.toHex(), function (err) { if (err) return done(err) - regtestUtils.broadcast(tx.toHex(), function (err) { - if (err) return done(err) - - regtestUtils.verify({ - txId: tx.getId(), - address: regtestUtils.RANDOM_ADDRESS, - vout: 0, - value: 7e4 - }, done) - }) + regtestUtils.verify({ + txId: tx.getId(), + address: regtestUtils.RANDOM_ADDRESS, + vout: 0, + value: 7e4 + }, done) }) }) +// }) }) }) }) @@ -136,8 +137,8 @@ describe('bitcoinjs-lib (transactions w/ CLTV)', function () { this.timeout(30000) // two hours ago - var timeUtc = utcNow() - (3600 * 2) - var redeemScript = cltvCheckSigOutput(alice, bob, timeUtc) + var lockTime = bip65.encode({ utc: utcNow() - (3600 * 2) }) + var redeemScript = cltvCheckSigOutput(alice, bob, lockTime) var scriptPubKey = bitcoin.script.scriptHash.output.encode(bitcoin.crypto.hash160(redeemScript)) var address = bitcoin.address.fromOutputScript(scriptPubKey, regtest) @@ -146,7 +147,7 @@ describe('bitcoinjs-lib (transactions w/ CLTV)', function () { if (err) return done(err) var txb = new bitcoin.TransactionBuilder(regtest) - txb.setLockTime(timeUtc) + txb.setLockTime(lockTime) txb.addInput(unspent.txId, unspent.vout, 0xfffffffe) txb.addOutput(regtestUtils.RANDOM_ADDRESS, 8e4) @@ -178,8 +179,8 @@ describe('bitcoinjs-lib (transactions w/ CLTV)', function () { this.timeout(30000) // two hours from now - var timeUtc = utcNow() + (3600 * 2) - var redeemScript = cltvCheckSigOutput(alice, bob, timeUtc) + var lockTime = bip65.encode({ utc: utcNow() + (3600 * 2) }) + var redeemScript = cltvCheckSigOutput(alice, bob, lockTime) var scriptPubKey = bitcoin.script.scriptHash.output.encode(bitcoin.crypto.hash160(redeemScript)) var address = bitcoin.address.fromOutputScript(scriptPubKey, regtest) @@ -188,7 +189,7 @@ describe('bitcoinjs-lib (transactions w/ CLTV)', function () { if (err) return done(err) var txb = new bitcoin.TransactionBuilder(regtest) - txb.setLockTime(timeUtc) + txb.setLockTime(lockTime) txb.addInput(unspent.txId, unspent.vout, 0xfffffffe) txb.addOutput(regtestUtils.RANDOM_ADDRESS, 1e4)