Skip to content

Commit

Permalink
fix: client
Browse files Browse the repository at this point in the history
  • Loading branch information
vasco-santos committed Nov 3, 2023
1 parent fb3170d commit 5f63e59
Show file tree
Hide file tree
Showing 28 changed files with 155 additions and 115 deletions.
6 changes: 5 additions & 1 deletion packages/filecoin-api/src/aggregator/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ export type BufferQueue = Queue<BufferMessage>
export type BufferStore = Store<Link, BufferRecord>
export type AggregateStore = Store<AggregateRecordKey, AggregateRecord>
export type PieceAcceptQueue = Queue<PieceAcceptMessage>
export type InclusionStore = QueryableStore<InclusionRecordKey, InclusionRecord, InclusionRecordQueryByGroup>
export type InclusionStore = QueryableStore<
InclusionRecordKey,
InclusionRecord,
InclusionRecordQueryByGroup
>
export type AggregateOfferQueue = Queue<AggregateOfferMessage>

export interface ServiceContext {
Expand Down
6 changes: 5 additions & 1 deletion packages/filecoin-api/src/deal-tracker/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import type { Signer } from '@ucanto/interface'
import { PieceLink } from '@web3-storage/data-segment'
import { QueryableStore } from '../types.js'

export type DealStore = QueryableStore<DealRecordKey, DealRecord, DealRecordQueryByPiece>
export type DealStore = QueryableStore<
DealRecordKey,
DealRecord,
DealRecordQueryByPiece
>

export interface ServiceContext {
/**
Expand Down
3 changes: 2 additions & 1 deletion packages/filecoin-api/src/dealer/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ export interface AggregateUpdatedStatusEventContext {
dealerService: ServiceConfig<DealerService>
}

export interface CronContext extends Pick<ServiceContext, 'aggregateStore' | 'dealTrackerService'> {}
export interface CronContext
extends Pick<ServiceContext, 'aggregateStore' | 'dealTrackerService'> {}

export interface AggregateRecord {
/**
Expand Down
2 changes: 1 addition & 1 deletion packages/filecoin-api/src/dealer/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ async function updateApprovedDeals({
{ aggregate: deal.aggregate },
{
status: 'accepted',
updatedAt: new Date().toISOString()
updatedAt: new Date().toISOString(),
}
)

Expand Down
15 changes: 7 additions & 8 deletions packages/filecoin-api/src/dealer/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ import * as DealerCaps from '@web3-storage/capabilities/filecoin/dealer'
import { DealTracker } from '@web3-storage/filecoin-client'
// eslint-disable-next-line no-unused-vars
import * as API from '../types.js'
import {
StoreOperationFailed,
DecodeBlockOperationFailed,
} from '../errors.js'
import { StoreOperationFailed, DecodeBlockOperationFailed } from '../errors.js'

/**
* @param {API.Input<DealerCaps.aggregateOffer>} input
Expand Down Expand Up @@ -112,17 +109,19 @@ export const aggregateAccept = async ({ capability }, context) => {
const deals = Object.keys(info.out.ok.deals || {})
if (!deals.length) {
return {
error: new Server.Failure('no deals were obtained for given aggregate CID')
error: new Server.Failure(
'no deals were obtained for given aggregate CID'
),
}
}

// For receipts, we only care about first deal
// TODO: We need to revisit this with renewals
const deal = {
dataType: 0n,
dataSource: {
dealID: BigInt(deals[0])
}
dealID: BigInt(deals[0]),
},
}

return {
Expand Down
6 changes: 5 additions & 1 deletion packages/filecoin-api/src/storefront/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ import {
ServiceConfig,
} from '../types.js'

export type PieceStore = UpdatableAndQueryableStore<PieceRecordKey, PieceRecord, Pick<PieceRecord, 'status'>>
export type PieceStore = UpdatableAndQueryableStore<
PieceRecordKey,
PieceRecord,
Pick<PieceRecord, 'status'>
>
export type FilecoinSubmitQueue = Queue<FilecoinSubmitMessage>
export type PieceOfferQueue = Queue<PieceOfferMessage>
export type TaskStore = Store<UnknownLink, Invocation>
Expand Down
2 changes: 1 addition & 1 deletion packages/filecoin-api/src/storefront/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const handleFilecoinSubmitMessage = async (context, message) => {
}
if (hasRes.ok) {
return {
ok: {}
ok: {},
}
}

Expand Down
5 changes: 1 addition & 4 deletions packages/filecoin-api/src/storefront/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ import * as StorefrontCaps from '@web3-storage/capabilities/filecoin/storefront'
import * as AggregatorCaps from '@web3-storage/capabilities/filecoin/aggregator'
// eslint-disable-next-line no-unused-vars
import * as API from '../types.js'
import {
QueueOperationFailed,
StoreOperationFailed,
} from '../errors.js'
import { QueueOperationFailed, StoreOperationFailed } from '../errors.js'

/**
* @param {API.Input<StorefrontCaps.filecoinOffer>} input
Expand Down
14 changes: 4 additions & 10 deletions packages/filecoin-api/test/aggregator.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,9 @@ describe('Aggregator', () => {
// resources
/** @type {Map<string, unknown[]>} */
const queuedMessages = new Map()
const { pieceQueue } = getQueues(queuedMessages)
const {
pieceQueue,
} = getQueues(queuedMessages)
const {
aggregator: {
pieceStore,
aggregateStore,
inclusionStore,
},
aggregator: { pieceStore, aggregateStore, inclusionStore },
} = getStoreImplementations()

await test(
Expand All @@ -55,7 +49,7 @@ describe('Aggregator', () => {
inclusionStore,
pieceQueue,
queuedMessages,
validateAuthorization
validateAuthorization,
}
)
})
Expand Down Expand Up @@ -138,7 +132,7 @@ describe('Aggregator', () => {
minAggregateSize: 2 ** 34,
minUtilizationFactor: 4,
},
validateAuthorization
validateAuthorization,
}
)
})
Expand Down
6 changes: 3 additions & 3 deletions packages/filecoin-api/test/context/queue-implementations.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Queue } from './queue.js'

/**
* @param {Map<string, unknown[]>} queuedMessages
* @param {Map<string, unknown[]>} queuedMessages
*/
export const getQueueImplementations = (
queuedMessages,
Expand All @@ -26,7 +26,7 @@ export const getQueueImplementations = (
return {
storefront: {
filecoinSubmitQueue,
pieceOfferQueue
}
pieceOfferQueue,
},
}
}
2 changes: 1 addition & 1 deletion packages/filecoin-api/test/context/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ export function getConnection(id, service) {
id: id,
service,
codec: CAR.inbound,
validateAuthorization
validateAuthorization,
})
const connection = Client.connect({
id: id,
Expand Down
9 changes: 6 additions & 3 deletions packages/filecoin-api/test/context/store-implementations.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,18 @@ export const getStoreImplementations = (
/** @type {Set<DealerAggregateRecord>} */ items,
/** @type {Partial<DealerAggregateRecord>} */ search
) => {
return Array.from(items).filter((i) => i.status === search.status || i.aggregate.equals(search.aggregate))
return Array.from(items).filter(
(i) =>
i.status === search.status || i.aggregate.equals(search.aggregate)
)
},
updateFn: (
/** @type {Set<DealerAggregateRecord>} */ items,
/** @type {DealerAggregateRecordKey} */ key,
/** @type {Partial<DealerAggregateRecord>} */ item
) => {
const itemToUpdate = Array.from(items).find(
(i) => i.aggregate.equals(key.aggregate)
const itemToUpdate = Array.from(items).find((i) =>
i.aggregate.equals(key.aggregate)
)
if (!itemToUpdate) {
throw new Error('not found')
Expand Down
2 changes: 1 addition & 1 deletion packages/filecoin-api/test/deal-tracker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('deal-tracker', () => {
assert.fail(error)
},
},
validateAuthorization
validateAuthorization,
}
)
})
Expand Down
4 changes: 2 additions & 2 deletions packages/filecoin-api/test/dealer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe('Dealer', () => {
audience: dealTrackerSigner,
},
},
validateAuthorization
validateAuthorization,
}
)
})
Expand Down Expand Up @@ -122,7 +122,7 @@ describe('Dealer', () => {
},
},
service,
validateAuthorization
validateAuthorization,
}
)
})
Expand Down
30 changes: 24 additions & 6 deletions packages/filecoin-api/test/events/aggregator.js
Original file line number Diff line number Diff line change
Expand Up @@ -674,8 +674,14 @@ export const test = {
if (!inclusionProof.ok) {
throw new Error()
}
assert.deepEqual(BigInt(message.inclusion.subtree[0]), inclusionProof.ok?.[0][0])
assert.deepEqual(BigInt(message.inclusion.index[0]), inclusionProof.ok?.[1][0])
assert.deepEqual(
BigInt(message.inclusion.subtree[0]),
inclusionProof.ok?.[0][0]
)
assert.deepEqual(
BigInt(message.inclusion.index[0]),
inclusionProof.ok?.[1][0]
)

assert.deepEqual(message.inclusion.subtree[1], inclusionProof.ok?.[0][1])
assert.deepEqual(message.inclusion.index[1], inclusionProof.ok?.[1][1])
Expand Down Expand Up @@ -824,13 +830,25 @@ export const test = {
assert.equal(hasStoredInclusion.ok?.group, group)
assert.ok(hasStoredInclusion.ok?.insertedAt)
// @ts-ignore
assert.deepEqual(BigInt(message.inclusion.subtree[0]), BigInt(hasStoredInclusion.ok?.inclusion.subtree[0]))
assert.deepEqual(
BigInt(message.inclusion.subtree[0]),
BigInt(hasStoredInclusion.ok?.inclusion.subtree[0])
)
// @ts-ignore
assert.deepEqual(BigInt(message.inclusion.index[0]), BigInt(hasStoredInclusion.ok?.inclusion.index[0]))
assert.deepEqual(
BigInt(message.inclusion.index[0]),
BigInt(hasStoredInclusion.ok?.inclusion.index[0])
)
// @ts-ignore
assert.deepEqual(message.inclusion.subtree[1], hasStoredInclusion.ok?.inclusion.subtree[1])
assert.deepEqual(
message.inclusion.subtree[1],
hasStoredInclusion.ok?.inclusion.subtree[1]
)
// @ts-ignore
assert.deepEqual(message.inclusion.index[1], hasStoredInclusion.ok?.inclusion.index[1])
assert.deepEqual(
message.inclusion.index[1],
hasStoredInclusion.ok?.inclusion.index[1]
)
},
'handles piece accept message errors when fails to store on inclusion store':
wichMockableContext(
Expand Down
2 changes: 1 addition & 1 deletion packages/filecoin-api/test/events/dealer.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ export const test = {

// Validate stores
const storedDealAfterCron = await context.aggregateStore.get({
aggregate: aggregate.link.link()
aggregate: aggregate.link.link(),
})
assert.ok(storedDealAfterCron.ok)
assert.equal(storedDealAfterCron.ok?.status, 'accepted')
Expand Down
8 changes: 4 additions & 4 deletions packages/filecoin-api/test/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@ export const test = {
...StorefrontService.test,
},
aggregator: {
...AggregatorService.test
...AggregatorService.test,
},
dealer: {
...DealerService.test,
},
dealTracker: {
...DealTrackerService.test
}
...DealTrackerService.test,
},
},
events: {
storefront: {
...StorefrontEvents.test,
},
aggregator: {
...AggregatorEvents.test
...AggregatorEvents.test,
},
dealer: {
...DealerEvents.test,
Expand Down
4 changes: 2 additions & 2 deletions packages/filecoin-api/test/services/aggregator.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ export const test = {
piece,
group,
},
expiration: Infinity
expiration: Infinity,
})

const response = await pieceAcceptInv.execute(connection)
Expand Down Expand Up @@ -306,7 +306,7 @@ export const test = {
aggregate: aggregate.link,
pieces: piecesBlock.cid,
},
expiration: Infinity
expiration: Infinity,
})
.delegate()
assert.ok(response.fx.join)
Expand Down
Loading

0 comments on commit 5f63e59

Please sign in to comment.