Skip to content

Commit

Permalink
fix: transaction endpoint order (#80)
Browse files Browse the repository at this point in the history
# What ❔

Transactions order fix.

## Why ❔

Because current order doesn't take into account block numbers which is
incorrect.

## Checklist

<!-- Check your PR fulfills the following items. -->
<!-- For draft PRs check the boxes as you complete them. -->

- [X] PR title corresponds to the body of PR (we generate changelog
entries from PRs).
- [X] Tests for the changes have been added / updated.
  • Loading branch information
vasyl-ivanchuk committed Nov 8, 2023
1 parent 04429f6 commit 08518d1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
7 changes: 4 additions & 3 deletions packages/api/src/transaction/transaction.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});

Expand Down
3 changes: 2 additions & 1 deletion packages/api/src/transaction/transaction.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Transaction>(queryBuilder, paginationOptions);
}
Expand Down

0 comments on commit 08518d1

Please sign in to comment.