mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-04-25 18:42:15 +00:00
test: update tests to new API
This commit is contained in:
parent
59df82a675
commit
f7f85dce0a
@ -215,11 +215,11 @@ class Node extends EventEmitter {
|
|||||||
this._getPeerInfo(peer, (err, peerInfo) => {
|
this._getPeerInfo(peer, (err, peerInfo) => {
|
||||||
if (err) { return callback(err) }
|
if (err) { return callback(err) }
|
||||||
|
|
||||||
this.switch.dial(peerInfo, (err, conn) => {
|
this.switch.dial(peerInfo, (err) => {
|
||||||
if (err) { return callback(err) }
|
if (err) { return callback(err) }
|
||||||
|
|
||||||
this.peerBook.put(peerInfo)
|
this.peerBook.put(peerInfo)
|
||||||
callback(null, conn)
|
callback()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,16 @@
|
|||||||
/* eslint-env mocha */
|
/* eslint-env mocha */
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
const pull = require('pull-stream')
|
|
||||||
const waterfall = require('async/waterfall')
|
const waterfall = require('async/waterfall')
|
||||||
const series = require('async/series')
|
const series = require('async/series')
|
||||||
const parallel = require('async/parallel')
|
const parallel = require('async/parallel')
|
||||||
const utils = require('./utils/node')
|
const utils = require('./utils/node')
|
||||||
const Circuit = require('libp2p-circuit')
|
const Circuit = require('libp2p-circuit')
|
||||||
const multiaddr = require('multiaddr')
|
const multiaddr = require('multiaddr')
|
||||||
|
const tryEcho = require('./utils/try-echo')
|
||||||
|
|
||||||
const chai = require('chai')
|
const chai = require('chai')
|
||||||
chai.use(require('dirty-chai'))
|
chai.use(require('dirty-chai'))
|
||||||
|
|
||||||
const expect = chai.expect
|
const expect = chai.expect
|
||||||
const sinon = require('sinon')
|
const sinon = require('sinon')
|
||||||
|
|
||||||
@ -153,25 +152,16 @@ describe('circuit relay', function () {
|
|||||||
describe('any relay', function () {
|
describe('any relay', function () {
|
||||||
this.timeout(20 * 1000)
|
this.timeout(20 * 1000)
|
||||||
|
|
||||||
it('should dial from WS1 to TCP1 over any R', (done) => {
|
it('dial from WS1 to TCP1 over any R', (done) => {
|
||||||
nodeWS1.dial(nodeTCP1.peerInfo, '/echo/1.0.0', (err, conn) => {
|
nodeWS1.dialProtocol(nodeTCP1.peerInfo, '/echo/1.0.0', (err, conn) => {
|
||||||
expect(err).to.not.exist()
|
expect(err).to.not.exist()
|
||||||
expect(conn).to.exist()
|
expect(conn).to.exist()
|
||||||
|
tryEcho(conn, done)
|
||||||
pull(
|
|
||||||
pull.values(['hello']),
|
|
||||||
conn,
|
|
||||||
pull.collect((err, result) => {
|
|
||||||
expect(err).to.not.exist()
|
|
||||||
expect(result[0].toString()).to.equal('hello')
|
|
||||||
done()
|
|
||||||
})
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should not dial - no R from WS2 to TCP1', (done) => {
|
it('fail to dial - no R from WS2 to TCP1', (done) => {
|
||||||
nodeWS2.dial(nodeTCP2.peerInfo, '/echo/1.0.0', (err, conn) => {
|
nodeWS2.dialProtocol(nodeTCP2.peerInfo, '/echo/1.0.0', (err, conn) => {
|
||||||
expect(err).to.exist()
|
expect(err).to.exist()
|
||||||
expect(conn).to.not.exist()
|
expect(conn).to.not.exist()
|
||||||
done()
|
done()
|
||||||
@ -182,43 +172,29 @@ describe('circuit relay', function () {
|
|||||||
describe('explicit relay', function () {
|
describe('explicit relay', function () {
|
||||||
this.timeout(20 * 1000)
|
this.timeout(20 * 1000)
|
||||||
|
|
||||||
it('should dial from WS1 to TCP1 over R1', (done) => {
|
it('dial from WS1 to TCP1 over R1', (done) => {
|
||||||
nodeWS1.dial(nodeTCP1.peerInfo, '/echo/1.0.0', (err, conn) => {
|
nodeWS1.dialProtocol(nodeTCP1.peerInfo, '/echo/1.0.0', (err, conn) => {
|
||||||
expect(err).to.not.exist()
|
expect(err).to.not.exist()
|
||||||
expect(conn).to.exist()
|
expect(conn).to.exist()
|
||||||
|
|
||||||
pull(
|
tryEcho(conn, () => {
|
||||||
pull.values(['hello']),
|
const addr = multiaddr(handlerSpies[0].args[2][0].dstPeer.addrs[0]).toString()
|
||||||
conn,
|
expect(addr).to.equal(`/ipfs/${nodeTCP1.peerInfo.id.toB58String()}`)
|
||||||
pull.collect((err, result) => {
|
done()
|
||||||
expect(err).to.not.exist()
|
})
|
||||||
expect(result[0].toString()).to.equal('hello')
|
|
||||||
|
|
||||||
const addr = multiaddr(handlerSpies[0].args[2][0].dstPeer.addrs[0]).toString()
|
|
||||||
expect(addr).to.equal(`/ipfs/${nodeTCP1.peerInfo.id.toB58String()}`)
|
|
||||||
done()
|
|
||||||
})
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should dial from WS1 to TCP2 over R2', (done) => {
|
it('dial from WS1 to TCP2 over R2', (done) => {
|
||||||
nodeWS1.dial(nodeTCP2.peerInfo, '/echo/1.0.0', (err, conn) => {
|
nodeWS1.dialProtocol(nodeTCP2.peerInfo, '/echo/1.0.0', (err, conn) => {
|
||||||
expect(err).to.not.exist()
|
expect(err).to.not.exist()
|
||||||
expect(conn).to.exist()
|
expect(conn).to.exist()
|
||||||
|
|
||||||
pull(
|
tryEcho(conn, () => {
|
||||||
pull.values(['hello']),
|
const addr = multiaddr(handlerSpies[1].args[2][0].dstPeer.addrs[0]).toString()
|
||||||
conn,
|
expect(addr).to.equal(`/ipfs/${nodeTCP2.peerInfo.id.toB58String()}`)
|
||||||
pull.collect((err, result) => {
|
done()
|
||||||
expect(err).to.not.exist()
|
})
|
||||||
expect(result[0].toString()).to.equal('hello')
|
|
||||||
|
|
||||||
const addr = multiaddr(handlerSpies[1].args[2][0].dstPeer.addrs[0]).toString()
|
|
||||||
expect(addr).to.equal(`/ipfs/${nodeTCP2.peerInfo.id.toB58String()}`)
|
|
||||||
done()
|
|
||||||
})
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -6,24 +6,15 @@ chai.use(require('dirty-chai'))
|
|||||||
const expect = chai.expect
|
const expect = chai.expect
|
||||||
const parallel = require('async/parallel')
|
const parallel = require('async/parallel')
|
||||||
const series = require('async/series')
|
const series = require('async/series')
|
||||||
const pull = require('pull-stream')
|
|
||||||
const utils = require('./utils/node')
|
const utils = require('./utils/node')
|
||||||
|
const tryEcho = require('./utils/try-echo')
|
||||||
const createNode = utils.createNode
|
const createNode = utils.createNode
|
||||||
const echo = utils.echo
|
const echo = utils.echo
|
||||||
|
|
||||||
function test (nodeA, nodeB, callback) {
|
function test (nodeA, nodeB, callback) {
|
||||||
nodeA.dial(nodeB.peerInfo, '/echo/1.0.0', (err, conn) => {
|
nodeA.dialProtocol(nodeB.peerInfo, '/echo/1.0.0', (err, conn) => {
|
||||||
expect(err).to.not.exist()
|
expect(err).to.not.exist()
|
||||||
|
tryEcho(conn, callback)
|
||||||
pull(
|
|
||||||
pull.values([Buffer.from('hey')]),
|
|
||||||
conn,
|
|
||||||
pull.collect((err, data) => {
|
|
||||||
expect(err).to.not.exist()
|
|
||||||
expect(data).to.be.eql([Buffer.from('hey')])
|
|
||||||
callback()
|
|
||||||
})
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,7 +127,7 @@ describe('stream muxing', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('spdy + multiplex switched order', function (done) {
|
it('spdy + multiplex switched order', function (done) {
|
||||||
this.timeout(5000)
|
this.timeout(5 * 1000)
|
||||||
|
|
||||||
let nodeA
|
let nodeA
|
||||||
let nodeB
|
let nodeB
|
||||||
@ -170,7 +161,7 @@ describe('stream muxing', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('one without the other fails to establish a muxedConn', function (done) {
|
it('one without the other fails to establish a muxedConn', function (done) {
|
||||||
this.timeout(5000)
|
this.timeout(5 * 1000)
|
||||||
|
|
||||||
let nodeA
|
let nodeA
|
||||||
let nodeB
|
let nodeB
|
||||||
|
@ -12,6 +12,7 @@ const parallel = require('async/parallel')
|
|||||||
const goodbye = require('pull-goodbye')
|
const goodbye = require('pull-goodbye')
|
||||||
const serializer = require('pull-serializer')
|
const serializer = require('pull-serializer')
|
||||||
const w = require('webrtcsupport')
|
const w = require('webrtcsupport')
|
||||||
|
const tryEcho = require('./utils/try-echo')
|
||||||
|
|
||||||
const Node = require('./utils/bundle.browser')
|
const Node = require('./utils/bundle.browser')
|
||||||
const rawPeer = require('./fixtures/test-peer.json')
|
const rawPeer = require('./fixtures/test-peer.json')
|
||||||
@ -63,7 +64,7 @@ describe('transports', () => {
|
|||||||
|
|
||||||
// General connectivity tests
|
// General connectivity tests
|
||||||
|
|
||||||
it('libp2p.dial using Multiaddr nodeA to nodeB', (done) => {
|
it('.dial using Multiaddr', (done) => {
|
||||||
nodeA.dial(peerB.multiaddrs.toArray()[0], (err) => {
|
nodeA.dial(peerB.multiaddrs.toArray()[0], (err) => {
|
||||||
expect(err).to.not.exist()
|
expect(err).to.not.exist()
|
||||||
|
|
||||||
@ -77,26 +78,18 @@ describe('transports', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('libp2p.dial using Multiaddr on Protocol nodeA to nodeB', (done) => {
|
it('.dialProtocol using Multiaddr', (done) => {
|
||||||
nodeA.dial(peerB.multiaddrs.toArray()[0], '/echo/1.0.0', (err, conn) => {
|
nodeA.dialProtocol(peerB.multiaddrs.toArray()[0], '/echo/1.0.0', (err, conn) => {
|
||||||
expect(err).to.not.exist()
|
expect(err).to.not.exist()
|
||||||
|
|
||||||
const peers = nodeA.peerBook.getAll()
|
const peers = nodeA.peerBook.getAll()
|
||||||
expect(Object.keys(peers)).to.have.length(1)
|
expect(Object.keys(peers)).to.have.length(1)
|
||||||
|
|
||||||
pull(
|
tryEcho(conn, done)
|
||||||
pull.values([Buffer.from('hey')]),
|
|
||||||
conn,
|
|
||||||
pull.collect((err, data) => {
|
|
||||||
expect(err).to.not.exist()
|
|
||||||
expect(data).to.eql([Buffer.from('hey')])
|
|
||||||
done()
|
|
||||||
})
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('libp2p.hangUp using Multiaddr nodeA to nodeB', (done) => {
|
it('.hangUp using Multiaddr', (done) => {
|
||||||
nodeA.hangUp(peerB.multiaddrs.toArray()[0], (err) => {
|
nodeA.hangUp(peerB.multiaddrs.toArray()[0], (err) => {
|
||||||
expect(err).to.not.exist()
|
expect(err).to.not.exist()
|
||||||
|
|
||||||
@ -111,7 +104,7 @@ describe('transports', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('libp2p.dial using PeerInfo nodeA to nodeB', (done) => {
|
it('.dial using PeerInfo', (done) => {
|
||||||
nodeA.dial(peerB, (err) => {
|
nodeA.dial(peerB, (err) => {
|
||||||
expect(err).to.not.exist()
|
expect(err).to.not.exist()
|
||||||
|
|
||||||
@ -125,26 +118,18 @@ describe('transports', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('libp2p.dial using PeerInfo on Protocol nodeA to nodeB', (done) => {
|
it('.dialProtocol using PeerInfo', (done) => {
|
||||||
nodeA.dial(peerB, '/echo/1.0.0', (err, conn) => {
|
nodeA.dialProtocol(peerB, '/echo/1.0.0', (err, conn) => {
|
||||||
expect(err).to.not.exist()
|
expect(err).to.not.exist()
|
||||||
const peers = nodeA.peerBook.getAll()
|
const peers = nodeA.peerBook.getAll()
|
||||||
expect(err).to.not.exist()
|
expect(err).to.not.exist()
|
||||||
expect(Object.keys(peers)).to.have.length(1)
|
expect(Object.keys(peers)).to.have.length(1)
|
||||||
|
|
||||||
pull(
|
tryEcho(conn, done)
|
||||||
pull.values([Buffer.from('hey')]),
|
|
||||||
conn,
|
|
||||||
pull.collect((err, data) => {
|
|
||||||
expect(err).to.not.exist()
|
|
||||||
expect(data).to.eql([Buffer.from('hey')])
|
|
||||||
done()
|
|
||||||
})
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('libp2p.hangUp using PeerInfo nodeA to nodeB', (done) => {
|
it('.hangUp using PeerInfo', (done) => {
|
||||||
nodeA.hangUp(peerB, (err) => {
|
nodeA.hangUp(peerB, (err) => {
|
||||||
expect(err).to.not.exist()
|
expect(err).to.not.exist()
|
||||||
setTimeout(check, 500)
|
setTimeout(check, 500)
|
||||||
@ -161,7 +146,7 @@ describe('transports', () => {
|
|||||||
|
|
||||||
describe('stress', () => {
|
describe('stress', () => {
|
||||||
it('one big write', (done) => {
|
it('one big write', (done) => {
|
||||||
nodeA.dial(peerB, '/echo/1.0.0', (err, conn) => {
|
nodeA.dialProtocol(peerB, '/echo/1.0.0', (err, conn) => {
|
||||||
expect(err).to.not.exist()
|
expect(err).to.not.exist()
|
||||||
const rawMessage = Buffer.alloc(100000)
|
const rawMessage = Buffer.alloc(100000)
|
||||||
rawMessage.fill('a')
|
rawMessage.fill('a')
|
||||||
@ -180,7 +165,7 @@ describe('transports', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('many writes', (done) => {
|
it('many writes', (done) => {
|
||||||
nodeA.dial(peerB, '/echo/1.0.0', (err, conn) => {
|
nodeA.dialProtocol(peerB, '/echo/1.0.0', (err, conn) => {
|
||||||
expect(err).to.not.exist()
|
expect(err).to.not.exist()
|
||||||
|
|
||||||
const s = serializer(goodbye({
|
const s = serializer(goodbye({
|
||||||
@ -235,39 +220,30 @@ describe('transports', () => {
|
|||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('listen on the two libp2p nodes', (done) => {
|
it('start two libp2p nodes', (done) => {
|
||||||
parallel([
|
parallel([
|
||||||
(cb) => node1.start(cb),
|
(cb) => node1.start(cb),
|
||||||
(cb) => node2.start(cb)
|
(cb) => node2.start(cb)
|
||||||
], done)
|
], done)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('handle a protocol on the first node', () => {
|
it('.handle echo on first node', () => {
|
||||||
node2.handle('/echo/1.0.0', (protocol, conn) => pull(conn, conn))
|
node2.handle('/echo/1.0.0', (protocol, conn) => pull(conn, conn))
|
||||||
})
|
})
|
||||||
|
|
||||||
it('dial from the second node to the first node', (done) => {
|
it('.dialProtocol from the second node to the first node', (done) => {
|
||||||
node1.dial(peer2, '/echo/1.0.0', (err, conn) => {
|
node1.dialProtocol(peer2, '/echo/1.0.0', (err, conn) => {
|
||||||
expect(err).to.not.exist()
|
expect(err).to.not.exist()
|
||||||
setTimeout(check, 500)
|
setTimeout(check, 500)
|
||||||
|
|
||||||
function check () {
|
function check () {
|
||||||
const text = 'hello'
|
|
||||||
const peers1 = node1.peerBook.getAll()
|
const peers1 = node1.peerBook.getAll()
|
||||||
expect(Object.keys(peers1)).to.have.length(1)
|
expect(Object.keys(peers1)).to.have.length(1)
|
||||||
|
|
||||||
const peers2 = node2.peerBook.getAll()
|
const peers2 = node2.peerBook.getAll()
|
||||||
expect(Object.keys(peers2)).to.have.length(1)
|
expect(Object.keys(peers2)).to.have.length(1)
|
||||||
|
|
||||||
pull(
|
tryEcho(conn, done)
|
||||||
pull.values([Buffer.from(text)]),
|
|
||||||
conn,
|
|
||||||
pull.collect((err, data) => {
|
|
||||||
expect(err).to.not.exist()
|
|
||||||
expect(data[0].toString()).to.equal(text)
|
|
||||||
done()
|
|
||||||
})
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -355,28 +331,19 @@ describe('transports', () => {
|
|||||||
node2.handle('/echo/1.0.0', (protocol, conn) => pull(conn, conn))
|
node2.handle('/echo/1.0.0', (protocol, conn) => pull(conn, conn))
|
||||||
})
|
})
|
||||||
|
|
||||||
it('dial from the second node to the first node', (done) => {
|
it('.dialProtocol from the second node to the first node', (done) => {
|
||||||
node1.dial(peer2, '/echo/1.0.0', (err, conn) => {
|
node1.dialProtocol(peer2, '/echo/1.0.0', (err, conn) => {
|
||||||
expect(err).to.not.exist()
|
expect(err).to.not.exist()
|
||||||
setTimeout(check, 500)
|
setTimeout(check, 500)
|
||||||
|
|
||||||
function check () {
|
function check () {
|
||||||
const text = 'hello'
|
|
||||||
const peers1 = node1.peerBook.getAll()
|
const peers1 = node1.peerBook.getAll()
|
||||||
expect(Object.keys(peers1)).to.have.length(1)
|
expect(Object.keys(peers1)).to.have.length(1)
|
||||||
|
|
||||||
const peers2 = node2.peerBook.getAll()
|
const peers2 = node2.peerBook.getAll()
|
||||||
expect(Object.keys(peers2)).to.have.length(1)
|
expect(Object.keys(peers2)).to.have.length(1)
|
||||||
|
|
||||||
pull(
|
tryEcho(conn, done)
|
||||||
pull.values([Buffer.from(text)]),
|
|
||||||
conn,
|
|
||||||
pull.collect((err, data) => {
|
|
||||||
expect(err).to.not.exist()
|
|
||||||
expect(data[0].toString()).to.equal(text)
|
|
||||||
done()
|
|
||||||
})
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -13,6 +13,7 @@ const rendezvous = require('libp2p-websocket-star-rendezvous')
|
|||||||
const WSStar = require('libp2p-websocket-star')
|
const WSStar = require('libp2p-websocket-star')
|
||||||
const WRTCStar = require('libp2p-webrtc-star')
|
const WRTCStar = require('libp2p-webrtc-star')
|
||||||
const wrtc = require('wrtc')
|
const wrtc = require('wrtc')
|
||||||
|
const tryEcho = require('./utils/try-echo')
|
||||||
|
|
||||||
const createNode = utils.createNode
|
const createNode = utils.createNode
|
||||||
const echo = utils.echo
|
const echo = utils.echo
|
||||||
@ -73,18 +74,10 @@ describe('transports', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('nodeA.dial nodeB using PeerInfo', (done) => {
|
it('nodeA.dial nodeB using PeerInfo', (done) => {
|
||||||
nodeA.dial(nodeB.peerInfo, '/echo/1.0.0', (err, conn) => {
|
nodeA.dialProtocol(nodeB.peerInfo, '/echo/1.0.0', (err, conn) => {
|
||||||
expect(err).to.not.exist()
|
expect(err).to.not.exist()
|
||||||
|
|
||||||
pull(
|
tryEcho(conn, done)
|
||||||
pull.values([Buffer.from('hey')]),
|
|
||||||
conn,
|
|
||||||
pull.collect((err, data) => {
|
|
||||||
expect(err).to.not.exist()
|
|
||||||
expect(data).to.be.eql([Buffer.from('hey')])
|
|
||||||
done()
|
|
||||||
})
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -113,8 +106,8 @@ describe('transports', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('nodeA.dial nodeB using multiaddr', (done) => {
|
it('nodeA.dialProtocol nodeB using multiaddr', (done) => {
|
||||||
nodeA.dial(nodeB.peerInfo.multiaddrs.toArray()[0], '/echo/1.0.0', (err, conn) => {
|
nodeA.dialProtocol(nodeB.peerInfo.multiaddrs.toArray()[0], '/echo/1.0.0', (err, conn) => {
|
||||||
// Some time for Identify to finish
|
// Some time for Identify to finish
|
||||||
setTimeout(check, 500)
|
setTimeout(check, 500)
|
||||||
|
|
||||||
@ -135,17 +128,7 @@ describe('transports', () => {
|
|||||||
expect(Object.keys(nodeA.switch.muxedConns)).to.have.length(1)
|
expect(Object.keys(nodeA.switch.muxedConns)).to.have.length(1)
|
||||||
cb()
|
cb()
|
||||||
}
|
}
|
||||||
], () => {
|
], () => tryEcho(conn, done))
|
||||||
pull(
|
|
||||||
pull.values([Buffer.from('hey')]),
|
|
||||||
conn,
|
|
||||||
pull.collect((err, data) => {
|
|
||||||
expect(err).to.not.exist()
|
|
||||||
expect(data).to.be.eql([Buffer.from('hey')])
|
|
||||||
done()
|
|
||||||
})
|
|
||||||
)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -176,8 +159,8 @@ describe('transports', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('nodeA.dial nodeB using PeerId', (done) => {
|
it('nodeA.dialProtocol nodeB using PeerId', (done) => {
|
||||||
nodeA.dial(nodeB.peerInfo.id, '/echo/1.0.0', (err, conn) => {
|
nodeA.dialProtocol(nodeB.peerInfo.id, '/echo/1.0.0', (err, conn) => {
|
||||||
// Some time for Identify to finish
|
// Some time for Identify to finish
|
||||||
setTimeout(check, 500)
|
setTimeout(check, 500)
|
||||||
|
|
||||||
@ -196,17 +179,7 @@ describe('transports', () => {
|
|||||||
expect(Object.keys(nodeA.switch.muxedConns)).to.have.length(1)
|
expect(Object.keys(nodeA.switch.muxedConns)).to.have.length(1)
|
||||||
cb()
|
cb()
|
||||||
}
|
}
|
||||||
], () => {
|
], () => tryEcho(conn, done))
|
||||||
pull(
|
|
||||||
pull.values([Buffer.from('hey')]),
|
|
||||||
conn,
|
|
||||||
pull.collect((err, data) => {
|
|
||||||
expect(err).to.not.exist()
|
|
||||||
expect(data).to.eql([Buffer.from('hey')])
|
|
||||||
done()
|
|
||||||
})
|
|
||||||
)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
21
test/utils/try-echo.js
Normal file
21
test/utils/try-echo.js
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
'use strict'
|
||||||
|
|
||||||
|
const pull = require('pull-stream')
|
||||||
|
const chai = require('chai')
|
||||||
|
const dirtyChai = require('dirty-chai')
|
||||||
|
const expect = chai.expect
|
||||||
|
chai.use(dirtyChai)
|
||||||
|
|
||||||
|
module.exports = (conn, callback) => {
|
||||||
|
const values = [Buffer.from('echo')]
|
||||||
|
|
||||||
|
pull(
|
||||||
|
pull.values(values),
|
||||||
|
conn,
|
||||||
|
pull.collect((err, _values) => {
|
||||||
|
expect(err).to.not.exist()
|
||||||
|
expect(_values).to.eql(values)
|
||||||
|
callback()
|
||||||
|
})
|
||||||
|
)
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user