From 882d1c5bda412103fa7d635f4ef1b99c1782e17a Mon Sep 17 00:00:00 2001 From: Natalie Bravo Date: Wed, 20 Nov 2024 18:12:56 -0300 Subject: [PATCH] fix: use configured receipts endpoint --- packages/w3up-client/src/capability/blob.js | 6 +++- packages/w3up-client/src/client.js | 18 +++++++++-- .../w3up-client/test/capability/blob.test.js | 20 +++++-------- packages/w3up-client/test/client.test.js | 30 +++++++++---------- packages/w3up-client/test/test.js | 2 ++ 5 files changed, 44 insertions(+), 32 deletions(-) diff --git a/packages/w3up-client/src/capability/blob.js b/packages/w3up-client/src/capability/blob.js index 450fcfa4d..d9f0c3e60 100644 --- a/packages/w3up-client/src/capability/blob.js +++ b/packages/w3up-client/src/capability/blob.js @@ -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)) } diff --git a/packages/w3up-client/src/client.js b/packages/w3up-client/src/client.js index 89211ad7f..aebdd9d23 100644 --- a/packages/w3up-client/src/client.js +++ b/packages/w3up-client/src/client.js @@ -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) } @@ -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) } @@ -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) } diff --git a/packages/w3up-client/test/capability/blob.test.js b/packages/w3up-client/test/capability/blob.test.js index 1baacf1ff..564dbddcf 100644 --- a/packages/w3up-client/test/capability/blob.test.js +++ b/packages/w3up-client/test/capability/blob.test.js @@ -16,6 +16,7 @@ export const BlobClient = Test.withContext({ access: connection, upload: connection, }, + receiptsEndpoint: new URL(receiptsEndpoint) }) const space = await alice.createSpace('test') @@ -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), { @@ -54,6 +53,7 @@ export const BlobClient = Test.withContext({ access: connection, upload: connection, }, + receiptsEndpoint: new URL(receiptsEndpoint) }) const space = await alice.createSpace('test') @@ -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 { @@ -93,6 +91,7 @@ export const BlobClient = Test.withContext({ access: connection, upload: connection, }, + receiptsEndpoint: new URL(receiptsEndpoint), }) const space = await alice.createSpace('test') @@ -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) @@ -126,6 +123,7 @@ export const BlobClient = Test.withContext({ access: connection, upload: connection, }, + receiptsEndpoint: new URL(receiptsEndpoint), }) const space = await alice.createSpace('test') @@ -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) diff --git a/packages/w3up-client/test/client.test.js b/packages/w3up-client/test/client.test.js index 10da152c4..e10bed0e2 100644 --- a/packages/w3up-client/test/client.test.js +++ b/packages/w3up-client/test/client.test.js @@ -35,6 +35,7 @@ export const testClient = { access: connection, upload: connection, }, + receiptsEndpoint: new URL(receiptsEndpoint), }) const space = await alice.createSpace('upload-test') @@ -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), { @@ -81,6 +81,7 @@ export const testClient = { access: connection, upload: connection, }, + receiptsEndpoint: new URL(receiptsEndpoint), }) const bytes = await randomBytes(128) @@ -111,6 +112,7 @@ export const testClient = { access: connection, upload: connection, }, + receiptsEndpoint: new URL(receiptsEndpoint) }) const space = await alice.createSpace('upload-dir-test') @@ -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), { @@ -156,6 +157,7 @@ export const testClient = { access: connection, upload: connection, }, + receiptsEndpoint: new URL(receiptsEndpoint), }) const space = await alice.createSpace('car-space') @@ -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), { @@ -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 @@ -655,6 +656,7 @@ export const testClient = { access: connection, upload: connection, }, + receiptsEndpoint: new URL(receiptsEndpoint), }) // setup space @@ -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, @@ -705,6 +705,7 @@ export const testClient = { access: connection, upload: connection, }, + receiptsEndpoint: new URL(receiptsEndpoint), }) // setup space @@ -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, @@ -782,6 +781,7 @@ export const testClient = { access: connection, upload: connection, }, + receiptsEndpoint: new URL(receiptsEndpoint), }) // setup space @@ -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) diff --git a/packages/w3up-client/test/test.js b/packages/w3up-client/test/test.js index fd0647944..ef87f178b 100644 --- a/packages/w3up-client/test/test.js +++ b/packages/w3up-client/test/test.js @@ -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] @@ -83,6 +84,7 @@ export const setup = async () => { upload: context.connection, filecoin: context.connection, }, + receiptsEndpoint: new URL(receiptsEndpoint) }) return {