fix unit tests

Signed-off-by: Karim TAAM <karim.t2am@gmail.com>
pull/6920/head
Karim TAAM 1 year ago
parent 657a78e62b
commit 6d4a4bb582
  1. 20
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/worldstate/WorldStateStorageCoordinator.java
  2. 11
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/SnapWorldDownloadState.java
  3. 31
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckPointSyncChainDownloaderTest.java
  4. 73
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastDownloaderFactoryTest.java
  5. 1
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncActionsTest.java
  6. 1
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncChainDownloaderTest.java
  7. 147
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncDownloaderTest.java
  8. 2
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/worldstate/FastWorldStateDownloaderTest.java
  9. 7
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/worldstate/LoadLocalDataStepTest.java

@ -26,7 +26,12 @@ import java.util.function.Function;
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.bytes.Bytes32;
public record WorldStateStorageCoordinator(WorldStateKeyValueStorage worldStateKeyValueStorage) {
public class WorldStateStorageCoordinator {
private final WorldStateKeyValueStorage worldStateKeyValueStorage;
public WorldStateStorageCoordinator(final WorldStateKeyValueStorage worldStateKeyValueStorage) {
this.worldStateKeyValueStorage = worldStateKeyValueStorage;
}
public DataStorageFormat getDataStorageFormat() {
return worldStateKeyValueStorage.getDataStorageFormat();
@ -63,6 +68,15 @@ public record WorldStateStorageCoordinator(WorldStateKeyValueStorage worldStateK
return (STRATEGY) worldStateKeyValueStorage;
}
public boolean isMatchingFlatMode(final FlatDbMode flatDbMode) {
if (getDataStorageFormat().equals(DataStorageFormat.BONSAI)) {
final BonsaiWorldStateKeyValueStorage bonsaiWorldStateStorageStrategy =
(BonsaiWorldStateKeyValueStorage) worldStateKeyValueStorage();
return bonsaiWorldStateStorageStrategy.getFlatDbMode().equals(flatDbMode);
}
return false;
}
public void applyOnMatchingFlatMode(
final FlatDbMode flatDbMode, final Consumer<BonsaiWorldStateKeyValueStorage> onStrategy) {
applyOnMatchingStrategy(
@ -134,4 +148,8 @@ public record WorldStateStorageCoordinator(WorldStateKeyValueStorage worldStateK
public void clear() {
worldStateKeyValueStorage.clear();
}
public WorldStateKeyValueStorage worldStateKeyValueStorage() {
return worldStateKeyValueStorage;
}
}

@ -194,15 +194,10 @@ public class SnapWorldDownloadState extends WorldDownloadState<SnapDataRequest>
blockObserverId.ifPresent(blockchain::removeObserver);
// If the flat database healing process is not in progress and the flat database mode is
// FULL
if (!snapSyncState.isHealFlatDatabaseInProgress()) {
worldStateStorageCoordinator.applyOnMatchingFlatMode(
FlatDbMode.FULL,
bonsaiWorldStateStorageStrategy -> {
// Start the flat database healing process
startFlatDatabaseHeal(header);
});
if (!snapSyncState.isHealFlatDatabaseInProgress()
&& worldStateStorageCoordinator.isMatchingFlatMode(FlatDbMode.FULL)) {
startFlatDatabaseHeal(header);
}
// If the flat database healing process is in progress or the flat database mode is not FULL
else {
final WorldStateKeyValueStorage.Updater updater = worldStateStorageCoordinator.updater();

@ -20,6 +20,8 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.WorldStateKeyValueStorage;
import org.hyperledger.besu.ethereum.bonsai.storage.BonsaiWorldStateKeyValueStorage;
import org.hyperledger.besu.ethereum.chain.Blockchain;
import org.hyperledger.besu.ethereum.chain.MutableBlockchain;
import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil;
@ -35,6 +37,7 @@ import org.hyperledger.besu.ethereum.eth.sync.fastsync.FastSyncState;
import org.hyperledger.besu.ethereum.eth.sync.fastsync.checkpoint.Checkpoint;
import org.hyperledger.besu.ethereum.eth.sync.fastsync.checkpoint.ImmutableCheckpoint;
import org.hyperledger.besu.ethereum.eth.sync.state.SyncState;
import org.hyperledger.besu.ethereum.forest.storage.ForestWorldStateKeyValueStorage;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.ethereum.worldstate.DataStorageFormat;
import org.hyperledger.besu.ethereum.worldstate.WorldStateStorageCoordinator;
@ -53,9 +56,6 @@ import org.junit.jupiter.params.provider.ArgumentsSource;
public class CheckPointSyncChainDownloaderTest {
private final WorldStateStorageCoordinator worldStateStorageCoordinator =
mock(WorldStateStorageCoordinator.class);
protected ProtocolSchedule protocolSchedule;
protected EthProtocolManager ethProtocolManager;
protected EthContext ethContext;
@ -67,6 +67,8 @@ public class CheckPointSyncChainDownloaderTest {
protected Blockchain otherBlockchain;
private Checkpoint checkpoint;
private WorldStateStorageCoordinator worldStateStorageCoordinator;
static class CheckPointSyncChainDownloaderTestArguments implements ArgumentsProvider {
@Override
public Stream<? extends Arguments> provideArguments(final ExtensionContext context) {
@ -75,11 +77,26 @@ public class CheckPointSyncChainDownloaderTest {
}
}
public void setup(final DataStorageFormat storageFormat) {
when(worldStateStorageCoordinator.isWorldStateAvailable(any(), any())).thenReturn(true);
final BlockchainSetupUtil localBlockchainSetup = BlockchainSetupUtil.forTesting(storageFormat);
public void setup(final DataStorageFormat dataStorageFormat) {
final WorldStateKeyValueStorage worldStateKeyValueStorage;
if (dataStorageFormat.equals(DataStorageFormat.BONSAI)) {
worldStateKeyValueStorage = mock(BonsaiWorldStateKeyValueStorage.class);
when(((BonsaiWorldStateKeyValueStorage) worldStateKeyValueStorage)
.isWorldStateAvailable(any(), any()))
.thenReturn(true);
} else {
worldStateKeyValueStorage = mock(ForestWorldStateKeyValueStorage.class);
when(((ForestWorldStateKeyValueStorage) worldStateKeyValueStorage)
.isWorldStateAvailable(any()))
.thenReturn(true);
}
when(worldStateKeyValueStorage.getDataStorageFormat()).thenReturn(dataStorageFormat);
worldStateStorageCoordinator = new WorldStateStorageCoordinator(worldStateKeyValueStorage);
final BlockchainSetupUtil localBlockchainSetup =
BlockchainSetupUtil.forTesting(dataStorageFormat);
localBlockchain = localBlockchainSetup.getBlockchain();
otherBlockchainSetup = BlockchainSetupUtil.forTesting(storageFormat);
otherBlockchainSetup = BlockchainSetupUtil.forTesting(dataStorageFormat);
otherBlockchain = otherBlockchainSetup.getBlockchain();
protocolSchedule = localBlockchainSetup.getProtocolSchedule();
protocolContext = localBlockchainSetup.getProtocolContext();

@ -23,6 +23,8 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.WorldStateKeyValueStorage;
import org.hyperledger.besu.ethereum.bonsai.storage.BonsaiWorldStateKeyValueStorage;
import org.hyperledger.besu.ethereum.chain.MutableBlockchain;
import org.hyperledger.besu.ethereum.eth.manager.EthContext;
import org.hyperledger.besu.ethereum.eth.sync.PivotBlockSelector;
@ -30,7 +32,9 @@ import org.hyperledger.besu.ethereum.eth.sync.SyncMode;
import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration;
import org.hyperledger.besu.ethereum.eth.sync.fastsync.worldstate.FastDownloaderFactory;
import org.hyperledger.besu.ethereum.eth.sync.state.SyncState;
import org.hyperledger.besu.ethereum.forest.storage.ForestWorldStateKeyValueStorage;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.ethereum.worldstate.DataStorageFormat;
import org.hyperledger.besu.ethereum.worldstate.WorldStateStorageCoordinator;
import org.hyperledger.besu.plugin.services.MetricsSystem;
@ -40,10 +44,16 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Clock;
import java.util.Optional;
import java.util.stream.Stream;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.ArgumentsProvider;
import org.junit.jupiter.params.provider.ArgumentsSource;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.junit.jupiter.MockitoSettings;
@ -59,15 +69,36 @@ public class FastDownloaderFactoryTest {
@Mock private ProtocolContext protocolContext;
@Mock private MetricsSystem metricsSystem;
@Mock private EthContext ethContext;
@Mock private WorldStateStorageCoordinator worldStateStorageCoordinator;
@Mock private SyncState syncState;
@Mock private Clock clock;
@Mock private Path dataDirectory;
@Mock private PivotBlockSelector pivotBlockSelector;
private WorldStateKeyValueStorage worldStateKeyValueStorage;
private WorldStateStorageCoordinator worldStateStorageCoordinator;
@SuppressWarnings("unchecked")
@Test
public void shouldThrowIfSyncModeChangedWhileFastSyncIncomplete() {
static class FastDownloaderFactoryTestArguments implements ArgumentsProvider {
@Override
public Stream<? extends Arguments> provideArguments(final ExtensionContext context) {
return Stream.of(
Arguments.of(DataStorageFormat.BONSAI), Arguments.of(DataStorageFormat.FOREST));
}
}
public void setup(final DataStorageFormat dataStorageFormat) {
if (dataStorageFormat.equals(DataStorageFormat.BONSAI)) {
worldStateKeyValueStorage = mock(BonsaiWorldStateKeyValueStorage.class);
} else {
worldStateKeyValueStorage = mock(ForestWorldStateKeyValueStorage.class);
}
when(worldStateKeyValueStorage.getDataStorageFormat()).thenReturn(dataStorageFormat);
worldStateStorageCoordinator = new WorldStateStorageCoordinator(worldStateKeyValueStorage);
}
@ParameterizedTest
@ArgumentsSource(FastDownloaderFactoryTestArguments.class)
public void shouldThrowIfSyncModeChangedWhileFastSyncIncomplete(
final DataStorageFormat dataStorageFormat) {
setup(dataStorageFormat);
initDataDirectory(true);
when(syncConfig.getSyncMode()).thenReturn(SyncMode.FULL);
@ -88,8 +119,11 @@ public class FastDownloaderFactoryTest {
}
@SuppressWarnings({"unchecked", "rawtypes"})
@Test
public void shouldNotThrowIfSyncModeChangedWhileFastSyncComplete() {
@ParameterizedTest
@ArgumentsSource(FastDownloaderFactoryTestArguments.class)
public void shouldNotThrowIfSyncModeChangedWhileFastSyncComplete(
final DataStorageFormat dataStorageFormat) {
setup(dataStorageFormat);
initDataDirectory(false);
when(syncConfig.getSyncMode()).thenReturn(SyncMode.FULL);
@ -109,8 +143,11 @@ public class FastDownloaderFactoryTest {
}
@SuppressWarnings("unchecked")
@Test
public void shouldNotThrowWhenFastSyncModeRequested() throws NoSuchFieldException {
@ParameterizedTest
@ArgumentsSource(FastDownloaderFactoryTestArguments.class)
public void shouldNotThrowWhenFastSyncModeRequested(final DataStorageFormat dataStorageFormat)
throws NoSuchFieldException {
setup(dataStorageFormat);
initDataDirectory(false);
final MutableBlockchain mutableBlockchain = mock(MutableBlockchain.class);
@ -133,8 +170,12 @@ public class FastDownloaderFactoryTest {
verify(mutableBlockchain).getChainHeadBlockNumber();
}
@Test
public void shouldClearWorldStateDuringFastSyncWhenStateQueDirectoryExists() throws IOException {
@ParameterizedTest
@ArgumentsSource(FastDownloaderFactoryTestArguments.class)
public void shouldClearWorldStateDuringFastSyncWhenStateQueDirectoryExists(
final DataStorageFormat dataStorageFormat) throws IOException {
Assumptions.assumeTrue(dataStorageFormat == DataStorageFormat.FOREST);
setup(dataStorageFormat);
when(syncConfig.getSyncMode()).thenReturn(SyncMode.FAST);
final MutableBlockchain mutableBlockchain = mock(MutableBlockchain.class);
when(mutableBlockchain.getChainHeadBlockNumber()).thenReturn(0L);
@ -160,12 +201,16 @@ public class FastDownloaderFactoryTest {
syncState,
clock);
verify(worldStateStorageCoordinator).clear();
verify(worldStateKeyValueStorage).clear();
assertThat(Files.exists(stateQueueDir)).isFalse();
}
@Test
public void shouldCrashWhenStateQueueIsNotDirectory() throws IOException {
@ParameterizedTest
@ArgumentsSource(FastDownloaderFactoryTestArguments.class)
public void shouldCrashWhenStateQueueIsNotDirectory(final DataStorageFormat dataStorageFormat)
throws IOException {
Assumptions.assumeTrue(dataStorageFormat == DataStorageFormat.FOREST);
setup(dataStorageFormat);
when(syncConfig.getSyncMode()).thenReturn(SyncMode.FAST);
final MutableBlockchain mutableBlockchain = mock(MutableBlockchain.class);
when(mutableBlockchain.getChainHeadBlockNumber()).thenReturn(0L);

@ -86,6 +86,7 @@ public class FastSyncActionsTest {
}
public void setUp(final DataStorageFormat storageFormat) {
when(worldStateStorageCoordinator.getDataStorageFormat()).thenReturn(storageFormat);
blockchainSetupUtil = BlockchainSetupUtil.forTesting(storageFormat);
blockchainSetupUtil.importAllBlocks();
blockchain = blockchainSetupUtil.getBlockchain();

@ -74,6 +74,7 @@ public class FastSyncChainDownloaderTest {
}
public void setup(final DataStorageFormat storageFormat) {
when(worldStateStorageCoordinator.getDataStorageFormat()).thenReturn(storageFormat);
when(worldStateStorageCoordinator.isWorldStateAvailable(any(), any())).thenReturn(true);
final BlockchainSetupUtil localBlockchainSetup = BlockchainSetupUtil.forTesting(storageFormat);
localBlockchain = localBlockchainSetup.getBlockchain();

@ -26,6 +26,8 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import org.hyperledger.besu.ethereum.WorldStateKeyValueStorage;
import org.hyperledger.besu.ethereum.bonsai.storage.BonsaiWorldStateKeyValueStorage;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture;
import org.hyperledger.besu.ethereum.eth.sync.ChainDownloader;
@ -34,6 +36,7 @@ import org.hyperledger.besu.ethereum.eth.sync.fastsync.worldstate.FastWorldState
import org.hyperledger.besu.ethereum.eth.sync.fastsync.worldstate.NodeDataRequest;
import org.hyperledger.besu.ethereum.eth.sync.worldstate.StalledDownloadException;
import org.hyperledger.besu.ethereum.eth.sync.worldstate.WorldStateDownloader;
import org.hyperledger.besu.ethereum.forest.storage.ForestWorldStateKeyValueStorage;
import org.hyperledger.besu.ethereum.worldstate.DataStorageFormat;
import org.hyperledger.besu.ethereum.worldstate.WorldStateStorageCoordinator;
import org.hyperledger.besu.services.tasks.TaskCollection;
@ -44,19 +47,20 @@ import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
import java.util.stream.Stream;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.ArgumentsProvider;
import org.junit.jupiter.params.provider.ArgumentsSource;
public class FastSyncDownloaderTest {
@SuppressWarnings("unchecked")
private final FastSyncActions fastSyncActions = mock(FastSyncActions.class);
private final WorldStateStorageCoordinator worldStateStorageCoordinator =
mock(WorldStateStorageCoordinator.class);
private final WorldStateDownloader worldStateDownloader = mock(FastWorldStateDownloader.class);
private final FastSyncStateStorage storage = mock(FastSyncStateStorage.class);
@ -66,25 +70,47 @@ public class FastSyncDownloaderTest {
private final ChainDownloader chainDownloader = mock(ChainDownloader.class);
private final Path fastSyncDataDirectory = null;
private WorldStateStorageCoordinator worldStateStorageCoordinator;
private FastSyncDownloader<NodeDataRequest> downloader;
static class FastSyncDownloaderTestArguments implements ArgumentsProvider {
@Override
public Stream<? extends Arguments> provideArguments(final ExtensionContext context) {
return Stream.of(
Arguments.of(DataStorageFormat.BONSAI), Arguments.of(DataStorageFormat.FOREST));
}
}
private final FastSyncDownloader<NodeDataRequest> downloader =
new FastSyncDownloader<>(
fastSyncActions,
worldStateStorageCoordinator,
worldStateDownloader,
storage,
taskCollection,
fastSyncDataDirectory,
FastSyncState.EMPTY_SYNC_STATE);
@BeforeEach
public void setup() {
when(worldStateStorageCoordinator.getDataStorageFormat()).thenReturn(DataStorageFormat.FOREST);
when(worldStateStorageCoordinator.isWorldStateAvailable(any(), any())).thenReturn(true);
public void setup(final DataStorageFormat dataStorageFormat) {
final WorldStateKeyValueStorage worldStateKeyValueStorage;
if (dataStorageFormat.equals(DataStorageFormat.BONSAI)) {
worldStateKeyValueStorage = mock(BonsaiWorldStateKeyValueStorage.class);
when(((BonsaiWorldStateKeyValueStorage) worldStateKeyValueStorage)
.isWorldStateAvailable(any(), any()))
.thenReturn(true);
} else {
worldStateKeyValueStorage = mock(ForestWorldStateKeyValueStorage.class);
when(((ForestWorldStateKeyValueStorage) worldStateKeyValueStorage)
.isWorldStateAvailable(any()))
.thenReturn(true);
}
when(worldStateKeyValueStorage.getDataStorageFormat()).thenReturn(dataStorageFormat);
worldStateStorageCoordinator = new WorldStateStorageCoordinator(worldStateKeyValueStorage);
downloader =
new FastSyncDownloader<>(
fastSyncActions,
worldStateStorageCoordinator,
worldStateDownloader,
storage,
taskCollection,
fastSyncDataDirectory,
FastSyncState.EMPTY_SYNC_STATE);
}
@Test
public void shouldCompleteFastSyncSuccessfully() {
@ParameterizedTest
@ArgumentsSource(FastSyncDownloaderTestArguments.class)
public void shouldCompleteFastSyncSuccessfully(final DataStorageFormat dataStorageFormat) {
setup(dataStorageFormat);
final FastSyncState selectPivotBlockState = new FastSyncState(50);
final BlockHeader pivotBlockHeader = new BlockHeaderTestFixture().number(50).buildHeader();
final FastSyncState downloadPivotBlockHeaderState = new FastSyncState(pivotBlockHeader);
@ -112,8 +138,10 @@ public class FastSyncDownloaderTest {
assertThat(result).isCompletedWithValue(downloadPivotBlockHeaderState);
}
@Test
public void shouldResumeFastSync() {
@ParameterizedTest
@ArgumentsSource(FastSyncDownloaderTestArguments.class)
public void shouldResumeFastSync(final DataStorageFormat dataStorageFormat) {
setup(dataStorageFormat);
final BlockHeader pivotBlockHeader = new BlockHeaderTestFixture().number(50).buildHeader();
final FastSyncState fastSyncState = new FastSyncState(pivotBlockHeader);
final CompletableFuture<FastSyncState> complete = completedFuture(fastSyncState);
@ -148,8 +176,10 @@ public class FastSyncDownloaderTest {
assertThat(result).isCompletedWithValue(fastSyncState);
}
@Test
public void shouldAbortIfSelectPivotBlockFails() {
@ParameterizedTest
@ArgumentsSource(FastSyncDownloaderTestArguments.class)
public void shouldAbortIfSelectPivotBlockFails(final DataStorageFormat dataStorageFormat) {
setup(dataStorageFormat);
when(fastSyncActions.selectPivotBlock(FastSyncState.EMPTY_SYNC_STATE))
.thenThrow(new FastSyncException(FastSyncError.UNEXPECTED_ERROR));
@ -161,8 +191,10 @@ public class FastSyncDownloaderTest {
verifyNoMoreInteractions(fastSyncActions);
}
@Test
public void shouldAbortIfWorldStateDownloadFails() {
@ParameterizedTest
@ArgumentsSource(FastSyncDownloaderTestArguments.class)
public void shouldAbortIfWorldStateDownloadFails(final DataStorageFormat dataStorageFormat) {
setup(dataStorageFormat);
final CompletableFuture<Void> worldStateFuture = new CompletableFuture<>();
final CompletableFuture<Void> chainFuture = new CompletableFuture<>();
final FastSyncState selectPivotBlockState = new FastSyncState(50);
@ -199,8 +231,10 @@ public class FastSyncDownloaderTest {
assertThat(chainFuture).isCancelled();
}
@Test
public void shouldAbortIfChainDownloadFails() {
@ParameterizedTest
@ArgumentsSource(FastSyncDownloaderTestArguments.class)
public void shouldAbortIfChainDownloadFails(final DataStorageFormat dataStorageFormat) {
setup(dataStorageFormat);
final CompletableFuture<Void> chainFuture = new CompletableFuture<>();
final CompletableFuture<Void> worldStateFuture = new CompletableFuture<>();
final FastSyncState selectPivotBlockState = new FastSyncState(50);
@ -235,8 +269,10 @@ public class FastSyncDownloaderTest {
assertThat(worldStateFuture).isCancelled();
}
@Test
public void shouldAbortIfStopped() {
@ParameterizedTest
@ArgumentsSource(FastSyncDownloaderTestArguments.class)
public void shouldAbortIfStopped(final DataStorageFormat dataStorageFormat) {
setup(dataStorageFormat);
final FastSyncState selectPivotBlockState = new FastSyncState(50);
final BlockHeader pivotBlockHeader = new BlockHeaderTestFixture().number(50).buildHeader();
final FastSyncState downloadPivotBlockHeaderState = new FastSyncState(pivotBlockHeader);
@ -269,8 +305,11 @@ public class FastSyncDownloaderTest {
verifyNoMoreInteractions(fastSyncActions, worldStateDownloader, storage);
}
@Test
public void shouldNotConsiderFastSyncCompleteIfOnlyWorldStateDownloadIsComplete() {
@ParameterizedTest
@ArgumentsSource(FastSyncDownloaderTestArguments.class)
public void shouldNotConsiderFastSyncCompleteIfOnlyWorldStateDownloadIsComplete(
final DataStorageFormat dataStorageFormat) {
setup(dataStorageFormat);
final CompletableFuture<Void> chainFuture = new CompletableFuture<>();
final CompletableFuture<Void> worldStateFuture = new CompletableFuture<>();
final FastSyncState selectPivotBlockState = new FastSyncState(50);
@ -304,8 +343,11 @@ public class FastSyncDownloaderTest {
assertThat(result).isNotDone();
}
@Test
public void shouldNotConsiderFastSyncCompleteIfOnlyChainDownloadIsComplete() {
@ParameterizedTest
@ArgumentsSource(FastSyncDownloaderTestArguments.class)
public void shouldNotConsiderFastSyncCompleteIfOnlyChainDownloadIsComplete(
final DataStorageFormat dataStorageFormat) {
setup(dataStorageFormat);
final CompletableFuture<Void> chainFuture = new CompletableFuture<>();
final CompletableFuture<Void> worldStateFuture = new CompletableFuture<>();
final FastSyncState selectPivotBlockState = new FastSyncState(50);
@ -340,8 +382,11 @@ public class FastSyncDownloaderTest {
}
@SuppressWarnings("unchecked")
@Test
public void shouldResetFastSyncStateAndRestartProcessIfWorldStateIsUnavailable() {
@ParameterizedTest
@ArgumentsSource(FastSyncDownloaderTestArguments.class)
public void shouldResetFastSyncStateAndRestartProcessIfWorldStateIsUnavailable(
final DataStorageFormat dataStorageFormat) {
setup(dataStorageFormat);
final CompletableFuture<Void> firstWorldStateFuture = new CompletableFuture<>();
final CompletableFuture<Void> secondWorldStateFuture = new CompletableFuture<>();
final CompletableFuture<Void> chainFuture = new CompletableFuture<>();
@ -411,8 +456,11 @@ public class FastSyncDownloaderTest {
}
@SuppressWarnings("unchecked")
@Test
public void shouldResetFastSyncStateAndRestartProcessIfANonFastSyncExceptionOccurs() {
@ParameterizedTest
@ArgumentsSource(FastSyncDownloaderTestArguments.class)
public void shouldResetFastSyncStateAndRestartProcessIfANonFastSyncExceptionOccurs(
final DataStorageFormat dataStorageFormat) {
setup(dataStorageFormat);
final CompletableFuture<Void> firstWorldStateFuture = new CompletableFuture<>();
final CompletableFuture<Void> secondWorldStateFuture = new CompletableFuture<>();
final CompletableFuture<Void> chainFuture = new CompletableFuture<>();
@ -485,14 +533,20 @@ public class FastSyncDownloaderTest {
assertThat(result).isCompletedWithValue(secondDownloadPivotBlockHeaderState);
}
@Test
public void shouldNotHaveTrailingPeerRequirementsBeforePivotBlockSelected() {
@ParameterizedTest
@ArgumentsSource(FastSyncDownloaderTestArguments.class)
public void shouldNotHaveTrailingPeerRequirementsBeforePivotBlockSelected(
final DataStorageFormat dataStorageFormat) {
setup(dataStorageFormat);
downloader.start();
Assertions.assertThat(downloader.calculateTrailingPeerRequirements()).isEmpty();
}
@Test
public void shouldNotAllowPeersBeforePivotBlockOnceSelected() {
@ParameterizedTest
@ArgumentsSource(FastSyncDownloaderTestArguments.class)
public void shouldNotAllowPeersBeforePivotBlockOnceSelected(
final DataStorageFormat dataStorageFormat) {
setup(dataStorageFormat);
final FastSyncState selectPivotBlockState = new FastSyncState(50);
final BlockHeader pivotBlockHeader = new BlockHeaderTestFixture().number(50).buildHeader();
final FastSyncState downloadPivotBlockHeaderState = new FastSyncState(pivotBlockHeader);
@ -513,8 +567,11 @@ public class FastSyncDownloaderTest {
.contains(new TrailingPeerRequirements(50, 0));
}
@Test
public void shouldNotHaveTrailingPeerRequirementsAfterDownloadCompletes() {
@ParameterizedTest
@ArgumentsSource(FastSyncDownloaderTestArguments.class)
public void shouldNotHaveTrailingPeerRequirementsAfterDownloadCompletes(
final DataStorageFormat dataStorageFormat) {
setup(dataStorageFormat);
final FastSyncState selectPivotBlockState = new FastSyncState(50);
final BlockHeader pivotBlockHeader = new BlockHeaderTestFixture().number(50).buildHeader();
final FastSyncState downloadPivotBlockHeaderState = new FastSyncState(pivotBlockHeader);

@ -218,7 +218,7 @@ class FastWorldStateDownloaderTest {
final WorldStateDownloader downloader =
createDownloader(
ethProtocolManager.ethContext(),
worldStateArchive.getWorldStateStorage().worldStateKeyValueStorage(),
worldStateArchive.getWorldStateStorage(),
taskCollection);
final FastSyncState fastSyncState = new FastSyncState(header);

@ -23,6 +23,7 @@ import static org.mockito.Mockito.when;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.ethereum.bonsai.storage.BonsaiWorldStateKeyValueStorage;
import org.hyperledger.besu.ethereum.worldstate.DataStorageFormat;
import org.hyperledger.besu.ethereum.worldstate.WorldStateStorageCoordinator;
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;
import org.hyperledger.besu.services.pipeline.Pipe;
@ -32,6 +33,7 @@ import java.util.Optional;
import java.util.stream.Stream;
import org.apache.tuweni.bytes.Bytes;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
@ -54,6 +56,11 @@ public class LoadLocalDataStepTest {
new LoadLocalDataStep(
new WorldStateStorageCoordinator(worldStateKeyValueStorage), new NoOpMetricsSystem());
@BeforeEach
public void setup() {
when(worldStateKeyValueStorage.getDataStorageFormat()).thenReturn(DataStorageFormat.BONSAI);
}
@Test
public void shouldReturnStreamWithUnchangedTaskWhenDataNotPresent() {
final Stream<Task<NodeDataRequest>> output =

Loading…
Cancel
Save