Skip to content

Commit 19fc7a8

Browse files
authored
Merge pull request #693 from humanprotocol/develop
Release Q3 - sprint 2
2 parents 76f42da + 4fab3c2 commit 19fc7a8

File tree

90 files changed

+1910
-602
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+1910
-602
lines changed

packages/apps/fortune/exchange-oracle/server/src/common/config/env.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export const ConfigNames = {
44
HOST: 'HOST',
55
PORT: 'PORT',
66
WEB3_PRIVATE_KEY: 'WEB3_PRIVATE_KEY',
7+
REPUTATION_ORACLE_URL: 'REPUTATION_ORACLE_URL',
78
};
89

910
export const envValidator = Joi.object({

packages/apps/fortune/exchange-oracle/server/src/modules/job/job.controller.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { ConfigService } from '@nestjs/config';
12
import { Test } from '@nestjs/testing';
23
import { JobController } from './job.controller';
34
import { JobService } from './job.service';
@@ -14,11 +15,20 @@ describe('JobController', () => {
1415
const escrowAddress = '0x1234567890123456789012345678901234567890';
1516
const workerAddress = '0x1234567890123456789012345678901234567891';
1617

18+
const reputationOracleURL = 'https://example.com/reputationoracle';
19+
const configServiceMock = {
20+
get: jest.fn().mockReturnValue(reputationOracleURL),
21+
};
22+
1723
beforeAll(async () => {
1824
const moduleRef = await Test.createTestingModule({
1925
controllers: [JobController],
2026
providers: [
2127
JobService,
28+
{
29+
provide: ConfigService,
30+
useValue: configServiceMock,
31+
},
2232
{
2333
provide: Web3Service,
2434
useValue: {

packages/apps/fortune/exchange-oracle/server/src/modules/job/job.module.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { Module } from '@nestjs/common';
2+
import { ConfigModule } from '@nestjs/config';
23
import { JobController } from './job.controller';
34
import { JobService } from './job.service';
45
import { HttpModule } from '@nestjs/axios';
56
import { Web3Module } from '../web3/web3.module';
67

78
@Module({
8-
imports: [HttpModule, Web3Module],
9+
imports: [ConfigModule, HttpModule, Web3Module],
910
controllers: [JobController],
1011
providers: [JobService],
1112
})

packages/apps/fortune/exchange-oracle/server/src/modules/job/job.service.spec.ts

Lines changed: 25 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
import { HttpService } from '@nestjs/axios';
2+
import { ConfigService } from '@nestjs/config';
23
import { Test } from '@nestjs/testing';
34
import { of } from 'rxjs';
45
import { Web3Service } from '../web3/web3.service';
56
import { JobService } from './job.service';
6-
import {
7-
EscrowClient,
8-
KVStoreClient,
9-
StorageClient,
10-
} from '@human-protocol/sdk';
7+
import { EscrowClient, KVStoreClient } from '@human-protocol/sdk';
118

129
jest.mock('@human-protocol/sdk', () => ({
1310
...jest.requireActual('@human-protocol/sdk'),
@@ -27,8 +24,10 @@ jest.mock('axios', () => ({
2724
}));
2825

2926
describe('JobService', () => {
27+
let configService: ConfigService;
3028
let jobService: JobService;
3129
let web3Service: Web3Service;
30+
let httpService: HttpService;
3231

3332
const chainId = 1;
3433
const escrowAddress = '0x1234567890123456789012345678901234567890';
@@ -39,6 +38,11 @@ describe('JobService', () => {
3938
getNetwork: jest.fn().mockResolvedValue({ chainId: 1 }),
4039
};
4140

41+
const reputationOracleURL = 'https://example.com/reputationoracle';
42+
const configServiceMock = {
43+
get: jest.fn().mockReturnValue(reputationOracleURL),
44+
};
45+
4246
const httpServicePostMock = jest
4347
.fn()
4448
.mockReturnValue(of({ status: 200, data: {} }));
@@ -47,6 +51,10 @@ describe('JobService', () => {
4751
const moduleRef = await Test.createTestingModule({
4852
providers: [
4953
JobService,
54+
{
55+
provide: ConfigService,
56+
useValue: configServiceMock,
57+
},
5058
{
5159
provide: Web3Service,
5260
useValue: {
@@ -57,13 +65,18 @@ describe('JobService', () => {
5765
provide: HttpService,
5866
useValue: {
5967
post: httpServicePostMock,
68+
axiosRef: {
69+
get: jest.fn(),
70+
},
6071
},
6172
},
6273
],
6374
}).compile();
6475

76+
configService = moduleRef.get<ConfigService>(ConfigService);
6577
jobService = moduleRef.get<JobService>(JobService);
6678
web3Service = moduleRef.get<Web3Service>(Web3Service);
79+
httpService = moduleRef.get<HttpService>(HttpService);
6780
});
6881

6982
describe('getDetails', () => {
@@ -74,14 +87,10 @@ describe('JobService', () => {
7487
fortunesRequested: 5,
7588
fundAmount: 100,
7689
};
77-
(EscrowClient.build as any).mockImplementation(() => ({
78-
getManifestUrl: jest
79-
.fn()
80-
.mockResolvedValue('https://example.com/manifest.json'),
81-
}));
82-
(StorageClient.downloadFileFromUrl as any).mockResolvedValue({
83-
...manifest,
84-
fortunesRequired: manifest.fortunesRequested,
90+
91+
httpService.axiosRef.get = jest.fn().mockResolvedValue({
92+
status: 200,
93+
data: { ...manifest, fortunesRequired: manifest.fortunesRequested },
8594
});
8695

8796
const result = await jobService.getDetails(chainId, escrowAddress);
@@ -91,37 +100,14 @@ describe('JobService', () => {
91100
chainId,
92101
manifest,
93102
});
94-
expect(web3Service.getSigner).toHaveBeenCalledWith(chainId);
95103
});
96104

97-
it('should fail if the escrow address is invalid', async () => {
98-
const escrowAddress = 'invalid_address';
99-
(EscrowClient.build as any).mockImplementation(() => ({
100-
getManifestUrl: jest
101-
.fn()
102-
.mockRejectedValue(new Error('Invalid address')),
103-
}));
105+
it('should fail if reputation oracle url is empty', async () => {
106+
configService.get = jest.fn().mockReturnValue('');
104107

105108
await expect(
106109
jobService.getDetails(chainId, escrowAddress),
107-
).rejects.toThrow('Invalid address');
108-
expect(web3Service.getSigner).toHaveBeenCalledWith(chainId);
109-
});
110-
111-
it('should fail if the file does not exist', async () => {
112-
(EscrowClient.build as any).mockImplementation(() => ({
113-
getManifestUrl: jest
114-
.fn()
115-
.mockResolvedValue('https://example.com/manifest.json'),
116-
}));
117-
(StorageClient.downloadFileFromUrl as any).mockRejectedValue(
118-
new Error('File not found'),
119-
);
120-
121-
await expect(
122-
jobService.getDetails(chainId, escrowAddress),
123-
).rejects.toThrow('File not found');
124-
expect(web3Service.getSigner).toHaveBeenCalledWith(chainId);
110+
).rejects.toThrow('Unable to get Reputation Oracle URL');
125111
});
126112
});
127113

packages/apps/fortune/exchange-oracle/server/src/modules/job/job.service.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ import {
33
EscrowStatus,
44
KVStoreClient,
55
KVStoreKeys,
6-
StorageClient,
76
} from '@human-protocol/sdk';
87
import { HttpService } from '@nestjs/axios';
98
import { Inject, Injectable, Logger } from '@nestjs/common';
9+
import { ConfigService } from '@nestjs/config';
10+
import { ConfigNames } from '../../common/config';
1011
import { Web3Service } from '../web3/web3.service';
1112
import { JobDetailsDto } from './job.dto';
1213

@@ -18,6 +19,7 @@ export class JobService {
1819
} = {};
1920

2021
constructor(
22+
private readonly configService: ConfigService,
2123
@Inject(Web3Service)
2224
private readonly web3Service: Web3Service,
2325
private readonly httpService: HttpService,
@@ -27,10 +29,19 @@ export class JobService {
2729
chainId: number,
2830
escrowAddress: string,
2931
): Promise<JobDetailsDto> {
30-
const signer = this.web3Service.getSigner(chainId);
31-
const escrowClient = await EscrowClient.build(signer);
32-
const manifestUrl = await escrowClient.getManifestUrl(escrowAddress);
33-
const manifest = await StorageClient.downloadFileFromUrl(manifestUrl);
32+
const reputationOracleURL = this.configService.get(
33+
ConfigNames.REPUTATION_ORACLE_URL,
34+
);
35+
36+
if (!reputationOracleURL)
37+
throw new Error('Unable to get Reputation Oracle URL');
38+
39+
const manifest = await this.httpService.axiosRef
40+
.get<any>(
41+
reputationOracleURL +
42+
`/manifest?chainId=${chainId}&escrowAddress=${escrowAddress}`,
43+
)
44+
.then((res) => res.data);
3445

3546
return {
3647
escrowAddress,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import { envValidator } from './common/config';
4343
UserModule,
4444
JobModule,
4545
PaymentModule,
46-
Web3Module
46+
Web3Module,
4747
],
4848
controllers: [AppController],
4949
})

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,11 @@ export const envValidator = Joi.object({
7575
S3_BACKET: Joi.string().default('launcher'),
7676
S3_USE_SSL: Joi.string().default(false),
7777
// Stripe
78-
STRIPE_SECRET_KEY: Joi.string().default('sk_test_51MO1RkABE7VUdqB3hviLNxMYafYQYhvtWd3Jaj9ZEH3SvkxM4frJLz00FmC5J8xYbNGhmzwobaLkN0GKUbuhQDvx00NeZwI93C'),
78+
STRIPE_SECRET_KEY: Joi.string().default(
79+
'sk_test_51MO1RkABE7VUdqB3hviLNxMYafYQYhvtWd3Jaj9ZEH3SvkxM4frJLz00FmC5J8xYbNGhmzwobaLkN0GKUbuhQDvx00NeZwI93C',
80+
),
7981
STRIPE_API_VERSION: Joi.string().default('2022-11-15'),
8082
STRIPE_APP_NAME: Joi.string().default('Fortune'),
8183
STRIPE_APP_VERSION: Joi.string().default('0.0.1'),
8284
STRIPE_APP_INFO_URL: Joi.string().default('https://hmt.ai'),
83-
});
85+
});
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
export * from './env';
2-
export * from './networks';
2+
export * from './networks';
Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,39 @@
11
export interface NetworkDto {
2-
chainId: number;
3-
rpcUrl: string;
4-
}
5-
6-
interface NetworkMapDto {
7-
[key: string]: NetworkDto;
8-
}
9-
10-
export const networkMap: NetworkMapDto = {
11-
polygon: {
12-
chainId: 137,
13-
rpcUrl:
14-
'https://polygon-mainnet.g.alchemy.com/v2/0Lorh5KRkGl5FsRwy2epTg8fEFFoqUfY',
15-
},
16-
bsc: {
17-
chainId: 56,
18-
rpcUrl: 'https://bsc-dataseed1.binance.org/',
19-
},
20-
mumbai: {
21-
chainId: 80001,
22-
rpcUrl:
23-
'https://polygon-mumbai.g.alchemy.com/v2/vKNSJzJf6SW2sdW-05bgFwoyFxUrMzii',
24-
},
25-
goerli: {
26-
chainId: 5,
27-
rpcUrl: 'https://goerli.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161',
28-
},
29-
moonbeam: {
30-
chainId: 1284,
31-
rpcUrl: 'https://rpc.api.moonbeam.network',
32-
},
33-
bsctest: {
34-
chainId: 97,
35-
rpcUrl: 'https://data-seed-prebsc-1-s1.binance.org:8545/',
36-
},
37-
};
38-
39-
export const networks = Object.values(networkMap).map((network) => network);
2+
chainId: number;
3+
rpcUrl: string;
4+
}
5+
6+
interface NetworkMapDto {
7+
[key: string]: NetworkDto;
8+
}
9+
10+
export const networkMap: NetworkMapDto = {
11+
polygon: {
12+
chainId: 137,
13+
rpcUrl:
14+
'https://polygon-mainnet.g.alchemy.com/v2/0Lorh5KRkGl5FsRwy2epTg8fEFFoqUfY',
15+
},
16+
bsc: {
17+
chainId: 56,
18+
rpcUrl: 'https://bsc-dataseed1.binance.org/',
19+
},
20+
mumbai: {
21+
chainId: 80001,
22+
rpcUrl:
23+
'https://polygon-mumbai.g.alchemy.com/v2/vKNSJzJf6SW2sdW-05bgFwoyFxUrMzii',
24+
},
25+
goerli: {
26+
chainId: 5,
27+
rpcUrl: 'https://goerli.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161',
28+
},
29+
moonbeam: {
30+
chainId: 1284,
31+
rpcUrl: 'https://rpc.api.moonbeam.network',
32+
},
33+
bsctest: {
34+
chainId: 97,
35+
rpcUrl: 'https://data-seed-prebsc-1-s1.binance.org:8545/',
36+
},
37+
};
38+
39+
export const networks = Object.values(networkMap).map((network) => network);

0 commit comments

Comments
 (0)