Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

Commit

Permalink
fix: validate list (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
vasco-santos committed Nov 28, 2019
1 parent 83201ca commit 5041f28
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
},
"devDependencies": {
"aegir": "^20.4.1",
"chai": "^4.2.0"
"chai": "^4.2.0",
"dirty-chai": "^2.0.1"
},
"dependencies": {
"debug": "^4.1.1",
Expand Down
9 changes: 6 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
'use strict'

const assert = require('assert')
const PeerId = require('peer-id')
const PeerInfo = require('peer-info')
const multiaddr = require('multiaddr')
const mafmt = require('mafmt')
const EventEmitter = require('events').EventEmitter
const { EventEmitter } = require('events')
const debug = require('debug')

const log = debug('libp2p:bootstrap')
Expand All @@ -19,11 +20,13 @@ class Bootstrap extends EventEmitter {
*
* @param {Object} options
* @param {Array<string>} options.list - the list of peer addresses in multi-address format
* @param {number} options.interval - the interval between emitting addresses (in milli-seconds)
* @param {number} [options.interval] - the interval between emitting addresses in milliseconds (default: 10000)
*
*/
constructor (options) {
constructor (options = {}) {
assert(options.list && options.list.length, 'Bootstrap requires a list of peer addresses')
super()

this._list = options.list
this._interval = options.interval || 10000
this._timer = null
Expand Down
17 changes: 15 additions & 2 deletions test/bootstrap.spec.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
/* eslint-env mocha */
'use strict'
/* eslint-env mocha */

const chai = require('chai')
chai.use(require('dirty-chai'))
const { expect } = chai

const Bootstrap = require('../src')
const peerList = require('./default-peers')
const partialValidPeerList = require('./some-invalid-peers')
const { expect } = require('chai')
const mafmt = require('mafmt')

describe('bootstrap', () => {
it('should throw if no peer list is provided', () => {
try {
const b = new Bootstrap() // eslint-disable-line no-unused-vars
} catch (err) {
expect(err).to.exist()
return
}
throw new Error('should throw if no peer list is provided')
})

it('find the other peer', function () {
this.timeout(5 * 1000)
const r = new Bootstrap({
Expand Down

0 comments on commit 5041f28

Please sign in to comment.