js-libp2p/test/pubsub/configuration.node.js
Vasco Santos 55c9bfac44 feat: gossipsub 1.1 (#733)
* feat: gossipsub 1.1

BREAKING CHANGE: pubsub implementation is now directly exposed and its API was updated according to the new pubsub interface in js-libp2p-interfaces repo

* chore: use gossipsub branch with src added

* fix: add pubsub handlers adapter

* chore: fix deps

* chore: update pubsub docs and examples

* chore: apply suggestions from code review

Co-authored-by: Jacob Heun <jacobheun@gmail.com>

* chore: use new floodsub

* chore: change validator doc set

Co-authored-by: Jacob Heun <jacobheun@gmail.com>

* chore: add new gossipsub src

Co-authored-by: Jacob Heun <jacobheun@gmail.com>
2020-08-27 15:38:01 +02:00

99 lines
2.3 KiB
JavaScript

'use strict'
/* eslint-env mocha */
const chai = require('chai')
chai.use(require('dirty-chai'))
const { expect } = chai
const mergeOptions = require('merge-options')
const multiaddr = require('multiaddr')
const { create } = require('../../src')
const { baseOptions, subsystemOptions } = require('./utils')
const peerUtils = require('../utils/creators/peer')
const listenAddr = multiaddr('/ip4/127.0.0.1/tcp/0')
describe('Pubsub subsystem is configurable', () => {
let libp2p
afterEach(async () => {
libp2p && await libp2p.stop()
})
it('should not exist if no module is provided', async () => {
libp2p = await create(baseOptions)
expect(libp2p.pubsub).to.not.exist()
})
it('should exist if the module is provided', async () => {
libp2p = await create(subsystemOptions)
expect(libp2p.pubsub).to.exist()
})
it('should start and stop by default once libp2p starts', async () => {
const [peerId] = await peerUtils.createPeerId()
const customOptions = mergeOptions(subsystemOptions, {
peerId,
addresses: {
listen: [listenAddr]
}
})
libp2p = await create(customOptions)
expect(libp2p.pubsub.started).to.equal(false)
await libp2p.start()
expect(libp2p.pubsub.started).to.equal(true)
await libp2p.stop()
expect(libp2p.pubsub.started).to.equal(false)
})
it('should not start if disabled once libp2p starts', async () => {
const [peerId] = await peerUtils.createPeerId()
const customOptions = mergeOptions(subsystemOptions, {
peerId,
addresses: {
listen: [listenAddr]
},
config: {
pubsub: {
enabled: false
}
}
})
libp2p = await create(customOptions)
expect(libp2p.pubsub.started).to.equal(false)
await libp2p.start()
expect(libp2p.pubsub.started).to.equal(false)
})
it('should allow a manual start', async () => {
const [peerId] = await peerUtils.createPeerId()
const customOptions = mergeOptions(subsystemOptions, {
peerId,
addresses: {
listen: [listenAddr]
},
config: {
pubsub: {
enabled: false
}
}
})
libp2p = await create(customOptions)
await libp2p.start()
expect(libp2p.pubsub.started).to.equal(false)
await libp2p.pubsub.start()
expect(libp2p.pubsub.started).to.equal(true)
})
})