Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
oXtxNt9U committed Dec 20, 2024
1 parent dea6823 commit 5b909d8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
8 changes: 4 additions & 4 deletions packages/transaction-pool-service/source/query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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] },
Expand All @@ -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,
]);
});

Expand Down
13 changes: 9 additions & 4 deletions packages/transaction-pool-service/source/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}),
);
}

Expand Down

0 comments on commit 5b909d8

Please sign in to comment.