js-libp2p-websockets/tests/libp2p-websockets-test.js

56 lines
1.2 KiB
JavaScript
Raw Normal View History

2016-03-14 20:25:00 +00:00
/* eslint-env mocha */
const expect = require('chai').expect
const WSlibp2p = require('../src')
const multiaddr = require('multiaddr')
describe('libp2p-websockets', function () {
this.timeout(10000)
var ws
it('create', (done) => {
ws = new WSlibp2p()
expect(ws).to.exist
done()
})
it('listen and dial', (done) => {
const mh = multiaddr('/ip4/127.0.0.1/tcp/9090/websockets')
ws.createListener(mh, (socket) => {
expect(socket).to.exist
socket.end()
ws.close(() => {
done()
})
}, () => {
const conn = ws.dial(mh)
conn.end()
})
})
it('listen on several', (done) => {
const mh1 = multiaddr('/ip4/127.0.0.1/tcp/9090/websockets')
const mh2 = multiaddr('/ip4/127.0.0.1/tcp/9091/websockets')
const ws = new WSlibp2p()
ws.createListener([mh1, mh2], (socket) => {}, () => {
ws.close(done)
})
})
it('get observed addrs', (done) => {
const mh = multiaddr('/ip4/127.0.0.1/tcp/9090/websockets')
ws.createListener(mh, (socket) => {
expect(socket).to.exist
socket.end()
expect(socket.getObservedAddrs()).to.deep.equal([])
ws.close(() => {
done()
})
}, () => {
const conn = ws.dial(mh)
conn.end()
})
})
})