Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@
"async": "^0.9.0",
"browserify": "^10.0.0",
"bs58": "^2.0.1",
"cb-helloblock": "^0.4.13",
"cb-blockr": "^3.1.1",
"cb-insight": "git://github.com/weilu/cb-insight",
"coveralls": "^2.11.2",
"istanbul": "^0.3.5",
"mocha": "^2.2.0",
Expand Down
8 changes: 5 additions & 3 deletions test/integration/advanced.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

var assert = require('assert')
var bitcoin = require('../../')
var blockchain = new (require('cb-helloblock'))('testnet')
var blockchain = new (require('cb-insight'))('https://test-insight.bitpay.com')
var faucetWithdraw = require('./utils').faucetWithdraw
var pollUnspent = require('./utils').pollUnspent

describe('bitcoinjs-lib (advanced)', function () {
it('can sign a Bitcoin message', function () {
Expand All @@ -29,10 +31,10 @@ describe('bitcoinjs-lib (advanced)', function () {
})
var address = keyPair.getAddress().toString()

blockchain.addresses.__faucetWithdraw(address, 2e4, function (err) {
faucetWithdraw(address, 2e4, function (err) {
if (err) return done(err)

blockchain.addresses.unspents(address, function (err, unspents) {
pollUnspent(blockchain, address, function (err, unspents) {
if (err) return done(err)

var tx = new bitcoin.TransactionBuilder()
Expand Down
2 changes: 1 addition & 1 deletion test/integration/crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var assert = require('assert')
var async = require('async')
var bigi = require('bigi')
var bitcoin = require('../../')
var blockchain = new (require('cb-helloblock'))('bitcoin')
var blockchain = new (require('cb-blockr'))('bitcoin')
var crypto = require('crypto')

describe('bitcoinjs-lib (crypto)', function () {
Expand Down
11 changes: 7 additions & 4 deletions test/integration/multisig.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

var assert = require('assert')
var bitcoin = require('../../')
var blockchain = new (require('cb-helloblock'))('testnet')
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 () {
Expand Down Expand Up @@ -37,11 +40,11 @@ describe('bitcoinjs-lib (multisig)', function () {
var address = bitcoin.Address.fromOutputScript(scriptPubKey, bitcoin.networks.testnet).toString()

// Attempt to send funds to the source address
blockchain.addresses.__faucetWithdraw(address, 2e4, function (err) {
faucetWithdraw(address, 2e4, function (err) {
if (err) return done(err)

// get latest unspents from the address
blockchain.addresses.unspents(address, function (err, unspents) {
pollUnspent(blockchain, address, function (err, unspents) {
if (err) return done(err)

// filter small unspents
Expand Down Expand Up @@ -70,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)
Expand Down
42 changes: 42 additions & 0 deletions test/integration/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
var https = require('https')

function faucetWithdraw (address, amount, done) {
var url = 'https://coconut-macaroon.herokuapp.com/withdrawal?address=' + address + '&amount=' + amount
https.get(url, function (res) {
res.statusCode === 200 ? done(null) : done(new Error('non-200 status: ' + res.statusCode))
}).on('error', done)
}

function pollUnspent (blockchain, address, done) {
blockchain.addresses.unspents(address, function (err, unspents) {
if (err) return done(err)

if (!unspents || unspents.length === 0) {
return setTimeout(function () {
pollUnspent(blockchain, address, done)
}, 200)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this just go on forever?

}

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,
pollSummary: pollSummary
}