Skip to content

Commit

Permalink
Remove floating promise from constructor (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpuri authored Nov 14, 2023
1 parent 8fc82a8 commit 80042a7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
12 changes: 8 additions & 4 deletions src/ppom-controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,10 @@ describe('PPOMController', () => {
await flushPromises();
expect(spy).toHaveBeenCalledTimes(6);
});
});

it('should create instance of PPOMController even if there is an error in initialising PPOM', async () => {
describe('usePPOM', () => {
it('should throw error if there is an error in initialising PPOM', async () => {
buildFetchSpy();
ppomController = buildPPOMController({
ppomProvider: {
Expand All @@ -95,11 +97,13 @@ describe('PPOMController', () => {
jest.advanceTimersByTime(REFRESH_TIME_INTERVAL);
await flushPromises();

expect(ppomController).toBeDefined();
await expect(async () => {
await ppomController.usePPOM(async () => {
return Promise.resolve();
});
}).rejects.toThrow('Error initializing PPOM');
});
});

describe('usePPOM', () => {
it('should provide instance of ppom to the passed ballback', async () => {
buildFetchSpy();
ppomController = buildPPOMController();
Expand Down
8 changes: 2 additions & 6 deletions src/ppom-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,11 +306,6 @@ export class PPOMController extends BaseControllerV2<

// start scheduled task to fetch data files
this.#checkScheduleFileDownloadForAllChains();

// Async initialisation of PPOM as soon as controller is constructed and not when transactions are received
// This helps to reduce the delay in validating transactions.
// eslint-disable-next-line @typescript-eslint/no-floating-promises
this.#initialisePPOM();
}

/**
Expand Down Expand Up @@ -383,8 +378,9 @@ export class PPOMController extends BaseControllerV2<
await ppomInit('./ppom_bg.wasm');
this.#ppomInitialised = true;
})
.catch(() => {
.catch((error: unknown) => {
console.error('Error in trying to initialize PPOM');
throw error;
});
}
}
Expand Down

0 comments on commit 80042a7

Please sign in to comment.