Browse Source

poll address summary until balance non-zero or timeout

hk-custom-address
Wei Lu 10 years ago
parent
commit
9a921ad181
  1. 3
      test/integration/multisig.js
  2. 16
      test/integration/utils.js

3
test/integration/multisig.js

@ -5,6 +5,7 @@ var bitcoin = require('../../')
var blockchain = new (require('cb-insight'))('https://test-insight.bitpay.com') var blockchain = new (require('cb-insight'))('https://test-insight.bitpay.com')
var faucetWithdraw = require('./utils').faucetWithdraw var faucetWithdraw = require('./utils').faucetWithdraw
var pollUnspent = require('./utils').pollUnspent var pollUnspent = require('./utils').pollUnspent
var pollSummary = require('./utils').pollSummary
describe('bitcoinjs-lib (multisig)', function () { describe('bitcoinjs-lib (multisig)', function () {
it('can create a 2-of-3 multisig P2SH address', 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) if (err) return done(err)
// check that the funds (1e4 Satoshis) indeed arrived at the intended address // 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) if (err) return done(err)
assert.strictEqual(result.balance, 1e4) assert.strictEqual(result.balance, 1e4)

16
test/integration/utils.js

@ -19,10 +19,24 @@ function pollUnspent(blockchain, address, done) {
done(null, unspents) 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 = { module.exports = {
faucetWithdraw: faucetWithdraw, faucetWithdraw: faucetWithdraw,
pollUnspent: pollUnspent pollUnspent: pollUnspent,
pollSummary: pollSummary
} }

Loading…
Cancel
Save