Skip to content

Commit

Permalink
[Job Launcher] Job bounties (#851)
Browse files Browse the repository at this point in the history
* Fix job bouties calculations

* Fix reputation oracle tests
  • Loading branch information
flopez7 authored Aug 30, 2023
1 parent af1e50d commit d90724c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ export class JobService {
};

this.storageClient = new StorageClient(
storageCredentials,
this.storageParams,
storageCredentials,
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,13 +313,13 @@ describe('JobService', () => {

describe('calculateJobBounty', () => {
it('should calculate the job bounty correctly', async () => {
const fundAmount = 10;
const fundAmount = 0.013997056833333334;
const result = await jobService['calculateJobBounty'](
MOCK_FILE_URL,
fundAmount,
);

expect(result).toEqual(2);
expect(result).toEqual('0.002332842805555555');
});
});

Expand Down
14 changes: 8 additions & 6 deletions packages/apps/job-launcher/server/src/modules/job/job.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,7 @@ export class JobService {
),
gt_url: dto.gtUrl,
},
job_bounty: (
await this.calculateJobBounty(dto.dataUrl, fundAmount)
).toString(),
job_bounty: await this.calculateJobBounty(dto.dataUrl, fundAmount),
}));
}

Expand Down Expand Up @@ -222,7 +220,7 @@ export class JobService {
private async calculateJobBounty(
endpointUrl: string,
fundAmount: number,
): Promise<number> {
): Promise<string> {
const storageData = parseUrl(endpointUrl);
const storageClient = new StorageClient({
endPoint: storageData.endpoint,
Expand All @@ -234,11 +232,15 @@ export class JobService {
.length;

const totalJobs = Math.ceil(
totalImages /
div(
totalImages,
Number(this.configService.get<number>(ConfigNames.CVAT_JOB_SIZE)!),
),
);

return fundAmount / totalJobs;
return ethers.utils.formatEther(
ethers.utils.parseUnits(fundAmount.toString(), 'ether').div(totalJobs),
);
}

public async launchJob(jobEntity: JobEntity): Promise<JobEntity> {
Expand Down
9 changes: 8 additions & 1 deletion packages/apps/job-launcher/server/test/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ export const MOCK_ADDRESS = '0xCf88b3f1992458C2f5a229573c768D0E9F70C44e';
export const MOCK_FILE_URL = 'http://mockedFileUrl.test';
export const MOCK_FILE_HASH = 'mockedFileHash';
export const MOCK_FILE_KEY = 'manifest.json';
export const MOCK_BUCKET_FILES = ['file0', 'file1', 'file2', 'file3', 'file4'];
export const MOCK_BUCKET_FILES = [
'file0',
'file1',
'file2',
'file3',
'file4',
'file5',
];
export const MOCK_PRIVATE_KEY =
'd334daf65a631f40549cc7de126d5a0016f32a2d00c49f94563f9737f7135e55';
export const MOCK_BUCKET_NAME = 'bucket-name';
Expand Down

1 comment on commit d90724c

@vercel
Copy link

@vercel vercel bot commented on d90724c Aug 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

job-launcher-server – ./packages/apps/job-launcher/server

job-launcher-server-git-develop-humanprotocol.vercel.app
job-launcher-server-humanprotocol.vercel.app
job-launcher-server-nine.vercel.app

Please sign in to comment.