From eb6a1fc07c0a7c85a2ada7d7fb776e2d93fbce52 Mon Sep 17 00:00:00 2001 From: Karim TAAM Date: Sun, 31 Dec 2023 13:35:01 +0100 Subject: [PATCH 1/3] mark deleted slot during clear storage step (#6305) Signed-off-by: Karim Taam Co-authored-by: garyschulte --- .../bonsai/worldview/BonsaiWorldState.java | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/worldview/BonsaiWorldState.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/worldview/BonsaiWorldState.java index b9cfcbeb368..323a9e510e5 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/worldview/BonsaiWorldState.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/worldview/BonsaiWorldState.java @@ -59,6 +59,7 @@ import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.bytes.Bytes32; +import org.apache.tuweni.rlp.RLP; import org.apache.tuweni.units.bigints.UInt256; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -361,14 +362,24 @@ private void clearStorage( (location, key) -> getStorageTrieNode(addressHash, location, key), oldAccount.getStorageRoot()); try { + + final StorageConsumingMap> storageToDelete = + worldStateUpdater.getStorageToUpdate().get(address); Map entriesToDelete = storageTrie.entriesFrom(Bytes32.ZERO, 256); while (!entriesToDelete.isEmpty()) { - entriesToDelete - .keySet() - .forEach( - k -> - bonsaiUpdater.removeStorageValueBySlotHash( - address.addressHash(), Hash.wrap(k))); + entriesToDelete.forEach( + (k, v) -> { + final StorageSlotKey storageSlotKey = + new StorageSlotKey(Hash.wrap(k), Optional.empty()); + final UInt256 slotValue = + UInt256.fromBytes(Bytes32.leftPad(RLP.decodeValue(v))); + bonsaiUpdater.removeStorageValueBySlotHash( + address.addressHash(), storageSlotKey.getSlotHash()); + storageToDelete + .computeIfAbsent( + storageSlotKey, key -> new BonsaiValue<>(slotValue, null, true)) + .setPrior(slotValue); + }); entriesToDelete.keySet().forEach(storageTrie::remove); if (entriesToDelete.size() == 256) { entriesToDelete = storageTrie.entriesFrom(Bytes32.ZERO, 256); From e62781bbc1cfa958dd7002ebd4b8bdd34d721d70 Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Wed, 3 Jan 2024 11:35:17 +1000 Subject: [PATCH 2/3] made directory structure of tests match source; fixed one typo (#6337) Signed-off-by: Sally MacFarlane --- .../cli/subcommands/operator/GenerateBlockchainConfig.java | 2 +- .../{ => subcommands}/operator/OperatorSubCommandTest.java | 7 +++---- .../besu/cli/{ => subcommands}/rlp/RLPSubCommandTest.java | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) rename besu/src/test/java/org/hyperledger/besu/cli/{ => subcommands}/operator/OperatorSubCommandTest.java (98%) rename besu/src/test/java/org/hyperledger/besu/cli/{ => subcommands}/rlp/RLPSubCommandTest.java (99%) diff --git a/besu/src/main/java/org/hyperledger/besu/cli/subcommands/operator/GenerateBlockchainConfig.java b/besu/src/main/java/org/hyperledger/besu/cli/subcommands/operator/GenerateBlockchainConfig.java index 0fe2b2f2cf8..3dc02f0f2bf 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/subcommands/operator/GenerateBlockchainConfig.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/subcommands/operator/GenerateBlockchainConfig.java @@ -61,7 +61,7 @@ @Command( name = "generate-blockchain-config", - description = "Generates node keypairs and genesis file with RLP encoded extra data.", + description = "Generate node keypairs and genesis file with RLP encoded extra data.", mixinStandardHelpOptions = true, versionProvider = VersionProvider.class) class GenerateBlockchainConfig implements Runnable { diff --git a/besu/src/test/java/org/hyperledger/besu/cli/operator/OperatorSubCommandTest.java b/besu/src/test/java/org/hyperledger/besu/cli/subcommands/operator/OperatorSubCommandTest.java similarity index 98% rename from besu/src/test/java/org/hyperledger/besu/cli/operator/OperatorSubCommandTest.java rename to besu/src/test/java/org/hyperledger/besu/cli/subcommands/operator/OperatorSubCommandTest.java index ac1ec2e5777..7e9a36719d7 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/operator/OperatorSubCommandTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/subcommands/operator/OperatorSubCommandTest.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.cli.operator; +package org.hyperledger.besu.cli.subcommands.operator; import static java.lang.String.format; import static java.lang.System.currentTimeMillis; @@ -22,11 +22,10 @@ import static java.util.Collections.singletonList; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.contentOf; -import static org.hyperledger.besu.cli.operator.OperatorSubCommandTest.Cmd.cmd; +import static org.hyperledger.besu.cli.subcommands.operator.OperatorSubCommandTest.Cmd.cmd; import org.hyperledger.besu.BesuInfo; import org.hyperledger.besu.cli.CommandTestAbstract; -import org.hyperledger.besu.cli.subcommands.operator.OperatorSubCommand; import org.hyperledger.besu.crypto.SECP256K1; import org.hyperledger.besu.crypto.SECP256R1; import org.hyperledger.besu.crypto.SECPPrivateKey; @@ -72,7 +71,7 @@ public class OperatorSubCommandTest extends CommandTestAbstract { + System.lineSeparator() + "Commands:" + System.lineSeparator() - + " generate-blockchain-config Generates node keypairs and genesis file with RLP" + + " generate-blockchain-config Generate node keypairs and genesis file with RLP" + System.lineSeparator() + " encoded extra data." + System.lineSeparator() diff --git a/besu/src/test/java/org/hyperledger/besu/cli/rlp/RLPSubCommandTest.java b/besu/src/test/java/org/hyperledger/besu/cli/subcommands/rlp/RLPSubCommandTest.java similarity index 99% rename from besu/src/test/java/org/hyperledger/besu/cli/rlp/RLPSubCommandTest.java rename to besu/src/test/java/org/hyperledger/besu/cli/subcommands/rlp/RLPSubCommandTest.java index 3eca54df252..8c9b9aad932 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/rlp/RLPSubCommandTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/subcommands/rlp/RLPSubCommandTest.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.cli.rlp; +package org.hyperledger.besu.cli.subcommands.rlp; import static java.nio.charset.StandardCharsets.UTF_8; import static org.assertj.core.api.Assertions.assertThat; From e0cd89f9b5ca27763ba4b7b2589d486df81a9626 Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Wed, 3 Jan 2024 12:30:23 +1000 Subject: [PATCH 3/3] migrate controller tests to junit 5 (#6338) Signed-off-by: Sally MacFarlane --- .../controller/BesuControllerBuilderTest.java | 35 +++++---- .../besu/controller/BesuControllerTest.java | 8 +-- ...nsusScheduleBesuControllerBuilderTest.java | 8 +-- .../MergeBesuControllerBuilderTest.java | 71 ++++++++++-------- .../QbftBesuControllerBuilderTest.java | 72 +++++++++++-------- .../TransitionControllerBuilderTest.java | 34 +++++---- 6 files changed, 132 insertions(+), 96 deletions(-) diff --git a/besu/src/test/java/org/hyperledger/besu/controller/BesuControllerBuilderTest.java b/besu/src/test/java/org/hyperledger/besu/controller/BesuControllerBuilderTest.java index bb7304d9f77..dd9452e7806 100644 --- a/besu/src/test/java/org/hyperledger/besu/controller/BesuControllerBuilderTest.java +++ b/besu/src/test/java/org/hyperledger/besu/controller/BesuControllerBuilderTest.java @@ -16,6 +16,7 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.spy; @@ -58,21 +59,21 @@ import org.hyperledger.besu.services.kvstore.InMemoryKeyValueStorage; import java.math.BigInteger; +import java.nio.file.Path; import java.time.Clock; import java.util.OptionalLong; import com.google.common.collect.Range; import org.apache.tuweni.bytes.Bytes; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -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.junit.jupiter.api.io.TempDir; import org.mockito.Answers; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class BesuControllerBuilderTest { private BesuControllerBuilder besuControllerBuilder; @@ -100,9 +101,9 @@ public class BesuControllerBuilderTest { BigInteger networkId = BigInteger.ONE; - @Rule public final TemporaryFolder tempDirRule = new TemporaryFolder(); + @TempDir Path tempDir; - @Before + @BeforeEach public void setup() { when(genesisConfigFile.getParentHash()).thenReturn(Hash.ZERO.toHexString()); when(genesisConfigFile.getDifficulty()).thenReturn(Bytes.of(0).toHexString()); @@ -129,14 +130,18 @@ public void setup() { when(synchronizerConfiguration.getBlockPropagationRange()).thenReturn(Range.closed(1L, 2L)); - when(storageProvider.createWorldStateStorage(DataStorageFormat.FOREST)) + lenient() + .when(storageProvider.createWorldStateStorage(DataStorageFormat.FOREST)) .thenReturn(worldStateStorage); - when(storageProvider.createWorldStatePreimageStorage()).thenReturn(worldStatePreimageStorage); + lenient() + .when(storageProvider.createWorldStatePreimageStorage()) + .thenReturn(worldStatePreimageStorage); - when(worldStateStorage.isWorldStateAvailable(any(), any())).thenReturn(true); - when(worldStatePreimageStorage.updater()) + lenient().when(worldStateStorage.isWorldStateAvailable(any(), any())).thenReturn(true); + lenient() + .when(worldStatePreimageStorage.updater()) .thenReturn(mock(WorldStatePreimageStorage.Updater.class)); - when(worldStateStorage.updater()).thenReturn(mock(WorldStateStorage.Updater.class)); + lenient().when(worldStateStorage.updater()).thenReturn(mock(WorldStateStorage.Updater.class)); besuControllerBuilder = spy(visitWithMockConfigs(new MainnetBesuControllerBuilder())); } @@ -149,7 +154,7 @@ BesuControllerBuilder visitWithMockConfigs(final BesuControllerBuilder builder) .miningParameters(miningParameters) .metricsSystem(observableMetricsSystem) .privacyParameters(privacyParameters) - .dataDirectory(tempDirRule.getRoot().toPath()) + .dataDirectory(tempDir) .clock(clock) .transactionPoolConfiguration(poolConfiguration) .nodeKey(nodeKey) diff --git a/besu/src/test/java/org/hyperledger/besu/controller/BesuControllerTest.java b/besu/src/test/java/org/hyperledger/besu/controller/BesuControllerTest.java index e6b631a4e88..29667c9c0bf 100644 --- a/besu/src/test/java/org/hyperledger/besu/controller/BesuControllerTest.java +++ b/besu/src/test/java/org/hyperledger/besu/controller/BesuControllerTest.java @@ -37,13 +37,13 @@ import java.util.OptionalLong; import com.google.common.io.Resources; -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.Spy; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class BesuControllerTest { @Spy private GenesisConfigFile genesisConfigFile = GenesisConfigFile.mainnet(); diff --git a/besu/src/test/java/org/hyperledger/besu/controller/ConsensusScheduleBesuControllerBuilderTest.java b/besu/src/test/java/org/hyperledger/besu/controller/ConsensusScheduleBesuControllerBuilderTest.java index 4e1d87f4a68..cf98ec49add 100644 --- a/besu/src/test/java/org/hyperledger/besu/controller/ConsensusScheduleBesuControllerBuilderTest.java +++ b/besu/src/test/java/org/hyperledger/besu/controller/ConsensusScheduleBesuControllerBuilderTest.java @@ -54,13 +54,13 @@ import java.util.function.BiFunction; import org.assertj.core.api.SoftAssertions; -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.Mockito; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class ConsensusScheduleBesuControllerBuilderTest { private @Mock BiFunction< NavigableSet>, Optional, ProtocolSchedule> diff --git a/besu/src/test/java/org/hyperledger/besu/controller/MergeBesuControllerBuilderTest.java b/besu/src/test/java/org/hyperledger/besu/controller/MergeBesuControllerBuilderTest.java index 33a539f8bc2..4368e831381 100644 --- a/besu/src/test/java/org/hyperledger/besu/controller/MergeBesuControllerBuilderTest.java +++ b/besu/src/test/java/org/hyperledger/besu/controller/MergeBesuControllerBuilderTest.java @@ -18,6 +18,7 @@ import static org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider.createInMemoryBlockchain; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; @@ -61,6 +62,7 @@ import org.hyperledger.besu.services.kvstore.InMemoryKeyValueStorage; import java.math.BigInteger; +import java.nio.file.Path; import java.time.Clock; import java.util.Collections; import java.util.Optional; @@ -70,16 +72,15 @@ import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.bytes.Bytes32; import org.apache.tuweni.units.bigints.UInt256; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -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.junit.jupiter.api.io.TempDir; import org.mockito.Answers; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class MergeBesuControllerBuilderTest { private MergeBesuControllerBuilder besuControllerBuilder; @@ -108,46 +109,54 @@ public class MergeBesuControllerBuilderTest { TransactionPoolConfiguration.DEFAULT; private final ObservableMetricsSystem observableMetricsSystem = new NoOpMetricsSystem(); - @Rule public final TemporaryFolder tempDirRule = new TemporaryFolder(); + @TempDir Path tempDir; - @Before + @BeforeEach public void setup() { - when(genesisConfigFile.getParentHash()).thenReturn(Hash.ZERO.toHexString()); - when(genesisConfigFile.getDifficulty()).thenReturn(Bytes.of(0).toHexString()); - when(genesisConfigFile.getExtraData()).thenReturn(Bytes.EMPTY.toHexString()); - when(genesisConfigFile.getMixHash()).thenReturn(Hash.ZERO.toHexString()); - when(genesisConfigFile.getNonce()).thenReturn(Long.toHexString(1)); - when(genesisConfigFile.getConfigOptions(any())).thenReturn(genesisConfigOptions); - when(genesisConfigFile.getConfigOptions()).thenReturn(genesisConfigOptions); - when(genesisConfigOptions.getCheckpointOptions()).thenReturn(checkpointConfigOptions); + lenient().when(genesisConfigFile.getParentHash()).thenReturn(Hash.ZERO.toHexString()); + lenient().when(genesisConfigFile.getDifficulty()).thenReturn(Bytes.of(0).toHexString()); + lenient().when(genesisConfigFile.getExtraData()).thenReturn(Bytes.EMPTY.toHexString()); + lenient().when(genesisConfigFile.getMixHash()).thenReturn(Hash.ZERO.toHexString()); + lenient().when(genesisConfigFile.getNonce()).thenReturn(Long.toHexString(1)); + lenient().when(genesisConfigFile.getConfigOptions(any())).thenReturn(genesisConfigOptions); + lenient().when(genesisConfigFile.getConfigOptions()).thenReturn(genesisConfigOptions); + lenient().when(genesisConfigOptions.getCheckpointOptions()).thenReturn(checkpointConfigOptions); when(genesisConfigOptions.getTerminalTotalDifficulty()) .thenReturn((Optional.of(UInt256.valueOf(100L)))); when(genesisConfigOptions.getThanosBlockNumber()).thenReturn(OptionalLong.empty()); when(genesisConfigOptions.getTerminalBlockHash()).thenReturn(Optional.of(Hash.ZERO)); - when(genesisConfigOptions.getTerminalBlockNumber()).thenReturn(OptionalLong.of(1L)); - when(storageProvider.createBlockchainStorage(any(), any())) + lenient().when(genesisConfigOptions.getTerminalBlockNumber()).thenReturn(OptionalLong.of(1L)); + lenient() + .when(storageProvider.createBlockchainStorage(any(), any())) .thenReturn( new KeyValueStoragePrefixedKeyBlockchainStorage( new InMemoryKeyValueStorage(), new VariablesKeyValueStorage(new InMemoryKeyValueStorage()), new MainnetBlockHeaderFunctions())); - when(storageProvider.getStorageBySegmentIdentifier(any())) + lenient() + .when(storageProvider.getStorageBySegmentIdentifier(any())) .thenReturn(new InMemoryKeyValueStorage()); - when(synchronizerConfiguration.getDownloaderParallelism()).thenReturn(1); - when(synchronizerConfiguration.getTransactionsParallelism()).thenReturn(1); - when(synchronizerConfiguration.getComputationParallelism()).thenReturn(1); + lenient().when(synchronizerConfiguration.getDownloaderParallelism()).thenReturn(1); + lenient().when(synchronizerConfiguration.getTransactionsParallelism()).thenReturn(1); + lenient().when(synchronizerConfiguration.getComputationParallelism()).thenReturn(1); - when(synchronizerConfiguration.getBlockPropagationRange()).thenReturn(Range.closed(1L, 2L)); + lenient() + .when(synchronizerConfiguration.getBlockPropagationRange()) + .thenReturn(Range.closed(1L, 2L)); - when(storageProvider.createWorldStateStorage(DataStorageFormat.FOREST)) + lenient() + .when(storageProvider.createWorldStateStorage(DataStorageFormat.FOREST)) .thenReturn(worldStateStorage); - when(storageProvider.createWorldStatePreimageStorage()).thenReturn(worldStatePreimageStorage); + lenient() + .when(storageProvider.createWorldStatePreimageStorage()) + .thenReturn(worldStatePreimageStorage); - when(worldStateStorage.isWorldStateAvailable(any(), any())).thenReturn(true); - when(worldStatePreimageStorage.updater()) + lenient().when(worldStateStorage.isWorldStateAvailable(any(), any())).thenReturn(true); + lenient() + .when(worldStatePreimageStorage.updater()) .thenReturn(mock(WorldStatePreimageStorage.Updater.class)); - when(worldStateStorage.updater()).thenReturn(mock(WorldStateStorage.Updater.class)); - when(miningParameters.getTargetGasLimit()).thenReturn(OptionalLong.empty()); + lenient().when(worldStateStorage.updater()).thenReturn(mock(WorldStateStorage.Updater.class)); + lenient().when(miningParameters.getTargetGasLimit()).thenReturn(OptionalLong.empty()); besuControllerBuilder = visitWithMockConfigs(new MergeBesuControllerBuilder()); } @@ -162,7 +171,7 @@ MergeBesuControllerBuilder visitWithMockConfigs(final MergeBesuControllerBuilder .miningParameters(miningParameters) .metricsSystem(observableMetricsSystem) .privacyParameters(privacyParameters) - .dataDirectory(tempDirRule.getRoot().toPath()) + .dataDirectory(tempDir) .clock(clock) .transactionPoolConfiguration(poolConfiguration) .nodeKey(nodeKey) diff --git a/besu/src/test/java/org/hyperledger/besu/controller/QbftBesuControllerBuilderTest.java b/besu/src/test/java/org/hyperledger/besu/controller/QbftBesuControllerBuilderTest.java index 585f138027e..75fecf3f96e 100644 --- a/besu/src/test/java/org/hyperledger/besu/controller/QbftBesuControllerBuilderTest.java +++ b/besu/src/test/java/org/hyperledger/besu/controller/QbftBesuControllerBuilderTest.java @@ -17,6 +17,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -56,20 +57,20 @@ import org.hyperledger.besu.services.kvstore.InMemoryKeyValueStorage; import java.math.BigInteger; +import java.nio.file.Path; import java.time.Clock; import java.util.List; import com.google.common.collect.Range; import org.apache.tuweni.bytes.Bytes; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -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.junit.jupiter.api.io.TempDir; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class QbftBesuControllerBuilderTest { private BesuControllerBuilder qbftBesuControllerBuilder; @@ -92,43 +93,54 @@ public class QbftBesuControllerBuilderTest { TransactionPoolConfiguration.DEFAULT; private final ObservableMetricsSystem observableMetricsSystem = new NoOpMetricsSystem(); - @Rule public final TemporaryFolder tempDirRule = new TemporaryFolder(); + @TempDir Path tempDir; - @Before + @BeforeEach public void setup() { // besu controller setup - when(genesisConfigFile.getParentHash()).thenReturn(Hash.ZERO.toHexString()); - when(genesisConfigFile.getDifficulty()).thenReturn(Bytes.of(0).toHexString()); + lenient().when(genesisConfigFile.getParentHash()).thenReturn(Hash.ZERO.toHexString()); + lenient().when(genesisConfigFile.getDifficulty()).thenReturn(Bytes.of(0).toHexString()); when(genesisConfigFile.getExtraData()).thenReturn(Bytes.EMPTY.toHexString()); - when(genesisConfigFile.getMixHash()).thenReturn(Hash.ZERO.toHexString()); - when(genesisConfigFile.getNonce()).thenReturn(Long.toHexString(1)); - when(genesisConfigFile.getConfigOptions(any())).thenReturn(genesisConfigOptions); - when(genesisConfigFile.getConfigOptions()).thenReturn(genesisConfigOptions); - when(genesisConfigOptions.getCheckpointOptions()).thenReturn(checkpointConfigOptions); - when(storageProvider.createBlockchainStorage(any(), any())) + lenient().when(genesisConfigFile.getMixHash()).thenReturn(Hash.ZERO.toHexString()); + lenient().when(genesisConfigFile.getNonce()).thenReturn(Long.toHexString(1)); + lenient().when(genesisConfigFile.getConfigOptions(any())).thenReturn(genesisConfigOptions); + lenient().when(genesisConfigFile.getConfigOptions()).thenReturn(genesisConfigOptions); + lenient().when(genesisConfigOptions.getCheckpointOptions()).thenReturn(checkpointConfigOptions); + lenient() + .when(storageProvider.createBlockchainStorage(any(), any())) .thenReturn( new KeyValueStoragePrefixedKeyBlockchainStorage( new InMemoryKeyValueStorage(), new VariablesKeyValueStorage(new InMemoryKeyValueStorage()), new MainnetBlockHeaderFunctions())); - when(storageProvider.createWorldStateStorage(DataStorageFormat.FOREST)) + lenient() + .when(storageProvider.createWorldStateStorage(DataStorageFormat.FOREST)) .thenReturn(worldStateStorage); - when(worldStateStorage.isWorldStateAvailable(any(), any())).thenReturn(true); - when(worldStateStorage.updater()).thenReturn(mock(WorldStateStorage.Updater.class)); - when(worldStatePreimageStorage.updater()) + lenient().when(worldStateStorage.isWorldStateAvailable(any(), any())).thenReturn(true); + lenient().when(worldStateStorage.updater()).thenReturn(mock(WorldStateStorage.Updater.class)); + lenient() + .when(worldStatePreimageStorage.updater()) .thenReturn(mock(WorldStatePreimageStorage.Updater.class)); - when(storageProvider.createWorldStatePreimageStorage()).thenReturn(worldStatePreimageStorage); - when(synchronizerConfiguration.getDownloaderParallelism()).thenReturn(1); - when(synchronizerConfiguration.getTransactionsParallelism()).thenReturn(1); - when(synchronizerConfiguration.getComputationParallelism()).thenReturn(1); + lenient() + .when(storageProvider.createWorldStatePreimageStorage()) + .thenReturn(worldStatePreimageStorage); + lenient().when(synchronizerConfiguration.getDownloaderParallelism()).thenReturn(1); + lenient().when(synchronizerConfiguration.getTransactionsParallelism()).thenReturn(1); + lenient().when(synchronizerConfiguration.getComputationParallelism()).thenReturn(1); - when(synchronizerConfiguration.getBlockPropagationRange()).thenReturn(Range.closed(1L, 2L)); + lenient() + .when(synchronizerConfiguration.getBlockPropagationRange()) + .thenReturn(Range.closed(1L, 2L)); // qbft prepForBuild setup - when(genesisConfigOptions.getQbftConfigOptions()) + lenient() + .when(genesisConfigOptions.getQbftConfigOptions()) .thenReturn(new MutableQbftConfigOptions(JsonQbftConfigOptions.DEFAULT)); - when(genesisConfigOptions.getTransitions()).thenReturn(mock(TransitionsConfigOptions.class)); - when(genesisConfigFile.getExtraData()) + lenient() + .when(genesisConfigOptions.getTransitions()) + .thenReturn(mock(TransitionsConfigOptions.class)); + lenient() + .when(genesisConfigFile.getExtraData()) .thenReturn( QbftExtraDataCodec.createGenesisExtraDataString(List.of(Address.fromHexString("1")))); @@ -141,7 +153,7 @@ public void setup() { .miningParameters(miningParameters) .metricsSystem(observableMetricsSystem) .privacyParameters(privacyParameters) - .dataDirectory(tempDirRule.getRoot().toPath()) + .dataDirectory(tempDir) .clock(clock) .transactionPoolConfiguration(poolConfiguration) .nodeKey(nodeKey) diff --git a/besu/src/test/java/org/hyperledger/besu/controller/TransitionControllerBuilderTest.java b/besu/src/test/java/org/hyperledger/besu/controller/TransitionControllerBuilderTest.java index ab914ad4f5f..9b2011612a1 100644 --- a/besu/src/test/java/org/hyperledger/besu/controller/TransitionControllerBuilderTest.java +++ b/besu/src/test/java/org/hyperledger/besu/controller/TransitionControllerBuilderTest.java @@ -16,6 +16,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; @@ -53,18 +54,18 @@ import java.util.Optional; -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.Answers; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; /** * We only bother testing transitionControllerBuilder for PoW and Clique since those are the only * network types that are transitioning to PoS. */ -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class TransitionControllerBuilderTest { @Mock ProtocolSchedule preMergeProtocolSchedule; @@ -87,7 +88,7 @@ public class TransitionControllerBuilderTest { TransitionProtocolSchedule transitionProtocolSchedule; - @Before + @BeforeEach public void setup() { transitionProtocolSchedule = spy( @@ -99,13 +100,22 @@ public void setup() { powBuilder.genesisConfigFile(GenesisConfigFile.DEFAULT); postMergeBuilder.genesisConfigFile(GenesisConfigFile.DEFAULT); postMergeBuilder.storageProvider(storageProvider); - when(protocolContext.getBlockchain()).thenReturn(mockBlockchain); - when(transitionProtocolSchedule.getPostMergeSchedule()).thenReturn(postMergeProtocolSchedule); - when(transitionProtocolSchedule.getPreMergeSchedule()).thenReturn(preMergeProtocolSchedule); - when(protocolContext.getConsensusContext(CliqueContext.class)) + lenient().when(protocolContext.getBlockchain()).thenReturn(mockBlockchain); + lenient() + .when(transitionProtocolSchedule.getPostMergeSchedule()) + .thenReturn(postMergeProtocolSchedule); + lenient() + .when(transitionProtocolSchedule.getPreMergeSchedule()) + .thenReturn(preMergeProtocolSchedule); + lenient() + .when(protocolContext.getConsensusContext(CliqueContext.class)) .thenReturn(mock(CliqueContext.class)); - when(protocolContext.getConsensusContext(PostMergeContext.class)).thenReturn(mergeContext); - when(protocolContext.getConsensusContext(MergeContext.class)).thenReturn(mergeContext); + lenient() + .when(protocolContext.getConsensusContext(PostMergeContext.class)) + .thenReturn(mergeContext); + lenient() + .when(protocolContext.getConsensusContext(MergeContext.class)) + .thenReturn(mergeContext); when(ethProtocolManager.ethContext().getScheduler()) .thenReturn(new DeterministicEthScheduler()); miningParameters = MiningParameters.newDefault();