Skip to content

Commit 64e14ab

Browse files
authored
[Reputation Oracle] feat: get rid of sdk's storage module (#2781)
1 parent 1c1dc2f commit 64e14ab

File tree

12 files changed

+211
-124
lines changed

12 files changed

+211
-124
lines changed

packages/apps/job-launcher/server/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"experimentalDecorators": true,
88
"allowSyntheticDefaultImports": true,
99
"allowJs": true,
10-
"target": "ES2020",
10+
"target": "ES2022",
1111
"sourceMap": true,
1212
"outDir": "./dist",
1313
"baseUrl": "./",

packages/apps/reputation-oracle/server/docker-compose.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,9 @@ services:
2626
ports:
2727
- 9001:9001
2828
- 9000:9000
29-
environment:
30-
MINIO_ROOT_USER: ${S3_ACCESS_KEY}
31-
MINIO_ROOT_PASSWORD: ${S3_SECRET_KEY}
3229
entrypoint: 'sh'
3330
command:
34-
-c "mkdir -p /data/reputation && minio server /data --console-address ':9001'"
31+
-c "minio server /data --console-address ':9001'"
3532
healthcheck:
3633
test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
3734
interval: 5s
@@ -45,7 +42,7 @@ services:
4542
condition: service_healthy
4643
entrypoint: >
4744
/bin/sh -c "
48-
/usr/bin/mc config host add myminio http://minio:9000 ${S3_ACCESS_KEY} ${S3_SECRET_KEY};
45+
/usr/bin/mc config host add myminio http://minio:9000 minioadmin minioadmin;
4946
/usr/bin/mc mb myminio/reputation;
5047
/usr/bin/mc anonymous set public myminio/reputation;
5148
"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export class BaseError extends Error {
2+
constructor(message: string, cause?: unknown) {
3+
const errorOptions: ErrorOptions = {};
4+
if (cause) {
5+
errorOptions.cause = cause;
6+
}
7+
8+
super(message, errorOptions);
9+
this.name = this.constructor.name;
10+
}
11+
}

packages/apps/reputation-oracle/server/src/modules/payout/payout.service.spec.ts

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,9 @@ describe('PayoutService', () => {
142142
job_bounty: '10',
143143
};
144144

145-
jest.spyOn(storageService, 'download').mockResolvedValue(manifest);
145+
jest
146+
.spyOn(storageService, 'downloadJsonLikeData')
147+
.mockResolvedValue(manifest);
146148

147149
const escrowAddress = MOCK_ADDRESS;
148150
const chainId = ChainId.LOCALHOST;
@@ -160,7 +162,9 @@ describe('PayoutService', () => {
160162
requestType: JobRequestType.FORTUNE,
161163
};
162164

163-
jest.spyOn(storageService, 'download').mockResolvedValue(manifest);
165+
jest
166+
.spyOn(storageService, 'downloadJsonLikeData')
167+
.mockResolvedValue(manifest);
164168

165169
const results: SaveResultDto = {
166170
url: MOCK_FILE_URL,
@@ -236,7 +240,9 @@ describe('PayoutService', () => {
236240
job_bounty: '10',
237241
};
238242

239-
jest.spyOn(storageService, 'download').mockResolvedValue(manifest);
243+
jest
244+
.spyOn(storageService, 'downloadJsonLikeData')
245+
.mockResolvedValue(manifest);
240246

241247
const escrowAddress = MOCK_ADDRESS;
242248
const chainId = ChainId.LOCALHOST;
@@ -261,7 +267,9 @@ describe('PayoutService', () => {
261267
requestType: JobRequestType.FORTUNE,
262268
};
263269

264-
jest.spyOn(storageService, 'download').mockResolvedValue(manifest);
270+
jest
271+
.spyOn(storageService, 'downloadJsonLikeData')
272+
.mockResolvedValue(manifest);
265273

266274
const results: PayoutsDataDto = {
267275
recipients: [MOCK_ADDRESS],
@@ -332,7 +340,7 @@ describe('PayoutService', () => {
332340
];
333341

334342
jest
335-
.spyOn(storageService, 'download')
343+
.spyOn(storageService, 'downloadJsonLikeData')
336344
.mockResolvedValue(intermediateResults);
337345

338346
jest.spyOn(storageService, 'uploadJobSolutions').mockResolvedValue({
@@ -361,7 +369,9 @@ describe('PayoutService', () => {
361369
requestType: JobRequestType.FORTUNE,
362370
};
363371

364-
jest.spyOn(storageService, 'download').mockResolvedValue([] as any);
372+
jest
373+
.spyOn(storageService, 'downloadJsonLikeData')
374+
.mockResolvedValue([] as any);
365375

366376
await expect(
367377
payoutService.saveResultsFortune(manifest, chainId, escrowAddress),
@@ -393,7 +403,7 @@ describe('PayoutService', () => {
393403
];
394404

395405
jest
396-
.spyOn(storageService, 'download')
406+
.spyOn(storageService, 'downloadJsonLikeData')
397407
.mockResolvedValue(intermediateResults);
398408

399409
await expect(
@@ -425,7 +435,7 @@ describe('PayoutService', () => {
425435
];
426436

427437
jest
428-
.spyOn(storageService, 'download')
438+
.spyOn(storageService, 'downloadJsonLikeData')
429439
.mockResolvedValue(intermediateResults);
430440

431441
const result = await payoutService.calculatePayoutsFortune(
@@ -475,7 +485,9 @@ describe('PayoutService', () => {
475485
url: MOCK_FILE_URL,
476486
hash: MOCK_FILE_HASH,
477487
});
478-
jest.spyOn(storageService, 'download').mockResolvedValue(results);
488+
jest
489+
.spyOn(storageService, 'downloadJsonLikeData')
490+
.mockResolvedValue(results);
479491

480492
const result = await payoutService.saveResultsCvat(
481493
chainId,
@@ -539,7 +551,9 @@ describe('PayoutService', () => {
539551
],
540552
};
541553

542-
jest.spyOn(storageService, 'download').mockResolvedValue(results);
554+
jest
555+
.spyOn(storageService, 'downloadJsonLikeData')
556+
.mockResolvedValue(results);
543557

544558
const result = await payoutService.calculatePayoutsCvat(
545559
manifest as any,
@@ -563,7 +577,9 @@ describe('PayoutService', () => {
563577
results: [],
564578
};
565579

566-
jest.spyOn(storageService, 'download').mockResolvedValue(results);
580+
jest
581+
.spyOn(storageService, 'downloadJsonLikeData')
582+
.mockResolvedValue(results);
567583

568584
await expect(
569585
payoutService.calculatePayoutsCvat(

packages/apps/reputation-oracle/server/src/modules/payout/payout.service.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ export class PayoutService {
6060
);
6161
}
6262

63-
const manifest = await this.storageService.download(manifestUrl);
63+
const manifest =
64+
await this.storageService.downloadJsonLikeData(manifestUrl);
6465

6566
const requestType = getRequestType(manifest);
6667

@@ -102,7 +103,8 @@ export class PayoutService {
102103
);
103104
}
104105

105-
const manifest = await this.storageService.download(manifestUrl);
106+
const manifest =
107+
await this.storageService.downloadJsonLikeData(manifestUrl);
106108

107109
const requestType = getRequestType(manifest);
108110

@@ -209,7 +211,7 @@ export class PayoutService {
209211
const intermediateResultsUrl =
210212
await escrowClient.getIntermediateResultsUrl(escrowAddress);
211213

212-
const intermediateResults = (await this.storageService.download(
214+
const intermediateResults = (await this.storageService.downloadJsonLikeData(
213215
intermediateResultsUrl,
214216
)) as FortuneFinalResult[];
215217

@@ -279,7 +281,7 @@ export class PayoutService {
279281
manifest: FortuneManifestDto,
280282
finalResultsUrl: string,
281283
): Promise<PayoutsDataDto> {
282-
const finalResults = (await this.storageService.download(
284+
const finalResults = (await this.storageService.downloadJsonLikeData(
283285
finalResultsUrl,
284286
)) as FortuneFinalResult[];
285287

@@ -315,9 +317,10 @@ export class PayoutService {
315317
const intermediateResultsUrl =
316318
await escrowClient.getIntermediateResultsUrl(escrowAddress);
317319

318-
const annotations: CvatAnnotationMeta = await this.storageService.download(
319-
`${intermediateResultsUrl}/${CVAT_VALIDATION_META_FILENAME}`,
320-
);
320+
const annotations: CvatAnnotationMeta =
321+
await this.storageService.downloadJsonLikeData(
322+
`${intermediateResultsUrl}/${CVAT_VALIDATION_META_FILENAME}`,
323+
);
321324

322325
// If annotation meta results does not exist
323326
if (

packages/apps/reputation-oracle/server/src/modules/reputation/reputation.service.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ describe('ReputationService', () => {
137137
};
138138

139139
jest
140-
.spyOn(storageService, 'download')
140+
.spyOn(storageService, 'downloadJsonLikeData')
141141
.mockResolvedValueOnce(manifest) // Mock manifest
142142
.mockResolvedValueOnce([]); // Mock final results
143143

@@ -165,7 +165,7 @@ describe('ReputationService', () => {
165165
];
166166

167167
jest
168-
.spyOn(storageService, 'download')
168+
.spyOn(storageService, 'downloadJsonLikeData')
169169
.mockResolvedValueOnce(manifest)
170170
.mockResolvedValueOnce(finalResults);
171171

@@ -238,7 +238,7 @@ describe('ReputationService', () => {
238238
}));
239239

240240
jest
241-
.spyOn(storageService, 'download')
241+
.spyOn(storageService, 'downloadJsonLikeData')
242242
.mockResolvedValueOnce(manifest) // Mock manifest
243243
.mockResolvedValueOnce([]); // Mock final results
244244

@@ -289,7 +289,7 @@ describe('ReputationService', () => {
289289
};
290290

291291
jest
292-
.spyOn(storageService, 'download')
292+
.spyOn(storageService, 'downloadJsonLikeData')
293293
.mockResolvedValueOnce(manifest)
294294
.mockResolvedValueOnce(annotationMeta);
295295

packages/apps/reputation-oracle/server/src/modules/reputation/reputation.service.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ export class ReputationService {
6565
);
6666
}
6767

68-
const manifest = await this.storageService.download(manifestUrl);
68+
const manifest =
69+
await this.storageService.downloadJsonLikeData(manifestUrl);
6970

7071
const requestType = getRequestType(manifest);
7172

@@ -160,7 +161,8 @@ export class ReputationService {
160161
const escrowClient = await EscrowClient.build(signer);
161162

162163
const finalResultsUrl = await escrowClient.getResultsUrl(escrowAddress);
163-
const finalResults = await this.storageService.download(finalResultsUrl);
164+
const finalResults =
165+
await this.storageService.downloadJsonLikeData(finalResultsUrl);
164166

165167
if (finalResults.length === 0) {
166168
throw new ControlledError(
@@ -202,9 +204,10 @@ export class ReputationService {
202204
const intermediateResultsUrl =
203205
await escrowClient.getIntermediateResultsUrl(escrowAddress);
204206

205-
const annotations: CvatAnnotationMeta = await this.storageService.download(
206-
`${intermediateResultsUrl}/${CVAT_VALIDATION_META_FILENAME}`,
207-
);
207+
const annotations: CvatAnnotationMeta =
208+
await this.storageService.downloadJsonLikeData(
209+
`${intermediateResultsUrl}/${CVAT_VALIDATION_META_FILENAME}`,
210+
);
208211

209212
// If annotation meta does not exist
210213
if (annotations && Array.isArray(annotations) && annotations.length === 0) {
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { BaseError } from '../../common/errors/base';
2+
3+
export class FileDownloadError extends BaseError {
4+
public readonly location: string;
5+
6+
constructor(location: string, cause?: unknown) {
7+
super('Failed to download file', cause);
8+
9+
this.location = location;
10+
}
11+
}
12+
13+
export class InvalidFileUrl extends FileDownloadError {
14+
constructor(url: string) {
15+
super(url);
16+
this.message = 'Invalid file URL';
17+
}
18+
}
19+
20+
export class FileNotFoundError extends FileDownloadError {
21+
constructor(location: string) {
22+
super(location);
23+
this.message = 'File not found';
24+
}
25+
}

0 commit comments

Comments
 (0)