Skip to content

Commit

Permalink
Update unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Fabio Di Fabio <[email protected]>
  • Loading branch information
fab-10 committed May 30, 2024
1 parent c8348ca commit 55bd42e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ public class ProfitabilityValidatorTest {
Address.fromHexString("0x0000000000000000000000000000000000001000");
public static final Address RECIPIENT =
Address.fromHexString("0x0000000000000000000000000000000000001001");
private static Wei PROFITABLE_GAS_PRICE = Wei.of(11000000);
private static Wei UNPROFITABLE_GAS_PRICE = Wei.of(1000000);
private static Wei PROFITABLE_GAS_PRICE = Wei.of(11_000_000);
private static Wei UNPROFITABLE_GAS_PRICE = Wei.of(200_000);
private static final SECPSignature FAKE_SIGNATURE;

static {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@
import org.junit.jupiter.api.Test;

public class ProfitableTransactionSelectorTest {
private static final int FIXED_GAS_COST_WEI = 0;
private static final int VARIABLE_GAS_COST_WEI = 1_000_000_000;
private static final double MIN_MARGIN = 1.0;
private static final int FIXED_GAS_COST_WEI = 600_000;
private static final int VARIABLE_GAS_COST_WEI = 1_000_000;
private static final double MIN_MARGIN = 1.5;
private static final int UNPROFITABLE_CACHE_SIZE = 2;
private static final int UNPROFITABLE_RETRY_LIMIT = 1;
private final LineaTransactionSelectorConfiguration txSelectorConf =
Expand Down Expand Up @@ -80,23 +80,12 @@ public void shouldSelectWhenProfitable() {
SELECTED);
}

@Test
public void shouldSelectWhenProfitableWithAdjustedSize() {
var mockTransactionProcessingResult = mockTransactionProcessingResult(21000);
verifyTransactionSelection(
transactionSelector,
mockEvaluationContext(false, 150, Wei.of(1_100_000_000), Wei.of(1_000_000_000), 21000),
mockTransactionProcessingResult,
SELECTED,
SELECTED);
}

@Test
public void shouldNotSelectWhenUnprofitableUpfront() {
var mockTransactionProcessingResult = mockTransactionProcessingResult(21000);
verifyTransactionSelection(
transactionSelector,
mockEvaluationContext(false, 1000, Wei.of(1_100_000_000), Wei.of(1_000_000_000), 21000),
mockEvaluationContext(false, 10000, Wei.of(1_000_100), Wei.of(1_000_000), 21000),
mockTransactionProcessingResult,
TX_UNPROFITABLE_UPFRONT,
null);
Expand All @@ -107,7 +96,7 @@ public void shouldNotSelectWhenUnprofitable() {
var mockTransactionProcessingResult = mockTransactionProcessingResult(21000);
verifyTransactionSelection(
transactionSelector,
mockEvaluationContext(false, 1000, Wei.of(1_100_000_000), Wei.of(1_000_000_000), 210000),
mockEvaluationContext(false, 10000, Wei.of(1_000_100), Wei.of(1_000_000), 210000),
mockTransactionProcessingResult,
SELECTED,
TX_UNPROFITABLE);
Expand Down Expand Up @@ -140,7 +129,7 @@ public void shouldSelectPriorityTxEvenWhenUnprofitable() {
public void shouldRetryUnprofitableTxWhenBelowLimit() {
var mockTransactionProcessingResult = mockTransactionProcessingResult(21000);
var mockEvaluationContext =
mockEvaluationContext(false, 1000, Wei.of(1_100_000_000), Wei.of(1_000_000_000), 210000);
mockEvaluationContext(false, 10000, Wei.of(1_000_010), Wei.of(1_000_000), 210000);
// first try
verifyTransactionSelection(
transactionSelector,
Expand Down Expand Up @@ -175,7 +164,7 @@ public void shouldEvictWhenUnprofitableCacheIsFull() {
for (int i = 0; i <= UNPROFITABLE_CACHE_SIZE; i++) {
var mockTransactionProcessingResult = mockTransactionProcessingResult(21000);
var mockEvaluationContext =
mockEvaluationContext(false, 1000, Wei.of(1_100_000_000), Wei.of(1_000_000_000), 210000);
mockEvaluationContext(false, 10000, Wei.of(1_000_010), Wei.of(1_000_000), 210000);
evaluationContexts[i] = mockEvaluationContext;
verifyTransactionSelection(
transactionSelector,
Expand Down Expand Up @@ -205,10 +194,10 @@ public void shouldEvictWhenUnprofitableCacheIsFull() {

@Test
public void shouldNotRetryUnprofitableTxWhenRetryLimitReached() {
var minGasPriceBlock1 = Wei.of(1_000_000_000);
var minGasPriceBlock1 = Wei.of(1_000_000);
var mockTransactionProcessingResult1 = mockTransactionProcessingResult(21000);
var mockEvaluationContext1 =
mockEvaluationContext(false, 1000, Wei.of(1_100_000_000), minGasPriceBlock1, 210000);
mockEvaluationContext(false, 10000, Wei.of(1_000_010), minGasPriceBlock1, 210000);
// first try of first tx
verifyTransactionSelection(
transactionSelector,
Expand All @@ -219,7 +208,7 @@ public void shouldNotRetryUnprofitableTxWhenRetryLimitReached() {

var mockTransactionProcessingResult2 = mockTransactionProcessingResult(21000);
var mockEvaluationContext2 =
mockEvaluationContext(false, 1000, Wei.of(1_100_000_000), minGasPriceBlock1, 210000);
mockEvaluationContext(false, 10000, Wei.of(1_000_010), minGasPriceBlock1, 210000);
// first try of second tx
verifyTransactionSelection(
transactionSelector,
Expand All @@ -240,7 +229,7 @@ public void shouldNotRetryUnprofitableTxWhenRetryLimitReached() {
// simulate another block
transactionSelector = newSelectorForNewBlock();
// we need to decrease the min gas price in order to allow a retry
var minGasPriceBlock2 = Wei.of(1_000_000_000).subtract(1);
var minGasPriceBlock2 = minGasPriceBlock1.subtract(1);

// we should remember of the unprofitable txs for the new block
assertThat(
Expand Down Expand Up @@ -271,10 +260,10 @@ public void shouldNotRetryUnprofitableTxWhenRetryLimitReached() {

@Test
public void shouldNotRetryUnprofitableTxWhenMinGasPriceNotDecreased() {
var minGasPriceBlock1 = Wei.of(1_000_000_000);
var minGasPriceBlock1 = Wei.of(1_000_000);
var mockTransactionProcessingResult1 = mockTransactionProcessingResult(21000);
var mockEvaluationContext1 =
mockEvaluationContext(false, 1000, Wei.of(1_100_000_000), minGasPriceBlock1, 210000);
mockEvaluationContext(false, 10000, Wei.of(1_000_010), minGasPriceBlock1, 210000);
// first try of first tx
verifyTransactionSelection(
transactionSelector,
Expand Down Expand Up @@ -310,10 +299,10 @@ public void shouldNotRetryUnprofitableTxWhenMinGasPriceNotDecreased() {

@Test
public void profitableAndUnprofitableTxsMix() {
var minGasPriceBlock1 = Wei.of(1_000_000_000);
var minGasPriceBlock1 = Wei.of(1_000_000);
var mockTransactionProcessingResult1 = mockTransactionProcessingResult(21000);
var mockEvaluationContext1 =
mockEvaluationContext(false, 1000, Wei.of(1_100_000_000), minGasPriceBlock1, 210000);
mockEvaluationContext(false, 10000, Wei.of(1_000_010), minGasPriceBlock1, 210000);
// first try of first tx
verifyTransactionSelection(
transactionSelector,
Expand All @@ -324,7 +313,7 @@ public void profitableAndUnprofitableTxsMix() {

var mockTransactionProcessingResult2 = mockTransactionProcessingResult(21000);
var mockEvaluationContext2 =
mockEvaluationContext(false, 100, Wei.of(1_100_000_000), minGasPriceBlock1, 210000);
mockEvaluationContext(false, 1000, Wei.of(1_000_010), minGasPriceBlock1, 210000);
// first try of second tx
verifyTransactionSelection(
transactionSelector,
Expand Down

0 comments on commit 55bd42e

Please sign in to comment.