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.2k
/
id.js
98 lines (78 loc) · 2.79 KB
/
id.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/* eslint-env mocha */
import { expect } from 'aegir/chai'
import { getDescribe, getIt } from '../utils/mocha.js'
import { isMultiaddr } from '@multiformats/multiaddr'
import { isWebWorker } from 'ipfs-utils/src/env.js'
import retry from 'p-retry'
/**
* @typedef {import('ipfsd-ctl').Factory} Factory
*/
/**
* @param {Factory} factory
* @param {object} options
*/
export function testId (factory, options) {
const describe = getDescribe(options)
const it = getIt(options)
describe('.id', function () {
this.timeout(60 * 1000)
/** @type {import('ipfs-core-types').IPFS} */
let ipfs
before(async () => {
ipfs = (await factory.spawn()).api
})
after(() => factory.clean())
it('should get the node ID', async () => {
const res = await ipfs.id()
expect(res).to.have.a.property('id')
expect(res).to.have.a.property('publicKey')
expect(res).to.have.a.property('agentVersion').that.is.a('string')
expect(res).to.have.a.property('protocolVersion').that.is.a('string')
expect(res).to.have.a.property('addresses').that.is.an('array')
for (const ma of res.addresses) {
expect(isMultiaddr(ma)).to.be.true()
}
})
it('should have protocols property', async () => {
const res = await ipfs.id()
expect(res).to.have.a.property('protocols').that.is.an('array')
expect(res.protocols).to.include.members([
'/ipfs/bitswap/1.2.0',
'/ipfs/id/1.0.0',
'/ipfs/id/push/1.0.0',
'/ipfs/lan/kad/1.0.0',
'/ipfs/ping/1.0.0'
])
})
it('should return swarm ports opened after startup', async function () {
if (isWebWorker) {
// TODO: webworkers are not currently dialable
return this.skip()
}
await expect(ipfs.id()).to.eventually.have.property('addresses').that.is.not.empty()
})
it('should get the id of another node in the swarm', async function () {
if (isWebWorker) {
// TODO: https://github.com/libp2p/js-libp2p-websockets/issues/129
return this.skip()
}
const ipfsB = (await factory.spawn()).api
const ipfsBId = await ipfsB.id()
await ipfs.swarm.connect(ipfsBId.addresses[0])
// have to wait for identify to complete before protocols etc are available for remote hosts
await retry(async () => {
const result = await ipfs.id({
peerId: ipfsBId.id
})
expect(JSON.stringify(result, null, 2)).to.deep.equal(JSON.stringify(ipfsBId, null, 2))
}, { retries: 5 })
})
it('should get our own id when passed as an option', async function () {
const res = await ipfs.id()
const result = await ipfs.id({
peerId: res.id
})
expect(JSON.stringify(res, null, 2)).to.deep.equal(JSON.stringify(result, null, 2))
})
})
}