2021-08-13 10:21:50 -04:00
|
|
|
'use strict'
|
|
|
|
/* eslint-env mocha */
|
|
|
|
|
|
|
|
const { expect } = require('aegir/utils/chai')
|
|
|
|
const mergeOptions = require('merge-options')
|
|
|
|
|
|
|
|
const { create } = require('../../src')
|
|
|
|
const { baseOptions } = require('./utils')
|
|
|
|
|
|
|
|
describe('Protocol prefix is configurable', () => {
|
|
|
|
let libp2p
|
|
|
|
|
2022-01-20 12:03:35 +00:00
|
|
|
afterEach(async () => {
|
|
|
|
libp2p && await libp2p.stop()
|
|
|
|
})
|
|
|
|
|
2021-08-13 10:21:50 -04:00
|
|
|
it('protocolPrefix is provided', async () => {
|
|
|
|
const testProtocol = 'test-protocol'
|
|
|
|
libp2p = await create(mergeOptions(baseOptions, {
|
|
|
|
config: {
|
|
|
|
protocolPrefix: testProtocol
|
|
|
|
}
|
|
|
|
}))
|
2022-01-20 12:03:35 +00:00
|
|
|
await libp2p.start()
|
2021-08-13 10:21:50 -04:00
|
|
|
|
2022-01-20 12:03:35 +00:00
|
|
|
const protocols = await libp2p.peerStore.protoBook.get(libp2p.peerId)
|
|
|
|
expect(protocols).to.include.members([
|
2021-08-13 10:21:50 -04:00
|
|
|
'/libp2p/circuit/relay/0.1.0',
|
|
|
|
`/${testProtocol}/id/1.0.0`,
|
|
|
|
`/${testProtocol}/id/push/1.0.0`,
|
|
|
|
`/${testProtocol}/ping/1.0.0`
|
2022-01-20 12:03:35 +00:00
|
|
|
])
|
2021-08-13 10:21:50 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('protocolPrefix is not provided', async () => {
|
|
|
|
libp2p = await create(baseOptions)
|
2022-01-20 12:03:35 +00:00
|
|
|
await libp2p.start()
|
2021-08-13 10:21:50 -04:00
|
|
|
|
2022-01-20 12:03:35 +00:00
|
|
|
const protocols = await libp2p.peerStore.protoBook.get(libp2p.peerId)
|
|
|
|
expect(protocols).to.include.members([
|
2021-08-13 10:21:50 -04:00
|
|
|
'/libp2p/circuit/relay/0.1.0',
|
|
|
|
'/ipfs/id/1.0.0',
|
|
|
|
'/ipfs/id/push/1.0.0',
|
|
|
|
'/ipfs/ping/1.0.0'
|
2022-01-20 12:03:35 +00:00
|
|
|
])
|
2021-08-13 10:21:50 -04:00
|
|
|
})
|
|
|
|
})
|