mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-05-03 06:22:14 +00:00
Do not allow undefined peerInfo
# What The code assumes that `peerInfo` exists, the API doesn't. # How to test ```js swarm = new Swarm() swarm.addTransport('tcp', tcp, { multiaddr: mh }, {}, {port: 8095}) ``` This shouldn't explode because of `self.peerInfo.multiaddrs`.
This commit is contained in:
parent
cd53344441
commit
0514b0034b
@ -1,4 +1,3 @@
|
|||||||
var Swarm = require('./swarm')
|
var Swarm = require('./swarm')
|
||||||
|
|
||||||
exports = module.exports = Swarm
|
exports = module.exports = Swarm
|
||||||
exports.singleton = new Swarm()
|
|
||||||
|
@ -11,6 +11,10 @@ function Swarm (peerInfo) {
|
|||||||
throw new Error('Swarm must be called with new')
|
throw new Error('Swarm must be called with new')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!peerInfo) {
|
||||||
|
throw new Error('You must provide a value for `peerInfo`')
|
||||||
|
}
|
||||||
|
|
||||||
self.peerInfo = peerInfo
|
self.peerInfo = peerInfo
|
||||||
|
|
||||||
// peerIdB58: { conn: <conn> }
|
// peerIdB58: { conn: <conn> }
|
||||||
|
@ -24,6 +24,16 @@ process.on('uncaughtException', function (err) {
|
|||||||
console.log('Caught exception: ' + err)
|
console.log('Caught exception: ' + err)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
experiment('Without a peer', function () {
|
||||||
|
test('it throws an exception', function (done) {
|
||||||
|
expect(function () {
|
||||||
|
var sw = new Swarm()
|
||||||
|
sw.close()
|
||||||
|
}).to.throw(Error)
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
experiment('Without a Stream Muxer', function () {
|
experiment('Without a Stream Muxer', function () {
|
||||||
experiment('tcp', function () {
|
experiment('tcp', function () {
|
||||||
test('add the transport', function (done) {
|
test('add the transport', function (done) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user