mirror of
https://github.com/benjamin-wilson/public-pool.git
synced 2026-09-29 09:05:06 -07:00
Read best difficulty in API workers
This commit is contained in:
@@ -105,6 +105,34 @@ describe('ClientController', () => {
|
|||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should read address best difficulty in API-only mode', async () => {
|
||||||
|
const originalApiOnly = process.env.API_ONLY;
|
||||||
|
process.env.API_ONLY = 'true';
|
||||||
|
try {
|
||||||
|
addressSettingsService.getSettings.mockResolvedValue({ bestDifficulty: 8192 });
|
||||||
|
shareAccountingService.getSessionSummaries.mockResolvedValue(new Map());
|
||||||
|
shareAccountingService.getAddressSummary.mockResolvedValue({
|
||||||
|
totalAcceptedShares: 10,
|
||||||
|
totalCreditedDifficulty: 100,
|
||||||
|
bestSubmissionDifficulty: 0,
|
||||||
|
});
|
||||||
|
|
||||||
|
await expect(controller.getClientInfo('bc1qtest')).resolves.toEqual(expect.objectContaining({
|
||||||
|
bestDifficulty: 8192,
|
||||||
|
accounting: expect.objectContaining({
|
||||||
|
bestSubmissionDifficulty: 8192,
|
||||||
|
}),
|
||||||
|
}));
|
||||||
|
expect(addressSettingsService.getSettings).toHaveBeenCalledWith('bc1qtest', false);
|
||||||
|
} finally {
|
||||||
|
if (originalApiOnly == null) {
|
||||||
|
delete process.env.API_ONLY;
|
||||||
|
} else {
|
||||||
|
process.env.API_ONLY = originalApiOnly;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
it('should expose the latest current PPLNS expected payout for an address', async () => {
|
it('should expose the latest current PPLNS expected payout for an address', async () => {
|
||||||
addressSettingsService.getSettings.mockResolvedValue(null);
|
addressSettingsService.getSettings.mockResolvedValue(null);
|
||||||
shareAccountingService.getAddressSummary.mockResolvedValue({
|
shareAccountingService.getAddressSummary.mockResolvedValue({
|
||||||
|
|||||||
@@ -28,9 +28,7 @@ export class ClientController {
|
|||||||
const workers = await this.getActiveAddressWorkers(address, mode);
|
const workers = await this.getActiveAddressWorkers(address, mode);
|
||||||
const sessionSummaries = await this.shareAccountingService.getSessionSummaries(workers.map(worker => worker.clientId));
|
const sessionSummaries = await this.shareAccountingService.getSessionSummaries(workers.map(worker => worker.clientId));
|
||||||
|
|
||||||
const addressSettings = process.env.API_ONLY === 'true'
|
const addressSettings = await this.addressSettingsService.getSettings(address, false);
|
||||||
? null
|
|
||||||
: await this.addressSettingsService.getSettings(address, false);
|
|
||||||
const bestDifficulty = addressSettings?.bestDifficulty ?? workers.reduce((best, worker) => {
|
const bestDifficulty = addressSettings?.bestDifficulty ?? workers.reduce((best, worker) => {
|
||||||
return Math.max(best, Number(worker.bestDifficulty ?? 0));
|
return Math.max(best, Number(worker.bestDifficulty ?? 0));
|
||||||
}, 0);
|
}, 0);
|
||||||
|
|||||||
Reference in New Issue
Block a user