|
| 1 | +/* eslint-env mocha */ |
| 2 | +'use strict' |
| 3 | + |
| 4 | +const chai = require('chai') |
| 5 | +chai.use(require('dirty-chai')) |
| 6 | +const expect = chai.expect |
| 7 | +const series = require('async/series') |
| 8 | +const createNode = require('./utils/create-node') |
| 9 | +const sinon = require('sinon') |
| 10 | + |
| 11 | +describe('libp2p creation', () => { |
| 12 | + it('should be able to start and stop successfully', (done) => { |
| 13 | + createNode([], { |
| 14 | + config: { |
| 15 | + EXPERIMENTAL: { |
| 16 | + dht: true, |
| 17 | + pubsub: true |
| 18 | + } |
| 19 | + } |
| 20 | + }, (err, node) => { |
| 21 | + expect(err).to.not.exist() |
| 22 | + |
| 23 | + let sw = node._switch |
| 24 | + let cm = node.connectionManager |
| 25 | + let dht = node._dht |
| 26 | + let pub = node._floodSub |
| 27 | + |
| 28 | + sinon.spy(sw, 'start') |
| 29 | + sinon.spy(cm, 'start') |
| 30 | + sinon.spy(dht, 'start') |
| 31 | + sinon.spy(pub, 'start') |
| 32 | + sinon.spy(sw, 'stop') |
| 33 | + sinon.spy(cm, 'stop') |
| 34 | + sinon.spy(dht, 'stop') |
| 35 | + sinon.spy(pub, 'stop') |
| 36 | + sinon.spy(node, 'emit') |
| 37 | + |
| 38 | + series([ |
| 39 | + (cb) => node.start(cb), |
| 40 | + (cb) => { |
| 41 | + expect(sw.start.calledOnce).to.equal(true) |
| 42 | + expect(cm.start.calledOnce).to.equal(true) |
| 43 | + expect(dht.start.calledOnce).to.equal(true) |
| 44 | + expect(pub.start.calledOnce).to.equal(true) |
| 45 | + expect(node.emit.calledWith('start')).to.equal(true) |
| 46 | + |
| 47 | + cb() |
| 48 | + }, |
| 49 | + (cb) => node.stop(cb) |
| 50 | + ], (err) => { |
| 51 | + expect(err).to.not.exist() |
| 52 | + |
| 53 | + expect(sw.stop.calledOnce).to.equal(true) |
| 54 | + expect(cm.stop.calledOnce).to.equal(true) |
| 55 | + expect(dht.stop.calledOnce).to.equal(true) |
| 56 | + expect(pub.stop.calledOnce).to.equal(true) |
| 57 | + expect(node.emit.calledWith('stop')).to.equal(true) |
| 58 | + |
| 59 | + done() |
| 60 | + }) |
| 61 | + }) |
| 62 | + }) |
| 63 | + |
| 64 | + it('should not create disabled modules', (done) => { |
| 65 | + createNode([], { |
| 66 | + config: { |
| 67 | + EXPERIMENTAL: { |
| 68 | + dht: false, |
| 69 | + pubsub: false |
| 70 | + } |
| 71 | + } |
| 72 | + }, (err, node) => { |
| 73 | + expect(err).to.not.exist() |
| 74 | + expect(node._dht).to.not.exist() |
| 75 | + expect(node._floodSub).to.not.exist() |
| 76 | + done() |
| 77 | + }) |
| 78 | + }) |
| 79 | +}) |
0 commit comments