tests: resist txn-mempool-conflicts

This commit is contained in:
Daniel Cousens 2017-08-21 18:32:16 +10:00 committed by Daniel Cousens
parent 6d0a20cee1
commit 9bae30d112

View file

@ -11,11 +11,12 @@ var blockchain = new Blockchain('https://api.blocktrail.com/cb/v0.2.1/tBTC', { a
var kpNetwork = bitcoin.networks.testnet var kpNetwork = bitcoin.networks.testnet
var keyPair = bitcoin.ECPair.fromWIF('cQqjeq2rxqwnqwMewJhkNtJDixtX8ctA4bYoWHdxY4xRPVvAEjmk', kpNetwork) var keyPair = bitcoin.ECPair.fromWIF('cQqjeq2rxqwnqwMewJhkNtJDixtX8ctA4bYoWHdxY4xRPVvAEjmk', kpNetwork)
var kpAddress = keyPair.getAddress() var kpAddress = keyPair.getAddress()
var conflicts = {}
function fundAddress (unspents, outputs, callback) { function fundAddress (unspents, outputs, callback) {
// avoid too-long-mempool-chain // avoid too-long-mempool-chain
unspents = unspents.filter(function (x) { unspents = unspents.filter(function (x) {
return x.confirmations > 0 return x.confirmations > 0 && !conflicts[x.txId + x.vout]
}) })
var result = coinSelect(unspents, outputs, 10) var result = coinSelect(unspents, outputs, 10)
@ -23,6 +24,7 @@ function fundAddress (unspents, outputs, callback) {
var txb = new bitcoin.TransactionBuilder(kpNetwork) var txb = new bitcoin.TransactionBuilder(kpNetwork)
result.inputs.forEach(function (x) { result.inputs.forEach(function (x) {
conflicts[x.txId + x.vout] = true
txb.addInput(x.txId, x.vout) txb.addInput(x.txId, x.vout)
}) })
@ -68,7 +70,7 @@ blockchain.faucet = function faucet (address, value, callback) {
} }
// verify TX was accepted // verify TX was accepted
blockchain.verify = function (address, txId, value, done) { blockchain.verify = function verify (address, txId, value, done) {
async.retry(5, function (callback) { async.retry(5, function (callback) {
setTimeout(function () { setTimeout(function () {
// check that the above transaction included the intended address // check that the above transaction included the intended address
@ -85,7 +87,7 @@ blockchain.verify = function (address, txId, value, done) {
}, done) }, done)
} }
blockchain.transactions.propagate = function (txHex, callback) { blockchain.transactions.propagate = function broadcast (txHex, callback) {
dhttp({ dhttp({
method: 'POST', method: 'POST',
url: 'https://api.ei8ht.com.au:9443/3/pushtx', url: 'https://api.ei8ht.com.au:9443/3/pushtx',