Skip to content

Commit

Permalink
chore: fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
achingbrain committed Dec 11, 2024
1 parent f1f1b20 commit 58c4088
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { isPeerId, start, stop } from '@libp2p/interface'
import { streamPair } from '@libp2p/interface-compliance-tests/mocks'
import { defaultLogger } from '@libp2p/logger'
import { peerIdFromString } from '@libp2p/peer-id'
import { multiaddr, type Multiaddr, type Protocol } from '@multiformats/multiaddr'
import { multiaddr, type Multiaddr } from '@multiformats/multiaddr'
import { expect } from 'aegir/chai'
import { duplexPair } from 'it-pair/duplex'
import { type Libp2p } from 'libp2p'
Expand Down Expand Up @@ -45,20 +45,24 @@ describe('whatwg-fetch', () => {

let serverCB: StreamHandler
const serverCBRegistered = pDefer()
serverComponents.registrar.handle.callsFake(async (protocol: Protocol, cb: StreamHandler) => {
serverComponents.registrar.handle.callsFake(async (protocol: string, cb: StreamHandler) => {
serverCB = cb
serverCBRegistered.resolve()
})

const conn = stubInterface<Connection>()
conn.newStream.callsFake(async (protos: Protocol[], options?: any) => {
conn.newStream.callsFake(async (protos: string | string[], options?: any) => {
const duplexes = duplexPair<any>()
const streams = streamPair({ duplex: duplexes[0] }, { duplex: duplexes[1] })
serverCB({ stream: streams[0], connection: conn })
return streams[1]
})

clientComponents.connectionManager.openConnection.callsFake(async (peer: PeerId | Multiaddr, options?: any) => {
clientComponents.connectionManager.openConnection.callsFake(async (peer: PeerId | Multiaddr | Multiaddr[], options?: any) => {
if (Array.isArray(peer)) {
peer = peer[0]
}

if (isPeerId(peer) ? peer.equals(serverPeerID) : peer.getPeerId() === serverMultiaddr.getPeerId()) {
await serverCBRegistered.promise
return conn
Expand Down

0 comments on commit 58c4088

Please sign in to comment.