Skip to content

Commit

Permalink
test: added webRTC webkit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maschad committed Jun 21, 2023
1 parent 327e5cb commit c0c2f07
Show file tree
Hide file tree
Showing 18 changed files with 76 additions and 64 deletions.
29 changes: 18 additions & 11 deletions packages/transport-webrtc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,24 @@
"test": "aegir test -t browser",
"test:chrome": "aegir test -t browser --cov",
"test:firefox": "aegir test -t browser -- --browser firefox",
"test:webkit": "aegir test -t browser -- --browser webkit",
"lint": "aegir lint",
"lint:fix": "aegir lint --fix",
"clean": "aegir clean",
"dep-check": "aegir dep-check"
"dep-check": "aegir dep-check -i protons"
},
"dependencies": {
"@chainsafe/libp2p-noise": "^12.0.1",
"@libp2p/interface": "~0.0.1",
"@libp2p/interface-internal": "~0.0.1",
"@libp2p/logger": "^2.0.0",
"@libp2p/peer-id": "^2.0.0",
"@multiformats/mafmt": "^12.1.2",
"@libp2p/interface-connection": "^5.1.1",
"@libp2p/interface-metrics": "^4.0.8",
"@libp2p/interface-peer-id": "^2.0.2",
"@libp2p/interface-registrar": "^2.0.12",
"@libp2p/interface-stream-muxer": "^4.1.2",
"@libp2p/interface-transport": "^4.0.3",
"@libp2p/interfaces": "^3.3.2",
"@libp2p/logger": "^2.1.1",
"@libp2p/peer-id": "^2.0.4",
"@multiformats/mafmt": "^12.1.5",
"@multiformats/multiaddr": "^12.1.3",
"abortable-iterator": "^5.0.1",
"detect-browser": "^5.3.0",
Expand All @@ -68,17 +74,18 @@
"uint8arrays": "^4.0.4"
},
"devDependencies": {
"@chainsafe/libp2p-yamux": "^4.0.1",
"@libp2p/interface-compliance-tests": "^3.0.0",
"@libp2p/peer-id-factory": "^2.0.0",
"@libp2p/websockets": "^6.0.0",
"@chainsafe/libp2p-yamux": "^4.0.2",
"@libp2p/interface-libp2p": "^3.2.0",
"@libp2p/interface-mocks": "^12.0.1",
"@libp2p/peer-id-factory": "^2.0.4",
"@libp2p/websockets": "^6.0.3",
"@types/sinon": "^10.0.15",
"aegir": "^39.0.10",
"delay": "^6.0.0",
"it-length": "^3.0.2",
"it-map": "^3.0.3",
"it-pair": "^2.0.6",
"libp2p": "^0.45.0",
"libp2p": "^0.45.9",
"protons": "^7.0.2",
"sinon": "^15.1.2",
"sinon-ts": "^1.0.0"
Expand Down
4 changes: 2 additions & 2 deletions packages/transport-webrtc/src/error.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CodeError } from '@libp2p/interface/errors'
import type { Direction } from '@libp2p/interface/connection'
import { CodeError } from '@libp2p/interfaces/errors'
import type { Direction } from '@libp2p/interface-connection'

export enum codes {
ERR_ALREADY_ABORTED = 'ERR_ALREADY_ABORTED',
Expand Down
2 changes: 1 addition & 1 deletion packages/transport-webrtc/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { WebRTCTransport } from './private-to-private/transport.js'
import { WebRTCDirectTransport, type WebRTCTransportDirectInit, type WebRTCDirectTransportComponents } from './private-to-public/transport.js'
import type { WebRTCTransportComponents, WebRTCTransportInit } from './private-to-private/transport.js'
import type { Transport } from '@libp2p/interface/transport'
import type { Transport } from '@libp2p/interface-transport'

/**
* @param {WebRTCTransportDirectInit} init - WebRTC direct transport configuration
Expand Down
4 changes: 2 additions & 2 deletions packages/transport-webrtc/src/maconn.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { logger } from '@libp2p/logger'
import { nopSink, nopSource } from './util.js'
import type { MultiaddrConnection, MultiaddrConnectionTimeline } from '@libp2p/interface/connection'
import type { CounterGroup } from '@libp2p/interface/metrics'
import type { MultiaddrConnection, MultiaddrConnectionTimeline } from '@libp2p/interface-connection'
import type { CounterGroup } from '@libp2p/interface-metrics'
import type { Multiaddr } from '@multiformats/multiaddr'
import type { Source, Sink } from 'it-stream-types'

Expand Down
6 changes: 3 additions & 3 deletions packages/transport-webrtc/src/muxer.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { createStream } from './stream.js'
import { nopSink, nopSource } from './util.js'
import type { DataChannelOpts } from './stream.js'
import type { Stream } from '@libp2p/interface/connection'
import type { CounterGroup } from '@libp2p/interface/metrics'
import type { StreamMuxer, StreamMuxerFactory, StreamMuxerInit } from '@libp2p/interface/stream-muxer'
import type { Stream } from '@libp2p/interface-connection'
import type { CounterGroup } from '@libp2p/interface-metrics'
import type { StreamMuxer, StreamMuxerFactory, StreamMuxerInit } from '@libp2p/interface-stream-muxer'
import type { Source, Sink } from 'it-stream-types'
import type { Uint8ArrayList } from 'uint8arraylist'

Expand Down
6 changes: 3 additions & 3 deletions packages/transport-webrtc/src/private-to-private/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { DataChannelMuxerFactory } from '../muxer.js'
import { Message } from './pb/message.js'
import { readCandidatesUntilConnected, resolveOnConnected } from './util.js'
import type { DataChannelOpts } from '../stream.js'
import type { Stream } from '@libp2p/interface/connection'
import type { StreamMuxerFactory } from '@libp2p/interface/stream-muxer'
import type { IncomingStreamData } from '@libp2p/interface-internal/registrar'
import type { Stream } from '@libp2p/interface-connection'
import type { IncomingStreamData } from '@libp2p/interface-registrar'
import type { StreamMuxerFactory } from '@libp2p/interface-stream-muxer'

const DEFAULT_TIMEOUT = 30 * 1000

Expand Down
7 changes: 3 additions & 4 deletions packages/transport-webrtc/src/private-to-private/listener.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { EventEmitter } from '@libp2p/interface/events'
import { EventEmitter } from '@libp2p/interfaces/events'
import { Circuit } from '@multiformats/mafmt'
import type { PeerId } from '@libp2p/interface/peer-id'
import type { ListenerEvents, Listener } from '@libp2p/interface/transport'
import type { TransportManager } from '@libp2p/interface-internal/transport-manager'
import type { PeerId } from '@libp2p/interface-peer-id'
import type { ListenerEvents, Listener, TransportManager } from '@libp2p/interface-transport'
import type { Multiaddr } from '@multiformats/multiaddr'

export interface ListenerOptions {
Expand Down
13 changes: 6 additions & 7 deletions packages/transport-webrtc/src/private-to-private/transport.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CodeError } from '@libp2p/interface/errors'
import { type CreateListenerOptions, type DialOptions, symbol, type Transport, type Listener, type Upgrader } from '@libp2p/interface/transport'
import { type CreateListenerOptions, type DialOptions, type Listener, symbol, type Transport, type Upgrader, type TransportManager } from '@libp2p/interface-transport'
import { CodeError } from '@libp2p/interfaces/errors'
import { logger } from '@libp2p/logger'
import { peerIdFromString } from '@libp2p/peer-id'
import { multiaddr, type Multiaddr, protocols } from '@multiformats/multiaddr'
Expand All @@ -8,11 +8,10 @@ import { WebRTCMultiaddrConnection } from '../maconn.js'
import { initiateConnection, handleIncomingStream } from './handler.js'
import { WebRTCPeerListener } from './listener.js'
import type { DataChannelOpts } from '../stream.js'
import type { Connection } from '@libp2p/interface/connection'
import type { PeerId } from '@libp2p/interface/peer-id'
import type { Startable } from '@libp2p/interface/startable'
import type { IncomingStreamData, Registrar } from '@libp2p/interface-internal/registrar'
import type { TransportManager } from '@libp2p/interface-internal/transport-manager'
import type { Connection } from '@libp2p/interface-connection'
import type { PeerId } from '@libp2p/interface-peer-id'
import type { IncomingStreamData, Registrar } from '@libp2p/interface-registrar'
import type { Startable } from '@libp2p/interfaces/startable'

const log = logger('libp2p:webrtc:peer')

Expand Down
2 changes: 1 addition & 1 deletion packages/transport-webrtc/src/private-to-public/options.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { CreateListenerOptions, DialOptions } from '@libp2p/interface/transport'
import type { CreateListenerOptions, DialOptions } from '@libp2p/interface-transport'

export interface WebRTCListenerOptions extends CreateListenerOptions {}
export interface WebRTCDialOptions extends DialOptions {}
8 changes: 4 additions & 4 deletions packages/transport-webrtc/src/private-to-public/transport.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { noise as Noise } from '@chainsafe/libp2p-noise'
import { type CreateListenerOptions, symbol, type Transport, type Listener } from '@libp2p/interface/transport'
import { type CreateListenerOptions, type Listener, symbol, type Transport } from '@libp2p/interface-transport'
import { logger } from '@libp2p/logger'
import * as p from '@libp2p/peer-id'
import { protocols } from '@multiformats/multiaddr'
Expand All @@ -15,9 +15,9 @@ import * as sdp from './sdp.js'
import { genUfrag } from './util.js'
import type { WebRTCDialOptions } from './options.js'
import type { DataChannelOpts } from '../stream.js'
import type { Connection } from '@libp2p/interface/connection'
import type { CounterGroup, Metrics } from '@libp2p/interface/metrics'
import type { PeerId } from '@libp2p/interface/peer-id'
import type { Connection } from '@libp2p/interface-connection'
import type { CounterGroup, Metrics } from '@libp2p/interface-metrics'
import type { PeerId } from '@libp2p/interface-peer-id'
import type { Multiaddr } from '@multiformats/multiaddr'

const log = logger('libp2p:webrtc:transport')
Expand Down
6 changes: 3 additions & 3 deletions packages/transport-webrtc/src/stream.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { CodeError } from '@libp2p/interface/errors'
import { AbstractStream, type AbstractStreamInit } from '@libp2p/interface/stream-muxer/stream'
import { AbstractStream, type AbstractStreamInit } from '@libp2p/interface-stream-muxer/stream'
import { CodeError } from '@libp2p/interfaces/errors'
import { logger } from '@libp2p/logger'
import * as lengthPrefixed from 'it-length-prefixed'
import { type Pushable, pushable } from 'it-pushable'
import { pEvent, TimeoutError } from 'p-event'
import { Uint8ArrayList } from 'uint8arraylist'
import { Message } from './pb/message.js'
import type { Direction, Stream } from '@libp2p/interface/connection'
import type { Direction, Stream } from '@libp2p/interface-connection'

const log = logger('libp2p:webrtc:stream')

Expand Down
14 changes: 2 additions & 12 deletions packages/transport-webrtc/test/basics.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import { createLibp2p } from 'libp2p'
import { circuitRelayTransport } from 'libp2p/circuit-relay'
import { identifyService } from 'libp2p/identify'
import { webRTC } from '../src/index.js'
import type { Libp2p } from '@libp2p/interface'
import type { Connection } from '@libp2p/interface/connection'
import type { Connection } from '@libp2p/interface-connection'
import type { Libp2p } from '@libp2p/interface-libp2p'

async function createNode (): Promise<Libp2p> {
return createLibp2p({
Expand Down Expand Up @@ -85,16 +85,6 @@ describe('basics', () => {
remoteNode = await createNode()
})

afterEach(async () => {
if (localNode != null) {
await localNode.stop()
}

if (remoteNode != null) {
await remoteNode.stop()
}
})

it('can dial through a relay', async () => {
const connection = await connectNodes()

Expand Down
3 changes: 1 addition & 2 deletions packages/transport-webrtc/test/listener.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { multiaddr } from '@multiformats/multiaddr'
import { expect } from 'aegir/chai'
import { stubInterface } from 'sinon-ts'
import { WebRTCPeerListener } from '../src/private-to-private/listener'
import type { Listener } from '@libp2p/interface/transport'
import type { TransportManager } from '@libp2p/interface-internal/transport-manager'
import type { Listener, TransportManager } from '@libp2p/interface-transport'

describe('webrtc private-to-private listener', () => {
it('should only return relay addresses as webrtc listen addresses', async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/transport-webrtc/test/maconn.browser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { multiaddr } from '@multiformats/multiaddr'
import { expect } from 'aegir/chai'
import { stubObject } from 'sinon-ts'
import { WebRTCMultiaddrConnection } from '../src/maconn.js'
import type { CounterGroup } from '@libp2p/interface/metrics'
import type { CounterGroup } from '@libp2p/interface-metrics'

describe('Multiaddr Connection', () => {
it('can open and close', async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/transport-webrtc/test/peer.browser.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mockConnection, mockMultiaddrConnection, mockRegistrar, mockStream, mockUpgrader } from '@libp2p/interface-compliance-tests/mocks'
import { mockConnection, mockMultiaddrConnection, mockRegistrar, mockStream, mockUpgrader } from '@libp2p/interface-mocks'
import { createEd25519PeerId } from '@libp2p/peer-id-factory'
import { multiaddr } from '@multiformats/multiaddr'
import { expect } from 'aegir/chai'
Expand Down
2 changes: 1 addition & 1 deletion packages/transport-webrtc/test/stream.browser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as lengthPrefixed from 'it-length-prefixed'
import { bytes } from 'multiformats'
import { Message } from '../src/pb/message.js'
import { createStream } from '../src/stream'
import type { Stream } from '@libp2p/interface/connection'
import type { Stream } from '@libp2p/interface-connection'
const TEST_MESSAGE = 'test_message'

function setup (): { peerConnection: RTCPeerConnection, dataChannel: RTCDataChannel, stream: Stream } {
Expand Down
6 changes: 3 additions & 3 deletions packages/transport-webrtc/test/transport.browser.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/* eslint-disable @typescript-eslint/no-floating-promises */

import { type CreateListenerOptions, symbol } from '@libp2p/interface/transport'
import { mockMetrics, mockUpgrader } from '@libp2p/interface-compliance-tests/mocks'
import { mockMetrics, mockUpgrader } from '@libp2p/interface-mocks'
import { type CreateListenerOptions, symbol } from '@libp2p/interface-transport'
import { createEd25519PeerId } from '@libp2p/peer-id-factory'
import { multiaddr, type Multiaddr } from '@multiformats/multiaddr'
import { expect, assert } from 'aegir/chai'
import { UnimplementedError } from '../src/error.js'
import * as underTest from '../src/private-to-public/transport.js'
import { expectError } from './util.js'
import type { Metrics } from '@libp2p/interface/metrics'
import type { Metrics } from '@libp2p/interface-metrics'

function ignoredDialOption (): CreateListenerOptions {
const upgrader = mockUpgrader({})
Expand Down
24 changes: 21 additions & 3 deletions packages/transport-webrtc/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,31 @@
],
"references": [
{
"path": "../interface"
"path": "../interface-connection"
},
{
"path": "../interface-compliance-tests"
"path": "../interface-libp2p"
},
{
"path": "../interface-internal"
"path": "../interface-metrics"
},
{
"path": "../interface-mocks"
},
{
"path": "../interface-peer-id"
},
{
"path": "../interface-registrar"
},
{
"path": "../interface-stream-muxer"
},
{
"path": "../interface-transport"
},
{
"path": "../interfaces"
},
{
"path": "../libp2p"
Expand Down

0 comments on commit c0c2f07

Please sign in to comment.