Browse Source

Merge branch 'master' into jprichardson-patch-1

hk-custom-address
Daniel Cousens 9 years ago
parent
commit
9ab8739652
  1. 6
      package.json
  2. 31
      test/integration/_blockchain.js
  3. 15
      test/integration/advanced.js
  4. 14
      test/integration/multisig.js

6
package.json

@ -1,6 +1,6 @@
{
"name": "bitcoinjs-lib",
"version": "2.1.2",
"version": "2.1.3",
"description": "Client-side Bitcoin JavaScript library",
"main": "./src/index.js",
"keywords": [
@ -68,11 +68,11 @@
"create-hmac": "^1.1.3",
"ecurve": "^1.0.0",
"randombytes": "^2.0.1",
"typeforce": "^1.3.0",
"typeforce": "^1.5.5",
"wif": "^1.1.0"
},
"devDependencies": {
"async": "^0.9.0",
"async": "^1.5.0",
"blanket": "^1.1.0",
"browserify": "^10.0.0",
"bs58": "^2.0.1",

31
test/integration/_blockchain.js

@ -1,3 +1,4 @@
var async = require('async')
var Blockchain = require('cb-http-client')
var httpify = require('httpify')
@ -5,7 +6,13 @@ var BLOCKTRAIL_API_KEY = process.env.BLOCKTRAIL_API_KEY || 'c0bd8155c66e3fb148bb
var mainnet = new Blockchain('https://api.blocktrail.com/cb/v0.2.1/BTC', { api_key: BLOCKTRAIL_API_KEY })
var testnet = new Blockchain('https://api.blocktrail.com/cb/v0.2.1/tBTC', { api_key: BLOCKTRAIL_API_KEY })
testnet.faucet = function faucet (address, amount, callback) {
testnet.faucet = function faucet (address, amount, done) {
var unspents = []
async.whilst(
function condition () { return unspents.length === 0 },
function f (callback) {
httpify({
method: 'POST',
url: 'https://api.blocktrail.com/v1/tBTC/faucet/withdrawl?api_key=' + BLOCKTRAIL_API_KEY,
@ -14,7 +21,27 @@ testnet.faucet = function faucet (address, amount, callback) {
address: address,
amount: amount
})
}, callback)
}, function (err) {
if (err) return callback(err)
testnet.addresses.unspents(address, function (err, result) {
if (err) return callback(err)
// filter small unspents
unspents = result.filter(function (unspent) {
return unspent.value > 1e3
})
callback()
})
})
},
function (err) {
if (err) return done(err)
done(null, unspents)
}
)
}
module.exports = {

15
test/integration/advanced.js

@ -22,27 +22,17 @@ describe('bitcoinjs-lib (advanced)', function () {
})
it('can create an OP_RETURN transaction', function (done) {
this.timeout(20000)
this.timeout(30000)
var network = bitcoin.networks.testnet
var keyPair = bitcoin.ECPair.makeRandom({ network: network })
var address = keyPair.getAddress()
blockchain.t.faucet(address, 2e4, function (err) {
blockchain.t.faucet(address, 2e4, function (err, unspents) {
if (err) return done(err)
blockchain.t.addresses.unspents(address, function (err, unspents) {
if (err) return done(err)
// filter small unspents
unspents = unspents.filter(function (unspent) {
return unspent.value > 1e4
})
// use the oldest unspent
var unspent = unspents.pop()
if (!unspent) throw new Error('Faucet didn\'t provide an unspent')
var tx = new bitcoin.TransactionBuilder(network)
var data = new Buffer('bitcoinjs-lib')
var dataScript = bitcoin.script.nullDataOutput(data)
@ -73,4 +63,3 @@ describe('bitcoinjs-lib (advanced)', function () {
})
})
})
})

14
test/integration/multisig.js

@ -37,23 +37,12 @@ describe('bitcoinjs-lib (multisig)', function () {
var address = bitcoin.address.fromOutputScript(scriptPubKey, bitcoin.networks.testnet)
// attempt to send funds to the source address
blockchain.t.faucet(address, 2e4, function (err) {
blockchain.t.faucet(address, 2e4, function (err, unspents) {
if (err) return done(err)
// get latest unspents from the address
blockchain.t.addresses.unspents(address, function (err, unspents) {
if (err) return done(err)
// filter small unspents
unspents = unspents.filter(function (unspent) {
return unspent.value > 1e4
})
// use the oldest unspent
var unspent = unspents.pop()
if (!unspent) throw new Error('Faucet didn\'t provide an unspent')
// make a random destination address
var targetAddress = bitcoin.ECPair.makeRandom({
network: bitcoin.networks.testnet
@ -88,4 +77,3 @@ describe('bitcoinjs-lib (multisig)', function () {
})
})
})
})

Loading…
Cancel
Save