Skip to content

Commit

Permalink
Rename variable and tests
Browse files Browse the repository at this point in the history
Signed-off-by: Gabriel-Trintinalia <[email protected]>
  • Loading branch information
Gabriel-Trintinalia committed Nov 2, 2023
1 parent 7f0e8f9 commit 912e7cb
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -827,12 +827,12 @@ public void decreaseOfMinGasPriceAtRuntimeIncludeTxThatWasPreviouslyNotSelected(
public void shouldNotSelectTransactionsWithPriorityFeeLessThanConfig() {
ProcessableBlockHeader blockHeader = createBlock(5_000_000, Wei.ONE);
miningParameters.setMinPriorityFeePerGas(Wei.of(7));
final Transaction tx1 = createTransaction(1, Wei.of(8), 100_000);
ensureTransactionIsValid(tx1);
// transaction tx2 should not be selected
final Transaction tx2 = createTransaction(2, Wei.of(7), 100_000);
ensureTransactionIsValid(tx2);
transactionPool.addRemoteTransactions(List.of(tx1, tx2));
final Transaction txSelected = createTransaction(1, Wei.of(8), 100_000);
ensureTransactionIsValid(txSelected);
// transaction txNotSelected should not be selected
final Transaction txNotSelected = createTransaction(2, Wei.of(7), 100_000);
ensureTransactionIsValid(txNotSelected);
transactionPool.addRemoteTransactions(List.of(txSelected, txNotSelected));

final BlockTransactionSelector selector =
createBlockSelector(
Expand All @@ -845,10 +845,11 @@ public void shouldNotSelectTransactionsWithPriorityFeeLessThanConfig() {

final TransactionSelectionResults results = selector.buildTransactionListForBlock();

assertThat(results.getSelectedTransactions()).containsOnly(tx1);
assertThat(results.getSelectedTransactions()).containsOnly(txSelected);
assertThat(results.getNotSelectedTransactions())
.containsOnly(
entry(tx2, TransactionSelectionResult.PRIORITY_FEE_PER_GAS_BELOW_CURRENT_MIN));
entry(
txNotSelected, TransactionSelectionResult.PRIORITY_FEE_PER_GAS_BELOW_CURRENT_MIN));
}

protected BlockTransactionSelector createBlockSelector(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,22 +222,23 @@ public void shouldNotSelectTransactionsWithPriorityFeeLessThanConfig() {
ProcessableBlockHeader blockHeader = createBlock(5_000_000, Wei.ONE);
miningParameters.setMinPriorityFeePerGas(Wei.of(7));

final Transaction tx1 = createEIP1559Transaction(1, Wei.of(8), Wei.of(8), 100_000);
ensureTransactionIsValid(tx1);
final Transaction txSelected1 = createEIP1559Transaction(1, Wei.of(8), Wei.of(8), 100_000);
ensureTransactionIsValid(txSelected1);

// transaction tx2 should not be selected
final Transaction tx2 = createEIP1559Transaction(2, Wei.of(7), Wei.of(7), 100_000);
ensureTransactionIsValid(tx2);
// transaction txNotSelected1 should not be selected
final Transaction txNotSelected1 = createEIP1559Transaction(2, Wei.of(7), Wei.of(7), 100_000);
ensureTransactionIsValid(txNotSelected1);

// transaction tx3 should be selected
final Transaction tx3 = createEIP1559Transaction(3, Wei.of(8), Wei.of(8), 100_000);
ensureTransactionIsValid(tx3);
// transaction txSelected2 should be selected
final Transaction txSelected2 = createEIP1559Transaction(3, Wei.of(8), Wei.of(8), 100_000);
ensureTransactionIsValid(txSelected2);

// transaction tx4 should not be selected
final Transaction tx4 = createEIP1559Transaction(4, Wei.of(8), Wei.of(6), 100_000);
ensureTransactionIsValid(tx4);
// transaction txNotSelected2 should not be selected
final Transaction txNotSelected2 = createEIP1559Transaction(4, Wei.of(8), Wei.of(6), 100_000);
ensureTransactionIsValid(txNotSelected2);

transactionPool.addRemoteTransactions(List.of(tx1, tx2, tx3, tx4));
transactionPool.addRemoteTransactions(
List.of(txSelected1, txNotSelected1, txSelected2, txNotSelected2));

assertThat(transactionPool.getPendingTransactions().size()).isEqualTo(4);

Expand All @@ -252,10 +253,12 @@ public void shouldNotSelectTransactionsWithPriorityFeeLessThanConfig() {

final TransactionSelectionResults results = selector.buildTransactionListForBlock();

assertThat(results.getSelectedTransactions()).containsOnly(tx1, tx3);
assertThat(results.getSelectedTransactions()).containsOnly(txSelected1, txSelected2);
assertThat(results.getNotSelectedTransactions())
.containsOnly(
entry(tx2, TransactionSelectionResult.PRIORITY_FEE_PER_GAS_BELOW_CURRENT_MIN),
entry(tx4, TransactionSelectionResult.PRIORITY_FEE_PER_GAS_BELOW_CURRENT_MIN));
entry(
txNotSelected1, TransactionSelectionResult.PRIORITY_FEE_PER_GAS_BELOW_CURRENT_MIN),
entry(
txNotSelected2, TransactionSelectionResult.PRIORITY_FEE_PER_GAS_BELOW_CURRENT_MIN));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,32 +57,33 @@ public void initialize() {
@Test
public void shouldNotSelectWhen_PriorityFeePerGas_IsLessThan_MinPriorityFeePerGas() {
var transaction = mockTransactionWithPriorityFee(minPriorityFeeParameter - 1);
assertSelection(transaction, TransactionSelectionResult.PRIORITY_FEE_PER_GAS_BELOW_CURRENT_MIN);
assertSelectionResult(
transaction, TransactionSelectionResult.PRIORITY_FEE_PER_GAS_BELOW_CURRENT_MIN);
}

@Test
public void shouldSelectWhen_PriorityFeePerGas_IsEqual_MinPriorityFeePerGas() {
var transaction = mockTransactionWithPriorityFee(minPriorityFeeParameter);
assertSelection(transaction, TransactionSelectionResult.SELECTED);
assertSelectionResult(transaction, TransactionSelectionResult.SELECTED);
}

@Test
public void shouldSelectWhen_PriorityFeePerGas_IsGreaterThan_MinPriorityFeePerGas() {
var transaction = mockTransactionWithPriorityFee(minPriorityFeeParameter + 1);
assertSelection(transaction, TransactionSelectionResult.SELECTED);
assertSelectionResult(transaction, TransactionSelectionResult.SELECTED);
}

@Test
public void shouldSelectWhenPrioritySender() {
var prioritySenderTransaction = mockTransactionWithPriorityFee(minPriorityFeeParameter - 1);
assertSelection(
assertSelectionResult(
prioritySenderTransaction,
TransactionSelectionResult.PRIORITY_FEE_PER_GAS_BELOW_CURRENT_MIN);
when(prioritySenderTransaction.hasPriority()).thenReturn(true);
assertSelection(prioritySenderTransaction, TransactionSelectionResult.SELECTED);
assertSelectionResult(prioritySenderTransaction, TransactionSelectionResult.SELECTED);
}

private void assertSelection(
private void assertSelectionResult(
final PendingTransaction transaction, final TransactionSelectionResult expectedResult) {
var actualResult = transactionSelector.evaluateTransactionPreProcessing(transaction, null);
assertThat(actualResult).isEqualTo(expectedResult);
Expand Down

0 comments on commit 912e7cb

Please sign in to comment.