|
|
@ -1,5 +1,6 @@ |
|
|
|
/* global describe, it */ |
|
|
|
|
|
|
|
var async = require('async') |
|
|
|
var assert = require('assert') |
|
|
|
var bitcoin = require('../../') |
|
|
|
var blockchain = require('./_blockchain') |
|
|
@ -40,6 +41,9 @@ describe('bitcoinjs-lib (multisig)', function () { |
|
|
|
blockchain.t.faucet(address, 2e4, function (err, unspent) { |
|
|
|
if (err) return done(err) |
|
|
|
|
|
|
|
var fee = 1e4 |
|
|
|
var targetValue = unspent.value - fee |
|
|
|
|
|
|
|
// make a random destination address
|
|
|
|
var targetAddress = bitcoin.ECPair.makeRandom({ |
|
|
|
network: bitcoin.networks.testnet |
|
|
@ -47,7 +51,7 @@ describe('bitcoinjs-lib (multisig)', function () { |
|
|
|
|
|
|
|
var txb = new bitcoin.TransactionBuilder(bitcoin.networks.testnet) |
|
|
|
txb.addInput(unspent.txId, unspent.vout) |
|
|
|
txb.addOutput(targetAddress, 1e4) |
|
|
|
txb.addOutput(targetAddress, targetValue) |
|
|
|
|
|
|
|
// sign with 1st and 3rd key
|
|
|
|
txb.sign(0, keyPairs[0], redeemScript) |
|
|
@ -60,16 +64,22 @@ describe('bitcoinjs-lib (multisig)', function () { |
|
|
|
blockchain.t.transactions.propagate(tx.toHex(), function (err) { |
|
|
|
if (err) return done(err) |
|
|
|
|
|
|
|
// check that the above transaction included the intended address
|
|
|
|
blockchain.t.addresses.unspents(targetAddress, function (err, unspents) { |
|
|
|
if (err) return done(err) |
|
|
|
|
|
|
|
assert(unspents.some(function (unspent) { |
|
|
|
return unspent.txId === txId && unspent.value === 1e4 |
|
|
|
})) |
|
|
|
|
|
|
|
done() |
|
|
|
}) |
|
|
|
// allow for TX to be processed
|
|
|
|
async.retry(5, function (callback) { |
|
|
|
setTimeout(function () { |
|
|
|
// check that the above transaction included the intended address
|
|
|
|
blockchain.t.addresses.unspents(targetAddress, function (err, unspents) { |
|
|
|
if (err) return callback(err) |
|
|
|
|
|
|
|
var unspentFound = unspents.some(function (unspent) { |
|
|
|
return unspent.txId === txId && unspent.value === targetValue |
|
|
|
}) |
|
|
|
|
|
|
|
if (!unspentFound) return callback(new Error('Could not find unspent after propagate')) |
|
|
|
callback() |
|
|
|
}) |
|
|
|
}, 600) |
|
|
|
}, done) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|