@libp2p/interface-compliance-tests 0.2.0 → 1.0.3
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/crypto/index.d.ts.map +1 -1
- package/dist/src/crypto/index.js +7 -8
- package/dist/src/crypto/index.js.map +1 -1
- package/dist/src/crypto/utils/index.d.ts +3 -0
- package/dist/src/crypto/utils/index.d.ts.map +1 -0
- package/dist/src/crypto/utils/index.js +19 -0
- package/dist/src/crypto/utils/index.js.map +1 -0
- package/dist/src/stream-muxer/base-test.d.ts.map +1 -1
- package/dist/src/stream-muxer/base-test.js +26 -23
- package/dist/src/stream-muxer/base-test.js.map +1 -1
- package/dist/src/stream-muxer/close-test.d.ts.map +1 -1
- package/dist/src/stream-muxer/close-test.js +16 -17
- package/dist/src/stream-muxer/close-test.js.map +1 -1
- package/dist/src/stream-muxer/spawner.d.ts.map +1 -1
- package/dist/src/stream-muxer/spawner.js +13 -12
- package/dist/src/stream-muxer/spawner.js.map +1 -1
- package/dist/src/transport/dial-test.js +4 -4
- package/dist/src/transport/dial-test.js.map +1 -1
- package/dist/src/transport/listen-test.d.ts.map +1 -1
- package/dist/src/transport/listen-test.js +13 -9
- package/dist/src/transport/listen-test.js.map +1 -1
- package/dist/src/transport/utils/index.d.ts.map +1 -1
- package/dist/src/transport/utils/index.js +2 -4
- package/dist/src/transport/utils/index.js.map +1 -1
- package/dist/test/connection/index.spec.js +2 -4
- package/dist/test/connection/index.spec.js.map +1 -1
- package/dist/test/crypto/mock-crypto.d.ts.map +1 -1
- package/dist/test/crypto/mock-crypto.js +5 -7
- package/dist/test/crypto/mock-crypto.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +107 -24
- package/src/crypto/index.ts +9 -9
- package/src/crypto/utils/index.ts +24 -0
- package/src/stream-muxer/base-test.ts +36 -31
- package/src/stream-muxer/close-test.ts +16 -17
- package/src/stream-muxer/spawner.ts +14 -13
- package/src/transport/dial-test.ts +4 -4
- package/src/transport/listen-test.ts +14 -10
- package/src/transport/utils/index.ts +4 -6
|
@@ -1,24 +1,29 @@
|
|
|
1
1
|
import { expect } from 'aegir/utils/chai.js'
|
|
2
|
-
|
|
3
|
-
import pair from 'it-pair/duplex.js'
|
|
2
|
+
import { duplexPair } from 'it-pair/duplex'
|
|
4
3
|
import { pipe } from 'it-pipe'
|
|
5
|
-
import
|
|
4
|
+
import drain from 'it-drain'
|
|
5
|
+
import map from 'it-map'
|
|
6
|
+
import all from 'it-all'
|
|
6
7
|
import defer from 'p-defer'
|
|
8
|
+
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
|
|
9
|
+
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
|
|
10
|
+
import { isValidTick } from '../transport/utils/index.js'
|
|
11
|
+
import type { DeferredPromise } from 'p-defer'
|
|
7
12
|
import type { TestSetup } from '../index.js'
|
|
8
13
|
import type { Muxer, MuxerOptions, MuxedStream } from '@libp2p/interfaces/stream-muxer'
|
|
9
|
-
import {
|
|
14
|
+
import type { Source } from 'it-stream-types'
|
|
10
15
|
|
|
11
|
-
function close (stream: MuxedStream) {
|
|
12
|
-
return pipe([], stream,
|
|
16
|
+
async function close (stream: MuxedStream) {
|
|
17
|
+
return await pipe([], stream, drain)
|
|
13
18
|
}
|
|
14
19
|
|
|
15
20
|
export default (common: TestSetup<Muxer, MuxerOptions>) => {
|
|
16
21
|
describe('base', () => {
|
|
17
22
|
it('Open a stream from the dialer', async () => {
|
|
18
|
-
const p =
|
|
23
|
+
const p = duplexPair<Uint8Array>()
|
|
19
24
|
const dialer = await common.setup()
|
|
20
|
-
const onStreamPromise:
|
|
21
|
-
const onStreamEndPromise:
|
|
25
|
+
const onStreamPromise: DeferredPromise<MuxedStream> = defer()
|
|
26
|
+
const onStreamEndPromise: DeferredPromise<MuxedStream> = defer()
|
|
22
27
|
|
|
23
28
|
const listener = await common.setup({
|
|
24
29
|
onStream: stream => {
|
|
@@ -29,8 +34,8 @@ export default (common: TestSetup<Muxer, MuxerOptions>) => {
|
|
|
29
34
|
}
|
|
30
35
|
})
|
|
31
36
|
|
|
32
|
-
pipe(p[0], dialer, p[0])
|
|
33
|
-
pipe(p[1], listener, p[1])
|
|
37
|
+
void pipe(p[0], dialer.newStream('/test/stream'), p[0])
|
|
38
|
+
void pipe(p[1], listener.newStream('/test/stream'), p[1])
|
|
34
39
|
|
|
35
40
|
const conn = dialer.newStream()
|
|
36
41
|
expect(dialer.streams).to.include(conn)
|
|
@@ -40,7 +45,7 @@ export default (common: TestSetup<Muxer, MuxerOptions>) => {
|
|
|
40
45
|
expect(isValidTick(stream.timeline.open)).to.equal(true)
|
|
41
46
|
// Make sure the stream is being tracked
|
|
42
47
|
expect(listener.streams).to.include(stream)
|
|
43
|
-
close(stream)
|
|
48
|
+
void close(stream)
|
|
44
49
|
|
|
45
50
|
// Make sure stream is closed properly
|
|
46
51
|
const endedStream = await onStreamEndPromise.promise
|
|
@@ -61,8 +66,8 @@ export default (common: TestSetup<Muxer, MuxerOptions>) => {
|
|
|
61
66
|
})
|
|
62
67
|
|
|
63
68
|
it('Open a stream from the listener', async () => {
|
|
64
|
-
const p =
|
|
65
|
-
const onStreamPromise:
|
|
69
|
+
const p = duplexPair<Uint8Array>()
|
|
70
|
+
const onStreamPromise: DeferredPromise<MuxedStream> = defer()
|
|
66
71
|
const dialer = await common.setup({
|
|
67
72
|
onStream: stream => {
|
|
68
73
|
onStreamPromise.resolve(stream)
|
|
@@ -71,8 +76,8 @@ export default (common: TestSetup<Muxer, MuxerOptions>) => {
|
|
|
71
76
|
|
|
72
77
|
const listener = await common.setup()
|
|
73
78
|
|
|
74
|
-
pipe(p[0], dialer, p[0])
|
|
75
|
-
pipe(p[1], listener, p[1])
|
|
79
|
+
void pipe(p[0], dialer.newStream('/test/stream'), p[0])
|
|
80
|
+
void pipe(p[1], listener.newStream('/test/stream'), p[1])
|
|
76
81
|
|
|
77
82
|
const conn = listener.newStream()
|
|
78
83
|
|
|
@@ -86,9 +91,9 @@ export default (common: TestSetup<Muxer, MuxerOptions>) => {
|
|
|
86
91
|
})
|
|
87
92
|
|
|
88
93
|
it('Open a stream on both sides', async () => {
|
|
89
|
-
const p =
|
|
90
|
-
const onDialerStreamPromise:
|
|
91
|
-
const onListenerStreamPromise:
|
|
94
|
+
const p = duplexPair<Uint8Array>()
|
|
95
|
+
const onDialerStreamPromise: DeferredPromise<MuxedStream> = defer()
|
|
96
|
+
const onListenerStreamPromise: DeferredPromise<MuxedStream> = defer()
|
|
92
97
|
const dialer = await common.setup({
|
|
93
98
|
onStream: stream => {
|
|
94
99
|
onDialerStreamPromise.resolve(stream)
|
|
@@ -100,8 +105,8 @@ export default (common: TestSetup<Muxer, MuxerOptions>) => {
|
|
|
100
105
|
}
|
|
101
106
|
})
|
|
102
107
|
|
|
103
|
-
pipe(p[0], dialer, p[0])
|
|
104
|
-
pipe(p[1], listener, p[1])
|
|
108
|
+
void pipe(p[0], dialer.newStream('/test/stream'), p[0])
|
|
109
|
+
void pipe(p[1], listener.newStream('/test/stream'), p[1])
|
|
105
110
|
|
|
106
111
|
const listenerConn = listener.newStream()
|
|
107
112
|
const dialerConn = dialer.newStream()
|
|
@@ -117,10 +122,10 @@ export default (common: TestSetup<Muxer, MuxerOptions>) => {
|
|
|
117
122
|
})
|
|
118
123
|
|
|
119
124
|
it('Open a stream on one side, write, open a stream on the other side', async () => {
|
|
120
|
-
const toString =
|
|
121
|
-
const p =
|
|
122
|
-
const onDialerStreamPromise:
|
|
123
|
-
const onListenerStreamPromise:
|
|
125
|
+
const toString = (source: Source<Uint8Array>) => map(source, (u) => uint8ArrayToString(u))
|
|
126
|
+
const p = duplexPair<Uint8Array>()
|
|
127
|
+
const onDialerStreamPromise: DeferredPromise<MuxedStream> = defer()
|
|
128
|
+
const onListenerStreamPromise: DeferredPromise<MuxedStream> = defer()
|
|
124
129
|
const dialer = await common.setup({
|
|
125
130
|
onStream: stream => {
|
|
126
131
|
onDialerStreamPromise.resolve(stream)
|
|
@@ -132,22 +137,22 @@ export default (common: TestSetup<Muxer, MuxerOptions>) => {
|
|
|
132
137
|
}
|
|
133
138
|
})
|
|
134
139
|
|
|
135
|
-
pipe(p[0], dialer, p[0])
|
|
136
|
-
pipe(p[1], listener, p[1])
|
|
140
|
+
void pipe(p[0], dialer.newStream('/test/stream'), p[0])
|
|
141
|
+
void pipe(p[1], listener.newStream('/test/stream'), p[1])
|
|
137
142
|
|
|
138
143
|
const dialerConn = dialer.newStream()
|
|
139
144
|
const listenerConn = listener.newStream()
|
|
140
145
|
|
|
141
|
-
pipe(['hey'], dialerConn)
|
|
142
|
-
pipe(['hello'], listenerConn)
|
|
146
|
+
void pipe([uint8ArrayFromString('hey')], dialerConn)
|
|
147
|
+
void pipe([uint8ArrayFromString('hello')], listenerConn)
|
|
143
148
|
|
|
144
149
|
const listenerStream = await onListenerStreamPromise.promise
|
|
145
150
|
const dialerStream = await onDialerStreamPromise.promise
|
|
146
151
|
|
|
147
|
-
const listenerChunks = await pipe(listenerStream, toString,
|
|
152
|
+
const listenerChunks = await pipe(listenerStream, toString, async (source) => await all(source))
|
|
148
153
|
expect(listenerChunks).to.be.eql(['hey'])
|
|
149
154
|
|
|
150
|
-
const dialerChunks = await pipe(dialerStream, toString,
|
|
155
|
+
const dialerChunks = await pipe(dialerStream, toString, async (source) => await all(source))
|
|
151
156
|
expect(dialerChunks).to.be.eql(['hello'])
|
|
152
157
|
})
|
|
153
158
|
})
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
/* eslint max-nested-callbacks: ["error", 8] */
|
|
2
|
-
// @ts-expect-error no types
|
|
3
|
-
import pair from 'it-pair/duplex.js'
|
|
4
2
|
import { pipe } from 'it-pipe'
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
3
|
+
import { duplexPair } from 'it-pair/duplex'
|
|
4
|
+
import { abortableSource, abortableDuplex } from 'abortable-iterator'
|
|
7
5
|
import AbortController from 'abort-controller'
|
|
8
6
|
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
|
|
7
|
+
import drain from 'it-drain'
|
|
9
8
|
import type { TestSetup } from '../index.js'
|
|
10
9
|
import type { Muxer, MuxerOptions } from '@libp2p/interfaces/stream-muxer'
|
|
11
10
|
import type { Connection } from '@libp2p/interfaces/connection'
|
|
@@ -47,16 +46,16 @@ export default (common: TestSetup<Muxer, MuxerOptions>) => {
|
|
|
47
46
|
const mockUpgrade = async (maConn: any) => {
|
|
48
47
|
const muxer = await common.setup({
|
|
49
48
|
onStream: (stream) => {
|
|
50
|
-
pipe(stream, stream)
|
|
49
|
+
void pipe(stream, stream)
|
|
51
50
|
}
|
|
52
51
|
})
|
|
53
|
-
pipe(maConn, muxer, maConn)
|
|
52
|
+
pipe(maConn, muxer.newStream('/test/stream'), maConn)
|
|
54
53
|
return mockConn(muxer)
|
|
55
54
|
}
|
|
56
55
|
|
|
57
|
-
const [local, remote] =
|
|
56
|
+
const [local, remote] = duplexPair<Uint8Array>()
|
|
58
57
|
const controller = new AbortController()
|
|
59
|
-
const abortableRemote =
|
|
58
|
+
const abortableRemote = abortableDuplex(remote, controller.signal, {
|
|
60
59
|
returnOnAbort: true
|
|
61
60
|
})
|
|
62
61
|
|
|
@@ -69,8 +68,8 @@ export default (common: TestSetup<Muxer, MuxerOptions>) => {
|
|
|
69
68
|
// close the remote in a bit
|
|
70
69
|
setTimeout(() => controller.abort(), 50)
|
|
71
70
|
|
|
72
|
-
const s1Result = pipe(infiniteRandom, s1,
|
|
73
|
-
const s2Result = pipe(infiniteRandom, s2,
|
|
71
|
+
const s1Result = pipe(infiniteRandom, s1.stream, drain)
|
|
72
|
+
const s2Result = pipe(infiniteRandom, s2.stream, drain)
|
|
74
73
|
|
|
75
74
|
// test is complete when all muxed streams have closed
|
|
76
75
|
await s1Result
|
|
@@ -78,16 +77,16 @@ export default (common: TestSetup<Muxer, MuxerOptions>) => {
|
|
|
78
77
|
})
|
|
79
78
|
|
|
80
79
|
it('closing one of the muxed streams doesn\'t close others', async () => {
|
|
81
|
-
const p =
|
|
80
|
+
const p = duplexPair<Uint8Array>()
|
|
82
81
|
const dialer = await common.setup()
|
|
83
82
|
|
|
84
83
|
// Listener is echo server :)
|
|
85
84
|
const listener = await common.setup({
|
|
86
|
-
onStream: (stream) => pipe(stream, stream)
|
|
85
|
+
onStream: async (stream) => await pipe(stream, stream)
|
|
87
86
|
})
|
|
88
87
|
|
|
89
|
-
pipe(p[0], dialer, p[0])
|
|
90
|
-
pipe(p[1], listener, p[1])
|
|
88
|
+
void pipe(p[0], dialer.newStream('/test/stream'), p[0])
|
|
89
|
+
void pipe(p[1], listener.newStream('/test/stream'), p[1])
|
|
91
90
|
|
|
92
91
|
const stream = dialer.newStream()
|
|
93
92
|
const streams = Array.from(Array(5), () => dialer.newStream())
|
|
@@ -99,8 +98,8 @@ export default (common: TestSetup<Muxer, MuxerOptions>) => {
|
|
|
99
98
|
controllers.push(controller)
|
|
100
99
|
|
|
101
100
|
try {
|
|
102
|
-
const abortableRand =
|
|
103
|
-
await pipe(abortableRand, stream,
|
|
101
|
+
const abortableRand = abortableSource(infiniteRandom, controller.signal, { abortCode: 'ERR_TEST_ABORT' })
|
|
102
|
+
await pipe(abortableRand, stream, drain)
|
|
104
103
|
} catch (err: any) {
|
|
105
104
|
if (err.code !== 'ERR_TEST_ABORT') throw err
|
|
106
105
|
}
|
|
@@ -110,7 +109,7 @@ export default (common: TestSetup<Muxer, MuxerOptions>) => {
|
|
|
110
109
|
|
|
111
110
|
// Pause, and then send some data and close the first stream
|
|
112
111
|
await pause(50)
|
|
113
|
-
await pipe([randomBuffer()], stream,
|
|
112
|
+
await pipe([randomBuffer()], stream, drain)
|
|
114
113
|
closed = true
|
|
115
114
|
|
|
116
115
|
// Abort all the other streams later
|
|
@@ -1,44 +1,45 @@
|
|
|
1
1
|
import { expect } from 'aegir/utils/chai.js'
|
|
2
|
-
|
|
3
|
-
import pair from 'it-pair/duplex.js'
|
|
2
|
+
import { duplexPair } from 'it-pair/duplex'
|
|
4
3
|
import { pipe } from 'it-pipe'
|
|
5
4
|
import pLimit from 'p-limit'
|
|
6
|
-
import {
|
|
5
|
+
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
|
|
6
|
+
import drain from 'it-drain'
|
|
7
|
+
import all from 'it-all'
|
|
7
8
|
import type { Muxer, MuxerOptions } from '@libp2p/interfaces/stream-muxer'
|
|
8
9
|
|
|
9
10
|
export default async (createMuxer: (options?: MuxerOptions) => Promise<Muxer>, nStreams: number, nMsg: number, limit?: number) => {
|
|
10
|
-
const [dialerSocket, listenerSocket] =
|
|
11
|
+
const [dialerSocket, listenerSocket] = duplexPair<Uint8Array>()
|
|
11
12
|
|
|
12
|
-
const msg = 'simple msg'
|
|
13
|
+
const msg = uint8ArrayFromString('simple msg')
|
|
13
14
|
|
|
14
15
|
const listener = await createMuxer({
|
|
15
16
|
onStream: async (stream) => {
|
|
16
17
|
await pipe(
|
|
17
18
|
stream,
|
|
18
|
-
|
|
19
|
+
drain
|
|
19
20
|
)
|
|
20
21
|
|
|
21
|
-
pipe([], stream)
|
|
22
|
+
void pipe([], stream)
|
|
22
23
|
}
|
|
23
24
|
})
|
|
24
25
|
|
|
25
26
|
const dialer = await createMuxer()
|
|
26
27
|
|
|
27
|
-
pipe(listenerSocket, listener, listenerSocket)
|
|
28
|
-
pipe(dialerSocket, dialer, dialerSocket)
|
|
28
|
+
void pipe(listenerSocket, listener.newStream('/test/stream'), listenerSocket)
|
|
29
|
+
void pipe(dialerSocket, dialer.newStream('/test/stream'), dialerSocket)
|
|
29
30
|
|
|
30
31
|
const spawnStream = async () => {
|
|
31
32
|
const stream = dialer.newStream()
|
|
32
33
|
expect(stream).to.exist // eslint-disable-line
|
|
33
34
|
|
|
34
35
|
const res = await pipe(
|
|
35
|
-
(function * () {
|
|
36
|
+
(async function * () {
|
|
36
37
|
for (let i = 0; i < nMsg; i++) {
|
|
37
|
-
yield
|
|
38
|
+
yield msg
|
|
38
39
|
}
|
|
39
|
-
}
|
|
40
|
+
}()),
|
|
40
41
|
stream,
|
|
41
|
-
|
|
42
|
+
async (source) => await all(source)
|
|
42
43
|
)
|
|
43
44
|
|
|
44
45
|
expect(res).to.be.eql([])
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { expect } from 'aegir/utils/chai.js'
|
|
2
2
|
import { isValidTick, mockUpgrader } from './utils/index.js'
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
import { collect } from 'streaming-iterables'
|
|
3
|
+
import { goodbye } from 'it-goodbye'
|
|
4
|
+
import all from 'it-all'
|
|
6
5
|
import { pipe } from 'it-pipe'
|
|
7
6
|
import AbortController from 'abort-controller'
|
|
8
7
|
import { AbortError } from '@libp2p/interfaces/errors'
|
|
9
8
|
import sinon from 'sinon'
|
|
9
|
+
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
|
|
10
10
|
import type { TestSetup } from '../index.js'
|
|
11
11
|
import type { Transport, Listener } from '@libp2p/interfaces/transport'
|
|
12
12
|
import type { TransportTestFixtures, SetupArgs, Connector } from './index.js'
|
|
@@ -43,7 +43,7 @@ export default (common: TestSetup<TransportTestFixtures, SetupArgs>) => {
|
|
|
43
43
|
const upgradeSpy = sinon.spy(upgrader, 'upgradeOutbound')
|
|
44
44
|
const conn = await transport.dial(addrs[0])
|
|
45
45
|
const { stream } = await conn.newStream(['/hello'])
|
|
46
|
-
const s = goodbye({ source: ['hey'], sink:
|
|
46
|
+
const s = goodbye({ source: [uint8ArrayFromString('hey')], sink: async (source) => await all(source) })
|
|
47
47
|
|
|
48
48
|
const result = await pipe(s, stream, s)
|
|
49
49
|
|
|
@@ -16,7 +16,7 @@ export default (common: TestSetup<TransportTestFixtures, SetupArgs>) => {
|
|
|
16
16
|
describe('listen', () => {
|
|
17
17
|
const upgrader = mockUpgrader()
|
|
18
18
|
let addrs: Multiaddr[]
|
|
19
|
-
let transport: Transport
|
|
19
|
+
let transport: Transport
|
|
20
20
|
|
|
21
21
|
before(async () => {
|
|
22
22
|
({ transport, addrs } = await common.setup({ upgrader }))
|
|
@@ -31,7 +31,7 @@ export default (common: TestSetup<TransportTestFixtures, SetupArgs>) => {
|
|
|
31
31
|
})
|
|
32
32
|
|
|
33
33
|
it('simple', async () => {
|
|
34
|
-
const listener = transport.createListener(
|
|
34
|
+
const listener = transport.createListener()
|
|
35
35
|
await listener.listen(addrs[0])
|
|
36
36
|
await listener.close()
|
|
37
37
|
})
|
|
@@ -40,8 +40,10 @@ export default (common: TestSetup<TransportTestFixtures, SetupArgs>) => {
|
|
|
40
40
|
const upgradeSpy = sinon.spy(upgrader, 'upgradeInbound')
|
|
41
41
|
const listenerConns: Connection[] = []
|
|
42
42
|
|
|
43
|
-
const listener = transport.createListener({
|
|
44
|
-
|
|
43
|
+
const listener = transport.createListener({
|
|
44
|
+
handler: (conn) => {
|
|
45
|
+
listenerConns.push(conn)
|
|
46
|
+
}
|
|
45
47
|
})
|
|
46
48
|
|
|
47
49
|
// Listen
|
|
@@ -83,8 +85,10 @@ export default (common: TestSetup<TransportTestFixtures, SetupArgs>) => {
|
|
|
83
85
|
it('should not handle connection if upgradeInbound throws', async () => {
|
|
84
86
|
sinon.stub(upgrader, 'upgradeInbound').throws()
|
|
85
87
|
|
|
86
|
-
const listener = transport.createListener(
|
|
87
|
-
|
|
88
|
+
const listener = transport.createListener({
|
|
89
|
+
handler: () => {
|
|
90
|
+
throw new Error('should not handle the connection if upgradeInbound throws')
|
|
91
|
+
}
|
|
88
92
|
})
|
|
89
93
|
|
|
90
94
|
// Listen
|
|
@@ -100,7 +104,7 @@ export default (common: TestSetup<TransportTestFixtures, SetupArgs>) => {
|
|
|
100
104
|
describe('events', () => {
|
|
101
105
|
it('connection', async () => {
|
|
102
106
|
const upgradeSpy = sinon.spy(upgrader, 'upgradeInbound')
|
|
103
|
-
const listener = transport.createListener(
|
|
107
|
+
const listener = transport.createListener()
|
|
104
108
|
const deferred = defer()
|
|
105
109
|
let conn
|
|
106
110
|
|
|
@@ -122,7 +126,7 @@ export default (common: TestSetup<TransportTestFixtures, SetupArgs>) => {
|
|
|
122
126
|
})
|
|
123
127
|
|
|
124
128
|
it('listening', (done) => {
|
|
125
|
-
const listener = transport.createListener(
|
|
129
|
+
const listener = transport.createListener()
|
|
126
130
|
listener.on('listening', () => {
|
|
127
131
|
listener.close().then(done, done)
|
|
128
132
|
})
|
|
@@ -130,7 +134,7 @@ export default (common: TestSetup<TransportTestFixtures, SetupArgs>) => {
|
|
|
130
134
|
})
|
|
131
135
|
|
|
132
136
|
it('error', (done) => {
|
|
133
|
-
const listener = transport.createListener(
|
|
137
|
+
const listener = transport.createListener()
|
|
134
138
|
listener.on('error', (err) => {
|
|
135
139
|
expect(err).to.exist()
|
|
136
140
|
listener.close().then(done, done)
|
|
@@ -139,7 +143,7 @@ export default (common: TestSetup<TransportTestFixtures, SetupArgs>) => {
|
|
|
139
143
|
})
|
|
140
144
|
|
|
141
145
|
it('close', (done) => {
|
|
142
|
-
const listener = transport.createListener(
|
|
146
|
+
const listener = transport.createListener()
|
|
143
147
|
listener.on('close', done)
|
|
144
148
|
|
|
145
149
|
void (async () => {
|
|
@@ -2,8 +2,7 @@ import { expect } from 'aegir/utils/chai.js'
|
|
|
2
2
|
import type { Upgrader, MultiaddrConnection } from '@libp2p/interfaces/transport'
|
|
3
3
|
import type { Connection, StreamData } from '@libp2p/interfaces/connection'
|
|
4
4
|
import type { MuxedStream } from '@libp2p/interfaces/stream-muxer'
|
|
5
|
-
|
|
6
|
-
import pair from 'it-pair'
|
|
5
|
+
import { pair } from 'it-pair'
|
|
7
6
|
import { PeerId } from '@libp2p/peer-id'
|
|
8
7
|
import * as PeerIdFactory from '@libp2p/peer-id-factory'
|
|
9
8
|
/**
|
|
@@ -59,7 +58,7 @@ async function createConnection (maConn: MultiaddrConnection, direction: 'inboun
|
|
|
59
58
|
const localPeer = localPeerIdStr != null ? PeerId.fromString(localPeerIdStr) : await PeerIdFactory.createEd25519PeerId()
|
|
60
59
|
const remotePeer = remotePeerIdStr != null ? PeerId.fromString(remotePeerIdStr) : await PeerIdFactory.createEd25519PeerId()
|
|
61
60
|
|
|
62
|
-
const streams:
|
|
61
|
+
const streams: MuxedStream[] = []
|
|
63
62
|
let streamId = 0
|
|
64
63
|
|
|
65
64
|
const registry = new Map()
|
|
@@ -85,7 +84,7 @@ async function createConnection (maConn: MultiaddrConnection, direction: 'inboun
|
|
|
85
84
|
throw new Error('protocols must have a length')
|
|
86
85
|
}
|
|
87
86
|
|
|
88
|
-
const echo = pair()
|
|
87
|
+
const echo = pair<Uint8Array>()
|
|
89
88
|
|
|
90
89
|
const id = `${streamId++}`
|
|
91
90
|
const stream: MuxedStream = {
|
|
@@ -97,8 +96,7 @@ async function createConnection (maConn: MultiaddrConnection, direction: 'inboun
|
|
|
97
96
|
reset: () => {},
|
|
98
97
|
timeline: {
|
|
99
98
|
open: 0
|
|
100
|
-
}
|
|
101
|
-
[Symbol.asyncIterator]: echo.source
|
|
99
|
+
}
|
|
102
100
|
}
|
|
103
101
|
|
|
104
102
|
const streamData = {
|