Skip to content

Commit

Permalink
Fix test flakyness
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 Apr 11, 2024
1 parent e398ff3 commit 88a814a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ private void assertTransactionsInCorrectBlocks(Web3j web3j, List<String> hashes,
protected SimpleStorage deploySimpleStorage() throws Exception {
final Web3j web3j = minerNode.nodeRequests().eth();
final Credentials credentials = Credentials.create(Accounts.GENESIS_ACCOUNT_ONE_PRIVATE_KEY);
TransactionManager txManager = new RawTransactionManager(web3j, credentials, CHAIN_ID);
TransactionManager txManager =
new RawTransactionManager(web3j, credentials, CHAIN_ID, createReceiptProcessor(web3j));

final RemoteCall<SimpleStorage> deploy =
SimpleStorage.deploy(web3j, txManager, new DefaultGasProvider());
Expand Down Expand Up @@ -206,8 +207,8 @@ protected List<Map<String, String>> getTxPoolContent() {
private TransactionReceiptProcessor createReceiptProcessor(Web3j web3j) {
return new PollingTransactionReceiptProcessor(
web3j,
TransactionManager.DEFAULT_POLLING_FREQUENCY,
TransactionManager.DEFAULT_POLLING_ATTEMPTS_PER_TX_HASH);
Math.max(1000, LINEA_CLIQUE_OPTIONS.blockPeriodSeconds() * 1000 / 5),
LINEA_CLIQUE_OPTIONS.blockPeriodSeconds() * 3);
}

protected String sendTransactionWithGivenLengthPayload(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
package net.consensys.linea.sequencer.txpoolvalidation.validators;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.when;

import java.math.BigInteger;
import java.nio.file.Path;
import java.util.Optional;

import lombok.RequiredArgsConstructor;
Expand All @@ -30,18 +30,18 @@
import org.bouncycastle.crypto.params.ECDomainParameters;
import org.hyperledger.besu.crypto.SECPSignature;
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.plugin.data.BlockContext;
import org.hyperledger.besu.plugin.data.BlockHeader;
import org.hyperledger.besu.plugin.services.BesuConfiguration;
import org.hyperledger.besu.plugin.services.BlockchainService;
import org.hyperledger.besu.plugin.services.storage.DataStorageFormat;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

@Slf4j
@RequiredArgsConstructor
@ExtendWith(MockitoExtension.class)
public class ProfitabilityValidatorTest {
public static final Address SENDER =
Address.fromHexString("0x0000000000000000000000000000000000001000");
Expand Down Expand Up @@ -71,6 +71,9 @@ public class ProfitabilityValidatorTest {
private ProfitabilityValidator profitabilityValidatorOnlyP2p;
private ProfitabilityValidator profitabilityValidatorNever;

@Mock BesuConfiguration besuConfiguration;
@Mock BlockchainService blockchainService;

@BeforeEach
public void initialize() {
final var profitabilityConfBuilder =
Expand All @@ -79,35 +82,35 @@ public void initialize() {

profitabilityValidatorAlways =
new ProfitabilityValidator(
new TestBesuConfiguration(),
new TestBlockchainService(),
besuConfiguration,
blockchainService,
profitabilityConfBuilder
.txPoolCheckP2pEnabled(true)
.txPoolCheckApiEnabled(true)
.build());

profitabilityValidatorNever =
new ProfitabilityValidator(
new TestBesuConfiguration(),
new TestBlockchainService(),
besuConfiguration,
blockchainService,
profitabilityConfBuilder
.txPoolCheckP2pEnabled(false)
.txPoolCheckApiEnabled(false)
.build());

profitabilityValidatorOnlyApi =
new ProfitabilityValidator(
new TestBesuConfiguration(),
new TestBlockchainService(),
besuConfiguration,
blockchainService,
profitabilityConfBuilder
.txPoolCheckP2pEnabled(false)
.txPoolCheckApiEnabled(true)
.build());

profitabilityValidatorOnlyP2p =
new ProfitabilityValidator(
new TestBesuConfiguration(),
new TestBlockchainService(),
besuConfiguration,
blockchainService,
profitabilityConfBuilder
.txPoolCheckP2pEnabled(true)
.txPoolCheckApiEnabled(false)
Expand All @@ -132,6 +135,8 @@ public void acceptPriorityRemoteWhenBelowMinProfitability() {

@Test
public void rejectRemoteWhenBelowMinProfitability() {
when(besuConfiguration.getMinGasPrice()).thenReturn(Wei.of(100_000_000));
when(blockchainService.getNextBlockBaseFee()).thenReturn(Optional.of(Wei.of(7)));
final org.hyperledger.besu.ethereum.core.Transaction transaction =
org.hyperledger.besu.ethereum.core.Transaction.builder()
.sender(SENDER)
Expand Down Expand Up @@ -196,6 +201,8 @@ public void acceptRemoteWhenBelowMinProfitabilityIfCheckDisabledForP2p() {

@Test
public void rejectRemoteWhenBelowMinProfitabilityIfCheckEnableForP2p() {
when(besuConfiguration.getMinGasPrice()).thenReturn(Wei.of(100_000_000));
when(blockchainService.getNextBlockBaseFee()).thenReturn(Optional.of(Wei.of(7)));
final org.hyperledger.besu.ethereum.core.Transaction transaction =
org.hyperledger.besu.ethereum.core.Transaction.builder()
.sender(SENDER)
Expand Down Expand Up @@ -229,6 +236,8 @@ public void acceptLocalWhenBelowMinProfitabilityIfCheckDisabledForApi() {

@Test
public void rejectLocalWhenBelowMinProfitabilityIfCheckEnableForApi() {
when(besuConfiguration.getMinGasPrice()).thenReturn(Wei.of(100_000_000));
when(blockchainService.getNextBlockBaseFee()).thenReturn(Optional.of(Wei.of(7)));
final org.hyperledger.besu.ethereum.core.Transaction transaction =
org.hyperledger.besu.ethereum.core.Transaction.builder()
.sender(SENDER)
Expand All @@ -243,49 +252,4 @@ public void rejectLocalWhenBelowMinProfitabilityIfCheckEnableForApi() {
.isPresent()
.contains("Gas price too low");
}

private static class TestBesuConfiguration implements BesuConfiguration {
@Override
public Path getStoragePath() {
throw new UnsupportedOperationException();
}

@Override
public Path getDataPath() {
throw new UnsupportedOperationException();
}

@Override
public DataStorageFormat getDatabaseFormat() {
throw new UnsupportedOperationException();
}

@Override
public Wei getMinGasPrice() {
return Wei.of(100_000_000);
}
}

private static class TestBlockchainService implements BlockchainService {

@Override
public Optional<BlockContext> getBlockByNumber(final long l) {
throw new UnsupportedOperationException();
}

@Override
public Hash getChainHeadHash() {
throw new UnsupportedOperationException();
}

@Override
public BlockHeader getChainHeadHeader() {
throw new UnsupportedOperationException();
}

@Override
public Optional<Wei> getNextBlockBaseFee() {
return Optional.of(Wei.of(7));
}
}
}

0 comments on commit 88a814a

Please sign in to comment.