Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Jul 30, 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
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
},
"devDependencies": {
"@nodeutils/defaults-deep": "^1.1.0",
"aegir": "^19.0.3",
"aegir": "^20.0.0",
"chai": "^4.2.0",
"chai-checkmark": "^1.0.1",
"cids": "^0.7.1",
Expand All @@ -74,7 +74,7 @@
"libp2p-circuit": "^0.3.7",
"libp2p-delegated-content-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-mplex": "^0.8.4",
"libp2p-secio": "^0.11.1",
Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class Libp2p extends EventEmitter {

// Attach stream multiplexers
if (this._modules.streamMuxer) {
let muxers = this._modules.streamMuxer
const muxers = this._modules.streamMuxer
muxers.forEach((muxer) => this._switch.connection.addStreamMuxer(muxer))

// If muxer exists
Expand Down Expand Up @@ -99,7 +99,7 @@ class Libp2p extends EventEmitter {

// Attach crypto channels
if (this._modules.connEncryption) {
let cryptos = this._modules.connEncryption
const cryptos = this._modules.connEncryption
cryptos.forEach((crypto) => {
this._switch.connection.crypto(crypto.tag, crypto.encrypt)
})
Expand Down
2 changes: 1 addition & 1 deletion test/circuit-relay.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const tryEcho = require('./utils/try-echo')
const echo = require('./utils/echo')

describe('circuit relay', () => {
let handlerSpies = []
const handlerSpies = []
let relayNode1
let relayNode2
let nodeWS1
Expand Down
38 changes: 19 additions & 19 deletions test/config.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('configuration', () => {
expect(() => {
validateConfig({
modules: {
transport: [ WS ]
transport: [WS]
}
})
}).to.throw()
Expand All @@ -52,7 +52,7 @@ describe('configuration', () => {
validateConfig({
peerInfo,
modules: {
transport: [ ]
transport: []
}
})
}).to.throw('ERROR_EMPTY')
Expand All @@ -62,8 +62,8 @@ describe('configuration', () => {
const options = {
peerInfo,
modules: {
transport: [ WS ],
peerDiscovery: [ Bootstrap ],
transport: [WS],
peerDiscovery: [Bootstrap],
dht: DHT
}
}
Expand All @@ -74,8 +74,8 @@ describe('configuration', () => {
minPeers: 25
},
modules: {
transport: [ WS ],
peerDiscovery: [ Bootstrap ],
transport: [WS],
peerDiscovery: [Bootstrap],
dht: DHT
},
config: {
Expand Down Expand Up @@ -112,8 +112,8 @@ describe('configuration', () => {
const options = {
peerInfo,
modules: {
transport: [ WS ],
peerDiscovery: [ Bootstrap ],
transport: [WS],
peerDiscovery: [Bootstrap],
dht: DHT
},
config: {
Expand All @@ -132,8 +132,8 @@ describe('configuration', () => {
minPeers: 25
},
modules: {
transport: [ WS ],
peerDiscovery: [ Bootstrap ],
transport: [WS],
peerDiscovery: [Bootstrap],
dht: DHT
},
config: {
Expand Down Expand Up @@ -181,8 +181,8 @@ describe('configuration', () => {
dialTimeout: 30e3
},
modules: {
transport: [ WS ],
peerDiscovery: [ ]
transport: [WS],
peerDiscovery: []
}
}

Expand All @@ -204,10 +204,10 @@ describe('configuration', () => {
const options = {
peerInfo,
modules: {
transport: [ WS ],
peerDiscovery: [ Bootstrap ],
peerRouting: [ peerRouter ],
contentRouting: [ contentRouter ],
transport: [WS],
peerDiscovery: [Bootstrap],
peerRouting: [peerRouter],
contentRouting: [contentRouter],
dht: DHT
},
config: {
Expand All @@ -221,16 +221,16 @@ describe('configuration', () => {
}

expect(validateConfig(options).modules).to.deep.include({
peerRouting: [ peerRouter ],
contentRouting: [ contentRouter ]
peerRouting: [peerRouter],
contentRouting: [contentRouter]
})
})

it('should not allow for dht to be enabled without it being provided', () => {
const options = {
peerInfo,
modules: {
transport: [ WS ]
transport: [WS]
},
config: {
dht: {
Expand Down
9 changes: 5 additions & 4 deletions test/content-routing.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,9 @@ describe('.contentRouting', () => {
const cid = new CID('QmTp9VkYvnHyrqKQuFPiuZkiX9gPcqj6x5LJ1rmWuSnnnn')

nodeE.contentRouting.findProviders(cid, { maxTimeout: 5000 }, (err, providers) => {
expect(err).to.not.exist()
expect(providers).to.have.length(0)
expect(err).to.exist()
expect(err.code).to.eql('ERR_NOT_FOUND')
expect(providers).to.not.exist()
done()
})
})
Expand Down Expand Up @@ -150,7 +151,7 @@ describe('.contentRouting', () => {
nodeA = new Node({
peerInfo,
modules: {
contentRouting: [ delegate ]
contentRouting: [delegate]
},
config: {
dht: {
Expand Down Expand Up @@ -300,7 +301,7 @@ describe('.contentRouting', () => {
nodeA = new Node({
peerInfo,
modules: {
contentRouting: [ delegate ]
contentRouting: [delegate]
},
config: {
relay: {
Expand Down
12 changes: 6 additions & 6 deletions test/create.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ describe('libp2p creation', () => {
}, (err, node) => {
expect(err).to.not.exist()

let sw = node._switch
let cm = node.connectionManager
let dht = node._dht
let pub = node._floodSub
const sw = node._switch
const cm = node.connectionManager
const dht = node._dht
const pub = node._floodSub

sinon.spy(sw, 'start')
sinon.spy(cm, 'start')
Expand Down Expand Up @@ -113,7 +113,7 @@ describe('libp2p creation', () => {
this.timeout(10e3)
createLibp2p({
modules: {
transport: [ WS ]
transport: [WS]
}
}, (err, libp2p) => {
expect(err).to.not.exist()
Expand All @@ -130,7 +130,7 @@ describe('libp2p creation', () => {
createLibp2p({
peerInfo,
modules: {
transport: [ WS ]
transport: [WS]
}
}, (err, libp2p) => {
expect(err).to.not.exist()
Expand Down
2 changes: 1 addition & 1 deletion test/fsm.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ describe('libp2p state machine (fsm)', () => {
})

it('should error on start with no transports', (done) => {
let transports = node._modules.transport
const transports = node._modules.transport
node._modules.transport = null

node.on('stop', () => {
Expand Down
20 changes: 10 additions & 10 deletions test/peer-discovery.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ describe('peer discovery', () => {
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) => {
expect(err).to.not.exist()
Expand All @@ -95,7 +95,7 @@ describe('peer discovery', () => {

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) => {
expect(err).to.not.exist()
Expand All @@ -120,7 +120,7 @@ describe('peer discovery', () => {
const enabled = sinon.stub().returns(true)

const options = {
modules: { peerDiscovery: [ mockDiscovery ] },
modules: { peerDiscovery: [mockDiscovery] },
config: {
peerDiscovery: {
mockDiscovery: {
Expand Down Expand Up @@ -156,7 +156,7 @@ describe('peer discovery', () => {
const disabled = sinon.stub().returns(false)

const options = {
modules: { peerDiscovery: [ mockDiscovery ] },
modules: { peerDiscovery: [mockDiscovery] },
config: {
peerDiscovery: {
mockDiscovery: {
Expand Down Expand Up @@ -192,7 +192,7 @@ describe('peer discovery', () => {
MockDiscovery.tag = 'mockDiscovery'

const options = {
modules: { peerDiscovery: [ MockDiscovery ] },
modules: { peerDiscovery: [MockDiscovery] },
config: {
peerDiscovery: {
mockDiscovery: {
Expand Down Expand Up @@ -228,7 +228,7 @@ describe('peer discovery', () => {
}

const options = {
modules: { peerDiscovery: [ mockDiscovery ] },
modules: { peerDiscovery: [mockDiscovery] },
config: {
peerDiscovery: {
mockDiscovery: { enabled: true }
Expand Down Expand Up @@ -294,7 +294,7 @@ describe('peer discovery', () => {
})

it('find peers', function (done) {
let expectedPeers = new Set([
const expectedPeers = new Set([
nodeB.peerInfo.id.toB58String(),
nodeC.peerInfo.id.toB58String()
])
Expand Down Expand Up @@ -332,7 +332,7 @@ describe('peer discovery', () => {

it('find peers', function (done) {
this.timeout(20e3)
let expectedPeers = new Set([
const expectedPeers = new Set([
nodeB.peerInfo.id.toB58String(),
nodeC.peerInfo.id.toB58String()
])
Expand Down Expand Up @@ -374,7 +374,7 @@ describe('peer discovery', () => {
})

it('find peers', function (done) {
let expectedPeers = new Set([
const expectedPeers = new Set([
nodeB.peerInfo.id.toB58String(),
nodeC.peerInfo.id.toB58String()
])
Expand Down Expand Up @@ -421,7 +421,7 @@ describe('peer discovery', () => {
})

it('find peers through the dht', function (done) {
let expectedPeers = new Set([
const expectedPeers = new Set([
nodeB.peerInfo.id.toB58String(),
nodeC.peerInfo.id.toB58String()
])
Expand Down
4 changes: 2 additions & 2 deletions test/peer-routing.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ describe('.peerRouting', () => {
})
createNode('/ip4/0.0.0.0/tcp/0', {
modules: {
peerRouting: [ delegate ]
peerRouting: [delegate]
},
config: {
dht: {
Expand Down Expand Up @@ -211,7 +211,7 @@ describe('.peerRouting', () => {
})
createNode('/ip4/0.0.0.0/tcp/0', {
modules: {
peerRouting: [ delegate ]
peerRouting: [delegate]
}
}, (err, node) => {
expect(err).to.not.exist()
Expand Down
8 changes: 4 additions & 4 deletions test/pnet.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('private network', () => {
config = {
peerInfo,
modules: {
transport: [ WS ],
transport: [WS],
dht: DHT
}
}
Expand All @@ -50,14 +50,14 @@ describe('private network', () => {

it('should create a libp2p node with a provided protector', () => {
let node
let protector = {
const protector = {
psk: '123',
tag: '/psk/1.0.0',
protect: () => { }
}

expect(() => {
let options = defaultsDeep(config, {
const options = defaultsDeep(config, {
modules: {
connProtector: protector
}
Expand All @@ -71,7 +71,7 @@ describe('private network', () => {

it('should throw an error if the protector does not have a protect method', () => {
expect(() => {
let options = defaultsDeep(config, {
const options = defaultsDeep(config, {
modules: {
connProtector: { }
}
Expand Down
Loading