Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit b2106c1

Browse files
authored
test: bootstrapers tests, for @lgierth (#899)
1 parent 6db3fb8 commit b2106c1

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

.aegir.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ const stop = ads.stopNodes
1111
*/
1212
function start (done) {
1313
const base = '/ip4/127.0.0.1/tcp'
14-
1514
if (!process.env.IPFS_TEST) {
1615
parallel([
1716
(cb) => js([`${base}/10007`, `${base}/20007/ws`], true, 31007, 32007, cb),
@@ -21,13 +20,15 @@ function start (done) {
2120
(cb) => js([`${base}/10014`, `${base}/20014/ws`], true, 31014, 32014, cb),
2221
(cb) => js([`${base}/10015`, `${base}/20015/ws`], true, 31015, 32015, cb)
2322
], done)
24-
} else {
23+
} else if (process.env.IPFS_TEST === 'interop') {
2524
parallel([
2625
(cb) => go([`${base}/10027`, `${base}/20027/ws`], true, 33027, 44027, cb),
2726
(cb) => go([`${base}/10028`, `${base}/20028/ws`], true, 33028, 44028, cb),
2827
(cb) => go([`${base}/10031`, `${base}/20031/ws`], true, 33031, 44031, cb),
2928
(cb) => go([`${base}/10032`, `${base}/20032/ws`], true, 33032, 44032, cb)
3029
], done)
30+
} else if (process.env.IPFS_TEST === 'bootstrapers') {
31+
done()
3132
}
3233
}
3334

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"test:interop": "IPFS_TEST=interop aegir test -t node -t browser -f test/interop",
3737
"test:interop:node": "IPFS_TEST=interop aegir test -t node -f test/interop/node.js",
3838
"test:interop:browser": "IPFS_TEST=interop aegir test -t browser -f test/interop/browser.js",
39+
"test:bootstrapers": "IPFS_TEST=bootstrapers aegir test -t browser -f test/bootstrapers.js",
3940
"test:benchmark": "echo \"Error: no benchmarks yet\" && exit 1",
4041
"test:benchmark:node": "echo \"Error: no benchmarks yet\" && exit 1",
4142
"test:benchmark:node:core": "echo \"Error: no benchmarks yet\" && exit 1",

test/bootstrapers.js

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/* eslint-env mocha */
2+
'use strict'
3+
4+
const chai = require('chai')
5+
const dirtyChai = require('dirty-chai')
6+
const expect = chai.expect
7+
chai.use(dirtyChai)
8+
const IPFS = require('..')
9+
const list = require('../src/core/runtime/config-browser.json').Bootstrap
10+
11+
/*
12+
* These tests were graciously made for lgierth, so that he can test the
13+
* WebSockets Bootstrappers easily <3
14+
*/
15+
describe('Check that a js-ipfs node can indeed contact the bootstrappers', function () {
16+
this.timeout(60 * 1000)
17+
18+
it('a node connects to bootstrapers', (done) => {
19+
const node = new IPFS({
20+
config: {
21+
Addresses: {
22+
Swarm: []
23+
}
24+
}
25+
})
26+
27+
node.on('ready', check)
28+
29+
function check () {
30+
node.swarm.peers((err, peers) => {
31+
expect(err).to.not.exist()
32+
33+
if (peers.length !== list.length) {
34+
return setTimeout(check, 2000)
35+
}
36+
37+
const peerList = peers.map((peer) => peer.addr.toString())
38+
expect(peers.length).to.equal(list.length)
39+
expect(peerList).to.eql(list)
40+
41+
node.stop(done)
42+
})
43+
}
44+
})
45+
})

0 commit comments

Comments
 (0)