diff --git a/packages/transport-webrtc/test/compliance.spec.ts b/packages/transport-webrtc/test/compliance.spec.ts index 42d0df752c..aa129393ce 100644 --- a/packages/transport-webrtc/test/compliance.spec.ts +++ b/packages/transport-webrtc/test/compliance.spec.ts @@ -2,71 +2,59 @@ import tests from '@libp2p/interface-compliance-tests/transport' import { multiaddr } from '@multiformats/multiaddr' -import { webRTC } from '../src/index.js' import { connectionPair, mockUpgrader } from '@libp2p/interface-compliance-tests/mocks' import { mockRegistrar } from '@libp2p/interface-compliance-tests/mocks' import { createEd25519PeerId } from '@libp2p/peer-id-factory' import type { TransportManager } from '@libp2p/interface-internal/transport-manager' import { stubInterface } from 'sinon-ts' import type { Connection } from '@libp2p/interface/connection' -import { SIGNALING_PROTO_ID } from '../src/private-to-private/transport.js' +import { SIGNALING_PROTO_ID, WebRTCTransport } from '../src/private-to-private/transport.js' import { pipe } from 'it-pipe' import drain from 'it-drain' - - - describe('interface-transport compliance', () => { tests({ async setup() { - const peerId = await createEd25519PeerId() - - const fakeDial = async (): Promise => { - // const connection = mockConnection(mockMultiaddrConnection(mockDuplex(), peerId)) - // const newStreamStub = sinon.stub().withArgs(SIGNALING_PROTO_ID).resolves({ close: sinon.stub(), abort: sinon.stub() }) - - // connection.newStream = newStreamStub - - const peerA = { - peerId: await createEd25519PeerId(), - registrar: mockRegistrar() - } + const peerAId = await createEd25519PeerId() + const peerBId = await createEd25519PeerId() + const fakeDial = async (peerA: any): Promise => { const peerB = { - peerId: await createEd25519PeerId(), - registrar: mockRegistrar() + peerId: peerBId, + registrar: mockRegistrar(), + upgrader: mockUpgrader() } await peerB.registrar.handle(SIGNALING_PROTO_ID, ({ stream }) => { void pipe(stream, drain) }) - const [connectionA] = connectionPair(peerA, peerB) + const [_, connectionToB] = connectionPair(peerA, peerB) - return connectionA + return connectionToB } - const components: any = { - peerId, + const peerA: any = { + peerAId, registrar: mockRegistrar(), upgrader: mockUpgrader(), - transportManager: stubInterface({ - dial: fakeDial(), - }), } - const wrtc = webRTC()(components) + peerA.transportManager = stubInterface({ + dial: fakeDial(peerA), + }) + + const wrtc = new WebRTCTransport(peerA) + + await wrtc.start() const addrs = [ - multiaddr('/ip4/127.0.0.1/tcp/9091/ws'), - multiaddr('/ip4/127.0.0.1/tcp/9092/ws'), - multiaddr('/dns4/ipfs.io/tcp/9092/ws'), - multiaddr('/dns4/ipfs.io/tcp/9092/ws') + multiaddr('/ip4/1.2.3.4/udp/1234/webrtc-direct/certhash/uEiAUqV7kzvM1wI5DYDc1RbcekYVmXli_Qprlw3IkiEg6tQ/p2p/12D3KooWGDMwwqrpcYKpKCgxuKT2NfqPqa94QnkoBBpqvCaiCzWd') ] const listeningAddrs = [ - multiaddr('/ip4/127.0.0.1/tcp/57708/ws/p2p/12D3KooWRqAUEzPwKMoGstpfJVqr3aoinwKVPu4DLo9nQncbnuLk/p2p-circuit/p2p/12D3KooWBZyVLJfQkofqLK4op9TPkHuUumCZt1ybQrPvNm7TVQV9/p2p-circuit/webrtc/p2p/12D3KooWBZyVLJfQkofqLK4op9TPkHuUumCZt1ybQrPvNm7TVQV9'), + multiaddr(`/ip4/127.0.0.1/tcp/57708/ws/p2p/12D3KooWRqAUEzPwKMoGstpfJVqr3aoinwKVPu4DLo9nQncbnuLk/p2p-circuit/p2p/${peerBId}/p2p-circuit/webrtc/p2p/${peerBId}`), ] // Used by the dial tests to simulate a delayed connect