Skip to content

Commit b1dd61d

Browse files
committed
fix: handle missing ProvideBufLen in bitswap stat response
kubo API doesn't return ProvideBufLen field in JSON response, default to 0 when missing to fix test failure
1 parent 2dea058 commit b1dd61d

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/bitswap/stat.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export function createStat (client: HTTPRPCClient): BitswapAPI['stat'] {
1818

1919
function toCoreInterface (res: any): BitswapStats {
2020
return {
21-
provideBufLen: res.ProvideBufLen,
21+
provideBufLen: res.ProvideBufLen ?? 0,
2222
wantlist: (res.Wantlist ?? []).map((k: any) => CID.parse(k['/'])),
2323
peers: (res.Peers ?? []).map((str: any) => peerIdFromString(str)),
2424
blocksReceived: BigInt(res.BlocksReceived),

test/interface-tests/src/stats/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export function expectIsBitswap (err: Error | null, stats: BitswapStats): void {
2020
expect(stats).to.have.a.property('dupBlksReceived')
2121
expect(stats).to.have.a.property('dupDataReceived')
2222

23-
expect(stats.provideBufLen).to.a('number')
23+
expect(stats.provideBufLen).to.a('number') // Defaults to 0 if not provided by API
2424
expect(stats.wantlist).to.be.an('array')
2525
expect(stats.peers).to.be.an('array')
2626
expect(isBigInt(stats.blocksReceived)).to.eql(true)

0 commit comments

Comments
 (0)