From 5b909d8724ff6e7a8839e7bc56e399aa6da0b71c Mon Sep 17 00:00:00 2001 From: oXtxNt9U <120286271+oXtxNt9U@users.noreply.github.com> Date: Fri, 20 Dec 2024 14:03:05 +0900 Subject: [PATCH] update tests --- .../transaction-pool-service/source/query.test.ts | 8 ++++---- packages/transaction-pool-service/source/query.ts | 13 +++++++++---- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/packages/transaction-pool-service/source/query.test.ts b/packages/transaction-pool-service/source/query.test.ts index a9739b294..eb4c03dc5 100644 --- a/packages/transaction-pool-service/source/query.test.ts +++ b/packages/transaction-pool-service/source/query.test.ts @@ -138,7 +138,7 @@ describe<{ ]); }); - it("getFromHighestPriority - should return transactions order by fee", async (context) => { + it("getFromHighestPriority - should return transactions order by nonce/fee", async (context) => { stub(context.mempool, "getSenderMempools").returnValueOnce([ { getFromEarliest: () => [context.sender1Transaction200, context.sender1Transaction100] }, { getFromEarliest: () => [context.sender2Transaction100, context.sender2Transaction200] }, @@ -148,10 +148,10 @@ describe<{ const result = await query.getFromHighestPriority().all(); assert.equal(result, [ - context.sender2Transaction200, - context.sender2Transaction100, - context.sender1Transaction200, context.sender1Transaction100, + context.sender1Transaction200, + context.sender2Transaction100, + context.sender2Transaction200, ]); }); diff --git a/packages/transaction-pool-service/source/query.ts b/packages/transaction-pool-service/source/query.ts index eb22e6a1d..0415a8f66 100644 --- a/packages/transaction-pool-service/source/query.ts +++ b/packages/transaction-pool-service/source/query.ts @@ -88,10 +88,15 @@ export class Query implements Contracts.TransactionPool.Query { return new QueryIterable( [...this.mempool.getSenderMempools()] .flatMap((senderMempool) => [...senderMempool.getFromLatest()]) - .sort( - (a: Contracts.Crypto.Transaction, b: Contracts.Crypto.Transaction) => - a.data.gasPrice - b.data.gasPrice, - ), + .sort((a: Contracts.Crypto.Transaction, b: Contracts.Crypto.Transaction) => { + // Compare by nonce in ascending order + if (!a.data.nonce.isEqualTo(b.data.nonce)) { + return a.data.nonce.comparedTo(b.data.nonce); + } + + // If nonce values are equal, compare by gas price in ascending order + return a.data.gasPrice - b.data.gasPrice; + }), ); }