Browse Source

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

hk-custom-address
Daniel Cousens 9 years ago
parent
commit
755c344e16
  1. 51
      test/integration/_blockchain.js
  2. 9
      test/integration/advanced.js
  3. 5
      test/integration/multisig.js

51
test/integration/_blockchain.js

@ -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 }) 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) { testnet.faucet = function faucet (address, amount, done) {
var unspents = [] async.retry(5, function (callback) {
httpify({
async.whilst( method: 'POST',
function condition () { return unspents.length === 0 }, url: 'https://api.blocktrail.com/v1/tBTC/faucet/withdrawl?api_key=' + BLOCKTRAIL_API_KEY,
function f (callback) { headers: { 'Content-Type': 'application/json' },
httpify({ body: JSON.stringify({
method: 'POST', address: address,
url: 'https://api.blocktrail.com/v1/tBTC/faucet/withdrawl?api_key=' + BLOCKTRAIL_API_KEY, amount: amount
headers: { 'Content-Type': 'application/json' }, })
body: JSON.stringify({ }, function (err) {
address: address, if (err) return callback(err)
amount: amount
}) testnet.addresses.unspents(address, function (err, result) {
}, function (err) {
if (err) return callback(err) 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) if (err) return callback(err)
// filter small unspents testnet.transactions.propagate(tx.txHex, function (err) {
unspents = result.filter(function (unspent) { if (err) return callback(err)
return unspent.value > 1e3
})
callback() callback(null, unspent)
})
}) })
}) })
}, })
function (err) { }, done)
if (err) return done(err)
done(null, unspents)
}
)
} }
module.exports = { module.exports = {

9
test/integration/advanced.js

@ -28,11 +28,9 @@ describe('bitcoinjs-lib (advanced)', function () {
var keyPair = bitcoin.ECPair.makeRandom({ network: network }) var keyPair = bitcoin.ECPair.makeRandom({ network: network })
var address = keyPair.getAddress() var address = keyPair.getAddress()
blockchain.t.faucet(address, 2e4, function (err, unspents) { blockchain.t.faucet(address, 2e4, function (err, unspent) {
if (err) return done(err) if (err) return done(err)
// use the oldest unspent
var unspent = unspents.pop()
var tx = new bitcoin.TransactionBuilder(network) var tx = new bitcoin.TransactionBuilder(network)
var data = new Buffer('bitcoinjs-lib') var data = new Buffer('bitcoinjs-lib')
var dataScript = bitcoin.script.nullDataOutput(data) var dataScript = bitcoin.script.nullDataOutput(data)
@ -76,12 +74,9 @@ describe('bitcoinjs-lib (advanced)', function () {
beforeEach(function (done) { beforeEach(function (done) {
this.timeout(10000) this.timeout(10000)
blockchain.t.faucet(alice.getAddress(), 2e4, function (err, unspents) { blockchain.t.faucet(alice.getAddress(), 2e4, function (err, unspent) {
if (err) return done(err) if (err) return done(err)
// use the oldest unspent
var unspent = unspents.pop()
// build the transaction // build the transaction
var tx = new bitcoin.TransactionBuilder(network) var tx = new bitcoin.TransactionBuilder(network)
tx.addInput(unspent.txId, unspent.vout) tx.addInput(unspent.txId, unspent.vout)

5
test/integration/multisig.js

@ -37,12 +37,9 @@ describe('bitcoinjs-lib (multisig)', function () {
var address = bitcoin.address.fromOutputScript(scriptPubKey, bitcoin.networks.testnet) var address = bitcoin.address.fromOutputScript(scriptPubKey, bitcoin.networks.testnet)
// attempt to send funds to the source address // attempt to send funds to the source address
blockchain.t.faucet(address, 2e4, function (err, unspents) { blockchain.t.faucet(address, 2e4, function (err, unspent) {
if (err) return done(err) if (err) return done(err)
// use the oldest unspent
var unspent = unspents.pop()
// make a random destination address // make a random destination address
var targetAddress = bitcoin.ECPair.makeRandom({ var targetAddress = bitcoin.ECPair.makeRandom({
network: bitcoin.networks.testnet network: bitcoin.networks.testnet

Loading…
Cancel
Save