@libp2p/interface-compliance-tests 3.0.7-f427cfc9 → 4.0.0

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.
Files changed (100) hide show
  1. package/dist/src/connection/index.d.ts.map +1 -1
  2. package/dist/src/connection/index.js +24 -25
  3. package/dist/src/connection/index.js.map +1 -1
  4. package/dist/src/connection-encryption/utils/index.d.ts.map +1 -1
  5. package/dist/src/connection-encryption/utils/index.js +1 -0
  6. package/dist/src/connection-encryption/utils/index.js.map +1 -1
  7. package/dist/src/index.d.ts.map +1 -1
  8. package/dist/src/is-valid-tick.d.ts.map +1 -1
  9. package/dist/src/is-valid-tick.js.map +1 -1
  10. package/dist/src/mocks/connection-manager.d.ts +2 -0
  11. package/dist/src/mocks/connection-manager.d.ts.map +1 -1
  12. package/dist/src/mocks/connection-manager.js.map +1 -1
  13. package/dist/src/mocks/connection.d.ts.map +1 -1
  14. package/dist/src/mocks/connection.js +44 -39
  15. package/dist/src/mocks/connection.js.map +1 -1
  16. package/dist/src/mocks/multiaddr-connection.d.ts.map +1 -1
  17. package/dist/src/mocks/multiaddr-connection.js +9 -0
  18. package/dist/src/mocks/multiaddr-connection.js.map +1 -1
  19. package/dist/src/mocks/muxer.d.ts +28 -0
  20. package/dist/src/mocks/muxer.d.ts.map +1 -1
  21. package/dist/src/mocks/muxer.js +85 -213
  22. package/dist/src/mocks/muxer.js.map +1 -1
  23. package/dist/src/mocks/upgrader.d.ts +1 -1
  24. package/dist/src/mocks/upgrader.d.ts.map +1 -1
  25. package/dist/src/pubsub/api.d.ts +6 -0
  26. package/dist/src/pubsub/api.d.ts.map +1 -0
  27. package/dist/src/pubsub/api.js +87 -0
  28. package/dist/src/pubsub/api.js.map +1 -0
  29. package/dist/src/pubsub/connection-handlers.d.ts +6 -0
  30. package/dist/src/pubsub/connection-handlers.d.ts.map +1 -0
  31. package/dist/src/pubsub/connection-handlers.js +329 -0
  32. package/dist/src/pubsub/connection-handlers.js.map +1 -0
  33. package/dist/src/pubsub/emit-self.d.ts +6 -0
  34. package/dist/src/pubsub/emit-self.d.ts.map +1 -0
  35. package/dist/src/pubsub/emit-self.js +80 -0
  36. package/dist/src/pubsub/emit-self.js.map +1 -0
  37. package/dist/src/pubsub/index.d.ts +18 -0
  38. package/dist/src/pubsub/index.d.ts.map +1 -0
  39. package/dist/src/pubsub/index.js +17 -0
  40. package/dist/src/pubsub/index.js.map +1 -0
  41. package/dist/src/pubsub/messages.d.ts +6 -0
  42. package/dist/src/pubsub/messages.d.ts.map +1 -0
  43. package/dist/src/pubsub/messages.js +48 -0
  44. package/dist/src/pubsub/messages.js.map +1 -0
  45. package/dist/src/pubsub/multiple-nodes.d.ts +6 -0
  46. package/dist/src/pubsub/multiple-nodes.d.ts.map +1 -0
  47. package/dist/src/pubsub/multiple-nodes.js +350 -0
  48. package/dist/src/pubsub/multiple-nodes.js.map +1 -0
  49. package/dist/src/pubsub/two-nodes.d.ts +6 -0
  50. package/dist/src/pubsub/two-nodes.d.ts.map +1 -0
  51. package/dist/src/pubsub/two-nodes.js +217 -0
  52. package/dist/src/pubsub/two-nodes.js.map +1 -0
  53. package/dist/src/pubsub/utils.d.ts +6 -0
  54. package/dist/src/pubsub/utils.d.ts.map +1 -0
  55. package/dist/src/pubsub/utils.js +22 -0
  56. package/dist/src/pubsub/utils.js.map +1 -0
  57. package/dist/src/stream-muxer/base-test.js +6 -6
  58. package/dist/src/stream-muxer/base-test.js.map +1 -1
  59. package/dist/src/stream-muxer/close-test.d.ts.map +1 -1
  60. package/dist/src/stream-muxer/close-test.js +100 -12
  61. package/dist/src/stream-muxer/close-test.js.map +1 -1
  62. package/dist/src/stream-muxer/fixtures/pb/message.d.ts +13 -0
  63. package/dist/src/stream-muxer/fixtures/pb/message.d.ts.map +1 -0
  64. package/dist/src/stream-muxer/fixtures/pb/message.js +67 -0
  65. package/dist/src/stream-muxer/fixtures/pb/message.js.map +1 -0
  66. package/dist/src/stream-muxer/spawner.d.ts.map +1 -1
  67. package/dist/src/stream-muxer/spawner.js +4 -3
  68. package/dist/src/stream-muxer/spawner.js.map +1 -1
  69. package/dist/src/stream-muxer/stress-test.js +1 -1
  70. package/dist/src/stream-muxer/stress-test.js.map +1 -1
  71. package/dist/src/transport/dial-test.js +1 -1
  72. package/dist/src/transport/dial-test.js.map +1 -1
  73. package/dist/src/transport/listen-test.js +4 -4
  74. package/dist/src/transport/listen-test.js.map +1 -1
  75. package/package.json +20 -14
  76. package/src/connection/index.ts +24 -26
  77. package/src/connection-encryption/utils/index.ts +1 -0
  78. package/src/index.ts +0 -1
  79. package/src/is-valid-tick.ts +0 -1
  80. package/src/mocks/connection-manager.ts +4 -2
  81. package/src/mocks/connection.ts +48 -40
  82. package/src/mocks/multiaddr-connection.ts +9 -0
  83. package/src/mocks/muxer.ts +105 -249
  84. package/src/mocks/upgrader.ts +1 -1
  85. package/src/pubsub/api.ts +114 -0
  86. package/src/pubsub/connection-handlers.ts +413 -0
  87. package/src/pubsub/emit-self.ts +99 -0
  88. package/src/pubsub/index.ts +34 -0
  89. package/src/pubsub/messages.ts +59 -0
  90. package/src/pubsub/multiple-nodes.ts +440 -0
  91. package/src/pubsub/two-nodes.ts +273 -0
  92. package/src/pubsub/utils.ts +29 -0
  93. package/src/stream-muxer/base-test.ts +6 -6
  94. package/src/stream-muxer/close-test.ts +110 -14
  95. package/src/stream-muxer/fixtures/pb/message.proto +7 -0
  96. package/src/stream-muxer/fixtures/pb/message.ts +87 -0
  97. package/src/stream-muxer/spawner.ts +3 -2
  98. package/src/stream-muxer/stress-test.ts +1 -1
  99. package/src/transport/dial-test.ts +1 -1
  100. package/src/transport/listen-test.ts +4 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libp2p/interface-compliance-tests",
3
- "version": "3.0.7-f427cfc9",
3
+ "version": "4.0.0",
4
4
  "description": "Compliance tests for JS libp2p interfaces",
5
5
  "license": "Apache-2.0 OR MIT",
6
6
  "homepage": "https://github.com/libp2p/js-libp2p/tree/master/packages/interface-compliance-tests#readme",
@@ -68,6 +68,10 @@
68
68
  "types": "./dist/src/peers.d.ts",
69
69
  "import": "./dist/src/peers.js"
70
70
  },
71
+ "./pubsub": {
72
+ "types": "./dist/src/pubsub/index.d.ts",
73
+ "import": "./dist/src/pubsub/index.js"
74
+ },
71
75
  "./stream-muxer": {
72
76
  "types": "./dist/src/stream-muxer/index.d.ts",
73
77
  "import": "./dist/src/stream-muxer/index.js"
@@ -88,6 +92,7 @@
88
92
  "lint": "aegir lint",
89
93
  "dep-check": "aegir dep-check",
90
94
  "build": "aegir build",
95
+ "generate": "protons src/stream-muxer/fixtures/pb/message.proto",
91
96
  "test": "aegir test",
92
97
  "test:chrome": "aegir test -t browser --cov",
93
98
  "test:chrome-webworker": "aegir test -t webworker",
@@ -97,16 +102,15 @@
97
102
  "test:electron-main": "aegir test -t electron-main"
98
103
  },
99
104
  "dependencies": {
100
- "@libp2p/interface": "0.0.1-f427cfc9",
101
- "@libp2p/interface-internal": "0.0.1-f427cfc9",
102
- "@libp2p/logger": "2.1.1-f427cfc9",
103
- "@libp2p/multistream-select": "3.1.9-f427cfc9",
104
- "@libp2p/peer-collections": "3.0.2-f427cfc9",
105
- "@libp2p/peer-id": "2.0.3-f427cfc9",
106
- "@libp2p/peer-id-factory": "2.0.3-f427cfc9",
105
+ "@libp2p/interface": "^0.1.0",
106
+ "@libp2p/interface-internal": "^0.1.0",
107
+ "@libp2p/logger": "^3.0.0",
108
+ "@libp2p/multistream-select": "^4.0.0",
109
+ "@libp2p/peer-collections": "^4.0.0",
110
+ "@libp2p/peer-id": "^3.0.0",
111
+ "@libp2p/peer-id-factory": "^3.0.0",
107
112
  "@multiformats/multiaddr": "^12.1.3",
108
113
  "abortable-iterator": "^5.0.1",
109
- "any-signal": "^4.1.1",
110
114
  "delay": "^6.0.0",
111
115
  "it-all": "^3.0.2",
112
116
  "it-drain": "^3.0.2",
@@ -115,21 +119,23 @@
115
119
  "it-ndjson": "^1.0.3",
116
120
  "it-pair": "^2.0.6",
117
121
  "it-pipe": "^3.0.1",
118
- "it-pushable": "^3.1.3",
122
+ "it-protobuf-stream": "^1.0.0",
123
+ "it-pushable": "^3.2.0",
119
124
  "it-stream-types": "^2.0.1",
125
+ "it-to-buffer": "^4.0.2",
120
126
  "merge-options": "^3.0.4",
121
127
  "p-defer": "^4.0.0",
128
+ "p-event": "^6.0.0",
122
129
  "p-limit": "^4.0.0",
123
130
  "p-wait-for": "^5.0.2",
131
+ "protons-runtime": "^5.0.0",
124
132
  "sinon": "^15.1.2",
125
133
  "ts-sinon": "^2.0.2",
126
134
  "uint8arraylist": "^2.4.3",
127
135
  "uint8arrays": "^4.0.4"
128
136
  },
129
137
  "devDependencies": {
130
- "aegir": "^39.0.10"
131
- },
132
- "typedoc": {
133
- "entryPoint": "./src/index.ts"
138
+ "aegir": "^40.0.1",
139
+ "protons": "^7.0.2"
134
140
  }
135
141
  }
@@ -22,21 +22,19 @@ export default (test: TestSetup<Connection>): void => {
22
22
  expect(connection.id).to.exist()
23
23
  expect(connection.remotePeer).to.exist()
24
24
  expect(connection.remoteAddr).to.exist()
25
- expect(connection.stat.status).to.equal('OPEN')
26
- expect(connection.stat.timeline.open).to.exist()
27
- expect(connection.stat.timeline.close).to.not.exist()
28
- expect(connection.stat.direction).to.exist()
25
+ expect(connection.status).to.equal('open')
26
+ expect(connection.timeline.open).to.exist()
27
+ expect(connection.timeline.close).to.not.exist()
28
+ expect(connection.direction).to.exist()
29
29
  expect(connection.streams).to.eql([])
30
30
  expect(connection.tags).to.eql([])
31
31
  })
32
32
 
33
33
  it('should get the metadata of an open connection', () => {
34
- const stat = connection.stat
35
-
36
- expect(stat.status).to.equal('OPEN')
37
- expect(stat.direction).to.exist()
38
- expect(stat.timeline.open).to.exist()
39
- expect(stat.timeline.close).to.not.exist()
34
+ expect(connection.status).to.equal('open')
35
+ expect(connection.direction).to.exist()
36
+ expect(connection.timeline.open).to.exist()
37
+ expect(connection.timeline.close).to.not.exist()
40
38
  })
41
39
 
42
40
  it('should return an empty array of streams', () => {
@@ -51,7 +49,7 @@ export default (test: TestSetup<Connection>): void => {
51
49
  const protocolToUse = '/echo/0.0.1'
52
50
  const stream = await connection.newStream([protocolToUse])
53
51
 
54
- expect(stream).to.have.nested.property('stat.protocol', protocolToUse)
52
+ expect(stream).to.have.property('protocol', protocolToUse)
55
53
 
56
54
  const connStreams = connection.streams
57
55
 
@@ -79,7 +77,7 @@ export default (test: TestSetup<Connection>): void => {
79
77
  }, proxyHandler)
80
78
 
81
79
  connection = await test.setup()
82
- connection.stat.timeline = timelineProxy
80
+ connection.timeline = timelineProxy
83
81
  })
84
82
 
85
83
  afterEach(async () => {
@@ -87,11 +85,11 @@ export default (test: TestSetup<Connection>): void => {
87
85
  })
88
86
 
89
87
  it('should be able to close the connection after being created', async () => {
90
- expect(connection.stat.timeline.close).to.not.exist()
88
+ expect(connection.timeline.close).to.not.exist()
91
89
  await connection.close()
92
90
 
93
- expect(connection.stat.timeline.close).to.exist()
94
- expect(connection.stat.status).to.equal('CLOSED')
91
+ expect(connection.timeline.close).to.exist()
92
+ expect(connection.status).to.equal('closed')
95
93
  })
96
94
 
97
95
  it('should be able to close the connection after opening a stream', async () => {
@@ -100,21 +98,21 @@ export default (test: TestSetup<Connection>): void => {
100
98
  await connection.newStream([protocol])
101
99
 
102
100
  // Close connection
103
- expect(connection.stat.timeline.close).to.not.exist()
101
+ expect(connection.timeline.close).to.not.exist()
104
102
  await connection.close()
105
103
 
106
- expect(connection.stat.timeline.close).to.exist()
107
- expect(connection.stat.status).to.equal('CLOSED')
104
+ expect(connection.timeline.close).to.exist()
105
+ expect(connection.status).to.equal('closed')
108
106
  })
109
107
 
110
108
  it('should properly track streams', async () => {
111
109
  // Open stream
112
110
  const protocol = '/echo/0.0.1'
113
111
  const stream = await connection.newStream([protocol])
114
- expect(stream).to.have.nested.property('stat.protocol', protocol)
112
+ expect(stream).to.have.property('protocol', protocol)
115
113
 
116
114
  // Close stream
117
- stream.close()
115
+ await stream.close()
118
116
 
119
117
  expect(connection.streams.filter(s => s.id === stream.id)).to.be.empty()
120
118
  })
@@ -123,7 +121,7 @@ export default (test: TestSetup<Connection>): void => {
123
121
  // Open stream
124
122
  const protocol = '/echo/0.0.1'
125
123
  const stream = await connection.newStream(protocol)
126
- expect(stream).to.have.nested.property('stat.direction', 'outbound')
124
+ expect(stream).to.have.property('direction', 'outbound')
127
125
  })
128
126
 
129
127
  it.skip('should track inbound streams', async () => {
@@ -135,20 +133,20 @@ export default (test: TestSetup<Connection>): void => {
135
133
 
136
134
  it('should support a proxy on the timeline', async () => {
137
135
  sinon.spy(proxyHandler, 'set')
138
- expect(connection.stat.timeline.close).to.not.exist()
136
+ expect(connection.timeline.close).to.not.exist()
139
137
 
140
138
  await connection.close()
141
139
  // @ts-expect-error - fails to infer callCount
142
140
  expect(proxyHandler.set.callCount).to.equal(1)
143
141
  // @ts-expect-error - fails to infer getCall
144
142
  const [obj, key, value] = proxyHandler.set.getCall(0).args
145
- expect(obj).to.eql(connection.stat.timeline)
143
+ expect(obj).to.eql(connection.timeline)
146
144
  expect(key).to.equal('close')
147
- expect(value).to.be.a('number').that.equals(connection.stat.timeline.close)
145
+ expect(value).to.be.a('number').that.equals(connection.timeline.close)
148
146
  })
149
147
 
150
148
  it('should fail to create a new stream if the connection is closing', async () => {
151
- expect(connection.stat.timeline.close).to.not.exist()
149
+ expect(connection.timeline.close).to.not.exist()
152
150
  const p = connection.close()
153
151
 
154
152
  try {
@@ -165,7 +163,7 @@ export default (test: TestSetup<Connection>): void => {
165
163
  })
166
164
 
167
165
  it('should fail to create a new stream if the connection is closed', async () => {
168
- expect(connection.stat.timeline.close).to.not.exist()
166
+ expect(connection.timeline.close).to.not.exist()
169
167
  await connection.close()
170
168
 
171
169
  try {
@@ -10,6 +10,7 @@ export function createMaConnPair (): [MultiaddrConnection, MultiaddrConnection]
10
10
  const output: MultiaddrConnection = {
11
11
  ...duplex,
12
12
  close: async () => {},
13
+ abort: () => {},
13
14
  remoteAddr: multiaddr('/ip4/127.0.0.1/tcp/4001'),
14
15
  timeline: {
15
16
  open: Date.now()
package/src/index.ts CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  export interface TestSetup<T, SetupArgs = Record<string, unknown>> {
3
2
  setup: (args?: SetupArgs) => Promise<T>
4
3
  teardown: () => Promise<void>
@@ -1,4 +1,3 @@
1
-
2
1
  /**
3
2
  * A tick is considered valid if it happened between now
4
3
  * and `ms` milliseconds ago
@@ -4,11 +4,12 @@ import { PeerMap } from '@libp2p/peer-collections'
4
4
  import { peerIdFromString } from '@libp2p/peer-id'
5
5
  import { isMultiaddr, type Multiaddr } from '@multiformats/multiaddr'
6
6
  import { connectionPair } from './connection.js'
7
- import type { Libp2pEvents } from '@libp2p/interface'
7
+ import type { Libp2pEvents, PendingDial } from '@libp2p/interface'
8
8
  import type { Connection } from '@libp2p/interface/connection'
9
9
  import type { EventEmitter } from '@libp2p/interface/events'
10
+ import type { PubSub } from '@libp2p/interface/pubsub'
10
11
  import type { Startable } from '@libp2p/interface/startable'
11
- import type { ConnectionManager, PendingDial } from '@libp2p/interface-internal/connection-manager'
12
+ import type { ConnectionManager } from '@libp2p/interface-internal/connection-manager'
12
13
  import type { Registrar } from '@libp2p/interface-internal/registrar'
13
14
 
14
15
  export interface MockNetworkComponents {
@@ -16,6 +17,7 @@ export interface MockNetworkComponents {
16
17
  registrar: Registrar
17
18
  connectionManager: ConnectionManager
18
19
  events: EventEmitter<Libp2pEvents>
20
+ pubsub?: PubSub
19
21
  }
20
22
 
21
23
  class MockNetwork {
@@ -1,4 +1,3 @@
1
- import * as STATUS from '@libp2p/interface/connection/status'
2
1
  import { CodeError } from '@libp2p/interface/errors'
3
2
  import { logger } from '@libp2p/logger'
4
3
  import * as mss from '@libp2p/multistream-select'
@@ -9,7 +8,7 @@ import { mockMultiaddrConnection } from './multiaddr-connection.js'
9
8
  import { mockMuxer } from './muxer.js'
10
9
  import { mockRegistrar } from './registrar.js'
11
10
  import type { AbortOptions } from '@libp2p/interface'
12
- import type { MultiaddrConnection, Connection, Stream, ConnectionStat, Direction } from '@libp2p/interface/connection'
11
+ import type { MultiaddrConnection, Connection, Stream, Direction, ConnectionTimeline, ConnectionStatus } from '@libp2p/interface/connection'
13
12
  import type { PeerId } from '@libp2p/interface/peer-id'
14
13
  import type { StreamMuxer, StreamMuxerFactory } from '@libp2p/interface/stream-muxer'
15
14
  import type { Registrar } from '@libp2p/interface-internal/registrar'
@@ -38,9 +37,13 @@ class MockConnection implements Connection {
38
37
  public remoteAddr: Multiaddr
39
38
  public remotePeer: PeerId
40
39
  public direction: Direction
41
- public stat: ConnectionStat
40
+ public timeline: ConnectionTimeline
41
+ public multiplexer?: string
42
+ public encryption?: string
43
+ public status: ConnectionStatus
42
44
  public streams: Stream[]
43
45
  public tags: string[]
46
+ public transient: boolean
44
47
 
45
48
  private readonly muxer: StreamMuxer
46
49
  private readonly maConn: MultiaddrConnection
@@ -52,17 +55,16 @@ class MockConnection implements Connection {
52
55
  this.remoteAddr = remoteAddr
53
56
  this.remotePeer = remotePeer
54
57
  this.direction = direction
55
- this.stat = {
56
- status: STATUS.OPEN,
57
- direction,
58
- timeline: maConn.timeline,
59
- multiplexer: 'test-multiplexer',
60
- encryption: 'yes-yes-very-secure'
61
- }
58
+ this.status = 'open'
59
+ this.direction = direction
60
+ this.timeline = maConn.timeline
61
+ this.multiplexer = 'test-multiplexer'
62
+ this.encryption = 'yes-yes-very-secure'
62
63
  this.streams = []
63
64
  this.tags = []
64
65
  this.muxer = muxer
65
66
  this.maConn = maConn
67
+ this.transient = false
66
68
  }
67
69
 
68
70
  async newStream (protocols: string | string[], options?: AbortOptions): Promise<Stream> {
@@ -74,7 +76,7 @@ class MockConnection implements Connection {
74
76
  throw new Error('protocols must have a length')
75
77
  }
76
78
 
77
- if (this.stat.status !== STATUS.OPEN) {
79
+ if (this.status !== 'open') {
78
80
  throw new CodeError('connection must be open to create streams', 'ERR_CONNECTION_CLOSED')
79
81
  }
80
82
 
@@ -82,19 +84,14 @@ class MockConnection implements Connection {
82
84
  const stream = await this.muxer.newStream(id)
83
85
  const result = await mss.select(stream, protocols, options)
84
86
 
85
- const streamWithProtocol: Stream = {
86
- ...stream,
87
- ...result.stream,
88
- stat: {
89
- ...stream.stat,
90
- direction: 'outbound',
91
- protocol: result.protocol
92
- }
93
- }
87
+ stream.protocol = result.protocol
88
+ stream.direction = 'outbound'
89
+ stream.sink = result.stream.sink
90
+ stream.source = result.stream.source
94
91
 
95
- this.streams.push(streamWithProtocol)
92
+ this.streams.push(stream)
96
93
 
97
- return streamWithProtocol
94
+ return stream
98
95
  }
99
96
 
100
97
  addStream (stream: Stream): void {
@@ -105,14 +102,24 @@ class MockConnection implements Connection {
105
102
  this.streams = this.streams.filter(stream => stream.id !== id)
106
103
  }
107
104
 
108
- async close (): Promise<void> {
109
- this.stat.status = STATUS.CLOSING
105
+ async close (options?: AbortOptions): Promise<void> {
106
+ this.status = 'closing'
107
+ await Promise.all(
108
+ this.streams.map(async s => s.close(options))
109
+ )
110
110
  await this.maConn.close()
111
+ this.status = 'closed'
112
+ this.timeline.close = Date.now()
113
+ }
114
+
115
+ abort (err: Error): void {
116
+ this.status = 'closing'
111
117
  this.streams.forEach(s => {
112
- s.close()
118
+ s.abort(err)
113
119
  })
114
- this.stat.status = STATUS.CLOSED
115
- this.stat.timeline.close = Date.now()
120
+ this.maConn.abort(err)
121
+ this.status = 'closed'
122
+ this.timeline.close = Date.now()
116
123
  }
117
124
  }
118
125
 
@@ -136,8 +143,9 @@ export function mockConnection (maConn: MultiaddrConnection, opts: MockConnectio
136
143
  mss.handle(muxedStream, registrar.getProtocols())
137
144
  .then(({ stream, protocol }) => {
138
145
  log('%s: incoming stream opened on %s', direction, protocol)
139
- muxedStream = { ...muxedStream, ...stream }
140
- muxedStream.stat.protocol = protocol
146
+ muxedStream.protocol = protocol
147
+ muxedStream.sink = stream.sink
148
+ muxedStream.source = stream.source
141
149
 
142
150
  connection.addStream(muxedStream)
143
151
  const { handler } = registrar.getHandler(protocol)
@@ -173,20 +181,20 @@ export function mockConnection (maConn: MultiaddrConnection, opts: MockConnectio
173
181
  export function mockStream (stream: Duplex<AsyncGenerator<Uint8ArrayList>, Source<Uint8ArrayList | Uint8Array>, Promise<void>>): Stream {
174
182
  return {
175
183
  ...stream,
176
- close: () => {},
177
- closeRead: () => {},
178
- closeWrite: () => {},
184
+ close: async () => {},
185
+ closeRead: async () => {},
186
+ closeWrite: async () => {},
179
187
  abort: () => {},
180
- reset: () => {},
181
- stat: {
182
- direction: 'outbound',
183
- protocol: '/foo/1.0.0',
184
- timeline: {
185
- open: Date.now()
186
- }
188
+ direction: 'outbound',
189
+ protocol: '/foo/1.0.0',
190
+ timeline: {
191
+ open: Date.now()
187
192
  },
188
193
  metadata: {},
189
- id: `stream-${Date.now()}`
194
+ id: `stream-${Date.now()}`,
195
+ status: 'open',
196
+ readStatus: 'ready',
197
+ writeStatus: 'ready'
190
198
  }
191
199
  }
192
200
 
@@ -11,6 +11,7 @@ export function mockMultiaddrConnection (source: Duplex<AsyncGenerator<Uint8Arra
11
11
  async close () {
12
12
 
13
13
  },
14
+ abort: () => {},
14
15
  timeline: {
15
16
  open: Date.now()
16
17
  },
@@ -44,6 +45,10 @@ export function mockMultiaddrConnPair (opts: MockMultiaddrConnPairOptions): { in
44
45
  close: async () => {
45
46
  outbound.timeline.close = Date.now()
46
47
  controller.abort()
48
+ },
49
+ abort: (err: Error) => {
50
+ outbound.timeline.close = Date.now()
51
+ controller.abort(err)
47
52
  }
48
53
  }
49
54
 
@@ -56,6 +61,10 @@ export function mockMultiaddrConnPair (opts: MockMultiaddrConnPairOptions): { in
56
61
  close: async () => {
57
62
  inbound.timeline.close = Date.now()
58
63
  controller.abort()
64
+ },
65
+ abort: (err: Error) => {
66
+ outbound.timeline.close = Date.now()
67
+ controller.abort(err)
59
68
  }
60
69
  }
61
70