diff --git a/src/controllers/client/client.controller.spec.ts b/src/controllers/client/client.controller.spec.ts index 27b3c62..9ffcce4 100644 --- a/src/controllers/client/client.controller.spec.ts +++ b/src/controllers/client/client.controller.spec.ts @@ -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 () => { addressSettingsService.getSettings.mockResolvedValue(null); shareAccountingService.getAddressSummary.mockResolvedValue({ diff --git a/src/controllers/client/client.controller.ts b/src/controllers/client/client.controller.ts index dfeceda..695efa4 100644 --- a/src/controllers/client/client.controller.ts +++ b/src/controllers/client/client.controller.ts @@ -28,9 +28,7 @@ export class ClientController { const workers = await this.getActiveAddressWorkers(address, mode); const sessionSummaries = await this.shareAccountingService.getSessionSummaries(workers.map(worker => worker.clientId)); - const addressSettings = process.env.API_ONLY === 'true' - ? null - : await this.addressSettingsService.getSettings(address, false); + const addressSettings = await this.addressSettingsService.getSettings(address, false); const bestDifficulty = addressSettings?.bestDifficulty ?? workers.reduce((best, worker) => { return Math.max(best, Number(worker.bestDifficulty ?? 0)); }, 0);