2019-11-15 16:48:32 +01:00
|
|
|
'use strict'
|
|
|
|
/* eslint-env mocha */
|
|
|
|
|
2020-10-15 15:31:33 +01:00
|
|
|
const { expect } = require('aegir/utils/chai')
|
2019-11-15 16:48:32 +01:00
|
|
|
const mergeOptions = require('merge-options')
|
2021-04-15 09:40:02 +02:00
|
|
|
const { Multiaddr } = require('multiaddr')
|
2019-11-15 16:48:32 +01:00
|
|
|
|
|
|
|
const { create } = require('../../src')
|
|
|
|
const { baseOptions, subsystemOptions } = require('./utils')
|
|
|
|
const peerUtils = require('../utils/creators/peer')
|
|
|
|
|
2021-04-15 09:40:02 +02:00
|
|
|
const listenAddr = new Multiaddr('/ip4/127.0.0.1/tcp/0')
|
2019-11-15 16:48:32 +01:00
|
|
|
|
|
|
|
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 () => {
|
2020-04-14 14:05:30 +02:00
|
|
|
const [peerId] = await peerUtils.createPeerId()
|
2019-11-15 16:48:32 +01:00
|
|
|
|
|
|
|
const customOptions = mergeOptions(subsystemOptions, {
|
2020-04-14 14:05:30 +02:00
|
|
|
peerId,
|
|
|
|
addresses: {
|
|
|
|
listen: [listenAddr]
|
|
|
|
}
|
2019-11-15 16:48:32 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
libp2p = await create(customOptions)
|
2020-08-25 16:48:04 +02:00
|
|
|
expect(libp2p.pubsub.started).to.equal(false)
|
2019-11-15 16:48:32 +01:00
|
|
|
|
|
|
|
await libp2p.start()
|
2020-08-25 16:48:04 +02:00
|
|
|
expect(libp2p.pubsub.started).to.equal(true)
|
2019-11-15 16:48:32 +01:00
|
|
|
|
|
|
|
await libp2p.stop()
|
2020-08-25 16:48:04 +02:00
|
|
|
expect(libp2p.pubsub.started).to.equal(false)
|
2019-11-15 16:48:32 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should not start if disabled once libp2p starts', async () => {
|
2020-04-14 14:05:30 +02:00
|
|
|
const [peerId] = await peerUtils.createPeerId()
|
2019-11-15 16:48:32 +01:00
|
|
|
|
|
|
|
const customOptions = mergeOptions(subsystemOptions, {
|
2020-04-14 14:05:30 +02:00
|
|
|
peerId,
|
|
|
|
addresses: {
|
|
|
|
listen: [listenAddr]
|
|
|
|
},
|
2019-11-15 16:48:32 +01:00
|
|
|
config: {
|
|
|
|
pubsub: {
|
|
|
|
enabled: false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
libp2p = await create(customOptions)
|
2020-08-25 16:48:04 +02:00
|
|
|
expect(libp2p.pubsub.started).to.equal(false)
|
2019-11-15 16:48:32 +01:00
|
|
|
|
|
|
|
await libp2p.start()
|
2020-08-25 16:48:04 +02:00
|
|
|
expect(libp2p.pubsub.started).to.equal(false)
|
2019-11-15 16:48:32 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should allow a manual start', async () => {
|
2020-04-14 14:05:30 +02:00
|
|
|
const [peerId] = await peerUtils.createPeerId()
|
2019-11-15 16:48:32 +01:00
|
|
|
|
|
|
|
const customOptions = mergeOptions(subsystemOptions, {
|
2020-04-14 14:05:30 +02:00
|
|
|
peerId,
|
|
|
|
addresses: {
|
|
|
|
listen: [listenAddr]
|
|
|
|
},
|
2019-11-15 16:48:32 +01:00
|
|
|
config: {
|
|
|
|
pubsub: {
|
|
|
|
enabled: false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
libp2p = await create(customOptions)
|
|
|
|
await libp2p.start()
|
2020-08-25 16:48:04 +02:00
|
|
|
expect(libp2p.pubsub.started).to.equal(false)
|
2019-11-15 16:48:32 +01:00
|
|
|
|
|
|
|
await libp2p.pubsub.start()
|
2020-08-25 16:48:04 +02:00
|
|
|
expect(libp2p.pubsub.started).to.equal(true)
|
2019-11-15 16:48:32 +01:00
|
|
|
})
|
|
|
|
})
|