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
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
Encryption,
EncryptionUtils,
EscrowClient,
EscrowUtils,
OperatorUtils,
} from '@human-protocol/sdk';
import { HttpService } from '@nestjs/axios';
Expand Down Expand Up @@ -417,6 +418,45 @@ describe('JobService', () => {
);
});

it('should calculate reward amount from net funded amount', async () => {
const manifest: ManifestDto = {
requesterTitle: 'Example Title',
requesterDescription: 'Example Description',
submissionsRequired: 5,
};

jest.spyOn(jobService, 'getManifest').mockResolvedValue(manifest);
jest.spyOn(EscrowUtils, 'getEscrow').mockResolvedValue({
token: MOCK_ADDRESS,
totalFundedAmount: 100000000000000000000n,
recordingOracleFee: 2,
reputationOracleFee: 3,
exchangeOracleFee: 5,
} as any);
jest.spyOn(HMToken__factory, 'connect').mockReturnValue({
decimals: jest.fn().mockResolvedValue(18),
} as any);
jest
.spyOn(jobRepository, 'fetchFiltered')
.mockResolvedValueOnce({ entities: jobs as any, itemCount: 1 });

const result = await jobService.getJobList(
{
chainId,
jobType: JobType.FORTUNE,
fields: [JobFieldName.RewardAmount],
escrowAddress,
status: JobStatus.ACTIVE,
page: 0,
pageSize: 10,
skip: 0,
},
workerAddress,
);

expect(result.results[0].rewardAmount).toBe('18');
});

it('should return an array of jobs without calling the manifest', async () => {
jest.spyOn(jobService, 'getManifest');
jest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -433,9 +433,18 @@ export class JobService {
this.web3Service.getSigner(chainId),
).decimals();

const netFundAmount = [
escrow.recordingOracleFee,
escrow.reputationOracleFee,
escrow.exchangeOracleFee,
].reduce(
(amount, fee) =>
amount - (escrow.totalFundedAmount * BigInt(fee ?? 0)) / 100n,
escrow.totalFundedAmount,
);

return (
Number(ethers.formatUnits(escrow.totalFundedAmount, decimals)) /
submissionsRequired
Number(ethers.formatUnits(netFundAmount, decimals)) / submissionsRequired
);
}
}
Loading