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

fix: swarm addrs test #454

Merged
merged 2 commits into from
Apr 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions SPEC/SWARM.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@

##### `ipfs.swarm.addrs([callback])`

`callback` must follow `function (err, addrs) {}` signature, where `err` is an error if the operation was not successful. `addrs` will be an array of [`PeerInfo`](https://github.com/libp2p/js-peer-info)s.
`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`](https://github.com/libp2p/js-peer-info)s.

If no `callback` is passed, a promise is returned.

**Example:**

```JavaScript
ipfs.swarm.addrs(function (err, addrs) {
ipfs.swarm.addrs(function (err, peerInfos) {
if (err) {
throw err
}
console.log(addrs)
console.log(peerInfos)
})
```

Expand Down
24 changes: 14 additions & 10 deletions src/swarm/addrs.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/* eslint-env mocha */
'use strict'

const PeerInfo = require('peer-info')
const { getDescribe, getIt, expect } = require('../utils/mocha')
const { spawnNodesWithId } = require('../utils/spawn')

module.exports = (createCommon, options) => {
const describe = getDescribe(options)
Expand All @@ -11,7 +13,7 @@ module.exports = (createCommon, options) => {
describe('.swarm.addrs', function () {
this.timeout(80 * 1000)

let ipfs
let ipfsA, ipfsB

before(function (done) {
// CI takes longer to instantiate the daemon, so we need to increase the
Expand All @@ -20,29 +22,31 @@ module.exports = (createCommon, options) => {

common.setup((err, factory) => {
expect(err).to.not.exist()
factory.spawnNode((err, node) => {

spawnNodesWithId(2, factory, (err, nodes) => {
expect(err).to.not.exist()
ipfs = node
done()
ipfsA = nodes[0]
ipfsB = nodes[1]
ipfsA.swarm.connect(ipfsB.peerId.addresses[0], done)
})
})
})

after((done) => common.teardown(done))

it('should get a list of node addresses', (done) => {
ipfs.swarm.addrs((err, multiaddrs) => {
ipfsA.swarm.addrs((err, peerInfos) => {
expect(err).to.not.exist()
expect(multiaddrs).to.not.be.empty()
expect(multiaddrs).to.be.an('array')
expect(multiaddrs[0].constructor.name).to.be.eql('PeerInfo')
expect(peerInfos).to.not.be.empty()
expect(peerInfos).to.be.an('array')
peerInfos.forEach(m => expect(PeerInfo.isPeerInfo(m)).to.be.true())
done()
})
})

it('should get a list of node addresses (promised)', () => {
return ipfs.swarm.addrs().then((multiaddrs) => {
expect(multiaddrs).to.have.length.above(0)
return ipfsA.swarm.addrs().then((peerInfos) => {
expect(peerInfos).to.have.length.above(0)
})
})
})
Expand Down