Skip to content

Commit ba531ba

Browse files
authored
Fix tests (#1)
* Get _regtest.js file * Fix integration tests * Update supported node version in tests
1 parent 9860b9b commit ba531ba

File tree

9 files changed

+369
-367
lines changed

9 files changed

+369
-367
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
sudo: false
22
language: node_js
33
node_js:
4-
- "4"
5-
- "5"
64
- "6"
75
- "7"
86
- "8"
7+
- "9"
8+
- "10"
99
matrix:
1010
include:
1111
- node_js: "7"

package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,10 @@
5050
"wif": "^2.0.1"
5151
},
5252
"devDependencies": {
53-
"async": "^2.0.1",
5453
"bip39": "^2.3.0",
54+
"bip65": "^1.0.1",
5555
"bs58": "^4.0.0",
56-
"cb-http-client": "^0.2.0",
57-
"coinselect": "^3.1.1",
58-
"dhttp": "^2.3.5",
56+
"dhttp": "^2.4.2",
5957
"minimaldata": "^1.0.2",
6058
"mocha": "^3.1.0",
6159
"nyc": "^10.2.0",

test/integration/_mainnet.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

test/integration/_regtest.js

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
var bitcoin = require('../../')
2+
var dhttp = require('dhttp/200')
3+
4+
var APIPASS = process.env.APIPASS || 'satoshi'
5+
var APIURL = 'https://api.dcousens.cloud/1'
6+
7+
function broadcast (txHex, callback) {
8+
dhttp({
9+
method: 'PUT',
10+
url: APIURL + '/t/push',
11+
body: txHex
12+
}, callback)
13+
}
14+
15+
function mine (count, callback) {
16+
dhttp({
17+
method: 'POST',
18+
url: APIURL + '/r/generate?count=' + count + '&key=' + APIPASS
19+
}, callback)
20+
}
21+
22+
function height (callback) {
23+
dhttp({
24+
method: 'GET',
25+
url: APIURL + '/b/best/height'
26+
}, callback)
27+
}
28+
29+
function faucet (address, value, callback) {
30+
dhttp({
31+
method: 'POST',
32+
url: APIURL + '/r/faucet?address=' + address + '&value=' + value + '&key=' + APIPASS
33+
}, function (err, txId) {
34+
if (err) return callback(err)
35+
36+
unspents(address, function (err, results) {
37+
if (err) return callback(err)
38+
39+
callback(null, results.filter(x => x.txId === txId).pop())
40+
})
41+
})
42+
}
43+
44+
function fetch (txId, callback) {
45+
dhttp({
46+
method: 'GET',
47+
url: APIURL + '/t/' + txId
48+
}, callback)
49+
}
50+
51+
function unspents (address, callback) {
52+
dhttp({
53+
method: 'GET',
54+
url: APIURL + '/a/' + address + '/unspents'
55+
}, callback)
56+
}
57+
58+
function verify (txo, callback) {
59+
var { txId } = txo
60+
61+
fetch(txId, function (err, txHex) {
62+
if (err) return callback(err)
63+
64+
// TODO: verify address and value
65+
callback()
66+
})
67+
}
68+
69+
function randomAddress () {
70+
return bitcoin.ECPair.makeRandom({
71+
network: bitcoin.networks.testnet
72+
}).getAddress()
73+
}
74+
75+
module.exports = {
76+
broadcast: broadcast,
77+
faucet: faucet,
78+
fetch: fetch,
79+
height: height,
80+
mine: mine,
81+
network: bitcoin.networks.testnet,
82+
unspents: unspents,
83+
verify: verify,
84+
randomAddress: randomAddress,
85+
RANDOM_ADDRESS: randomAddress()
86+
}

test/integration/_testnet.js

Lines changed: 0 additions & 99 deletions
This file was deleted.

test/integration/addresses.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,22 +97,20 @@ describe('bitcoinjs-lib (addresses)', function () {
9797
assert.strictEqual(address, '3P4mrxQfmExfhxqjLnR2Ah4WES5EB1KBrN')
9898
})
9999

100-
it('can support the retrieval of transactions for an address (3rd party blockchain)', function (done) {
100+
it('can support the retrieval of transactions for an address (via 3PBP)', function (done) {
101101
var keyPair = bitcoin.ECPair.makeRandom()
102102
var address = keyPair.getAddress()
103103

104104
dhttp({
105-
method: 'POST',
106-
url: 'https://api.ei8ht.com.au/3/addrtxs',
107-
body: {
108-
addrs: [address],
109-
height: 0
110-
}
111-
}, function (err, transactions) {
105+
method: 'GET',
106+
url: 'https://blockchain.info/rawaddr/' + address
107+
}, function (err, result) {
112108
if (err) return done(err)
113109

114-
// random private keys [probably] have no transactions
115-
assert.strictEqual(Object.keys(transactions).length, 0)
110+
// random private keys [probably!] have no transactions
111+
assert.strictEqual(result.n_tx, 0)
112+
assert.strictEqual(result.total_received, 0)
113+
assert.strictEqual(result.total_sent, 0)
116114
done()
117115
})
118116
})

0 commit comments

Comments
 (0)