Skip to content

Commit 3a2d218

Browse files
committed
test: cover Synapse v1 CLI drift
1 parent 93c1ffc commit 3a2d218

2 files changed

Lines changed: 29 additions & 14 deletions

File tree

cli/tests/command-mocks.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ export const synapseStorage = {
4949
prepare: mock(async () => ({
5050
transaction: null,
5151
costs: {
52-
rate: {
52+
rates: {
53+
perEpoch: 11n,
5354
perMonth: 111n,
5455
},
5556
depositNeeded: 222n,
@@ -164,7 +165,7 @@ export const waitForCreateDataSet = mock(async () => ({
164165

165166
export const uploadPiece = mock(async () => undefined)
166167
export const findPiece = mock(async () => undefined)
167-
export const calculate = mock(() => cid('baga-calculated'))
168+
export const calculate = mock(async () => cid('baga-calculated'))
168169

169170
export const createDataSetAndAddPieces = mock(async () => ({
170171
txHash: '0xdatasetupload',
@@ -192,13 +193,17 @@ export const terminateServiceSync = mock(async (_client: any, options: any) => {
192193
})
193194

194195
export const getAccountSummary = mock(async () => ({
196+
funds: 5n,
195197
availableFunds: 1n,
198+
debt: 0n,
199+
lockupRatePerEpoch: 6n,
200+
lockupRatePerMonth: 4n,
196201
totalLockup: 2n,
202+
totalFixedLockup: 7n,
197203
totalRateBasedLockup: 3n,
198-
lockupRatePerMonth: 4n,
199-
funds: 5n,
204+
runwayInEpochs: 120n,
205+
grossCoverageInEpochs: 240n,
200206
epoch: 100n,
201-
fundedUntilEpoch: 220n,
202207
}))
203208

204209
export const getBlockNumber = mock(async () => 123n)
@@ -307,7 +312,8 @@ export function resetCommandMocks() {
307312
synapseStorage.prepare.mockImplementation(async () => ({
308313
transaction: null,
309314
costs: {
310-
rate: {
315+
rates: {
316+
perEpoch: 11n,
311317
perMonth: 111n,
312318
},
313319
depositNeeded: 222n,
@@ -338,7 +344,7 @@ export function resetCommandMocks() {
338344
}))
339345
uploadPiece.mockImplementation(async () => undefined)
340346
findPiece.mockImplementation(async () => undefined)
341-
calculate.mockImplementation(() => cid('baga-calculated'))
347+
calculate.mockImplementation(async () => cid('baga-calculated'))
342348
createDataSetAndAddPieces.mockImplementation(async () => ({
343349
txHash: '0xdatasetupload',
344350
statusUrl: 'https://provider.example/status',
@@ -363,13 +369,17 @@ export function resetCommandMocks() {
363369
}
364370
)
365371
getAccountSummary.mockImplementation(async () => ({
372+
funds: 5n,
366373
availableFunds: 1n,
374+
debt: 0n,
375+
lockupRatePerEpoch: 6n,
376+
lockupRatePerMonth: 4n,
367377
totalLockup: 2n,
378+
totalFixedLockup: 7n,
368379
totalRateBasedLockup: 3n,
369-
lockupRatePerMonth: 4n,
370-
funds: 5n,
380+
runwayInEpochs: 120n,
381+
grossCoverageInEpochs: 240n,
371382
epoch: 100n,
372-
fundedUntilEpoch: 220n,
373383
}))
374384
getBlockNumber.mockImplementation(async () => 123n)
375385
waitForTransactionReceipt.mockImplementation(async () => ({

cli/tests/synapse-commands.test.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,8 @@ describe('wallet commands', () => {
387387
dataSize: 1024n,
388388
extraRunwayEpochs: 172800n,
389389
})
390+
expect(formatBalance).toHaveBeenNthCalledWith(1, { value: 111n })
391+
expect(formatBalance).toHaveBeenNthCalledWith(2, { value: 222n })
390392
expect(result).toEqual({
391393
newPerMonthRate: 'formatted:111',
392394
depositNeeded: 'formatted:222',
@@ -513,23 +515,26 @@ describe('dataset commands', () => {
513515
)
514516

515517
expect(calculate).toHaveBeenCalled()
518+
const uploadedPieceCid = uploadPiece.mock.calls[0]?.[0]?.pieceCid
519+
expect(uploadedPieceCid?.toString()).toBe('baga-calculated')
520+
expect(uploadedPieceCid).not.toHaveProperty('then')
516521
expect(uploadPiece).toHaveBeenCalledWith({
517522
data: expect.any(Buffer),
518523
serviceURL: 'https://provider.example',
519-
pieceCid: expect.anything(),
524+
pieceCid: uploadedPieceCid,
520525
})
521526
expect(findPiece).toHaveBeenCalledWith({
522-
pieceCid: expect.anything(),
527+
pieceCid: uploadedPieceCid,
523528
serviceURL: 'https://provider.example',
524-
retry: true,
529+
poll: true,
525530
})
526531
expect(createDataSetAndAddPieces).toHaveBeenCalledWith(fakeWalletClient, {
527532
serviceURL: 'https://provider.example',
528533
payee: fakeProvider.payee,
529534
cdn: false,
530535
pieces: [
531536
{
532-
pieceCid: expect.anything(),
537+
pieceCid: uploadedPieceCid,
533538
metadata: { name: 'dataset-file.txt' },
534539
},
535540
],

0 commit comments

Comments
 (0)