From 08518d196fba2b4ea276a6413cdc5d380421738c Mon Sep 17 00:00:00 2001 From: Vasyl Ivanchuk Date: Wed, 8 Nov 2023 11:03:07 +0200 Subject: [PATCH] fix: transaction endpoint order (#80) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # What ❔ Transactions order fix. ## Why ❔ Because current order doesn't take into account block numbers which is incorrect. ## Checklist - [X] PR title corresponds to the body of PR (we generate changelog entries from PRs). - [X] Tests for the changes have been added / updated. --- packages/api/src/transaction/transaction.service.spec.ts | 7 ++++--- packages/api/src/transaction/transaction.service.ts | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) 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); }