@libp2p/interface-compliance-tests 1.0.2 → 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 +9 -9
- package/src/crypto/index.ts +9 -9
- package/src/crypto/utils/index.ts +24 -0
- package/src/stream-muxer/base-test.ts +28 -24
- 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,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 = {
|