This repository has been archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathaddrs.js
55 lines (45 loc) · 1.5 KB
/
addrs.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
46
47
48
49
50
51
52
53
54
55
/* eslint-env mocha */
import { isMultiaddr } from '@multiformats/multiaddr'
import { expect } from 'aegir/chai'
import { getDescribe, getIt } from '../utils/mocha.js'
import { isWebWorker } from 'ipfs-utils/src/env.js'
/**
* @typedef {import('ipfsd-ctl').Factory} Factory
*/
/**
* @param {Factory} factory
* @param {object} options
*/
export function testAddrs (factory, options) {
const describe = getDescribe(options)
const it = getIt(options)
describe('.swarm.addrs', function () {
this.timeout(80 * 1000)
/** @type {import('ipfs-core-types').IPFS} */
let ipfsA
/** @type {import('ipfs-core-types').IPFS} */
let ipfsB
/** @type {import('ipfs-core-types/src/root').IDResult} */
let ipfsBId
before(async () => {
ipfsA = (await factory.spawn({ type: 'proc' })).api
// webworkers are not dialable because webrtc is not available
ipfsB = (await factory.spawn({ type: isWebWorker ? 'go' : undefined })).api
ipfsBId = await ipfsB.id()
await ipfsA.swarm.connect(ipfsBId.addresses[0])
})
after(() => factory.clean())
it('should get a list of node addresses', async () => {
const peers = await ipfsA.swarm.addrs()
expect(peers).to.not.be.empty()
expect(peers).to.be.an('array')
for (const peer of peers) {
expect(peer.id).to.be.ok()
expect(peer).to.have.a.property('addrs').that.is.an('array')
for (const ma of peer.addrs) {
expect(isMultiaddr(ma)).to.be.true()
}
}
})
})
}