This repository was 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
/
Copy pathswarm.js
103 lines (88 loc) · 2.42 KB
/
swarm.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
99
100
101
102
103
/* eslint max-nested-callbacks: ["error", 8] */
/* eslint-env mocha */
'use strict'
const chai = require('chai')
const dirtyChai = require('dirty-chai')
const expect = chai.expect
chai.use(dirtyChai)
const series = require('async/series')
const ipfsExec = require('../utils/ipfs-exec')
const parallel = require('async/parallel')
const DaemonFactory = require('ipfsd-ctl')
const df = DaemonFactory.create({ type: 'js' })
const config = {
Bootstrap: [],
Discovery: {
MDNS: {
Enabled:
false
}
}
}
describe('swarm', () => {
let bMultiaddr
let ipfsA
let nodes = []
before(function (done) {
// CI takes longer to instantiate the daemon, so we need to increase the
// timeout for the before step
this.timeout(80 * 1000)
series([
(cb) => {
df.spawn({ exec: `./src/cli/bin.js`, config }, (err, node) => {
expect(err).to.not.exist()
ipfsA = ipfsExec(node.repoPath)
nodes.push(node)
cb()
})
},
(cb) => {
df.spawn({ exec: `./src/cli/bin.js`, config }, (err, node) => {
expect(err).to.not.exist()
node.api.id((err, id) => {
expect(err).to.not.exist()
bMultiaddr = id.addresses[0]
nodes.push(node)
cb()
})
})
}
], done)
})
after((done) => parallel(nodes.map((node) => (cb) => node.stop(cb)), done))
describe('daemon on (through http-api)', function () {
this.timeout(60 * 1000)
it('connect', () => {
return ipfsA('swarm', 'connect', bMultiaddr).then((out) => {
expect(out).to.eql(`connect ${bMultiaddr} success\n`)
})
})
it('peers', () => {
return ipfsA('swarm peers').then((out) => {
expect(out).to.eql(bMultiaddr + '\n')
})
})
it('addrs', () => {
return ipfsA('swarm addrs').then((out) => {
expect(out).to.have.length.above(1)
})
})
it('addrs local', () => {
return ipfsA('swarm addrs local').then((out) => {
expect(out).to.have.length.above(1)
})
})
it('disconnect', () => {
return ipfsA('swarm', 'disconnect', bMultiaddr).then((out) => {
expect(out).to.eql(
`disconnect ${bMultiaddr} success\n`
)
})
})
it('`peers` should not throw after `disconnect`', () => {
return ipfsA('swarm peers').then((out) => {
expect(out).to.be.empty()
})
})
})
})