mirror of
https://github.com/fluencelabs/js-libp2p-websockets
synced 2025-04-25 17:12:26 +00:00
chore: remove old interface-transport tests
License: MIT Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
This commit is contained in:
parent
4d499935aa
commit
01cd1fd9ea
@ -56,9 +56,6 @@
|
||||
"it-goodbye": "^2.0.0",
|
||||
"it-pipe": "^1.0.0",
|
||||
"multiaddr": "^6.0.6",
|
||||
"pull-goodbye": "0.0.2",
|
||||
"pull-serializer": "~0.3.2",
|
||||
"pull-stream": "^3.6.9",
|
||||
"streaming-iterables": "^4.0.2"
|
||||
},
|
||||
"contributors": [
|
||||
|
@ -1,81 +0,0 @@
|
||||
/* eslint-env mocha */
|
||||
'use strict'
|
||||
|
||||
const chai = require('chai')
|
||||
const dirtyChai = require('dirty-chai')
|
||||
const expect = chai.expect
|
||||
chai.use(dirtyChai)
|
||||
|
||||
const multiaddr = require('multiaddr')
|
||||
const pull = require('pull-stream')
|
||||
const goodbye = require('pull-goodbye')
|
||||
|
||||
const WS = require('../../src/adapter')
|
||||
|
||||
describe('adapter libp2p-websockets', () => {
|
||||
const ma = multiaddr('/ip4/127.0.0.1/tcp/9095/ws')
|
||||
let ws
|
||||
let conn
|
||||
|
||||
beforeEach((done) => {
|
||||
ws = new WS()
|
||||
expect(ws).to.exist()
|
||||
conn = ws.dial(ma, (err, res) => {
|
||||
expect(err).to.not.exist()
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('echo', (done) => {
|
||||
const message = 'Hello World!'
|
||||
|
||||
const s = goodbye({
|
||||
source: pull.values([message]),
|
||||
sink: pull.collect((err, results) => {
|
||||
expect(err).to.not.exist()
|
||||
expect(results).to.eql([message])
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
pull(s, conn, s)
|
||||
})
|
||||
|
||||
describe('stress', () => {
|
||||
it('one big write', (done) => {
|
||||
const rawMessage = Buffer.allocUnsafe(1000000).fill('a')
|
||||
|
||||
const s = goodbye({
|
||||
source: pull.values([rawMessage]),
|
||||
sink: pull.collect((err, results) => {
|
||||
expect(err).to.not.exist()
|
||||
expect(results).to.eql([rawMessage])
|
||||
done()
|
||||
})
|
||||
})
|
||||
pull(s, conn, s)
|
||||
})
|
||||
|
||||
it('many writes', function (done) {
|
||||
this.timeout(100000)
|
||||
const s = goodbye({
|
||||
source: pull(
|
||||
pull.infinite(),
|
||||
pull.take(20000),
|
||||
pull.map((val) => Buffer.from(val.toString()))
|
||||
),
|
||||
sink: pull.collect((err, result) => {
|
||||
expect(err).to.not.exist()
|
||||
expect(result).to.have.length(20000)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
pull(s, conn, s)
|
||||
})
|
||||
})
|
||||
|
||||
it('.createServer throws in browser', () => {
|
||||
expect(new WS().createListener).to.throw()
|
||||
})
|
||||
})
|
@ -1,24 +0,0 @@
|
||||
/* eslint-env mocha */
|
||||
'use strict'
|
||||
|
||||
const tests = require('./compliance')
|
||||
const multiaddr = require('multiaddr')
|
||||
const WS = require('../../src/adapter')
|
||||
|
||||
describe('adapter compliance', () => {
|
||||
tests({
|
||||
setup (callback) {
|
||||
let ws = new WS()
|
||||
const addrs = [
|
||||
multiaddr('/ip4/127.0.0.1/tcp/9091/ws'),
|
||||
multiaddr('/ip4/127.0.0.1/tcp/9092/wss'),
|
||||
multiaddr('/dns4/ipfs.io/tcp/9092/ws'),
|
||||
multiaddr('/dns4/ipfs.io/tcp/9092/wss')
|
||||
]
|
||||
callback(null, ws, addrs)
|
||||
},
|
||||
teardown (callback) {
|
||||
callback()
|
||||
}
|
||||
})
|
||||
})
|
@ -1,73 +0,0 @@
|
||||
/* eslint-env mocha */
|
||||
'use strict'
|
||||
|
||||
const chai = require('chai')
|
||||
const dirtyChai = require('dirty-chai')
|
||||
const expect = chai.expect
|
||||
chai.use(dirtyChai)
|
||||
const pull = require('pull-stream')
|
||||
const goodbye = require('pull-goodbye')
|
||||
const serializer = require('pull-serializer')
|
||||
|
||||
module.exports = (common) => {
|
||||
describe('dial', () => {
|
||||
let addrs
|
||||
let transport
|
||||
let listener
|
||||
|
||||
before((done) => {
|
||||
common.setup((err, _transport, _addrs) => {
|
||||
if (err) return done(err)
|
||||
transport = _transport
|
||||
addrs = _addrs
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
after((done) => {
|
||||
common.teardown(done)
|
||||
})
|
||||
|
||||
beforeEach((done) => {
|
||||
listener = transport.createListener((conn) => {
|
||||
pull(conn, conn)
|
||||
})
|
||||
listener.listen(addrs[0], done)
|
||||
})
|
||||
|
||||
afterEach((done) => {
|
||||
listener.close(done)
|
||||
})
|
||||
|
||||
it('simple', (done) => {
|
||||
const s = serializer(goodbye({
|
||||
source: pull.values(['hey']),
|
||||
sink: pull.collect((err, values) => {
|
||||
expect(err).to.not.exist()
|
||||
expect(
|
||||
values
|
||||
).to.be.eql(
|
||||
['hey']
|
||||
)
|
||||
done()
|
||||
})
|
||||
}))
|
||||
|
||||
pull(
|
||||
s,
|
||||
transport.dial(addrs[0]),
|
||||
s
|
||||
)
|
||||
})
|
||||
|
||||
it('to non existent listener', (done) => {
|
||||
pull(
|
||||
transport.dial(addrs[1]),
|
||||
pull.onEnd((err) => {
|
||||
expect(err).to.exist()
|
||||
done()
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
/* eslint-env mocha */
|
||||
'use strict'
|
||||
|
||||
const dial = require('./dial-test')
|
||||
const listen = require('./listen-test')
|
||||
|
||||
module.exports = (common) => {
|
||||
describe('interface-transport', () => {
|
||||
dial(common)
|
||||
listen(common)
|
||||
})
|
||||
}
|
@ -1,124 +0,0 @@
|
||||
/* eslint max-nested-callbacks: ["error", 8] */
|
||||
/* eslint-env mocha */
|
||||
'use strict'
|
||||
|
||||
const chai = require('chai')
|
||||
const dirtyChai = require('dirty-chai')
|
||||
const expect = chai.expect
|
||||
chai.use(dirtyChai)
|
||||
|
||||
const pull = require('pull-stream')
|
||||
|
||||
module.exports = (common) => {
|
||||
describe('listen', () => {
|
||||
let addrs
|
||||
let transport
|
||||
|
||||
before((done) => {
|
||||
common.setup((err, _transport, _addrs) => {
|
||||
if (err) return done(err)
|
||||
transport = _transport
|
||||
addrs = _addrs
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
after((done) => {
|
||||
common.teardown(done)
|
||||
})
|
||||
|
||||
it('simple', (done) => {
|
||||
const listener = transport.createListener((conn) => {})
|
||||
listener.listen(addrs[0], () => {
|
||||
listener.close(done)
|
||||
})
|
||||
})
|
||||
|
||||
it('close listener with connections, through timeout', (done) => {
|
||||
const finish = plan(3, done)
|
||||
const listener = transport.createListener((conn) => {
|
||||
pull(conn, conn)
|
||||
})
|
||||
|
||||
listener.listen(addrs[0], () => {
|
||||
const socket1 = transport.dial(addrs[0], () => {
|
||||
listener.close(finish)
|
||||
})
|
||||
|
||||
pull(
|
||||
transport.dial(addrs[0]),
|
||||
pull.onEnd(() => {
|
||||
finish()
|
||||
})
|
||||
)
|
||||
|
||||
pull(
|
||||
pull.values([Buffer.from('Some data that is never handled')]),
|
||||
socket1,
|
||||
pull.onEnd(() => {
|
||||
finish()
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('events', () => {
|
||||
// eslint-disable-next-line
|
||||
// TODO: figure out why it fails in the full test suite
|
||||
it.skip('connection', (done) => {
|
||||
const finish = plan(2, done)
|
||||
|
||||
const listener = transport.createListener()
|
||||
|
||||
listener.on('connection', (conn) => {
|
||||
expect(conn).to.exist()
|
||||
finish()
|
||||
})
|
||||
|
||||
listener.listen(addrs[0], () => {
|
||||
transport.dial(addrs[0], () => {
|
||||
listener.close(finish)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('listening', (done) => {
|
||||
const listener = transport.createListener()
|
||||
listener.on('listening', () => {
|
||||
listener.close(done)
|
||||
})
|
||||
listener.listen(addrs[0])
|
||||
})
|
||||
|
||||
// eslint-disable-next-line
|
||||
// TODO: how to get the listener to emit an error?
|
||||
it.skip('error', (done) => {
|
||||
const listener = transport.createListener()
|
||||
listener.on('error', (err) => {
|
||||
expect(err).to.exist()
|
||||
listener.close(done)
|
||||
})
|
||||
})
|
||||
|
||||
it('close', (done) => {
|
||||
const finish = plan(2, done)
|
||||
const listener = transport.createListener()
|
||||
listener.on('close', finish)
|
||||
|
||||
listener.listen(addrs[0], () => {
|
||||
listener.close(finish)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function plan (n, done) {
|
||||
let i = 0
|
||||
return (err) => {
|
||||
if (err) return done(err)
|
||||
i++
|
||||
|
||||
if (i === n) done()
|
||||
}
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
'use strict'
|
||||
|
||||
require('./compliance.node')
|
||||
require('./node')
|
@ -1,556 +0,0 @@
|
||||
/* eslint-env mocha */
|
||||
/* eslint max-nested-callbacks: ["error", 6] */
|
||||
'use strict'
|
||||
|
||||
const chai = require('chai')
|
||||
const dirtyChai = require('dirty-chai')
|
||||
const expect = chai.expect
|
||||
chai.use(dirtyChai)
|
||||
const multiaddr = require('multiaddr')
|
||||
const pull = require('pull-stream')
|
||||
const goodbye = require('pull-goodbye')
|
||||
|
||||
const WS = require('../../src/adapter')
|
||||
|
||||
require('./compliance.node')
|
||||
|
||||
describe('adapter instantiate the transport', () => {
|
||||
it('create', () => {
|
||||
const ws = new WS()
|
||||
expect(ws).to.exist()
|
||||
})
|
||||
})
|
||||
|
||||
describe('adapter listen', () => {
|
||||
describe('ip4', () => {
|
||||
let ws
|
||||
const ma = multiaddr('/ip4/127.0.0.1/tcp/9090/ws')
|
||||
|
||||
beforeEach(() => {
|
||||
ws = new WS()
|
||||
})
|
||||
|
||||
it('listen, check for callback', (done) => {
|
||||
const listener = ws.createListener((conn) => { })
|
||||
|
||||
listener.listen(ma, () => {
|
||||
listener.close(done)
|
||||
})
|
||||
})
|
||||
|
||||
it('listen, check for listening event', (done) => {
|
||||
const listener = ws.createListener((conn) => { })
|
||||
|
||||
listener.on('listening', () => {
|
||||
listener.close(done)
|
||||
})
|
||||
|
||||
listener.listen(ma)
|
||||
})
|
||||
|
||||
it('listen, check for the close event', (done) => {
|
||||
const listener = ws.createListener((conn) => { })
|
||||
|
||||
listener.on('listening', () => {
|
||||
listener.on('close', done)
|
||||
listener.close()
|
||||
})
|
||||
|
||||
listener.listen(ma)
|
||||
})
|
||||
|
||||
it('listen on addr with /ipfs/QmHASH', (done) => {
|
||||
const ma = multiaddr('/ip4/127.0.0.1/tcp/9090/ws/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
|
||||
|
||||
const listener = ws.createListener((conn) => { })
|
||||
|
||||
listener.listen(ma, () => {
|
||||
listener.close(done)
|
||||
})
|
||||
})
|
||||
|
||||
it.skip('close listener with connections, through timeout', (done) => {
|
||||
// TODO `ws` closes all anyway, we need to make it not close
|
||||
// first - https://github.com/diasdavid/simple-websocket-server
|
||||
})
|
||||
|
||||
it.skip('listen on port 0', (done) => {
|
||||
// TODO port 0 not supported yet
|
||||
})
|
||||
|
||||
it.skip('listen on any Interface', (done) => {
|
||||
// TODO 0.0.0.0 not supported yet
|
||||
})
|
||||
|
||||
it('getAddrs', (done) => {
|
||||
const listener = ws.createListener((conn) => {
|
||||
})
|
||||
listener.listen(ma, () => {
|
||||
listener.getAddrs((err, addrs) => {
|
||||
expect(err).to.not.exist()
|
||||
expect(addrs.length).to.equal(1)
|
||||
expect(addrs[0]).to.deep.equal(ma)
|
||||
listener.close(done)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('getAddrs on port 0 listen', (done) => {
|
||||
const addr = multiaddr(`/ip4/127.0.0.1/tcp/0/ws`)
|
||||
const listener = ws.createListener((conn) => {
|
||||
})
|
||||
listener.listen(addr, () => {
|
||||
listener.getAddrs((err, addrs) => {
|
||||
expect(err).to.not.exist()
|
||||
expect(addrs.length).to.equal(1)
|
||||
expect(addrs.map((a) => a.toOptions().port)).to.not.include('0')
|
||||
listener.close(done)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('getAddrs from listening on 0.0.0.0', (done) => {
|
||||
const addr = multiaddr(`/ip4/0.0.0.0/tcp/9003/ws`)
|
||||
const listener = ws.createListener((conn) => {
|
||||
})
|
||||
listener.listen(addr, () => {
|
||||
listener.getAddrs((err, addrs) => {
|
||||
expect(err).to.not.exist()
|
||||
expect(addrs.map((a) => a.toOptions().host)).to.not.include('0.0.0.0')
|
||||
listener.close(done)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('getAddrs from listening on 0.0.0.0 and port 0', (done) => {
|
||||
const addr = multiaddr(`/ip4/0.0.0.0/tcp/0/ws`)
|
||||
const listener = ws.createListener((conn) => {
|
||||
})
|
||||
listener.listen(addr, () => {
|
||||
listener.getAddrs((err, addrs) => {
|
||||
expect(err).to.not.exist()
|
||||
expect(addrs.map((a) => a.toOptions().host)).to.not.include('0.0.0.0')
|
||||
expect(addrs.map((a) => a.toOptions().port)).to.not.include('0')
|
||||
listener.close(done)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('getAddrs preserves IPFS Id', (done) => {
|
||||
const ma = multiaddr('/ip4/127.0.0.1/tcp/9090/ws/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
|
||||
|
||||
const listener = ws.createListener((conn) => { })
|
||||
|
||||
listener.listen(ma, () => {
|
||||
listener.getAddrs((err, addrs) => {
|
||||
expect(err).to.not.exist()
|
||||
expect(addrs.length).to.equal(1)
|
||||
expect(addrs[0]).to.deep.equal(ma)
|
||||
listener.close(done)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('ip6', () => {
|
||||
let ws
|
||||
const ma = multiaddr('/ip6/::1/tcp/9091/ws')
|
||||
|
||||
beforeEach(() => {
|
||||
ws = new WS()
|
||||
})
|
||||
|
||||
it('listen, check for callback', (done) => {
|
||||
const listener = ws.createListener((conn) => { })
|
||||
|
||||
listener.listen(ma, () => {
|
||||
listener.close(done)
|
||||
})
|
||||
})
|
||||
|
||||
it('listen, check for listening event', (done) => {
|
||||
const listener = ws.createListener((conn) => { })
|
||||
|
||||
listener.on('listening', () => {
|
||||
listener.close(done)
|
||||
})
|
||||
|
||||
listener.listen(ma)
|
||||
})
|
||||
|
||||
it('listen, check for the close event', (done) => {
|
||||
const listener = ws.createListener((conn) => { })
|
||||
|
||||
listener.on('listening', () => {
|
||||
listener.on('close', done)
|
||||
listener.close()
|
||||
})
|
||||
|
||||
listener.listen(ma)
|
||||
})
|
||||
|
||||
it('listen on addr with /ipfs/QmHASH', (done) => {
|
||||
const ma = multiaddr('/ip6/::1/tcp/9091/ws/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
|
||||
|
||||
const listener = ws.createListener((conn) => { })
|
||||
|
||||
listener.listen(ma, () => {
|
||||
listener.close(done)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('adapter dial', () => {
|
||||
describe('ip4', () => {
|
||||
let ws
|
||||
let listener
|
||||
const ma = multiaddr('/ip4/127.0.0.1/tcp/9091/ws')
|
||||
|
||||
beforeEach((done) => {
|
||||
ws = new WS()
|
||||
listener = ws.createListener((conn) => {
|
||||
pull(conn, conn)
|
||||
})
|
||||
listener.listen(ma, done)
|
||||
})
|
||||
|
||||
afterEach((done) => {
|
||||
listener.close(done)
|
||||
})
|
||||
|
||||
it('dial', (done) => {
|
||||
const conn = ws.dial(ma)
|
||||
|
||||
const s = goodbye({
|
||||
source: pull.values(['hey']),
|
||||
sink: pull.collect((err, result) => {
|
||||
expect(err).to.not.exist()
|
||||
|
||||
expect(result).to.be.eql(['hey'])
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
pull(s, conn, s)
|
||||
})
|
||||
|
||||
it('dial with IPFS Id', (done) => {
|
||||
const ma = multiaddr('/ip4/127.0.0.1/tcp/9091/ws/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
|
||||
const conn = ws.dial(ma)
|
||||
|
||||
const s = goodbye({
|
||||
source: pull.values(['hey']),
|
||||
sink: pull.collect((err, result) => {
|
||||
expect(err).to.not.exist()
|
||||
|
||||
expect(result).to.be.eql(['hey'])
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
pull(s, conn, s)
|
||||
})
|
||||
})
|
||||
|
||||
describe('ip6', () => {
|
||||
let ws
|
||||
let listener
|
||||
const ma = multiaddr('/ip6/::1/tcp/9091')
|
||||
|
||||
beforeEach((done) => {
|
||||
ws = new WS()
|
||||
listener = ws.createListener((conn) => {
|
||||
pull(conn, conn)
|
||||
})
|
||||
listener.listen(ma, done)
|
||||
})
|
||||
|
||||
afterEach((done) => {
|
||||
listener.close(done)
|
||||
})
|
||||
|
||||
it('dial', (done) => {
|
||||
const conn = ws.dial(ma)
|
||||
|
||||
const s = goodbye({
|
||||
source: pull.values(['hey']),
|
||||
sink: pull.collect((err, result) => {
|
||||
expect(err).to.not.exist()
|
||||
|
||||
expect(result).to.be.eql(['hey'])
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
pull(s, conn, s)
|
||||
})
|
||||
|
||||
it('dial with IPFS Id', (done) => {
|
||||
const ma = multiaddr('/ip6/::1/tcp/9091/ws/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
|
||||
const conn = ws.dial(ma)
|
||||
|
||||
const s = goodbye({
|
||||
source: pull.values(['hey']),
|
||||
sink: pull.collect((err, result) => {
|
||||
expect(err).to.not.exist()
|
||||
|
||||
expect(result).to.be.eql(['hey'])
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
pull(s, conn, s)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('adapter filter addrs', () => {
|
||||
let ws
|
||||
|
||||
before(() => {
|
||||
ws = new WS()
|
||||
})
|
||||
|
||||
describe('filter valid addrs for this transport', function () {
|
||||
it('should fail invalid WS addresses', function () {
|
||||
const ma1 = multiaddr('/ip4/127.0.0.1/tcp/9090')
|
||||
const ma2 = multiaddr('/ip4/127.0.0.1/udp/9090')
|
||||
const ma3 = multiaddr('/ip6/::1/tcp/80')
|
||||
const ma4 = multiaddr('/dnsaddr/ipfs.io/tcp/80')
|
||||
|
||||
const valid = ws.filter([ma1, ma2, ma3, ma4])
|
||||
expect(valid.length).to.equal(0)
|
||||
})
|
||||
|
||||
it('should filter correct ipv4 addresses', function () {
|
||||
const ma1 = multiaddr('/ip4/127.0.0.1/tcp/80/ws')
|
||||
const ma2 = multiaddr('/ip4/127.0.0.1/tcp/443/wss')
|
||||
|
||||
const valid = ws.filter([ma1, ma2])
|
||||
expect(valid.length).to.equal(2)
|
||||
expect(valid[0]).to.deep.equal(ma1)
|
||||
expect(valid[1]).to.deep.equal(ma2)
|
||||
})
|
||||
|
||||
it('should filter correct ipv4 addresses with ipfs id', function () {
|
||||
const ma1 = multiaddr('/ip4/127.0.0.1/tcp/80/ws/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
|
||||
const ma2 = multiaddr('/ip4/127.0.0.1/tcp/80/wss/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
|
||||
|
||||
const valid = ws.filter([ma1, ma2])
|
||||
expect(valid.length).to.equal(2)
|
||||
expect(valid[0]).to.deep.equal(ma1)
|
||||
expect(valid[1]).to.deep.equal(ma2)
|
||||
})
|
||||
|
||||
it('should filter correct ipv6 address', function () {
|
||||
const ma1 = multiaddr('/ip6/::1/tcp/80/ws')
|
||||
const ma2 = multiaddr('/ip6/::1/tcp/443/wss')
|
||||
|
||||
const valid = ws.filter([ma1, ma2])
|
||||
expect(valid.length).to.equal(2)
|
||||
expect(valid[0]).to.deep.equal(ma1)
|
||||
expect(valid[1]).to.deep.equal(ma2)
|
||||
})
|
||||
|
||||
it('should filter correct ipv6 addresses with ipfs id', function () {
|
||||
const ma1 = multiaddr('/ip6/::1/tcp/80/ws/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
|
||||
const ma2 = multiaddr('/ip6/::1/tcp/443/wss/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
|
||||
|
||||
const valid = ws.filter([ma1, ma2])
|
||||
expect(valid.length).to.equal(2)
|
||||
expect(valid[0]).to.deep.equal(ma1)
|
||||
expect(valid[1]).to.deep.equal(ma2)
|
||||
})
|
||||
|
||||
it('should filter correct dns address', function () {
|
||||
const ma1 = multiaddr('/dnsaddr/ipfs.io/ws')
|
||||
const ma2 = multiaddr('/dnsaddr/ipfs.io/tcp/80/ws')
|
||||
const ma3 = multiaddr('/dnsaddr/ipfs.io/tcp/80/wss')
|
||||
|
||||
const valid = ws.filter([ma1, ma2, ma3])
|
||||
expect(valid.length).to.equal(3)
|
||||
expect(valid[0]).to.deep.equal(ma1)
|
||||
expect(valid[1]).to.deep.equal(ma2)
|
||||
expect(valid[2]).to.deep.equal(ma3)
|
||||
})
|
||||
|
||||
it('should filter correct dns address with ipfs id', function () {
|
||||
const ma1 = multiaddr('/dnsaddr/ipfs.io/tcp/80/ws/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
|
||||
const ma2 = multiaddr('/dnsaddr/ipfs.io/tcp/443/wss/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
|
||||
|
||||
const valid = ws.filter([ma1, ma2])
|
||||
expect(valid.length).to.equal(2)
|
||||
expect(valid[0]).to.deep.equal(ma1)
|
||||
expect(valid[1]).to.deep.equal(ma2)
|
||||
})
|
||||
|
||||
it('should filter correct dns4 address', function () {
|
||||
const ma1 = multiaddr('/dns4/ipfs.io/tcp/80/ws')
|
||||
const ma2 = multiaddr('/dns4/ipfs.io/tcp/443/wss')
|
||||
|
||||
const valid = ws.filter([ma1, ma2])
|
||||
expect(valid.length).to.equal(2)
|
||||
expect(valid[0]).to.deep.equal(ma1)
|
||||
expect(valid[1]).to.deep.equal(ma2)
|
||||
})
|
||||
|
||||
it('should filter correct dns6 address', function () {
|
||||
const ma1 = multiaddr('/dns6/ipfs.io/tcp/80/ws')
|
||||
const ma2 = multiaddr('/dns6/ipfs.io/tcp/443/wss')
|
||||
|
||||
const valid = ws.filter([ma1, ma2])
|
||||
expect(valid.length).to.equal(2)
|
||||
expect(valid[0]).to.deep.equal(ma1)
|
||||
expect(valid[1]).to.deep.equal(ma2)
|
||||
})
|
||||
|
||||
it('should filter correct dns6 address with ipfs id', function () {
|
||||
const ma1 = multiaddr('/dns6/ipfs.io/tcp/80/ws/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
|
||||
const ma2 = multiaddr('/dns6/ipfs.io/tcp/443/wss/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
|
||||
|
||||
const valid = ws.filter([ma1, ma2])
|
||||
expect(valid.length).to.equal(2)
|
||||
expect(valid[0]).to.deep.equal(ma1)
|
||||
expect(valid[1]).to.deep.equal(ma2)
|
||||
})
|
||||
|
||||
it('should filter mixed addresses', function () {
|
||||
const ma1 = multiaddr('/dns6/ipfs.io/tcp/80/ws/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
|
||||
const ma2 = multiaddr('/ip4/127.0.0.1/tcp/9090')
|
||||
const ma3 = multiaddr('/ip4/127.0.0.1/udp/9090')
|
||||
const ma4 = multiaddr('/dns6/ipfs.io/ws')
|
||||
const mh5 = multiaddr('/ip4/127.0.0.1/tcp/9090/ws/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw' +
|
||||
'/p2p-circuit/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
|
||||
|
||||
const valid = ws.filter([ma1, ma2, ma3, ma4, mh5])
|
||||
expect(valid.length).to.equal(2)
|
||||
expect(valid[0]).to.deep.equal(ma1)
|
||||
expect(valid[1]).to.deep.equal(ma4)
|
||||
})
|
||||
})
|
||||
|
||||
it('filter a single addr for this transport', (done) => {
|
||||
const ma = multiaddr('/ip4/127.0.0.1/tcp/9090/ws/ipfs/Qmb6owHp6eaWArVbcJJbQSyifyJBttMMjYV76N2hMbf5Vw')
|
||||
|
||||
const valid = ws.filter(ma)
|
||||
expect(valid.length).to.equal(1)
|
||||
expect(valid[0]).to.deep.equal(ma)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
describe('adapter valid Connection', () => {
|
||||
const ma = multiaddr('/ip4/127.0.0.1/tcp/9092/ws')
|
||||
|
||||
it('get observed addrs', (done) => {
|
||||
let dialerObsAddrs
|
||||
let listenerObsAddrs
|
||||
|
||||
const ws = new WS()
|
||||
|
||||
const listener = ws.createListener((conn) => {
|
||||
expect(conn).to.exist()
|
||||
|
||||
conn.getObservedAddrs((err, addrs) => {
|
||||
expect(err).to.not.exist()
|
||||
dialerObsAddrs = addrs
|
||||
})
|
||||
|
||||
pull(conn, conn)
|
||||
})
|
||||
|
||||
listener.listen(ma, () => {
|
||||
const conn = ws.dial(ma)
|
||||
|
||||
pull(
|
||||
pull.empty(),
|
||||
conn,
|
||||
pull.onEnd(onEnd)
|
||||
)
|
||||
|
||||
function onEnd () {
|
||||
conn.getObservedAddrs((err, addrs) => {
|
||||
expect(err).to.not.exist()
|
||||
listenerObsAddrs = addrs
|
||||
|
||||
listener.close(onClose)
|
||||
|
||||
function onClose () {
|
||||
expect(listenerObsAddrs[0]).to.deep.equal(ma)
|
||||
expect(dialerObsAddrs.length).to.equal(0)
|
||||
done()
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
it('get Peer Info', (done) => {
|
||||
const ws = new WS()
|
||||
|
||||
const listener = ws.createListener((conn) => {
|
||||
expect(conn).to.exist()
|
||||
|
||||
conn.getPeerInfo((err, peerInfo) => {
|
||||
expect(err).to.exist()
|
||||
})
|
||||
|
||||
pull(conn, conn)
|
||||
})
|
||||
|
||||
listener.listen(ma, () => {
|
||||
const conn = ws.dial(ma)
|
||||
|
||||
pull(
|
||||
pull.empty(),
|
||||
conn,
|
||||
pull.onEnd(onEnd)
|
||||
)
|
||||
|
||||
function onEnd () {
|
||||
conn.getPeerInfo((err, peerInfo) => {
|
||||
expect(err).to.exist()
|
||||
listener.close(done)
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
it('set Peer Info', (done) => {
|
||||
const ws = new WS()
|
||||
|
||||
const listener = ws.createListener((conn) => {
|
||||
expect(conn).to.exist()
|
||||
conn.setPeerInfo('a')
|
||||
|
||||
conn.getPeerInfo((err, peerInfo) => {
|
||||
expect(err).to.not.exist()
|
||||
expect(peerInfo).to.equal('a')
|
||||
})
|
||||
|
||||
pull(conn, conn)
|
||||
})
|
||||
|
||||
listener.listen(ma, onListen)
|
||||
|
||||
function onListen () {
|
||||
const conn = ws.dial(ma)
|
||||
conn.setPeerInfo('b')
|
||||
|
||||
pull(
|
||||
pull.empty(),
|
||||
conn,
|
||||
pull.onEnd(onEnd)
|
||||
)
|
||||
|
||||
function onEnd () {
|
||||
conn.getPeerInfo((err, peerInfo) => {
|
||||
expect(err).to.not.exist()
|
||||
expect(peerInfo).to.equal('b')
|
||||
listener.close(done)
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
@ -13,8 +13,6 @@ const { collect, take } = require('streaming-iterables')
|
||||
|
||||
const WS = require('../src')
|
||||
|
||||
require('./adapter/browser')
|
||||
|
||||
describe('libp2p-websockets', () => {
|
||||
const ma = multiaddr('/ip4/127.0.0.1/tcp/9095/ws')
|
||||
let ws
|
||||
|
Loading…
x
Reference in New Issue
Block a user