From 93c1ffc1038570707377822a059cd4a051b3c59a Mon Sep 17 00:00:00 2001 From: Mikers Date: Fri, 12 Jun 2026 12:46:39 -1000 Subject: [PATCH 1/2] fix: adapt CLI commands for Synapse v1 APIs --- cli/src/commands/dataset/upload.ts | 4 ++-- cli/src/commands/wallet/costs.ts | 2 +- cli/src/commands/wallet/summary.ts | 7 ++----- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/cli/src/commands/dataset/upload.ts b/cli/src/commands/dataset/upload.ts index 9def319..f54f3e8 100644 --- a/cli/src/commands/dataset/upload.ts +++ b/cli/src/commands/dataset/upload.ts @@ -60,7 +60,7 @@ export const uploadCommand = { const fileData = await readFile(absolutePath) out.step('Calculating piece CID') - const pieceCid = Piece.calculate(fileData) + const pieceCid = await Piece.calculate(fileData) out.step('Uploading to provider') await SP.uploadPiece({ @@ -71,7 +71,7 @@ export const uploadCommand = { await SP.findPiece({ pieceCid, serviceURL: provider.pdp.serviceURL, - retry: true, + poll: true, }) out.step('Creating dataset and adding pieces') diff --git a/cli/src/commands/wallet/costs.ts b/cli/src/commands/wallet/costs.ts index dedae6c..411f7c4 100644 --- a/cli/src/commands/wallet/costs.ts +++ b/cli/src/commands/wallet/costs.ts @@ -46,7 +46,7 @@ export const costsCommand = { }) const newPerMonthRate = formatBalance({ - value: prep.costs.rate.perMonth, + value: prep.costs.rates.perMonth, }) const depositNeeded = formatBalance({ value: prep.costs.depositNeeded }) const alreadyCovered = prep.costs.ready diff --git a/cli/src/commands/wallet/summary.ts b/cli/src/commands/wallet/summary.ts index 23665cb..30e9aee 100644 --- a/cli/src/commands/wallet/summary.ts +++ b/cli/src/commands/wallet/summary.ts @@ -57,13 +57,10 @@ export const summaryCommand = { } function formatTimeUntilFunded(summary: getAccountSummary.OutputType) { - const { fundedUntilEpoch, epoch } = summary - if (fundedUntilEpoch === maxUint256) { + if (summary.runwayInEpochs === maxUint256) { return 'No active storage, unlimited' } - const blocksUntilFunded = - fundedUntilEpoch < epoch ? 0n : fundedUntilEpoch - epoch - const secondsUntilFunded = blocksUntilFunded * 30n + const secondsUntilFunded = summary.runwayInEpochs * 30n const hoursUntilFunded = secondsUntilFunded / 60n / 60n const daysUntilFunded = hoursUntilFunded / 24n const weeksUntilFunded = daysUntilFunded / 7n From 3a2d218a2063a503ea515fdd3b7b049980f8e470 Mon Sep 17 00:00:00 2001 From: Mikers Date: Fri, 12 Jun 2026 12:48:11 -1000 Subject: [PATCH 2/2] test: cover Synapse v1 CLI drift --- cli/tests/command-mocks.ts | 30 ++++++++++++++++++++---------- cli/tests/synapse-commands.test.ts | 13 +++++++++---- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/cli/tests/command-mocks.ts b/cli/tests/command-mocks.ts index a86e41c..e0e63a8 100644 --- a/cli/tests/command-mocks.ts +++ b/cli/tests/command-mocks.ts @@ -49,7 +49,8 @@ export const synapseStorage = { prepare: mock(async () => ({ transaction: null, costs: { - rate: { + rates: { + perEpoch: 11n, perMonth: 111n, }, depositNeeded: 222n, @@ -164,7 +165,7 @@ export const waitForCreateDataSet = mock(async () => ({ export const uploadPiece = mock(async () => undefined) export const findPiece = mock(async () => undefined) -export const calculate = mock(() => cid('baga-calculated')) +export const calculate = mock(async () => cid('baga-calculated')) export const createDataSetAndAddPieces = mock(async () => ({ txHash: '0xdatasetupload', @@ -192,13 +193,17 @@ export const terminateServiceSync = mock(async (_client: any, options: any) => { }) export const getAccountSummary = mock(async () => ({ + funds: 5n, availableFunds: 1n, + debt: 0n, + lockupRatePerEpoch: 6n, + lockupRatePerMonth: 4n, totalLockup: 2n, + totalFixedLockup: 7n, totalRateBasedLockup: 3n, - lockupRatePerMonth: 4n, - funds: 5n, + runwayInEpochs: 120n, + grossCoverageInEpochs: 240n, epoch: 100n, - fundedUntilEpoch: 220n, })) export const getBlockNumber = mock(async () => 123n) @@ -307,7 +312,8 @@ export function resetCommandMocks() { synapseStorage.prepare.mockImplementation(async () => ({ transaction: null, costs: { - rate: { + rates: { + perEpoch: 11n, perMonth: 111n, }, depositNeeded: 222n, @@ -338,7 +344,7 @@ export function resetCommandMocks() { })) uploadPiece.mockImplementation(async () => undefined) findPiece.mockImplementation(async () => undefined) - calculate.mockImplementation(() => cid('baga-calculated')) + calculate.mockImplementation(async () => cid('baga-calculated')) createDataSetAndAddPieces.mockImplementation(async () => ({ txHash: '0xdatasetupload', statusUrl: 'https://provider.example/status', @@ -363,13 +369,17 @@ export function resetCommandMocks() { } ) getAccountSummary.mockImplementation(async () => ({ + funds: 5n, availableFunds: 1n, + debt: 0n, + lockupRatePerEpoch: 6n, + lockupRatePerMonth: 4n, totalLockup: 2n, + totalFixedLockup: 7n, totalRateBasedLockup: 3n, - lockupRatePerMonth: 4n, - funds: 5n, + runwayInEpochs: 120n, + grossCoverageInEpochs: 240n, epoch: 100n, - fundedUntilEpoch: 220n, })) getBlockNumber.mockImplementation(async () => 123n) waitForTransactionReceipt.mockImplementation(async () => ({ diff --git a/cli/tests/synapse-commands.test.ts b/cli/tests/synapse-commands.test.ts index 846a533..881f46f 100644 --- a/cli/tests/synapse-commands.test.ts +++ b/cli/tests/synapse-commands.test.ts @@ -387,6 +387,8 @@ describe('wallet commands', () => { dataSize: 1024n, extraRunwayEpochs: 172800n, }) + expect(formatBalance).toHaveBeenNthCalledWith(1, { value: 111n }) + expect(formatBalance).toHaveBeenNthCalledWith(2, { value: 222n }) expect(result).toEqual({ newPerMonthRate: 'formatted:111', depositNeeded: 'formatted:222', @@ -513,15 +515,18 @@ describe('dataset commands', () => { ) expect(calculate).toHaveBeenCalled() + const uploadedPieceCid = uploadPiece.mock.calls[0]?.[0]?.pieceCid + expect(uploadedPieceCid?.toString()).toBe('baga-calculated') + expect(uploadedPieceCid).not.toHaveProperty('then') expect(uploadPiece).toHaveBeenCalledWith({ data: expect.any(Buffer), serviceURL: 'https://provider.example', - pieceCid: expect.anything(), + pieceCid: uploadedPieceCid, }) expect(findPiece).toHaveBeenCalledWith({ - pieceCid: expect.anything(), + pieceCid: uploadedPieceCid, serviceURL: 'https://provider.example', - retry: true, + poll: true, }) expect(createDataSetAndAddPieces).toHaveBeenCalledWith(fakeWalletClient, { serviceURL: 'https://provider.example', @@ -529,7 +534,7 @@ describe('dataset commands', () => { cdn: false, pieces: [ { - pieceCid: expect.anything(), + pieceCid: uploadedPieceCid, metadata: { name: 'dataset-file.txt' }, }, ],