commit
96fb92feb5
4 changed files with 23 additions and 71 deletions
30
test/fixtures/network.json
vendored
30
test/fixtures/network.json
vendored
|
@ -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"
|
||||
}
|
||||
}
|
||||
]
|
|
@ -8,40 +8,30 @@ 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) {
|
||||
if (err) return callback(err)
|
||||
var unspent = result.filter(function (unspent) {
|
||||
return unspent.value > 1e3
|
||||
}).pop()
|
||||
|
||||
// filter small unspents
|
||||
unspents = result.filter(function (unspent) {
|
||||
return unspent.value > 1e3
|
||||
})
|
||||
|
||||
callback()
|
||||
})
|
||||
if (!unspent) return callback(new Error('No unspent given'))
|
||||
callback(null, unspent)
|
||||
})
|
||||
},
|
||||
function (err) {
|
||||
if (err) return done(err)
|
||||
|
||||
done(null, unspents)
|
||||
}
|
||||
)
|
||||
})
|
||||
}, done)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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',
|
||||
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue