Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/apps/job-launcher/server/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"allowJs": true,
"target": "ES2020",
"target": "ES2022",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./",
Expand Down
7 changes: 2 additions & 5 deletions packages/apps/reputation-oracle/server/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,9 @@ services:
ports:
- 9001:9001
- 9000:9000
environment:
MINIO_ROOT_USER: ${S3_ACCESS_KEY}
MINIO_ROOT_PASSWORD: ${S3_SECRET_KEY}
entrypoint: 'sh'
command:
-c "mkdir -p /data/reputation && minio server /data --console-address ':9001'"
-c "minio server /data --console-address ':9001'"
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
interval: 5s
Expand All @@ -45,7 +42,7 @@ services:
condition: service_healthy
entrypoint: >
/bin/sh -c "
/usr/bin/mc config host add myminio http://minio:9000 ${S3_ACCESS_KEY} ${S3_SECRET_KEY};
/usr/bin/mc config host add myminio http://minio:9000 minioadmin minioadmin;
/usr/bin/mc mb myminio/reputation;
/usr/bin/mc anonymous set public myminio/reputation;
"
Expand Down
11 changes: 11 additions & 0 deletions packages/apps/reputation-oracle/server/src/common/errors/base.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export class BaseError extends Error {
constructor(message: string, cause?: unknown) {
const errorOptions: ErrorOptions = {};
if (cause) {
errorOptions.cause = cause;
}

super(message, errorOptions);
this.name = this.constructor.name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ describe('PayoutService', () => {
job_bounty: '10',
};

jest.spyOn(storageService, 'download').mockResolvedValue(manifest);
jest
.spyOn(storageService, 'downloadJsonLikeData')
.mockResolvedValue(manifest);

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

jest.spyOn(storageService, 'download').mockResolvedValue(manifest);
jest
.spyOn(storageService, 'downloadJsonLikeData')
.mockResolvedValue(manifest);

const results: SaveResultDto = {
url: MOCK_FILE_URL,
Expand Down Expand Up @@ -236,7 +240,9 @@ describe('PayoutService', () => {
job_bounty: '10',
};

jest.spyOn(storageService, 'download').mockResolvedValue(manifest);
jest
.spyOn(storageService, 'downloadJsonLikeData')
.mockResolvedValue(manifest);

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

jest.spyOn(storageService, 'download').mockResolvedValue(manifest);
jest
.spyOn(storageService, 'downloadJsonLikeData')
.mockResolvedValue(manifest);

const results: PayoutsDataDto = {
recipients: [MOCK_ADDRESS],
Expand Down Expand Up @@ -332,7 +340,7 @@ describe('PayoutService', () => {
];

jest
.spyOn(storageService, 'download')
.spyOn(storageService, 'downloadJsonLikeData')
.mockResolvedValue(intermediateResults);

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

jest.spyOn(storageService, 'download').mockResolvedValue([] as any);
jest
.spyOn(storageService, 'downloadJsonLikeData')
.mockResolvedValue([] as any);

await expect(
payoutService.saveResultsFortune(manifest, chainId, escrowAddress),
Expand Down Expand Up @@ -393,7 +403,7 @@ describe('PayoutService', () => {
];

jest
.spyOn(storageService, 'download')
.spyOn(storageService, 'downloadJsonLikeData')
.mockResolvedValue(intermediateResults);

await expect(
Expand Down Expand Up @@ -425,7 +435,7 @@ describe('PayoutService', () => {
];

jest
.spyOn(storageService, 'download')
.spyOn(storageService, 'downloadJsonLikeData')
.mockResolvedValue(intermediateResults);

const result = await payoutService.calculatePayoutsFortune(
Expand Down Expand Up @@ -475,7 +485,9 @@ describe('PayoutService', () => {
url: MOCK_FILE_URL,
hash: MOCK_FILE_HASH,
});
jest.spyOn(storageService, 'download').mockResolvedValue(results);
jest
.spyOn(storageService, 'downloadJsonLikeData')
.mockResolvedValue(results);

const result = await payoutService.saveResultsCvat(
chainId,
Expand Down Expand Up @@ -539,7 +551,9 @@ describe('PayoutService', () => {
],
};

jest.spyOn(storageService, 'download').mockResolvedValue(results);
jest
.spyOn(storageService, 'downloadJsonLikeData')
.mockResolvedValue(results);

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

jest.spyOn(storageService, 'download').mockResolvedValue(results);
jest
.spyOn(storageService, 'downloadJsonLikeData')
.mockResolvedValue(results);

await expect(
payoutService.calculatePayoutsCvat(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ export class PayoutService {
);
}

const manifest = await this.storageService.download(manifestUrl);
const manifest =
await this.storageService.downloadJsonLikeData(manifestUrl);

const requestType = getRequestType(manifest);

Expand Down Expand Up @@ -102,7 +103,8 @@ export class PayoutService {
);
}

const manifest = await this.storageService.download(manifestUrl);
const manifest =
await this.storageService.downloadJsonLikeData(manifestUrl);

const requestType = getRequestType(manifest);

Expand Down Expand Up @@ -209,7 +211,7 @@ export class PayoutService {
const intermediateResultsUrl =
await escrowClient.getIntermediateResultsUrl(escrowAddress);

const intermediateResults = (await this.storageService.download(
const intermediateResults = (await this.storageService.downloadJsonLikeData(
intermediateResultsUrl,
)) as FortuneFinalResult[];

Expand Down Expand Up @@ -279,7 +281,7 @@ export class PayoutService {
manifest: FortuneManifestDto,
finalResultsUrl: string,
): Promise<PayoutsDataDto> {
const finalResults = (await this.storageService.download(
const finalResults = (await this.storageService.downloadJsonLikeData(
finalResultsUrl,
)) as FortuneFinalResult[];

Expand Down Expand Up @@ -315,9 +317,10 @@ export class PayoutService {
const intermediateResultsUrl =
await escrowClient.getIntermediateResultsUrl(escrowAddress);

const annotations: CvatAnnotationMeta = await this.storageService.download(
`${intermediateResultsUrl}/${CVAT_VALIDATION_META_FILENAME}`,
);
const annotations: CvatAnnotationMeta =
await this.storageService.downloadJsonLikeData(
`${intermediateResultsUrl}/${CVAT_VALIDATION_META_FILENAME}`,
);

// If annotation meta results does not exist
if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ describe('ReputationService', () => {
};

jest
.spyOn(storageService, 'download')
.spyOn(storageService, 'downloadJsonLikeData')
.mockResolvedValueOnce(manifest) // Mock manifest
.mockResolvedValueOnce([]); // Mock final results

Expand Down Expand Up @@ -165,7 +165,7 @@ describe('ReputationService', () => {
];

jest
.spyOn(storageService, 'download')
.spyOn(storageService, 'downloadJsonLikeData')
.mockResolvedValueOnce(manifest)
.mockResolvedValueOnce(finalResults);

Expand Down Expand Up @@ -238,7 +238,7 @@ describe('ReputationService', () => {
}));

jest
.spyOn(storageService, 'download')
.spyOn(storageService, 'downloadJsonLikeData')
.mockResolvedValueOnce(manifest) // Mock manifest
.mockResolvedValueOnce([]); // Mock final results

Expand Down Expand Up @@ -289,7 +289,7 @@ describe('ReputationService', () => {
};

jest
.spyOn(storageService, 'download')
.spyOn(storageService, 'downloadJsonLikeData')
.mockResolvedValueOnce(manifest)
.mockResolvedValueOnce(annotationMeta);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ export class ReputationService {
);
}

const manifest = await this.storageService.download(manifestUrl);
const manifest =
await this.storageService.downloadJsonLikeData(manifestUrl);

const requestType = getRequestType(manifest);

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

const finalResultsUrl = await escrowClient.getResultsUrl(escrowAddress);
const finalResults = await this.storageService.download(finalResultsUrl);
const finalResults =
await this.storageService.downloadJsonLikeData(finalResultsUrl);

if (finalResults.length === 0) {
throw new ControlledError(
Expand Down Expand Up @@ -202,9 +204,10 @@ export class ReputationService {
const intermediateResultsUrl =
await escrowClient.getIntermediateResultsUrl(escrowAddress);

const annotations: CvatAnnotationMeta = await this.storageService.download(
`${intermediateResultsUrl}/${CVAT_VALIDATION_META_FILENAME}`,
);
const annotations: CvatAnnotationMeta =
await this.storageService.downloadJsonLikeData(
`${intermediateResultsUrl}/${CVAT_VALIDATION_META_FILENAME}`,
);

// If annotation meta does not exist
if (annotations && Array.isArray(annotations) && annotations.length === 0) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { BaseError } from '../../common/errors/base';

export class FileDownloadError extends BaseError {
public readonly location: string;

constructor(location: string, cause?: unknown) {
super('Failed to download file', cause);

this.location = location;
}
}

export class InvalidFileUrl extends FileDownloadError {
constructor(url: string) {
super(url);
this.message = 'Invalid file URL';
}
}

export class FileNotFoundError extends FileDownloadError {
constructor(location: string) {
super(location);
this.message = 'File not found';
}
}
Loading