-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathjs2go.js
45 lines (34 loc) · 1.25 KB
/
js2go.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/* eslint-env mocha */
'use strict'
const chai = require('chai')
chai.use(require('dirty-chai'))
chai.use(require('chai-checkmark'))
const expect = chai.expect
const pRetry = require('p-retry')
const spawnDaemons = require('../../utils/spawnDaemons')
describe('dht.peerRouting', () => {
let daemons
// Start Daemons
before(async function () {
this.timeout(20 * 1000)
daemons = await spawnDaemons(3, ['js', 'js', 'go'], { dht: true })
})
// Stop daemons
after(async function () {
await Promise.all(
daemons.map((daemon) => daemon.stop())
)
})
it('js peer to go peer', async function () {
const identify1 = await daemons[1].client.identify()
const identify2 = await daemons[2].client.identify()
// peers need at least one peer in their routing table or they fail with:
// connect 0 => 1
await daemons[0].client.connect(identify1.peerId, identify1.addrs)
// connect 0 => 2
await daemons[0].client.connect(identify2.peerId, identify2.addrs)
// peer 1 find peer 2, retry up to 10 times to allow the routing table to refresh
const peerData = await pRetry(() => daemons[1].client.dht.findPeer(identify2.peerId), { retry: 10 })
expect(identify2.addrs).to.include.deep.members(peerData.addrs)
})
})