diff --git a/packages/api/src/token/token.service.spec.ts b/packages/api/src/token/token.service.spec.ts index d756d85f8d..e7c63f55b5 100644 --- a/packages/api/src/token/token.service.spec.ts +++ b/packages/api/src/token/token.service.spec.ts @@ -139,11 +139,12 @@ describe("TokenService", () => { expect(repositoryMock.createQueryBuilder).toHaveBeenCalledWith("token"); }); - it("returns tokens ordered by blockNumber and logIndex DESC", async () => { + it("returns tokens ordered by liquidity, blockNumber and logIndex DESC", async () => { await service.findAll(pagingOptions); expect(queryBuilderMock.orderBy).toBeCalledTimes(1); - expect(queryBuilderMock.orderBy).toHaveBeenCalledWith("token.blockNumber", "DESC"); - expect(queryBuilderMock.addOrderBy).toBeCalledTimes(1); + expect(queryBuilderMock.orderBy).toHaveBeenCalledWith("token.liquidity", "DESC"); + expect(queryBuilderMock.addOrderBy).toBeCalledTimes(2); + expect(queryBuilderMock.addOrderBy).toHaveBeenCalledWith("token.blockNumber", "DESC"); expect(queryBuilderMock.addOrderBy).toHaveBeenCalledWith("token.logIndex", "DESC"); }); diff --git a/packages/worker/src/app.service.spec.ts b/packages/worker/src/app.service.spec.ts index fc136c47ad..486051d35f 100644 --- a/packages/worker/src/app.service.spec.ts +++ b/packages/worker/src/app.service.spec.ts @@ -10,6 +10,7 @@ import { CounterService } from "./counter"; import { BatchService } from "./batch"; import { BlockService } from "./block"; import { BlocksRevertService } from "./blocksRevert"; +import { TokenOffChainDataSaverService } from "./token/tokenInfo/tokenOffChainDataSaver.service"; import runMigrations from "./utils/runMigrations"; import { BLOCKS_REVERT_DETECTED_EVENT } from "./constants"; @@ -35,6 +36,7 @@ describe("AppService", () => { let batchService: BatchService; let blockService: BlockService; let blocksRevertService: BlocksRevertService; + let tokenOffChainDataSaverService: TokenOffChainDataSaverService; let dataSourceMock: DataSource; let configServiceMock: ConfigService; @@ -58,6 +60,10 @@ describe("AppService", () => { blocksRevertService = mock({ handleRevert: jest.fn().mockResolvedValue(null), }); + tokenOffChainDataSaverService = mock({ + start: jest.fn().mockResolvedValue(null), + stop: jest.fn().mockResolvedValue(null), + }); dataSourceMock = mock(); configServiceMock = mock({ get: jest.fn().mockReturnValue(false), @@ -88,6 +94,10 @@ describe("AppService", () => { provide: BlocksRevertService, useValue: blocksRevertService, }, + { + provide: TokenOffChainDataSaverService, + useValue: tokenOffChainDataSaverService, + }, { provide: DataSource, useValue: dataSourceMock, @@ -156,6 +166,13 @@ describe("AppService", () => { expect(balancesCleanerService.stop).toBeCalledTimes(1); }); + it("does not start token offchain data saver service by default", async () => { + appService.onModuleInit(); + await migrationsRunFinished; + expect(tokenOffChainDataSaverService.start).not.toBeCalled(); + appService.onModuleDestroy(); + }); + it("does not start batches service when disableBatchesProcessing is true", async () => { (configServiceMock.get as jest.Mock).mockReturnValue(true); appService.onModuleInit(); @@ -179,6 +196,15 @@ describe("AppService", () => { expect(balancesCleanerService.start).not.toBeCalled(); appService.onModuleDestroy(); }); + + it("starts token offchain data saver service when enableTokenOffChainDataSaver is true", async () => { + (configServiceMock.get as jest.Mock).mockReturnValue(true); + appService.onModuleInit(); + await migrationsRunFinished; + expect(tokenOffChainDataSaverService.start).toBeCalledTimes(1); + appService.onModuleDestroy(); + expect(tokenOffChainDataSaverService.stop).toBeCalledTimes(1); + }); }); describe("onModuleDestroy", () => { @@ -201,6 +227,11 @@ describe("AppService", () => { appService.onModuleDestroy(); expect(balancesCleanerService.stop).toBeCalledTimes(1); }); + + it("stops token offchain data saver service", async () => { + appService.onModuleDestroy(); + expect(tokenOffChainDataSaverService.stop).toBeCalledTimes(1); + }); }); describe("Handling blocks revert event", () => { @@ -212,6 +243,7 @@ describe("AppService", () => { expect(batchService.stop).toBeCalledTimes(1); expect(counterService.stop).toBeCalledTimes(1); expect(balancesCleanerService.stop).toBeCalledTimes(1); + expect(tokenOffChainDataSaverService.stop).toBeCalledTimes(1); expect(blocksRevertService.handleRevert).toBeCalledWith(blockNumber); @@ -219,6 +251,7 @@ describe("AppService", () => { expect(batchService.start).toBeCalledTimes(2); expect(counterService.start).toBeCalledTimes(2); expect(balancesCleanerService.start).toBeCalledTimes(2); + expect(tokenOffChainDataSaverService.start).toBeCalledTimes(2); await app.close(); });