fixed issues with integration tests that use the faucet
This commit is contained in:
parent
7937835415
commit
0e1424c2cb
2 changed files with 49 additions and 32 deletions
test/integration
|
@ -8,30 +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) {
|
||||
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)
|
||||
|
||||
testnet.addresses.unspents(address, function (err, result) {
|
||||
if (err) return callback(err)
|
||||
|
||||
var unspent = result.filter(function (unspent) {
|
||||
return unspent.value > 1e3
|
||||
}).pop()
|
||||
|
||||
if (!unspent) return callback(new Error('No unspent given'))
|
||||
callback(null, unspent)
|
||||
})
|
||||
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
|
||||
})
|
||||
}, done)
|
||||
}, function (err, result) {
|
||||
if (err) return done(err)
|
||||
|
||||
if (result.body.code === 401) {
|
||||
return done(new Error('Hit faucet rate limit; ' + result.body.msg))
|
||||
}
|
||||
|
||||
// allow for TX to be processed
|
||||
async.retry(5, function (callback) {
|
||||
setTimeout(function () {
|
||||
testnet.addresses.unspents(address, function (err, result) {
|
||||
if (err) return callback(err)
|
||||
|
||||
var unspent = result.filter(function (unspent) {
|
||||
return unspent.value >= amount
|
||||
}).pop()
|
||||
|
||||
if (!unspent) return callback(new Error('No unspent given'))
|
||||
callback(null, unspent)
|
||||
})
|
||||
}, 600)
|
||||
}, done)
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue