Skip to content

Commit

Permalink
chore: run transport compliance tests on WebRTC and Circuit Relay (#2816
Browse files Browse the repository at this point in the history
)

Runs transport compliance tests with WebRTC and Circuit Relay transports
  • Loading branch information
achingbrain authored Nov 8, 2024
1 parent 18e8e1c commit 02f285f
Show file tree
Hide file tree
Showing 37 changed files with 589 additions and 673 deletions.
7 changes: 4 additions & 3 deletions packages/integration-tests/.aegir.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ export default {
],
streamMuxers: [
yamux(),
mplex(),
() => mockMuxer()
() => mockMuxer(),
mplex()
],
connectionEncrypters: [
noise(),
Expand All @@ -48,7 +48,8 @@ export default {
identify: identify(),
relay: circuitRelayServer({
reservations: {
maxReservations: Infinity
maxReservations: Infinity,
applyDefaultLimit: false
}
}),
echo: echo({
Expand Down
6 changes: 3 additions & 3 deletions packages/integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
},
"scripts": {
"build": "aegir build",
"test": "aegir test",
"test": "aegir test -- --exit",
"clean": "aegir clean",
"lint": "aegir lint",
"test:chrome": "aegir test -t browser --cov",
"test:chrome-webworker": "aegir test -t webworker",
"test:firefox": "aegir test -t browser -- --browser firefox",
"test:firefox-webworker": "aegir test -t webworker -- --browser firefox",
"test:node": "aegir test -t node --cov",
"test:node": "aegir test -t node --cov -- --exit",
"test:interop": "aegir test -t node -f dist/test/interop.js",
"dep-check": "aegir dep-check"
},
Expand All @@ -50,7 +50,7 @@
"@libp2p/interface-compliance-tests": "^6.0.0",
"@libp2p/interface-internal": "^2.0.0",
"@libp2p/interop": "^13.0.0",
"@libp2p/kad-dht": "^13.0.0",
"@libp2p/kad-dht": "^14.0.0",
"@libp2p/logger": "^5.0.0",
"@libp2p/mdns": "^11.0.0",
"@libp2p/memory": "^0.0.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/* eslint-env mocha */

import { noise } from '@chainsafe/libp2p-noise'
import { yamux } from '@chainsafe/libp2p-yamux'
import { circuitRelayTransport } from '@libp2p/circuit-relay-v2'
import { identify } from '@libp2p/identify'
import tests from '@libp2p/interface-compliance-tests/transport'
import { webSockets } from '@libp2p/websockets'
import { all } from '@libp2p/websockets/filters'
import { Circuit, P2P } from '@multiformats/multiaddr-matcher'
import { and, fmt, literal } from '@multiformats/multiaddr-matcher/utils'

export const CircuitListen = fmt(
and(P2P.matchers[0], literal('p2p-circuit'))
)

describe('Circuit relay transport interface compliance', () => {
tests({
async setup () {
const dialer = {
transports: [
circuitRelayTransport(),
webSockets({
filter: all
})
],
connectionEncrypters: [
noise()
],
streamMuxers: [
yamux()
],
services: {
identify: identify()
},
connectionGater: {
denyDialMultiaddr: () => false
}
}

return {
dialer,
listener: {
addresses: {
listen: [
`${process.env.RELAY_WS_MULTIADDR_0}/p2p-circuit`,
`${process.env.RELAY_WS_MULTIADDR_1}/p2p-circuit`
]
},
...dialer
},
dialMultiaddrMatcher: Circuit,
listenMultiaddrMatcher: CircuitListen
}
},
async teardown () {}
})
})
Original file line number Diff line number Diff line change
@@ -1,18 +1,38 @@
import { noise } from '@chainsafe/libp2p-noise'
import { yamux } from '@chainsafe/libp2p-yamux'
import tests from '@libp2p/interface-compliance-tests/transport'
import { memory } from '@libp2p/memory'
import { multiaddr } from '@multiformats/multiaddr'
import type { Multiaddr } from '@multiformats/multiaddr'
import { Memory } from '@multiformats/multiaddr-matcher'

describe('memory transport interface compliance tests', () => {
tests({
async setup () {
const transport = memory()
const dialAddrs: [Multiaddr, Multiaddr] = [
multiaddr('/memory/addr-1'),
multiaddr('/memory/addr-2')
]
const dialer = {
transports: [
memory()
],
connectionEncrypters: [
noise()
],
streamMuxers: [
yamux()
]
}

return { transport, dialAddrs }
return {
dialer,
listener: {
addresses: {
listen: [
'/memory/addr-1',
'/memory/addr-2'
]
},
...dialer
},
dialMultiaddrMatcher: Memory,
listenMultiaddrMatcher: Memory
}
},
async teardown () {}
})
Expand Down
67 changes: 53 additions & 14 deletions packages/integration-tests/test/compliance/transport/tcp.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { noise } from '@chainsafe/libp2p-noise'
import { yamux } from '@chainsafe/libp2p-yamux'
import tests from '@libp2p/interface-compliance-tests/transport'
import { tcp } from '@libp2p/tcp'
import { multiaddr } from '@multiformats/multiaddr'
import { TCP } from '@multiformats/multiaddr-matcher'
import { isBrowser, isWebWorker } from 'wherearewe'
import type { Multiaddr } from '@multiformats/multiaddr'

describe('tcp transport interface compliance IPv4', () => {
if (isBrowser || isWebWorker) {
Expand All @@ -11,13 +12,32 @@ describe('tcp transport interface compliance IPv4', () => {

tests({
async setup () {
const transport = tcp()
const dialAddrs: [Multiaddr, Multiaddr] = [
multiaddr('/ip4/127.0.0.1/tcp/9091'),
multiaddr('/ip4/127.0.0.1/tcp/9092')
]
const dialer = {
transports: [
tcp()
],
connectionEncrypters: [
noise()
],
streamMuxers: [
yamux()
]
}

return { transport, dialAddrs }
return {
dialer,
listener: {
addresses: {
listen: [
'/ip4/127.0.0.1/tcp/0',
'/ip4/127.0.0.1/tcp/0'
]
},
...dialer
},
dialMultiaddrMatcher: TCP,
listenMultiaddrMatcher: TCP
}
},
async teardown () {}
})
Expand All @@ -30,13 +50,32 @@ describe('tcp transport interface compliance IPv6', () => {

tests({
async setup () {
const transport = tcp()
const dialAddrs: [Multiaddr, Multiaddr] = [
multiaddr('/ip6/::/tcp/9093'),
multiaddr('/ip6/::/tcp/9094')
]
const dialer = {
transports: [
tcp()
],
connectionEncrypters: [
noise()
],
streamMuxers: [
yamux()
]
}

return { transport, dialAddrs }
return {
dialer,
listener: {
addresses: {
listen: [
'/ip6/::/tcp/0',
'/ip6/::/tcp/0'
]
},
...dialer
},
dialMultiaddrMatcher: TCP,
listenMultiaddrMatcher: TCP
}
},
async teardown () {}
})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/* eslint-env mocha */

import { noise } from '@chainsafe/libp2p-noise'
import { yamux } from '@chainsafe/libp2p-yamux'
import { circuitRelayTransport } from '@libp2p/circuit-relay-v2'
import { identify } from '@libp2p/identify'
import tests from '@libp2p/interface-compliance-tests/transport'
import { webRTC } from '@libp2p/webrtc'
import { webSockets } from '@libp2p/websockets'
import { all } from '@libp2p/websockets/filters'
import { WebRTC } from '@multiformats/multiaddr-matcher'
import { isWebWorker } from 'wherearewe'

describe('WebRTC transport interface compliance', () => {
if (isWebWorker) {
return
}

tests({
async setup () {
const dialer = {
transports: [
circuitRelayTransport(),
webSockets({
filter: all
}),
webRTC()
],
connectionEncrypters: [
noise()
],
streamMuxers: [
yamux()
],
services: {
identify: identify()
},
connectionGater: {
denyDialMultiaddr: () => false
}
}

return {
dialer,
listener: {
addresses: {
listen: [
`${process.env.RELAY_WS_MULTIADDR_0}/p2p-circuit`,
`${process.env.RELAY_WS_MULTIADDR_1}/p2p-circuit`,
'/webrtc'
]
},
...dialer
},
dialMultiaddrMatcher: WebRTC,
listenMultiaddrMatcher: WebRTC
}
},
async teardown () {}
})
})
Original file line number Diff line number Diff line change
@@ -1,35 +1,57 @@
/* eslint-env mocha */

import { noise } from '@chainsafe/libp2p-noise'
import { yamux } from '@chainsafe/libp2p-yamux'
import tests from '@libp2p/interface-compliance-tests/transport'
import { webSockets } from '@libp2p/websockets'
import * as filters from '@libp2p/websockets/filters'
import { all } from '@libp2p/websockets/filters'
import { multiaddr } from '@multiformats/multiaddr'
import { WebSockets } from '@multiformats/multiaddr-matcher'
import { isElectronMain, isNode } from 'wherearewe'
import type { Multiaddr } from '@multiformats/multiaddr'

describe('websocket transport interface compliance', () => {
tests({
async setup () {
const dialOnly = !isNode && !isElectronMain
const canListen = isNode || isElectronMain

const transport = webSockets({ filter: filters.all })
let dialAddrs: [Multiaddr, Multiaddr] = [
multiaddr('/ip4/127.0.0.1/tcp/9096/ws'),
multiaddr('/ip4/127.0.0.1/tcp/9097/ws')
]

if (dialOnly) {
dialAddrs = [
multiaddr(process.env.RELAY_WS_MULTIADDR_0),
multiaddr(process.env.RELAY_WS_MULTIADDR_1)
]
const dialer = {
transports: [
webSockets({
filter: all
})
],
connectionEncrypters: [
noise()
],
streamMuxers: [
yamux()
],
connectionGater: {
denyDialMultiaddr: () => false
}
}

return {
transport,
listenAddrs: dialOnly ? undefined : dialAddrs,
dialAddrs,
dialOnly
dialer,
listener: canListen
? {
addresses: {
listen: [
'/ip4/127.0.0.1/tcp/0/ws',
'/ip4/127.0.0.1/tcp/0/ws'
]
},
...dialer
}
: undefined,
dialAddrs: canListen
? undefined
: [
multiaddr(process.env.RELAY_WS_MULTIADDR_0 ?? ''),
multiaddr(process.env.RELAY_WS_MULTIADDR_1 ?? '')
],
dialMultiaddrMatcher: WebSockets,
listenMultiaddrMatcher: WebSockets
}
},
async teardown () {}
Expand Down
1 change: 1 addition & 0 deletions packages/interface-compliance-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
"@libp2p/plaintext": "^2.0.10",
"@libp2p/utils": "^6.1.3",
"@multiformats/multiaddr": "^12.2.3",
"@multiformats/multiaddr-matcher": "^1.5.0",
"abortable-iterator": "^5.0.1",
"aegir": "^44.0.1",
"delay": "^6.0.0",
Expand Down
Loading

0 comments on commit 02f285f

Please sign in to comment.