Skip to content
This repository was 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
Changes from 1 commit
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
18 changes: 11 additions & 7 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,28 +22,30 @@ 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, multiaddrs) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we change multiaddrs to peers or peersInfo?

I was not understanding the forEach validation, but after getting into the code, I noticed that in fact ipfs.swarm.addrs() returns an array of PeerInfo. This way, calling this multiaddrs seems confusing. I think we should also update in the SPEC

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed to peerInfos as there's already precedent for that name in swarm.peers docs.

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')
multiaddrs.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) => {
return ipfsA.swarm.addrs().then((multiaddrs) => {
expect(multiaddrs).to.have.length.above(0)
})
})
Expand Down