Skip to content

Commit

Permalink
fix: failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Gozala committed May 15, 2024
1 parent a3382e4 commit f1aebae
Show file tree
Hide file tree
Showing 16 changed files with 137 additions and 60 deletions.
3 changes: 3 additions & 0 deletions packages/upload-client/src/blob.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ export async function add(
},
},
proofs,
nonce: options.nonce,
})
.execute(conn)
},
Expand Down Expand Up @@ -341,6 +342,7 @@ export async function list(
cursor: options.cursor,
size: options.size,
},
nonce: options.nonce,
})
.execute(conn)

Expand Down Expand Up @@ -389,6 +391,7 @@ export async function remove(
digest: multihash.bytes,
},
proofs,
nonce: options.nonce,
})
.execute(conn)

Expand Down
4 changes: 4 additions & 0 deletions packages/upload-client/src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export async function add(
with: SpaceDID.from(resource),
nb: { link, size: bytes.length },
proofs,
nonce: options.nonce,
})
.execute(conn)
},
Expand Down Expand Up @@ -185,6 +186,7 @@ export async function get(
with: SpaceDID.from(resource),
nb: { link },
proofs,
nonce: options.nonce,
})
.execute(conn)
},
Expand Down Expand Up @@ -240,6 +242,7 @@ export async function list(
size: options.size,
pre: options.pre,
},
nonce: options.nonce,
})
.execute(conn)

Expand Down Expand Up @@ -286,6 +289,7 @@ export async function remove(
with: SpaceDID.from(resource),
nb: { link },
proofs,
nonce: options.nonce,
})
.execute(conn)

Expand Down
1 change: 1 addition & 0 deletions packages/upload-client/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ export interface RequestOptions
Connectable,
UploadProgressTrackable {
fetch?: typeof globalThis.fetch
nonce?: string
}

export interface ListRequestOptions extends RequestOptions, Pageable {}
Expand Down
4 changes: 4 additions & 0 deletions packages/upload-client/src/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export async function add(
with: SpaceDID.from(resource),
nb: { root, shards },
proofs,
nonce: options.nonce,
})
.execute(conn)
},
Expand Down Expand Up @@ -103,6 +104,7 @@ export async function get(
with: SpaceDID.from(resource),
nb: { root },
proofs,
nonce: options.nonce,
})
.execute(conn)
},
Expand Down Expand Up @@ -159,6 +161,7 @@ export async function list(
size: options.size,
pre: options.pre,
},
nonce: options.nonce,
})
.execute(conn)

Expand Down Expand Up @@ -205,6 +208,7 @@ export async function remove(
with: SpaceDID.from(resource),
nb: { root },
proofs,
nonce: options.nonce,
})
.execute(conn)

Expand Down
2 changes: 1 addition & 1 deletion packages/w3up-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
"prepare": "npm run build",
"test": "npm-run-all -p -r mock:* test:all",
"test:all": "run-s test:node test:browser",
"test:node": "hundreds -r html -r text mocha 'test/**/!(*.browser).test.js' -n experimental-vm-modules -n no-warnings -n stack-trace-limit=1000",
"test:node": "hundreds -r html -r text mocha 'test/**/!(*.browser).test.js' -n experimental-vm-modules -n no-warnings -n stack-trace-limit=1000 -t 10000",
"test:browser": "playwright-test --runner mocha 'test/**/!(*.node).test.js'",
"mock": "run-p mock:*",
"mock:bucket-200": "PORT=8989 STATUS=200 node test/helpers/bucket-server.js",
Expand Down
27 changes: 22 additions & 5 deletions packages/w3up-client/src/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,13 @@ export class AccountPlan {

/**
* Gets information about the plan associated with this account.
*
* @param {object} [options]
* @param {string} [options.nonce]
*/
async get() {
async get(options) {
return await Plan.get(this.model, {
...options,
account: this.model.id,
proofs: this.model.proofs,
})
Expand All @@ -219,9 +223,12 @@ export class AccountPlan {
* Sets the plan associated with this account.
*
* @param {import('@ucanto/interface').DID} productDID
* @param {object} [options]
* @param {string} [options.nonce]
*/
async set(productDID) {
async set(productDID, options) {
return await Plan.set(this.model, {
...options,
account: this.model.id,
product: productDID,
proofs: this.model.proofs,
Expand All @@ -232,17 +239,27 @@ export class AccountPlan {
*
* @param {import('@web3-storage/access').AccountDID} accountDID
* @param {string} returnURL
* @returns
* @param {object} [options]
* @param {string} [options.nonce]
*/
async createAdminSession(accountDID, returnURL) {
async createAdminSession(accountDID, returnURL, options) {
return await Plan.createAdminSession(this.model, {
...options,
account: accountDID,
returnURL,
})
}

async subscriptions() {
/**
*
* @param {object} [options]
* @param {string} [options.nonce]
*/

async subscriptions(options) {
return await Subscription.list(this.model, {
...options,
account: this.model.id,
proofs: this.model.proofs,
})
Expand Down
10 changes: 8 additions & 2 deletions packages/w3up-client/src/capability/filecoin.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ export class FilecoinClient extends Base {
*
* @param {import('multiformats').UnknownLink} content
* @param {import('@web3-storage/capabilities/types').PieceLink} piece
* @param {object} [options]
* @param {string} [options.nonce]
*/
async offer(content, piece) {
async offer(content, piece, options) {
const conf = await this._invocationConfig([FilecoinCapabilities.offer.can])
return Storefront.filecoinOffer(conf, content, piece, {
...options,
connection: this._serviceConf.filecoin,
})
}
Expand All @@ -23,10 +26,13 @@ export class FilecoinClient extends Base {
* Request info about a content piece in Filecoin deals
*
* @param {import('@web3-storage/capabilities/types').PieceLink} piece
* @param {object} [options]
* @param {string} [options.nonce]
*/
async info(piece) {
async info(piece, options) {
const conf = await this._invocationConfig([FilecoinCapabilities.info.can])
return Storefront.filecoinInfo(conf, piece, {
...options,
connection: this._serviceConf.filecoin,
})
}
Expand Down
36 changes: 27 additions & 9 deletions packages/w3up-client/src/capability/plan.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ export class PlanClient extends Base {
/**
*
* @param {import('@web3-storage/access').AccountDID} account
* @param {object} [options]
* @param {string} [options.nonce]
*/
async get(account) {
const out = await get({ agent: this.agent }, { account })
async get(account, options) {
const out = await get({ agent: this.agent }, { ...options, account })

if (!out.ok) {
throw new Error(`failed ${Plan.get.can} invocation`, {
Expand All @@ -22,9 +24,14 @@ export class PlanClient extends Base {
*
* @param {API.AccountDID} account
* @param {API.DID} product
* @param {object} [options]
* @param {string} [options.nonce]
*/
async set(account, product) {
const out = await set({ agent: this.agent }, { account, product })
async set(account, product, options) {
const out = await set(
{ agent: this.agent },
{ ...options, account, product }
)
if (!out.ok) {
throw new Error(`failed ${Plan.set.can} invocation`, {
cause: out.error,
Expand All @@ -37,11 +44,13 @@ export class PlanClient extends Base {
*
* @param {API.AccountDID} account
* @param {string} returnURL
* @param {object} [options]
* @param {string} [options.nonce]
*/
async createAdminSession(account, returnURL) {
async createAdminSession(account, returnURL, options) {
const out = await createAdminSession(
{ agent: this.agent },
{ account, returnURL }
{ ...options, account, returnURL }
)
if (!out.ok) {
throw new Error(`failed ${Plan.createAdminSession.can} invocation`, {
Expand All @@ -58,12 +67,14 @@ export class PlanClient extends Base {
* @param {{agent: API.Agent}} client
* @param {object} options
* @param {API.AccountDID} options.account
* @param {string} [options.nonce]
* @param {API.Delegation[]} [options.proofs]
*/
export const get = async ({ agent }, { account, proofs = [] }) => {
export const get = async ({ agent }, { account, nonce, proofs = [] }) => {
const receipt = await agent.invokeAndExecute(Plan.get, {
with: account,
proofs,
nonce,
})
return receipt.out
}
Expand All @@ -75,12 +86,17 @@ export const get = async ({ agent }, { account, proofs = [] }) => {
* @param {object} options
* @param {API.DID} options.product
* @param {API.AccountDID} options.account
* @param {string} [options.nonce]
* @param {API.Delegation[]} [options.proofs]
*/
export const set = async ({ agent }, { account, product, proofs = [] }) => {
export const set = async (
{ agent },
{ account, product, nonce, proofs = [] }
) => {
const receipt = await agent.invokeAndExecute(Plan.set, {
with: account,
nb: { product },
nonce,
proofs,
})
return receipt.out
Expand All @@ -96,15 +112,17 @@ export const set = async ({ agent }, { account, product, proofs = [] }) => {
* @param {object} options
* @param {API.AccountDID} options.account
* @param {string} options.returnURL
* @param {string} [options.nonce]
* @param {API.Delegation[]} [options.proofs]
*/
export const createAdminSession = async (
{ agent },
{ account, returnURL, proofs = [] }
{ account, returnURL, nonce, proofs = [] }
) => {
const receipt = await agent.invokeAndExecute(Plan.createAdminSession, {
with: account,
proofs,
nonce,
nb: {
returnURL,
},
Expand Down
6 changes: 4 additions & 2 deletions packages/w3up-client/src/capability/space.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ export class SpaceClient extends Base {
* Get information about a space.
*
* @param {import('../types.js').DID} space - DID of the space to retrieve info about.
* @param {object} [options]
* @param {string} [options.nonce]
*/
async info(space) {
return await this._agent.getSpaceInfo(space)
async info(space, options) {
return await this._agent.getSpaceInfo(space, options)
}
}
10 changes: 7 additions & 3 deletions packages/w3up-client/src/capability/subscription.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ export class SubscriptionClient extends Base {
* List subscriptions for the passed account.
*
* @param {import('@web3-storage/access').AccountDID} account
* @param {object} [options]
* @param {string} [options.nonce]
*/
/* c8 ignore next */
async list(account) {
const out = await list({ agent: this.agent }, { account })
async list(account, options) {
const out = await list({ agent: this.agent }, { ...options, account })
/* c8 ignore next 8 */
if (!out.ok) {
throw new Error(
Expand All @@ -34,13 +36,15 @@ export class SubscriptionClient extends Base {
* @param {{agent: API.Agent}} client
* @param {object} options
* @param {API.AccountDID} options.account
* @param {string} [options.nonce]
* @param {API.Delegation[]} [options.proofs]
*/
export const list = async ({ agent }, { account, proofs = [] }) => {
export const list = async ({ agent }, { account, nonce, proofs = [] }) => {
const receipt = await agent.invokeAndExecute(SubscriptionCapabilities.list, {
with: account,
proofs,
nb: {},
nonce,
})
return receipt.out
}
16 changes: 13 additions & 3 deletions packages/w3up-client/src/capability/usage.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@ export class UsageClient extends Base {
*
* @param {import('../types.js').SpaceDID} space
* @param {{ from: Date, to: Date }} period
* @param {object} [options]
* @param {string} [options.nonce]
*/
async report(space, period) {
const out = await report({ agent: this.agent }, { space, period })
async report(space, period, options) {
const out = await report(
{ agent: this.agent },
{ ...options, space, period }
)
/* c8 ignore next 7 */
if (!out.ok) {
throw new Error(`failed ${UsageCapabilities.report.can} invocation`, {
Expand All @@ -32,13 +37,18 @@ export class UsageClient extends Base {
* @param {object} options
* @param {API.SpaceDID} options.space
* @param {{ from: Date, to: Date }} options.period
* @param {string} [options.nonce]
* @param {API.Delegation[]} [options.proofs]
* @returns {Promise<API.Result<API.UsageReportSuccess, API.UsageReportFailure>>}
*/
export const report = async ({ agent }, { space, period, proofs = [] }) => {
export const report = async (
{ agent },
{ space, period, nonce, proofs = [] }
) => {
const receipt = await agent.invokeAndExecute(UsageCapabilities.report, {
with: space,
proofs,
nonce,
nb: {
period: {
from: Math.floor(period.from.getTime() / 1000),
Expand Down
4 changes: 2 additions & 2 deletions packages/w3up-client/test/account.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,13 @@ export const testAccount = Test.withContext({
)
)

const { ok: plan } = await account.plan.get()
const { ok: plan } = await account.plan.get({ nonce: '2' })

assert.ok(plan?.product, 'did:web:free.web3.storage')

Result.unwrap(await account.plan.set('did:web:lite.web3.storage'))

const { ok: newPlan } = await account.plan.get()
const { ok: newPlan } = await account.plan.get({ nonce: '3' })

assert.ok(newPlan?.product, 'did:web:lite.web3.storage')
},
Expand Down
Loading

0 comments on commit f1aebae

Please sign in to comment.