From 9f87ec48b2d8b21ec32351e33929ffaf16cd7f01 Mon Sep 17 00:00:00 2001 From: Justin Florentine Date: Fri, 1 Dec 2023 15:41:17 -0500 Subject: [PATCH 01/28] Release 23.10.3 rc1 in progress, uprev main. (#6227) moving on to 23.10.4 developmnet --------- Signed-off-by: Justin Florentine --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index df2f0da93de..32269ba9415 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -version=23.10.3-SNAPSHOT +version=23.10.4-SNAPSHOT org.gradle.welcome=never # Set exports/opens flags required by Google Java Format and ErrorProne plugins. (JEP-396) From 9d579275726225835278ca51666c84e1c25205ca Mon Sep 17 00:00:00 2001 From: Gabriel-Trintinalia Date: Mon, 4 Dec 2023 15:12:51 +1100 Subject: [PATCH 02/28] New cli options to limit rewards return by eth_feeHistory (#6202) Signed-off-by: Gabriel-Trintinalia --- .../org/hyperledger/besu/cli/BesuCommand.java | 65 ++++++++++++-- .../hyperledger/besu/cli/BesuCommandTest.java | 71 ++++++++++++++++ .../common/MigratingMiningCoordinator.java | 5 ++ .../blockcreation/BftBlockCreatorFactory.java | 9 ++ .../blockcreation/BftMiningCoordinator.java | 5 ++ .../merge/blockcreation/MergeCoordinator.java | 5 ++ .../blockcreation/TransitionCoordinator.java | 5 ++ .../besu/ethereum/api/ApiConfiguration.java | 18 ++++ .../internal/methods/EthFeeHistory.java | 63 +++++++++++++- .../jsonrpc/methods/EthJsonRpcMethods.java | 6 +- .../internal/methods/EthFeeHistoryTest.java | 85 +++++++++++++++---- .../blockcreation/AbstractMinerExecutor.java | 4 + .../AbstractMiningCoordinator.java | 5 ++ .../blockcreation/MiningCoordinator.java | 2 + .../blockcreation/NoopMiningCoordinator.java | 5 ++ 15 files changed, 323 insertions(+), 30 deletions(-) diff --git a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java index a909b1994ac..91ef840d62e 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java @@ -1217,6 +1217,29 @@ static class PermissionsOptionGroup { description = "Maximum gas price for eth_gasPrice (default: ${DEFAULT-VALUE})") private final Long apiGasPriceMax = 500_000_000_000L; + @CommandLine.Option( + names = {"--api-priority-fee-limiting-enabled"}, + hidden = true, + description = + "Set to enable priority fee limit in eth_feeHistory (default: ${DEFAULT-VALUE})") + private final Boolean apiPriorityFeeLimitingEnabled = false; + + @CommandLine.Option( + names = {"--api-priority-fee-lower-bound-coefficient"}, + hidden = true, + description = + "Coefficient for setting the lower limit of minimum priority fee in eth_feeHistory (default: ${DEFAULT-VALUE})") + private final Long apiPriorityFeeLowerBoundCoefficient = + ApiConfiguration.DEFAULT_LOWER_BOUND_PRIORITY_FEE_COEFFICIENT; + + @CommandLine.Option( + names = {"--api-priority-fee-upper-bound-coefficient"}, + hidden = true, + description = + "Coefficient for setting the upper limit of minimum priority fee in eth_feeHistory (default: ${DEFAULT-VALUE})") + private final Long apiPriorityFeeUpperBoundCoefficient = + ApiConfiguration.DEFAULT_UPPER_BOUND_PRIORITY_FEE_COEFFICIENT; + @CommandLine.Option( names = {"--static-nodes-file"}, paramLabel = MANDATORY_FILE_FORMAT_HELP, @@ -1875,6 +1898,17 @@ private void validateDnsOptionsParams() { } } + private void checkApiOptionsDependencies() { + CommandLineUtils.checkOptionDependencies( + logger, + commandLine, + "--api-priority-fee-limiting-enabled", + !apiPriorityFeeLimitingEnabled, + asList( + "--api-priority-fee-upper-bound-coefficient", + "--api-priority-fee-lower-bound-coefficient")); + } + private void ensureValidPeerBoundParams() { maxPeers = p2PDiscoveryOptionGroup.maxPeers; peersLowerBound = unstableNetworkingOptions.toDomainObject().getPeerLowerBound(); @@ -2485,15 +2519,28 @@ && rpcWsAuthenticationCredentialsFile() == null } private ApiConfiguration apiConfiguration() { - return ImmutableApiConfiguration.builder() - .gasPriceBlocks(apiGasPriceBlocks) - .gasPricePercentile(apiGasPricePercentile) - .gasPriceMinSupplier( - getMiningParameters().getMinTransactionGasPrice().getAsBigInteger()::longValueExact) - .gasPriceMax(apiGasPriceMax) - .maxLogsRange(rpcMaxLogsRange) - .gasCap(rpcGasCap) - .build(); + checkApiOptionsDependencies(); + var builder = + ImmutableApiConfiguration.builder() + .gasPriceBlocks(apiGasPriceBlocks) + .gasPricePercentile(apiGasPricePercentile) + .gasPriceMinSupplier( + getMiningParameters().getMinTransactionGasPrice().getAsBigInteger()::longValueExact) + .gasPriceMax(apiGasPriceMax) + .maxLogsRange(rpcMaxLogsRange) + .gasCap(rpcGasCap) + .isPriorityFeeLimitingEnabled(apiPriorityFeeLimitingEnabled); + if (apiPriorityFeeLimitingEnabled) { + if (apiPriorityFeeLowerBoundCoefficient > apiPriorityFeeUpperBoundCoefficient) { + throw new ParameterException( + this.commandLine, + "--api-priority-fee-lower-bound-coefficient cannot be greater than the value of --api-priority-fee-upper-bound-coefficient"); + } + builder + .lowerBoundPriorityFeeCoefficient(apiPriorityFeeLowerBoundCoefficient) + .upperBoundPriorityFeeCoefficient(apiPriorityFeeUpperBoundCoefficient); + } + return builder.build(); } /** diff --git a/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java b/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java index 19e42e1cd82..85586871483 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java @@ -1609,6 +1609,77 @@ public void rpcGasCapOptionMustBeUsed() { assertThat(commandErrorOutput.toString(UTF_8)).isEmpty(); } + @Test + public void apiPriorityFeeLimitingEnabledOptionMustBeUsed() { + parseCommand("--api-priority-fee-limiting-enabled"); + verify(mockRunnerBuilder).apiConfiguration(apiConfigurationCaptor.capture()); + verify(mockRunnerBuilder).build(); + assertThat(apiConfigurationCaptor.getValue()) + .isEqualTo(ImmutableApiConfiguration.builder().isPriorityFeeLimitingEnabled(true).build()); + + assertThat(commandOutput.toString(UTF_8)).isEmpty(); + assertThat(commandErrorOutput.toString(UTF_8)).isEmpty(); + } + + @Test + public void apiPriorityFeeLowerBoundCoefficientOptionMustBeUsed() { + final long lowerBound = 150L; + parseCommand( + "--api-priority-fee-lower-bound-coefficient", + Long.toString(lowerBound), + "--api-priority-fee-limiting-enabled"); + verify(mockRunnerBuilder).apiConfiguration(apiConfigurationCaptor.capture()); + verify(mockRunnerBuilder).build(); + assertThat(apiConfigurationCaptor.getValue()) + .isEqualTo( + ImmutableApiConfiguration.builder() + .lowerBoundPriorityFeeCoefficient(lowerBound) + .isPriorityFeeLimitingEnabled(true) + .build()); + + assertThat(commandOutput.toString(UTF_8)).isEmpty(); + assertThat(commandErrorOutput.toString(UTF_8)).isEmpty(); + } + + @Test + public void + apiPriorityFeeLowerBoundCoefficients_MustNotBeGreaterThan_apiPriorityFeeUpperBoundCoefficient() { + final long lowerBound = 200L; + final long upperBound = 100L; + + parseCommand( + "--api-priority-fee-limiting-enabled", + "--api-priority-fee-lower-bound-coefficient", + Long.toString(lowerBound), + "--api-priority-fee-upper-bound-coefficient", + Long.toString(upperBound)); + Mockito.verifyNoInteractions(mockRunnerBuilder); + assertThat(commandOutput.toString(UTF_8)).isEmpty(); + assertThat(commandErrorOutput.toString(UTF_8)) + .contains( + "--api-priority-fee-lower-bound-coefficient cannot be greater than the value of --api-priority-fee-upper-bound-coefficient"); + } + + @Test + public void apiPriorityFeeUpperBoundCoefficientsOptionMustBeUsed() { + final long upperBound = 200L; + parseCommand( + "--api-priority-fee-upper-bound-coefficient", + Long.toString(upperBound), + "--api-priority-fee-limiting-enabled"); + verify(mockRunnerBuilder).apiConfiguration(apiConfigurationCaptor.capture()); + verify(mockRunnerBuilder).build(); + assertThat(apiConfigurationCaptor.getValue()) + .isEqualTo( + ImmutableApiConfiguration.builder() + .upperBoundPriorityFeeCoefficient(upperBound) + .isPriorityFeeLimitingEnabled(true) + .build()); + + assertThat(commandOutput.toString(UTF_8)).isEmpty(); + assertThat(commandErrorOutput.toString(UTF_8)).isEmpty(); + } + @Test public void p2pPeerUpperBound_without_p2pPeerLowerBound_shouldSetLowerBoundEqualToUpperBound() { diff --git a/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/MigratingMiningCoordinator.java b/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/MigratingMiningCoordinator.java index de3fc3a3a0f..29f31228d24 100644 --- a/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/MigratingMiningCoordinator.java +++ b/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/MigratingMiningCoordinator.java @@ -103,6 +103,11 @@ public Wei getMinTransactionGasPrice() { return activeMiningCoordinator.getMinTransactionGasPrice(); } + @Override + public Wei getMinPriorityFeePerGas() { + return activeMiningCoordinator.getMinPriorityFeePerGas(); + } + @Override public void setExtraData(final Bytes extraData) { activeMiningCoordinator.setExtraData(extraData); diff --git a/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/blockcreation/BftBlockCreatorFactory.java b/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/blockcreation/BftBlockCreatorFactory.java index 437c5dc65ef..52e913f95e0 100644 --- a/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/blockcreation/BftBlockCreatorFactory.java +++ b/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/blockcreation/BftBlockCreatorFactory.java @@ -147,6 +147,15 @@ public Wei getMinTransactionGasPrice() { return miningParameters.getMinTransactionGasPrice(); } + /** + * Gets min priority fee per gas + * + * @return min priority fee per gas + */ + public Wei getMinPriorityFeePerGas() { + return miningParameters.getMinPriorityFeePerGas(); + } + /** * Create extra data bytes. * diff --git a/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/blockcreation/BftMiningCoordinator.java b/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/blockcreation/BftMiningCoordinator.java index 5107a00fe15..47542ec8ebb 100644 --- a/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/blockcreation/BftMiningCoordinator.java +++ b/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/blockcreation/BftMiningCoordinator.java @@ -148,6 +148,11 @@ public Wei getMinTransactionGasPrice() { return blockCreatorFactory.getMinTransactionGasPrice(); } + @Override + public Wei getMinPriorityFeePerGas() { + return blockCreatorFactory.getMinPriorityFeePerGas(); + } + @Override public void setExtraData(final Bytes extraData) { blockCreatorFactory.setExtraData(extraData); diff --git a/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeCoordinator.java b/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeCoordinator.java index ab7fd05ea21..5773a468251 100644 --- a/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeCoordinator.java +++ b/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeCoordinator.java @@ -211,6 +211,11 @@ public Wei getMinTransactionGasPrice() { return miningParameters.getMinTransactionGasPrice(); } + @Override + public Wei getMinPriorityFeePerGas() { + return miningParameters.getMinPriorityFeePerGas(); + } + @Override public void setExtraData(final Bytes extraData) { this.miningParameters.setExtraData(extraData); diff --git a/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/blockcreation/TransitionCoordinator.java b/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/blockcreation/TransitionCoordinator.java index 4044ac3d34b..75da1d22f3b 100644 --- a/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/blockcreation/TransitionCoordinator.java +++ b/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/blockcreation/TransitionCoordinator.java @@ -101,6 +101,11 @@ public Wei getMinTransactionGasPrice() { return dispatchFunctionAccordingToMergeState(MiningCoordinator::getMinTransactionGasPrice); } + @Override + public Wei getMinPriorityFeePerGas() { + return dispatchFunctionAccordingToMergeState(MiningCoordinator::getMinPriorityFeePerGas); + } + @Override public void setExtraData(final Bytes extraData) { miningCoordinator.setExtraData(extraData); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/ApiConfiguration.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/ApiConfiguration.java index b88f374aa3f..e277c2ba2ff 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/ApiConfiguration.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/ApiConfiguration.java @@ -24,6 +24,9 @@ @Value.Style(allParameters = true) public abstract class ApiConfiguration { + public static final long DEFAULT_LOWER_BOUND_PRIORITY_FEE_COEFFICIENT = 0L; + public static final long DEFAULT_UPPER_BOUND_PRIORITY_FEE_COEFFICIENT = Long.MAX_VALUE; + @Value.Default public long getGasPriceBlocks() { return 100; @@ -59,4 +62,19 @@ public Long getMaxLogsRange() { public Long getGasCap() { return 0L; } + + @Value.Default + public boolean isPriorityFeeLimitingEnabled() { + return false; + } + + @Value.Default + public Long getLowerBoundPriorityFeeCoefficient() { + return DEFAULT_LOWER_BOUND_PRIORITY_FEE_COEFFICIENT; + } + + @Value.Default + public Long getUpperBoundPriorityFeeCoefficient() { + return DEFAULT_UPPER_BOUND_PRIORITY_FEE_COEFFICIENT; + } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistory.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistory.java index 3b155743267..e4d71ae8e79 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistory.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistory.java @@ -18,6 +18,7 @@ import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.Wei; +import org.hyperledger.besu.ethereum.api.ApiConfiguration; import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameter; @@ -28,6 +29,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.FeeHistory; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.ImmutableFeeHistory; +import org.hyperledger.besu.ethereum.blockcreation.MiningCoordinator; import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockHeader; @@ -53,14 +55,22 @@ public class EthFeeHistory implements JsonRpcMethod { private final ProtocolSchedule protocolSchedule; private final Blockchain blockchain; + private final MiningCoordinator miningCoordinator; + private final ApiConfiguration apiConfiguration; private final Cache> cache; private static final int MAXIMUM_CACHE_SIZE = 100_000; record RewardCacheKey(Hash blockHash, List rewardPercentiles) {} - public EthFeeHistory(final ProtocolSchedule protocolSchedule, final Blockchain blockchain) { + public EthFeeHistory( + final ProtocolSchedule protocolSchedule, + final Blockchain blockchain, + final MiningCoordinator miningCoordinator, + final ApiConfiguration apiConfiguration) { this.protocolSchedule = protocolSchedule; this.blockchain = blockchain; + this.miningCoordinator = miningCoordinator; + this.apiConfiguration = apiConfiguration; this.cache = Caffeine.newBuilder().maximumSize(MAXIMUM_CACHE_SIZE).build(); } @@ -203,7 +213,16 @@ public List computeRewards(final List rewardPercentiles, final Bloc final List transactionsGasUsed = calculateTransactionsGasUsed(block); final List transactionsInfo = generateTransactionsInfo(transactions, transactionsGasUsed, baseFee); - return calculateRewards(rewardPercentiles, block, transactionsInfo); + + var realRewards = calculateRewards(rewardPercentiles, block, transactionsInfo); + + // If the priority fee boundary is set, return the bounded rewards. Otherwise, return the real + // rewards. + if (apiConfiguration.isPriorityFeeLimitingEnabled()) { + return boundRewards(realRewards); + } else { + return realRewards; + } } private List calculateRewards( @@ -235,6 +254,46 @@ private List calculateRewards( return rewards; } + /** + * This method returns a list of bounded rewards. + * + * @param rewards The list of rewards to be bounded. + * @return The list of bounded rewards. + */ + private List boundRewards(final List rewards) { + Wei minPriorityFee = miningCoordinator.getMinPriorityFeePerGas(); + Wei lowerBound = + minPriorityFee.multiply(apiConfiguration.getLowerBoundPriorityFeeCoefficient()).divide(100); + Wei upperBound = + minPriorityFee.multiply(apiConfiguration.getUpperBoundPriorityFeeCoefficient()).divide(100); + + return rewards.stream().map(reward -> boundReward(reward, lowerBound, upperBound)).toList(); + } + + /** + * This method bounds the reward between a lower and upper limit. + * + * @param reward The reward to be bounded. + * @param lowerBound The lower limit for the reward. + * @param upperBound The upper limit for the reward. + * @return The bounded reward. + */ + private Wei boundReward(final Wei reward, final Wei lowerBound, final Wei upperBound) { + + // If the reward is less than the lower bound, return the lower bound. + if (reward.compareTo(lowerBound) <= 0) { + return lowerBound; + } + + // If the reward is greater than the upper bound, return the upper bound. + if (reward.compareTo(upperBound) > 0) { + return upperBound; + } + + // If the reward is within the bounds, return the reward as is. + return reward; + } + private List calculateTransactionsGasUsed(final Block block) { final List transactionsGasUsed = new ArrayList<>(); long cumulativeGasUsed = 0L; diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EthJsonRpcMethods.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EthJsonRpcMethods.java index 9dfe2e45772..9d70e681fdf 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EthJsonRpcMethods.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EthJsonRpcMethods.java @@ -130,7 +130,11 @@ protected Map create() { blockchainQueries.getWorldStateArchive(), protocolSchedule, apiConfiguration.getGasCap())), - new EthFeeHistory(protocolSchedule, blockchainQueries.getBlockchain()), + new EthFeeHistory( + protocolSchedule, + blockchainQueries.getBlockchain(), + miningCoordinator, + apiConfiguration), new EthGetCode(blockchainQueries), new EthGetLogs(blockchainQueries, apiConfiguration.getMaxLogsRange()), new EthGetProof(blockchainQueries), diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistoryTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistoryTest.java index eaf88bbf9e6..bffd9278e37 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistoryTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistoryTest.java @@ -23,8 +23,11 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import org.hyperledger.besu.consensus.merge.blockcreation.MergeCoordinator; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.Wei; +import org.hyperledger.besu.ethereum.api.ApiConfiguration; +import org.hyperledger.besu.ethereum.api.ImmutableApiConfiguration; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters; @@ -35,6 +38,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.FeeHistory; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.ImmutableFeeHistory; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.ImmutableFeeHistoryResult; +import org.hyperledger.besu.ethereum.blockcreation.MiningCoordinator; import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.chain.MutableBlockchain; import org.hyperledger.besu.ethereum.core.Block; @@ -64,6 +68,7 @@ public class EthFeeHistoryTest { private MutableBlockchain blockchain; private EthFeeHistory method; private ProtocolSchedule protocolSchedule; + private MiningCoordinator miningCoordinator; @BeforeEach public void setUp() { @@ -72,7 +77,15 @@ public void setUp() { blockchain = createInMemoryBlockchain(genesisBlock); gen.blockSequence(genesisBlock, 10) .forEach(block -> blockchain.appendBlock(block, gen.receipts(block))); - method = new EthFeeHistory(protocolSchedule, blockchain); + miningCoordinator = mock(MergeCoordinator.class); + when(miningCoordinator.getMinPriorityFeePerGas()).thenReturn(Wei.ONE); + + method = + new EthFeeHistory( + protocolSchedule, + blockchain, + miningCoordinator, + ImmutableApiConfiguration.builder().build()); } @Test @@ -121,12 +134,63 @@ public void allFieldsPresentForLatestBlock() { public void shouldComputeRewardsCorrectly() { // Define the percentiles of rewards we want to compute List rewardPercentiles = - Arrays.asList(0.0, 5.0, 10.0, 30.0, 31.0, 59.0, 60.0, 61.0, 100.0); + Arrays.asList(0.0, 5.0, 10.0, 27.50, 31.0, 59.0, 60.0, 61.0, 100.0); + + Block block = mock(Block.class); + Blockchain blockchain = mockBlockchainTransactionsWithPriorityFee(block); + + EthFeeHistory ethFeeHistory = + new EthFeeHistory( + null, blockchain, miningCoordinator, ImmutableApiConfiguration.builder().build()); + + List rewards = ethFeeHistory.computeRewards(rewardPercentiles, block); // Define the expected rewards for each percentile // The expected rewards match the fees of the transactions at each percentile in the // rewardPercentiles list - List expectedRewards = Stream.of(1, 1, 2, 5, 5, 6, 6, 7, 7).map(Wei::of).toList(); + List expectedRewards = Stream.of(1, 1, 2, 4, 5, 6, 6, 7, 7).map(Wei::of).toList(); + + // Check that the number of computed rewards is equal to the number of requested percentiles + assertThat(rewards.size()).isEqualTo(rewardPercentiles.size()); + assertThat(expectedRewards).isEqualTo(rewards); + } + + @Test + public void shouldBoundRewardsCorrectly() { + // This test checks that the rewards are correctly bounded by the lower and upper limits. + // The lower and upper limits are defined by the lowerBoundPriorityFeeCoefficient and + // upperBoundPriorityFeeCoefficient in the ApiConfiguration. + // The lower limit is 2.0 (Wei.One * 200L / 100) and the upper limit is 5.0 (Wei.One * 500L / + // 100). + // The rewards are computed for a list of percentiles, and the expected bounded rewards are + // defined for each percentile. + // The test checks that the computed rewards match the expected bounded rewards. + + List rewardPercentiles = + Arrays.asList(0.0, 5.0, 10.0, 27.50, 31.0, 59.0, 60.0, 61.0, 100.0); + + Block block = mock(Block.class); + Blockchain blockchain = mockBlockchainTransactionsWithPriorityFee(block); + + ApiConfiguration apiConfiguration = + ImmutableApiConfiguration.builder() + .isPriorityFeeLimitingEnabled(true) + .lowerBoundPriorityFeeCoefficient(200L) // Min reward = Wei.One * 200L / 100 = 2.0 + .upperBoundPriorityFeeCoefficient(500L) + .build(); // Max reward = Wei.One * 500L / 100 = 5.0 + + EthFeeHistory ethFeeHistory = + new EthFeeHistory(null, blockchain, miningCoordinator, apiConfiguration); + + List rewards = ethFeeHistory.computeRewards(rewardPercentiles, block); + + // Define the expected bounded rewards for each percentile + List expectedBoundedRewards = Stream.of(2, 2, 2, 4, 5, 5, 5, 5, 5).map(Wei::of).toList(); + assertThat(expectedBoundedRewards).isEqualTo(rewards); + } + + private Blockchain mockBlockchainTransactionsWithPriorityFee(final Block block) { + final Blockchain blockchain = mock(Blockchain.class); // Define a list of gas used and fee pairs. Each pair represents a transaction in the block. // The first number is the gas used by the transaction, and the second number the fee. @@ -141,21 +205,6 @@ public void shouldComputeRewardsCorrectly() { gasUsedAndFee.add(new Object[] {800, 7L}); // 100.0% Collections.shuffle(gasUsedAndFee); - Block block = mock(Block.class); - Blockchain blockchain = mockBlockchainTransactionsWithPriorityFee(gasUsedAndFee, block); - EthFeeHistory ethFeeHistory = new EthFeeHistory(null, blockchain); - - List rewards = ethFeeHistory.computeRewards(rewardPercentiles, block); - - // Check that the number of computed rewards is equal to the number of requested percentiles - assertThat(rewards.size()).isEqualTo(rewardPercentiles.size()); - assertThat(rewards).isEqualTo(expectedRewards); - } - - private Blockchain mockBlockchainTransactionsWithPriorityFee( - final List gasUsedAndFee, final Block block) { - final Blockchain blockchain = mock(Blockchain.class); - when(block.getHash()).thenReturn(Hash.wrap(Bytes32.wrap(Bytes.random(32)))); BlockBody body = mock(BlockBody.class); BlockHeader blockHeader = mock(BlockHeader.class); diff --git a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/AbstractMinerExecutor.java b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/AbstractMinerExecutor.java index 451af2df12b..ec66f2725ad 100644 --- a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/AbstractMinerExecutor.java +++ b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/AbstractMinerExecutor.java @@ -110,6 +110,10 @@ public Wei getMinTransactionGasPrice() { return miningParameters.getMinTransactionGasPrice(); } + public Wei getMinPriorityFeePerGas() { + return miningParameters.getMinPriorityFeePerGas(); + } + public abstract Optional
getCoinbase(); public void changeTargetGasLimit(final Long newTargetGasLimit) { diff --git a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/AbstractMiningCoordinator.java b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/AbstractMiningCoordinator.java index 43475bc58b6..6d87f1da7da 100644 --- a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/AbstractMiningCoordinator.java +++ b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/AbstractMiningCoordinator.java @@ -207,6 +207,11 @@ public Wei getMinTransactionGasPrice() { return executor.getMinTransactionGasPrice(); } + @Override + public Wei getMinPriorityFeePerGas() { + return executor.getMinPriorityFeePerGas(); + } + @Override public void setExtraData(final Bytes extraData) { executor.setExtraData(extraData); diff --git a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/MiningCoordinator.java b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/MiningCoordinator.java index 68353f7ae7e..4ab98f3ca9a 100644 --- a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/MiningCoordinator.java +++ b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/MiningCoordinator.java @@ -58,6 +58,8 @@ default void onPauseMining() {} Wei getMinTransactionGasPrice(); + Wei getMinPriorityFeePerGas(); + void setExtraData(Bytes extraData); default void setCoinbase(final Address coinbase) { diff --git a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/NoopMiningCoordinator.java b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/NoopMiningCoordinator.java index ab0a5c3d717..ea4f2c756f2 100644 --- a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/NoopMiningCoordinator.java +++ b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/NoopMiningCoordinator.java @@ -64,6 +64,11 @@ public Wei getMinTransactionGasPrice() { return miningParameters.getMinTransactionGasPrice(); } + @Override + public Wei getMinPriorityFeePerGas() { + return miningParameters.getMinPriorityFeePerGas(); + } + @Override public void setExtraData(final Bytes extraData) {} From 7feea547eb41621a26b17841154d86f0370e7982 Mon Sep 17 00:00:00 2001 From: David Lutzardo Date: Mon, 4 Dec 2023 15:36:06 +0100 Subject: [PATCH 03/28] [#5851] Add error messages on authentication failures with username and password (#6212) * Add error messages on authentication failures with username and password Signed-off-by: David Lutzardo * Add a constant for the 'password' Signed-off-by: David Lutzardo * Add test to check empty login and check response in body is not empty Signed-off-by: David Lutzardo * Correct format (spotless) Signed-off-by: David Lutzardo * Update ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceLoginTest.java Co-authored-by: Fabio Di Fabio Signed-off-by: David Lutzardo * Update ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceLoginTest.java Co-authored-by: Fabio Di Fabio Signed-off-by: David Lutzardo * Update JsonRpcHttpServiceLoginTest.java use containsIgnoringCase Signed-off-by: David Lutzardo * Add a CHANGELOG entry for PR 6212 Signed-off-by: David Lutzardo --------- Signed-off-by: David Lutzardo Co-authored-by: Fabio Di Fabio --- CHANGELOG.md | 1 + .../DefaultAuthenticationService.java | 11 +++++++---- .../api/jsonrpc/JsonRpcHttpServiceLoginTest.java | 14 ++++++++++++++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eaa028a84a0..f0a00eda376 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ - Add `rpc-gas-cap` to allow users to set gas limit to the RPC methods used to simulate transactions[#6156](https://github.com/hyperledger/besu/pull/6156) - Fix the unavailability of `address` field when returning an `Account` entity on GraphQL in case of unreachable world state [#6198](https://github.com/hyperledger/besu/pull/6198) - Update OpenJ9 Docker image to latest version [#6226](https://github.com/hyperledger/besu/pull/6226) +- Add error messages on authentication failures with username and password [#6212](https://github.com/hyperledger/besu/pull/6212) ### Bug fixes - Fix Docker image name clash between Besu and evmtool [#6194](https://github.com/hyperledger/besu/pull/6194) diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/authentication/DefaultAuthenticationService.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/authentication/DefaultAuthenticationService.java index 96a1a2d023f..89f747d1710 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/authentication/DefaultAuthenticationService.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/authentication/DefaultAuthenticationService.java @@ -46,6 +46,7 @@ public class DefaultAuthenticationService implements AuthenticationService { public static final String USERNAME = "username"; + public static final String PASSWORD = "password"; private final JWTAuth jwtAuthProvider; @VisibleForTesting public final JWTAuthOptions jwtAuthOptions; private final Optional credentialAuthProvider; @@ -171,19 +172,21 @@ private void login( final RoutingContext routingContext, final AuthenticationProvider credentialAuthProvider) { final JsonObject requestBody = routingContext.body().asJsonObject(); - if (requestBody == null) { + if (requestBody == null + || requestBody.getValue(USERNAME) == null + || requestBody.getValue(PASSWORD) == null) { routingContext .response() .setStatusCode(HttpResponseStatus.BAD_REQUEST.code()) .setStatusMessage(HttpResponseStatus.BAD_REQUEST.reasonPhrase()) - .end(); + .end("Authentication failed: username and password are required."); return; } // Check user final JsonObject authParams = new JsonObject(); authParams.put(USERNAME, requestBody.getValue(USERNAME)); - authParams.put("password", requestBody.getValue("password")); + authParams.put(PASSWORD, requestBody.getValue(PASSWORD)); final Credentials credentials = new UsernamePasswordCredentials(authParams); credentialAuthProvider.authenticate( @@ -194,7 +197,7 @@ private void login( .response() .setStatusCode(HttpResponseStatus.UNAUTHORIZED.code()) .setStatusMessage(HttpResponseStatus.UNAUTHORIZED.reasonPhrase()) - .end(); + .end("Authentication failed: the username or password is incorrect."); } else { final User user = r.result(); diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceLoginTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceLoginTest.java index a00e7ed7cb8..8d087bbd4e9 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceLoginTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceLoginTest.java @@ -203,6 +203,18 @@ public static void shutdownServer() { service.stop().join(); } + @Test + public void loginWithEmptyCredentials() throws IOException { + final RequestBody body = RequestBody.create("{}", JSON); + final Request request = new Request.Builder().post(body).url(baseUrl + "/login").build(); + try (final Response resp = client.newCall(request).execute()) { + assertThat(resp.code()).isEqualTo(400); + assertThat(resp.message()).isEqualTo("Bad Request"); + final String bodyString = resp.body().string(); + assertThat(bodyString).containsIgnoringCase("username and password are required"); + } + } + @Test public void loginWithBadCredentials() throws IOException { final RequestBody body = @@ -211,6 +223,8 @@ public void loginWithBadCredentials() throws IOException { try (final Response resp = client.newCall(request).execute()) { assertThat(resp.code()).isEqualTo(401); assertThat(resp.message()).isEqualTo("Unauthorized"); + final String bodyString = resp.body().string(); + assertThat(bodyString).containsIgnoringCase("the username or password is incorrect"); } } From e3db18e99f0a4e446cdc19a2ae5c4eccb7606be4 Mon Sep 17 00:00:00 2001 From: Simon Dudley Date: Tue, 5 Dec 2023 10:28:00 +1000 Subject: [PATCH 04/28] Add RockDB Subcommand for printing usage per column family (#6185) * Add RockDB Subcommand for printing usage per column family Signed-off-by: Simon Dudley * changed output to follow a MD table notation. Signed-off-by: Gabriel Fukushima --------- Signed-off-by: Gabriel Fukushima Co-authored-by: Gabriel Fukushima --- CHANGELOG.md | 1 + besu/build.gradle | 1 + .../storage/RocksDbSubCommand.java | 115 ++++++++++++++++++ .../storage/RocksDbUsageHelper.java | 105 ++++++++++++++++ .../storage/StorageSubCommand.java | 4 +- .../hyperledger/besu/crypto/KeyPairUtil.java | 1 + 6 files changed, 225 insertions(+), 2 deletions(-) create mode 100644 besu/src/main/java/org/hyperledger/besu/cli/subcommands/storage/RocksDbSubCommand.java create mode 100644 besu/src/main/java/org/hyperledger/besu/cli/subcommands/storage/RocksDbUsageHelper.java diff --git a/CHANGELOG.md b/CHANGELOG.md index f0a00eda376..7b2607eed4e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ - Fix the unavailability of `address` field when returning an `Account` entity on GraphQL in case of unreachable world state [#6198](https://github.com/hyperledger/besu/pull/6198) - Update OpenJ9 Docker image to latest version [#6226](https://github.com/hyperledger/besu/pull/6226) - Add error messages on authentication failures with username and password [#6212](https://github.com/hyperledger/besu/pull/6212) +- Add `rocksdb usage` to the `storage` subcommand to allow users and dev to check columns families usage [#6185](https://github.com/hyperledger/besu/pull/6185) ### Bug fixes - Fix Docker image name clash between Besu and evmtool [#6194](https://github.com/hyperledger/besu/pull/6194) diff --git a/besu/build.gradle b/besu/build.gradle index 9d72f50b021..fe5bb45c30d 100644 --- a/besu/build.gradle +++ b/besu/build.gradle @@ -77,6 +77,7 @@ dependencies { implementation 'org.springframework.security:spring-security-crypto' implementation 'org.xerial.snappy:snappy-java' implementation 'tech.pegasys:jc-kzg-4844' + implementation 'org.rocksdb:rocksdbjni' runtimeOnly 'org.apache.logging.log4j:log4j-jul' runtimeOnly 'com.splunk.logging:splunk-library-javalogging' diff --git a/besu/src/main/java/org/hyperledger/besu/cli/subcommands/storage/RocksDbSubCommand.java b/besu/src/main/java/org/hyperledger/besu/cli/subcommands/storage/RocksDbSubCommand.java new file mode 100644 index 00000000000..461175a2282 --- /dev/null +++ b/besu/src/main/java/org/hyperledger/besu/cli/subcommands/storage/RocksDbSubCommand.java @@ -0,0 +1,115 @@ +/* + * Copyright Hyperledger Besu Contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.cli.subcommands.storage; + +import static org.hyperledger.besu.controller.BesuController.DATABASE_PATH; + +import org.hyperledger.besu.cli.util.VersionProvider; + +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.List; + +import org.rocksdb.ColumnFamilyDescriptor; +import org.rocksdb.ColumnFamilyHandle; +import org.rocksdb.Options; +import org.rocksdb.RocksDB; +import org.rocksdb.RocksDBException; +import picocli.CommandLine; +import picocli.CommandLine.Command; +import picocli.CommandLine.ParentCommand; + +/** The RocksDB subcommand. */ +@Command( + name = "rocksdb", + description = "Print RocksDB information", + mixinStandardHelpOptions = true, + versionProvider = VersionProvider.class, + subcommands = {RocksDbSubCommand.RocksDbUsage.class}) +public class RocksDbSubCommand implements Runnable { + + @SuppressWarnings("unused") + @ParentCommand + private StorageSubCommand parentCommand; + + @SuppressWarnings("unused") + @CommandLine.Spec + private CommandLine.Model.CommandSpec spec; + + @Override + public void run() { + spec.commandLine().usage(System.out); + } + + @Command( + name = "usage", + description = "Print disk usage", + mixinStandardHelpOptions = true, + versionProvider = VersionProvider.class) + static class RocksDbUsage implements Runnable { + + @SuppressWarnings("unused") + @CommandLine.Spec + private CommandLine.Model.CommandSpec spec; + + @SuppressWarnings("unused") + @ParentCommand + private RocksDbSubCommand parentCommand; + + @Override + public void run() { + + final PrintWriter out = spec.commandLine().getOut(); + + final String dbPath = + parentCommand + .parentCommand + .parentCommand + .dataDir() + .toString() + .concat("/") + .concat(DATABASE_PATH); + + RocksDB.loadLibrary(); + Options options = new Options(); + options.setCreateIfMissing(true); + + // Open the RocksDB database with multiple column families + List cfNames; + try { + cfNames = RocksDB.listColumnFamilies(options, dbPath); + } catch (RocksDBException e) { + throw new RuntimeException(e); + } + final List cfHandles = new ArrayList<>(); + final List cfDescriptors = new ArrayList<>(); + for (byte[] cfName : cfNames) { + cfDescriptors.add(new ColumnFamilyDescriptor(cfName)); + } + RocksDbUsageHelper.printTableHeader(out); + try (final RocksDB rocksdb = RocksDB.openReadOnly(dbPath, cfDescriptors, cfHandles)) { + for (ColumnFamilyHandle cfHandle : cfHandles) { + RocksDbUsageHelper.printUsageForColumnFamily(rocksdb, cfHandle, out); + } + } catch (RocksDBException e) { + throw new RuntimeException(e); + } finally { + for (ColumnFamilyHandle cfHandle : cfHandles) { + cfHandle.close(); + } + } + } + } +} diff --git a/besu/src/main/java/org/hyperledger/besu/cli/subcommands/storage/RocksDbUsageHelper.java b/besu/src/main/java/org/hyperledger/besu/cli/subcommands/storage/RocksDbUsageHelper.java new file mode 100644 index 00000000000..4bfd9f42951 --- /dev/null +++ b/besu/src/main/java/org/hyperledger/besu/cli/subcommands/storage/RocksDbUsageHelper.java @@ -0,0 +1,105 @@ +/* + * Copyright contributors to Hyperledger Besu. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.hyperledger.besu.cli.subcommands.storage; + +import org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueSegmentIdentifier; + +import java.io.PrintWriter; + +import org.bouncycastle.util.Arrays; +import org.rocksdb.ColumnFamilyHandle; +import org.rocksdb.RocksDB; +import org.rocksdb.RocksDBException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** RocksDB Usage subcommand helper methods for formatting and printing. */ +public class RocksDbUsageHelper { + private static final Logger LOG = LoggerFactory.getLogger(RocksDbUsageHelper.class); + + static void printUsageForColumnFamily( + final RocksDB rocksdb, final ColumnFamilyHandle cfHandle, final PrintWriter out) + throws RocksDBException, NumberFormatException { + final String size = rocksdb.getProperty(cfHandle, "rocksdb.estimate-live-data-size"); + boolean emptyColumnFamily = false; + if (!size.isEmpty() && !size.isBlank()) { + try { + final long sizeLong = Long.parseLong(size); + final String totalSstFilesSize = + rocksdb.getProperty(cfHandle, "rocksdb.total-sst-files-size"); + final long totalSstFilesSizeLong = + !totalSstFilesSize.isEmpty() && !totalSstFilesSize.isBlank() + ? Long.parseLong(totalSstFilesSize) + : 0; + if (sizeLong == 0) { + emptyColumnFamily = true; + } + + if (!emptyColumnFamily) { + printLine( + out, + getNameById(cfHandle.getName()), + rocksdb.getProperty(cfHandle, "rocksdb.estimate-num-keys"), + formatOutputSize(sizeLong), + formatOutputSize(totalSstFilesSizeLong)); + } + } catch (NumberFormatException e) { + LOG.error("Failed to parse string into long: " + e.getMessage()); + } + } + } + + private static String formatOutputSize(final long size) { + if (size > (1024 * 1024 * 1024)) { + long sizeInGiB = size / (1024 * 1024 * 1024); + return sizeInGiB + " GiB"; + } else if (size > (1024 * 1024)) { + long sizeInMiB = size / (1024 * 1024); + return sizeInMiB + " MiB"; + } else if (size > 1024) { + long sizeInKiB = size / 1024; + return sizeInKiB + " KiB"; + } else { + return size + " B"; + } + } + + private static String getNameById(final byte[] id) { + for (KeyValueSegmentIdentifier segment : KeyValueSegmentIdentifier.values()) { + if (Arrays.areEqual(segment.getId(), id)) { + return segment.getName(); + } + } + return null; // id not found + } + + static void printTableHeader(final PrintWriter out) { + out.format( + "| Column Family | Keys | Column Size | SST Files Size |\n"); + out.format( + "|--------------------------------|-----------------|--------------|-----------------|\n"); + } + + static void printLine( + final PrintWriter out, + final String cfName, + final String keys, + final String columnSize, + final String sstFilesSize) { + final String format = "| %-30s | %-15s | %-12s | %-15s |\n"; + out.format(format, cfName, keys, columnSize, sstFilesSize); + } +} diff --git a/besu/src/main/java/org/hyperledger/besu/cli/subcommands/storage/StorageSubCommand.java b/besu/src/main/java/org/hyperledger/besu/cli/subcommands/storage/StorageSubCommand.java index bd40a42a431..e46ffde2739 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/subcommands/storage/StorageSubCommand.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/subcommands/storage/StorageSubCommand.java @@ -45,7 +45,7 @@ description = "This command provides storage related actions.", mixinStandardHelpOptions = true, versionProvider = VersionProvider.class, - subcommands = {StorageSubCommand.RevertVariablesStorage.class}) + subcommands = {StorageSubCommand.RevertVariablesStorage.class, RocksDbSubCommand.class}) public class StorageSubCommand implements Runnable { /** The constant COMMAND_NAME. */ @@ -53,7 +53,7 @@ public class StorageSubCommand implements Runnable { @SuppressWarnings("unused") @ParentCommand - private BesuCommand parentCommand; + BesuCommand parentCommand; @SuppressWarnings("unused") @Spec diff --git a/crypto/algorithms/src/main/java/org/hyperledger/besu/crypto/KeyPairUtil.java b/crypto/algorithms/src/main/java/org/hyperledger/besu/crypto/KeyPairUtil.java index f20b1b37103..013b385c3c2 100644 --- a/crypto/algorithms/src/main/java/org/hyperledger/besu/crypto/KeyPairUtil.java +++ b/crypto/algorithms/src/main/java/org/hyperledger/besu/crypto/KeyPairUtil.java @@ -84,6 +84,7 @@ public static KeyPair loadKeyPair(final File keyFile) { final KeyPair key; if (keyFile.exists()) { + LOG.info("Attempting to load public key from {}", keyFile.getAbsolutePath()); key = load(keyFile); LOG.info( "Loaded public key {} from {}", key.getPublicKey().toString(), keyFile.getAbsolutePath()); From ee810eb00f580f1649afaf3e9b783a5e85c6044c Mon Sep 17 00:00:00 2001 From: Stefan Pingel <16143240+pinges@users.noreply.github.com> Date: Tue, 5 Dec 2023 16:17:54 +1000 Subject: [PATCH 05/28] revert (#6232) Signed-off-by: stefan.pingel@consensys.net --- .../besu/ethereum/eth/manager/EthPeers.java | 4 +- .../ethereum/eth/manager/PeerReputation.java | 50 +++++-------------- .../eth/manager/PeerReputationTest.java | 9 ---- 3 files changed, 15 insertions(+), 48 deletions(-) diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthPeers.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthPeers.java index 36f57b15686..a5af86551bb 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthPeers.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthPeers.java @@ -197,7 +197,7 @@ private boolean registerDisconnect( disconnectCallbacks.forEach(callback -> callback.onDisconnect(peer)); peer.handleDisconnect(); abortPendingRequestsAssignedToDisconnectedPeers(); - LOG.debug("Disconnected EthPeer {}...", peer.getShortNodeId()); + LOG.debug("Disconnected EthPeer {}", peer.getShortNodeId()); LOG.trace("Disconnected EthPeer {}", peer); } } @@ -391,7 +391,7 @@ public void disconnectWorstUselessPeer() { peer -> { LOG.atDebug() .setMessage( - "disconnecting peer {}... Waiting for better peers. Current {} of max {}") + "disconnecting peer {}. Waiting for better peers. Current {} of max {}") .addArgument(peer::getShortNodeId) .addArgument(this::peerCount) .addArgument(this::getMaxPeers) diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/PeerReputation.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/PeerReputation.java index ff7617b0f46..e4c263ea783 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/PeerReputation.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/PeerReputation.java @@ -34,13 +34,10 @@ public class PeerReputation implements Comparable { static final long USELESS_RESPONSE_WINDOW_IN_MILLIS = TimeUnit.MILLISECONDS.convert(1, TimeUnit.MINUTES); - static final int DEFAULT_MAX_SCORE = 200; - // how much above the initial score you need to be to not get disconnected for timeouts/useless - // responses - private final int hasBeenUsefulThreshold; + static final int DEFAULT_MAX_SCORE = 150; static final int DEFAULT_INITIAL_SCORE = 100; private static final Logger LOG = LoggerFactory.getLogger(PeerReputation.class); - private static final int TIMEOUT_THRESHOLD = 5; + private static final int TIMEOUT_THRESHOLD = 3; private static final int USELESS_RESPONSE_THRESHOLD = 5; private final ConcurrentMap timeoutCountByRequestType = @@ -48,7 +45,8 @@ public class PeerReputation implements Comparable { private final Queue uselessResponseTimes = new ConcurrentLinkedQueue<>(); private static final int SMALL_ADJUSTMENT = 1; - private static final int LARGE_ADJUSTMENT = 5; + private static final int LARGE_ADJUSTMENT = 10; + private int score; private final int maxScore; @@ -61,37 +59,22 @@ public PeerReputation(final int initialScore, final int maxScore) { checkArgument( initialScore <= maxScore, "Initial score must be less than or equal to max score"); this.maxScore = maxScore; - this.hasBeenUsefulThreshold = Math.min(maxScore, initialScore + 10); this.score = initialScore; } public Optional recordRequestTimeout(final int requestCode) { final int newTimeoutCount = getOrCreateTimeoutCount(requestCode).incrementAndGet(); if (newTimeoutCount >= TIMEOUT_THRESHOLD) { - score -= LARGE_ADJUSTMENT; - // don't trigger disconnect if this peer has a sufficiently high reputation score - if (peerHasNotBeenUseful()) { - LOG.debug( - "Disconnection triggered by {} repeated timeouts for requestCode {}, peer score {}", - newTimeoutCount, - requestCode, - score); - return Optional.of(DisconnectReason.TIMEOUT); - } - - LOG.trace( - "Not triggering disconnect for {} repeated timeouts for requestCode {} because peer has high score {}", + LOG.debug( + "Disconnection triggered by {} repeated timeouts for requestCode {}", newTimeoutCount, - requestCode, - score); + requestCode); + score -= LARGE_ADJUSTMENT; + return Optional.of(DisconnectReason.TIMEOUT); } else { score -= SMALL_ADJUSTMENT; + return Optional.empty(); } - return Optional.empty(); - } - - private boolean peerHasNotBeenUseful() { - return score < hasBeenUsefulThreshold; } public void resetTimeoutCount(final int requestCode) { @@ -113,19 +96,12 @@ public Optional recordUselessResponse(final long timestamp) { } if (uselessResponseTimes.size() >= USELESS_RESPONSE_THRESHOLD) { score -= LARGE_ADJUSTMENT; - // don't trigger disconnect if this peer has a sufficiently high reputation score - if (peerHasNotBeenUseful()) { - LOG.debug( - "Disconnection triggered by exceeding useless response threshold, score {}", score); - return Optional.of(DisconnectReason.USELESS_PEER); - } - LOG.trace( - "Not triggering disconnect for exceeding useless response threshold because peer has high score {}", - score); + LOG.debug("Disconnection triggered by exceeding useless response threshold"); + return Optional.of(DisconnectReason.USELESS_PEER); } else { score -= SMALL_ADJUSTMENT; + return Optional.empty(); } - return Optional.empty(); } public void recordUsefulResponse() { diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/PeerReputationTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/PeerReputationTest.java index f49abee8bb9..9706369a069 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/PeerReputationTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/PeerReputationTest.java @@ -36,8 +36,6 @@ public void shouldThrowOnInvalidInitialScore() { @Test public void shouldOnlyDisconnectWhenTimeoutLimitReached() { - assertThat(reputation.recordRequestTimeout(EthPV62.GET_BLOCK_HEADERS)).isEmpty(); - assertThat(reputation.recordRequestTimeout(EthPV62.GET_BLOCK_HEADERS)).isEmpty(); assertThat(reputation.recordRequestTimeout(EthPV62.GET_BLOCK_HEADERS)).isEmpty(); assertThat(reputation.recordRequestTimeout(EthPV62.GET_BLOCK_HEADERS)).isEmpty(); assertThat(reputation.recordRequestTimeout(EthPV62.GET_BLOCK_HEADERS)).contains(TIMEOUT); @@ -47,11 +45,6 @@ public void shouldOnlyDisconnectWhenTimeoutLimitReached() { public void shouldTrackTimeoutsSeparatelyForDifferentRequestTypes() { assertThat(reputation.recordRequestTimeout(EthPV62.GET_BLOCK_HEADERS)).isEmpty(); assertThat(reputation.recordRequestTimeout(EthPV62.GET_BLOCK_HEADERS)).isEmpty(); - assertThat(reputation.recordRequestTimeout(EthPV62.GET_BLOCK_HEADERS)).isEmpty(); - assertThat(reputation.recordRequestTimeout(EthPV62.GET_BLOCK_HEADERS)).isEmpty(); - - assertThat(reputation.recordRequestTimeout(EthPV62.GET_BLOCK_BODIES)).isEmpty(); - assertThat(reputation.recordRequestTimeout(EthPV62.GET_BLOCK_BODIES)).isEmpty(); assertThat(reputation.recordRequestTimeout(EthPV62.GET_BLOCK_BODIES)).isEmpty(); assertThat(reputation.recordRequestTimeout(EthPV62.GET_BLOCK_BODIES)).isEmpty(); @@ -64,8 +57,6 @@ public void shouldResetTimeoutCountForRequestType() { assertThat(reputation.recordRequestTimeout(EthPV62.GET_BLOCK_HEADERS)).isEmpty(); assertThat(reputation.recordRequestTimeout(EthPV62.GET_BLOCK_HEADERS)).isEmpty(); - assertThat(reputation.recordRequestTimeout(EthPV62.GET_BLOCK_BODIES)).isEmpty(); - assertThat(reputation.recordRequestTimeout(EthPV62.GET_BLOCK_BODIES)).isEmpty(); assertThat(reputation.recordRequestTimeout(EthPV62.GET_BLOCK_BODIES)).isEmpty(); assertThat(reputation.recordRequestTimeout(EthPV62.GET_BLOCK_BODIES)).isEmpty(); From c2578638d1344a4172f1028dabda17655354168f Mon Sep 17 00:00:00 2001 From: Fabio Di Fabio Date: Tue, 5 Dec 2023 14:11:19 +0100 Subject: [PATCH 06/28] Update Gradle verification metadata (#6236) Signed-off-by: Fabio Di Fabio --- gradle/verification-metadata.xml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/gradle/verification-metadata.xml b/gradle/verification-metadata.xml index 99ff1238216..01ea0e02269 100644 --- a/gradle/verification-metadata.xml +++ b/gradle/verification-metadata.xml @@ -3989,6 +3989,11 @@ + + + + + @@ -4082,6 +4087,11 @@ + + + + + From c2d1b7de557ba149c0793768bffaad2811debce2 Mon Sep 17 00:00:00 2001 From: Fabio Di Fabio Date: Tue, 5 Dec 2023 17:40:52 +0100 Subject: [PATCH 07/28] Deprecation warning if Forest pruning is enabled (#6230) Signed-off-by: Fabio Di Fabio --- CHANGELOG.md | 13 +++++++++++++ .../org/hyperledger/besu/cli/BesuCommand.java | 5 +++++ .../org/hyperledger/besu/cli/BesuCommandTest.java | 15 +++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b2607eed4e..927fbf2f90d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,18 @@ # Changelog +## 23.10.4 + +### Breaking Changes + +### Deprecations +- Forest pruning (`pruning-enabled` options) is deprecated and will be removed soon. To save disk space consider switching to Bonsai data storage format [#6230](https://github.com/hyperledger/besu/pull/6230) + +### Additions and Improvements +- Add error messages on authentication failures with username and password [#6212](https://github.com/hyperledger/besu/pull/6212) + +### Bug fixes + + ## 23.10.3 ### Breaking Changes diff --git a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java index 91ef840d62e..a4045cee1c5 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java @@ -2059,6 +2059,11 @@ private void issueOptionWarnings() { "--privacy-onchain-groups-enabled", "--privacy-flexible-groups-enabled"); } + + if (isPruningEnabled()) { + logger.warn( + "Forest pruning is deprecated and will be removed soon. To save disk space consider switching to Bonsai data storage format."); + } } private void configure() throws Exception { diff --git a/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java b/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java index 85586871483..0df397af71f 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java @@ -3815,6 +3815,21 @@ public void pruningParametersAreCaptured() throws Exception { assertThat(pruningArg.getValue().getBlockConfirmations()).isEqualTo(4); } + @Test + public void pruningLogsDeprecationWarning() { + parseCommand("--pruning-enabled"); + + verify(mockControllerBuilder).isPruningEnabled(true); + + assertThat(commandOutput.toString(UTF_8)).isEmpty(); + assertThat(commandErrorOutput.toString(UTF_8)).isEmpty(); + verify(mockLogger) + .warn( + contains( + "Forest pruning is deprecated and will be removed soon." + + " To save disk space consider switching to Bonsai data storage format.")); + } + @Test public void devModeOptionMustBeUsed() throws Exception { parseCommand("--network", "dev"); From eeebe4da2752b16412593235c3b22a17d62206ab Mon Sep 17 00:00:00 2001 From: Fabio Di Fabio Date: Tue, 5 Dec 2023 23:35:33 +0100 Subject: [PATCH 08/28] Fix the annoying "Errors occurred while build effective model" during builds (#6241) Signed-off-by: Fabio Di Fabio --- gradle/versions.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/gradle/versions.gradle b/gradle/versions.gradle index 34a56730ee0..f239370ab7a 100644 --- a/gradle/versions.gradle +++ b/gradle/versions.gradle @@ -15,6 +15,7 @@ dependencyManagement { dependencies { + applyMavenExclusions = false dependencySet(group: 'org.antlr', version: '4.11.1') { entry 'antlr4' From 254dd6d8c09efd7f01982499993a6eecb53cfd3b Mon Sep 17 00:00:00 2001 From: Gabriel Fukushima Date: Wed, 6 Dec 2023 17:28:33 +1100 Subject: [PATCH 09/28] Run ATs sequentially (#6244) Signed-off-by: Gabriel Fukushima --- .circleci/config.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index d91ccb64d0a..bff2f447944 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -424,9 +424,11 @@ workflows: - acceptanceTestsCliqueBft: requires: - assemble + - acceptanceTests - acceptanceTestsPermissioning: requires: - assemble + - acceptanceTestsCliqueBft - buildDocker: requires: - assemble From 9aaaf79c594480d0acc8d26de4558cb1cc3fc705 Mon Sep 17 00:00:00 2001 From: delehef Date: Wed, 6 Dec 2023 13:06:17 +0100 Subject: [PATCH 10/28] fix: double calls to trace{Start,End}Transaction (#6247) Signed-off-by: delehef --- .../hyperledger/besu/services/TraceServiceImpl.java | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/besu/src/main/java/org/hyperledger/besu/services/TraceServiceImpl.java b/besu/src/main/java/org/hyperledger/besu/services/TraceServiceImpl.java index 98c233197f3..02fff10d2fb 100644 --- a/besu/src/main/java/org/hyperledger/besu/services/TraceServiceImpl.java +++ b/besu/src/main/java/org/hyperledger/besu/services/TraceServiceImpl.java @@ -212,7 +212,6 @@ private List trace( .orElse(BlobGas.ZERO)); final WorldUpdater worldUpdater = chainUpdater.getNextUpdater(); - tracer.traceStartTransaction(worldUpdater, transaction); final TransactionProcessingResult result = transactionProcessor.processTransaction( blockchain, @@ -225,16 +224,6 @@ private List trace( false, blobGasPrice); - long transactionGasUsed = transaction.getGasLimit() - result.getGasRemaining(); - tracer.traceEndTransaction( - worldUpdater, - transaction, - result.isSuccessful(), - result.getOutput(), - result.getLogs(), - transactionGasUsed, - 0); - results.add(result); }); From c4fce130208cf413bab8811b91289d921019acda Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Thu, 7 Dec 2023 07:43:22 +1000 Subject: [PATCH 11/28] migrate to junit5 (#6234) Signed-off-by: Sally MacFarlane --- crypto/algorithms/build.gradle | 1 - .../org/hyperledger/besu/crypto/ECPointUtilTest.java | 2 +- .../java/org/hyperledger/besu/crypto/HashTest.java | 2 +- .../java/org/hyperledger/besu/crypto/KeyPairTest.java | 6 +++--- .../org/hyperledger/besu/crypto/KeyPairUtilTest.java | 2 +- .../org/hyperledger/besu/crypto/SECP256K1Test.java | 10 +++++----- .../org/hyperledger/besu/crypto/SECP256R1Test.java | 10 +++++----- .../hyperledger/besu/crypto/SECPPrivateKeyTest.java | 6 +++--- .../org/hyperledger/besu/crypto/SECPPublicKeyTest.java | 6 +++--- .../org/hyperledger/besu/crypto/SECPSignatureTest.java | 6 +++--- .../besu/crypto/SignatureAlgorithmFactoryTest.java | 6 +++--- .../besu/crypto/SignatureAlgorithmTypeTest.java | 2 +- .../besu/crypto/altbn128/AltBn128Fq12PairerTest.java | 2 +- .../besu/crypto/altbn128/AltBn128Fq12PointTest.java | 2 +- .../besu/crypto/altbn128/AltBn128Fq2PointTest.java | 2 +- .../besu/crypto/altbn128/AltBn128PointTest.java | 2 +- .../org/hyperledger/besu/crypto/altbn128/Fq12Test.java | 2 +- .../org/hyperledger/besu/crypto/altbn128/Fq2Test.java | 2 +- .../org/hyperledger/besu/crypto/altbn128/FqTest.java | 2 +- 19 files changed, 36 insertions(+), 37 deletions(-) diff --git a/crypto/algorithms/build.gradle b/crypto/algorithms/build.gradle index dcddb83be34..190ecae4a21 100644 --- a/crypto/algorithms/build.gradle +++ b/crypto/algorithms/build.gradle @@ -40,7 +40,6 @@ dependencies { implementation 'org.hyperledger.besu:blake2bf' implementation 'com.google.guava:guava' - testImplementation 'junit:junit' testImplementation 'org.assertj:assertj-core' testImplementation 'org.junit.jupiter:junit-jupiter' diff --git a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/ECPointUtilTest.java b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/ECPointUtilTest.java index ac95635ef1e..ff802516575 100644 --- a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/ECPointUtilTest.java +++ b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/ECPointUtilTest.java @@ -20,7 +20,7 @@ import java.security.spec.ECPoint; import org.apache.tuweni.bytes.Bytes; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class ECPointUtilTest { diff --git a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/HashTest.java b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/HashTest.java index a2d8318e120..bc71c0c1530 100644 --- a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/HashTest.java +++ b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/HashTest.java @@ -19,7 +19,7 @@ import org.apache.tuweni.bytes.Bytes; import org.bouncycastle.util.encoders.Hex; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class HashTest { diff --git a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/KeyPairTest.java b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/KeyPairTest.java index a8c1ac7e8f0..4155d2c5a4d 100644 --- a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/KeyPairTest.java +++ b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/KeyPairTest.java @@ -28,8 +28,8 @@ import org.bouncycastle.asn1.x9.X9ECParameters; import org.bouncycastle.crypto.params.ECDomainParameters; import org.bouncycastle.jce.provider.BouncyCastleProvider; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; public class KeyPairTest { public static final String ALGORITHM = SignatureAlgorithm.ALGORITHM; @@ -39,7 +39,7 @@ public class KeyPairTest { public static KeyPairGenerator keyPairGenerator; public static ECDomainParameters curve; - @BeforeClass + @BeforeAll public static void setUp() { Security.addProvider(new BouncyCastleProvider()); diff --git a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/KeyPairUtilTest.java b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/KeyPairUtilTest.java index 13c78d52bdc..cc2bcb0f460 100644 --- a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/KeyPairUtilTest.java +++ b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/KeyPairUtilTest.java @@ -19,7 +19,7 @@ import java.io.File; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class KeyPairUtilTest { diff --git a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/SECP256K1Test.java b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/SECP256K1Test.java index 060bdad844b..28fb0fb4f1c 100644 --- a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/SECP256K1Test.java +++ b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/SECP256K1Test.java @@ -28,9 +28,9 @@ import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.bytes.Bytes32; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class SECP256K1Test { @@ -39,7 +39,7 @@ public class SECP256K1Test { protected static String suiteStartTime = null; protected static String suiteName = null; - @BeforeClass + @BeforeAll public static void setTestSuiteStartTime() { suiteStartTime = LocalDateTime.now(ZoneId.systemDefault()) @@ -47,7 +47,7 @@ public static void setTestSuiteStartTime() { suiteName(SECP256K1Test.class); } - @Before + @BeforeEach public void setUp() { secp256K1 = new SECP256K1(); } diff --git a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/SECP256R1Test.java b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/SECP256R1Test.java index bd791ef9be3..26e03e5bd3c 100644 --- a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/SECP256R1Test.java +++ b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/SECP256R1Test.java @@ -29,9 +29,9 @@ import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.bytes.Bytes32; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class SECP256R1Test { @@ -103,7 +103,7 @@ public class SECP256R1Test { protected static String suiteStartTime = null; protected static String suiteName = null; - @BeforeClass + @BeforeAll public static void setTestSuiteStartTime() { suiteStartTime = LocalDateTime.now(ZoneId.systemDefault()) @@ -113,7 +113,7 @@ public static void setTestSuiteStartTime() { SignatureAlgorithmFactory.setInstance(SignatureAlgorithmType.create("secp256r1")); } - @Before + @BeforeEach public void setUp() { secp256R1 = new SECP256R1(); } diff --git a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/SECPPrivateKeyTest.java b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/SECPPrivateKeyTest.java index d99d4940915..24fbdb05288 100644 --- a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/SECPPrivateKeyTest.java +++ b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/SECPPrivateKeyTest.java @@ -29,8 +29,8 @@ import org.bouncycastle.asn1.sec.SECNamedCurves; import org.bouncycastle.asn1.x9.X9ECParameters; import org.bouncycastle.crypto.params.ECDomainParameters; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; public class SECPPrivateKeyTest { public static final String ALGORITHM = SignatureAlgorithm.ALGORITHM; @@ -40,7 +40,7 @@ public class SECPPrivateKeyTest { protected static String suiteName = null; public static ECDomainParameters curve; - @BeforeClass + @BeforeAll public static void setUp() { suiteStartTime = LocalDateTime.now(ZoneId.systemDefault()) diff --git a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/SECPPublicKeyTest.java b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/SECPPublicKeyTest.java index e5e9e6bb3a0..fe6e08404d5 100644 --- a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/SECPPublicKeyTest.java +++ b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/SECPPublicKeyTest.java @@ -24,8 +24,8 @@ import org.bouncycastle.asn1.sec.SECNamedCurves; import org.bouncycastle.asn1.x9.X9ECParameters; import org.bouncycastle.crypto.params.ECDomainParameters; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class SECPPublicKeyTest { public static final String ALGORITHM = SignatureAlgorithm.ALGORITHM; @@ -33,7 +33,7 @@ public class SECPPublicKeyTest { public ECDomainParameters curve; - @Before + @BeforeEach public void setUp() { final X9ECParameters params = SECNamedCurves.getByName(CURVE_NAME); curve = new ECDomainParameters(params.getCurve(), params.getG(), params.getN(), params.getH()); diff --git a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/SECPSignatureTest.java b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/SECPSignatureTest.java index a737a93f0b1..4298f662067 100644 --- a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/SECPSignatureTest.java +++ b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/SECPSignatureTest.java @@ -22,15 +22,15 @@ import org.bouncycastle.asn1.sec.SECNamedCurves; import org.bouncycastle.asn1.x9.X9ECParameters; import org.bouncycastle.crypto.params.ECDomainParameters; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; public class SECPSignatureTest { public static final String CURVE_NAME = "secp256k1"; public static BigInteger curveOrder; - @BeforeClass + @BeforeAll public static void setUp() { final X9ECParameters params = SECNamedCurves.getByName(CURVE_NAME); final ECDomainParameters curve = diff --git a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/SignatureAlgorithmFactoryTest.java b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/SignatureAlgorithmFactoryTest.java index 38c71c99db8..cabdaa7668a 100644 --- a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/SignatureAlgorithmFactoryTest.java +++ b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/SignatureAlgorithmFactoryTest.java @@ -17,12 +17,12 @@ import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class SignatureAlgorithmFactoryTest { - @Before + @BeforeEach public void setUp() { SignatureAlgorithmFactory.resetInstance(); } diff --git a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/SignatureAlgorithmTypeTest.java b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/SignatureAlgorithmTypeTest.java index faa0b5eeda7..13b37a05612 100644 --- a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/SignatureAlgorithmTypeTest.java +++ b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/SignatureAlgorithmTypeTest.java @@ -17,7 +17,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class SignatureAlgorithmTypeTest { @Test diff --git a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/altbn128/AltBn128Fq12PairerTest.java b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/altbn128/AltBn128Fq12PairerTest.java index 18da8a44fcb..d88c54269fe 100644 --- a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/altbn128/AltBn128Fq12PairerTest.java +++ b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/altbn128/AltBn128Fq12PairerTest.java @@ -18,7 +18,7 @@ import java.math.BigInteger; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Adapted from the pc_ecc (Apache 2 License) implementation: diff --git a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/altbn128/AltBn128Fq12PointTest.java b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/altbn128/AltBn128Fq12PointTest.java index 75f153e814a..0a57b76ff0f 100644 --- a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/altbn128/AltBn128Fq12PointTest.java +++ b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/altbn128/AltBn128Fq12PointTest.java @@ -18,7 +18,7 @@ import java.math.BigInteger; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Adapted from the pc_ecc (Apache 2 License) implementation: diff --git a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/altbn128/AltBn128Fq2PointTest.java b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/altbn128/AltBn128Fq2PointTest.java index 56c925a5647..5d0871505f4 100644 --- a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/altbn128/AltBn128Fq2PointTest.java +++ b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/altbn128/AltBn128Fq2PointTest.java @@ -18,7 +18,7 @@ import java.math.BigInteger; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Adapted from the pc_ecc (Apache 2 License) implementation: diff --git a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/altbn128/AltBn128PointTest.java b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/altbn128/AltBn128PointTest.java index 5794753c4a7..9f0a783a583 100644 --- a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/altbn128/AltBn128PointTest.java +++ b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/altbn128/AltBn128PointTest.java @@ -18,7 +18,7 @@ import java.math.BigInteger; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Adapted from the pc_ecc (Apache 2 License) implementation: diff --git a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/altbn128/Fq12Test.java b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/altbn128/Fq12Test.java index fb806866afe..081bcadf207 100644 --- a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/altbn128/Fq12Test.java +++ b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/altbn128/Fq12Test.java @@ -16,7 +16,7 @@ import static org.assertj.core.api.Assertions.assertThat; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Adapted from the pc_ecc (Apache 2 License) implementation: diff --git a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/altbn128/Fq2Test.java b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/altbn128/Fq2Test.java index 6f3bc862ba9..9164657387e 100644 --- a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/altbn128/Fq2Test.java +++ b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/altbn128/Fq2Test.java @@ -18,7 +18,7 @@ import java.math.BigInteger; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Adapted from the pc_ecc (Apache 2 License) implementation: diff --git a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/altbn128/FqTest.java b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/altbn128/FqTest.java index 8eab290be31..8752cb14d1a 100644 --- a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/altbn128/FqTest.java +++ b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/altbn128/FqTest.java @@ -18,7 +18,7 @@ import java.math.BigInteger; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Adapted from the pc_ecc (Apache 2 License) implementation: From 017f9aa2243ffdf1ee1635674ef3f4ea981c8233 Mon Sep 17 00:00:00 2001 From: garyschulte Date: Wed, 6 Dec 2023 15:39:20 -0800 Subject: [PATCH 12/28] fixes for problems discovered in main (#6248) Signed-off-by: garyschulte --- besu/src/test/java/org/hyperledger/besu/PrivacyTest.java | 2 +- docker/openjdk-17-debug/Dockerfile | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/besu/src/test/java/org/hyperledger/besu/PrivacyTest.java b/besu/src/test/java/org/hyperledger/besu/PrivacyTest.java index c71d44284fb..038dcdedd1f 100644 --- a/besu/src/test/java/org/hyperledger/besu/PrivacyTest.java +++ b/besu/src/test/java/org/hyperledger/besu/PrivacyTest.java @@ -68,7 +68,7 @@ public class PrivacyTest { private final Vertx vertx = Vertx.vertx(); - @TempDir private static Path dataDir; + @TempDir private Path dataDir; @AfterEach public void cleanUp() { diff --git a/docker/openjdk-17-debug/Dockerfile b/docker/openjdk-17-debug/Dockerfile index a8e2276209b..c08f1ea4b9f 100644 --- a/docker/openjdk-17-debug/Dockerfile +++ b/docker/openjdk-17-debug/Dockerfile @@ -35,11 +35,9 @@ ENV BESU_GRAPHQL_HTTP_HOST 0.0.0.0 ENV BESU_METRICS_HOST 0.0.0.0 ENV BESU_JMX_HOST 0.0.0.0 ENV BESU_PID_PATH "/tmp/pid" -ENV BESU_HOST_ALLOWLIST "*" #debug options for maximum observability ENV BESU_LOGGING "INFO" -ENV BESU_RPC_HTTP_API "ETH,NET,TRACE,DEBUG,ADMIN,TXPOOL" ENV JDWP_OPTS "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005" ENV JAVA_OPTS "${JDWP_OPTS} " From 4cc2eed4e6783f94b21cdf7790d915e1377168d4 Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Thu, 7 Dec 2023 12:05:45 +1000 Subject: [PATCH 13/28] Pki - migrate to junit 5 (#6235) * migrate to junit5 Signed-off-by: Sally MacFarlane * fix: double calls to trace{Start,End}Transaction (#6247) Signed-off-by: Franklin Delehelle * migrate to junit5 (#6234) Signed-off-by: Sally MacFarlane * fixes for problems discovered in main (#6248) Signed-off-by: garyschulte * fixed test comparing size of collection Signed-off-by: Sally MacFarlane --------- Signed-off-by: Sally MacFarlane Signed-off-by: Franklin Delehelle Signed-off-by: garyschulte Co-authored-by: delehef Co-authored-by: garyschulte --- pki/build.gradle | 3 +- .../pki/cms/CmsCreationAndValidationTest.java | 26 ++- .../keystore/BaseKeyStoreFileWrapperTest.java | 166 +++++++++++------- .../HardwareKeyStoreFileWrapperTest.java | 48 +++-- .../keystore/HardwareKeyStoreWrapperTest.java | 23 +-- .../SoftwareKeyStoreFileWrapperTest.java | 22 +-- .../keystore/SoftwareKeyStoreWrapperTest.java | 39 ++-- 7 files changed, 172 insertions(+), 155 deletions(-) diff --git a/pki/build.gradle b/pki/build.gradle index c9021b3a83e..8e2f52a4735 100644 --- a/pki/build.gradle +++ b/pki/build.gradle @@ -34,10 +34,9 @@ dependencies { implementation 'io.tmio:tuweni-bytes' implementation 'org.bouncycastle:bcpkix-jdk18on' - testImplementation 'junit:junit' - testImplementation 'org.assertj:assertj-core' testImplementation 'org.junit.jupiter:junit-jupiter' testImplementation 'org.mockito:mockito-core' + testImplementation 'org.mockito:mockito-junit-jupiter' testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' } diff --git a/pki/src/test/java/org/hyperledger/besu/pki/cms/CmsCreationAndValidationTest.java b/pki/src/test/java/org/hyperledger/besu/pki/cms/CmsCreationAndValidationTest.java index ceb30e1e00f..2daf9b576be 100644 --- a/pki/src/test/java/org/hyperledger/besu/pki/cms/CmsCreationAndValidationTest.java +++ b/pki/src/test/java/org/hyperledger/besu/pki/cms/CmsCreationAndValidationTest.java @@ -15,9 +15,10 @@ package org.hyperledger.besu.pki.cms; -import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.hyperledger.besu.pki.util.TestCertificateUtils.Algorithm.EC; import static org.hyperledger.besu.pki.util.TestCertificateUtils.Algorithm.RSA; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import org.hyperledger.besu.pki.util.TestCertificateUtils.Algorithm; @@ -56,8 +57,7 @@ private CmsTestKeystores getCmsTestKeystores(final Algorithm algorithm) { public void cmsValidationWithEmptyCmsMessage(final Algorithm algorithm) { final Bytes data = Bytes.random(32); - assertThat(getCmsTestKeystores(algorithm).getCmsValidator().validate(Bytes.EMPTY, data)) - .isFalse(); + assertFalse(getCmsTestKeystores(algorithm).getCmsValidator().validate(Bytes.EMPTY, data)); } @ParameterizedTest @@ -69,7 +69,7 @@ public void cmsValidationWithTrustedSelfSignedCertificate(final Algorithm algori final Bytes cms = cmsCreator.create(data); - assertThat(getCmsTestKeystores(algorithm).getCmsValidator().validate(cms, data)).isTrue(); + assertTrue(getCmsTestKeystores(algorithm).getCmsValidator().validate(cms, data)); } @ParameterizedTest @@ -81,7 +81,7 @@ public void cmsValidationWithUntrustedSelfSignedCertificate(final Algorithm algo final Bytes cms = cmsCreator.create(data); - assertThat(getCmsTestKeystores(algorithm).getCmsValidator().validate(cms, data)).isFalse(); + assertFalse(getCmsTestKeystores(algorithm).getCmsValidator().validate(cms, data)); } @ParameterizedTest @@ -93,7 +93,7 @@ public void cmsValidationWithTrustedChain(final Algorithm algorithm) { final Bytes cms = cmsCreator.create(data); - assertThat(getCmsTestKeystores(algorithm).getCmsValidator().validate(cms, data)).isTrue(); + assertTrue(getCmsTestKeystores(algorithm).getCmsValidator().validate(cms, data)); } @ParameterizedTest @@ -105,7 +105,7 @@ public void cmsValidationWithUntrustedChain(final Algorithm algorithm) { final Bytes cms = cmsCreator.create(data); - assertThat(getCmsTestKeystores(algorithm).getCmsValidator().validate(cms, data)).isFalse(); + assertFalse(getCmsTestKeystores(algorithm).getCmsValidator().validate(cms, data)); } @ParameterizedTest @@ -117,7 +117,7 @@ public void cmsValidationWithExpiredCertificate(final Algorithm algorithm) { final Bytes cms = cmsCreator.create(data); - assertThat(getCmsTestKeystores(algorithm).getCmsValidator().validate(cms, data)).isFalse(); + assertFalse(getCmsTestKeystores(algorithm).getCmsValidator().validate(cms, data)); } @ParameterizedTest @@ -129,7 +129,7 @@ public void cmsValidationWithRevokedCertificate(final Algorithm algorithm) { final Bytes cms = cmsCreator.create(data); - assertThat(getCmsTestKeystores(algorithm).getCmsValidator().validate(cms, data)).isFalse(); + assertFalse(getCmsTestKeystores(algorithm).getCmsValidator().validate(cms, data)); } @ParameterizedTest @@ -144,7 +144,7 @@ public void cmsValidationWithoutCRLConfigDisablesCRLCheck(final Algorithm algori CmsValidator cmsValidator = getCmsTestKeystores(algorithm).getCmsValidatorWithoutCrl(); // Because we don't have a CRL CertStore, revocation is not checked - assertThat(cmsValidator.validate(cms, data)).isTrue(); + assertTrue(cmsValidator.validate(cms, data)); } @ParameterizedTest @@ -156,8 +156,7 @@ public void cmsValidationWithWrongSignedData(final Algorithm algorithm) { final Bytes cms = cmsCreator.create(otherData); final Bytes expectedData = Bytes.random(32); - assertThat(getCmsTestKeystores(algorithm).getCmsValidator().validate(cms, expectedData)) - .isFalse(); + assertFalse(getCmsTestKeystores(algorithm).getCmsValidator().validate(cms, expectedData)); } @ParameterizedTest @@ -198,7 +197,6 @@ public void cmsValidationWithInvalidSignature(final Algorithm algorithm) throws final CMSSignedData cmsSignedData = cmsGenerator.generate(cmsData, true); final Bytes cmsBytes = Bytes.wrap(cmsSignedData.getEncoded()); - assertThat(getCmsTestKeystores(algorithm).getCmsValidator().validate(cmsBytes, expectedData)) - .isFalse(); + assertFalse(getCmsTestKeystores(algorithm).getCmsValidator().validate(cmsBytes, expectedData)); } } diff --git a/pki/src/test/java/org/hyperledger/besu/pki/keystore/BaseKeyStoreFileWrapperTest.java b/pki/src/test/java/org/hyperledger/besu/pki/keystore/BaseKeyStoreFileWrapperTest.java index 254e8bf23c7..3cbeff8985a 100644 --- a/pki/src/test/java/org/hyperledger/besu/pki/keystore/BaseKeyStoreFileWrapperTest.java +++ b/pki/src/test/java/org/hyperledger/besu/pki/keystore/BaseKeyStoreFileWrapperTest.java @@ -14,113 +14,143 @@ */ package org.hyperledger.besu.pki.keystore; -import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; import java.nio.file.Path; import java.security.cert.Certificate; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; -@RunWith(Parameterized.class) public abstract class BaseKeyStoreFileWrapperTest { protected static final String KEYSTORE_VALID_KEY_ALIAS = "partner1client1"; protected static final String KEYSTORE_INVALID_KEY_ALIAS = "partner1clientinvalid"; protected static final String TRUSTSTORE_VALID_CERTIFICATE_ALIAS = "interca"; protected static final String TRUSTSTORE_INVALID_CERTIFICATE_ALIAS = "interca-invalid"; - @Parameterized.Parameter public String keyStoreWrapperDescription; - - @Parameterized.Parameter(1) - public boolean keystoreWrapperConfiguredWithTruststore; - - @Parameterized.Parameter(2) - public KeyStoreWrapper keyStoreWrapper; - protected static Path toPath(final String path) throws Exception { return null == path ? null : Path.of(BaseKeyStoreFileWrapperTest.class.getResource(path).toURI()); } - @Test - public void getPublicKey_WithValidAlias_ReturnsExpectedValue() { - assertThat(keyStoreWrapper.getPublicKey(KEYSTORE_VALID_KEY_ALIAS)) - .as("Public key is not null") - .isNotNull(); + @ParameterizedTest + @MethodSource("data") + public void getPublicKey_WithValidAlias_ReturnsExpectedValue( + final KeyStoreWrapperTestParameter keyStoreWrapperTestParameter) { + assertNotNull( + keyStoreWrapperTestParameter.keyStoreWrapper.getPublicKey(KEYSTORE_VALID_KEY_ALIAS)); } - @Test - public void getPublicKey_WithInvalidAlias_ReturnsExpectedValue() { - assertThat(keyStoreWrapper.getPublicKey(KEYSTORE_INVALID_KEY_ALIAS)) - .as("Public key is null") - .isNull(); + @ParameterizedTest + @MethodSource("data") + public void getPublicKey_WithInvalidAlias_ReturnsExpectedValue( + final KeyStoreWrapperTestParameter keyStoreWrapperTestParameter) { + assertNull( + keyStoreWrapperTestParameter.keyStoreWrapper.getPublicKey(KEYSTORE_INVALID_KEY_ALIAS)); } - @Test - public void getPrivateKey_WithValidAlias_ReturnsExpectedValue() { - assertThat(keyStoreWrapper.getPrivateKey(KEYSTORE_VALID_KEY_ALIAS)) - .as("Private key is not null") - .isNotNull(); + @ParameterizedTest + @MethodSource("data") + public void getPrivateKey_WithValidAlias_ReturnsExpectedValue( + final KeyStoreWrapperTestParameter keyStoreWrapperTestParameter) { + assertNotNull( + keyStoreWrapperTestParameter.keyStoreWrapper.getPrivateKey(KEYSTORE_VALID_KEY_ALIAS), + "Private key is not null"); } - @Test - public void getPrivateKey_WithInvalidAlias_ReturnsExpectedValue() { - assertThat(keyStoreWrapper.getPrivateKey(KEYSTORE_INVALID_KEY_ALIAS)) - .as("Private key is null") - .isNull(); + @ParameterizedTest + @MethodSource("data") + public void getPrivateKey_WithInvalidAlias_ReturnsExpectedValue( + final KeyStoreWrapperTestParameter keyStoreWrapperTestParameter) { + assertNull( + keyStoreWrapperTestParameter.keyStoreWrapper.getPrivateKey(KEYSTORE_INVALID_KEY_ALIAS), + "Private key is null"); } - @Test - public void getCertificate_WithValidAlias_ReturnsExpectedValue() { - assertThat(keyStoreWrapper.getCertificate(KEYSTORE_VALID_KEY_ALIAS)) - .as("Certificate is not null") - .isNotNull(); + @ParameterizedTest + @MethodSource("data") + public void getCertificate_WithValidAlias_ReturnsExpectedValue( + final KeyStoreWrapperTestParameter keyStoreWrapperTestParameter) { + assertNotNull( + keyStoreWrapperTestParameter.keyStoreWrapper.getCertificate(KEYSTORE_VALID_KEY_ALIAS), + "Certificate is not null"); } - @Test - public void getCertificate_WithInvalidAlias_ReturnsExpectedValue() { - assertThat(keyStoreWrapper.getCertificate(KEYSTORE_INVALID_KEY_ALIAS)) - .as("Certificate is null") - .isNull(); + @ParameterizedTest + @MethodSource("data") + public void getCertificate_WithInvalidAlias_ReturnsExpectedValue( + final KeyStoreWrapperTestParameter keyStoreWrapperTestParameter) { + assertNull( + keyStoreWrapperTestParameter.keyStoreWrapper.getCertificate(KEYSTORE_INVALID_KEY_ALIAS), + "Certificate is null"); } - @Test - public void getCertificateChain_WithValidAlias_ReturnsExpectedValue() { - assertThat(keyStoreWrapper.getCertificateChain(KEYSTORE_VALID_KEY_ALIAS)) - .as("Certificate chain is not null") - .isNotNull(); + @ParameterizedTest + @MethodSource("data") + public void getCertificateChain_WithValidAlias_ReturnsExpectedValue( + final KeyStoreWrapperTestParameter keyStoreWrapperTestParameter) { + assertNotNull( + keyStoreWrapperTestParameter.keyStoreWrapper.getCertificateChain(KEYSTORE_VALID_KEY_ALIAS), + "Certificate chain is not null"); } - @Test - public void getCertificateChain_WithInvalidAlias_ReturnsExpectedValue() { - assertThat(keyStoreWrapper.getCertificateChain(KEYSTORE_INVALID_KEY_ALIAS)) - .as("Certificate is null") - .isNull(); + @ParameterizedTest + @MethodSource("data") + public void getCertificateChain_WithInvalidAlias_ReturnsExpectedValue( + final KeyStoreWrapperTestParameter keyStoreWrapperTestParameter) { + assertNull( + keyStoreWrapperTestParameter.keyStoreWrapper.getCertificateChain( + KEYSTORE_INVALID_KEY_ALIAS), + "Certificate is null"); } - @Test - public void getCertificate_FromTruststore_WithValidAlias_ReturnsExpectedValue() { + @ParameterizedTest + @MethodSource("data") + public void getCertificate_FromTruststore_WithValidAlias_ReturnsExpectedValue( + final KeyStoreWrapperTestParameter keyStoreWrapperTestParameter) { final Certificate certificate = - keyStoreWrapper.getCertificate(TRUSTSTORE_VALID_CERTIFICATE_ALIAS); - if (keystoreWrapperConfiguredWithTruststore) { - assertThat(certificate).as("Certificate is not null").isNotNull(); + keyStoreWrapperTestParameter.keyStoreWrapper.getCertificate( + TRUSTSTORE_VALID_CERTIFICATE_ALIAS); + if (keyStoreWrapperTestParameter.keystoreWrapperConfiguredWithTruststore) { + assertNotNull(certificate, "Certificate is not null"); } else { - assertThat(certificate).as("Certificate is null").isNull(); + assertNull(certificate, "Certificate is null"); } } - @Test - public void getCertificate_FromTruststore_WithInvalidAlias_ReturnsExpectedValue() { - assertThat(keyStoreWrapper.getPrivateKey(TRUSTSTORE_INVALID_CERTIFICATE_ALIAS)) - .as("Certificate is null") - .isNull(); + @ParameterizedTest + @MethodSource("data") + public void getCertificate_FromTruststore_WithInvalidAlias_ReturnsExpectedValue( + final KeyStoreWrapperTestParameter keyStoreWrapperTestParameter) { + assertNull( + keyStoreWrapperTestParameter.keyStoreWrapper.getPrivateKey( + TRUSTSTORE_INVALID_CERTIFICATE_ALIAS), + "Certificate is null"); } - @Test - public void getCRLS_Check() { - assertThat(keyStoreWrapper.getCRLs()).as("CRLs is not null").isNotNull(); - assertThat(keyStoreWrapper.getCRLs().size()).as("CRLs size matches").isEqualTo(2); + @ParameterizedTest + @MethodSource("data") + public void getCRLS_Check(final KeyStoreWrapperTestParameter keyStoreWrapperTestParameter) { + assertNotNull(keyStoreWrapperTestParameter.keyStoreWrapper.getCRLs(), "CRLs is not null"); + assertEquals( + keyStoreWrapperTestParameter.keyStoreWrapper.getCRLs().size(), 2, "CRLs size matches"); + } + + public static class KeyStoreWrapperTestParameter { + public String keyStoreWrapperDescription; + public boolean keystoreWrapperConfiguredWithTruststore; + public KeyStoreWrapper keyStoreWrapper; + + public KeyStoreWrapperTestParameter( + final String keyStoreWrapperDescription, + final boolean keystoreWrapperConfiguredWithTruststore, + final KeyStoreWrapper keyStoreWrapper) { + this.keyStoreWrapperDescription = keyStoreWrapperDescription; + this.keystoreWrapperConfiguredWithTruststore = keystoreWrapperConfiguredWithTruststore; + this.keyStoreWrapper = keyStoreWrapper; + } } } diff --git a/pki/src/test/java/org/hyperledger/besu/pki/keystore/HardwareKeyStoreFileWrapperTest.java b/pki/src/test/java/org/hyperledger/besu/pki/keystore/HardwareKeyStoreFileWrapperTest.java index 99208e01c5b..0dde591cf50 100644 --- a/pki/src/test/java/org/hyperledger/besu/pki/keystore/HardwareKeyStoreFileWrapperTest.java +++ b/pki/src/test/java/org/hyperledger/besu/pki/keystore/HardwareKeyStoreFileWrapperTest.java @@ -14,7 +14,8 @@ */ package org.hyperledger.besu.pki.keystore; -import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assumptions.assumeTrue; import org.hyperledger.besu.pki.PkiException; @@ -26,11 +27,9 @@ import java.util.Optional; import java.util.stream.Stream; -import org.junit.Assume; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.OS; -import org.junit.runners.Parameterized; public class HardwareKeyStoreFileWrapperTest extends BaseKeyStoreFileWrapperTest { @@ -39,16 +38,12 @@ public class HardwareKeyStoreFileWrapperTest extends BaseKeyStoreFileWrapperTest private static final String configName = "NSScrypto-partner1client1"; private static final String validKeystorePassword = "test123"; - @Parameterized.Parameters(name = "{index}: {0}") - public static Collection data() { + public static Collection data() { return Arrays.asList( - new Object[][] { - { + new KeyStoreWrapperTestParameter( "HardwareKeyStoreWrapper[PKCS11 keystore/truststore]", true, - CryptoTestUtil.isNSSLibInstalled() ? getHardwareKeyStoreWrapper(configName) : null - } - }); + CryptoTestUtil.isNSSLibInstalled() ? getHardwareKeyStoreWrapper(configName) : null)); } private static KeyStoreWrapper getHardwareKeyStoreWrapper(final String cfgName) { @@ -66,26 +61,26 @@ private static KeyStoreWrapper getHardwareKeyStoreWrapper(final String cfgName) if (OS.MAC.isCurrentOs()) { // nss3 is difficult to setup on mac correctly, don't let it break unit tests for dev // machines. - Assume.assumeNoException("Failed to initialize hardware keystore", e); + System.out.println("Failed to initialize hardware keystore " + e.getLocalizedMessage()); } // Not a mac, probably a production build. Full failure. throw new PkiException("Failed to initialize hardware keystore", e); } } - @Before + @BeforeEach public void beforeMethod() { - Assume.assumeTrue( - "Test ignored due to NSS library not being installed/detected.", - CryptoTestUtil.isNSSLibInstalled()); + assumeTrue( + CryptoTestUtil.isNSSLibInstalled(), + "Test ignored due to NSS library not being installed/detected."); } @Test public void getPkcs11Provider() throws Exception { final HardwareKeyStoreWrapper sut = (HardwareKeyStoreWrapper) getHardwareKeyStoreWrapper(configName); - assertThatThrownBy(() -> sut.getPkcs11ProviderForConfig("no-library")) - .isInstanceOf(IllegalArgumentException.class); + assertThrows( + IllegalArgumentException.class, () -> sut.getPkcs11ProviderForConfig("no-library")); } @Test @@ -96,21 +91,22 @@ public void init_keystorePassword_config() throws Exception { @Test public void init_keystorePassword_config_invalid() throws Exception { final String config = "invalid"; - assertThatThrownBy( - () -> new HardwareKeyStoreWrapper(validKeystorePassword, toPath(config), toPath(crl))) - .isInstanceOf(NullPointerException.class); + assertThrows( + NullPointerException.class, + () -> new HardwareKeyStoreWrapper(validKeystorePassword, toPath(config), toPath(crl))); } @Test public void init_keystorePassword_config_missing_pw() throws Exception { - assertThatThrownBy(() -> new HardwareKeyStoreWrapper(null, toPath(config), toPath(crl))) - .isInstanceOf(PkiException.class); + assertThrows( + PkiException.class, () -> new HardwareKeyStoreWrapper(null, toPath(config), toPath(crl))); } @Test public void init_keystorePassword_provider_missing_pw() throws Exception { final Provider p = null; - assertThatThrownBy(() -> new HardwareKeyStoreWrapper(validKeystorePassword, p, toPath(crl))) - .isInstanceOf(PkiException.class); + assertThrows( + PkiException.class, + () -> new HardwareKeyStoreWrapper(validKeystorePassword, p, toPath(crl))); } } diff --git a/pki/src/test/java/org/hyperledger/besu/pki/keystore/HardwareKeyStoreWrapperTest.java b/pki/src/test/java/org/hyperledger/besu/pki/keystore/HardwareKeyStoreWrapperTest.java index bbbe68f8232..1d72a0537f4 100644 --- a/pki/src/test/java/org/hyperledger/besu/pki/keystore/HardwareKeyStoreWrapperTest.java +++ b/pki/src/test/java/org/hyperledger/besu/pki/keystore/HardwareKeyStoreWrapperTest.java @@ -15,7 +15,8 @@ package org.hyperledger.besu.pki.keystore; -import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.Mockito.when; import java.security.KeyStore; @@ -23,13 +24,13 @@ import java.security.PublicKey; import java.security.cert.Certificate; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +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.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class HardwareKeyStoreWrapperTest { private static final String KEY_ALIAS = "keyalias"; @@ -43,7 +44,7 @@ public class HardwareKeyStoreWrapperTest { private HardwareKeyStoreWrapper keyStoreWrapper; - @Before + @BeforeEach public void before() { keyStoreWrapper = new HardwareKeyStoreWrapper(null, keyStore, new String(PASSWORD)); } @@ -52,7 +53,7 @@ public void before() { public void getPrivateKey() throws Exception { when(keyStore.getKey(KEY_ALIAS, PASSWORD)).thenReturn(privateKey); - assertThat(keyStoreWrapper.getPrivateKey(KEY_ALIAS)).isNotNull(); + assertNotNull(keyStoreWrapper.getPrivateKey(KEY_ALIAS)); } @Test @@ -61,14 +62,14 @@ public void getPublicKey() throws Exception { when(keyStore.getCertificate(KEY_ALIAS)).thenReturn(certificate); when(certificate.getPublicKey()).thenReturn(publicKey); - assertThat(keyStoreWrapper.getPublicKey(KEY_ALIAS)).isNotNull(); + assertNotNull(keyStoreWrapper.getPublicKey(KEY_ALIAS)); } @Test public void getCertificate() throws Exception { when(keyStore.getCertificate(CERTIFICATE_ALIAS)).thenReturn(certificate); - assertThat(keyStoreWrapper.getCertificate(CERTIFICATE_ALIAS)).isNotNull(); + assertNotNull(keyStoreWrapper.getCertificate(CERTIFICATE_ALIAS)); } @Test @@ -76,6 +77,6 @@ public void getCertificateChain() throws Exception { when(keyStore.getCertificateChain(CERTIFICATE_ALIAS)) .thenReturn(new Certificate[] {certificate}); - assertThat(keyStoreWrapper.getCertificateChain(CERTIFICATE_ALIAS)).hasSize(1); + assertEquals(keyStoreWrapper.getCertificateChain(CERTIFICATE_ALIAS).length, 1); } } diff --git a/pki/src/test/java/org/hyperledger/besu/pki/keystore/SoftwareKeyStoreFileWrapperTest.java b/pki/src/test/java/org/hyperledger/besu/pki/keystore/SoftwareKeyStoreFileWrapperTest.java index a194d8ec690..2550d070f72 100644 --- a/pki/src/test/java/org/hyperledger/besu/pki/keystore/SoftwareKeyStoreFileWrapperTest.java +++ b/pki/src/test/java/org/hyperledger/besu/pki/keystore/SoftwareKeyStoreFileWrapperTest.java @@ -20,8 +20,6 @@ import java.util.Arrays; import java.util.Collection; -import org.junit.runners.Parameterized; - public class SoftwareKeyStoreFileWrapperTest extends BaseKeyStoreFileWrapperTest { private static final String p12KeyStore = "/keystore/partner1client1/keys.p12"; @@ -30,26 +28,20 @@ public class SoftwareKeyStoreFileWrapperTest extends BaseKeyStoreFileWrapperTest private static final String crl = "/keystore/partner1client1/crl.pem"; private static final String validKeystorePassword = "test123"; - @Parameterized.Parameters(name = "{index}: {0}") - public static Collection data() { + public static Collection data() { return Arrays.asList( - new Object[][] { - { + new KeyStoreWrapperTestParameter( "SoftwareKeyStoreWrapper[PKCS12 keystore only]", false, - getPKCS12SoftwareKeyStoreWrapper() - }, - { + getPKCS12SoftwareKeyStoreWrapper()), + new KeyStoreWrapperTestParameter( "SoftwareKeyStoreWrapper[JKS keystore only]", false, - getJKSSoftwareKeyStoreWrapper(false) - }, - { + getJKSSoftwareKeyStoreWrapper(false)), + new KeyStoreWrapperTestParameter( "SoftwareKeyStoreWrapper[JKS keystore/truststore]", true, - getJKSSoftwareKeyStoreWrapper(true) - } - }); + getJKSSoftwareKeyStoreWrapper(true))); } private static KeyStoreWrapper getPKCS12SoftwareKeyStoreWrapper() { diff --git a/pki/src/test/java/org/hyperledger/besu/pki/keystore/SoftwareKeyStoreWrapperTest.java b/pki/src/test/java/org/hyperledger/besu/pki/keystore/SoftwareKeyStoreWrapperTest.java index e198084ac44..8f7f8164bc8 100644 --- a/pki/src/test/java/org/hyperledger/besu/pki/keystore/SoftwareKeyStoreWrapperTest.java +++ b/pki/src/test/java/org/hyperledger/besu/pki/keystore/SoftwareKeyStoreWrapperTest.java @@ -15,8 +15,9 @@ package org.hyperledger.besu.pki.keystore; -import static org.assertj.core.api.Assertions.assertThat; import static org.hyperledger.besu.pki.keystore.KeyStoreWrapper.KEYSTORE_TYPE_PKCS12; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -28,13 +29,13 @@ import java.security.PublicKey; import java.security.cert.Certificate; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +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.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class SoftwareKeyStoreWrapperTest { private static final String KEY_ALIAS = "keyalias"; @@ -49,7 +50,7 @@ public class SoftwareKeyStoreWrapperTest { @Mock private PublicKey publicKey; @Mock private Certificate certificate; - @Before + @BeforeEach public void before() { keyStoreWrapper = new SoftwareKeyStoreWrapper(keyStore, new String(PASSWORD), null, ""); } @@ -59,7 +60,7 @@ public void getPrivateKey() throws Exception { when(keyStore.containsAlias(KEY_ALIAS)).thenReturn(true); when(keyStore.getKey(KEY_ALIAS, PASSWORD)).thenReturn(privateKey); - assertThat(keyStoreWrapper.getPrivateKey(KEY_ALIAS)).isNotNull(); + assertNotNull(keyStoreWrapper.getPrivateKey(KEY_ALIAS)); } @Test @@ -83,7 +84,7 @@ public void getPrivateKeyFallbackToTrustStore() throws Exception { when(trustStore.containsAlias(KEY_ALIAS)).thenReturn(true); when(trustStore.getKey(KEY_ALIAS, PASSWORD)).thenReturn(privateKey); - assertThat(keyStoreWrapper.getPrivateKey(KEY_ALIAS)).isNotNull(); + assertNotNull(keyStoreWrapper.getPrivateKey(KEY_ALIAS)); verify(trustStore).getKey(eq(KEY_ALIAS), eq(PASSWORD)); } @@ -93,7 +94,7 @@ public void getPublicKey() throws Exception { when(keyStore.containsAlias(KEY_ALIAS)).thenReturn(true); when(keyStore.getKey(KEY_ALIAS, PASSWORD)).thenReturn(publicKey); - assertThat(keyStoreWrapper.getPublicKey(KEY_ALIAS)).isNotNull(); + assertNotNull(keyStoreWrapper.getPublicKey(KEY_ALIAS)); } @Test @@ -117,7 +118,7 @@ public void getPublicKeyFallbackToTrustStore() throws Exception { when(trustStore.containsAlias(KEY_ALIAS)).thenReturn(true); when(trustStore.getKey(KEY_ALIAS, PASSWORD)).thenReturn(publicKey); - assertThat(keyStoreWrapper.getPublicKey(KEY_ALIAS)).isNotNull(); + assertNotNull(keyStoreWrapper.getPublicKey(KEY_ALIAS)); verify(trustStore).getKey(eq(KEY_ALIAS), eq(PASSWORD)); } @@ -126,7 +127,7 @@ public void getPublicKeyFallbackToTrustStore() throws Exception { public void getCertificate() throws Exception { when(keyStore.getCertificate(CERTIFICATE_ALIAS)).thenReturn(certificate); - assertThat(keyStoreWrapper.getCertificate(CERTIFICATE_ALIAS)).isNotNull(); + assertNotNull(keyStoreWrapper.getCertificate(CERTIFICATE_ALIAS)); } @Test @@ -148,7 +149,7 @@ public void getCertificateFallbackToTrustStore() throws Exception { when(keyStore.getCertificate(CERTIFICATE_ALIAS)).thenReturn(null); when(trustStore.getCertificate(CERTIFICATE_ALIAS)).thenReturn(certificate); - assertThat(keyStoreWrapper.getCertificate(CERTIFICATE_ALIAS)).isNotNull(); + assertNotNull(keyStoreWrapper.getCertificate(CERTIFICATE_ALIAS)); verify(trustStore).getCertificate(eq(CERTIFICATE_ALIAS)); } @@ -158,7 +159,7 @@ public void getCertificateChain() throws Exception { when(keyStore.getCertificateChain(CERTIFICATE_ALIAS)) .thenReturn(new Certificate[] {certificate}); - assertThat(keyStoreWrapper.getCertificateChain(CERTIFICATE_ALIAS)).hasSize(1); + assertEquals(keyStoreWrapper.getCertificateChain(CERTIFICATE_ALIAS).length, 1); } @Test @@ -171,7 +172,7 @@ public void getCertificateChainFallbackToTrustStore() throws Exception { when(trustStore.getCertificateChain(CERTIFICATE_ALIAS)) .thenReturn(new Certificate[] {certificate}); - assertThat(keyStoreWrapper.getCertificateChain(CERTIFICATE_ALIAS)).hasSize(1); + assertEquals(keyStoreWrapper.getCertificateChain(CERTIFICATE_ALIAS).length, 1); verify(trustStore).getCertificateChain(eq(CERTIFICATE_ALIAS)); } @@ -188,10 +189,10 @@ public void loadKeyStoreFromFile() { "validator", null); - assertThat(loadedKeyStore.getPublicKey("validator")).isNotNull(); - assertThat(loadedKeyStore.getPrivateKey("validator")).isNotNull(); - assertThat(loadedKeyStore.getCertificate("validator")).isNotNull(); + assertNotNull(loadedKeyStore.getPublicKey("validator")); + assertNotNull(loadedKeyStore.getPrivateKey("validator")); + assertNotNull(loadedKeyStore.getCertificate("validator")); // CA -> INTERCA -> PARTNERACA -> VALIDATOR - assertThat(loadedKeyStore.getCertificateChain("validator")).hasSize(4); + assertEquals(loadedKeyStore.getCertificateChain("validator").length, 4); } } From b6e73ae0804096839cd44d800b4d392d74910cbb Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Thu, 7 Dec 2023 12:57:06 +1000 Subject: [PATCH 14/28] junit 5 ftw (#6253) Signed-off-by: Sally MacFarlane --- consensus/common/build.gradle | 2 +- .../CombinedProtocolScheduleFactoryTest.java | 8 ++++---- .../consensus/common/ForksScheduleTest.java | 2 +- .../MigratingMiningCoordinatorTest.java | 16 ++++++++-------- .../common/MigratingProtocolContextTest.java | 2 +- .../BaseBftProtocolScheduleBuilderTest.java | 2 +- .../bft/BaseForksSchedulesFactoryTest.java | 2 +- .../common/bft/BftEventQueueTest.java | 2 +- .../bft/BftForksScheduleFactoryTest.java | 2 +- .../consensus/common/bft/BftHelpersTest.java | 2 +- .../common/bft/BftProcessorTest.java | 12 ++++++------ .../consensus/common/bft/BlockTimerTest.java | 12 ++++++------ .../bft/EthSynchronizerUpdaterTest.java | 8 ++++---- .../common/bft/MessageTrackerTest.java | 2 +- .../consensus/common/bft/RoundTimerTest.java | 12 ++++++------ .../common/bft/SizeLimitedMapTest.java | 2 +- .../bft/UniqueMessageMulticasterTest.java | 8 ++++---- .../besu/consensus/common/bft/VoteTest.java | 2 +- .../BftMiningCoordinatorTest.java | 19 ++++++++++--------- .../blockcreation/ProposerSelectorTest.java | 2 +- .../BftCoinbaseValidationRuleTest.java | 2 +- .../BftCommitSealsValidationRuleTest.java | 2 +- .../BftValidatorsValidationRuleTest.java | 2 +- .../BftVanityDataValidationRuleTest.java | 2 +- .../bft/network/ValidatorPeersTest.java | 17 +++++++++-------- .../bft/queries/BftQueryServiceImplTest.java | 12 ++++++------ .../statemachine/FutureMessageBufferTest.java | 6 +++--- .../blockbased/ForkingVoteTallyCacheTest.java | 2 +- .../blockbased/VoteProposerTest.java | 2 +- .../blockbased/VoteTallyCacheTest.java | 2 +- .../blockbased/VoteTallyCacheTestBase.java | 4 ++-- .../validator/blockbased/VoteTallyTest.java | 2 +- .../blockbased/VoteTallyUpdaterTest.java | 2 +- 33 files changed, 89 insertions(+), 87 deletions(-) diff --git a/consensus/common/build.gradle b/consensus/common/build.gradle index 49c73e7d176..04132ab6d00 100644 --- a/consensus/common/build.gradle +++ b/consensus/common/build.gradle @@ -53,11 +53,11 @@ dependencies { testImplementation project( path: ':crypto:services', configuration: 'testSupportArtifacts') testImplementation project(':metrics:core') - testImplementation 'junit:junit' testImplementation 'org.assertj:assertj-core' testImplementation 'org.awaitility:awaitility' testImplementation 'org.junit.jupiter:junit-jupiter' testImplementation 'org.mockito:mockito-core' + testImplementation 'org.mockito:mockito-junit-jupiter' testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/CombinedProtocolScheduleFactoryTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/CombinedProtocolScheduleFactoryTest.java index 29b197b9ece..9c1e8005a80 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/CombinedProtocolScheduleFactoryTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/CombinedProtocolScheduleFactoryTest.java @@ -35,11 +35,11 @@ import java.util.function.Function; import java.util.stream.Collectors; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.junit.MockitoJUnitRunner; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class CombinedProtocolScheduleFactoryTest { private final CombinedProtocolScheduleFactory combinedProtocolScheduleFactory = diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/ForksScheduleTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/ForksScheduleTest.java index bf6d32f4694..053037e933c 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/ForksScheduleTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/ForksScheduleTest.java @@ -24,7 +24,7 @@ import java.util.List; import java.util.Optional; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class ForksScheduleTest { diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/MigratingMiningCoordinatorTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/MigratingMiningCoordinatorTest.java index 31eabf22aaf..df301f44a17 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/MigratingMiningCoordinatorTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/MigratingMiningCoordinatorTest.java @@ -16,6 +16,7 @@ import static java.util.Collections.emptyList; import static org.hyperledger.besu.ethereum.core.BlockHeader.GENESIS_BLOCK_NUMBER; +import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.reset; import static org.mockito.Mockito.verify; @@ -40,13 +41,13 @@ import java.util.function.Consumer; import org.apache.tuweni.bytes.Bytes; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +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.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class MigratingMiningCoordinatorTest { @Mock private BftMiningCoordinator coordinator1; @@ -58,7 +59,7 @@ public class MigratingMiningCoordinatorTest { private ForksSchedule coordinatorSchedule; private static final long MIGRATION_BLOCK_NUMBER = 5L; - @Before + @BeforeEach public void setup() { coordinatorSchedule = createCoordinatorSchedule(coordinator1, coordinator2); final Block block = new Block(blockHeader, blockBody); @@ -87,13 +88,12 @@ public void startShouldRegisterThisCoordinatorAsObserver() { @Test public void startShouldUnregisterDelegateCoordinatorAsObserver() { final BftMiningCoordinator delegateCoordinator = createDelegateCoordinator(); - when(blockchain.observeBlockAdded(delegateCoordinator)).thenReturn(1L); + lenient().when(blockchain.observeBlockAdded(delegateCoordinator)).thenReturn(1L); final MigratingMiningCoordinator coordinator = new MigratingMiningCoordinator( createCoordinatorSchedule(delegateCoordinator, coordinator2), blockchain); coordinator.start(); - verify(blockchain).observeBlockAdded(coordinator); verify(blockchain).observeBlockAdded(delegateCoordinator); verify(blockchain).removeObserver(1L); diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/MigratingProtocolContextTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/MigratingProtocolContextTest.java index 21ba7638c40..c675219c352 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/MigratingProtocolContextTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/MigratingProtocolContextTest.java @@ -25,7 +25,7 @@ import java.util.List; import java.util.Optional; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; public class MigratingProtocolContextTest { diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BaseBftProtocolScheduleBuilderTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BaseBftProtocolScheduleBuilderTest.java index d704cddce85..b2b2a9fe3af 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BaseBftProtocolScheduleBuilderTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BaseBftProtocolScheduleBuilderTest.java @@ -42,7 +42,7 @@ import java.util.List; import java.util.Optional; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class BaseBftProtocolScheduleBuilderTest { diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BaseForksSchedulesFactoryTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BaseForksSchedulesFactoryTest.java index 5102276f8e8..ba65dffbff7 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BaseForksSchedulesFactoryTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BaseForksSchedulesFactoryTest.java @@ -30,7 +30,7 @@ import java.util.function.Consumer; import com.fasterxml.jackson.databind.node.ObjectNode; -import org.junit.Test; +import org.junit.jupiter.api.Test; public abstract class BaseForksSchedulesFactoryTest< C extends BftConfigOptions, M extends MutableBftConfigOptions> { diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BftEventQueueTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BftEventQueueTest.java index 28e444e0e42..db5587b9d28 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BftEventQueueTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BftEventQueueTest.java @@ -24,7 +24,7 @@ import java.util.List; import java.util.concurrent.TimeUnit; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class BftEventQueueTest { private static final int MAX_QUEUE_SIZE = 1000; diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BftForksScheduleFactoryTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BftForksScheduleFactoryTest.java index dbfc16da29e..72b15b58bcf 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BftForksScheduleFactoryTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BftForksScheduleFactoryTest.java @@ -29,7 +29,7 @@ import java.util.List; import java.util.Map; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; public class BftForksScheduleFactoryTest { diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BftHelpersTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BftHelpersTest.java index 6daadc0fd41..67e7cc283b9 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BftHelpersTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BftHelpersTest.java @@ -15,7 +15,7 @@ package org.hyperledger.besu.consensus.common.bft; import org.assertj.core.api.Assertions; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class BftHelpersTest { diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BftProcessorTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BftProcessorTest.java index da62a8f5cc5..5ff31b538bc 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BftProcessorTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BftProcessorTest.java @@ -31,17 +31,17 @@ import java.util.concurrent.TimeUnit; import org.awaitility.Awaitility; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.StrictStubs.class) +@ExtendWith(MockitoExtension.class) public class BftProcessorTest { private EventMultiplexer mockeEventMultiplexer; - @Before + @BeforeEach public void initialise() { mockeEventMultiplexer = mock(EventMultiplexer.class); } diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BlockTimerTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BlockTimerTest.java index ec0783f6a3e..23026148114 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BlockTimerTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BlockTimerTest.java @@ -37,14 +37,14 @@ import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentCaptor; import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.StrictStubs.class) +@ExtendWith(MockitoExtension.class) public class BlockTimerTest { private BftExecutors bftExecutors; @@ -52,7 +52,7 @@ public class BlockTimerTest { private Clock mockClock; private ForksSchedule mockForksSchedule; - @Before + @BeforeEach @SuppressWarnings("unchecked") public void initialise() { bftExecutors = mock(BftExecutors.class); diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/EthSynchronizerUpdaterTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/EthSynchronizerUpdaterTest.java index 7d01ebe059e..62465a183d5 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/EthSynchronizerUpdaterTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/EthSynchronizerUpdaterTest.java @@ -27,12 +27,12 @@ import org.hyperledger.besu.ethereum.eth.manager.EthPeers; import org.hyperledger.besu.ethereum.p2p.rlpx.connections.PeerConnection; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class EthSynchronizerUpdaterTest { @Mock private EthPeers ethPeers; diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/MessageTrackerTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/MessageTrackerTest.java index 72eb918c74a..68fce007271 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/MessageTrackerTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/MessageTrackerTest.java @@ -19,7 +19,7 @@ import org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData; import org.apache.tuweni.bytes.Bytes; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class MessageTrackerTest { private final MessageTracker messageTracker = new MessageTracker(5); diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/RoundTimerTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/RoundTimerTest.java index 693074bdfb0..f8a061471db 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/RoundTimerTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/RoundTimerTest.java @@ -28,20 +28,20 @@ import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentCaptor; import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.StrictStubs.class) +@ExtendWith(MockitoExtension.class) public class RoundTimerTest { private BftExecutors bftExecutors; private BftEventQueue queue; private RoundTimer timer; - @Before + @BeforeEach public void initialise() { bftExecutors = mock(BftExecutors.class); queue = new BftEventQueue(1000); diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/SizeLimitedMapTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/SizeLimitedMapTest.java index b6eb9a057fd..e363920078d 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/SizeLimitedMapTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/SizeLimitedMapTest.java @@ -16,7 +16,7 @@ import static org.assertj.core.api.Assertions.assertThat; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class SizeLimitedMapTest { diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/UniqueMessageMulticasterTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/UniqueMessageMulticasterTest.java index 70c18c52303..cbc731317e9 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/UniqueMessageMulticasterTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/UniqueMessageMulticasterTest.java @@ -31,11 +31,11 @@ import com.google.common.collect.Lists; import org.apache.tuweni.bytes.Bytes; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.junit.MockitoJUnitRunner; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class UniqueMessageMulticasterTest { private final MessageTracker messageTracker = mock(MessageTracker.class); diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/VoteTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/VoteTest.java index cb96b9d4f71..b01a3a97c6f 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/VoteTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/VoteTest.java @@ -18,7 +18,7 @@ import org.hyperledger.besu.datatypes.Address; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class VoteTest { @Test diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/blockcreation/BftMiningCoordinatorTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/blockcreation/BftMiningCoordinatorTest.java index 5b1d7a3cf64..dda38b45af1 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/blockcreation/BftMiningCoordinatorTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/blockcreation/BftMiningCoordinatorTest.java @@ -15,6 +15,7 @@ package org.hyperledger.besu.consensus.common.bft.blockcreation; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -35,13 +36,13 @@ import java.util.concurrent.TimeUnit; import org.apache.tuweni.bytes.Bytes; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +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.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class BftMiningCoordinatorTest { @Mock private BftEventHandler controller; @Mock private BftExecutors bftExecutors; @@ -54,14 +55,14 @@ public class BftMiningCoordinatorTest { private final BftEventQueue eventQueue = new BftEventQueue(1000); private BftMiningCoordinator bftMiningCoordinator; - @Before + @BeforeEach public void setup() { bftMiningCoordinator = new BftMiningCoordinator( bftExecutors, controller, bftProcessor, bftBlockCreatorFactory, blockChain, eventQueue); - when(block.getBody()).thenReturn(blockBody); - when(block.getHeader()).thenReturn(blockHeader); - when(blockBody.getTransactions()).thenReturn(Collections.emptyList()); + lenient().when(block.getBody()).thenReturn(blockBody); + lenient().when(block.getHeader()).thenReturn(blockHeader); + lenient().when(blockBody.getTransactions()).thenReturn(Collections.emptyList()); } @Test diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/blockcreation/ProposerSelectorTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/blockcreation/ProposerSelectorTest.java index 80737668027..ebe74b16988 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/blockcreation/ProposerSelectorTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/blockcreation/ProposerSelectorTest.java @@ -35,7 +35,7 @@ import java.util.List; import java.util.Optional; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class ProposerSelectorTest { diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftCoinbaseValidationRuleTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftCoinbaseValidationRuleTest.java index fcbea4954d8..e8d7ee79e98 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftCoinbaseValidationRuleTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftCoinbaseValidationRuleTest.java @@ -30,7 +30,7 @@ import java.util.Optional; import com.google.common.collect.Lists; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class BftCoinbaseValidationRuleTest { diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftCommitSealsValidationRuleTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftCommitSealsValidationRuleTest.java index 453b28a601c..facc4ee2e3a 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftCommitSealsValidationRuleTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftCommitSealsValidationRuleTest.java @@ -38,7 +38,7 @@ import java.util.stream.IntStream; import com.google.common.collect.Lists; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class BftCommitSealsValidationRuleTest { diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftValidatorsValidationRuleTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftValidatorsValidationRuleTest.java index 00b994295ca..690dc26f155 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftValidatorsValidationRuleTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftValidatorsValidationRuleTest.java @@ -29,7 +29,7 @@ import java.util.Optional; import com.google.common.collect.Lists; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class BftValidatorsValidationRuleTest { diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftVanityDataValidationRuleTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftVanityDataValidationRuleTest.java index cd148f8787a..5b9252df567 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftVanityDataValidationRuleTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftVanityDataValidationRuleTest.java @@ -27,7 +27,7 @@ import java.util.Optional; import org.apache.tuweni.bytes.Bytes; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class BftVanityDataValidationRuleTest { private final BftVanityDataValidationRule validationRule = new BftVanityDataValidationRule(); diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/network/ValidatorPeersTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/network/ValidatorPeersTest.java index 38ad26c658b..3f8c9f24153 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/network/ValidatorPeersTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/network/ValidatorPeersTest.java @@ -16,6 +16,7 @@ import static com.google.common.collect.Lists.newArrayList; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; @@ -37,13 +38,13 @@ import java.util.List; import org.apache.tuweni.bytes.Bytes; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +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.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class ValidatorPeersTest { public static final String PROTOCOL_NAME = "BFT"; @@ -53,7 +54,7 @@ public class ValidatorPeersTest { private final List peerConnections = newArrayList(); @Mock ValidatorProvider validatorProvider; - @Before + @BeforeEach public void setup() { for (int i = 0; i < 4; i++) { final SECPPublicKey pubKey = @@ -71,8 +72,8 @@ public void setup() { private PeerConnection mockPeerConnection(final Address address) { final PeerInfo peerInfo = mock(PeerInfo.class); final PeerConnection peerConnection = mock(PeerConnection.class); - when(peerConnection.getPeerInfo()).thenReturn(peerInfo); - when(peerInfo.getAddress()).thenReturn(address); + lenient().when(peerConnection.getPeerInfo()).thenReturn(peerInfo); + lenient().when(peerInfo.getAddress()).thenReturn(address); return peerConnection; } diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/queries/BftQueryServiceImplTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/queries/BftQueryServiceImplTest.java index ab161c2c401..cc99cf805fc 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/queries/BftQueryServiceImplTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/queries/BftQueryServiceImplTest.java @@ -42,13 +42,13 @@ import com.google.common.collect.Lists; import org.apache.tuweni.bytes.Bytes; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +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.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class BftQueryServiceImplTest { @Mock private Blockchain blockchain; @@ -66,7 +66,7 @@ public class BftQueryServiceImplTest { private BlockHeader blockHeader; - @Before + @BeforeEach public void setup() { final BlockHeaderTestFixture blockHeaderTestFixture = new BlockHeaderTestFixture(); blockHeaderTestFixture.number(1); // can't be genesis block (due to extradata serialisation) diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/statemachine/FutureMessageBufferTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/statemachine/FutureMessageBufferTest.java index 1267d5794b6..b584c9a16b5 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/statemachine/FutureMessageBufferTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/statemachine/FutureMessageBufferTest.java @@ -30,15 +30,15 @@ import java.util.stream.IntStream; import org.apache.tuweni.bytes.Bytes; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class FutureMessageBufferTest { private Message message; private FutureMessageBuffer futureMsgBuffer; private final PeerConnection peerConnection = MockPeerFactory.create(AddressHelpers.ofValue(9)); - @Before + @BeforeEach public void setup() { message = createMessage(10); futureMsgBuffer = new FutureMessageBuffer(5, 5, 0); diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/ForkingVoteTallyCacheTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/ForkingVoteTallyCacheTest.java index f1692201cec..d877223a8fd 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/ForkingVoteTallyCacheTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/ForkingVoteTallyCacheTest.java @@ -26,7 +26,7 @@ import java.util.Map; import com.google.common.collect.Lists; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class ForkingVoteTallyCacheTest extends VoteTallyCacheTestBase { diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteProposerTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteProposerTest.java index d486a41979a..6263bc960cc 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteProposerTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteProposerTest.java @@ -24,7 +24,7 @@ import java.util.Collections; import java.util.Optional; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class VoteProposerTest { private final Address localAddress = Address.fromHexString("0"); diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteTallyCacheTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteTallyCacheTest.java index c69f2bb7697..514e5b8ab37 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteTallyCacheTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteTallyCacheTest.java @@ -35,7 +35,7 @@ import java.util.Optional; import com.google.common.util.concurrent.UncheckedExecutionException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; public class VoteTallyCacheTest extends VoteTallyCacheTestBase { diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteTallyCacheTestBase.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteTallyCacheTestBase.java index 1a3dba12b1d..00e22532e2f 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteTallyCacheTestBase.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteTallyCacheTestBase.java @@ -33,7 +33,7 @@ import org.apache.tuweni.bytes.Bytes; import org.assertj.core.util.Lists; -import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; public class VoteTallyCacheTestBase { @@ -55,7 +55,7 @@ protected Block createEmptyBlock(final long blockNumber, final Hash parentHash) protected final BlockInterface blockInterface = mock(BlockInterface.class); - @Before + @BeforeEach public void constructThreeBlockChain() { for (int i = 0; i < 3; i++) { validators.add(AddressHelpers.ofValue(i)); diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteTallyTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteTallyTest.java index 96671716cae..9c8d1033cba 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteTallyTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteTallyTest.java @@ -22,7 +22,7 @@ import org.hyperledger.besu.consensus.common.validator.VoteType; import org.hyperledger.besu.datatypes.Address; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class VoteTallyTest { diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteTallyUpdaterTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteTallyUpdaterTest.java index 6d7590edf9a..21039c84d85 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteTallyUpdaterTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/VoteTallyUpdaterTest.java @@ -37,7 +37,7 @@ import java.util.Optional; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class VoteTallyUpdaterTest { From d69b89a915e7cde948dcd3f289afc62a280ecd75 Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Thu, 7 Dec 2023 14:27:04 +1000 Subject: [PATCH 15/28] removed unnecessary use of static temp dir (#6251) * don't use static tempdir Signed-off-by: Sally MacFarlane --------- Signed-off-by: Sally MacFarlane --- besu/src/test/java/org/hyperledger/besu/PrivacyReorgTest.java | 2 +- besu/src/test/java/org/hyperledger/besu/RunnerTest.java | 2 +- .../ethereum/api/graphql/AbstractEthGraphQLHttpServiceTest.java | 2 +- .../besu/ethereum/api/graphql/GraphQLHttpServiceCorsTest.java | 2 +- .../api/graphql/GraphQLHttpServiceHostWhitelistTest.java | 2 +- .../besu/ethereum/api/graphql/GraphQLHttpServiceTest.java | 1 + .../besu/ethereum/api/jsonrpc/JsonRpcHttpServiceCorsTest.java | 2 +- .../besu/ethereum/api/jsonrpc/JsonRpcHttpServiceLoginTest.java | 1 + .../ethereum/api/jsonrpc/JsonRpcHttpServiceRpcApisTest.java | 2 +- .../besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTestBase.java | 1 + .../api/jsonrpc/JsonRpcHttpServiceTlsClientAuthTest.java | 1 + .../internal/methods/DebugStandardTraceBlockToFileTest.java | 1 + .../api/jsonrpc/internal/processor/TransactionTracerTest.java | 2 +- .../besu/ethereum/api/query/BlockchainQueriesLogCacheTest.java | 1 + .../privacy/PrivacyPrecompiledContractIntegrationTest.java | 1 + .../hyperledger/besu/ethereum/util/RawBlockIteratorTest.java | 2 +- .../besu/ethereum/p2p/peers/StaticNodesParserTest.java | 2 +- 17 files changed, 17 insertions(+), 10 deletions(-) diff --git a/besu/src/test/java/org/hyperledger/besu/PrivacyReorgTest.java b/besu/src/test/java/org/hyperledger/besu/PrivacyReorgTest.java index 276740fbfed..4f1b31c76b6 100644 --- a/besu/src/test/java/org/hyperledger/besu/PrivacyReorgTest.java +++ b/besu/src/test/java/org/hyperledger/besu/PrivacyReorgTest.java @@ -81,7 +81,7 @@ @SuppressWarnings("rawtypes") public class PrivacyReorgTest { - @TempDir private static Path folder; + @TempDir private Path folder; private static final Supplier SIGNATURE_ALGORITHM = Suppliers.memoize(SignatureAlgorithmFactory::getInstance); diff --git a/besu/src/test/java/org/hyperledger/besu/RunnerTest.java b/besu/src/test/java/org/hyperledger/besu/RunnerTest.java index 20d3c3ee448..f8bdb5cb690 100644 --- a/besu/src/test/java/org/hyperledger/besu/RunnerTest.java +++ b/besu/src/test/java/org/hyperledger/besu/RunnerTest.java @@ -122,7 +122,7 @@ public void stopVertx() { vertx.close(); } - @TempDir private static Path temp; + @TempDir private Path temp; @Test public void getFixedNodes() { diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/AbstractEthGraphQLHttpServiceTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/AbstractEthGraphQLHttpServiceTest.java index 59da8e18b75..20b77eed839 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/AbstractEthGraphQLHttpServiceTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/AbstractEthGraphQLHttpServiceTest.java @@ -56,7 +56,7 @@ import org.mockito.Mockito; public abstract class AbstractEthGraphQLHttpServiceTest { - @TempDir private static Path tempDir; + @TempDir private Path tempDir; private static BlockchainSetupUtil blockchainSetupUtil; diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/GraphQLHttpServiceCorsTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/GraphQLHttpServiceCorsTest.java index 1b86c21e130..d6a04b4cb8c 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/GraphQLHttpServiceCorsTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/GraphQLHttpServiceCorsTest.java @@ -41,7 +41,7 @@ import org.mockito.Mockito; public class GraphQLHttpServiceCorsTest { - @TempDir private static Path folder; + @TempDir private Path folder; private final Vertx vertx = Vertx.vertx(); private final OkHttpClient client = new OkHttpClient(); diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/GraphQLHttpServiceHostWhitelistTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/GraphQLHttpServiceHostWhitelistTest.java index 5b083a79580..c2fb617fbb8 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/GraphQLHttpServiceHostWhitelistTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/GraphQLHttpServiceHostWhitelistTest.java @@ -46,7 +46,7 @@ public class GraphQLHttpServiceHostWhitelistTest { - @TempDir private static Path folder; + @TempDir private Path folder; protected static Vertx vertx; diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/GraphQLHttpServiceTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/GraphQLHttpServiceTest.java index b5d0463883b..71ff8565157 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/GraphQLHttpServiceTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/GraphQLHttpServiceTest.java @@ -59,6 +59,7 @@ public class GraphQLHttpServiceTest { + // this tempDir is deliberately static @TempDir private static Path folder; private static final Vertx vertx = Vertx.vertx(); diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceCorsTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceCorsTest.java index b090869bb5c..a875555af13 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceCorsTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceCorsTest.java @@ -35,7 +35,7 @@ import org.junit.jupiter.api.io.TempDir; public class JsonRpcHttpServiceCorsTest { - @TempDir private static Path folder; + @TempDir private Path folder; private final Vertx vertx = Vertx.vertx(); private final OkHttpClient client = new OkHttpClient(); diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceLoginTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceLoginTest.java index 8d087bbd4e9..7b9eac24788 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceLoginTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceLoginTest.java @@ -90,6 +90,7 @@ @ExtendWith(MockitoExtension.class) public class JsonRpcHttpServiceLoginTest { + // this tempDir is deliberately static @TempDir private static Path folder; private static final Vertx vertx = Vertx.vertx(); diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceRpcApisTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceRpcApisTest.java index b259d9d3ab0..6870c4fed03 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceRpcApisTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceRpcApisTest.java @@ -88,7 +88,7 @@ @ExtendWith(MockitoExtension.class) public class JsonRpcHttpServiceRpcApisTest { - @TempDir private static Path folder; + @TempDir private Path folder; private final Vertx vertx = Vertx.vertx(); private final OkHttpClient client = new OkHttpClient(); diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTestBase.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTestBase.java index 1b5e58529b8..580af7b7467 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTestBase.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTestBase.java @@ -67,6 +67,7 @@ public class JsonRpcHttpServiceTestBase { + // this tempDir is deliberately static @TempDir private static Path folder; protected final JsonRpcTestHelper testHelper = new JsonRpcTestHelper(); diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTlsClientAuthTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTlsClientAuthTest.java index 46eee17ea6a..3a9a5577a1d 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTlsClientAuthTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTlsClientAuthTest.java @@ -79,6 +79,7 @@ import org.junit.jupiter.api.io.TempDir; public class JsonRpcHttpServiceTlsClientAuthTest { + // this tempDir is deliberately static @TempDir private static Path folder; protected static final Vertx vertx = Vertx.vertx(); diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugStandardTraceBlockToFileTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugStandardTraceBlockToFileTest.java index 073c604c111..42ec4c697f5 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugStandardTraceBlockToFileTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugStandardTraceBlockToFileTest.java @@ -44,6 +44,7 @@ public class DebugStandardTraceBlockToFileTest { + // this tempDir is deliberately static @TempDir private static Path folder; private final WorldStateArchive archive = diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/processor/TransactionTracerTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/processor/TransactionTracerTest.java index 70c6812c5cd..57c627a0664 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/processor/TransactionTracerTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/processor/TransactionTracerTest.java @@ -66,7 +66,7 @@ @MockitoSettings(strictness = Strictness.LENIENT) public class TransactionTracerTest { - @TempDir private static Path traceDir; + @TempDir private Path traceDir; @Mock private ProtocolSchedule protocolSchedule; @Mock private Blockchain blockchain; diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/query/BlockchainQueriesLogCacheTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/query/BlockchainQueriesLogCacheTest.java index 77476cd97d7..71cbc26515b 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/query/BlockchainQueriesLogCacheTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/query/BlockchainQueriesLogCacheTest.java @@ -58,6 +58,7 @@ @MockitoSettings(strictness = Strictness.LENIENT) public class BlockchainQueriesLogCacheTest { + // this tempDir is deliberately static @TempDir private static Path cacheDir; private static LogsQuery logsQuery; diff --git a/ethereum/core/src/integration-test/java/org/hyperledger/besu/ethereum/mainnet/precompiles/privacy/PrivacyPrecompiledContractIntegrationTest.java b/ethereum/core/src/integration-test/java/org/hyperledger/besu/ethereum/mainnet/precompiles/privacy/PrivacyPrecompiledContractIntegrationTest.java index 2c6e07433f0..d14e682e367 100644 --- a/ethereum/core/src/integration-test/java/org/hyperledger/besu/ethereum/mainnet/precompiles/privacy/PrivacyPrecompiledContractIntegrationTest.java +++ b/ethereum/core/src/integration-test/java/org/hyperledger/besu/ethereum/mainnet/precompiles/privacy/PrivacyPrecompiledContractIntegrationTest.java @@ -72,6 +72,7 @@ public class PrivacyPrecompiledContractIntegrationTest { + // this tempDir is deliberately static @TempDir private static Path folder; private static final Bytes VALID_PRIVATE_TRANSACTION_RLP = diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/util/RawBlockIteratorTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/util/RawBlockIteratorTest.java index 7581fe7f75e..408377b7178 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/util/RawBlockIteratorTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/util/RawBlockIteratorTest.java @@ -38,7 +38,7 @@ public class RawBlockIteratorTest { - @TempDir private static Path tmp; + @TempDir private Path tmp; private BlockDataGenerator gen; @BeforeEach diff --git a/ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/peers/StaticNodesParserTest.java b/ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/peers/StaticNodesParserTest.java index 91f5e2d602e..6764126222e 100644 --- a/ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/peers/StaticNodesParserTest.java +++ b/ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/peers/StaticNodesParserTest.java @@ -68,7 +68,7 @@ public class StaticNodesParserTest { .discoveryAndListeningPorts(30306) .build()); - @TempDir private static Path testFolder; + @TempDir private Path testFolder; @Test public void validFileLoadsWithExpectedEnodes() throws IOException, URISyntaxException { From d2bd021fca3047e16034107e83aa9266bce00ef6 Mon Sep 17 00:00:00 2001 From: Gabriel Fukushima Date: Thu, 7 Dec 2023 17:07:57 +1100 Subject: [PATCH 16/28] Remove parallelism usage from mainnet AT (#6252) * Remove parallelism usage from mainnet AT Signed-off-by: Gabriel Fukushima * Increase parallelism usage from mainnet AT Signed-off-by: Gabriel Fukushima * Add the split command back Signed-off-by: Gabriel Fukushima --------- Signed-off-by: Gabriel Fukushima --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index bff2f447944..bcd81e45cbe 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -211,7 +211,7 @@ jobs: - capture_test_results acceptanceTests: - parallelism: 2 + parallelism: 4 executor: xl_machine_executor # needs the machine executor since privacy test uses container tests (docker) steps: - prepare From ce0f30c886813b190ff04e3a78651e8504e7097a Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Thu, 7 Dec 2023 16:52:02 +1000 Subject: [PATCH 17/28] fix log params (#6254) Signed-off-by: Sally MacFarlane Co-authored-by: Stefan Pingel <16143240+pinges@users.noreply.github.com> --- .../besu/ethereum/eth/manager/EthProtocolManager.java | 6 +++++- .../besu/ethereum/eth/sync/ChainHeadTracker.java | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManager.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManager.java index 8b14197b007..6925df9d490 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManager.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManager.java @@ -456,7 +456,11 @@ private void handleStatusMessage(final EthPeer peer, final Message message) { message.getConnection()); } } catch (final RLPException e) { - LOG.debug("Unable to parse status message from peer {}.", peer, e); + LOG.atDebug() + .setMessage("Unable to parse status message from peer {}... {}") + .addArgument(peer::getShortNodeId) + .addArgument(e) + .log(); // Parsing errors can happen when clients broadcast network ids outside the int range, // So just disconnect with "subprotocol" error rather than "breach of protocol". peer.disconnect(DisconnectReason.SUBPROTOCOL_TRIGGERED); diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/ChainHeadTracker.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/ChainHeadTracker.java index 5e4862da1ec..b67d3101931 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/ChainHeadTracker.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/ChainHeadTracker.java @@ -95,7 +95,11 @@ public void onPeerConnected(final EthPeer peer) { .addArgument(peer::getShortNodeId) .log(); } else { - LOG.debug("Failed to retrieve chain head info. Disconnecting {}", peer, error); + LOG.atDebug() + .setMessage("Failed to retrieve chain head info. Disconnecting {}... {}") + .addArgument(peer::getShortNodeId) + .addArgument(error) + .log(); peer.disconnect(DisconnectReason.USELESS_PEER); } }); From ecb23ba78bc0fae31e0de39c536b76ceac9f62e6 Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Thu, 7 Dec 2023 17:31:17 +1000 Subject: [PATCH 18/28] add dependency on jar task (#6255) Signed-off-by: Sally MacFarlane --- acceptance-tests/tests/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/acceptance-tests/tests/build.gradle b/acceptance-tests/tests/build.gradle index cc4a54b009b..464805779c8 100644 --- a/acceptance-tests/tests/build.gradle +++ b/acceptance-tests/tests/build.gradle @@ -98,7 +98,7 @@ sourceSets { } } -processTestResources.dependsOn(':acceptance-tests:test-plugins:testPluginsJar') +processTestResources.dependsOn(':acceptance-tests:test-plugins:testPluginsJar',':acceptance-tests:test-plugins:jar') task acceptanceTest(type: Test) { inputs.property "integration.date", LocalTime.now() // so it runs at every invocation From 3bfe59722a3416807d31f83a96e7387b319837b6 Mon Sep 17 00:00:00 2001 From: Fabio Di Fabio Date: Thu, 7 Dec 2023 18:28:34 +0100 Subject: [PATCH 19/28] Fix and test that the BlockAwareOperationTracer methods are invoked the correct number of times (#6259) * Test that the BlockAwareOperationTracer are invoked the correct number of times * Remove redundant calls to traceEndBlock Signed-off-by: Fabio Di Fabio --- .../besu/services/TraceServiceImpl.java | 2 - .../besu/services/TraceServiceImplTest.java | 103 ++++++++++++++++-- 2 files changed, 94 insertions(+), 11 deletions(-) diff --git a/besu/src/main/java/org/hyperledger/besu/services/TraceServiceImpl.java b/besu/src/main/java/org/hyperledger/besu/services/TraceServiceImpl.java index 02fff10d2fb..3ab2961734f 100644 --- a/besu/src/main/java/org/hyperledger/besu/services/TraceServiceImpl.java +++ b/besu/src/main/java/org/hyperledger/besu/services/TraceServiceImpl.java @@ -162,7 +162,6 @@ public void trace( blocks.forEach( block -> { results.addAll(trace(blockchain, block, chainUpdater, tracer)); - tracer.traceEndBlock(block.getHeader(), block.getBody()); }); afterTracing.accept(chainUpdater.getNextUpdater()); return Optional.of(results); @@ -180,7 +179,6 @@ private Optional> trace( block.getHash(), traceableState -> Optional.of(trace(blockchain, block, new ChainUpdater(traceableState), tracer))); - tracer.traceEndBlock(block.getHeader(), block.getBody()); return results; } diff --git a/besu/src/test/java/org/hyperledger/besu/services/TraceServiceImplTest.java b/besu/src/test/java/org/hyperledger/besu/services/TraceServiceImplTest.java index 30d51cfa737..f7ae97cdf57 100644 --- a/besu/src/test/java/org/hyperledger/besu/services/TraceServiceImplTest.java +++ b/besu/src/test/java/org/hyperledger/besu/services/TraceServiceImplTest.java @@ -15,31 +15,46 @@ package org.hyperledger.besu.services; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; import org.hyperledger.besu.datatypes.Address; +import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import org.hyperledger.besu.ethereum.chain.MutableBlockchain; +import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil; import org.hyperledger.besu.ethereum.worldstate.DataStorageFormat; import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; import org.hyperledger.besu.evm.log.Log; import org.hyperledger.besu.evm.worldstate.WorldView; +import org.hyperledger.besu.plugin.data.BlockBody; +import org.hyperledger.besu.plugin.data.BlockHeader; import org.hyperledger.besu.plugin.data.BlockTraceResult; import org.hyperledger.besu.plugin.data.TransactionTraceResult; import org.hyperledger.besu.plugin.services.TraceService; import org.hyperledger.besu.plugin.services.tracer.BlockAwareOperationTracer; +import java.util.HashSet; import java.util.List; +import java.util.Optional; +import java.util.Set; +import java.util.stream.LongStream; import org.apache.tuweni.bytes.Bytes; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.junit.runner.RunWith; -import org.mockito.junit.MockitoJUnitRunner; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) class TraceServiceImplTest { TraceService traceService; @@ -73,19 +88,40 @@ void shouldRetrieveStateUpdatePostTracingForOneBlock() { final long persistedNonceForAccount = worldStateArchive.getMutable().get(addressToVerify).getNonce(); + final long blockNumber = 2; + + final BlockAwareOperationTracer opTracer = mock(BlockAwareOperationTracer.class); + traceService.trace( - 2, - 2, + blockNumber, + blockNumber, worldState -> { assertThat(worldState.get(addressToVerify).getNonce()).isEqualTo(1); }, worldState -> { assertThat(worldState.get(addressToVerify).getNonce()).isEqualTo(2); }, - BlockAwareOperationTracer.NO_TRACING); + opTracer); assertThat(worldStateArchive.getMutable().get(addressToVerify).getNonce()) .isEqualTo(persistedNonceForAccount); + + final Block tracedBlock = blockchain.getBlockByNumber(blockNumber).get(); + + verify(opTracer).traceStartBlock(tracedBlock.getHeader(), tracedBlock.getBody()); + + tracedBlock + .getBody() + .getTransactions() + .forEach( + tx -> { + verify(opTracer).traceStartTransaction(any(), eq(tx)); + verify(opTracer) + .traceEndTransaction( + any(), eq(tx), anyBoolean(), any(), any(), anyLong(), anyLong()); + }); + + verify(opTracer).traceEndBlock(tracedBlock.getHeader(), tracedBlock.getBody()); } @Test @@ -96,9 +132,13 @@ void shouldRetrieveStateUpdatePostTracingForAllBlocks() { final long persistedNonceForAccount = worldStateArchive.getMutable().get(addressToVerify).getNonce(); + final long startBlock = 1; + final long endBlock = 32; + final BlockAwareOperationTracer opTracer = mock(BlockAwareOperationTracer.class); + traceService.trace( - 0, - 32, + startBlock, + endBlock, worldState -> { assertThat(worldState.get(addressToVerify).getNonce()).isEqualTo(0); }, @@ -106,10 +146,30 @@ void shouldRetrieveStateUpdatePostTracingForAllBlocks() { assertThat(worldState.get(addressToVerify).getNonce()) .isEqualTo(persistedNonceForAccount); }, - BlockAwareOperationTracer.NO_TRACING); + opTracer); assertThat(worldStateArchive.getMutable().get(addressToVerify).getNonce()) .isEqualTo(persistedNonceForAccount); + + LongStream.rangeClosed(startBlock, endBlock) + .mapToObj(blockchain::getBlockByNumber) + .map(Optional::get) + .forEach( + tracedBlock -> { + verify(opTracer).traceStartBlock(tracedBlock.getHeader(), tracedBlock.getBody()); + tracedBlock + .getBody() + .getTransactions() + .forEach( + tx -> { + verify(opTracer).traceStartTransaction(any(), eq(tx)); + verify(opTracer) + .traceEndTransaction( + any(), eq(tx), anyBoolean(), any(), any(), anyLong(), anyLong()); + }); + + verify(opTracer).traceEndBlock(tracedBlock.getHeader(), tracedBlock.getBody()); + }); } @Test @@ -197,8 +257,16 @@ private static class TxStartEndTracer implements BlockAwareOperationTracer { public long txEndGasUsed; public Long txEndTimeNs; + private final Set traceStartTxCalled = new HashSet<>(); + private final Set traceEndTxCalled = new HashSet<>(); + private final Set traceStartBlockCalled = new HashSet<>(); + private final Set traceEndBlockCalled = new HashSet<>(); + @Override public void traceStartTransaction(final WorldView worldView, final Transaction transaction) { + if (!traceStartTxCalled.add(transaction)) { + fail("traceStartTransaction already called for tx " + transaction); + } txStartWorldView = worldView; txStartTransaction = transaction; } @@ -212,6 +280,9 @@ public void traceEndTransaction( final List logs, final long gasUsed, final long timeNs) { + if (!traceEndTxCalled.add(transaction)) { + fail("traceEndTransaction already called for tx " + transaction); + } txEndWorldView = worldView; txEndTransaction = transaction; txEndStatus = status; @@ -220,5 +291,19 @@ public void traceEndTransaction( txEndGasUsed = gasUsed; txEndTimeNs = timeNs; } + + @Override + public void traceStartBlock(final BlockHeader blockHeader, final BlockBody blockBody) { + if (!traceStartBlockCalled.add(blockHeader.getBlockHash())) { + fail("traceStartBlock already called for block " + blockHeader); + } + } + + @Override + public void traceEndBlock(final BlockHeader blockHeader, final BlockBody blockBody) { + if (!traceEndBlockCalled.add(blockHeader.getBlockHash())) { + fail("traceEndBlock already called for block " + blockHeader); + } + } } } From 7975ceb60e28f2d34851b4dd13d64dfb5ec0fe6a Mon Sep 17 00:00:00 2001 From: Gabriel-Trintinalia Date: Fri, 8 Dec 2023 10:43:10 +1100 Subject: [PATCH 20/28] [RPC] Use apiConfiguration to limit gasPrice in eth_getGasPrice (#6243) Signed-off-by: Gabriel-Trintinalia --- .../org/hyperledger/besu/cli/BesuCommand.java | 42 +++---- .../hyperledger/besu/cli/BesuCommandTest.java | 29 ++--- .../besu/ethereum/api/ApiConfiguration.java | 14 +-- .../internal/methods/EthFeeHistory.java | 26 ++--- .../jsonrpc/internal/methods/EthGasPrice.java | 53 +++++++-- .../jsonrpc/methods/EthJsonRpcMethods.java | 2 +- .../internal/methods/EthFeeHistoryTest.java | 6 +- .../internal/methods/EthGasPriceTest.java | 104 ++++++++++++++++-- 8 files changed, 196 insertions(+), 80 deletions(-) diff --git a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java index a4045cee1c5..b2cd625e9ec 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java @@ -1218,27 +1218,27 @@ static class PermissionsOptionGroup { private final Long apiGasPriceMax = 500_000_000_000L; @CommandLine.Option( - names = {"--api-priority-fee-limiting-enabled"}, + names = {"--api-gas-and-priority-fee-limiting-enabled"}, hidden = true, description = - "Set to enable priority fee limit in eth_feeHistory (default: ${DEFAULT-VALUE})") - private final Boolean apiPriorityFeeLimitingEnabled = false; + "Set to enable gas price and minimum priority fee limit in eth_getGasPrice and eth_feeHistory (default: ${DEFAULT-VALUE})") + private final Boolean apiGasAndPriorityFeeLimitingEnabled = false; @CommandLine.Option( - names = {"--api-priority-fee-lower-bound-coefficient"}, + names = {"--api-gas-and-priority-fee-lower-bound-coefficient"}, hidden = true, description = - "Coefficient for setting the lower limit of minimum priority fee in eth_feeHistory (default: ${DEFAULT-VALUE})") - private final Long apiPriorityFeeLowerBoundCoefficient = - ApiConfiguration.DEFAULT_LOWER_BOUND_PRIORITY_FEE_COEFFICIENT; + "Coefficient for setting the lower limit of gas price and minimum priority fee in eth_getGasPrice and eth_feeHistory (default: ${DEFAULT-VALUE})") + private final Long apiGasAndPriorityFeeLowerBoundCoefficient = + ApiConfiguration.DEFAULT_LOWER_BOUND_GAS_AND_PRIORITY_FEE_COEFFICIENT; @CommandLine.Option( - names = {"--api-priority-fee-upper-bound-coefficient"}, + names = {"--api-gas-and-priority-fee-upper-bound-coefficient"}, hidden = true, description = - "Coefficient for setting the upper limit of minimum priority fee in eth_feeHistory (default: ${DEFAULT-VALUE})") - private final Long apiPriorityFeeUpperBoundCoefficient = - ApiConfiguration.DEFAULT_UPPER_BOUND_PRIORITY_FEE_COEFFICIENT; + "Coefficient for setting the upper limit of gas price and minimum priority fee in eth_getGasPrice and eth_feeHistory (default: ${DEFAULT-VALUE})") + private final Long apiGasAndPriorityFeeUpperBoundCoefficient = + ApiConfiguration.DEFAULT_UPPER_BOUND_GAS_AND_PRIORITY_FEE_COEFFICIENT; @CommandLine.Option( names = {"--static-nodes-file"}, @@ -1902,11 +1902,11 @@ private void checkApiOptionsDependencies() { CommandLineUtils.checkOptionDependencies( logger, commandLine, - "--api-priority-fee-limiting-enabled", - !apiPriorityFeeLimitingEnabled, + "--api-gas-and-priority-fee-limiting-enabled", + !apiGasAndPriorityFeeLimitingEnabled, asList( - "--api-priority-fee-upper-bound-coefficient", - "--api-priority-fee-lower-bound-coefficient")); + "--api-gas-and-priority-fee-upper-bound-coefficient", + "--api-gas-and-priority-fee-lower-bound-coefficient")); } private void ensureValidPeerBoundParams() { @@ -2534,16 +2534,16 @@ private ApiConfiguration apiConfiguration() { .gasPriceMax(apiGasPriceMax) .maxLogsRange(rpcMaxLogsRange) .gasCap(rpcGasCap) - .isPriorityFeeLimitingEnabled(apiPriorityFeeLimitingEnabled); - if (apiPriorityFeeLimitingEnabled) { - if (apiPriorityFeeLowerBoundCoefficient > apiPriorityFeeUpperBoundCoefficient) { + .isGasAndPriorityFeeLimitingEnabled(apiGasAndPriorityFeeLimitingEnabled); + if (apiGasAndPriorityFeeLimitingEnabled) { + if (apiGasAndPriorityFeeLowerBoundCoefficient > apiGasAndPriorityFeeUpperBoundCoefficient) { throw new ParameterException( this.commandLine, - "--api-priority-fee-lower-bound-coefficient cannot be greater than the value of --api-priority-fee-upper-bound-coefficient"); + "--api-gas-and-priority-fee-lower-bound-coefficient cannot be greater than the value of --api-gas-and-priority-fee-upper-bound-coefficient"); } builder - .lowerBoundPriorityFeeCoefficient(apiPriorityFeeLowerBoundCoefficient) - .upperBoundPriorityFeeCoefficient(apiPriorityFeeUpperBoundCoefficient); + .lowerBoundGasAndPriorityFeeCoefficient(apiGasAndPriorityFeeLowerBoundCoefficient) + .upperBoundGasAndPriorityFeeCoefficient(apiGasAndPriorityFeeUpperBoundCoefficient); } return builder.build(); } diff --git a/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java b/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java index 0df397af71f..955c9df7aaf 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java @@ -1611,11 +1611,12 @@ public void rpcGasCapOptionMustBeUsed() { @Test public void apiPriorityFeeLimitingEnabledOptionMustBeUsed() { - parseCommand("--api-priority-fee-limiting-enabled"); + parseCommand("--api-gas-and-priority-fee-limiting-enabled"); verify(mockRunnerBuilder).apiConfiguration(apiConfigurationCaptor.capture()); verify(mockRunnerBuilder).build(); assertThat(apiConfigurationCaptor.getValue()) - .isEqualTo(ImmutableApiConfiguration.builder().isPriorityFeeLimitingEnabled(true).build()); + .isEqualTo( + ImmutableApiConfiguration.builder().isGasAndPriorityFeeLimitingEnabled(true).build()); assertThat(commandOutput.toString(UTF_8)).isEmpty(); assertThat(commandErrorOutput.toString(UTF_8)).isEmpty(); @@ -1625,16 +1626,16 @@ public void apiPriorityFeeLimitingEnabledOptionMustBeUsed() { public void apiPriorityFeeLowerBoundCoefficientOptionMustBeUsed() { final long lowerBound = 150L; parseCommand( - "--api-priority-fee-lower-bound-coefficient", + "--api-gas-and-priority-fee-lower-bound-coefficient", Long.toString(lowerBound), - "--api-priority-fee-limiting-enabled"); + "--api-gas-and-priority-fee-limiting-enabled"); verify(mockRunnerBuilder).apiConfiguration(apiConfigurationCaptor.capture()); verify(mockRunnerBuilder).build(); assertThat(apiConfigurationCaptor.getValue()) .isEqualTo( ImmutableApiConfiguration.builder() - .lowerBoundPriorityFeeCoefficient(lowerBound) - .isPriorityFeeLimitingEnabled(true) + .lowerBoundGasAndPriorityFeeCoefficient(lowerBound) + .isGasAndPriorityFeeLimitingEnabled(true) .build()); assertThat(commandOutput.toString(UTF_8)).isEmpty(); @@ -1648,32 +1649,32 @@ public void apiPriorityFeeLowerBoundCoefficientOptionMustBeUsed() { final long upperBound = 100L; parseCommand( - "--api-priority-fee-limiting-enabled", - "--api-priority-fee-lower-bound-coefficient", + "--api-gas-and-priority-fee-limiting-enabled", + "--api-gas-and-priority-fee-lower-bound-coefficient", Long.toString(lowerBound), - "--api-priority-fee-upper-bound-coefficient", + "--api-gas-and-priority-fee-upper-bound-coefficient", Long.toString(upperBound)); Mockito.verifyNoInteractions(mockRunnerBuilder); assertThat(commandOutput.toString(UTF_8)).isEmpty(); assertThat(commandErrorOutput.toString(UTF_8)) .contains( - "--api-priority-fee-lower-bound-coefficient cannot be greater than the value of --api-priority-fee-upper-bound-coefficient"); + "--api-gas-and-priority-fee-lower-bound-coefficient cannot be greater than the value of --api-gas-and-priority-fee-upper-bound-coefficient"); } @Test public void apiPriorityFeeUpperBoundCoefficientsOptionMustBeUsed() { final long upperBound = 200L; parseCommand( - "--api-priority-fee-upper-bound-coefficient", + "--api-gas-and-priority-fee-upper-bound-coefficient", Long.toString(upperBound), - "--api-priority-fee-limiting-enabled"); + "--api-gas-and-priority-fee-limiting-enabled"); verify(mockRunnerBuilder).apiConfiguration(apiConfigurationCaptor.capture()); verify(mockRunnerBuilder).build(); assertThat(apiConfigurationCaptor.getValue()) .isEqualTo( ImmutableApiConfiguration.builder() - .upperBoundPriorityFeeCoefficient(upperBound) - .isPriorityFeeLimitingEnabled(true) + .upperBoundGasAndPriorityFeeCoefficient(upperBound) + .isGasAndPriorityFeeLimitingEnabled(true) .build()); assertThat(commandOutput.toString(UTF_8)).isEmpty(); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/ApiConfiguration.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/ApiConfiguration.java index e277c2ba2ff..e9f30fca336 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/ApiConfiguration.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/ApiConfiguration.java @@ -24,8 +24,8 @@ @Value.Style(allParameters = true) public abstract class ApiConfiguration { - public static final long DEFAULT_LOWER_BOUND_PRIORITY_FEE_COEFFICIENT = 0L; - public static final long DEFAULT_UPPER_BOUND_PRIORITY_FEE_COEFFICIENT = Long.MAX_VALUE; + public static final long DEFAULT_LOWER_BOUND_GAS_AND_PRIORITY_FEE_COEFFICIENT = 0L; + public static final long DEFAULT_UPPER_BOUND_GAS_AND_PRIORITY_FEE_COEFFICIENT = Long.MAX_VALUE; @Value.Default public long getGasPriceBlocks() { @@ -64,17 +64,17 @@ public Long getGasCap() { } @Value.Default - public boolean isPriorityFeeLimitingEnabled() { + public boolean isGasAndPriorityFeeLimitingEnabled() { return false; } @Value.Default - public Long getLowerBoundPriorityFeeCoefficient() { - return DEFAULT_LOWER_BOUND_PRIORITY_FEE_COEFFICIENT; + public Long getLowerBoundGasAndPriorityFeeCoefficient() { + return DEFAULT_LOWER_BOUND_GAS_AND_PRIORITY_FEE_COEFFICIENT; } @Value.Default - public Long getUpperBoundPriorityFeeCoefficient() { - return DEFAULT_UPPER_BOUND_PRIORITY_FEE_COEFFICIENT; + public Long getUpperBoundGasAndPriorityFeeCoefficient() { + return DEFAULT_UPPER_BOUND_GAS_AND_PRIORITY_FEE_COEFFICIENT; } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistory.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistory.java index e4d71ae8e79..4455bd30b55 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistory.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistory.java @@ -218,7 +218,7 @@ public List computeRewards(final List rewardPercentiles, final Bloc // If the priority fee boundary is set, return the bounded rewards. Otherwise, return the real // rewards. - if (apiConfiguration.isPriorityFeeLimitingEnabled()) { + if (apiConfiguration.isGasAndPriorityFeeLimitingEnabled()) { return boundRewards(realRewards); } else { return realRewards; @@ -263,9 +263,13 @@ private List calculateRewards( private List boundRewards(final List rewards) { Wei minPriorityFee = miningCoordinator.getMinPriorityFeePerGas(); Wei lowerBound = - minPriorityFee.multiply(apiConfiguration.getLowerBoundPriorityFeeCoefficient()).divide(100); + minPriorityFee + .multiply(apiConfiguration.getLowerBoundGasAndPriorityFeeCoefficient()) + .divide(100); Wei upperBound = - minPriorityFee.multiply(apiConfiguration.getUpperBoundPriorityFeeCoefficient()).divide(100); + minPriorityFee + .multiply(apiConfiguration.getUpperBoundGasAndPriorityFeeCoefficient()) + .divide(100); return rewards.stream().map(reward -> boundReward(reward, lowerBound, upperBound)).toList(); } @@ -279,19 +283,9 @@ private List boundRewards(final List rewards) { * @return The bounded reward. */ private Wei boundReward(final Wei reward, final Wei lowerBound, final Wei upperBound) { - - // If the reward is less than the lower bound, return the lower bound. - if (reward.compareTo(lowerBound) <= 0) { - return lowerBound; - } - - // If the reward is greater than the upper bound, return the upper bound. - if (reward.compareTo(upperBound) > 0) { - return upperBound; - } - - // If the reward is within the bounds, return the reward as is. - return reward; + return reward.compareTo(lowerBound) <= 0 + ? lowerBound + : reward.compareTo(upperBound) >= 0 ? upperBound : reward; } private List calculateTransactionsGasUsed(final Block block) { diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGasPrice.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGasPrice.java index 117fdbdcbb1..4913f70ede1 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGasPrice.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGasPrice.java @@ -14,6 +14,8 @@ */ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods; +import org.hyperledger.besu.datatypes.Wei; +import org.hyperledger.besu.ethereum.api.ApiConfiguration; import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; @@ -22,22 +24,29 @@ import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import org.hyperledger.besu.ethereum.blockcreation.MiningCoordinator; +import java.util.Optional; import java.util.function.Supplier; public class EthGasPrice implements JsonRpcMethod { private final Supplier blockchain; private final MiningCoordinator miningCoordinator; + private final ApiConfiguration apiConfiguration; public EthGasPrice( - final BlockchainQueries blockchain, final MiningCoordinator miningCoordinator) { - this(() -> blockchain, miningCoordinator); + final BlockchainQueries blockchain, + final MiningCoordinator miningCoordinator, + final ApiConfiguration apiConfiguration) { + this(() -> blockchain, miningCoordinator, apiConfiguration); } public EthGasPrice( - final Supplier blockchain, final MiningCoordinator miningCoordinator) { + final Supplier blockchain, + final MiningCoordinator miningCoordinator, + final ApiConfiguration apiConfiguration) { this.blockchain = blockchain; this.miningCoordinator = miningCoordinator; + this.apiConfiguration = apiConfiguration; } @Override @@ -48,11 +57,37 @@ public String getName() { @Override public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { return new JsonRpcSuccessResponse( - requestContext.getRequest().getId(), - blockchain - .get() - .gasPrice() - .map(Quantity::create) - .orElseGet(() -> Quantity.create(miningCoordinator.getMinTransactionGasPrice()))); + requestContext.getRequest().getId(), Quantity.create(calculateGasPrice())); + } + + private Wei calculateGasPrice() { + Wei gasPrice = getGasPrice().orElseGet(miningCoordinator::getMinTransactionGasPrice); + return isGasPriceLimitingEnabled() ? limitGasPrice(gasPrice) : gasPrice; + } + + private Optional getGasPrice() { + return blockchain.get().gasPrice().map(Wei::of); + } + + private boolean isGasPriceLimitingEnabled() { + return apiConfiguration.isGasAndPriorityFeeLimitingEnabled(); + } + + private Wei limitGasPrice(final Wei gasPrice) { + Wei minTransactionGasPrice = miningCoordinator.getMinTransactionGasPrice(); + Wei lowerBound = + calculateBound( + minTransactionGasPrice, apiConfiguration.getLowerBoundGasAndPriorityFeeCoefficient()); + Wei upperBound = + calculateBound( + minTransactionGasPrice, apiConfiguration.getUpperBoundGasAndPriorityFeeCoefficient()); + + return gasPrice.compareTo(lowerBound) <= 0 + ? lowerBound + : gasPrice.compareTo(upperBound) >= 0 ? upperBound : gasPrice; + } + + private Wei calculateBound(final Wei price, final long coefficient) { + return price.multiply(coefficient).divide(100); } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EthJsonRpcMethods.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EthJsonRpcMethods.java index 9d70e681fdf..88b9348edf0 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EthJsonRpcMethods.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EthJsonRpcMethods.java @@ -174,7 +174,7 @@ protected Map create() { new EthMining(miningCoordinator), new EthCoinbase(miningCoordinator), new EthProtocolVersion(supportedCapabilities), - new EthGasPrice(blockchainQueries, miningCoordinator), + new EthGasPrice(blockchainQueries, miningCoordinator, apiConfiguration), new EthGetWork(miningCoordinator), new EthSubmitWork(miningCoordinator), new EthHashrate(miningCoordinator), diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistoryTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistoryTest.java index bffd9278e37..7d58848a132 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistoryTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistoryTest.java @@ -174,9 +174,9 @@ public void shouldBoundRewardsCorrectly() { ApiConfiguration apiConfiguration = ImmutableApiConfiguration.builder() - .isPriorityFeeLimitingEnabled(true) - .lowerBoundPriorityFeeCoefficient(200L) // Min reward = Wei.One * 200L / 100 = 2.0 - .upperBoundPriorityFeeCoefficient(500L) + .isGasAndPriorityFeeLimitingEnabled(true) + .lowerBoundGasAndPriorityFeeCoefficient(200L) // Min reward = Wei.One * 200L / 100 = 2.0 + .upperBoundGasAndPriorityFeeCoefficient(500L) .build(); // Max reward = Wei.One * 500L / 100 = 5.0 EthFeeHistory ethFeeHistory = diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGasPriceTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGasPriceTest.java index 27462501010..cd1e890fd41 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGasPriceTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGasPriceTest.java @@ -23,6 +23,7 @@ import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.Wei; +import org.hyperledger.besu.ethereum.api.ApiConfiguration; import org.hyperledger.besu.ethereum.api.ImmutableApiConfiguration; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext; @@ -60,15 +61,8 @@ public class EthGasPriceTest { @BeforeEach public void setUp() { - method = - new EthGasPrice( - new BlockchainQueries( - blockchain, - null, - Optional.empty(), - Optional.empty(), - ImmutableApiConfiguration.builder().gasPriceMinSupplier(() -> 100).build()), - miningCoordinator); + ApiConfiguration apiConfig = createDefaultApiConfiguration(); + method = createEthGasPriceMethod(apiConfig); } @Test @@ -141,6 +135,68 @@ public void shortChainQueriesAllBlocks() { verifyNoMoreInteractions(blockchain); } + /** + * Test to verify that the method returns the lower bound gas price when the lower bound parameter + * is present. + */ + @Test + public void shouldReturnLimitedPriceWhenLowerBoundIsPresent() { + long gasPrice = 5000000; + long lowerBoundGasPrice = gasPrice + 1; + verifyGasPriceLimit(lowerBoundGasPrice, null, lowerBoundGasPrice); + } + + /** + * Test to verify that the method returns the upper bound gas price when the upper bound parameter + * is present. + */ + @Test + public void shouldReturnLimitedPriceWhenUpperBoundIsPresent() { + long gasPrice = 5000000; + long upperBoundGasPrice = gasPrice - 1; + verifyGasPriceLimit(null, upperBoundGasPrice, upperBoundGasPrice); + } + + /** + * Test to verify that the method returns the actual gas price when the gas price is within the + * bound range. + */ + @Test + public void shouldReturnActualGasPriceWhenWithinBoundRange() { + long gasPrice = 5000000; + long lowerBoundGasPrice = gasPrice - 1; + long upperBoundGasPrice = gasPrice + 1; + verifyGasPriceLimit(lowerBoundGasPrice, upperBoundGasPrice, gasPrice); + } + + /** + * Helper method to verify the gas price limit. + * + * @param lowerBound The lower bound of the gas price. + * @param upperBound The upper bound of the gas price. + * @param expectedGasPrice The expected gas price. + */ + private void verifyGasPriceLimit( + final Long lowerBound, final Long upperBound, final long expectedGasPrice) { + when(miningCoordinator.getMinTransactionGasPrice()).thenReturn(Wei.of(100)); + + var apiConfig = + createApiConfiguration(Optional.ofNullable(lowerBound), Optional.ofNullable(upperBound)); + method = createEthGasPriceMethod(apiConfig); + + final JsonRpcRequestContext request = requestWithParams(); + final JsonRpcResponse expectedResponse = + new JsonRpcSuccessResponse( + request.getRequest().getId(), Wei.of(expectedGasPrice).toShortHexString()); + + when(blockchain.getChainHeadBlockNumber()).thenReturn(10L); + when(blockchain.getBlockByNumber(anyLong())) + .thenAnswer(invocation -> createFakeBlock(invocation.getArgument(0, Long.class))); + + final JsonRpcResponse actualResponse = method.response(request); + assertThat(actualResponse).usingRecursiveComparison().isEqualTo(expectedResponse); + } + private Object createFakeBlock(final Long height) { return Optional.of( new Block( @@ -210,4 +266,34 @@ private Object createEmptyBlock(final Long height) { private JsonRpcRequestContext requestWithParams(final Object... params) { return new JsonRpcRequestContext(new JsonRpcRequest(JSON_RPC_VERSION, ETH_METHOD, params)); } + + private ApiConfiguration createDefaultApiConfiguration() { + return createApiConfiguration(Optional.empty(), Optional.empty()); + } + + private ApiConfiguration createApiConfiguration( + final Optional lowerBound, final Optional upperBound) { + ImmutableApiConfiguration.Builder builder = + ImmutableApiConfiguration.builder().gasPriceMinSupplier(() -> 100); + + lowerBound.ifPresent( + value -> + builder + .isGasAndPriorityFeeLimitingEnabled(true) + .lowerBoundGasAndPriorityFeeCoefficient(value)); + upperBound.ifPresent( + value -> + builder + .isGasAndPriorityFeeLimitingEnabled(true) + .upperBoundGasAndPriorityFeeCoefficient(value)); + + return builder.build(); + } + + private EthGasPrice createEthGasPriceMethod(final ApiConfiguration apiConfig) { + return new EthGasPrice( + new BlockchainQueries(blockchain, null, Optional.empty(), Optional.empty(), apiConfig), + miningCoordinator, + apiConfig); + } } From 7a96a650d6668e5a6305a22fbfba75160bf0dd6e Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Mon, 11 Dec 2023 12:25:23 +1000 Subject: [PATCH 21/28] log bootnodes and static nodes list at debug level (#6273) * log bootnodes and static nodes list at debug level Signed-off-by: Sally MacFarlane * log if zero bootnodes Signed-off-by: Sally MacFarlane * null safeguards Signed-off-by: Sally MacFarlane --------- Signed-off-by: Sally MacFarlane --- .../java/org/hyperledger/besu/cli/BesuCommand.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java index b2cd625e9ec..b42c4aad977 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java @@ -2120,8 +2120,6 @@ private void configure() throws Exception { instantiateSignatureAlgorithmFactory(); logger.info(generateConfigurationOverview()); - logger.info("Connecting to {} static nodes.", staticNodes.size()); - logger.trace("Static Nodes = {}", staticNodes); logger.info("Security Module: {}", securityModuleName); } @@ -3119,9 +3117,14 @@ private EthNetworkConfig updateNetworkConfig(final NetworkName network) { if (listBootNodes != null) { if (!p2PDiscoveryOptionGroup.peerDiscoveryEnabled) { logger.warn("Discovery disabled: bootnodes will be ignored."); + } else { + logger.info("Configured {} bootnodes.", listBootNodes.size()); + logger.debug("Bootnodes = {}", listBootNodes); } DiscoveryConfiguration.assertValidBootnodes(listBootNodes); builder.setBootNodes(listBootNodes); + } else { + logger.info("0 Bootnodes configured"); } return builder.build(); } @@ -3224,7 +3227,11 @@ private Set loadStaticNodes() throws IOException { staticNodesPath = dataDir().resolve(staticNodesFilename); } logger.debug("Static Nodes file: {}", staticNodesPath); - return StaticNodesParser.fromPath(staticNodesPath, getEnodeDnsConfiguration()); + final Set staticNodes = + StaticNodesParser.fromPath(staticNodesPath, getEnodeDnsConfiguration()); + logger.info("Connecting to {} static nodes.", staticNodes.size()); + logger.debug("Static Nodes = {}", staticNodes); + return staticNodes; } private List buildEnodes( From 4bc04b29392bd58a986713b4faf3cecf5775e418 Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Mon, 11 Dec 2023 12:58:40 +1000 Subject: [PATCH 22/28] junit 5 (#6256) Signed-off-by: Sally MacFarlane --- acceptance-tests/test-plugins/build.gradle | 1 - .../services/BesuPluginContextImplTest.java | 10 +++---- .../jsonrpc/AbstractJsonRpcTest.java | 28 +++++++++---------- .../DebugReplayBlockAcceptanceTest.java | 23 +++++++-------- .../jsonrpc/DebugSetHeadAcceptanceTest.java | 23 +++++++-------- .../jsonrpc/EthEstimateGasAcceptanceTest.java | 6 ++-- ...ByNumberAndHashShanghaiAcceptanceTest.java | 24 +++++++--------- ...gineCancunBlockBuildingAcceptanceTest.java | 24 +++++++--------- .../ExecutionEngineEip6110AcceptanceTest.java | 23 +++++++-------- .../ExecutionEngineParisAcceptanceTest.java | 23 +++++++-------- ...ExecutionEngineShanghaiAcceptanceTest.java | 24 +++++++--------- .../ipc/Web3JSupportAcceptanceTest.java | 6 ++-- 12 files changed, 94 insertions(+), 121 deletions(-) diff --git a/acceptance-tests/test-plugins/build.gradle b/acceptance-tests/test-plugins/build.gradle index f9e960b4944..c31175cee8f 100644 --- a/acceptance-tests/test-plugins/build.gradle +++ b/acceptance-tests/test-plugins/build.gradle @@ -11,7 +11,6 @@ dependencies { implementation 'com.google.auto.service:auto-service' implementation 'info.picocli:picocli' - testImplementation 'junit:junit' testImplementation 'org.assertj:assertj-core' testImplementation 'org.junit.jupiter:junit-jupiter' diff --git a/acceptance-tests/test-plugins/src/test/java/org/hyperledger/besu/services/BesuPluginContextImplTest.java b/acceptance-tests/test-plugins/src/test/java/org/hyperledger/besu/services/BesuPluginContextImplTest.java index 5fd73b66b8f..57797462739 100644 --- a/acceptance-tests/test-plugins/src/test/java/org/hyperledger/besu/services/BesuPluginContextImplTest.java +++ b/acceptance-tests/test-plugins/src/test/java/org/hyperledger/besu/services/BesuPluginContextImplTest.java @@ -29,13 +29,13 @@ import org.assertj.core.api.Assertions; import org.assertj.core.api.ThrowableAssert; -import org.junit.After; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; public class BesuPluginContextImplTest { - @BeforeClass + @BeforeAll public static void createFakePluginDir() throws IOException { if (System.getProperty("besu.plugins.dir") == null) { final Path pluginDir = Files.createTempDirectory("besuTest"); @@ -44,7 +44,7 @@ public static void createFakePluginDir() throws IOException { } } - @After + @AfterEach public void clearTestPluginState() { System.clearProperty("testPicoCLIPlugin.testOption"); } diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/AbstractJsonRpcTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/AbstractJsonRpcTest.java index 508fb891c0e..86b037c1578 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/AbstractJsonRpcTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/AbstractJsonRpcTest.java @@ -30,7 +30,7 @@ import java.net.URISyntaxException; import java.net.URL; import java.util.Arrays; -import java.util.stream.Collectors; +import java.util.stream.Stream; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; @@ -40,10 +40,12 @@ import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; -import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; abstract class AbstractJsonRpcTest { - private static final MediaType MEDIA_TYPE_JSON = + protected static final MediaType MEDIA_TYPE_JSON = MediaType.parse("application/json; charset=utf-8"); static class JsonRpcTestsContext { @@ -69,16 +71,14 @@ public void tearDown() { } private final JsonRpcTestsContext testsContext; - private final URI testCaseFileURI; - public AbstractJsonRpcTest( - final String ignored, final JsonRpcTestsContext testsContext, final URI testCaseFileURI) { - this.testCaseFileURI = testCaseFileURI; + public AbstractJsonRpcTest(final JsonRpcTestsContext testsContext) { this.testsContext = testsContext; } - @Test - public void test() throws IOException { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("testCases") + public void test(final URI testCaseFileURI) throws IOException { final JsonRpcTestCase testCase = testsContext.mapper.readValue(testCaseFileURI.toURL(), JsonRpcTestCase.class); @@ -118,7 +118,7 @@ protected void evaluateResponse( final JsonRpcTestCase testCase, final URL url) {} - private String getRpcUrl(final String rpcMethod) { + protected String getRpcUrl(final String rpcMethod) { if (rpcMethod.contains("eth_") || rpcMethod.contains("engine_")) { return testsContext.besuNode.engineRpcUrl().get(); } @@ -126,14 +126,12 @@ private String getRpcUrl(final String rpcMethod) { return testsContext.besuNode.jsonRpcBaseUrl().get(); } - public static Iterable testCases(final String testCasesPath) throws URISyntaxException { + public static Stream testCasesFromPath(final String testCasesPath) + throws URISyntaxException { final File[] testCasesList = new File(AbstractJsonRpcTest.class.getResource(testCasesPath).toURI()).listFiles(); - return Arrays.stream(testCasesList) - .sorted() - .map(file -> new Object[] {file.getName(), file.toURI()}) - .collect(Collectors.toList()); + return Arrays.stream(testCasesList).sorted().map(File::toURI).map(Arguments::of); } } diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/DebugReplayBlockAcceptanceTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/DebugReplayBlockAcceptanceTest.java index 0b6f76f4de2..aa8547d83bb 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/DebugReplayBlockAcceptanceTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/DebugReplayBlockAcceptanceTest.java @@ -15,36 +15,33 @@ package org.hyperledger.besu.tests.acceptance.jsonrpc; import java.io.IOException; -import java.net.URI; import java.net.URISyntaxException; +import java.util.stream.Stream; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.params.provider.Arguments; -@RunWith(Parameterized.class) public class DebugReplayBlockAcceptanceTest extends AbstractJsonRpcTest { private static final String GENESIS_FILE = "/jsonrpc/debug/replayBlock/genesis.json"; private static final String TEST_CASE_PATH = "/jsonrpc/debug/replayBlock/test-cases/"; private static AbstractJsonRpcTest.JsonRpcTestsContext testsContext; - public DebugReplayBlockAcceptanceTest(final String ignored, final URI testCaseFileURI) { - super(ignored, testsContext, testCaseFileURI); + public DebugReplayBlockAcceptanceTest() { + super(testsContext); } - @BeforeClass + @BeforeAll public static void init() throws IOException { testsContext = new JsonRpcTestsContext(GENESIS_FILE); } - @Parameterized.Parameters(name = "{0}") - public static Iterable testCases() throws URISyntaxException { - return testCases(TEST_CASE_PATH); + public static Stream testCases() throws URISyntaxException { + return testCasesFromPath(TEST_CASE_PATH); } - @AfterClass + @AfterAll public static void tearDown() { testsContext.cluster.close(); } diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/DebugSetHeadAcceptanceTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/DebugSetHeadAcceptanceTest.java index b4db91a39aa..4a2b956efcd 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/DebugSetHeadAcceptanceTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/DebugSetHeadAcceptanceTest.java @@ -15,36 +15,33 @@ package org.hyperledger.besu.tests.acceptance.jsonrpc; import java.io.IOException; -import java.net.URI; import java.net.URISyntaxException; +import java.util.stream.Stream; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.params.provider.Arguments; -@RunWith(Parameterized.class) public class DebugSetHeadAcceptanceTest extends AbstractJsonRpcTest { private static final String GENESIS_FILE = "/jsonrpc/debug/setHead/genesis.json"; private static final String TEST_CASE_PATH = "/jsonrpc/debug/setHead/test-cases/"; private static JsonRpcTestsContext testsContext; - public DebugSetHeadAcceptanceTest(final String ignored, final URI testCaseFileURI) { - super(ignored, testsContext, testCaseFileURI); + public DebugSetHeadAcceptanceTest() { + super(testsContext); } - @BeforeClass + @BeforeAll public static void init() throws IOException { testsContext = new JsonRpcTestsContext(GENESIS_FILE); } - @Parameterized.Parameters(name = "{0}") - public static Iterable testCases() throws URISyntaxException { - return testCases(TEST_CASE_PATH); + public static Stream testCases() throws URISyntaxException { + return testCasesFromPath(TEST_CASE_PATH); } - @AfterClass + @AfterAll public static void tearDown() { testsContext.cluster.close(); } diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/EthEstimateGasAcceptanceTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/EthEstimateGasAcceptanceTest.java index b8b4e2e45f4..5326c5763cb 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/EthEstimateGasAcceptanceTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/EthEstimateGasAcceptanceTest.java @@ -28,8 +28,8 @@ import java.util.ArrayList; import java.util.List; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class EthEstimateGasAcceptanceTest extends AcceptanceTestBase { @@ -38,7 +38,7 @@ public class EthEstimateGasAcceptanceTest extends AcceptanceTestBase { List> testCase = new ArrayList<>(); - @Before + @BeforeEach public void setUp() throws Exception { node = besu.createMinerNode( diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/EthGetBlockByNumberAndHashShanghaiAcceptanceTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/EthGetBlockByNumberAndHashShanghaiAcceptanceTest.java index f50e6c4a3bf..e795ee27abc 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/EthGetBlockByNumberAndHashShanghaiAcceptanceTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/EthGetBlockByNumberAndHashShanghaiAcceptanceTest.java @@ -15,15 +15,13 @@ package org.hyperledger.besu.tests.acceptance.jsonrpc; import java.io.IOException; -import java.net.URI; import java.net.URISyntaxException; +import java.util.stream.Stream; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.params.provider.Arguments; -@RunWith(Parameterized.class) public class EthGetBlockByNumberAndHashShanghaiAcceptanceTest extends AbstractJsonRpcTest { private static final String TEST_RESOURCES_DIR = "/jsonrpc/eth/getBlockBy/"; private static final String GENESIS_FILE = TEST_RESOURCES_DIR + "genesis.json"; @@ -31,22 +29,20 @@ public class EthGetBlockByNumberAndHashShanghaiAcceptanceTest extends AbstractJs private static AbstractJsonRpcTest.JsonRpcTestsContext testsContext; - public EthGetBlockByNumberAndHashShanghaiAcceptanceTest( - final String ignored, final URI testCaseFileURI) { - super(ignored, testsContext, testCaseFileURI); + public EthGetBlockByNumberAndHashShanghaiAcceptanceTest() { + super(testsContext); } - @BeforeClass + @BeforeAll public static void init() throws IOException { testsContext = new JsonRpcTestsContext(GENESIS_FILE); } - @Parameterized.Parameters(name = "{0}") - public static Iterable testCases() throws URISyntaxException { - return testCases(TEST_CASE_PATH); + public static Stream testCases() throws URISyntaxException { + return testCasesFromPath(TEST_CASE_PATH); } - @AfterClass + @AfterAll public static void tearDown() { testsContext.cluster.close(); } diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/ExecutionEngineCancunBlockBuildingAcceptanceTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/ExecutionEngineCancunBlockBuildingAcceptanceTest.java index 7fe498e4c94..a9acdd14c5b 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/ExecutionEngineCancunBlockBuildingAcceptanceTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/ExecutionEngineCancunBlockBuildingAcceptanceTest.java @@ -19,39 +19,35 @@ import org.hyperledger.besu.tests.acceptance.dsl.rpc.JsonRpcTestCase; import java.io.IOException; -import java.net.URI; import java.net.URISyntaxException; import java.net.URL; +import java.util.stream.Stream; import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.JsonNodeType; import com.fasterxml.jackson.databind.node.ObjectNode; import okhttp3.Call; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.params.provider.Arguments; -@RunWith(Parameterized.class) public class ExecutionEngineCancunBlockBuildingAcceptanceTest extends AbstractJsonRpcTest { private static final String GENESIS_FILE = "/jsonrpc/engine/cancun/genesis.json"; private static final String TEST_CASE_PATH = "/jsonrpc/engine/cancun/test-cases/block-production"; private static JsonRpcTestsContext testsContext; - public ExecutionEngineCancunBlockBuildingAcceptanceTest( - final String ignored, final URI testCaseFileURI) { - super(ignored, testsContext, testCaseFileURI); + public ExecutionEngineCancunBlockBuildingAcceptanceTest() { + super(testsContext); } - @BeforeClass + @BeforeAll public static void init() throws IOException { testsContext = new JsonRpcTestsContext(GENESIS_FILE); } - @Parameterized.Parameters(name = "{0}") - public static Iterable testCases() throws URISyntaxException { - return testCases(TEST_CASE_PATH); + public static Stream testCases() throws URISyntaxException { + return testCasesFromPath(TEST_CASE_PATH); } @Override @@ -90,7 +86,7 @@ protected void evaluateResponse( } } - @AfterClass + @AfterAll public static void tearDown() { testsContext.cluster.close(); } diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/ExecutionEngineEip6110AcceptanceTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/ExecutionEngineEip6110AcceptanceTest.java index d1771ac5990..e77f011d9b4 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/ExecutionEngineEip6110AcceptanceTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/ExecutionEngineEip6110AcceptanceTest.java @@ -15,36 +15,33 @@ package org.hyperledger.besu.tests.acceptance.jsonrpc; import java.io.IOException; -import java.net.URI; import java.net.URISyntaxException; +import java.util.stream.Stream; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.params.provider.Arguments; -@RunWith(Parameterized.class) public class ExecutionEngineEip6110AcceptanceTest extends AbstractJsonRpcTest { private static final String GENESIS_FILE = "/jsonrpc/engine/eip6110/genesis.json"; private static final String TEST_CASE_PATH = "/jsonrpc/engine/eip6110/test-cases/"; private static JsonRpcTestsContext testsContext; - public ExecutionEngineEip6110AcceptanceTest(final String ignored, final URI testCaseFileURI) { - super(ignored, testsContext, testCaseFileURI); + public ExecutionEngineEip6110AcceptanceTest() { + super(testsContext); } - @BeforeClass + @BeforeAll public static void init() throws IOException { testsContext = new JsonRpcTestsContext(GENESIS_FILE); } - @Parameterized.Parameters(name = "{0}") - public static Iterable testCases() throws URISyntaxException { - return testCases(TEST_CASE_PATH); + public static Stream testCases() throws URISyntaxException { + return testCasesFromPath(TEST_CASE_PATH); } - @AfterClass + @AfterAll public static void tearDown() { testsContext.cluster.close(); } diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/ExecutionEngineParisAcceptanceTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/ExecutionEngineParisAcceptanceTest.java index c6cb8a62ea4..e7cb8a9150e 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/ExecutionEngineParisAcceptanceTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/ExecutionEngineParisAcceptanceTest.java @@ -15,36 +15,33 @@ package org.hyperledger.besu.tests.acceptance.jsonrpc; import java.io.IOException; -import java.net.URI; import java.net.URISyntaxException; +import java.util.stream.Stream; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.params.provider.Arguments; -@RunWith(Parameterized.class) public class ExecutionEngineParisAcceptanceTest extends AbstractJsonRpcTest { private static final String GENESIS_FILE = "/jsonrpc/engine/paris/genesis.json"; private static final String TEST_CASE_PATH = "/jsonrpc/engine/paris/test-cases/"; private static JsonRpcTestsContext testsContext; - public ExecutionEngineParisAcceptanceTest(final String ignored, final URI testCaseFileURI) { - super(ignored, testsContext, testCaseFileURI); + public ExecutionEngineParisAcceptanceTest() { + super(testsContext); } - @BeforeClass + @BeforeAll public static void init() throws IOException { testsContext = new JsonRpcTestsContext(GENESIS_FILE); } - @Parameterized.Parameters(name = "{0}") - public static Iterable testCases() throws URISyntaxException { - return testCases(TEST_CASE_PATH); + public static Stream testCases() throws URISyntaxException { + return testCasesFromPath(TEST_CASE_PATH); } - @AfterClass + @AfterAll public static void tearDown() { testsContext.cluster.close(); } diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/ExecutionEngineShanghaiAcceptanceTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/ExecutionEngineShanghaiAcceptanceTest.java index c676af5922b..85f966e3d2d 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/ExecutionEngineShanghaiAcceptanceTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/ExecutionEngineShanghaiAcceptanceTest.java @@ -15,36 +15,32 @@ package org.hyperledger.besu.tests.acceptance.jsonrpc; import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; +import java.util.stream.Stream; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.params.provider.Arguments; -@RunWith(Parameterized.class) public class ExecutionEngineShanghaiAcceptanceTest extends AbstractJsonRpcTest { private static final String GENESIS_FILE = "/jsonrpc/engine/shanghai/genesis.json"; private static final String TEST_CASE_PATH = "/jsonrpc/engine/shanghai/test-cases/"; private static JsonRpcTestsContext testsContext; - public ExecutionEngineShanghaiAcceptanceTest(final String ignored, final URI testCaseFileURI) { - super(ignored, testsContext, testCaseFileURI); + public ExecutionEngineShanghaiAcceptanceTest() { + super(testsContext); } - @BeforeClass + @BeforeAll public static void init() throws IOException { testsContext = new JsonRpcTestsContext(GENESIS_FILE); } - @Parameterized.Parameters(name = "{0}") - public static Iterable testCases() throws URISyntaxException { - return testCases(TEST_CASE_PATH); + public static Stream testCases() throws Exception { + return testCasesFromPath(TEST_CASE_PATH); } - @AfterClass + @AfterAll public static void tearDown() { testsContext.cluster.close(); } diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/ipc/Web3JSupportAcceptanceTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/ipc/Web3JSupportAcceptanceTest.java index c13c195cb33..b1887303ba2 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/ipc/Web3JSupportAcceptanceTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/ipc/Web3JSupportAcceptanceTest.java @@ -29,8 +29,8 @@ import java.util.Collections; import java.util.Locale; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.web3j.protocol.Web3j; import org.web3j.protocol.core.Request; import org.web3j.protocol.core.methods.response.NetVersion; @@ -41,7 +41,7 @@ public class Web3JSupportAcceptanceTest extends AcceptanceTestBase { private Node node; private Path socketPath; - @Before + @BeforeEach public void setUp() throws Exception { socketPath = Files.createTempFile("besu-test-", ".ipc"); node = From 1d3eb9386bd483d267dd665eba01f803c9a3f89b Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Mon, 11 Dec 2023 14:06:16 +1000 Subject: [PATCH 23/28] Non bft group ats junit 5 (#6260) * migrate to junit 5 Signed-off-by: Sally MacFarlane --------- Signed-off-by: Sally MacFarlane --- .../AbstractPreexistingNodeTest.java | 7 -- .../besu/tests/acceptance/LoggingTest.java | 2 +- .../backup/BackupRoundTripAcceptanceTest.java | 79 ++++++++----------- .../bootstrap/ClusterAcceptanceTest.java | 6 +- .../ClusterNoDiscoveryAcceptanceTest.java | 6 +- ...ClusterThreadNodeRunnerAcceptanceTest.java | 6 +- .../bootstrap/P2pDisabledAcceptanceTest.java | 6 +- .../bootstrap/StaticNodesAcceptanceTest.java | 6 +- .../config/BootNodesGenesisSetupTest.java | 10 +-- .../crypto/SECP256R1AcceptanceTest.java | 6 +- .../DatabaseMigrationAcceptanceTest.java | 74 ++++++++--------- 11 files changed, 91 insertions(+), 117 deletions(-) diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/AbstractPreexistingNodeTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/AbstractPreexistingNodeTest.java index 5c4b58ec019..a407b389e44 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/AbstractPreexistingNodeTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/AbstractPreexistingNodeTest.java @@ -43,15 +43,8 @@ import org.apache.commons.compress.utils.IOUtils; public class AbstractPreexistingNodeTest extends AcceptanceTestBase { - protected final String testName; - protected final String dataPath; protected Path hostDataPath; - public AbstractPreexistingNodeTest(final String testName, final String dataPath) { - this.testName = testName; - this.dataPath = dataPath; - } - protected static void extract(final Path path, final String destDirectory) throws IOException { try (final TarArchiveInputStream fin = new TarArchiveInputStream( diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/LoggingTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/LoggingTest.java index e0276842f06..1c1f0c33b68 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/LoggingTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/LoggingTest.java @@ -21,7 +21,7 @@ import java.io.IOException; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class LoggingTest extends AcceptanceTestBase { diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/backup/BackupRoundTripAcceptanceTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/backup/BackupRoundTripAcceptanceTest.java index 5136cc64ab3..aa58ffb2fdf 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/backup/BackupRoundTripAcceptanceTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/backup/BackupRoundTripAcceptanceTest.java @@ -29,7 +29,6 @@ import org.hyperledger.besu.tests.acceptance.dsl.node.BesuNode; import org.hyperledger.besu.tests.acceptance.dsl.node.configuration.BesuNodeConfigurationBuilder; -import java.io.IOException; import java.math.BigInteger; import java.net.URL; import java.nio.file.Files; @@ -37,64 +36,42 @@ import java.nio.file.Paths; import java.util.List; import java.util.function.UnaryOperator; +import java.util.stream.Stream; import javax.annotation.Nonnull; import com.fasterxml.jackson.databind.node.ObjectNode; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; -@RunWith(Parameterized.class) public class BackupRoundTripAcceptanceTest extends AbstractPreexistingNodeTest { - private final Path backupPath; - private final Path restorePath; - private final Path rebackupPath; - - @SuppressWarnings({"unused", "FieldCanBeLocal"}) - private final List testAccounts; - - @SuppressWarnings({"unused", "FieldCanBeLocal"}) - private final long expectedChainHeight; + private Path backupPath; + private Path restorePath; + private Path rebackupPath; + + public static Stream getParameters() { + // First 10 blocks of ropsten + return Stream.of( + Arguments.of( + "After versioning was enabled and using multiple RocksDB columns", + "version1", + 0xA, + singletonList( + new AccountData( + "0xd1aeb42885a43b72b518182ef893125814811048", + BigInteger.valueOf(0xA), + Wei.fromHexString("0x2B5E3AF16B1880000"))))); + } - public BackupRoundTripAcceptanceTest( - final String testName, - final String dataPath, - final long expectedChainHeight, - final List testAccounts) - throws IOException { - super(testName, dataPath); - this.expectedChainHeight = expectedChainHeight; - this.testAccounts = testAccounts; + public void setUp(final String testName, final String dataPath) throws Exception { backupPath = Files.createTempDirectory("backup"); backupPath.toFile().deleteOnExit(); restorePath = Files.createTempDirectory("restore"); restorePath.toFile().deleteOnExit(); rebackupPath = Files.createTempDirectory("rebackup"); rebackupPath.toFile().deleteOnExit(); - } - @Parameters(name = "{0}") - public static Object[][] getParameters() { - return new Object[][] { - // First 10 blocks of ropsten - new Object[] { - "After versioning was enabled and using multiple RocksDB columns", - "version1", - 0xA, - singletonList( - new AccountData( - "0xd1aeb42885a43b72b518182ef893125814811048", - BigInteger.valueOf(0xA), - Wei.fromHexString("0x2B5E3AF16B1880000"))) - } - }; - } - - @Before - public void setUp() throws Exception { final URL rootURL = DatabaseMigrationAcceptanceTest.class.getResource(dataPath); hostDataPath = copyDataDir(rootURL); final Path databaseArchive = @@ -105,8 +82,16 @@ public void setUp() throws Exception { extract(databaseArchive, hostDataPath.toAbsolutePath().toString()); } - @Test - public void backupRoundtripAndBack() throws IOException { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("getParameters") + public void backupRoundtripAndBack( + final String testName, + final String dataPath, + final long expectedChainHeight, + final List testAccounts) + throws Exception { + + setUp(testName, dataPath); // backup from existing files final BesuNode backupNode = diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bootstrap/ClusterAcceptanceTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bootstrap/ClusterAcceptanceTest.java index c4c9e42671c..e7ad04dc594 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bootstrap/ClusterAcceptanceTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bootstrap/ClusterAcceptanceTest.java @@ -17,15 +17,15 @@ import org.hyperledger.besu.tests.acceptance.dsl.AcceptanceTestBase; import org.hyperledger.besu.tests.acceptance.dsl.node.Node; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class ClusterAcceptanceTest extends AcceptanceTestBase { private Node minerNode; private Node fullNode; - @Before + @BeforeEach public void setUp() throws Exception { minerNode = besu.createMinerNode("node1"); fullNode = besu.createArchiveNode("node2"); diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bootstrap/ClusterNoDiscoveryAcceptanceTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bootstrap/ClusterNoDiscoveryAcceptanceTest.java index 6c7c8127997..3a7da4f4768 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bootstrap/ClusterNoDiscoveryAcceptanceTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bootstrap/ClusterNoDiscoveryAcceptanceTest.java @@ -20,8 +20,8 @@ import org.hyperledger.besu.tests.acceptance.dsl.node.cluster.ClusterConfiguration; import org.hyperledger.besu.tests.acceptance.dsl.node.cluster.ClusterConfigurationBuilder; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class ClusterNoDiscoveryAcceptanceTest extends AcceptanceTestBase { @@ -29,7 +29,7 @@ public class ClusterNoDiscoveryAcceptanceTest extends AcceptanceTestBase { private Node noDiscoveryNode; private Cluster noDiscoveryCluster; - @Before + @BeforeEach public void setUp() throws Exception { final ClusterConfiguration clusterConfiguration = new ClusterConfigurationBuilder().awaitPeerDiscovery(false).build(); diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bootstrap/ClusterThreadNodeRunnerAcceptanceTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bootstrap/ClusterThreadNodeRunnerAcceptanceTest.java index 805749a0bf8..8fbd0d3d625 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bootstrap/ClusterThreadNodeRunnerAcceptanceTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bootstrap/ClusterThreadNodeRunnerAcceptanceTest.java @@ -23,15 +23,15 @@ import org.hyperledger.besu.tests.acceptance.dsl.node.cluster.ClusterConfiguration; import org.hyperledger.besu.tests.acceptance.dsl.node.cluster.ClusterConfigurationBuilder; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class ClusterThreadNodeRunnerAcceptanceTest extends AcceptanceTestBase { private Node fullNode; private Cluster noDiscoveryCluster; - @Before + @BeforeEach public void setUp() throws Exception { final ClusterConfiguration clusterConfiguration = new ClusterConfigurationBuilder().awaitPeerDiscovery(false).build(); diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bootstrap/P2pDisabledAcceptanceTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bootstrap/P2pDisabledAcceptanceTest.java index aa71839b181..67a9bf2754f 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bootstrap/P2pDisabledAcceptanceTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bootstrap/P2pDisabledAcceptanceTest.java @@ -20,14 +20,14 @@ import org.hyperledger.besu.tests.acceptance.dsl.node.cluster.ClusterConfiguration; import org.hyperledger.besu.tests.acceptance.dsl.node.cluster.ClusterConfigurationBuilder; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class P2pDisabledAcceptanceTest extends AcceptanceTestBase { private Node node; private Cluster p2pDisabledCluster; - @Before + @BeforeEach public void setUp() throws Exception { final ClusterConfiguration clusterConfiguration = new ClusterConfigurationBuilder().awaitPeerDiscovery(false).build(); diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bootstrap/StaticNodesAcceptanceTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bootstrap/StaticNodesAcceptanceTest.java index 1f28a4a9f3c..0ce5ea02b13 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bootstrap/StaticNodesAcceptanceTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bootstrap/StaticNodesAcceptanceTest.java @@ -20,15 +20,15 @@ import java.util.Arrays; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class StaticNodesAcceptanceTest extends AcceptanceTestBase { private Node otherNode; private Node node; - @Before + @BeforeEach public void setUp() throws Exception { otherNode = besu.createNodeWithNoDiscovery("other-node"); cluster.start(otherNode); diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/config/BootNodesGenesisSetupTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/config/BootNodesGenesisSetupTest.java index 1ad2587ded3..616afc19669 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/config/BootNodesGenesisSetupTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/config/BootNodesGenesisSetupTest.java @@ -29,9 +29,9 @@ import org.bouncycastle.asn1.sec.SECNamedCurves; import org.bouncycastle.asn1.x9.X9ECParameters; import org.bouncycastle.crypto.params.ECDomainParameters; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class BootNodesGenesisSetupTest extends AcceptanceTestBase { private static final String CURVE_NAME = "secp256k1"; @@ -42,13 +42,13 @@ public class BootNodesGenesisSetupTest extends AcceptanceTestBase { private Node nodeA; private Node nodeB; - @BeforeClass + @BeforeAll public static void environment() { final X9ECParameters params = SECNamedCurves.getByName(CURVE_NAME); curve = new ECDomainParameters(params.getCurve(), params.getG(), params.getN(), params.getH()); } - @Before + @BeforeEach public void setUp() throws Exception { int nodeAP2pBindingPort; int nodeBP2pBindingPort; diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/crypto/SECP256R1AcceptanceTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/crypto/SECP256R1AcceptanceTest.java index 8b4ef9f864b..7164de0b7aa 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/crypto/SECP256R1AcceptanceTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/crypto/SECP256R1AcceptanceTest.java @@ -32,8 +32,8 @@ import java.util.List; import org.apache.tuweni.bytes.Bytes32; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class SECP256R1AcceptanceTest extends AcceptanceTestBase { private Node minerNode; @@ -49,7 +49,7 @@ public class SECP256R1AcceptanceTest extends AcceptanceTestBase { private static final SECP256R1 SECP256R1_SIGNATURE_ALGORITHM = new SECP256R1(); - @Before + @BeforeEach public void setUp() throws Exception { KeyPair minerNodeKeyPair = createKeyPair(MINER_NODE_PRIVATE_KEY); KeyPair otherNodeKeyPair = createKeyPair(OTHER_NODE_PRIVATE_KEY); diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/database/DatabaseMigrationAcceptanceTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/database/DatabaseMigrationAcceptanceTest.java index 291506498ba..b2166a1cc58 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/database/DatabaseMigrationAcceptanceTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/database/DatabaseMigrationAcceptanceTest.java @@ -28,49 +28,31 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.List; +import java.util.stream.Stream; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; -@RunWith(Parameterized.class) public class DatabaseMigrationAcceptanceTest extends org.hyperledger.besu.tests.acceptance.AbstractPreexistingNodeTest { - private final long expectedChainHeight; private BesuNode node; - private final List testAccounts; - public DatabaseMigrationAcceptanceTest( - final String testName, - final String dataPath, - final long expectedChainHeight, - final List testAccounts) { - super(testName, dataPath); - this.expectedChainHeight = expectedChainHeight; - this.testAccounts = testAccounts; + public static Stream getParameters() { + // First 10 blocks of ropsten + return Stream.of( + Arguments.of( + "After versioning was enabled and using multiple RocksDB columns", + "version1", + 0xA, + singletonList( + new AccountData( + "0xd1aeb42885a43b72b518182ef893125814811048", + BigInteger.valueOf(0xA), + Wei.fromHexString("0x2B5E3AF16B1880000"))))); } - @Parameters(name = "{0}") - public static Object[][] getParameters() { - return new Object[][] { - // First 10 blocks of ropsten - new Object[] { - "After versioning was enabled and using multiple RocksDB columns", - "version1", - 0xA, - singletonList( - new AccountData( - "0xd1aeb42885a43b72b518182ef893125814811048", - BigInteger.valueOf(0xA), - Wei.fromHexString("0x2B5E3AF16B1880000"))) - } - }; - } - - @Before - public void setUp() throws Exception { + public void setUp(final String testName, final String dataPath) throws Exception { final URL rootURL = DatabaseMigrationAcceptanceTest.class.getResource(dataPath); hostDataPath = copyDataDir(rootURL); final Path databaseArchive = @@ -83,13 +65,27 @@ public void setUp() throws Exception { cluster.start(node); } - @Test - public void shouldReturnCorrectBlockHeight() { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("getParameters") + public void shouldReturnCorrectBlockHeight( + final String testName, + final String dataPath, + final long expectedChainHeight, + final List testAccounts) + throws Exception { + setUp(testName, dataPath); blockchain.currentHeight(expectedChainHeight).verify(node); } - @Test - public void shouldReturnCorrectAccountBalance() { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("getParameters") + public void shouldReturnCorrectAccountBalance( + final String testName, + final String dataPath, + final long expectedChainHeight, + final List testAccounts) + throws Exception { + setUp(testName, dataPath); testAccounts.forEach( accountData -> accounts From 9f8f12137b082f73bab7a48918ad048cce3a509c Mon Sep 17 00:00:00 2001 From: garyschulte Date: Mon, 11 Dec 2023 08:53:57 -0800 Subject: [PATCH 24/28] Txparse subcommand implementation (#6268) * txparse subcommand Signed-off-by: garyschulte Co-authored-by: Sally MacFarlane --- .../org/hyperledger/besu/cli/BesuCommand.java | 3 + .../cli/subcommands/TxParseSubCommand.java | 129 ++++++++++++++++++ .../subcommands/TxParseSubCommandTest.java | 69 ++++++++++ 3 files changed, 201 insertions(+) create mode 100644 besu/src/main/java/org/hyperledger/besu/cli/subcommands/TxParseSubCommand.java create mode 100644 besu/src/test/java/org/hyperledger/besu/cli/subcommands/TxParseSubCommandTest.java diff --git a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java index b42c4aad977..b8b7efca3ab 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java @@ -78,6 +78,7 @@ import org.hyperledger.besu.cli.subcommands.PasswordSubCommand; import org.hyperledger.besu.cli.subcommands.PublicKeySubCommand; import org.hyperledger.besu.cli.subcommands.RetestethSubCommand; +import org.hyperledger.besu.cli.subcommands.TxParseSubCommand; import org.hyperledger.besu.cli.subcommands.ValidateConfigSubCommand; import org.hyperledger.besu.cli.subcommands.blocks.BlocksSubCommand; import org.hyperledger.besu.cli.subcommands.operator.OperatorSubCommand; @@ -1493,6 +1494,8 @@ private void addSubCommands(final InputStream in) { jsonBlockImporterFactory, rlpBlockExporterFactory, commandLine.getOut())); + commandLine.addSubcommand( + TxParseSubCommand.COMMAND_NAME, new TxParseSubCommand(commandLine.getOut())); commandLine.addSubcommand( PublicKeySubCommand.COMMAND_NAME, new PublicKeySubCommand(commandLine.getOut())); commandLine.addSubcommand( diff --git a/besu/src/main/java/org/hyperledger/besu/cli/subcommands/TxParseSubCommand.java b/besu/src/main/java/org/hyperledger/besu/cli/subcommands/TxParseSubCommand.java new file mode 100644 index 00000000000..221675c9dc5 --- /dev/null +++ b/besu/src/main/java/org/hyperledger/besu/cli/subcommands/TxParseSubCommand.java @@ -0,0 +1,129 @@ +/* + * Copyright Hyperledger Besu Contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.cli.subcommands; + +import static java.nio.charset.StandardCharsets.UTF_8; +import static org.hyperledger.besu.cli.subcommands.TxParseSubCommand.COMMAND_NAME; + +import org.hyperledger.besu.cli.util.VersionProvider; +import org.hyperledger.besu.crypto.SignatureAlgorithmFactory; +import org.hyperledger.besu.ethereum.core.encoding.EncodingContext; +import org.hyperledger.besu.ethereum.core.encoding.TransactionDecoder; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.math.BigInteger; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.stream.Stream; + +import org.apache.tuweni.bytes.Bytes; +import picocli.CommandLine; + +/** + * txparse sub command implementing txparse spec from + * https://github.com/holiman/txparse/tree/main/cmd/txparse + */ +@CommandLine.Command( + name = COMMAND_NAME, + description = "Parse input transactions and return the sender, or an error.", + mixinStandardHelpOptions = true, + versionProvider = VersionProvider.class) +public class TxParseSubCommand implements Runnable { + + /** The constant COMMAND_NAME. */ + public static final String COMMAND_NAME = "txparse"; + + @SuppressWarnings({"FieldCanBeFinal", "FieldMayBeFinal"}) // PicoCLI requires non-final Strings. + @CommandLine.Option( + names = "--corpus-file", + arity = "1..1", + description = "file to read transaction data lines from, otherwise defaults to stdin") + private String corpusFile = null; + + static final BigInteger halfCurveOrder = + SignatureAlgorithmFactory.getInstance().getHalfCurveOrder(); + static final BigInteger chainId = new BigInteger("1", 10); + + private final PrintWriter out; + + /** + * Instantiates a new TxParse sub command. + * + * @param out the PrintWriter where validation results will be reported. + */ + public TxParseSubCommand(final PrintWriter out) { + this.out = out; + } + + @SuppressWarnings("StreamResourceLeak") + Stream fileStreamReader(final String filePath) { + try { + return Files.lines(Paths.get(filePath)) + // skip comments + .filter(line -> !line.startsWith("#")) + // strip out non-alphanumeric characters + .map(line -> line.replaceAll("[^a-zA-Z0-9]", "")); + } catch (Exception ex) { + throw new RuntimeException(ex); + } + } + + @Override + public void run() { + + Stream txStream; + if (corpusFile != null) { + txStream = fileStreamReader(corpusFile); + } else { + txStream = new BufferedReader(new InputStreamReader(System.in, UTF_8)).lines(); + } + + txStream.forEach( + line -> { + try { + Bytes bytes = Bytes.fromHexStringLenient(line); + dump(bytes); + } catch (Exception ex) { + err(ex.getMessage()); + } + }); + } + + void dump(final Bytes tx) { + try { + var transaction = TransactionDecoder.decodeOpaqueBytes(tx, EncodingContext.BLOCK_BODY); + + // https://github.com/hyperledger/besu/blob/5fe49c60b30fe2954c7967e8475c3b3e9afecf35/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionValidator.java#L252 + if (transaction.getChainId().isPresent() && !transaction.getChainId().get().equals(chainId)) { + throw new Exception("wrong chain id"); + } + + // https://github.com/hyperledger/besu/blob/5fe49c60b30fe2954c7967e8475c3b3e9afecf35/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionValidator.java#L270 + if (transaction.getS().compareTo(halfCurveOrder) > 0) { + throw new Exception("signature s out of range"); + } + out.println(transaction.getSender()); + + } catch (Exception ex) { + err(ex.getMessage()); + } + } + + void err(final String message) { + out.println("err: " + message); + } +} diff --git a/besu/src/test/java/org/hyperledger/besu/cli/subcommands/TxParseSubCommandTest.java b/besu/src/test/java/org/hyperledger/besu/cli/subcommands/TxParseSubCommandTest.java new file mode 100644 index 00000000000..85839cc5b78 --- /dev/null +++ b/besu/src/test/java/org/hyperledger/besu/cli/subcommands/TxParseSubCommandTest.java @@ -0,0 +1,69 @@ +/* + * Copyright Hyperledger Besu Contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.cli.subcommands; + +import static java.nio.charset.StandardCharsets.UTF_8; +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; + +import java.io.ByteArrayOutputStream; +import java.io.OutputStreamWriter; +import java.io.PrintWriter; + +import org.apache.tuweni.bytes.Bytes; +import org.junit.jupiter.api.Test; + +public class TxParseSubCommandTest { + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + PrintWriter writer = new PrintWriter(new OutputStreamWriter(baos, UTF_8), true); + TxParseSubCommand txParseSubCommand = new TxParseSubCommand(writer); + + @Test + public void smokeTest() { + txParseSubCommand.dump( + Bytes.fromHexString( + "0x02f875018363bc5a8477359400850c570bd200825208943893d427c770de9b92065da03a8c825f13498da28702fbf8ccf8530480c080a0dd49141ecf93eeeaed5f3499a6103d6a9778e24a37b1f5c6a336c60c8a078c15a0511b51a3050771f66c1b779210a46a51be521a2446a3f87fc656dcfd1782aa5e")); + String output = baos.toString(UTF_8); + assertThat(output).isEqualTo("0xeb2629a2734e272bcc07bda959863f316f4bd4cf\n"); + } + + @Test + public void assertInvalidRlp() { + txParseSubCommand.dump( + Bytes.fromHexString( + "0x03f90124f9011e010516058261a89403040500000000000000000000000000000000006383000000f8b6f859940000000000000000000000000000000074657374f842a00100000000000000000000000000000000000000000000000000000000000000a00200000000000000000000000000000000000000000000000000000000000000f859940000000000000000000000000000000074657374f842a00100000000000000000000000000000000000000000000000000000000000000a002000000000000000000000000000000000000000000000000000000000000000fc080a082f96cae43a3f2554cad899a6e9168a3cd613454f82e93488f9b4c1a998cc814a06b7519cd0e3159d6ce9bf811ff3ca4e9c5d7ac63fc52142370a0725e4c5273b2c0c0c0")); + String output = baos.toString(UTF_8); + assertThat(output).startsWith("err: "); + assertThat(output).contains("arbitrary precision scalar"); + } + + @Test + public void assertValidRlp() { + txParseSubCommand.dump( + Bytes.fromHexString( + "0x03f9013f010516058261a89403040500000000000000000000000000000000006383000000f8b6f859940000000000000000000000000000000074657374f842a00100000000000000000000000000000000000000000000000000000000000000a00200000000000000000000000000000000000000000000000000000000000000f859940000000000000000000000000000000074657374f842a00100000000000000000000000000000000000000000000000000000000000000a002000000000000000000000000000000000000000000000000000000000000000fe1a0010657f37554c781402a22917dee2f75def7ab966d7b770905398eba3c44401401a0d98465c5489a09933e6428657f1fc4461d49febd8556c1c7e7053ed0be49cc4fa02c0d67e40aed75f87ea640cc47064d79f4383e24dec283ac6eb81e19da46cc26")); + String output = baos.toString(UTF_8); + assertThat(output).isEqualTo("0x730aa72228b55236de378f5267dfc77723b1380c\n"); + } + + @Test + public void assertInvalidChainId() { + txParseSubCommand.dump( + Bytes.fromHexString( + "0xf901fc303083303030803030b901ae30303030303030303030433030303030303030303030303030303030303030303030303030303030203030413030303030303030303000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000038390030000000002800380000413159000021000000002b0000000000003800000000003800000000000000000000002b633279315a00633200303041374222610063416200325832325a002543323861795930314130383058435931317a633043304239623900310031254363384361000023433158253041380037000027285839005a007937000000623700002761002b5a003937622e000000006300007863410000002a2e320000000000005a0000000000000037242778002039006120412e6362002138300000002a313030303030303030303030373030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030a03030303030303030303030303030303030303030303030303030303030303030a03030303030303030303030303030303030303030303030303030303030303030")); + String output = baos.toString(UTF_8); + assertThat(output).isEqualTo("err: wrong chain id\n"); + } +} From e90a7fa8238fa28e87d6832914ff2caaff0678ed Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Tue, 12 Dec 2023 10:39:55 +1000 Subject: [PATCH 25/28] [MINOR] migrate remaining Crypto tests to junit 5 (#6280) * update crypto tests to junit5 * fixed temp file * removed vintage junit dep Signed-off-by: Sally MacFarlane --------- Signed-off-by: Sally MacFarlane --- crypto/services/build.gradle | 3 --- .../cryptoservices/KeyPairSecurityModuleTest.java | 14 +++++--------- .../besu/cryptoservices/NodeKeyTest.java | 6 +++--- 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/crypto/services/build.gradle b/crypto/services/build.gradle index f6e082836c0..53b46d57473 100644 --- a/crypto/services/build.gradle +++ b/crypto/services/build.gradle @@ -32,11 +32,8 @@ dependencies { api project(':crypto:algorithms') api project(':plugin-api') - testImplementation 'junit:junit' testImplementation 'org.assertj:assertj-core' testImplementation 'org.junit.jupiter:junit-jupiter' - - testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' } artifacts { testSupportArtifacts testSupportJar } diff --git a/crypto/services/src/test/java/org/hyperledger/besu/cryptoservices/KeyPairSecurityModuleTest.java b/crypto/services/src/test/java/org/hyperledger/besu/cryptoservices/KeyPairSecurityModuleTest.java index 68d369ae538..fac403e041d 100644 --- a/crypto/services/src/test/java/org/hyperledger/besu/cryptoservices/KeyPairSecurityModuleTest.java +++ b/crypto/services/src/test/java/org/hyperledger/besu/cryptoservices/KeyPairSecurityModuleTest.java @@ -20,26 +20,22 @@ import org.hyperledger.besu.crypto.SECPPublicKey; import org.hyperledger.besu.crypto.SignatureAlgorithmFactory; -import java.io.File; import java.io.IOException; +import java.nio.file.Path; import java.security.spec.ECPoint; import org.apache.tuweni.bytes.Bytes; import org.assertj.core.api.Assertions; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; public class KeyPairSecurityModuleTest { - @Rule public final TemporaryFolder temp = new TemporaryFolder(); + @TempDir public Path keyFile; @Test public void validatePublicKeyFromECPointCanBeConstructed() throws IOException { - final File keyDirectory = temp.newFolder(); - final File keyFile = new File(keyDirectory, "key"); - - final KeyPair keyPair = KeyPairUtil.loadKeyPair(keyFile); + final KeyPair keyPair = KeyPairUtil.loadKeyPair(keyFile.resolve("key")); final KeyPairSecurityModule keyPairSecurityModule = new KeyPairSecurityModule(keyPair); final ECPoint ecPoint = keyPairSecurityModule.getPublicKey().getW(); diff --git a/crypto/services/src/test/java/org/hyperledger/besu/cryptoservices/NodeKeyTest.java b/crypto/services/src/test/java/org/hyperledger/besu/cryptoservices/NodeKeyTest.java index 07008f06cbc..261271aee9b 100644 --- a/crypto/services/src/test/java/org/hyperledger/besu/cryptoservices/NodeKeyTest.java +++ b/crypto/services/src/test/java/org/hyperledger/besu/cryptoservices/NodeKeyTest.java @@ -21,12 +21,12 @@ import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.bytes.Bytes32; import org.assertj.core.api.Assertions; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class NodeKeyTest { - @Before + @BeforeEach public void resetInstance() { SignatureAlgorithmFactory.resetInstance(); } From f47590a74b5a3736c580a77b9466eab228d91ac6 Mon Sep 17 00:00:00 2001 From: matkt Date: Tue, 12 Dec 2023 09:59:34 +0100 Subject: [PATCH 26/28] add a fix to load correctly the storage trie in the Bonsai WorldState (#6205) revert some modification that was made to pass tests #5686 and fix this tests by loading the storage with EMPTY_TRIE_HASH if we detect that it has been cleared before pushing the new slots after recreation. --------- Signed-off-by: Karim TAAM Signed-off-by: matkt --- .../ethereum/bonsai/worldview/BonsaiWorldState.java | 5 ++++- .../worldview/BonsaiWorldStateUpdateAccumulator.java | 11 ----------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/worldview/BonsaiWorldState.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/worldview/BonsaiWorldState.java index 7c7f7fd5516..73717425def 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/worldview/BonsaiWorldState.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/worldview/BonsaiWorldState.java @@ -282,7 +282,10 @@ private void updateAccountStorageState( worldStateUpdater.getAccountsToUpdate().get(updatedAddress); final BonsaiAccount accountOriginal = accountValue.getPrior(); final Hash storageRoot = - (accountOriginal == null) ? Hash.EMPTY_TRIE_HASH : accountOriginal.getStorageRoot(); + (accountOriginal == null + || worldStateUpdater.getStorageToClear().contains(updatedAddress)) + ? Hash.EMPTY_TRIE_HASH + : accountOriginal.getStorageRoot(); final StoredMerklePatriciaTrie storageTrie = createTrie( (location, key) -> diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/worldview/BonsaiWorldStateUpdateAccumulator.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/worldview/BonsaiWorldStateUpdateAccumulator.java index f66fcd0f56f..f4a0da55c9e 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/worldview/BonsaiWorldStateUpdateAccumulator.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/worldview/BonsaiWorldStateUpdateAccumulator.java @@ -328,17 +328,6 @@ public void commit() { } if (tracked.getStorageWasCleared()) { updatedAccount.clearStorage(); - wrappedWorldView() - .getAllAccountStorage(updatedAddress, updatedAccount.getStorageRoot()) - .forEach( - (keyHash, entryValue) -> { - final StorageSlotKey storageSlotKey = - new StorageSlotKey(Hash.wrap(keyHash), Optional.empty()); - final UInt256 value = UInt256.fromBytes(RLP.decodeOne(entryValue)); - pendingStorageUpdates.put( - storageSlotKey, new BonsaiValue<>(value, null, true)); - }); - updatedAccount.setStorageRoot(Hash.EMPTY_TRIE_HASH); } tracked.getUpdatedStorage().forEach(updatedAccount::setStorageValue); } From 54dfa7b563ca4456dbc9538629f237154564aaed Mon Sep 17 00:00:00 2001 From: Matt Whitehead Date: Tue, 12 Dec 2023 17:43:17 +0000 Subject: [PATCH 27/28] Sequenced pool synonym for legacy pool (#6274) * Sequenced pool synonym for legacy pool Signed-off-by: Matthew Whitehead * Class rename Signed-off-by: Matthew Whitehead * Spotless fixes Signed-off-by: Matthew Whitehead * Add SEQUENCED to config overview test Signed-off-by: Matthew Whitehead * Update CHANGELOG.md Co-authored-by: Sally MacFarlane Signed-off-by: Matt Whitehead * add a fix to load correctly the storage trie in the Bonsai WorldState (#6205) revert some modification that was made to pass tests #5686 and fix this tests by loading the storage with EMPTY_TRIE_HASH if we detect that it has been cleared before pushing the new slots after recreation. --------- Signed-off-by: Karim TAAM --------- Signed-off-by: Matthew Whitehead Signed-off-by: Matt Whitehead Signed-off-by: Karim TAAM Co-authored-by: Sally MacFarlane Co-authored-by: matkt --- CHANGELOG.md | 1 + .../cli/options/TransactionPoolOptions.java | 27 +++++++------- .../cli/ConfigurationOverviewBuilderTest.java | 8 +++++ .../options/TransactionPoolOptionsTest.java | 35 ++++++++++++++++--- .../src/test/resources/everything_config.toml | 2 +- .../TransactionPoolConfiguration.java | 5 +-- 6 files changed, 58 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 927fbf2f90d..f0d66a9cf07 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ ### Additions and Improvements - Add error messages on authentication failures with username and password [#6212](https://github.com/hyperledger/besu/pull/6212) +- New `Sequenced` transaction pool. The pool is an evolution of the `legacy` pool and is likely to be more suitable to enterprise or permissioned chains than the `layered` transaction pool. Select to use this pool with `--tx-pool=sequenced`. Supports the same options as the `legacy` pool [#6211](https://github.com/hyperledger/besu/issues/6211) ### Bug fixes diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/TransactionPoolOptions.java b/besu/src/main/java/org/hyperledger/besu/cli/options/TransactionPoolOptions.java index 3b34c4d2a61..0b6718387b1 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/TransactionPoolOptions.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/TransactionPoolOptions.java @@ -19,6 +19,7 @@ import static org.hyperledger.besu.cli.DefaultCommandValues.MANDATORY_LONG_FORMAT_HELP; import static org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration.Implementation.LAYERED; import static org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration.Implementation.LEGACY; +import static org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration.Implementation.SEQUENCED; import org.hyperledger.besu.cli.converter.DurationMillisConverter; import org.hyperledger.besu.cli.converter.FractionConverter; @@ -171,10 +172,10 @@ static class Layered { @CommandLine.ArgGroup( validate = false, - heading = "@|bold Tx Pool Legacy Implementation Options|@%n") - private final Legacy legacyOptions = new Legacy(); + heading = "@|bold Tx Pool Sequenced Implementation Options|@%n") + private final Sequenced sequencedOptions = new Sequenced(); - static class Legacy { + static class Sequenced { private static final String TX_POOL_RETENTION_HOURS = "--tx-pool-retention-hours"; private static final String TX_POOL_LIMIT_BY_ACCOUNT_PERCENTAGE = "--tx-pool-limit-by-account-percentage"; @@ -272,10 +273,10 @@ public static TransactionPoolOptions fromConfig(final TransactionPoolConfigurati config.getPendingTransactionsLayerMaxCapacityBytes(); options.layeredOptions.txPoolMaxPrioritized = config.getMaxPrioritizedTransactions(); options.layeredOptions.txPoolMaxFutureBySender = config.getMaxFutureBySender(); - options.legacyOptions.txPoolLimitByAccountPercentage = + options.sequencedOptions.txPoolLimitByAccountPercentage = config.getTxPoolLimitByAccountPercentage(); - options.legacyOptions.txPoolMaxSize = config.getTxPoolMaxSize(); - options.legacyOptions.pendingTxRetentionPeriod = config.getPendingTxRetentionPeriod(); + options.sequencedOptions.txPoolMaxSize = config.getTxPoolMaxSize(); + options.sequencedOptions.pendingTxRetentionPeriod = config.getPendingTxRetentionPeriod(); options.unstableOptions.txMessageKeepAliveSeconds = config.getUnstable().getTxMessageKeepAliveSeconds(); options.unstableOptions.eth65TrxAnnouncedBufferingPeriod = @@ -295,14 +296,14 @@ public void validate( final CommandLine commandLine, final GenesisConfigOptions genesisConfigOptions) { CommandLineUtils.failIfOptionDoesntMeetRequirement( commandLine, - "Could not use legacy transaction pool options with layered implementation", + "Could not use legacy or sequenced transaction pool options with layered implementation", !txPoolImplementation.equals(LAYERED), - CommandLineUtils.getCLIOptionNames(Legacy.class)); + CommandLineUtils.getCLIOptionNames(Sequenced.class)); CommandLineUtils.failIfOptionDoesntMeetRequirement( commandLine, - "Could not use layered transaction pool options with legacy implementation", - !txPoolImplementation.equals(LEGACY), + "Could not use layered transaction pool options with legacy or sequenced implementation", + !txPoolImplementation.equals(LEGACY) && !txPoolImplementation.equals(SEQUENCED), CommandLineUtils.getCLIOptionNames(Layered.class)); CommandLineUtils.failIfOptionDoesntMeetRequirement( @@ -327,9 +328,9 @@ public TransactionPoolConfiguration toDomainObject() { .pendingTransactionsLayerMaxCapacityBytes(layeredOptions.txPoolLayerMaxCapacity) .maxPrioritizedTransactions(layeredOptions.txPoolMaxPrioritized) .maxFutureBySender(layeredOptions.txPoolMaxFutureBySender) - .txPoolLimitByAccountPercentage(legacyOptions.txPoolLimitByAccountPercentage) - .txPoolMaxSize(legacyOptions.txPoolMaxSize) - .pendingTxRetentionPeriod(legacyOptions.pendingTxRetentionPeriod) + .txPoolLimitByAccountPercentage(sequencedOptions.txPoolLimitByAccountPercentage) + .txPoolMaxSize(sequencedOptions.txPoolMaxSize) + .pendingTxRetentionPeriod(sequencedOptions.pendingTxRetentionPeriod) .unstable( ImmutableTransactionPoolConfiguration.Unstable.builder() .txMessageKeepAliveSeconds(unstableOptions.txMessageKeepAliveSeconds) diff --git a/besu/src/test/java/org/hyperledger/besu/cli/ConfigurationOverviewBuilderTest.java b/besu/src/test/java/org/hyperledger/besu/cli/ConfigurationOverviewBuilderTest.java index 44718e96c67..ae00587c04d 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/ConfigurationOverviewBuilderTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/ConfigurationOverviewBuilderTest.java @@ -17,6 +17,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration.Implementation.LAYERED; import static org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration.Implementation.LEGACY; +import static org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration.Implementation.SEQUENCED; import static org.mockito.Mockito.mock; import org.hyperledger.besu.evm.internal.EvmConfiguration; @@ -180,6 +181,13 @@ void setTxPoolImplementationLegacy() { assertThat(legacyTxPoolSelected).contains("Using LEGACY transaction pool implementation"); } + @Test + void setTxPoolImplementationSequenced() { + builder.setTxPoolImplementation(SEQUENCED); + final String sequencedTxPoolSelected = builder.build(); + assertThat(sequencedTxPoolSelected).contains("Using SEQUENCED transaction pool implementation"); + } + @Test void setWorldStateUpdateModeDefault() { builder.setWorldStateUpdateMode(EvmConfiguration.DEFAULT.worldUpdaterMode()); diff --git a/besu/src/test/java/org/hyperledger/besu/cli/options/TransactionPoolOptionsTest.java b/besu/src/test/java/org/hyperledger/besu/cli/options/TransactionPoolOptionsTest.java index 5b5fff5014e..d7031eb9a4f 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/options/TransactionPoolOptionsTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/options/TransactionPoolOptionsTest.java @@ -17,6 +17,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration.Implementation.LAYERED; import static org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration.Implementation.LEGACY; +import static org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration.Implementation.SEQUENCED; import org.hyperledger.besu.cli.converter.DurationMillisConverter; import org.hyperledger.besu.datatypes.Address; @@ -63,7 +64,7 @@ public void strictTxReplayProtection_default() { } @Test - public void pendingTransactionRetentionPeriod() { + public void pendingTransactionRetentionPeriodLegacy() { final int pendingTxRetentionHours = 999; internalTestSuccess( config -> @@ -73,6 +74,17 @@ public void pendingTransactionRetentionPeriod() { "--tx-pool=legacy"); } + @Test + public void pendingTransactionRetentionPeriodSequenced() { + final int pendingTxRetentionHours = 999; + internalTestSuccess( + config -> + assertThat(config.getPendingTxRetentionPeriod()).isEqualTo(pendingTxRetentionHours), + "--tx-pool-retention-hours", + String.valueOf(pendingTxRetentionHours), + "--tx-pool=sequenced"); + } + @Test public void disableLocalsDefault() { internalTestSuccess(config -> assertThat(config.getNoLocalPriority()).isFalse()); @@ -193,17 +205,24 @@ public void selectLegacyImplementationByArg() { "--tx-pool=legacy"); } + @Test + public void selectSequencedImplementationByArg() { + internalTestSuccess( + config -> assertThat(config.getTxPoolImplementation()).isEqualTo(SEQUENCED), + "--tx-pool=sequenced"); + } + @Test public void failIfLegacyOptionsWhenLayeredSelectedByDefault() { internalTestFailure( - "Could not use legacy transaction pool options with layered implementation", + "Could not use legacy or sequenced transaction pool options with layered implementation", "--tx-pool-max-size=1000"); } @Test public void failIfLegacyOptionsWhenLayeredSelectedByArg() { internalTestFailure( - "Could not use legacy transaction pool options with layered implementation", + "Could not use legacy or sequenced transaction pool options with layered implementation", "--tx-pool=layered", "--tx-pool-max-size=1000"); } @@ -211,11 +230,19 @@ public void failIfLegacyOptionsWhenLayeredSelectedByArg() { @Test public void failIfLayeredOptionsWhenLegacySelectedByArg() { internalTestFailure( - "Could not use layered transaction pool options with legacy implementation", + "Could not use layered transaction pool options with legacy or sequenced implementation", "--tx-pool=legacy", "--tx-pool-max-prioritized=1000"); } + @Test + public void failIfLayeredOptionsWhenSequencedSelectedByArg() { + internalTestFailure( + "Could not use layered transaction pool options with legacy or sequenced implementation", + "--tx-pool=sequenced", + "--tx-pool-max-prioritized=1000"); + } + @Test public void byDefaultNoPrioritySenders() { internalTestSuccess(config -> assertThat(config.getPrioritySenders()).isEmpty()); diff --git a/besu/src/test/resources/everything_config.toml b/besu/src/test/resources/everything_config.toml index be337272e97..e516060da86 100644 --- a/besu/src/test/resources/everything_config.toml +++ b/besu/src/test/resources/everything_config.toml @@ -185,7 +185,7 @@ tx-pool-save-file="txpool.dump" tx-pool-layer-max-capacity=12345678 tx-pool-max-prioritized=9876 tx-pool-max-future-by-sender=321 -## Legacy +## Legacy/Sequenced tx-pool-retention-hours=999 tx-pool-max-size=1234 tx-pool-limit-by-account-percentage=0.017 diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolConfiguration.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolConfiguration.java index e30d24c158f..f6ef30667e6 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolConfiguration.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolConfiguration.java @@ -50,8 +50,9 @@ default int getTxMessageKeepAliveSeconds() { } enum Implementation { - LEGACY, - LAYERED; + LEGACY, // Remove in future version + LAYERED, + SEQUENCED; // Synonym for LEGACY } String DEFAULT_SAVE_FILE_NAME = "txpool.dump"; From d42380ed178d611b8d77a062b6abea9d20ea38ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20L=C3=B3pez=20Le=C3=B3n?= Date: Tue, 12 Dec 2023 15:39:43 -0300 Subject: [PATCH 28/28] ETC mainnet 'Spiral' activation block (#6267) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Set ENR tree for DNS discovery for ETC mainnet network Signed-off-by: Diego López León * Set activation block number for ECIP-1109 on ETC mainnet Signed-off-by: Diego López León --------- Signed-off-by: Diego López León --- CHANGELOG.md | 1 + .../java/org/hyperledger/besu/ForkIdsNetworkConfigTest.java | 5 +++-- config/src/main/resources/classic.json | 2 ++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f0d66a9cf07..b3a16d30983 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ ### Additions and Improvements - Add error messages on authentication failures with username and password [#6212](https://github.com/hyperledger/besu/pull/6212) - New `Sequenced` transaction pool. The pool is an evolution of the `legacy` pool and is likely to be more suitable to enterprise or permissioned chains than the `layered` transaction pool. Select to use this pool with `--tx-pool=sequenced`. Supports the same options as the `legacy` pool [#6211](https://github.com/hyperledger/besu/issues/6211) +- Set Ethereum Classic mainnet activation block for Spiral network upgrade [#6267](https://github.com/hyperledger/besu/pull/6267) ### Bug fixes diff --git a/besu/src/test/java/org/hyperledger/besu/ForkIdsNetworkConfigTest.java b/besu/src/test/java/org/hyperledger/besu/ForkIdsNetworkConfigTest.java index 5bc1c30bd61..7a83cd87515 100644 --- a/besu/src/test/java/org/hyperledger/besu/ForkIdsNetworkConfigTest.java +++ b/besu/src/test/java/org/hyperledger/besu/ForkIdsNetworkConfigTest.java @@ -147,8 +147,9 @@ public static Collection parameters() { new ForkId(Bytes.ofUnsignedInt(0x9007bfccL), 11700000L), new ForkId(Bytes.ofUnsignedInt(0xdb63a1caL), 13189133), new ForkId(Bytes.ofUnsignedInt(0x0f6bf187L), 14525000L), - new ForkId(Bytes.ofUnsignedInt(0x7fd1bb25L), 0L), - new ForkId(Bytes.ofUnsignedInt(0x7fd1bb25L), 0L)) + new ForkId(Bytes.ofUnsignedInt(0x7fd1bb25L), 19250000L), + new ForkId(Bytes.ofUnsignedInt(0xbe46d57cL), 0L), + new ForkId(Bytes.ofUnsignedInt(0xbe46d57cL), 0L)) }); } diff --git a/config/src/main/resources/classic.json b/config/src/main/resources/classic.json index efbc5be4fcf..ea7c49e1fa3 100644 --- a/config/src/main/resources/classic.json +++ b/config/src/main/resources/classic.json @@ -13,10 +13,12 @@ "thanosBlock": 11700000, "magnetoBlock": 13189133, "mystiqueBlock": 14525000, + "spiralBlock": 19250000, "ethash": { }, "discovery" : { + "dns": "enrtree://AJE62Q4DUX4QMMXEHCSSCSC65TDHZYSMONSD64P3WULVLSF6MRQ3K@all.classic.blockd.info", "bootnodes" : [ "enode://8e73168affd8d445edda09c561d607081ca5d7963317caae2702f701eb6546b06948b7f8687a795de576f6a5f33c44828e25a90aa63de18db380a11e660dd06f@159.203.37.80:30303", "enode://2b1ef75e8b7119b6e0294f2e51ead2cf1a5400472452c199e9587727ada99e7e2b1199e36adcad6cbae65dce2410559546e4d83d8c93d45a559e723e56444c03@67.207.93.100:30303",