tests/integration: re-broadcast input tx to avoid missing inputs error

This commit is contained in:
Daniel Cousens 2016-01-06 12:46:02 +11:00
parent 382409c575
commit 755c344e16
3 changed files with 26 additions and 37 deletions
test/integration

View file

@ -8,40 +8,37 @@ var mainnet = new Blockchain('https://api.blocktrail.com/cb/v0.2.1/BTC', { api_k
var testnet = new Blockchain('https://api.blocktrail.com/cb/v0.2.1/tBTC', { api_key: BLOCKTRAIL_API_KEY })
testnet.faucet = function faucet (address, amount, done) {
var unspents = []
async.retry(5, function (callback) {
httpify({
method: 'POST',
url: 'https://api.blocktrail.com/v1/tBTC/faucet/withdrawl?api_key=' + BLOCKTRAIL_API_KEY,
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
address: address,
amount: amount
})
}, function (err) {
if (err) return callback(err)
async.whilst(
function condition () { return unspents.length === 0 },
function f (callback) {
httpify({
method: 'POST',
url: 'https://api.blocktrail.com/v1/tBTC/faucet/withdrawl?api_key=' + BLOCKTRAIL_API_KEY,
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
address: address,
amount: amount
})
}, function (err) {
testnet.addresses.unspents(address, function (err, result) {
if (err) return callback(err)
testnet.addresses.unspents(address, function (err, result) {
var unspent = result.filter(function (unspent) {
return unspent.value > 1e3
}).pop()
testnet.transactions.get(unspent.txId, function (err, tx) {
if (err) return callback(err)
// filter small unspents
unspents = result.filter(function (unspent) {
return unspent.value > 1e3
})
testnet.transactions.propagate(tx.txHex, function (err) {
if (err) return callback(err)
callback()
callback(null, unspent)
})
})
})
},
function (err) {
if (err) return done(err)
done(null, unspents)
}
)
})
}, done)
}
module.exports = {