Skip to content

Commit f7ab5da

Browse files
author
flopez7
committed
Remove RoutingProtocol module and service, update JobService to use Web3Service for oracle selection
1 parent 5d7a1db commit f7ab5da

19 files changed

+186
-915
lines changed

packages/apps/job-launcher/server/src/common/config/env-schema.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ export const envValidator = Joi.object({
3030
GAS_PRICE_MULTIPLIER: Joi.number(),
3131
APPROVE_AMOUNT_USD: Joi.number(),
3232
REPUTATION_ORACLE_ADDRESS: Joi.string().required(),
33-
REPUTATION_ORACLES: Joi.string().required(),
3433
CVAT_EXCHANGE_ORACLE_ADDRESS: Joi.string().required(),
3534
CVAT_RECORDING_ORACLE_ADDRESS: Joi.string().required(),
3635
HCAPTCHA_ORACLE_ADDRESS: Joi.string().required(),
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { Injectable } from '@nestjs/common';
2+
import { ConfigService } from '@nestjs/config';
3+
4+
@Injectable()
5+
export class SlackConfigService {
6+
constructor(private configService: ConfigService) {}
7+
8+
/**
9+
* The abuse notification webhook URL for sending messages to a Slack channel.
10+
* Required
11+
*/
12+
get abuseNotificationWebhookUrl(): string {
13+
return this.configService.getOrThrow<string>(
14+
'SLACK_ABUSE_NOTIFICATION_WEBHOOK_URL',
15+
);
16+
}
17+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { Injectable } from '@nestjs/common';
2+
import { ConfigService } from '@nestjs/config';
3+
4+
@Injectable()
5+
export class VisionConfigService {
6+
constructor(private configService: ConfigService) {}
7+
8+
/**
9+
* The Google Cloud Storage (GCS) path name where temporary async moderation results will be saved.
10+
* Required
11+
*/
12+
get moderationResultsFilesPath(): string {
13+
return this.configService.getOrThrow<string>(
14+
'GCV_MODERATION_RESULTS_FILES_PATH',
15+
);
16+
}
17+
18+
/**
19+
* The Google Cloud Storage (GCS) bucket name where moderation results will be saved.
20+
* Required
21+
*/
22+
get moderationResultsBucket(): string {
23+
return this.configService.getOrThrow<string>(
24+
'GCV_MODERATION_RESULTS_BUCKET',
25+
);
26+
}
27+
28+
/**
29+
* The project ID for connecting to the Google Cloud Vision API.
30+
* Required
31+
*/
32+
get projectId(): string {
33+
return this.configService.getOrThrow<string>('GOOGLE_PROJECT_ID');
34+
}
35+
36+
/**
37+
* The private key for authenticating with the Google Cloud Vision API.
38+
* Required
39+
*/
40+
get privateKey(): string {
41+
return this.configService.getOrThrow<string>('GOOGLE_PRIVATE_KEY');
42+
}
43+
44+
/**
45+
* The client email used for authenticating requests to the Google Cloud Vision API.
46+
* Required
47+
*/
48+
get clientEmail(): string {
49+
return this.configService.getOrThrow<string>('GOOGLE_CLIENT_EMAIL');
50+
}
51+
}

packages/apps/job-launcher/server/src/common/config/web3-config.service.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,6 @@ export class Web3ConfigService {
3737
return this.configService.getOrThrow<string>('REPUTATION_ORACLE_ADDRESS');
3838
}
3939

40-
/**
41-
* List of reputation oracle addresses, typically comma-separated.
42-
* Required
43-
*/
44-
get reputationOracles(): string {
45-
return this.configService.getOrThrow<string>('REPUTATION_ORACLES');
46-
}
47-
4840
/**
4941
* URI for the hCaptcha recording oracle service.
5042
* Required

packages/apps/job-launcher/server/src/common/constants/errors.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -166,15 +166,6 @@ export enum ErrorWeb3 {
166166
ReputationOracleUrlNotSet = 'Reputation oracle URL not set',
167167
}
168168

169-
/**
170-
* Represents error messages related to routing protocol.
171-
*/
172-
export enum ErrorRoutingProtocol {
173-
ReputationOracleNotFound = 'The specified Reputation Oracle address is not found in the set of available oracles. Ensure the address is correct and check available oracles for this network.',
174-
ExchangeOracleNotFound = 'The specified Exchange Oracle address is not found in the set of available oracles. Ensure the address is correct and part of the available oracle pool.',
175-
RecordingOracleNotFound = 'The specified Recording Oracle address is not found in the set of available oracles. Ensure the address is correct and part of the available oracle pool.',
176-
}
177-
178169
/**
179170
* Represents error messages related to send grid.
180171
*/

packages/apps/job-launcher/server/src/modules/cron-job/cron-job.service.spec.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ import { PaymentRepository } from '../payment/payment.repository';
4747
import { PaymentService } from '../payment/payment.service';
4848
import { QualificationService } from '../qualification/qualification.service';
4949
import { RateService } from '../rate/rate.service';
50-
import { RoutingProtocolService } from '../routing-protocol/routing-protocol.service';
5150
import { StorageService } from '../storage/storage.service';
5251
import { Web3Service } from '../web3/web3.service';
5352
import { WebhookEntity } from '../webhook/webhook.entity';
@@ -124,10 +123,6 @@ describe('CronJobService', () => {
124123
{ provide: PaymentService, useValue: createMock<PaymentService>() },
125124
{ provide: WhitelistService, useValue: createMock<WhitelistService>() },
126125
{ provide: ConfigService, useValue: mockConfigService },
127-
{
128-
provide: RoutingProtocolService,
129-
useValue: createMock<RoutingProtocolService>(),
130-
},
131126
{
132127
provide: WebhookRepository,
133128
useValue: createMock<WebhookRepository>(),

packages/apps/job-launcher/server/src/modules/job/job.controller.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { ChainId } from '@human-protocol/sdk';
12
import { Test, TestingModule } from '@nestjs/testing';
23
import { JobController } from './job.controller';
34
import { JobService } from './job.service';
@@ -84,6 +85,7 @@ describe('JobController', () => {
8485
describe('quickLaunch', () => {
8586
it('should create a job and return job ID', async () => {
8687
const jobDto: JobQuickLaunchDto = {
88+
chainId: ChainId.POLYGON_AMOY,
8789
requestType: 'type_a' as JobRequestType,
8890
manifestUrl: MOCK_FILE_URL,
8991
manifestHash: MOCK_FILE_HASH,
@@ -119,6 +121,7 @@ describe('JobController', () => {
119121

120122
it('should throw a conflict error if mutex manager fails', async () => {
121123
const jobDto: JobQuickLaunchDto = {
124+
chainId: ChainId.POLYGON_AMOY,
122125
requestType: 'type_a' as JobRequestType,
123126
manifestUrl: MOCK_FILE_URL,
124127
manifestHash: MOCK_FILE_HASH,
@@ -159,6 +162,7 @@ describe('JobController', () => {
159162

160163
it('should return unauthorized error if user is not authenticated', async () => {
161164
const jobDto: JobQuickLaunchDto = {
165+
chainId: ChainId.POLYGON_AMOY,
162166
requestType: 'type_a' as JobRequestType,
163167
manifestUrl: MOCK_FILE_URL,
164168
manifestHash: MOCK_FILE_HASH,
@@ -185,6 +189,7 @@ describe('JobController', () => {
185189

186190
describe('createFortuneJob', () => {
187191
const jobFortuneDto: JobFortuneDto = {
192+
chainId: ChainId.POLYGON_AMOY,
188193
requesterTitle: MOCK_REQUESTER_TITLE,
189194
requesterDescription: MOCK_REQUESTER_DESCRIPTION,
190195
submissionsRequired: 10,
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { ChainId } from '@human-protocol/sdk';
2+
import { validate } from 'class-validator';
3+
import { EscrowFundToken, FortuneJobType } from '../../common/enums/job';
4+
import { PaymentCurrency } from '../../common/enums/payment';
5+
import { JobFortuneDto, JobQuickLaunchDto } from './job.dto';
6+
7+
describe('JobDto validation', () => {
8+
it('should require chainId for quick launch job creation', async () => {
9+
const dto = new JobQuickLaunchDto();
10+
dto.requestType = FortuneJobType.FORTUNE;
11+
dto.manifestUrl = 'https://example.com/manifest.json';
12+
dto.manifestHash = 'manifest.json';
13+
dto.paymentCurrency = PaymentCurrency.USD;
14+
dto.paymentAmount = 10;
15+
dto.escrowFundToken = EscrowFundToken.USDC;
16+
17+
const errors = await validate(dto);
18+
19+
expect(errors.some((error) => error.property === 'chainId')).toBe(true);
20+
});
21+
22+
it('should accept chainId for fortune job creation', async () => {
23+
const dto = new JobFortuneDto();
24+
dto.chainId = ChainId.POLYGON_AMOY;
25+
dto.requesterTitle = 'Title';
26+
dto.requesterDescription = 'Description';
27+
dto.submissionsRequired = 5;
28+
dto.paymentCurrency = PaymentCurrency.USD;
29+
dto.paymentAmount = 10;
30+
dto.escrowFundToken = EscrowFundToken.USDC;
31+
32+
const errors = await validate(dto);
33+
34+
expect(errors.some((error) => error.property === 'chainId')).toBe(false);
35+
});
36+
});

packages/apps/job-launcher/server/src/modules/job/job.dto.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,9 @@ import { IsValidToken } from '../../common/validators/tokens';
3232
import { ManifestDetails } from '../manifest/manifest.dto';
3333

3434
export class JobDto {
35-
@ApiProperty({ enum: ChainId, required: false, name: 'chain_id' })
35+
@ApiProperty({ enum: ChainId, name: 'chain_id' })
3636
@IsEnumCaseInsensitive(ChainId)
37-
@IsOptional()
38-
public chainId?: ChainId;
37+
public chainId: ChainId;
3938

4039
@ApiPropertyOptional()
4140
@IsArray()

packages/apps/job-launcher/server/src/modules/job/job.module.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import { WebhookRepository } from '../webhook/webhook.repository';
1515
import { MutexManagerService } from '../mutex/mutex-manager.service';
1616
import { QualificationModule } from '../qualification/qualification.module';
1717
import { WhitelistModule } from '../whitelist/whitelist.module';
18-
import { RoutingProtocolModule } from '../routing-protocol/routing-protocol.module';
1918
import { RateModule } from '../rate/rate.module';
2019
import { ManifestModule } from '../manifest/manifest.module';
2120

@@ -29,7 +28,6 @@ import { ManifestModule } from '../manifest/manifest.module';
2928
StorageModule,
3029
QualificationModule,
3130
WhitelistModule,
32-
RoutingProtocolModule,
3331
RateModule,
3432
ManifestModule,
3533
],

0 commit comments

Comments
 (0)