Merge pull request #412 from bitcoinjs/replace-cb-helloblock

Integration tests: replace cb-helloblock with cb-insight and cb-blockr
This commit is contained in:
Daniel Cousens 2015-06-01 11:56:39 +10:00
commit 768ed69784
5 changed files with 57 additions and 9 deletions

View file

@ -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",

View file

@ -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 () {
@ -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()

View file

@ -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 () {

View file

@ -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 () {
@ -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
@ -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)

42
test/integration/utils.js Normal file
View file

@ -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)
}
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
}