Skip to content

Commit c993de9

Browse files
committed
other ci issue resolved
1 parent 57f5e5d commit c993de9

3 files changed

Lines changed: 30 additions & 3 deletions

File tree

src/core/data-set/get-data-set-pieces.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import { getActivePieces, getScheduledRemovals } from '@filoz/synapse-core/pdp-verifier'
10-
import { getSizeFromPieceCID } from '@filoz/synapse-core/piece'
10+
import * as pieceTools from '@filoz/synapse-core/piece'
1111
import { getDataSet as getProviderDataSet } from '@filoz/synapse-core/sp'
1212
import { getAllPieceMetadata } from '@filoz/synapse-core/warm-storage'
1313
import { type DataSetPieceData, METADATA_KEYS, type Synapse } from '@filoz/synapse-sdk'
@@ -17,6 +17,22 @@ import { type DataSetPiecesResult, type GetDataSetPiecesOptions, type PieceInfo,
1717

1818
const ACTIVE_PIECES_BATCH_SIZE = 100n
1919

20+
type PieceSizeTools = {
21+
getSizeFromPieceCID?: (pieceCid: unknown) => number
22+
from?: (pieceCid: unknown) => { size: number }
23+
}
24+
25+
function getPieceSize(pieceCid: unknown): number {
26+
const tools = pieceTools as PieceSizeTools
27+
if (tools.getSizeFromPieceCID != null) {
28+
return tools.getSizeFromPieceCID(pieceCid)
29+
}
30+
if (tools.from != null) {
31+
return tools.from(pieceCid).size
32+
}
33+
throw new Error('No piece size helper is available from @filoz/synapse-core/piece')
34+
}
35+
2036
/**
2137
* Get all pieces for a dataset.
2238
*
@@ -100,7 +116,7 @@ export async function getDataSetPieces(
100116
}
101117

102118
try {
103-
pieceInfo.size = getSizeFromPieceCID(piece.cid)
119+
pieceInfo.size = getPieceSize(piece.cid)
104120
} catch (error) {
105121
logger?.warn(
106122
{ pieceId: piece.id.toString(), pieceCid: piece.cid.toString(), error },
@@ -124,7 +140,7 @@ export async function getDataSetPieces(
124140
status: PieceStatus.OFFCHAIN_ORPHANED,
125141
}
126142
try {
127-
pieceInfo.size = getSizeFromPieceCID(providerPiece.pieceCid)
143+
pieceInfo.size = getPieceSize(providerPiece.pieceCid)
128144
} catch {
129145
// size calculation is best-effort
130146
}

src/test/unit/core-data-set.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const {
2020
mockGetScheduledRemovals,
2121
mockGetProviderDataSet,
2222
mockGetSizeFromPieceCID,
23+
mockPieceFromCID,
2324
state,
2425
} = vi.hoisted(() => {
2526
const state = {
@@ -67,6 +68,7 @@ const {
6768
if (cidString === 'bafkpiece2') return 4194304
6869
throw new Error(`Invalid piece CID: ${cidString}`)
6970
})
71+
const mockPieceFromCID = vi.fn((cid: { toString: () => string } | string) => ({ size: mockGetSizeFromPieceCID(cid) }))
7072

7173
const mockSynapse = {
7274
client: { account: { address: '0xtest-address' as const } },
@@ -84,6 +86,7 @@ const {
8486
mockGetScheduledRemovals,
8587
mockGetProviderDataSet,
8688
mockGetSizeFromPieceCID,
89+
mockPieceFromCID,
8790
state,
8891
}
8992
})
@@ -111,6 +114,7 @@ vi.mock('@filoz/synapse-core/sp', () => ({
111114
// Mock piece size calculation
112115
vi.mock('@filoz/synapse-core/piece', () => ({
113116
getSizeFromPieceCID: mockGetSizeFromPieceCID,
117+
from: mockPieceFromCID,
114118
MAX_UPLOAD_SIZE: 32 * 1024 * 1024 * 1024, // 32 GiB
115119
}))
116120

@@ -215,6 +219,9 @@ describe('getDataSetPieces', () => {
215219
if (cidString === 'bafkpiece2') return 4194304
216220
throw new Error(`Invalid piece CID: ${cidString}`)
217221
})
222+
mockPieceFromCID.mockImplementation((cid: { toString: () => string } | string) => ({
223+
size: mockGetSizeFromPieceCID(cid),
224+
}))
218225
})
219226

220227
it('returns empty array when dataset has no pieces', async () => {

src/test/unit/data-set.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ vi.mock('@filoz/synapse-core/sp', () => ({
199199
// Mock piece size calculation
200200
vi.mock('@filoz/synapse-core/piece', () => ({
201201
MAX_UPLOAD_SIZE: 1048576,
202+
getSizeFromPieceCID: vi.fn(() => {
203+
// Return a realistic piece size (1 MiB = 1048576 bytes)
204+
return 1048576
205+
}),
202206
from: vi.fn(() => ({
203207
// Return a realistic piece size (1 MiB = 1048576 bytes)
204208
size: 1048576,

0 commit comments

Comments
 (0)