From 074e7e323bd3f6b784f8359b80aaced331d92d77 Mon Sep 17 00:00:00 2001 From: David Dias Date: Mon, 9 May 2016 07:56:06 +0100 Subject: [PATCH] make sure it does not try to dial on empty proto and write tests for it --- src/index.js | 3 +++ test/09-swarm-with-muxing.node.js | 26 +++++++++++++++++++++----- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/index.js b/src/index.js index 0f0bb3d..19662d8 100644 --- a/src/index.js +++ b/src/index.js @@ -246,6 +246,9 @@ function Swarm (peerInfo) { gotWarmedUpConn(conn) } } else { + if (!protocol) { + return callback() + } gotMuxer(this.muxedConns[b58Id].muxer) } diff --git a/test/09-swarm-with-muxing.node.js b/test/09-swarm-with-muxing.node.js index f904ea8..4af0c6b 100644 --- a/test/09-swarm-with-muxing.node.js +++ b/test/09-swarm-with-muxing.node.js @@ -125,11 +125,7 @@ describe('high level API - with everything mixed all together!', function () { it.skip('add multiplex', (done) => {}) - it('dial from tcp to tcp+ws', (done) => { - swarmB.handle('/anona/1.0.0', (conn) => { - conn.pipe(conn) - }) - + it('warm up from A to B on tcp to tcp+ws', (done) => { swarmB.once('peer-mux-established', (peerInfo) => { expect(peerInfo.id.toB58String()).to.equal(peerA.id.toB58String()) }) @@ -138,6 +134,26 @@ describe('high level API - with everything mixed all together!', function () { expect(peerInfo.id.toB58String()).to.equal(peerB.id.toB58String()) }) + swarmA.dial(peerB, (err) => { + expect(err).to.not.exist + expect(Object.keys(swarmA.muxedConns).length).to.equal(1) + done() + }) + }) + + it('warm up a warmed up, from B to A', (done) => { + swarmB.dial(peerA, (err) => { + expect(err).to.not.exist + expect(Object.keys(swarmA.muxedConns).length).to.equal(1) + done() + }) + }) + + it('dial from tcp to tcp+ws, on protocol', (done) => { + swarmB.handle('/anona/1.0.0', (conn) => { + conn.pipe(conn) + }) + swarmA.dial(peerB, '/anona/1.0.0', (err, conn) => { expect(err).to.not.exist expect(Object.keys(swarmA.muxedConns).length).to.equal(1)