mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-06-23 22:11:35 +00:00
feat: discovery modules (#486)
* feat: discovery modules * chore: address review
This commit is contained in:
@ -5,7 +5,11 @@ const chai = require('chai')
|
||||
chai.use(require('dirty-chai'))
|
||||
const { expect } = chai
|
||||
const sinon = require('sinon')
|
||||
|
||||
const defer = require('p-defer')
|
||||
const mergeOptions = require('merge-options')
|
||||
|
||||
const MulticastDNS = require('libp2p-mdns')
|
||||
|
||||
const Libp2p = require('../../src')
|
||||
const baseOptions = require('../utils/base-options.browser')
|
||||
@ -22,6 +26,7 @@ describe('peer discovery', () => {
|
||||
|
||||
afterEach(async () => {
|
||||
libp2p && await libp2p.stop()
|
||||
sinon.reset()
|
||||
})
|
||||
|
||||
it('should dial know peers on startup', async () => {
|
||||
@ -42,4 +47,20 @@ describe('peer discovery', () => {
|
||||
await deferred.promise
|
||||
expect(spy.getCall(0).args).to.eql([remotePeerInfo])
|
||||
})
|
||||
|
||||
it('should ignore self on discovery', async () => {
|
||||
libp2p = new Libp2p(mergeOptions(baseOptions, {
|
||||
peerInfo,
|
||||
modules: {
|
||||
peerDiscovery: [MulticastDNS]
|
||||
}
|
||||
}))
|
||||
|
||||
await libp2p.start()
|
||||
const discoverySpy = sinon.spy()
|
||||
libp2p.on('peer:discovery', discoverySpy)
|
||||
libp2p._discovery[0].emit('peer', libp2p.peerInfo)
|
||||
|
||||
expect(discoverySpy.called).to.eql(false)
|
||||
})
|
||||
})
|
||||
|
Reference in New Issue
Block a user