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

Commit

Permalink
chore: add tests for peer-discovery interface
Browse files Browse the repository at this point in the history
  • Loading branch information
vasco-santos committed Apr 16, 2020
1 parent 8a99f1b commit b782934
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"devDependencies": {
"aegir": "^21.2.0",
"chai": "^4.2.0",
"dirty-chai": "^2.0.1"
"dirty-chai": "^2.0.1",
"libp2p-interfaces": "libp2p/js-interfaces#v0.3.x"
},
"dependencies": {
"debug": "^4.1.1",
Expand Down
10 changes: 6 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ class Bootstrap extends EventEmitter {
* Emit each address in the list as a PeerInfo.
*/
_discoverBootstrapPeers () {
if (!this._timer) {
return
}

this._list.forEach((candidate) => {
if (!mafmt.P2P.matches(candidate)) {
return log.error('Invalid multiaddr')
Expand All @@ -73,10 +77,8 @@ class Bootstrap extends EventEmitter {
* Stop emitting events.
*/
stop () {
if (this._timer) {
clearInterval(this._timer)
this._timer = null
}
clearInterval(this._timer)
this._timer = null
}
}

Expand Down
21 changes: 21 additions & 0 deletions test/compliance.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict'

/* eslint-env mocha */

const tests = require('libp2p-interfaces/src/peer-discovery/tests')

const Bootstrap = require('../src')
const peerList = require('./default-peers')

describe('compliance tests', () => {
tests({
setup () {
const bootstrap = new Bootstrap({
list: peerList,
interval: 2000
})

return bootstrap
}
})
})

0 comments on commit b782934

Please sign in to comment.