From 88a814a41a02f2da15b219a8457e6f300770bfe5 Mon Sep 17 00:00:00 2001 From: Fabio Di Fabio Date: Thu, 11 Apr 2024 14:33:06 +0200 Subject: [PATCH] Fix test flakyness Signed-off-by: Fabio Di Fabio --- .../plugin/acc/test/LineaPluginTestBase.java | 7 +- .../ProfitabilityValidatorTest.java | 80 +++++-------------- 2 files changed, 26 insertions(+), 61 deletions(-) diff --git a/acceptance-tests/src/test/java/linea/plugin/acc/test/LineaPluginTestBase.java b/acceptance-tests/src/test/java/linea/plugin/acc/test/LineaPluginTestBase.java index 4275b8b6..38a898f1 100644 --- a/acceptance-tests/src/test/java/linea/plugin/acc/test/LineaPluginTestBase.java +++ b/acceptance-tests/src/test/java/linea/plugin/acc/test/LineaPluginTestBase.java @@ -150,7 +150,8 @@ private void assertTransactionsInCorrectBlocks(Web3j web3j, List 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 deploy = SimpleStorage.deploy(web3j, txManager, new DefaultGasProvider()); @@ -206,8 +207,8 @@ protected List> 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( diff --git a/arithmetization/src/test/java/net/consensys/linea/sequencer/txpoolvalidation/validators/ProfitabilityValidatorTest.java b/arithmetization/src/test/java/net/consensys/linea/sequencer/txpoolvalidation/validators/ProfitabilityValidatorTest.java index 34a18b6e..5a8a1143 100644 --- a/arithmetization/src/test/java/net/consensys/linea/sequencer/txpoolvalidation/validators/ProfitabilityValidatorTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/sequencer/txpoolvalidation/validators/ProfitabilityValidatorTest.java @@ -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; @@ -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"); @@ -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 = @@ -79,8 +82,8 @@ public void initialize() { profitabilityValidatorAlways = new ProfitabilityValidator( - new TestBesuConfiguration(), - new TestBlockchainService(), + besuConfiguration, + blockchainService, profitabilityConfBuilder .txPoolCheckP2pEnabled(true) .txPoolCheckApiEnabled(true) @@ -88,8 +91,8 @@ public void initialize() { profitabilityValidatorNever = new ProfitabilityValidator( - new TestBesuConfiguration(), - new TestBlockchainService(), + besuConfiguration, + blockchainService, profitabilityConfBuilder .txPoolCheckP2pEnabled(false) .txPoolCheckApiEnabled(false) @@ -97,8 +100,8 @@ public void initialize() { profitabilityValidatorOnlyApi = new ProfitabilityValidator( - new TestBesuConfiguration(), - new TestBlockchainService(), + besuConfiguration, + blockchainService, profitabilityConfBuilder .txPoolCheckP2pEnabled(false) .txPoolCheckApiEnabled(true) @@ -106,8 +109,8 @@ public void initialize() { profitabilityValidatorOnlyP2p = new ProfitabilityValidator( - new TestBesuConfiguration(), - new TestBlockchainService(), + besuConfiguration, + blockchainService, profitabilityConfBuilder .txPoolCheckP2pEnabled(true) .txPoolCheckApiEnabled(false) @@ -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) @@ -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) @@ -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) @@ -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 getBlockByNumber(final long l) { - throw new UnsupportedOperationException(); - } - - @Override - public Hash getChainHeadHash() { - throw new UnsupportedOperationException(); - } - - @Override - public BlockHeader getChainHeadHeader() { - throw new UnsupportedOperationException(); - } - - @Override - public Optional getNextBlockBaseFee() { - return Optional.of(Wei.of(7)); - } - } }