Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

Commit 2dd1e39

Browse files
committed
Implement all of the swarm API calls
1 parent 3db7441 commit 2dd1e39

File tree

3 files changed

+62
-3
lines changed

3 files changed

+62
-3
lines changed

src/api/swarm.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ const cmds = require('../cmd-helpers')
55
module.exports = (send) => {
66
return {
77
peers: cmds.command(send, 'swarm/peers'),
8-
connect: cmds.argCommand(send, 'swarm/connect')
8+
connect: cmds.argCommand(send, 'swarm/connect'),
9+
disconnect: cmds.argCommand(send, 'swarm/disconnect'),
10+
addrs: cmds.command(send, 'swarm/addrs'),
11+
localAddrs: cmds.command(send, 'swarm/addrs/local')
912
}
1013
}

test/api/swarm.spec.js

+37
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,49 @@ describe('.swarm', () => {
1515
done()
1616
})
1717

18+
it('.swarm.disconnect', (done) => {
19+
// Done in the 'after' segment
20+
done()
21+
})
22+
23+
it('.swarm.addrs', (done) => {
24+
apiClients['a'].swarm.addrs((err, res) => {
25+
expect(err).to.not.exist
26+
27+
expect(Object.keys(res.Addrs)).to.have.length(2)
28+
done()
29+
})
30+
})
31+
32+
it('.swarm.localAddrs', (done) => {
33+
apiClients['a'].swarm.localAddrs((err, res) => {
34+
expect(err).to.not.exist
35+
36+
expect(res.Strings).to.have.length(2)
37+
done()
38+
})
39+
})
40+
1841
describe('promise', () => {
1942
it('.swarm.peers', () => {
2043
return apiClients['a'].swarm.peers()
2144
.then((res) => {
2245
expect(res.Strings).to.have.length.above(1)
2346
})
2447
})
48+
49+
it('.swarm.addrs', () => {
50+
return apiClients['a'].swarm.addrs()
51+
.then((res) => {
52+
expect(Object.keys(res.Addrs)).to.have.length(2)
53+
})
54+
})
55+
56+
it('.swarm.localAddrs', () => {
57+
return apiClients['a'].swarm.localAddrs()
58+
.then((res) => {
59+
expect(res.Strings).to.have.length(2)
60+
})
61+
})
2562
})
2663
})

test/setup.js

+21-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ global.expect = require('chai').expect
77
global.apiClients = {} // a, b, c
88
global.isNode = require('detect-node')
99

10+
const addrs = {}
11+
1012
function connectNodes (done) {
11-
const addrs = {}
1213
let counter = 0
1314
collectAddr('b', finish)
1415
collectAddr('c', finish)
@@ -32,7 +33,7 @@ function connectNodes (done) {
3233
}
3334

3435
function dial () {
35-
apiClients['a'].swarm.connect(addrs['b'], (err, res) => {
36+
apiClients['a'].swarm.connect(addrs['b'], (err) => {
3637
if (err) {
3738
throw err
3839
}
@@ -46,6 +47,20 @@ function connectNodes (done) {
4647
}
4748
}
4849

50+
function disconnectNodes (done) {
51+
apiClients['a'].swarm.disconnect(addrs['b'], (err) => {
52+
if (err) {
53+
throw err
54+
}
55+
apiClients['a'].swarm.disconnect(addrs['c'], (err) => {
56+
if (err) {
57+
throw err
58+
}
59+
done()
60+
})
61+
})
62+
}
63+
4964
before(function (done) {
5065
this.timeout(20000)
5166

@@ -55,3 +70,7 @@ before(function (done) {
5570

5671
connectNodes(done)
5772
})
73+
74+
after(function (done) {
75+
disconnectNodes(done)
76+
})

0 commit comments

Comments
 (0)