Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions cli/bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
},
"dependencies": {
"@clack/prompts": "^1.0.0",
"@filoz/synapse-core": "^0.4.1",
"@filoz/synapse-sdk": "^0.40.4",
"@filoz/synapse-core": "^0.7.0",
"@filoz/synapse-sdk": "^1.0.1",
"@remix-run/fs": "^0.4.1",
"conf": "^15.0.2",
"incur": "^0.3.1",
Expand Down
4 changes: 2 additions & 2 deletions cli/src/commands/dataset/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion cli/src/commands/wallet/costs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 2 additions & 5 deletions cli/src/commands/wallet/summary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 20 additions & 10 deletions cli/tests/command-mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ export const synapseStorage = {
prepare: mock(async () => ({
transaction: null,
costs: {
rate: {
rates: {
perEpoch: 11n,
perMonth: 111n,
},
depositNeeded: 222n,
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -307,7 +312,8 @@ export function resetCommandMocks() {
synapseStorage.prepare.mockImplementation(async () => ({
transaction: null,
costs: {
rate: {
rates: {
perEpoch: 11n,
perMonth: 111n,
},
depositNeeded: 222n,
Expand Down Expand Up @@ -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',
Expand All @@ -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 () => ({
Expand Down
13 changes: 9 additions & 4 deletions cli/tests/synapse-commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -513,23 +515,26 @@ 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',
payee: fakeProvider.payee,
cdn: false,
pieces: [
{
pieceCid: expect.anything(),
pieceCid: uploadedPieceCid,
metadata: { name: 'dataset-file.txt' },
},
],
Expand Down
Loading