From 9a921ad1818af4431ee5898f7eaeef72d85804a4 Mon Sep 17 00:00:00 2001 From: Wei Lu Date: Sat, 30 May 2015 21:19:57 +0800 Subject: [PATCH] poll address summary until balance non-zero or timeout --- test/integration/multisig.js | 3 ++- test/integration/utils.js | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/test/integration/multisig.js b/test/integration/multisig.js index 5a9d88a..15d5a73 100644 --- a/test/integration/multisig.js +++ b/test/integration/multisig.js @@ -5,6 +5,7 @@ var bitcoin = require('../../') var blockchain = new (require('cb-insight'))('https://test-insight.bitpay.com') var faucetWithdraw = require('./utils').faucetWithdraw var pollUnspent = require('./utils').pollUnspent +var pollSummary = require('./utils').pollSummary describe('bitcoinjs-lib (multisig)', function () { it('can create a 2-of-3 multisig P2SH address', function () { @@ -72,7 +73,7 @@ describe('bitcoinjs-lib (multisig)', function () { if (err) return done(err) // check that the funds (1e4 Satoshis) indeed arrived at the intended address - blockchain.addresses.summary(targetAddress, function (err, result) { + pollSummary(blockchain, targetAddress, function (err, result) { if (err) return done(err) assert.strictEqual(result.balance, 1e4) diff --git a/test/integration/utils.js b/test/integration/utils.js index b31f3ed..91aafaf 100644 --- a/test/integration/utils.js +++ b/test/integration/utils.js @@ -19,10 +19,24 @@ function pollUnspent(blockchain, address, done) { done(null, unspents) }) +} +function pollSummary(blockchain, address, done) { + blockchain.addresses.summary(address, function (err, result) { + if (err) return done(err) + + if(result.balance == 0) { + return setTimeout(function() { + pollSummary(blockchain, address, done) + }, 200) + } + + done(null, result) + }) } module.exports = { faucetWithdraw: faucetWithdraw, - pollUnspent: pollUnspent + pollUnspent: pollUnspent, + pollSummary: pollSummary }