Skip to content

Commit 1dca655

Browse files
committed
chore: fix tests
1 parent e9bbbe6 commit 1dca655

File tree

9 files changed

+19
-14
lines changed

9 files changed

+19
-14
lines changed

packages/bitswap/src/bitswap.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export class Bitswap implements BitswapInterface {
5656

5757
constructor (components: BitswapComponents, init: BitswapOptions = {}) {
5858
this.logger = components.logger
59-
this.log = components.logger.forComponent('bitswap')
59+
this.log = components.logger.forComponent('helia:bitswap')
6060
this.status = 'stopped'
6161
this.libp2p = components.libp2p
6262
this.blockstore = components.blockstore

packages/bitswap/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import { Bitswap as BitswapClass } from './bitswap.js'
88
import type { BitswapNetworkNotifyProgressEvents, BitswapNetworkWantProgressEvents } from './network.js'
99
import type { WantType } from './pb/message.js'
10-
import type { Routing } from '@helia/interface'
10+
import type { Routing } from '@helia/interface/routing'
1111
import type { Libp2p, AbortOptions, Startable, ComponentLogger, Metrics, PeerId } from '@libp2p/interface'
1212
import type { PeerSet } from '@libp2p/peer-collections'
1313
import type { Blockstore } from 'interface-blockstore'

packages/bitswap/src/network.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { BitswapMessage } from './pb/message.js'
1818
import type { WantOptions } from './bitswap.js'
1919
import type { MultihashHasherLoader } from './index.js'
2020
import type { Block, BlockPresence, WantlistEntry } from './pb/message.js'
21-
import type { Provider, Routing } from '@helia/interface'
21+
import type { Provider, Routing } from '@helia/interface/routing'
2222
import type { Libp2p, AbortOptions, Connection, PeerId, IncomingStreamData, Topology, MetricGroup, ComponentLogger, Metrics } from '@libp2p/interface'
2323
import type { Logger } from '@libp2p/logger'
2424
import type { ProgressEvent, ProgressOptions } from 'progress-events'

packages/bitswap/src/peer-want-lists/index.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Ledger } from './ledger.js'
66
import type { BitswapNotifyProgressEvents, WantListEntry } from '../index.js'
77
import type { Network } from '../network.js'
88
import type { BitswapMessage } from '../pb/message.js'
9-
import type { ComponentLogger, Metrics, PeerId } from '@libp2p/interface'
9+
import type { ComponentLogger, Logger, Metrics, PeerId } from '@libp2p/interface'
1010
import type { PeerMap } from '@libp2p/peer-collections'
1111
import type { Blockstore } from 'interface-blockstore'
1212
import type { AbortOptions } from 'it-length-prefixed-stream'
@@ -36,11 +36,13 @@ export class PeerWantLists {
3636
public network: Network
3737
public readonly ledgerMap: PeerMap<Ledger>
3838
private readonly maxSizeReplaceHasWithBlock?: number
39+
private readonly log: Logger
3940

4041
constructor (components: PeerWantListsComponents, init: PeerWantListsInit = {}) {
4142
this.blockstore = components.blockstore
4243
this.network = components.network
4344
this.maxSizeReplaceHasWithBlock = init.maxSizeReplaceHasWithBlock
45+
this.log = components.logger.forComponent('helia:bitswap:peer-want-lists')
4446

4547
this.ledgerMap = trackedPeerMap({
4648
name: 'ipfs_bitswap_ledger_map',
@@ -110,8 +112,16 @@ export class PeerWantLists {
110112
const cidStr = uint8ArrayToString(cid.multihash.bytes, 'base64')
111113

112114
if (entry.cancel === true) {
115+
this.log('peer %p cancelled want of block for %c', peerId, cid)
116+
113117
ledger.wants.delete(cidStr)
114118
} else {
119+
if (entry.wantType === WantType.WantHave) {
120+
this.log('peer %p wanted block presence for %c', peerId, cid)
121+
} else {
122+
this.log('peer %p wanted block for %c', peerId, cid)
123+
}
124+
115125
ledger.wants.set(cidStr, {
116126
cid,
117127
session: new PeerSet(),

packages/bitswap/test/bitswap.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { Bitswap } from '../src/bitswap.js'
1717
import { DEFAULT_MAX_PROVIDERS_PER_REQUEST, DEFAULT_MIN_PROVIDERS_BEFORE_SESSION_READY } from '../src/constants.js'
1818
import { BitswapMessage, BlockPresenceType } from '../src/pb/message.js'
1919
import { cidToPrefix } from '../src/utils/cid-prefix.js'
20-
import type { Routing } from '@helia/interface'
20+
import type { Routing } from '@helia/interface/routing'
2121
import type { Connection, Libp2p, PeerId } from '@libp2p/interface'
2222
import type { Blockstore } from 'interface-blockstore'
2323
import type { StubbedInstance } from 'sinon-ts'

packages/bitswap/test/network.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { BITSWAP_120 } from '../src/constants.js'
1717
import { Network } from '../src/network.js'
1818
import { BitswapMessage, BlockPresenceType } from '../src/pb/message.js'
1919
import { cidToPrefix } from '../src/utils/cid-prefix.js'
20-
import type { Routing } from '@helia/interface'
20+
import type { Routing } from '@helia/interface/routing'
2121
import type { Connection, Libp2p, PeerId } from '@libp2p/interface'
2222

2323
interface StubbedNetworkComponents {

packages/block-brokers/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
"@helia/interface": "^4.0.0",
5858
"@libp2p/interface": "^1.1.2",
5959
"interface-blockstore": "^5.2.9",
60-
"ipfs-bitswap": "^20.0.2",
6160
"multiformats": "^13.0.1",
6261
"progress-events": "^1.0.0"
6362
},

packages/block-brokers/src/bitswap.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class BitswapBlockBroker implements BlockBroker<BitswapWantBlockProgressEvents,
6565
}
6666

6767
async announce (cid: CID, block: Uint8Array, options?: BlockAnnounceOptions<BitswapNotifyProgressEvents>): Promise<void> {
68-
this.bitswap.notify(cid, block, options)
68+
await this.bitswap.notify(cid, block, options)
6969
}
7070

7171
async retrieve (cid: CID, options: BlockRetrievalOptions<BitswapWantBlockProgressEvents> = {}): Promise<Uint8Array> {

packages/interop/src/unixfs-bitswap.spec.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,9 @@ describe('@helia/unixfs - bitswap', () => {
5252

5353
const cid = await unixFs.addFile(candidate)
5454

55-
const output: Uint8Array[] = []
55+
const bytes = await toBuffer(kubo.api.cat(CID.parse(cid.toString())))
5656

57-
for await (const b of kubo.api.cat(cid)) {
58-
output.push(b)
59-
}
60-
61-
expect(toBuffer(output)).to.equalBytes(toBuffer(input))
57+
expect(bytes).to.equalBytes(toBuffer(input))
6258
})
6359

6460
it('should add a large file to kubo and fetch it from helia', async () => {

0 commit comments

Comments
 (0)