Skip to content

Commit

Permalink
fix: use configured receipts endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
BravoNatalie committed Nov 20, 2024
1 parent 81b1429 commit 882d1c5
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 32 deletions.
6 changes: 5 additions & 1 deletion packages/w3up-client/src/capability/blob.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ export class BlobClient extends Base {
* @param {import('../types.js').RequestOptions} [options]
*/
async add(blob, options = {}) {
options = {
receiptsEndpoint: this._receiptsEndpoint.toString(),
connection: this._serviceConf.upload,
...options,
}
const conf = await this._invocationConfig([BlobCapabilities.add.can])
options.connection = this._serviceConf.upload
const bytes = new Uint8Array(await blob.arrayBuffer())
const digest = await sha256.digest(bytes)
return { digest, ...(await Blob.add(conf, digest, bytes, options)) }
Expand Down
18 changes: 15 additions & 3 deletions packages/w3up-client/src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,11 @@ export class Client extends Base {
FilecoinCapabilities.offer.can,
UploadCapabilities.add.can,
])
options.connection = this._serviceConf.upload
options = {
receiptsEndpoint: this._receiptsEndpoint.toString(),
connection: this._serviceConf.upload,
...options,
}
return uploadFile(conf, file, options)
}

Expand All @@ -152,7 +156,11 @@ export class Client extends Base {
FilecoinCapabilities.offer.can,
UploadCapabilities.add.can,
])
options.connection = this._serviceConf.upload
options = {
receiptsEndpoint: this._receiptsEndpoint.toString(),
connection: this._serviceConf.upload,
...options,
}
return uploadDirectory(conf, files, options)
}

Expand Down Expand Up @@ -182,7 +190,11 @@ export class Client extends Base {
FilecoinCapabilities.offer.can,
UploadCapabilities.add.can,
])
options.connection = this._serviceConf.upload
options = {
receiptsEndpoint: this._receiptsEndpoint.toString(),
connection: this._serviceConf.upload,
...options,
}
return uploadCAR(conf, car, options)
}

Expand Down
20 changes: 8 additions & 12 deletions packages/w3up-client/test/capability/blob.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const BlobClient = Test.withContext({
access: connection,
upload: connection,
},
receiptsEndpoint: new URL(receiptsEndpoint)
})

const space = await alice.createSpace('test')
Expand All @@ -33,9 +34,7 @@ export const BlobClient = Test.withContext({

const bytes = await randomBytes(128)
const bytesHash = await sha256.digest(bytes)
const { digest } = await alice.capability.blob.add(new Blob([bytes]), {
receiptsEndpoint,
})
const { digest } = await alice.capability.blob.add(new Blob([bytes]))

// TODO we should check blobsStorage as well
assert.deepEqual(await allocationsStorage.exists(space.did(), digest), {
Expand All @@ -54,6 +53,7 @@ export const BlobClient = Test.withContext({
access: connection,
upload: connection,
},
receiptsEndpoint: new URL(receiptsEndpoint)
})

const space = await alice.createSpace('test')
Expand All @@ -71,9 +71,7 @@ export const BlobClient = Test.withContext({

const bytes = await randomBytes(128)
const bytesHash = await sha256.digest(bytes)
const { digest } = await alice.capability.blob.add(new Blob([bytes]), {
receiptsEndpoint,
})
const { digest } = await alice.capability.blob.add(new Blob([bytes]))
assert.deepEqual(digest.bytes, bytesHash.bytes)

const {
Expand All @@ -93,6 +91,7 @@ export const BlobClient = Test.withContext({
access: connection,
upload: connection,
},
receiptsEndpoint: new URL(receiptsEndpoint),
})

const space = await alice.createSpace('test')
Expand All @@ -109,9 +108,7 @@ export const BlobClient = Test.withContext({
})

const bytes = await randomBytes(128)
const { digest } = await alice.capability.blob.add(new Blob([bytes]), {
receiptsEndpoint,
})
const { digest } = await alice.capability.blob.add(new Blob([bytes]))

const result = await alice.capability.blob.remove(digest)
assert.ok(result.ok)
Expand All @@ -126,6 +123,7 @@ export const BlobClient = Test.withContext({
access: connection,
upload: connection,
},
receiptsEndpoint: new URL(receiptsEndpoint),
})

const space = await alice.createSpace('test')
Expand All @@ -142,9 +140,7 @@ export const BlobClient = Test.withContext({
})

const bytes = await randomBytes(128)
const { digest } = await alice.capability.blob.add(new Blob([bytes]), {
receiptsEndpoint,
})
const { digest } = await alice.capability.blob.add(new Blob([bytes]))

const result = await alice.capability.blob.get(digest)
assert.ok(result.ok)
Expand Down
30 changes: 14 additions & 16 deletions packages/w3up-client/test/client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const testClient = {
access: connection,
upload: connection,
},
receiptsEndpoint: new URL(receiptsEndpoint),
})

const space = await alice.createSpace('upload-test')
Expand All @@ -53,8 +54,7 @@ export const testClient = {
const dataCID = await alice.uploadFile(file, {
onShardStored: (meta) => {
carCID = meta.cid
},
receiptsEndpoint,
}
})

assert.deepEqual(await uploadTable.exists(space.did(), dataCID), {
Expand All @@ -81,6 +81,7 @@ export const testClient = {
access: connection,
upload: connection,
},
receiptsEndpoint: new URL(receiptsEndpoint),
})

const bytes = await randomBytes(128)
Expand Down Expand Up @@ -111,6 +112,7 @@ export const testClient = {
access: connection,
upload: connection,
},
receiptsEndpoint: new URL(receiptsEndpoint)
})

const space = await alice.createSpace('upload-dir-test')
Expand All @@ -130,8 +132,7 @@ export const testClient = {
const dataCID = await alice.uploadDirectory(files, {
onShardStored: (meta) => {
carCID = meta.cid
},
receiptsEndpoint,
}
})

assert.deepEqual(await uploadTable.exists(space.did(), dataCID), {
Expand All @@ -156,6 +157,7 @@ export const testClient = {
access: connection,
upload: connection,
},
receiptsEndpoint: new URL(receiptsEndpoint),
})

const space = await alice.createSpace('car-space')
Expand All @@ -173,8 +175,7 @@ export const testClient = {
const root = await alice.uploadCAR(car, {
onShardStored: (meta) => {
carCID = meta.cid
},
receiptsEndpoint,
}
})

assert.deepEqual(await uploadTable.exists(space.did(), root), {
Expand Down Expand Up @@ -204,7 +205,7 @@ export const testClient = {
serviceConf: {
access: connection,
upload: connection,
},
}
})
const receipt = await alice.getReceipt(taskCid)
// This is a real `piece/accept` receipt exported as fixture
Expand Down Expand Up @@ -655,6 +656,7 @@ export const testClient = {
access: connection,
upload: connection,
},
receiptsEndpoint: new URL(receiptsEndpoint),
})

// setup space
Expand All @@ -672,9 +674,7 @@ export const testClient = {
})

const content = new Blob([bytes])
const fileLink = await alice.uploadFile(content, {
receiptsEndpoint,
})
const fileLink = await alice.uploadFile(content)

assert.deepEqual(await uploadTable.exists(space.did(), fileLink), {
ok: true,
Expand Down Expand Up @@ -705,6 +705,7 @@ export const testClient = {
access: connection,
upload: connection,
},
receiptsEndpoint: new URL(receiptsEndpoint),
})

// setup space
Expand All @@ -722,9 +723,7 @@ export const testClient = {
})

const content = new Blob([bytes])
const fileLink = await alice.uploadFile(content, {
receiptsEndpoint,
})
const fileLink = await alice.uploadFile(content)

assert.deepEqual(await uploadTable.exists(space.did(), fileLink), {
ok: true,
Expand Down Expand Up @@ -782,6 +781,7 @@ export const testClient = {
access: connection,
upload: connection,
},
receiptsEndpoint: new URL(receiptsEndpoint),
})

// setup space
Expand All @@ -799,9 +799,7 @@ export const testClient = {
})

const content = new Blob(bytesArray)
const fileLink = await alice.uploadFile(content, {
receiptsEndpoint,
})
const fileLink = await alice.uploadFile(content)

const upload = await uploadTable.get(space.did(), fileLink)

Expand Down
2 changes: 2 additions & 0 deletions packages/w3up-client/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { StoreMemory } from '@web3-storage/access/stores/store-memory'
import * as Context from '@web3-storage/upload-api/test/context'
import * as Client from '@web3-storage/w3up-client'
import * as assert from 'assert'
import { receiptsEndpoint } from './helpers/utils.js'

/**
* @template [Context=void]
Expand Down Expand Up @@ -83,6 +84,7 @@ export const setup = async () => {
upload: context.connection,
filecoin: context.connection,
},
receiptsEndpoint: new URL(receiptsEndpoint)
})

return {
Expand Down

0 comments on commit 882d1c5

Please sign in to comment.