Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
"libp2p-secio": "^0.13.1",
"libp2p-tcp": "^0.15.1",
"libp2p-webrtc-star": "^0.20.0",
"libp2p-websockets": "^0.14.0",
"libp2p-websockets": "^0.15.0",
"multihashes": "^3.0.1",
"nock": "^13.0.3",
"p-defer": "^3.0.0",
Expand Down
53 changes: 52 additions & 1 deletion test/dialing/direct.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const pDefer = require('p-defer')
const pWaitFor = require('p-wait-for')
const delay = require('delay')
const Transport = require('libp2p-websockets')
const filters = require('libp2p-websockets/src/filters')
const Muxer = require('libp2p-mplex')
const { NOISE: Crypto } = require('libp2p-noise')
const multiaddr = require('multiaddr')
Expand Down Expand Up @@ -41,7 +42,7 @@ describe('Dialing (direct, WebSockets)', () => {
upgrader: mockUpgrader,
onConnection: () => {}
})
localTM.add(Transport.prototype[Symbol.toStringTag], Transport)
localTM.add(Transport.prototype[Symbol.toStringTag], Transport, { filter: filters.all })
})

afterEach(() => {
Expand Down Expand Up @@ -292,6 +293,7 @@ describe('Dialing (direct, WebSockets)', () => {
})

describe('libp2p.dialer', () => {
const transportKey = Transport.prototype[Symbol.toStringTag]
let libp2p

afterEach(async () => {
Expand All @@ -307,6 +309,13 @@ describe('Dialing (direct, WebSockets)', () => {
transport: [Transport],
streamMuxer: [Muxer],
connEncryption: [Crypto]
},
config: {
transport: {
[transportKey]: {
filter: filters.all
}
}
}
})

Expand All @@ -330,6 +339,13 @@ describe('Dialing (direct, WebSockets)', () => {
maxParallelDials: 10,
maxDialsPerPeer: 1,
dialTimeout: 1e3 // 30 second dial timeout per peer
},
config: {
transport: {
[transportKey]: {
filter: filters.all
}
}
}
}
libp2p = await Libp2p.create(config)
Expand All @@ -347,6 +363,13 @@ describe('Dialing (direct, WebSockets)', () => {
transport: [Transport],
streamMuxer: [Muxer],
connEncryption: [Crypto]
},
config: {
transport: {
[transportKey]: {
filter: filters.all
}
}
}
})

Expand All @@ -370,6 +393,13 @@ describe('Dialing (direct, WebSockets)', () => {
transport: [Transport],
streamMuxer: [Muxer],
connEncryption: [Crypto]
},
config: {
transport: {
[transportKey]: {
filter: filters.all
}
}
}
})

Expand Down Expand Up @@ -397,6 +427,13 @@ describe('Dialing (direct, WebSockets)', () => {
transport: [Transport],
streamMuxer: [Muxer],
connEncryption: [Crypto]
},
config: {
transport: {
[transportKey]: {
filter: filters.all
}
}
}
})

Expand All @@ -414,6 +451,13 @@ describe('Dialing (direct, WebSockets)', () => {
transport: [Transport],
streamMuxer: [Muxer],
connEncryption: [Crypto]
},
config: {
transport: {
[transportKey]: {
filter: filters.all
}
}
}
})

Expand All @@ -427,6 +471,13 @@ describe('Dialing (direct, WebSockets)', () => {
transport: [Transport],
streamMuxer: [Muxer],
connEncryption: [Crypto]
},
config: {
transport: {
[transportKey]: {
filter: filters.all
}
}
}
})

Expand Down
3 changes: 2 additions & 1 deletion test/dialing/resolver.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ describe('Dialing (resolvable addresses)', () => {
[libp2p, remoteLibp2p] = await peerUtils.createPeer({
number: 2,
config: {
modules: baseOptions.modules,
...baseOptions,
addresses: {
listen: [multiaddr(`${relayAddr}/p2p-circuit`)]
},
config: {
...baseOptions.config,
peerDiscovery: {
autoDial: false
}
Expand Down
9 changes: 5 additions & 4 deletions test/transports/transport-manager.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const sinon = require('sinon')

const multiaddr = require('multiaddr')
const Transport = require('libp2p-websockets')
const filters = require('libp2p-websockets/src/filters')
const { NOISE: Crypto } = require('libp2p-noise')
const AddressManager = require('../../src/address-manager')
const TransportManager = require('../../src/transport-manager')
Expand Down Expand Up @@ -39,7 +40,7 @@ describe('Transport Manager (WebSockets)', () => {
})

it('should be able to add and remove a transport', async () => {
tm.add(Transport.prototype[Symbol.toStringTag], Transport)
tm.add(Transport.prototype[Symbol.toStringTag], Transport, { filter: filters.all })
expect(tm._transports.size).to.equal(1)
await tm.remove(Transport.prototype[Symbol.toStringTag])
})
Expand All @@ -66,23 +67,23 @@ describe('Transport Manager (WebSockets)', () => {
})

it('should be able to dial', async () => {
tm.add(Transport.prototype[Symbol.toStringTag], Transport)
tm.add(Transport.prototype[Symbol.toStringTag], Transport, { filter: filters.all })
const addr = MULTIADDRS_WEBSOCKETS[0]
const connection = await tm.dial(addr)
expect(connection).to.exist()
await connection.close()
})

it('should fail to dial an unsupported address', async () => {
tm.add(Transport.prototype[Symbol.toStringTag], Transport)
tm.add(Transport.prototype[Symbol.toStringTag], Transport, { filter: filters.all })
const addr = multiaddr('/ip4/127.0.0.1/tcp/0')
await expect(tm.dial(addr))
.to.eventually.be.rejected()
.and.to.have.property('code', ErrorCodes.ERR_TRANSPORT_UNAVAILABLE)
})

it('should fail to listen with no valid address', async () => {
tm.add(Transport.prototype[Symbol.toStringTag], Transport)
tm.add(Transport.prototype[Symbol.toStringTag], Transport, { filter: filters.all })

await expect(tm.listen([listenAddr]))
.to.eventually.be.rejected()
Expand Down
8 changes: 8 additions & 0 deletions test/utils/base-options.browser.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
'use strict'

const Transport = require('libp2p-websockets')
const filters = require('libp2p-websockets/src/filters')
const Muxer = require('libp2p-mplex')
const { NOISE: Crypto } = require('libp2p-noise')

const transportKey = Transport.prototype[Symbol.toStringTag]

module.exports = {
modules: {
transport: [Transport],
Expand All @@ -16,6 +19,11 @@ module.exports = {
hop: {
enabled: false
}
},
transport: {
[transportKey]: {
filter: filters.all
}
}
}
}