js-libp2p/test/core/encryption.spec.ts
Alex Potsides d4dd664071
feat!: update libp2p interfaces (#1252)
BREAKING CHANGE: uses new single-issue libp2p interface modules
2022-06-15 18:30:39 +01:00

55 lines
1.4 KiB
TypeScript

/* eslint-env mocha */
import { expect } from 'aegir/chai'
import { WebSockets } from '@libp2p/websockets'
import { NOISE } from '@chainsafe/libp2p-noise'
import { createLibp2p, Libp2pOptions } from '../../src/index.js'
import { codes as ErrorCodes } from '../../src/errors.js'
import { createPeerId } from '../utils/creators/peer.js'
import type { PeerId } from '@libp2p/interface-peer-id'
describe('Connection encryption configuration', () => {
let peerId: PeerId
before(async () => {
peerId = await createPeerId()
})
it('is required', async () => {
const config = {
peerId,
transports: [
new WebSockets()
]
}
await expect(createLibp2p(config)).to.eventually.be.rejected()
.and.to.have.property('code', ErrorCodes.CONN_ENCRYPTION_REQUIRED)
})
it('is required and needs at least one module', async () => {
const config = {
peerId,
transports: [
new WebSockets()
],
connectionEncryption: []
}
await expect(createLibp2p(config)).to.eventually.be.rejected()
.and.to.have.property('code', ErrorCodes.CONN_ENCRYPTION_REQUIRED)
})
it('can be created', async () => {
const config: Libp2pOptions = {
peerId,
transports: [
new WebSockets()
],
connectionEncryption: [
NOISE
]
}
await createLibp2p(config)
})
})