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

Commit 4f008d6

Browse files
committed
feat(swarm): tests
1 parent f62f648 commit 4f008d6

File tree

4 files changed

+150
-21
lines changed

4 files changed

+150
-21
lines changed

API/swarm/README.md

+22-18
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ swarm API
33

44
#### `addrs`
55

6-
> List of known addresses (from the peer).
6+
> List of known addresses of each peer connected.
77
88
##### `Go` **WIP**
99

@@ -61,6 +61,27 @@ Example:
6161
ipfs.swarm.disconnect(addr, function (err) {})
6262
```
6363

64+
#### `peers`
65+
66+
> List out the peers that we have connections with.
67+
68+
##### `Go` **WIP**
69+
70+
##### `JavaScript` - ipfs.swarm.peers([callback])
71+
72+
`callback` must follow `function (err, peerInfos) {}` signature, where `err` is an error if the operation was not successful. `peerInfos` will be an array of [PeerInfo]().
73+
74+
If no `callback` is passed, a promise is returned.
75+
76+
Example:
77+
78+
```JavaScript
79+
ipfs.swarm.peers(function (https://twitter.com/hichaelmart/status/763777073265709056err, peerInfos) {})
80+
```
81+
82+
------------------------------
83+
> NOT IMPLEMENTED YET
84+
6485
#### `filters`
6586
6687
> Display current multiaddr filters
@@ -119,21 +140,4 @@ Example:
119140
ipfs.swarm.filters.rm(filter, function (err) {})
120141
```
121142
122-
#### `peers`
123-
124-
> List out the peers that we have connections with.
125-
126-
##### `Go` **WIP**
127-
128-
##### `JavaScript` - ipfs.swarm.peers([callback])
129-
130-
`callback` must follow `function (err, peerInfos) {}` signature, where `err` is an error if the operation was not successful. `peerInfos` will be an array of [PeerInfo]().
131-
132-
If no `callback` is passed, a promise is returned.
133-
134-
Example:
135-
136-
```JavaScript
137-
ipfs.swarm.peers(function (err, peerInfos) {})
138-
```
139143

package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "interface-ipfs-core",
33
"version": "0.11.0",
44
"description": "A test suite and interface you can use to implement a IPFS core interface.",
5-
"main": "lib/index.js",
5+
"main": "src/index.js",
66
"jsnext:main": "src/index.js",
77
"scripts": {
88
"test": "exit(0)",
@@ -34,7 +34,8 @@
3434
"concat-stream": "^1.5.1",
3535
"detect-node": "^2.0.3",
3636
"ipfs-merkle-dag": "^0.6.2",
37-
"readable-stream": "1.1.13"
37+
"readable-stream": "1.1.13",
38+
"run-series": "^1.1.4"
3839
},
3940
"devDependencies": {
4041
"aegir": "^6.0.0"
@@ -47,4 +48,4 @@
4748
"greenkeeperio-bot <[email protected]>",
4849
"nginnever <[email protected]>"
4950
]
50-
}
51+
}

src/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ exports.files = require('./files')
55
exports.config = require('./config')
66
exports.pin = require('./pin')
77
exports.generic = require('./generic')
8+
exports.swarm = require('./swarm')

src/swarm.js

+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
/* eslint-env mocha */
2+
/* eslint max-nested-callbacks: ["error", 8] */
3+
4+
'use strict'
5+
6+
const expect = require('chai').expect
7+
const series = require('run-series')
8+
9+
module.exports = (common) => {
10+
describe.only('.swarm', () => {
11+
let ipfsA
12+
let ipfsB
13+
14+
before(function (done) {
15+
// CI takes longer to instantiate the daemon,
16+
// so we need to increase the timeout for the
17+
// before step
18+
this.timeout(20 * 1000)
19+
20+
common.setup((err, factory) => {
21+
expect(err).to.not.exist
22+
series([
23+
(cb) => {
24+
factory.spawnNode((err, node) => {
25+
expect(err).to.not.exist
26+
ipfsA = node
27+
cb()
28+
})
29+
},
30+
(cb) => {
31+
factory.spawnNode((err, node) => {
32+
expect(err).to.not.exist
33+
ipfsB = node
34+
cb()
35+
})
36+
}
37+
], done)
38+
})
39+
})
40+
41+
after((done) => {
42+
common.teardown(done)
43+
})
44+
45+
describe('callback API', () => {
46+
it('.connect', (done) => {
47+
ipfsB.id((err, id) => {
48+
expect(err).to.not.exist
49+
const ipfsBAddr = id.addresses[0]
50+
ipfsA.swarm.connect(ipfsBAddr, done)
51+
})
52+
})
53+
54+
it('.peers', (done) => {
55+
ipfsA.swarm.peers((err, multiaddrs) => {
56+
expect(err).to.not.exist
57+
expect(multiaddrs).to.have.length.above(0)
58+
done()
59+
})
60+
})
61+
62+
it('.addrs', (done) => {
63+
ipfsA.swarm.addrs((err, multiaddrs) => {
64+
expect(err).to.not.exist
65+
expect(multiaddrs).to.have.length.above(0)
66+
done()
67+
})
68+
})
69+
70+
it('.localAddrs', (done) => {
71+
ipfsA.swarm.localAddrs((err, multiaddrs) => {
72+
expect(err).to.not.exist
73+
expect(multiaddrs).to.have.length.above(0)
74+
done()
75+
})
76+
})
77+
78+
it('.disconnect', (done) => {
79+
ipfsB.id((err, id) => {
80+
expect(err).to.not.exist
81+
const ipfsBAddr = id.addresses[0]
82+
ipfsA.swarm.disconnect(ipfsBAddr, done)
83+
})
84+
})
85+
})
86+
87+
describe('promise API', () => {
88+
it('.connect', () => {
89+
return ipfsB.id()
90+
.then((id) => {
91+
const ipfsBAddr = id.addresses[0]
92+
return ipfsA.swarm.connect(ipfsBAddr)
93+
})
94+
})
95+
96+
it('.peers', () => {
97+
return ipfsA.swarm.peers().then((multiaddrs) => {
98+
expect(multiaddrs).to.have.length.above(0)
99+
})
100+
})
101+
102+
it('.addrs', () => {
103+
return ipfsA.swarm.addrs().then((multiaddrs) => {
104+
expect(multiaddrs).to.have.length.above(0)
105+
})
106+
})
107+
108+
it('.localAddrs', () => {
109+
return ipfsA.swarm.localAddrs().then((multiaddrs) => {
110+
expect(multiaddrs).to.have.length.above(0)
111+
})
112+
})
113+
114+
it('.disconnect', () => {
115+
return ipfsB.id()
116+
.then((id) => {
117+
const ipfsBAddr = id.addresses[0]
118+
return ipfsA.swarm.disconnect(ipfsBAddr)
119+
})
120+
})
121+
})
122+
})
123+
}

0 commit comments

Comments
 (0)