33import { type CreateListenerOptions , symbol } from '@libp2p/interface/transport'
44import { mockMetrics , mockUpgrader } from '@libp2p/interface-compliance-tests/mocks'
55import { createEd25519PeerId } from '@libp2p/peer-id-factory'
6- import { multiaddr , type Multiaddr } from '@multiformats/multiaddr'
7- import { expect , assert } from 'aegir/chai'
6+ import { multiaddr } from '@multiformats/multiaddr'
7+ import { expect } from 'aegir/chai'
88import { UnimplementedError } from '../src/error.js'
9- import * as underTest from '../src/private-to-public/transport.js'
9+ import { WebRTCDirectTransport , type WebRTCDirectTransportComponents } from '../src/private-to-public/transport.js'
1010import { expectError } from './util.js'
1111import type { Metrics } from '@libp2p/interface/metrics'
1212
@@ -15,9 +15,9 @@ function ignoredDialOption (): CreateListenerOptions {
1515 return { upgrader }
1616}
1717
18- describe ( 'WebRTC Transport' , ( ) => {
18+ describe ( 'WebRTCDirect Transport' , ( ) => {
1919 let metrics : Metrics
20- let components : underTest . WebRTCDirectTransportComponents
20+ let components : WebRTCDirectTransportComponents
2121
2222 before ( async ( ) => {
2323 metrics = mockMetrics ( ) ( )
@@ -28,21 +28,21 @@ describe('WebRTC Transport', () => {
2828 } )
2929
3030 it ( 'can construct' , ( ) => {
31- const t = new underTest . WebRTCDirectTransport ( components )
31+ const t = new WebRTCDirectTransport ( components )
3232 expect ( t . constructor . name ) . to . equal ( 'WebRTCDirectTransport' )
3333 } )
3434
3535 it ( 'can dial' , async ( ) => {
3636 const ma = multiaddr ( '/ip4/1.2.3.4/udp/1234/webrtc-direct/certhash/uEiAUqV7kzvM1wI5DYDc1RbcekYVmXli_Qprlw3IkiEg6tQ/p2p/12D3KooWGDMwwqrpcYKpKCgxuKT2NfqPqa94QnkoBBpqvCaiCzWd' )
37- const transport = new underTest . WebRTCDirectTransport ( components )
37+ const transport = new WebRTCDirectTransport ( components )
3838 const options = ignoredDialOption ( )
3939
4040 // don't await as this isn't an e2e test
4141 transport . dial ( ma , options )
4242 } )
4343
4444 it ( 'createListner throws' , ( ) => {
45- const t = new underTest . WebRTCDirectTransport ( components )
45+ const t = new WebRTCDirectTransport ( components )
4646 try {
4747 t . createListener ( ignoredDialOption ( ) )
4848 expect ( 'Should have thrown' ) . to . equal ( 'but did not' )
@@ -52,38 +52,38 @@ describe('WebRTC Transport', () => {
5252 } )
5353
5454 it ( 'toString property getter' , ( ) => {
55- const t = new underTest . WebRTCDirectTransport ( components )
55+ const t = new WebRTCDirectTransport ( components )
5656 const s = t [ Symbol . toStringTag ]
5757 expect ( s ) . to . equal ( '@libp2p/webrtc-direct' )
5858 } )
5959
6060 it ( 'symbol property getter' , ( ) => {
61- const t = new underTest . WebRTCDirectTransport ( components )
61+ const t = new WebRTCDirectTransport ( components )
6262 const s = t [ symbol ]
6363 expect ( s ) . to . equal ( true )
6464 } )
6565
6666 it ( 'transport filter filters out invalid multiaddrs' , async ( ) => {
67- const mas : Multiaddr [ ] = [
68- '/ip4/1.2.3.4/udp/1234/webrtc/certhash/uEiAUqV7kzvM1wI5DYDc1RbcekYVmXli_Qprlw3IkiEg6tQ' ,
69- '/ip4/1.2.3.4/udp/1234/webrtc-direct/certhash/uEiAUqV7kzvM1wI5DYDc1RbcekYVmXli_Qprlw3IkiEg6tQ/p2p/12D3KooWGDMwwqrpcYKpKCgxuKT2NfqPqa94QnkoBBpqvCaiCzWd' ,
70- '/ip4/1.2.3.4/udp/1234/webrtc-direct/p2p/12D3KooWGDMwwqrpcYKpKCgxuKT2NfqPqa94QnkoBBpqvCaiCzWd' ,
71- '/ip4/1.2.3.4/udp/1234/certhash/uEiAUqV7kzvM1wI5DYDc1RbcekYVmXli_Qprlw3IkiEg6tQ/p2p/12D3KooWGDMwwqrpcYKpKCgxuKT2NfqPqa94QnkoBBpqvCaiCzWd'
72- ] . map ( ( s ) => multiaddr ( s ) )
73- const t = new underTest . WebRTCDirectTransport ( components )
74- const result = t . filter ( mas )
75- const expected =
67+ const valid = [
7668 multiaddr ( '/ip4/1.2.3.4/udp/1234/webrtc-direct/certhash/uEiAUqV7kzvM1wI5DYDc1RbcekYVmXli_Qprlw3IkiEg6tQ/p2p/12D3KooWGDMwwqrpcYKpKCgxuKT2NfqPqa94QnkoBBpqvCaiCzWd' )
69+ ]
70+ const invalid = [
71+ multiaddr ( '/ip4/1.2.3.4/udp/1234/webrtc/certhash/uEiAUqV7kzvM1wI5DYDc1RbcekYVmXli_Qprlw3IkiEg6tQ' ) ,
72+ multiaddr ( '/ip4/1.2.3.4/udp/1234/webrtc-direct/p2p/12D3KooWGDMwwqrpcYKpKCgxuKT2NfqPqa94QnkoBBpqvCaiCzWd' ) ,
73+ multiaddr ( '/ip4/1.2.3.4/udp/1234/certhash/uEiAUqV7kzvM1wI5DYDc1RbcekYVmXli_Qprlw3IkiEg6tQ/p2p/12D3KooWGDMwwqrpcYKpKCgxuKT2NfqPqa94QnkoBBpqvCaiCzWd' )
74+ ]
7775
78- assert . isNotNull ( result )
79- expect ( result . constructor . name ) . to . equal ( 'Array' )
80- expect ( result ) . to . have . length ( 1 )
81- expect ( result [ 0 ] . equals ( expected ) ) . to . be . true ( )
76+ const t = new WebRTCDirectTransport ( components )
77+
78+ expect ( t . filter ( [
79+ ...valid ,
80+ ...invalid
81+ ] ) ) . to . deep . equal ( valid )
8282 } )
8383
8484 it ( 'throws WebRTC transport error when dialing a multiaddr without a PeerId' , async ( ) => {
8585 const ma = multiaddr ( '/ip4/1.2.3.4/udp/1234/webrtc-direct/certhash/uEiAUqV7kzvM1wI5DYDc1RbcekYVmXli_Qprlw3IkiEg6tQ' )
86- const transport = new underTest . WebRTCDirectTransport ( components )
86+ const transport = new WebRTCDirectTransport ( components )
8787
8888 try {
8989 await transport . dial ( ma , ignoredDialOption ( ) )
0 commit comments