Skip to content
This repository has been archived by the owner on Jun 26, 2023. It is now read-only.

fix: make mock muxer use abstract stream class #414

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions packages/interface-mocks/src/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,13 @@ class MockConnection implements Connection {
const stream = await this.muxer.newStream(id)
const result = await mss.select(stream, protocols, options)

const streamWithProtocol: Stream = {
...stream,
...result.stream,
stat: {
...stream.stat,
direction: 'outbound',
protocol: result.protocol
}
}
stream.sink = result.stream.sink
stream.source = result.stream.source
stream.stat.protocol = result.protocol

this.streams.push(streamWithProtocol)
this.streams.push(stream)

return streamWithProtocol
return stream
}

addStream (stream: Stream): void {
Expand Down Expand Up @@ -136,7 +130,9 @@ export function mockConnection (maConn: MultiaddrConnection, opts: MockConnectio
mss.handle(muxedStream, registrar.getProtocols())
.then(({ stream, protocol }) => {
log('%s: incoming stream opened on %s', direction, protocol)
muxedStream = { ...muxedStream, ...stream }

muxedStream.sink = stream.sink
muxedStream.source = stream.source
muxedStream.stat.protocol = protocol

connection.addStream(muxedStream)
Expand Down
Loading