@libp2p/interface-compliance-tests 6.1.8 → 6.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/matchers.d.ts +6 -0
- package/dist/src/matchers.d.ts.map +1 -1
- package/dist/src/matchers.js +6 -0
- package/dist/src/matchers.js.map +1 -1
- package/dist/src/mocks/index.d.ts +0 -2
- package/dist/src/mocks/index.d.ts.map +1 -1
- package/dist/src/mocks/index.js +0 -2
- package/dist/src/mocks/index.js.map +1 -1
- package/dist/src/mocks/muxer.d.ts +8 -3
- package/dist/src/mocks/muxer.d.ts.map +1 -1
- package/dist/src/mocks/muxer.js +15 -6
- package/dist/src/mocks/muxer.js.map +1 -1
- package/dist/src/mocks/upgrader.d.ts.map +1 -1
- package/dist/src/mocks/upgrader.js +0 -1
- package/dist/src/mocks/upgrader.js.map +1 -1
- package/dist/src/transport/index.d.ts +23 -10
- package/dist/src/transport/index.d.ts.map +1 -1
- package/dist/src/transport/index.js +418 -6
- package/dist/src/transport/index.js.map +1 -1
- package/dist/src/transport/utils.d.ts +17 -0
- package/dist/src/transport/utils.d.ts.map +1 -0
- package/dist/src/transport/utils.js +63 -0
- package/dist/src/transport/utils.js.map +1 -0
- package/dist/typedoc-urls.json +1 -6
- package/package.json +11 -10
- package/src/matchers.ts +6 -0
- package/src/mocks/index.ts +0 -2
- package/src/mocks/muxer.ts +24 -10
- package/src/mocks/upgrader.ts +1 -3
- package/src/transport/index.ts +570 -16
- package/src/transport/utils.ts +76 -0
- package/dist/src/connection/index.d.ts +0 -5
- package/dist/src/connection/index.d.ts.map +0 -1
- package/dist/src/connection/index.js +0 -135
- package/dist/src/connection/index.js.map +0 -1
- package/dist/src/mocks/connection-gater.d.ts +0 -3
- package/dist/src/mocks/connection-gater.d.ts.map +0 -1
- package/dist/src/mocks/connection-gater.js +0 -17
- package/dist/src/mocks/connection-gater.js.map +0 -1
- package/dist/src/mocks/metrics.d.ts +0 -3
- package/dist/src/mocks/metrics.d.ts.map +0 -1
- package/dist/src/mocks/metrics.js +0 -286
- package/dist/src/mocks/metrics.js.map +0 -1
- package/dist/src/mocks/peer-discovery.d.ts +0 -21
- package/dist/src/mocks/peer-discovery.d.ts.map +0 -1
- package/dist/src/mocks/peer-discovery.js +0 -47
- package/dist/src/mocks/peer-discovery.js.map +0 -1
- package/dist/src/transport/dial-test.d.ts +0 -5
- package/dist/src/transport/dial-test.d.ts.map +0 -1
- package/dist/src/transport/dial-test.js +0 -99
- package/dist/src/transport/dial-test.js.map +0 -1
- package/dist/src/transport/filter-test.d.ts +0 -5
- package/dist/src/transport/filter-test.d.ts.map +0 -1
- package/dist/src/transport/filter-test.js +0 -24
- package/dist/src/transport/filter-test.js.map +0 -1
- package/dist/src/transport/listen-test.d.ts +0 -5
- package/dist/src/transport/listen-test.d.ts.map +0 -1
- package/dist/src/transport/listen-test.js +0 -154
- package/dist/src/transport/listen-test.js.map +0 -1
- package/src/connection/index.ts +0 -166
- package/src/mocks/connection-gater.ts +0 -18
- package/src/mocks/metrics.ts +0 -385
- package/src/mocks/peer-discovery.ts +0 -59
- package/src/transport/dial-test.ts +0 -125
- package/src/transport/filter-test.ts +0 -32
- package/src/transport/listen-test.ts +0 -192
package/src/matchers.ts
CHANGED
|
@@ -2,10 +2,16 @@ import Sinon from 'sinon'
|
|
|
2
2
|
import type { PeerId } from '@libp2p/interface'
|
|
3
3
|
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* @deprecated PeerIds can be passed to sinon matchers directly
|
|
7
|
+
*/
|
|
5
8
|
export function matchPeerId (peerId: PeerId): Sinon.SinonMatcher {
|
|
6
9
|
return Sinon.match(p => p.toString() === peerId.toString())
|
|
7
10
|
}
|
|
8
11
|
|
|
12
|
+
/**
|
|
13
|
+
* @deprecated Multiaddrs can be passed to sinon matchers directly
|
|
14
|
+
*/
|
|
9
15
|
export function matchMultiaddr (ma: Multiaddr): Sinon.SinonMatcher {
|
|
10
16
|
return Sinon.match(m => m.toString() === ma.toString())
|
|
11
17
|
}
|
package/src/mocks/index.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export { mockConnectionGater } from './connection-gater.js'
|
|
2
1
|
export { mockConnectionManager, mockNetwork } from './connection-manager.js'
|
|
3
2
|
export { mockConnection, mockStream, streamPair, connectionPair } from './connection.js'
|
|
4
3
|
export { mockMultiaddrConnection, mockMultiaddrConnPair } from './multiaddr-connection.js'
|
|
@@ -6,7 +5,6 @@ export { mockMuxer } from './muxer.js'
|
|
|
6
5
|
export { mockRegistrar } from './registrar.js'
|
|
7
6
|
export { mockUpgrader } from './upgrader.js'
|
|
8
7
|
export { mockDuplex } from './duplex.js'
|
|
9
|
-
export { mockMetrics } from './metrics.js'
|
|
10
8
|
export type { MockUpgraderInit } from './upgrader.js'
|
|
11
9
|
export type { MockNetworkComponents, MockConnectionManagerComponents, MockNetwork } from './connection-manager.js'
|
|
12
10
|
export type { MockConnectionOptions, StreamInit, StreamPairInit } from './connection.js'
|
package/src/mocks/muxer.ts
CHANGED
|
@@ -27,9 +27,15 @@ interface ResetMessage {
|
|
|
27
27
|
direction: Direction
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
interface
|
|
30
|
+
interface CloseWriteMessage {
|
|
31
31
|
id: string
|
|
32
|
-
type: '
|
|
32
|
+
type: 'closeWrite'
|
|
33
|
+
direction: Direction
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
interface CloseReadMessage {
|
|
37
|
+
id: string
|
|
38
|
+
type: 'closeRead'
|
|
33
39
|
direction: Direction
|
|
34
40
|
}
|
|
35
41
|
|
|
@@ -39,7 +45,7 @@ interface CreateMessage {
|
|
|
39
45
|
direction: 'outbound'
|
|
40
46
|
}
|
|
41
47
|
|
|
42
|
-
type StreamMessage = DataMessage | ResetMessage |
|
|
48
|
+
type StreamMessage = DataMessage | ResetMessage | CloseWriteMessage | CloseReadMessage | CreateMessage
|
|
43
49
|
|
|
44
50
|
export interface MockMuxedStreamInit extends AbstractStreamInit {
|
|
45
51
|
push: Pushable<StreamMessage>
|
|
@@ -84,16 +90,21 @@ class MuxedStream extends AbstractStream {
|
|
|
84
90
|
}
|
|
85
91
|
|
|
86
92
|
sendCloseWrite (): void {
|
|
87
|
-
const closeMsg:
|
|
93
|
+
const closeMsg: CloseWriteMessage = {
|
|
88
94
|
id: this.id,
|
|
89
|
-
type: '
|
|
95
|
+
type: 'closeWrite',
|
|
90
96
|
direction: this.direction
|
|
91
97
|
}
|
|
92
98
|
this.push.push(closeMsg)
|
|
93
99
|
}
|
|
94
100
|
|
|
95
101
|
sendCloseRead (): void {
|
|
96
|
-
|
|
102
|
+
const closeMsg: CloseReadMessage = {
|
|
103
|
+
id: this.id,
|
|
104
|
+
type: 'closeRead',
|
|
105
|
+
direction: this.direction
|
|
106
|
+
}
|
|
107
|
+
this.push.push(closeMsg)
|
|
97
108
|
}
|
|
98
109
|
}
|
|
99
110
|
|
|
@@ -153,10 +164,10 @@ class MockMuxer implements StreamMuxer {
|
|
|
153
164
|
}
|
|
154
165
|
)
|
|
155
166
|
|
|
156
|
-
this.log('
|
|
167
|
+
this.log('muxer ended')
|
|
157
168
|
this.input.end()
|
|
158
169
|
} catch (err: any) {
|
|
159
|
-
this.log('
|
|
170
|
+
this.log.error('muxer errored - %e', err)
|
|
160
171
|
this.input.end(err)
|
|
161
172
|
}
|
|
162
173
|
}
|
|
@@ -192,9 +203,12 @@ class MockMuxer implements StreamMuxer {
|
|
|
192
203
|
} else if (message.type === 'reset') {
|
|
193
204
|
this.log('-> reset stream %s %s', muxedStream.direction, muxedStream.id)
|
|
194
205
|
muxedStream.reset()
|
|
195
|
-
} else if (message.type === '
|
|
196
|
-
this.log('-> closing stream %s %s', muxedStream.direction, muxedStream.id)
|
|
206
|
+
} else if (message.type === 'closeWrite') {
|
|
207
|
+
this.log('-> closing writeable end of stream %s %s', muxedStream.direction, muxedStream.id)
|
|
197
208
|
muxedStream.remoteCloseWrite()
|
|
209
|
+
} else if (message.type === 'closeRead') {
|
|
210
|
+
this.log('-> closing readable end of stream %s %s', muxedStream.direction, muxedStream.id)
|
|
211
|
+
muxedStream.remoteCloseRead()
|
|
198
212
|
}
|
|
199
213
|
}
|
|
200
214
|
|
package/src/mocks/upgrader.ts
CHANGED
|
@@ -28,7 +28,7 @@ class MockUpgrader implements Upgrader {
|
|
|
28
28
|
return connection
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
async upgradeInbound (multiaddrConnection: MultiaddrConnection, opts: UpgraderOptions = {}): Promise<
|
|
31
|
+
async upgradeInbound (multiaddrConnection: MultiaddrConnection, opts: UpgraderOptions = {}): Promise<void> {
|
|
32
32
|
const connection = mockConnection(multiaddrConnection, {
|
|
33
33
|
direction: 'inbound',
|
|
34
34
|
registrar: this.registrar,
|
|
@@ -36,8 +36,6 @@ class MockUpgrader implements Upgrader {
|
|
|
36
36
|
})
|
|
37
37
|
|
|
38
38
|
this.events?.safeDispatchEvent('connection:open', { detail: connection })
|
|
39
|
-
|
|
40
|
-
return connection
|
|
41
39
|
}
|
|
42
40
|
}
|
|
43
41
|
|