Skip to content

Commit

Permalink
Fix profitability acceptance 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 29, 2024
1 parent afca893 commit 66d39bb
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,12 @@
import org.web3j.tx.TransactionManager;

public class ProfitableTransactionTest extends LineaPluginTestBase {
private static final int VERIFICATION_GAS_COST = 1_200_000;
private static final int VERIFICATION_CAPACITY = 90_000;
private static final int GAS_PRICE_RATIO = 15;
private static final double MIN_MARGIN = 1.0;
private static final double MIN_MARGIN = 1.5;
private static final Wei MIN_GAS_PRICE = Wei.of(1_000_000_000);

@Override
public List<String> getTestCliOptions() {
return new TestCommandLineOptionsBuilder()
.set("--plugin-linea-verification-gas-cost=", String.valueOf(VERIFICATION_GAS_COST))
.set("--plugin-linea-verification-capacity=", String.valueOf(VERIFICATION_CAPACITY))
.set("--plugin-linea-gas-price-ratio=", String.valueOf(GAS_PRICE_RATIO))
.set("--plugin-linea-min-margin=", String.valueOf(MIN_MARGIN))
.build();
}
Expand Down Expand Up @@ -70,7 +64,7 @@ public void transactionIsNotMinedWhenUnprofitable() throws Exception {

final var txUnprofitable =
txManager.sendTransaction(
MIN_GAS_PRICE.getAsBigInteger(),
MIN_GAS_PRICE.getAsBigInteger().divide(BigInteger.valueOf(100)),
BigInteger.valueOf(MAX_TX_GAS_LIMIT / 2),
credentials.getAddress(),
txData.toString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public List<String> getTestCliOptions() {
protected void assertIsProfitable(
final Transaction tx,
final Wei baseFee,
final Wei estimatedPriorityFee,
final Wei estimatedMaxGasPrice,
final long estimatedGasLimit) {
final var minGasPrice = minerNode.getMiningParameters().getMinTransactionGasPrice();
Expand All @@ -62,6 +61,6 @@ protected void assertIsProfitable(
protected void assertMinGasPriceLowerBound(final Wei baseFee, final Wei estimatedMaxGasPrice) {
// since we are in compatibility mode, we want to check that returned profitable priority fee is
// the min priority fee per gas * multiplier + base fee
assertIsProfitable(null, baseFee, null, estimatedMaxGasPrice, 0);
assertIsProfitable(null, baseFee, estimatedMaxGasPrice, 0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,31 +141,26 @@ public void lineaEstimateGasIsProfitable() {
.signature(LineaEstimateGas.FAKE_SIGNATURE_FOR_SIZE_CALCULATION)
.build();

assertIsProfitable(tx, baseFee, estimatedPriorityFee, estimatedMaxGasPrice, estimatedGasLimit);
assertIsProfitable(tx, baseFee, estimatedMaxGasPrice, estimatedGasLimit);
}

protected void assertIsProfitable(
final org.hyperledger.besu.ethereum.core.Transaction tx,
final Wei baseFee,
final Wei estimatedPriorityFee,
final Wei estimatedMaxGasPrice,
final long estimatedGasLimit) {

final var minGasPrice = minerNode.getMiningParameters().getMinTransactionGasPrice();

final var profitabilityCalculator = new TransactionProfitabilityCalculator(profitabilityConf);

final var profitablePriorityFee =
profitabilityCalculator.profitablePriorityFeePerGas(
tx, profitabilityConf.txPoolMinMargin(), estimatedGasLimit, minGasPrice);

assertThat(profitablePriorityFee.greaterThan(minGasPrice)).isTrue();
assertThat(estimatedMaxGasPrice.greaterOrEqualThan(minGasPrice)).isTrue();

assertThat(
profitabilityCalculator.isProfitable(
"Test",
tx,
profitabilityConf.txPoolMinMargin(),
profitabilityConf.estimateGasMinMargin(),
estimatedMaxGasPrice,
estimatedGasLimit,
minGasPrice))
Expand Down

0 comments on commit 66d39bb

Please sign in to comment.