diff --git a/packages/api/src/transaction/transaction.service.spec.ts b/packages/api/src/transaction/transaction.service.spec.ts index 7fabab7d56..788582b82f 100644 --- a/packages/api/src/transaction/transaction.service.spec.ts +++ b/packages/api/src/transaction/transaction.service.spec.ts @@ -155,11 +155,12 @@ describe("TransactionService", () => { ]); }); - it("orders transactions by receivedAt and transactionIndex DESC", async () => { + it("orders transactions by blockNumber, receivedAt and transactionIndex DESC", async () => { await service.findAll(filterTransactionsOptions, pagingOptions); expect(queryBuilderMock.orderBy).toBeCalledTimes(1); - expect(queryBuilderMock.orderBy).toHaveBeenCalledWith("transaction.receivedAt", "DESC"); - expect(queryBuilderMock.addOrderBy).toBeCalledTimes(1); + expect(queryBuilderMock.orderBy).toHaveBeenCalledWith("transaction.blockNumber", "DESC"); + expect(queryBuilderMock.addOrderBy).toBeCalledTimes(2); + expect(queryBuilderMock.addOrderBy).toHaveBeenCalledWith("transaction.receivedAt", "DESC"); expect(queryBuilderMock.addOrderBy).toHaveBeenCalledWith("transaction.transactionIndex", "DESC"); }); diff --git a/packages/api/src/transaction/transaction.service.ts b/packages/api/src/transaction/transaction.service.ts index 95821b839f..32661d830d 100644 --- a/packages/api/src/transaction/transaction.service.ts +++ b/packages/api/src/transaction/transaction.service.ts @@ -82,7 +82,8 @@ export class TransactionService { queryBuilder.leftJoin("transaction.batch", "batch"); queryBuilder.addSelect(["batch.commitTxHash", "batch.executeTxHash", "batch.proveTxHash"]); queryBuilder.where(filterOptions); - queryBuilder.orderBy("transaction.receivedAt", "DESC"); + queryBuilder.orderBy("transaction.blockNumber", "DESC"); + queryBuilder.addOrderBy("transaction.receivedAt", "DESC"); queryBuilder.addOrderBy("transaction.transactionIndex", "DESC"); return await paginate(queryBuilder, paginationOptions); }