test(fix): correct findProviders test for missing provider (#391)

* test(fix): correct findProviders test for missing provider

* chore: fix lint
This commit is contained in:
Jacob Heun 2019-07-30 15:11:24 +02:00 committed by GitHub
parent 48b1b442e9
commit 65d52857a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 69 additions and 68 deletions

View File

@ -63,7 +63,7 @@
}, },
"devDependencies": { "devDependencies": {
"@nodeutils/defaults-deep": "^1.1.0", "@nodeutils/defaults-deep": "^1.1.0",
"aegir": "^19.0.3", "aegir": "^20.0.0",
"chai": "^4.2.0", "chai": "^4.2.0",
"chai-checkmark": "^1.0.1", "chai-checkmark": "^1.0.1",
"cids": "^0.7.1", "cids": "^0.7.1",
@ -74,7 +74,7 @@
"libp2p-circuit": "^0.3.7", "libp2p-circuit": "^0.3.7",
"libp2p-delegated-content-routing": "^0.2.2", "libp2p-delegated-content-routing": "^0.2.2",
"libp2p-delegated-peer-routing": "^0.2.2", "libp2p-delegated-peer-routing": "^0.2.2",
"libp2p-kad-dht": "^0.15.2", "libp2p-kad-dht": "^0.15.3",
"libp2p-mdns": "^0.12.3", "libp2p-mdns": "^0.12.3",
"libp2p-mplex": "^0.8.4", "libp2p-mplex": "^0.8.4",
"libp2p-secio": "^0.11.1", "libp2p-secio": "^0.11.1",

View File

@ -69,7 +69,7 @@ class Libp2p extends EventEmitter {
// Attach stream multiplexers // Attach stream multiplexers
if (this._modules.streamMuxer) { if (this._modules.streamMuxer) {
let muxers = this._modules.streamMuxer const muxers = this._modules.streamMuxer
muxers.forEach((muxer) => this._switch.connection.addStreamMuxer(muxer)) muxers.forEach((muxer) => this._switch.connection.addStreamMuxer(muxer))
// If muxer exists // If muxer exists
@ -99,7 +99,7 @@ class Libp2p extends EventEmitter {
// Attach crypto channels // Attach crypto channels
if (this._modules.connEncryption) { if (this._modules.connEncryption) {
let cryptos = this._modules.connEncryption const cryptos = this._modules.connEncryption
cryptos.forEach((crypto) => { cryptos.forEach((crypto) => {
this._switch.connection.crypto(crypto.tag, crypto.encrypt) this._switch.connection.crypto(crypto.tag, crypto.encrypt)
}) })

View File

@ -16,7 +16,7 @@ const tryEcho = require('./utils/try-echo')
const echo = require('./utils/echo') const echo = require('./utils/echo')
describe('circuit relay', () => { describe('circuit relay', () => {
let handlerSpies = [] const handlerSpies = []
let relayNode1 let relayNode1
let relayNode2 let relayNode2
let nodeWS1 let nodeWS1

View File

@ -33,7 +33,7 @@ describe('configuration', () => {
expect(() => { expect(() => {
validateConfig({ validateConfig({
modules: { modules: {
transport: [ WS ] transport: [WS]
} }
}) })
}).to.throw() }).to.throw()
@ -52,7 +52,7 @@ describe('configuration', () => {
validateConfig({ validateConfig({
peerInfo, peerInfo,
modules: { modules: {
transport: [ ] transport: []
} }
}) })
}).to.throw('ERROR_EMPTY') }).to.throw('ERROR_EMPTY')
@ -62,8 +62,8 @@ describe('configuration', () => {
const options = { const options = {
peerInfo, peerInfo,
modules: { modules: {
transport: [ WS ], transport: [WS],
peerDiscovery: [ Bootstrap ], peerDiscovery: [Bootstrap],
dht: DHT dht: DHT
} }
} }
@ -74,8 +74,8 @@ describe('configuration', () => {
minPeers: 25 minPeers: 25
}, },
modules: { modules: {
transport: [ WS ], transport: [WS],
peerDiscovery: [ Bootstrap ], peerDiscovery: [Bootstrap],
dht: DHT dht: DHT
}, },
config: { config: {
@ -112,8 +112,8 @@ describe('configuration', () => {
const options = { const options = {
peerInfo, peerInfo,
modules: { modules: {
transport: [ WS ], transport: [WS],
peerDiscovery: [ Bootstrap ], peerDiscovery: [Bootstrap],
dht: DHT dht: DHT
}, },
config: { config: {
@ -132,8 +132,8 @@ describe('configuration', () => {
minPeers: 25 minPeers: 25
}, },
modules: { modules: {
transport: [ WS ], transport: [WS],
peerDiscovery: [ Bootstrap ], peerDiscovery: [Bootstrap],
dht: DHT dht: DHT
}, },
config: { config: {
@ -181,8 +181,8 @@ describe('configuration', () => {
dialTimeout: 30e3 dialTimeout: 30e3
}, },
modules: { modules: {
transport: [ WS ], transport: [WS],
peerDiscovery: [ ] peerDiscovery: []
} }
} }
@ -204,10 +204,10 @@ describe('configuration', () => {
const options = { const options = {
peerInfo, peerInfo,
modules: { modules: {
transport: [ WS ], transport: [WS],
peerDiscovery: [ Bootstrap ], peerDiscovery: [Bootstrap],
peerRouting: [ peerRouter ], peerRouting: [peerRouter],
contentRouting: [ contentRouter ], contentRouting: [contentRouter],
dht: DHT dht: DHT
}, },
config: { config: {
@ -221,8 +221,8 @@ describe('configuration', () => {
} }
expect(validateConfig(options).modules).to.deep.include({ expect(validateConfig(options).modules).to.deep.include({
peerRouting: [ peerRouter ], peerRouting: [peerRouter],
contentRouting: [ contentRouter ] contentRouting: [contentRouter]
}) })
}) })
@ -230,7 +230,7 @@ describe('configuration', () => {
const options = { const options = {
peerInfo, peerInfo,
modules: { modules: {
transport: [ WS ] transport: [WS]
}, },
config: { config: {
dht: { dht: {

View File

@ -121,8 +121,9 @@ describe('.contentRouting', () => {
const cid = new CID('QmTp9VkYvnHyrqKQuFPiuZkiX9gPcqj6x5LJ1rmWuSnnnn') const cid = new CID('QmTp9VkYvnHyrqKQuFPiuZkiX9gPcqj6x5LJ1rmWuSnnnn')
nodeE.contentRouting.findProviders(cid, { maxTimeout: 5000 }, (err, providers) => { nodeE.contentRouting.findProviders(cid, { maxTimeout: 5000 }, (err, providers) => {
expect(err).to.not.exist() expect(err).to.exist()
expect(providers).to.have.length(0) expect(err.code).to.eql('ERR_NOT_FOUND')
expect(providers).to.not.exist()
done() done()
}) })
}) })
@ -150,7 +151,7 @@ describe('.contentRouting', () => {
nodeA = new Node({ nodeA = new Node({
peerInfo, peerInfo,
modules: { modules: {
contentRouting: [ delegate ] contentRouting: [delegate]
}, },
config: { config: {
dht: { dht: {
@ -300,7 +301,7 @@ describe('.contentRouting', () => {
nodeA = new Node({ nodeA = new Node({
peerInfo, peerInfo,
modules: { modules: {
contentRouting: [ delegate ] contentRouting: [delegate]
}, },
config: { config: {
relay: { relay: {

View File

@ -29,10 +29,10 @@ describe('libp2p creation', () => {
}, (err, node) => { }, (err, node) => {
expect(err).to.not.exist() expect(err).to.not.exist()
let sw = node._switch const sw = node._switch
let cm = node.connectionManager const cm = node.connectionManager
let dht = node._dht const dht = node._dht
let pub = node._floodSub const pub = node._floodSub
sinon.spy(sw, 'start') sinon.spy(sw, 'start')
sinon.spy(cm, 'start') sinon.spy(cm, 'start')
@ -113,7 +113,7 @@ describe('libp2p creation', () => {
this.timeout(10e3) this.timeout(10e3)
createLibp2p({ createLibp2p({
modules: { modules: {
transport: [ WS ] transport: [WS]
} }
}, (err, libp2p) => { }, (err, libp2p) => {
expect(err).to.not.exist() expect(err).to.not.exist()
@ -130,7 +130,7 @@ describe('libp2p creation', () => {
createLibp2p({ createLibp2p({
peerInfo, peerInfo,
modules: { modules: {
transport: [ WS ] transport: [WS]
} }
}, (err, libp2p) => { }, (err, libp2p) => {
expect(err).to.not.exist() expect(err).to.not.exist()

View File

@ -99,7 +99,7 @@ describe('libp2p state machine (fsm)', () => {
}) })
it('should error on start with no transports', (done) => { it('should error on start with no transports', (done) => {
let transports = node._modules.transport const transports = node._modules.transport
node._modules.transport = null node._modules.transport = null
node.on('stop', () => { node.on('stop', () => {

View File

@ -72,7 +72,7 @@ describe('peer discovery', () => {
stop: sinon.stub().callsArg(0) stop: sinon.stub().callsArg(0)
} }
const options = { modules: { peerDiscovery: [ mockDiscovery ] } } const options = { modules: { peerDiscovery: [mockDiscovery] } }
createNode(['/ip4/0.0.0.0/tcp/0'], options, (err, node) => { createNode(['/ip4/0.0.0.0/tcp/0'], options, (err, node) => {
expect(err).to.not.exist() expect(err).to.not.exist()
@ -95,7 +95,7 @@ describe('peer discovery', () => {
const MockDiscovery = sinon.stub().returns(mockDiscovery) const MockDiscovery = sinon.stub().returns(mockDiscovery)
const options = { modules: { peerDiscovery: [ MockDiscovery ] } } const options = { modules: { peerDiscovery: [MockDiscovery] } }
createNode(['/ip4/0.0.0.0/tcp/0'], options, (err, node) => { createNode(['/ip4/0.0.0.0/tcp/0'], options, (err, node) => {
expect(err).to.not.exist() expect(err).to.not.exist()
@ -120,7 +120,7 @@ describe('peer discovery', () => {
const enabled = sinon.stub().returns(true) const enabled = sinon.stub().returns(true)
const options = { const options = {
modules: { peerDiscovery: [ mockDiscovery ] }, modules: { peerDiscovery: [mockDiscovery] },
config: { config: {
peerDiscovery: { peerDiscovery: {
mockDiscovery: { mockDiscovery: {
@ -156,7 +156,7 @@ describe('peer discovery', () => {
const disabled = sinon.stub().returns(false) const disabled = sinon.stub().returns(false)
const options = { const options = {
modules: { peerDiscovery: [ mockDiscovery ] }, modules: { peerDiscovery: [mockDiscovery] },
config: { config: {
peerDiscovery: { peerDiscovery: {
mockDiscovery: { mockDiscovery: {
@ -192,7 +192,7 @@ describe('peer discovery', () => {
MockDiscovery.tag = 'mockDiscovery' MockDiscovery.tag = 'mockDiscovery'
const options = { const options = {
modules: { peerDiscovery: [ MockDiscovery ] }, modules: { peerDiscovery: [MockDiscovery] },
config: { config: {
peerDiscovery: { peerDiscovery: {
mockDiscovery: { mockDiscovery: {
@ -228,7 +228,7 @@ describe('peer discovery', () => {
} }
const options = { const options = {
modules: { peerDiscovery: [ mockDiscovery ] }, modules: { peerDiscovery: [mockDiscovery] },
config: { config: {
peerDiscovery: { peerDiscovery: {
mockDiscovery: { enabled: true } mockDiscovery: { enabled: true }
@ -294,7 +294,7 @@ describe('peer discovery', () => {
}) })
it('find peers', function (done) { it('find peers', function (done) {
let expectedPeers = new Set([ const expectedPeers = new Set([
nodeB.peerInfo.id.toB58String(), nodeB.peerInfo.id.toB58String(),
nodeC.peerInfo.id.toB58String() nodeC.peerInfo.id.toB58String()
]) ])
@ -332,7 +332,7 @@ describe('peer discovery', () => {
it('find peers', function (done) { it('find peers', function (done) {
this.timeout(20e3) this.timeout(20e3)
let expectedPeers = new Set([ const expectedPeers = new Set([
nodeB.peerInfo.id.toB58String(), nodeB.peerInfo.id.toB58String(),
nodeC.peerInfo.id.toB58String() nodeC.peerInfo.id.toB58String()
]) ])
@ -374,7 +374,7 @@ describe('peer discovery', () => {
}) })
it('find peers', function (done) { it('find peers', function (done) {
let expectedPeers = new Set([ const expectedPeers = new Set([
nodeB.peerInfo.id.toB58String(), nodeB.peerInfo.id.toB58String(),
nodeC.peerInfo.id.toB58String() nodeC.peerInfo.id.toB58String()
]) ])
@ -421,7 +421,7 @@ describe('peer discovery', () => {
}) })
it('find peers through the dht', function (done) { it('find peers through the dht', function (done) {
let expectedPeers = new Set([ const expectedPeers = new Set([
nodeB.peerInfo.id.toB58String(), nodeB.peerInfo.id.toB58String(),
nodeC.peerInfo.id.toB58String() nodeC.peerInfo.id.toB58String()
]) ])

View File

@ -105,7 +105,7 @@ describe('.peerRouting', () => {
}) })
createNode('/ip4/0.0.0.0/tcp/0', { createNode('/ip4/0.0.0.0/tcp/0', {
modules: { modules: {
peerRouting: [ delegate ] peerRouting: [delegate]
}, },
config: { config: {
dht: { dht: {
@ -211,7 +211,7 @@ describe('.peerRouting', () => {
}) })
createNode('/ip4/0.0.0.0/tcp/0', { createNode('/ip4/0.0.0.0/tcp/0', {
modules: { modules: {
peerRouting: [ delegate ] peerRouting: [delegate]
} }
}, (err, node) => { }, (err, node) => {
expect(err).to.not.exist() expect(err).to.not.exist()

View File

@ -24,7 +24,7 @@ describe('private network', () => {
config = { config = {
peerInfo, peerInfo,
modules: { modules: {
transport: [ WS ], transport: [WS],
dht: DHT dht: DHT
} }
} }
@ -50,14 +50,14 @@ describe('private network', () => {
it('should create a libp2p node with a provided protector', () => { it('should create a libp2p node with a provided protector', () => {
let node let node
let protector = { const protector = {
psk: '123', psk: '123',
tag: '/psk/1.0.0', tag: '/psk/1.0.0',
protect: () => { } protect: () => { }
} }
expect(() => { expect(() => {
let options = defaultsDeep(config, { const options = defaultsDeep(config, {
modules: { modules: {
connProtector: protector connProtector: protector
} }
@ -71,7 +71,7 @@ describe('private network', () => {
it('should throw an error if the protector does not have a protect method', () => { it('should throw an error if the protector does not have a protect method', () => {
expect(() => { expect(() => {
let options = defaultsDeep(config, { const options = defaultsDeep(config, {
modules: { modules: {
connProtector: { } connProtector: { }
} }

View File

@ -36,7 +36,7 @@ describe('stream muxing', () => {
parallel([ parallel([
(cb) => createNode('/ip4/0.0.0.0/tcp/0', { (cb) => createNode('/ip4/0.0.0.0/tcp/0', {
modules: { modules: {
streamMuxer: [ SPDY ] streamMuxer: [SPDY]
} }
}, (err, node) => { }, (err, node) => {
expect(err).to.not.exist() expect(err).to.not.exist()
@ -46,7 +46,7 @@ describe('stream muxing', () => {
}), }),
(cb) => createNode('/ip4/0.0.0.0/tcp/0', { (cb) => createNode('/ip4/0.0.0.0/tcp/0', {
modules: { modules: {
streamMuxer: [ SPDY ] streamMuxer: [SPDY]
} }
}, (err, node) => { }, (err, node) => {
expect(err).to.not.exist() expect(err).to.not.exist()
@ -72,7 +72,7 @@ describe('stream muxing', () => {
parallel([ parallel([
(cb) => createNode('/ip4/0.0.0.0/tcp/0', { (cb) => createNode('/ip4/0.0.0.0/tcp/0', {
modules: { modules: {
streamMuxer: [ Mplex ] streamMuxer: [Mplex]
} }
}, (err, node) => { }, (err, node) => {
expect(err).to.not.exist() expect(err).to.not.exist()
@ -82,7 +82,7 @@ describe('stream muxing', () => {
}), }),
(cb) => createNode('/ip4/0.0.0.0/tcp/0', { (cb) => createNode('/ip4/0.0.0.0/tcp/0', {
modules: { modules: {
streamMuxer: [ Mplex ] streamMuxer: [Mplex]
} }
}, (err, node) => { }, (err, node) => {
expect(err).to.not.exist() expect(err).to.not.exist()
@ -108,7 +108,7 @@ describe('stream muxing', () => {
parallel([ parallel([
(cb) => createNode('/ip4/0.0.0.0/tcp/0', { (cb) => createNode('/ip4/0.0.0.0/tcp/0', {
modules: { modules: {
streamMuxer: [ pMplex ] streamMuxer: [pMplex]
} }
}, (err, node) => { }, (err, node) => {
expect(err).to.not.exist() expect(err).to.not.exist()
@ -118,7 +118,7 @@ describe('stream muxing', () => {
}), }),
(cb) => createNode('/ip4/0.0.0.0/tcp/0', { (cb) => createNode('/ip4/0.0.0.0/tcp/0', {
modules: { modules: {
streamMuxer: [ pMplex ] streamMuxer: [pMplex]
} }
}, (err, node) => { }, (err, node) => {
expect(err).to.not.exist() expect(err).to.not.exist()
@ -146,7 +146,7 @@ describe('stream muxing', () => {
parallel([ parallel([
(cb) => createNode('/ip4/0.0.0.0/tcp/0', { (cb) => createNode('/ip4/0.0.0.0/tcp/0', {
modules: { modules: {
streamMuxer: [ Mplex ] streamMuxer: [Mplex]
} }
}, (err, node) => { }, (err, node) => {
expect(err).to.not.exist() expect(err).to.not.exist()
@ -156,7 +156,7 @@ describe('stream muxing', () => {
}), }),
(cb) => createNode('/ip4/0.0.0.0/tcp/0', { (cb) => createNode('/ip4/0.0.0.0/tcp/0', {
modules: { modules: {
streamMuxer: [ SPDY, Mplex ] streamMuxer: [SPDY, Mplex]
} }
}, (err, node) => { }, (err, node) => {
expect(err).to.not.exist() expect(err).to.not.exist()
@ -184,7 +184,7 @@ describe('stream muxing', () => {
parallel([ parallel([
(cb) => createNode('/ip4/0.0.0.0/tcp/0', { (cb) => createNode('/ip4/0.0.0.0/tcp/0', {
modules: { modules: {
streamMuxer: [ Mplex ] streamMuxer: [Mplex]
} }
}, (err, node) => { }, (err, node) => {
expect(err).to.not.exist() expect(err).to.not.exist()
@ -194,7 +194,7 @@ describe('stream muxing', () => {
}), }),
(cb) => createNode('/ip4/0.0.0.0/tcp/0', { (cb) => createNode('/ip4/0.0.0.0/tcp/0', {
modules: { modules: {
streamMuxer: [ pMplex ] streamMuxer: [pMplex]
} }
}, (err, node) => { }, (err, node) => {
expect(err).to.not.exist() expect(err).to.not.exist()
@ -222,7 +222,7 @@ describe('stream muxing', () => {
parallel([ parallel([
(cb) => createNode('/ip4/0.0.0.0/tcp/0', { (cb) => createNode('/ip4/0.0.0.0/tcp/0', {
modules: { modules: {
streamMuxer: [ SPDY, Mplex ] streamMuxer: [SPDY, Mplex]
} }
}, (err, node) => { }, (err, node) => {
expect(err).to.not.exist() expect(err).to.not.exist()
@ -232,7 +232,7 @@ describe('stream muxing', () => {
}), }),
(cb) => createNode('/ip4/0.0.0.0/tcp/0', { (cb) => createNode('/ip4/0.0.0.0/tcp/0', {
modules: { modules: {
streamMuxer: [ Mplex, SPDY ] streamMuxer: [Mplex, SPDY]
} }
}, (err, node) => { }, (err, node) => {
expect(err).to.not.exist() expect(err).to.not.exist()
@ -260,7 +260,7 @@ describe('stream muxing', () => {
parallel([ parallel([
(cb) => createNode('/ip4/0.0.0.0/tcp/0', { (cb) => createNode('/ip4/0.0.0.0/tcp/0', {
modules: { modules: {
streamMuxer: [ SPDY, pMplex ] streamMuxer: [SPDY, pMplex]
} }
}, (err, node) => { }, (err, node) => {
expect(err).to.not.exist() expect(err).to.not.exist()
@ -270,7 +270,7 @@ describe('stream muxing', () => {
}), }),
(cb) => createNode('/ip4/0.0.0.0/tcp/0', { (cb) => createNode('/ip4/0.0.0.0/tcp/0', {
modules: { modules: {
streamMuxer: [ pMplex, SPDY ] streamMuxer: [pMplex, SPDY]
} }
}, (err, node) => { }, (err, node) => {
expect(err).to.not.exist() expect(err).to.not.exist()
@ -298,7 +298,7 @@ describe('stream muxing', () => {
parallel([ parallel([
(cb) => createNode('/ip4/0.0.0.0/tcp/0', { (cb) => createNode('/ip4/0.0.0.0/tcp/0', {
modules: { modules: {
streamMuxer: [ SPDY ] streamMuxer: [SPDY]
} }
}, (err, node) => { }, (err, node) => {
expect(err).to.not.exist() expect(err).to.not.exist()
@ -308,7 +308,7 @@ describe('stream muxing', () => {
}), }),
(cb) => createNode('/ip4/0.0.0.0/tcp/0', { (cb) => createNode('/ip4/0.0.0.0/tcp/0', {
modules: { modules: {
streamMuxer: [ Mplex ] streamMuxer: [Mplex]
} }
}, (err, node) => { }, (err, node) => {
expect(err).to.not.exist() expect(err).to.not.exist()

View File

@ -55,7 +55,7 @@ describe('transports', () => {
const b = new Node({ const b = new Node({
peerInfo: peerInfo, peerInfo: peerInfo,
modules: { modules: {
streamMuxer: [ Mplex ] streamMuxer: [Mplex]
} }
}) })
expect(b._modules.streamMuxer).to.eql([require('pull-mplex')]) expect(b._modules.streamMuxer).to.eql([require('pull-mplex')])