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

Commit b782934

Browse files
committed
chore: add tests for peer-discovery interface
1 parent 8a99f1b commit b782934

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
"devDependencies": {
3131
"aegir": "^21.2.0",
3232
"chai": "^4.2.0",
33-
"dirty-chai": "^2.0.1"
33+
"dirty-chai": "^2.0.1",
34+
"libp2p-interfaces": "libp2p/js-interfaces#v0.3.x"
3435
},
3536
"dependencies": {
3637
"debug": "^4.1.1",

src/index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ class Bootstrap extends EventEmitter {
4949
* Emit each address in the list as a PeerInfo.
5050
*/
5151
_discoverBootstrapPeers () {
52+
if (!this._timer) {
53+
return
54+
}
55+
5256
this._list.forEach((candidate) => {
5357
if (!mafmt.P2P.matches(candidate)) {
5458
return log.error('Invalid multiaddr')
@@ -73,10 +77,8 @@ class Bootstrap extends EventEmitter {
7377
* Stop emitting events.
7478
*/
7579
stop () {
76-
if (this._timer) {
77-
clearInterval(this._timer)
78-
this._timer = null
79-
}
80+
clearInterval(this._timer)
81+
this._timer = null
8082
}
8183
}
8284

test/compliance.spec.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'use strict'
2+
3+
/* eslint-env mocha */
4+
5+
const tests = require('libp2p-interfaces/src/peer-discovery/tests')
6+
7+
const Bootstrap = require('../src')
8+
const peerList = require('./default-peers')
9+
10+
describe('compliance tests', () => {
11+
tests({
12+
setup () {
13+
const bootstrap = new Bootstrap({
14+
list: peerList,
15+
interval: 2000
16+
})
17+
18+
return bootstrap
19+
}
20+
})
21+
})

0 commit comments

Comments
 (0)