revert: reapply "fix: throw if no conn encryption module provided (#665)"

This reapplies commit b621fbdfdc.
This commit is contained in:
Vasco Santos
2020-06-15 12:51:19 +02:00
committed by Jacob Heun
parent 0e3cc5866b
commit 689f90a698
8 changed files with 91 additions and 22 deletions

View File

@ -0,0 +1,57 @@
'use strict'
/* eslint-env mocha */
const chai = require('chai')
chai.use(require('dirty-chai'))
chai.use(require('chai-as-promised'))
const { expect } = chai
const Transport = require('libp2p-websockets')
const { NOISE: Crypto } = require('libp2p-noise')
const Libp2p = require('../../src')
const { codes: ErrorCodes } = require('../../src/errors')
const { createPeerId } = require('../utils/creators/peer')
describe('Connection encryption configuration', () => {
let peerId
before(async () => {
[peerId] = await createPeerId()
})
it('is required', async () => {
const config = {
peerId,
modules: {
transport: [Transport]
}
}
await expect(Libp2p.create(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,
modules: {
transport: [Transport],
connEncryption: []
}
}
await expect(Libp2p.create(config)).to.eventually.be.rejected()
.and.to.have.property('code', ErrorCodes.CONN_ENCRYPTION_REQUIRED)
})
it('can be created', async () => {
const config = {
peerId,
modules: {
transport: [Transport],
connEncryption: [Crypto]
}
}
await Libp2p.create(config)
})
})