|
|
|
@ -18,6 +18,7 @@ import static org.assertj.core.api.Assertions.assertThat; |
|
|
|
|
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.metrics.noop.NoOpMetricsSystem; |
|
|
|
|
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 com.google.common.collect.Range; |
|
|
|
|
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 @@ public class MergeBesuControllerBuilderTest { |
|
|
|
|
.miningParameters(miningParameters) |
|
|
|
|
.metricsSystem(observableMetricsSystem) |
|
|
|
|
.privacyParameters(privacyParameters) |
|
|
|
|
.dataDirectory(tempDirRule.getRoot().toPath()) |
|
|
|
|
.dataDirectory(tempDir) |
|
|
|
|
.clock(clock) |
|
|
|
|
.transactionPoolConfiguration(poolConfiguration) |
|
|
|
|
.nodeKey(nodeKey) |
|
|
|
|