From 382409c575120c5898989aa0f5112a273049e7b2 Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Wed, 6 Jan 2016 08:32:50 +1100 Subject: [PATCH 1/5] tests: rm unused fixtures --- test/fixtures/network.json | 30 ------------------------------ 1 file changed, 30 deletions(-) delete mode 100644 test/fixtures/network.json diff --git a/test/fixtures/network.json b/test/fixtures/network.json deleted file mode 100644 index e542aad..0000000 --- a/test/fixtures/network.json +++ /dev/null @@ -1,30 +0,0 @@ -[ - { - "network": "bitcoin", - "bip32": { - "private": "xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi", - "public": "xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8" - } - }, - { - "network": "testnet", - "bip32": { - "private": "tprv8ZgxMBicQKsPeDgjzdC36fs6bMjGApWDNLR9erAXMs5skhMv36j9MV5ecvfavji5khqjWaWSFhN3YcCUUdiKH6isR4Pwy3U5y5egddBr16m", - "public": "tpubD6NzVbkrYhZ4XgiXtGrdW5XDAPFCL9h7we1vwNCpn8tGbBcgfVYjXyhWo4E1xkh56hjod1RhGjxbaTLV3X4FyWuejifB9jusQ46QzG87VKp" - } - }, - { - "network": "litecoin", - "bip32": { - "private": "Ltpv71G8qDifUiNetP6nmxPA5STrUVmv2J9YSmXajv8VsYBUyuPhvN9xCaQrfX2wo5xxJNtEazYCFRUu5FmokYMM79pcqz8pcdo4rNXAFPgyB4k", - "public": "Ltub2SSUS19CirucWFod2ZsYA2J4v4U76YiCXHdcQttnoiy5aGanFHCPDBX7utfG6f95u1cUbZJNafmvzNCzZZJTw1EmyFoL8u1gJbGM8ipu491" - } - }, - { - "network": "dogecoin", - "bip32": { - "private": "dgpv51eADS3spNJh9Gjth94XcPwAczvQaDJs9rqx11kvxKs6r3Ek8AgERHhjLs6mzXQFHRzQqGwqdeoDkZmr8jQMBfi43b7sT3sx3cCSk5fGeUR", - "public": "dgub8kXBZ7ymNWy2S8Q3jNgVjFUm5ZJ3QLLaSTdAA89ukSv7Q6MSXwE14b7Nv6eDpE9JJXinTKc8LeLVu19uDPrm5uJuhpKNzV2kAgncwo6bNpP" - } - } -] From 755c344e1699c270857c290ec4991bf8d78d5e1d Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Wed, 6 Jan 2016 12:46:02 +1100 Subject: [PATCH 2/5] tests/integration: re-broadcast input tx to avoid missing inputs error --- test/integration/_blockchain.js | 49 ++++++++++++++++----------------- test/integration/advanced.js | 9 ++---- test/integration/multisig.js | 5 +--- 3 files changed, 26 insertions(+), 37 deletions(-) diff --git a/test/integration/_blockchain.js b/test/integration/_blockchain.js index bb2b6b8..ac77e50 100644 --- a/test/integration/_blockchain.js +++ b/test/integration/_blockchain.js @@ -8,40 +8,37 @@ var mainnet = new Blockchain('https://api.blocktrail.com/cb/v0.2.1/BTC', { api_k var testnet = new Blockchain('https://api.blocktrail.com/cb/v0.2.1/tBTC', { api_key: BLOCKTRAIL_API_KEY }) testnet.faucet = function faucet (address, amount, done) { - var unspents = [] + async.retry(5, function (callback) { + httpify({ + method: 'POST', + url: 'https://api.blocktrail.com/v1/tBTC/faucet/withdrawl?api_key=' + BLOCKTRAIL_API_KEY, + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ + address: address, + amount: amount + }) + }, function (err) { + if (err) return callback(err) - 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, - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ - address: address, - amount: amount - }) - }, function (err) { + testnet.addresses.unspents(address, function (err, result) { if (err) return callback(err) - testnet.addresses.unspents(address, function (err, result) { + var unspent = result.filter(function (unspent) { + return unspent.value > 1e3 + }).pop() + + testnet.transactions.get(unspent.txId, function (err, tx) { if (err) return callback(err) - // filter small unspents - unspents = result.filter(function (unspent) { - return unspent.value > 1e3 - }) + testnet.transactions.propagate(tx.txHex, function (err) { + if (err) return callback(err) - callback() + callback(null, unspent) + }) }) }) - }, - function (err) { - if (err) return done(err) - - done(null, unspents) - } - ) + }) + }, done) } module.exports = { diff --git a/test/integration/advanced.js b/test/integration/advanced.js index 3abb665..c28e78d 100644 --- a/test/integration/advanced.js +++ b/test/integration/advanced.js @@ -28,11 +28,9 @@ describe('bitcoinjs-lib (advanced)', function () { var keyPair = bitcoin.ECPair.makeRandom({ network: network }) var address = keyPair.getAddress() - blockchain.t.faucet(address, 2e4, function (err, unspents) { + blockchain.t.faucet(address, 2e4, function (err, unspent) { if (err) return done(err) - // use the oldest unspent - var unspent = unspents.pop() var tx = new bitcoin.TransactionBuilder(network) var data = new Buffer('bitcoinjs-lib') var dataScript = bitcoin.script.nullDataOutput(data) @@ -76,12 +74,9 @@ describe('bitcoinjs-lib (advanced)', function () { beforeEach(function (done) { this.timeout(10000) - blockchain.t.faucet(alice.getAddress(), 2e4, function (err, unspents) { + blockchain.t.faucet(alice.getAddress(), 2e4, function (err, unspent) { if (err) return done(err) - // use the oldest unspent - var unspent = unspents.pop() - // build the transaction var tx = new bitcoin.TransactionBuilder(network) tx.addInput(unspent.txId, unspent.vout) diff --git a/test/integration/multisig.js b/test/integration/multisig.js index 1a211d5..83f0e81 100644 --- a/test/integration/multisig.js +++ b/test/integration/multisig.js @@ -37,12 +37,9 @@ 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, unspents) { + blockchain.t.faucet(address, 2e4, function (err, unspent) { if (err) return done(err) - // use the oldest unspent - var unspent = unspents.pop() - // make a random destination address var targetAddress = bitcoin.ECPair.makeRandom({ network: bitcoin.networks.testnet From f9f41adddae2078eaec191403ecfe35e7027ce89 Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Wed, 6 Jan 2016 13:01:43 +1100 Subject: [PATCH 3/5] tests/integration: throw if no unspent is given --- test/integration/_blockchain.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/integration/_blockchain.js b/test/integration/_blockchain.js index ac77e50..7af0ec3 100644 --- a/test/integration/_blockchain.js +++ b/test/integration/_blockchain.js @@ -27,6 +27,8 @@ testnet.faucet = function faucet (address, amount, done) { return unspent.value > 1e3 }).pop() + if (!unspent) return callback(new Error('No unspent given')) + testnet.transactions.get(unspent.txId, function (err, tx) { if (err) return callback(err) From a5f1994f8634ad51dd0980a64eaa6d2279a2433f Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Wed, 6 Jan 2016 13:10:57 +1100 Subject: [PATCH 4/5] tests/integration: remove redundant check --- test/integration/_blockchain.js | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/test/integration/_blockchain.js b/test/integration/_blockchain.js index 7af0ec3..f6bfb9f 100644 --- a/test/integration/_blockchain.js +++ b/test/integration/_blockchain.js @@ -28,16 +28,7 @@ testnet.faucet = function faucet (address, amount, done) { }).pop() if (!unspent) return callback(new Error('No unspent given')) - - testnet.transactions.get(unspent.txId, function (err, tx) { - if (err) return callback(err) - - testnet.transactions.propagate(tx.txHex, function (err) { - if (err) return callback(err) - - callback(null, unspent) - }) - }) + callback(null, unspent) }) }) }, done) From 35a2a6ba1edf5f2bc363ff3c8611e2716fb8a54b Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Wed, 6 Jan 2016 13:14:36 +1100 Subject: [PATCH 5/5] tests/integration: increase multisig timeout --- test/integration/multisig.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/multisig.js b/test/integration/multisig.js index 83f0e81..16f3f00 100644 --- a/test/integration/multisig.js +++ b/test/integration/multisig.js @@ -22,7 +22,7 @@ describe('bitcoinjs-lib (multisig)', function () { }) it('can spend from a 2-of-4 multsig P2SH address', function (done) { - this.timeout(22000) + this.timeout(30000) var keyPairs = [ '91avARGdfge8E4tZfYLoxeJ5sGBdNJQH4kvjJoQFacbgwmaKkrx',