From 21d8ff5b9e9d6f3a63a14523a7d2254f8faead75 Mon Sep 17 00:00:00 2001 From: David Dias Date: Mon, 3 Apr 2017 15:35:42 -0400 Subject: [PATCH] feat: new libp2p apis --- package.json | 12 ++++++------ test/2-nodes.js | 5 ++--- test/multiple-nodes.js | 15 ++++----------- test/utils.js | 10 +++------- test/utils.spec.js | 18 ++++++------------ 5 files changed, 21 insertions(+), 39 deletions(-) diff --git a/package.json b/package.json index 26aa6115a6..ab537a1f24 100644 --- a/package.json +++ b/package.json @@ -43,18 +43,18 @@ "homepage": "https://github.com/libp2p/js-libp2p-floodsub#readme", "devDependencies": { "aegir": "^11.0.1", - "benchmark": "^2.1.3", + "benchmark": "^2.1.4", "chai": "^3.5.0", "dirty-chai": "^1.2.2", - "libp2p-ipfs-nodejs": "~0.21.0", + "libp2p-ipfs-nodejs": "~0.23.0", "lodash.times": "^4.3.2", - "multiaddr": "^2.2.3", - "peer-id": "~0.8.5", - "peer-info": "~0.8.5", + "multiaddr": "^2.3.0", + "peer-id": "~0.8.7", + "peer-info": "~0.9.2", "pre-commit": "^1.2.2" }, "dependencies": { - "async": "^2.2.0", + "async": "^2.3.0", "debug": "^2.6.3", "length-prefixed-stream": "^1.5.1", "libp2p-crypto": "~0.8.7", diff --git a/test/2-nodes.js b/test/2-nodes.js index 50e95707c0..972a8b7118 100644 --- a/test/2-nodes.js +++ b/test/2-nodes.js @@ -106,6 +106,7 @@ describe('basics between 2 nodes', () => { fsA.once('Z', (msg) => { fsA.once('Z', shouldNotHappen) expect(msg.data.toString()).to.equal('banana') + setTimeout(() => { fsA.removeListener('Z', shouldNotHappen) fsB.removeListener('Z', shouldNotHappen) @@ -137,9 +138,7 @@ describe('basics between 2 nodes', () => { } } - _times(10, () => { - fsB.publish('Z', new Buffer('banana')) - }) + _times(10, () => fsB.publish('Z', new Buffer('banana'))) }) it('Unsubscribe from topic:Z in nodeA', (done) => { diff --git a/test/multiple-nodes.js b/test/multiple-nodes.js index 3f56a68e9d..f0c6416839 100644 --- a/test/multiple-nodes.js +++ b/test/multiple-nodes.js @@ -54,12 +54,8 @@ describe('multiple nodes (more than 2)', () => { it('establish the connections', (done) => { parallel([ - (cb) => { - a.libp2p.dial(b.libp2p.peerInfo, cb) - }, - (cb) => { - b.libp2p.dial(c.libp2p.peerInfo, cb) - } + (cb) => a.libp2p.dial(b.libp2p.peerInfo, cb), + (cb) => b.libp2p.dial(c.libp2p.peerInfo, cb) ], (err) => { expect(err).to.not.exist() // wait for the pubsub pipes to be established @@ -286,11 +282,8 @@ describe('multiple nodes (more than 2)', () => { // ◉────◎────◉ // a b c - before((done) => { - }) - - after((done) => { - }) + before((done) => {}) + after((done) => {}) }) describe('1 level tree', () => { diff --git a/test/utils.js b/test/utils.js index fa8da24a1b..31521d3770 100644 --- a/test/utils.js +++ b/test/utils.js @@ -10,19 +10,15 @@ const expect = require('chai').expect exports.first = (map) => map.values().next().value exports.expectSet = (set, subs) => { - expect( - Array.from(set.values()) - ).to.be.eql( - subs - ) + expect(Array.from(set.values())).to.eql(subs) } exports.createNode = (maddr, callback) => { waterfall([ - (cb) => PeerId.create(cb), + (cb) => PeerId.create({ bits: 1024 }, cb), (id, cb) => PeerInfo.create(id, cb), (peer, cb) => { - peer.multiaddr.add(multiaddr(maddr)) + peer.multiaddrs.add(multiaddr(maddr)) cb(null, new Node(peer)) }, (node, cb) => { diff --git a/test/utils.spec.js b/test/utils.spec.js index dc457be098..09b4857fda 100644 --- a/test/utils.spec.js +++ b/test/utils.spec.js @@ -12,7 +12,7 @@ describe('utils', () => { expect(first).to.have.length(40) expect(second).to.have.length(40) - expect(first).to.not.be.eql(second) + expect(first).to.not.eql(second) }) it('msgId', () => { @@ -28,17 +28,11 @@ describe('utils', () => { [[], [], false], [[1], [2], false] ].forEach((test) => { - expect( - utils.anyMatch(new Set(test[0]), new Set(test[1])) - ).to.be.eql( - test[2] - ) - - expect( - utils.anyMatch(new Set(test[0]), test[1]) - ).to.be.eql( - test[2] - ) + expect(utils.anyMatch(new Set(test[0]), new Set(test[1]))) + .to.eql(test[2]) + + expect(utils.anyMatch(new Set(test[0]), test[1])) + .to.eql(test[2]) }) })