[MINOR] CLI Subcommands migrate to junit 5 (#6282)

* updated cli and chainimport/export tests to junit 5

Signed-off-by: Sally MacFarlane <macfarla.github@gmail.com>

* subcommands and besucommand test to junit5

Signed-off-by: Sally MacFarlane <macfarla.github@gmail.com>

* removed duplicate line

Signed-off-by: Sally MacFarlane <macfarla.github@gmail.com>

* removed vintage junit dep

Signed-off-by: Sally MacFarlane <macfarla.github@gmail.com>

---------

Signed-off-by: Sally MacFarlane <macfarla.github@gmail.com>
Co-authored-by: Fabio Di Fabio <fabio.difabio@consensys.net>
pull/6309/head
Sally MacFarlane 11 months ago committed by GitHub
parent 4cbe7b0693
commit c9a41fa3e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      besu/build.gradle
  2. 57
      besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java
  3. 48
      besu/src/test/java/org/hyperledger/besu/cli/CommandTestAbstract.java
  4. 8
      besu/src/test/java/org/hyperledger/besu/cli/PasswordSubCommandTest.java
  5. 16
      besu/src/test/java/org/hyperledger/besu/cli/PublicKeySubCommandTest.java
  6. 8
      besu/src/test/java/org/hyperledger/besu/cli/ValidateConfigSubCommandTest.java
  7. 12
      besu/src/test/java/org/hyperledger/besu/cli/operator/OperatorSubCommandTest.java
  8. 2
      besu/src/test/java/org/hyperledger/besu/cli/options/AbstractCLIOptionsTest.java
  9. 8
      besu/src/test/java/org/hyperledger/besu/cli/options/EthProtocolOptionsTest.java
  10. 6
      besu/src/test/java/org/hyperledger/besu/cli/options/MetricsCLIOptionsTest.java
  11. 8
      besu/src/test/java/org/hyperledger/besu/cli/options/MiningOptionsTest.java
  12. 8
      besu/src/test/java/org/hyperledger/besu/cli/options/NetworkingOptionsTest.java
  13. 6
      besu/src/test/java/org/hyperledger/besu/cli/options/SynchronizerOptionsTest.java
  14. 8
      besu/src/test/java/org/hyperledger/besu/cli/options/TransactionPoolOptionsTest.java
  15. 2
      besu/src/test/java/org/hyperledger/besu/cli/options/stable/DataStorageOptionsTest.java
  16. 54
      besu/src/test/java/org/hyperledger/besu/cli/rlp/RLPSubCommandTest.java
  17. 111
      besu/src/test/java/org/hyperledger/besu/cli/subcommands/blocks/BlocksSubCommandTest.java
  18. 8
      besu/src/test/java/org/hyperledger/besu/cli/subcommands/storage/StorageSubCommandTest.java

@ -99,10 +99,8 @@ dependencies {
testImplementation 'org.awaitility:awaitility' testImplementation 'org.awaitility:awaitility'
testImplementation 'org.junit.jupiter:junit-jupiter' testImplementation 'org.junit.jupiter:junit-jupiter'
testImplementation 'org.mockito:mockito-core' testImplementation 'org.mockito:mockito-core'
testImplementation 'org.mockito:mockito-junit-jupiter'
testImplementation 'org.testcontainers:testcontainers' testImplementation 'org.testcontainers:testcontainers'
testImplementation 'tech.pegasys.discovery:discovery' testImplementation 'tech.pegasys.discovery:discovery'
testRuntimeOnly 'org.junit.vintage:junit-vintage-engine'
annotationProcessor 'com.google.dagger:dagger-compiler' annotationProcessor 'com.google.dagger:dagger-compiler'
} }

@ -127,19 +127,18 @@ import org.apache.commons.text.StringEscapeUtils;
import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.toml.Toml; import org.apache.tuweni.toml.Toml;
import org.apache.tuweni.toml.TomlParseResult; import org.apache.tuweni.toml.TomlParseResult;
import org.junit.After; import org.junit.jupiter.api.AfterEach;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Ignore; import org.junit.jupiter.api.Disabled;
import org.junit.Rule; import org.junit.jupiter.api.Test;
import org.junit.Test; import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.rules.TemporaryFolder; import org.junit.jupiter.api.io.TempDir;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor; import org.mockito.ArgumentCaptor;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner; import org.mockito.junit.jupiter.MockitoExtension;
import picocli.CommandLine; import picocli.CommandLine;
@RunWith(MockitoJUnitRunner.class) @ExtendWith(MockitoExtension.class)
public class BesuCommandTest extends CommandTestAbstract { public class BesuCommandTest extends CommandTestAbstract {
private static final String ENCLAVE_URI = "http://1.2.3.4:5555"; private static final String ENCLAVE_URI = "http://1.2.3.4:5555";
@ -198,7 +197,7 @@ public class BesuCommandTest extends CommandTestAbstract {
DEFAULT_API_CONFIGURATION = ImmutableApiConfiguration.builder().build(); DEFAULT_API_CONFIGURATION = ImmutableApiConfiguration.builder().build();
} }
@Before @BeforeEach
public void setup() { public void setup() {
try { try {
// optimistically tear down a potential previous loaded trusted setup // optimistically tear down a potential previous loaded trusted setup
@ -210,7 +209,7 @@ public class BesuCommandTest extends CommandTestAbstract {
MergeConfigOptions.setMergeEnabled(false); MergeConfigOptions.setMergeEnabled(false);
} }
@After @AfterEach
public void tearDown() { public void tearDown() {
MergeConfigOptions.setMergeEnabled(false); MergeConfigOptions.setMergeEnabled(false);
@ -366,10 +365,10 @@ public class BesuCommandTest extends CommandTestAbstract {
} }
@Test @Test
public void overrideDefaultValuesIfKeyIsPresentInConfigFile() throws IOException { public void overrideDefaultValuesIfKeyIsPresentInConfigFile(final @TempDir File dataFolder)
throws IOException {
final URL configFile = this.getClass().getResource("/complete_config.toml"); final URL configFile = this.getClass().getResource("/complete_config.toml");
final Path genesisFile = createFakeGenesisFile(GENESIS_VALID_JSON); final Path genesisFile = createFakeGenesisFile(GENESIS_VALID_JSON);
final File dataFolder = temp.newFolder();
final String updatedConfig = final String updatedConfig =
Resources.toString(configFile, UTF_8) Resources.toString(configFile, UTF_8)
.replace("/opt/besu/genesis.json", escapeTomlString(genesisFile.toString())) .replace("/opt/besu/genesis.json", escapeTomlString(genesisFile.toString()))
@ -3745,7 +3744,7 @@ public class BesuCommandTest extends CommandTestAbstract {
}); });
} }
@Ignore @Disabled
public void pruningIsEnabledIfSyncModeIsFast() { public void pruningIsEnabledIfSyncModeIsFast() {
parseCommand("--sync-mode", "FAST"); parseCommand("--sync-mode", "FAST");
@ -3756,7 +3755,7 @@ public class BesuCommandTest extends CommandTestAbstract {
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty(); assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();
} }
@Ignore @Disabled
public void pruningIsDisabledIfSyncModeIsFull() { public void pruningIsDisabledIfSyncModeIsFull() {
parseCommand("--sync-mode", "FULL"); parseCommand("--sync-mode", "FULL");
@ -3778,7 +3777,7 @@ public class BesuCommandTest extends CommandTestAbstract {
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty(); assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();
} }
@Ignore @Disabled
public void pruningDisabledExplicitly() { public void pruningDisabledExplicitly() {
parseCommand("--pruning-enabled=false", "--sync-mode=FAST"); parseCommand("--pruning-enabled=false", "--sync-mode=FAST");
@ -4373,14 +4372,11 @@ public class BesuCommandTest extends CommandTestAbstract {
assertThat(commandOutput.toString(UTF_8)).isEmpty(); assertThat(commandOutput.toString(UTF_8)).isEmpty();
} }
@Rule public TemporaryFolder testFolder = new TemporaryFolder();
@Test @Test
public void errorIsRaisedIfStaticNodesAreNotAllowed() throws IOException { public void errorIsRaisedIfStaticNodesAreNotAllowed(final @TempDir Path testFolder)
final File staticNodesFile = testFolder.newFile("static-nodes.json"); throws IOException {
staticNodesFile.deleteOnExit(); final Path staticNodesFile = testFolder.resolve("static-nodes.json");
final File permissioningConfig = testFolder.newFile("permissioning"); final Path permissioningConfig = testFolder.resolve("permissioning.json");
permissioningConfig.deleteOnExit();
final EnodeURL staticNodeURI = final EnodeURL staticNodeURI =
EnodeURLImpl.builder() EnodeURLImpl.builder()
@ -4399,17 +4395,16 @@ public class BesuCommandTest extends CommandTestAbstract {
.listeningPort(30304) .listeningPort(30304)
.build(); .build();
Files.write(staticNodesFile, ("[\"" + staticNodeURI.toString() + "\"]").getBytes(UTF_8));
Files.write( Files.write(
staticNodesFile.toPath(), ("[\"" + staticNodeURI.toString() + "\"]").getBytes(UTF_8)); permissioningConfig,
Files.write(
permissioningConfig.toPath(),
("nodes-allowlist=[\"" + allowedNode.toString() + "\"]").getBytes(UTF_8)); ("nodes-allowlist=[\"" + allowedNode.toString() + "\"]").getBytes(UTF_8));
parseCommand( parseCommand(
"--data-path=" + testFolder.getRoot().getPath(), "--data-path=" + testFolder,
"--bootnodes", "--bootnodes",
"--permissions-nodes-config-file-enabled=true", "--permissions-nodes-config-file-enabled=true",
"--permissions-nodes-config-file=" + permissioningConfig.getPath()); "--permissions-nodes-config-file=" + permissioningConfig);
assertThat(commandErrorOutput.toString(UTF_8)) assertThat(commandErrorOutput.toString(UTF_8))
.contains(staticNodeURI.toString(), "not in nodes-allowlist"); .contains(staticNodeURI.toString(), "not in nodes-allowlist");
} }
@ -4985,12 +4980,10 @@ public class BesuCommandTest extends CommandTestAbstract {
"File containing password to unlock keystore is required when PKI Block Creation is enabled"); "File containing password to unlock keystore is required when PKI Block Creation is enabled");
} }
@Rule public TemporaryFolder pkiTempFolder = new TemporaryFolder();
@Test @Test
public void pkiBlockCreationFullConfig() throws Exception { public void pkiBlockCreationFullConfig(final @TempDir Path pkiTempFolder) throws Exception {
// Create temp file with password // Create temp file with password
final File pwdFile = pkiTempFolder.newFile("pwd"); final File pwdFile = pkiTempFolder.resolve("pwd").toFile();
FileUtils.writeStringToFile(pwdFile, "foo", UTF_8); FileUtils.writeStringToFile(pwdFile, "foo", UTF_8);
parseCommand( parseCommand(

@ -112,22 +112,20 @@ import io.vertx.core.json.JsonObject;
import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.bytes.Bytes32; import org.apache.tuweni.bytes.Bytes32;
import org.awaitility.Awaitility; import org.awaitility.Awaitility;
import org.junit.After; import org.junit.jupiter.api.AfterEach;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Rule; import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor; import org.mockito.ArgumentCaptor;
import org.mockito.Captor; import org.mockito.Captor;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner; import org.mockito.junit.jupiter.MockitoExtension;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import picocli.CommandLine; import picocli.CommandLine;
import picocli.CommandLine.Model.CommandSpec; import picocli.CommandLine.Model.CommandSpec;
import picocli.CommandLine.RunLast; import picocli.CommandLine.RunLast;
@RunWith(MockitoJUnitRunner.class) @ExtendWith(MockitoExtension.class)
public abstract class CommandTestAbstract { public abstract class CommandTestAbstract {
private static final Logger TEST_LOGGER = LoggerFactory.getLogger(CommandTestAbstract.class); private static final Logger TEST_LOGGER = LoggerFactory.getLogger(CommandTestAbstract.class);
protected static final JsonObject VALID_GENESIS_QBFT_POST_LONDON = protected static final JsonObject VALID_GENESIS_QBFT_POST_LONDON =
@ -156,17 +154,30 @@ public abstract class CommandTestAbstract {
protected static final RpcEndpointServiceImpl rpcEndpointServiceImpl = protected static final RpcEndpointServiceImpl rpcEndpointServiceImpl =
new RpcEndpointServiceImpl(); new RpcEndpointServiceImpl();
@Mock protected RunnerBuilder mockRunnerBuilder; @Mock(lenient = true)
protected RunnerBuilder mockRunnerBuilder;
@Mock protected Runner mockRunner; @Mock protected Runner mockRunner;
@Mock protected BesuController.Builder mockControllerBuilderFactory; @Mock(lenient = true)
protected BesuController.Builder mockControllerBuilderFactory;
@Mock(lenient = true)
protected BesuControllerBuilder mockControllerBuilder;
@Mock(lenient = true)
protected EthProtocolManager mockEthProtocolManager;
@Mock protected BesuControllerBuilder mockControllerBuilder;
@Mock protected EthProtocolManager mockEthProtocolManager;
@Mock protected ProtocolSchedule mockProtocolSchedule; @Mock protected ProtocolSchedule mockProtocolSchedule;
@Mock protected ProtocolContext mockProtocolContext;
@Mock(lenient = true)
protected ProtocolContext mockProtocolContext;
@Mock protected BlockBroadcaster mockBlockBroadcaster; @Mock protected BlockBroadcaster mockBlockBroadcaster;
@Mock protected BesuController mockController;
@Mock(lenient = true)
protected BesuController mockController;
@Mock protected RlpBlockExporter rlpBlockExporter; @Mock protected RlpBlockExporter rlpBlockExporter;
@Mock protected JsonBlockImporter jsonBlockImporter; @Mock protected JsonBlockImporter jsonBlockImporter;
@Mock protected RlpBlockImporter rlpBlockImporter; @Mock protected RlpBlockImporter rlpBlockImporter;
@ -188,7 +199,8 @@ public abstract class CommandTestAbstract {
@Mock @Mock
protected Logger mockLogger; protected Logger mockLogger;
@Mock protected BesuComponent mockBesuComponent; @Mock(lenient = true)
protected BesuComponent mockBesuComponent;
@Mock protected PkiBlockCreationConfigurationProvider mockPkiBlockCreationConfigProvider; @Mock protected PkiBlockCreationConfigurationProvider mockPkiBlockCreationConfigProvider;
@Mock protected PkiBlockCreationConfiguration mockPkiBlockCreationConfiguration; @Mock protected PkiBlockCreationConfiguration mockPkiBlockCreationConfiguration;
@ -218,9 +230,7 @@ public abstract class CommandTestAbstract {
@Captor protected ArgumentCaptor<EthstatsOptions> ethstatsOptionsArgumentCaptor; @Captor protected ArgumentCaptor<EthstatsOptions> ethstatsOptionsArgumentCaptor;
@Rule public final TemporaryFolder temp = new TemporaryFolder(); @BeforeEach
@Before
public void initMocks() throws Exception { public void initMocks() throws Exception {
// doReturn used because of generic BesuController // doReturn used because of generic BesuController
doReturn(mockControllerBuilder) doReturn(mockControllerBuilder)
@ -353,7 +363,7 @@ public abstract class CommandTestAbstract {
when(mockBesuComponent.getBesuCommandLogger()).thenReturn(mockLogger); when(mockBesuComponent.getBesuCommandLogger()).thenReturn(mockLogger);
} }
@Before @BeforeEach
public void setUpStreams() { public void setUpStreams() {
// reset the global opentelemetry singleton // reset the global opentelemetry singleton
GlobalOpenTelemetry.resetForTest(); GlobalOpenTelemetry.resetForTest();
@ -364,7 +374,7 @@ public abstract class CommandTestAbstract {
} }
// Display outputs for debug purpose // Display outputs for debug purpose
@After @AfterEach
public void displayOutput() throws IOException { public void displayOutput() throws IOException {
TEST_LOGGER.info("Standard output {}", commandOutput.toString(UTF_8)); TEST_LOGGER.info("Standard output {}", commandOutput.toString(UTF_8));
TEST_LOGGER.info("Standard error {}", commandErrorOutput.toString(UTF_8)); TEST_LOGGER.info("Standard error {}", commandErrorOutput.toString(UTF_8));

@ -19,12 +19,12 @@ import static org.assertj.core.api.Assertions.assertThat;
import org.hyperledger.besu.BesuInfo; import org.hyperledger.besu.BesuInfo;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.MockitoJUnitRunner; import org.mockito.junit.jupiter.MockitoExtension;
import picocli.CommandLine.Model.CommandSpec; import picocli.CommandLine.Model.CommandSpec;
@RunWith(MockitoJUnitRunner.class) @ExtendWith(MockitoExtension.class)
public class PasswordSubCommandTest extends CommandTestAbstract { public class PasswordSubCommandTest extends CommandTestAbstract {
@Test @Test

@ -35,14 +35,14 @@ import org.apache.tuweni.bytes.Bytes32;
import org.bouncycastle.asn1.sec.SECNamedCurves; import org.bouncycastle.asn1.sec.SECNamedCurves;
import org.bouncycastle.asn1.x9.X9ECParameters; import org.bouncycastle.asn1.x9.X9ECParameters;
import org.bouncycastle.crypto.params.ECDomainParameters; import org.bouncycastle.crypto.params.ECDomainParameters;
import org.junit.Before; import org.junit.jupiter.api.BeforeAll;
import org.junit.BeforeClass; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.MockitoJUnitRunner; import org.mockito.junit.jupiter.MockitoExtension;
import picocli.CommandLine.Model.CommandSpec; import picocli.CommandLine.Model.CommandSpec;
@RunWith(MockitoJUnitRunner.class) @ExtendWith(MockitoExtension.class)
public class PublicKeySubCommandTest extends CommandTestAbstract { public class PublicKeySubCommandTest extends CommandTestAbstract {
private static final String EXPECTED_PUBLIC_KEY_USAGE = private static final String EXPECTED_PUBLIC_KEY_USAGE =
@ -126,13 +126,13 @@ public class PublicKeySubCommandTest extends CommandTestAbstract {
private static final String ALGORITHM = SignatureAlgorithm.ALGORITHM; private static final String ALGORITHM = SignatureAlgorithm.ALGORITHM;
private static ECDomainParameters curve; private static ECDomainParameters curve;
@BeforeClass @BeforeAll
public static void setUp() { public static void setUp() {
final X9ECParameters params = SECNamedCurves.getByName(CURVE_NAME); final X9ECParameters params = SECNamedCurves.getByName(CURVE_NAME);
curve = new ECDomainParameters(params.getCurve(), params.getG(), params.getN(), params.getH()); curve = new ECDomainParameters(params.getCurve(), params.getG(), params.getN(), params.getH());
} }
@Before @BeforeEach
public void before() { public void before() {
SignatureAlgorithmFactory.resetInstance(); SignatureAlgorithmFactory.resetInstance();
} }

@ -25,12 +25,12 @@ import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import com.google.common.io.Resources; import com.google.common.io.Resources;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.MockitoJUnitRunner; import org.mockito.junit.jupiter.MockitoExtension;
import picocli.CommandLine.Model.CommandSpec; import picocli.CommandLine.Model.CommandSpec;
@RunWith(MockitoJUnitRunner.class) @ExtendWith(MockitoExtension.class)
public class ValidateConfigSubCommandTest extends CommandTestAbstract { public class ValidateConfigSubCommandTest extends CommandTestAbstract {
private static final String EXPECTED_PUBLIC_KEY_USAGE = private static final String EXPECTED_PUBLIC_KEY_USAGE =

@ -52,13 +52,13 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import io.vertx.core.json.JsonObject; import io.vertx.core.json.JsonObject;
import org.apache.tuweni.bytes.Bytes32; import org.apache.tuweni.bytes.Bytes32;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.MockitoJUnitRunner; import org.mockito.junit.jupiter.MockitoExtension;
import picocli.CommandLine.Model.CommandSpec; import picocli.CommandLine.Model.CommandSpec;
@RunWith(MockitoJUnitRunner.class) @ExtendWith(MockitoExtension.class)
public class OperatorSubCommandTest extends CommandTestAbstract { public class OperatorSubCommandTest extends CommandTestAbstract {
private static final String EXPECTED_OPERATOR_USAGE = private static final String EXPECTED_OPERATOR_USAGE =
@ -80,7 +80,7 @@ public class OperatorSubCommandTest extends CommandTestAbstract {
private Path tmpOutputDirectoryPath; private Path tmpOutputDirectoryPath;
@Before @BeforeEach
public void init() throws IOException { public void init() throws IOException {
SignatureAlgorithmFactory.resetInstance(); SignatureAlgorithmFactory.resetInstance();
tmpOutputDirectoryPath = createTempDirectory(format("output-%d", currentTimeMillis())); tmpOutputDirectoryPath = createTempDirectory(format("output-%d", currentTimeMillis()));

@ -26,7 +26,7 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.function.Consumer; import java.util.function.Consumer;
import org.junit.Test; import org.junit.jupiter.api.Test;
public abstract class AbstractCLIOptionsTest<D, T extends CLIOptions<D>> public abstract class AbstractCLIOptionsTest<D, T extends CLIOptions<D>>
extends CommandTestAbstract { extends CommandTestAbstract {

@ -21,11 +21,11 @@ import static org.mockito.Mockito.verifyNoInteractions;
import org.hyperledger.besu.cli.options.unstable.EthProtocolOptions; import org.hyperledger.besu.cli.options.unstable.EthProtocolOptions;
import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.MockitoJUnitRunner; import org.mockito.junit.jupiter.MockitoExtension;
@RunWith(MockitoJUnitRunner.class) @ExtendWith(MockitoExtension.class)
public class EthProtocolOptionsTest public class EthProtocolOptionsTest
extends AbstractCLIOptionsTest<EthProtocolConfiguration, EthProtocolOptions> { extends AbstractCLIOptionsTest<EthProtocolConfiguration, EthProtocolOptions> {

@ -17,10 +17,10 @@ package org.hyperledger.besu.cli.options;
import org.hyperledger.besu.cli.options.unstable.MetricsCLIOptions; import org.hyperledger.besu.cli.options.unstable.MetricsCLIOptions;
import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration; import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration;
import org.junit.runner.RunWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.MockitoJUnitRunner; import org.mockito.junit.jupiter.MockitoExtension;
@RunWith(MockitoJUnitRunner.class) @ExtendWith(MockitoExtension.class)
public class MetricsCLIOptionsTest public class MetricsCLIOptionsTest
extends AbstractCLIOptionsTest<MetricsConfiguration.Builder, MetricsCLIOptions> { extends AbstractCLIOptionsTest<MetricsConfiguration.Builder, MetricsCLIOptions> {

@ -35,12 +35,12 @@ import java.nio.file.Path;
import java.util.Optional; import java.util.Optional;
import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.bytes.Bytes;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor; import org.mockito.ArgumentCaptor;
import org.mockito.junit.MockitoJUnitRunner; import org.mockito.junit.jupiter.MockitoExtension;
@RunWith(MockitoJUnitRunner.class) @ExtendWith(MockitoExtension.class)
public class MiningOptionsTest extends AbstractCLIOptionsTest<MiningParameters, MiningOptions> { public class MiningOptionsTest extends AbstractCLIOptionsTest<MiningParameters, MiningOptions> {
@Test @Test

@ -23,11 +23,11 @@ import org.hyperledger.besu.ethereum.p2p.config.NetworkingConfiguration;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.MockitoJUnitRunner; import org.mockito.junit.jupiter.MockitoExtension;
@RunWith(MockitoJUnitRunner.class) @ExtendWith(MockitoExtension.class)
public class NetworkingOptionsTest public class NetworkingOptionsTest
extends AbstractCLIOptionsTest<NetworkingConfiguration, NetworkingOptions> { extends AbstractCLIOptionsTest<NetworkingConfiguration, NetworkingOptions> {

@ -23,10 +23,10 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import com.google.common.collect.Range; import com.google.common.collect.Range;
import org.junit.runner.RunWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.MockitoJUnitRunner; import org.mockito.junit.jupiter.MockitoExtension;
@RunWith(MockitoJUnitRunner.class) @ExtendWith(MockitoExtension.class)
public class SynchronizerOptionsTest public class SynchronizerOptionsTest
extends AbstractCLIOptionsTest<SynchronizerConfiguration.Builder, SynchronizerOptions> { extends AbstractCLIOptionsTest<SynchronizerConfiguration.Builder, SynchronizerOptions> {

@ -28,11 +28,11 @@ import org.hyperledger.besu.util.number.Percentage;
import java.time.Duration; import java.time.Duration;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.MockitoJUnitRunner; import org.mockito.junit.jupiter.MockitoExtension;
@RunWith(MockitoJUnitRunner.class) @ExtendWith(MockitoExtension.class)
public class TransactionPoolOptionsTest public class TransactionPoolOptionsTest
extends AbstractCLIOptionsTest<TransactionPoolConfiguration, TransactionPoolOptions> { extends AbstractCLIOptionsTest<TransactionPoolConfiguration, TransactionPoolOptions> {

@ -23,7 +23,7 @@ import org.hyperledger.besu.ethereum.worldstate.DataStorageConfiguration;
import org.hyperledger.besu.ethereum.worldstate.DataStorageFormat; import org.hyperledger.besu.ethereum.worldstate.DataStorageFormat;
import org.hyperledger.besu.ethereum.worldstate.ImmutableDataStorageConfiguration; import org.hyperledger.besu.ethereum.worldstate.ImmutableDataStorageConfiguration;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class DataStorageOptionsTest public class DataStorageOptionsTest
extends AbstractCLIOptionsTest<DataStorageConfiguration, DataStorageOptions> { extends AbstractCLIOptionsTest<DataStorageConfiguration, DataStorageOptions> {

@ -24,11 +24,12 @@ import org.hyperledger.besu.cli.CommandTestAbstract;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path;
import org.junit.After; import org.junit.jupiter.api.AfterEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import picocli.CommandLine.Model.CommandSpec; import picocli.CommandLine.Model.CommandSpec;
public class RLPSubCommandTest extends CommandTestAbstract { public class RLPSubCommandTest extends CommandTestAbstract {
@ -158,10 +159,10 @@ public class RLPSubCommandTest extends CommandTestAbstract {
} }
@Test @Test
public void encodeWithInputFilePathMustReadFromThisFile() throws Exception { public void encodeWithInputFilePathMustReadFromThisFile(final @TempDir Path dir)
throws Exception {
final File tempJsonFile = temp.newFile("test.json"); final Path tempJsonFile = Files.createTempFile(dir, "input", "json");
try (final BufferedWriter fileWriter = Files.newBufferedWriter(tempJsonFile.toPath(), UTF_8)) { try (final BufferedWriter fileWriter = Files.newBufferedWriter(tempJsonFile, UTF_8)) {
fileWriter.write( fileWriter.write(
"[\"be068f726a13c8d46c44be6ce9d275600e1735a4\", \"5ff6f4b66a46a2b2310a6f3a93aaddc0d9a1c193\"]"); "[\"be068f726a13c8d46c44be6ce9d275600e1735a4\", \"5ff6f4b66a46a2b2310a6f3a93aaddc0d9a1c193\"]");
@ -169,7 +170,10 @@ public class RLPSubCommandTest extends CommandTestAbstract {
fileWriter.flush(); fileWriter.flush();
parseCommand( parseCommand(
RLP_SUBCOMMAND_NAME, RLP_ENCODE_SUBCOMMAND_NAME, "--from", tempJsonFile.getPath()); RLP_SUBCOMMAND_NAME,
RLP_ENCODE_SUBCOMMAND_NAME,
"--from",
tempJsonFile.toFile().getAbsolutePath());
final String expectedRlpString = final String expectedRlpString =
"0xf853a00000000000000000000000000000000000000000000000000000000000000000ea94be068f726a13c8d" "0xf853a00000000000000000000000000000000000000000000000000000000000000000ea94be068f726a13c8d"
@ -180,9 +184,9 @@ public class RLPSubCommandTest extends CommandTestAbstract {
} }
@Test @Test
public void canEncodeToQbftExtraData() throws IOException { public void canEncodeToQbftExtraData(final @TempDir Path dir) throws Exception {
final File tempJsonFile = temp.newFile("test.json"); final Path tempJsonFile = Files.createTempFile(dir, "qbft", "json");
try (final BufferedWriter fileWriter = Files.newBufferedWriter(tempJsonFile.toPath(), UTF_8)) { try (final BufferedWriter fileWriter = Files.newBufferedWriter(tempJsonFile, UTF_8)) {
fileWriter.write( fileWriter.write(
"[\"be068f726a13c8d46c44be6ce9d275600e1735a4\", \"5ff6f4b66a46a2b2310a6f3a93aaddc0d9a1c193\"]"); "[\"be068f726a13c8d46c44be6ce9d275600e1735a4\", \"5ff6f4b66a46a2b2310a6f3a93aaddc0d9a1c193\"]");
@ -193,7 +197,7 @@ public class RLPSubCommandTest extends CommandTestAbstract {
RLP_SUBCOMMAND_NAME, RLP_SUBCOMMAND_NAME,
RLP_ENCODE_SUBCOMMAND_NAME, RLP_ENCODE_SUBCOMMAND_NAME,
"--from", "--from",
tempJsonFile.getPath(), tempJsonFile.toFile().getAbsolutePath(),
"--type", "--type",
RLP_QBFT_TYPE); RLP_QBFT_TYPE);
@ -206,17 +210,19 @@ public class RLPSubCommandTest extends CommandTestAbstract {
} }
@Test @Test
public void encodeWithInvalidInputMustRaiseAnError() throws Exception { public void encodeWithInvalidInputMustRaiseAnError(final @TempDir Path dir) throws Exception {
final Path tempJsonFile = Files.createTempFile(dir, "invalid", "json");
final File tempJsonFile = temp.newFile("invalid_test.json"); try (final BufferedWriter fileWriter = Files.newBufferedWriter(tempJsonFile, UTF_8)) {
try (final BufferedWriter fileWriter = Files.newBufferedWriter(tempJsonFile.toPath(), UTF_8)) {
fileWriter.write("{\"property\":0}"); fileWriter.write("{\"property\":0}");
fileWriter.flush(); fileWriter.flush();
parseCommand( parseCommand(
RLP_SUBCOMMAND_NAME, RLP_ENCODE_SUBCOMMAND_NAME, "--from", tempJsonFile.getPath()); RLP_SUBCOMMAND_NAME,
RLP_ENCODE_SUBCOMMAND_NAME,
"--from",
tempJsonFile.toFile().getAbsolutePath());
assertThat(commandOutput.toString(UTF_8)).isEmpty(); assertThat(commandOutput.toString(UTF_8)).isEmpty();
assertThat(commandErrorOutput.toString(UTF_8)) assertThat(commandErrorOutput.toString(UTF_8))
@ -226,11 +232,13 @@ public class RLPSubCommandTest extends CommandTestAbstract {
} }
@Test @Test
public void encodeWithEmptyInputMustRaiseAnError() throws Exception { public void encodeWithEmptyInputMustRaiseAnError(final @TempDir Path dir) throws Exception {
final Path emptyFile = Files.createTempFile(dir, "empty", "json");
final File tempJsonFile = temp.newFile("empty.json"); parseCommand(
RLP_SUBCOMMAND_NAME,
parseCommand(RLP_SUBCOMMAND_NAME, RLP_ENCODE_SUBCOMMAND_NAME, "--from", tempJsonFile.getPath()); RLP_ENCODE_SUBCOMMAND_NAME,
"--from",
emptyFile.toFile().getAbsolutePath());
assertThat(commandOutput.toString(UTF_8)).isEmpty(); assertThat(commandOutput.toString(UTF_8)).isEmpty();
assertThat(commandErrorOutput.toString(UTF_8)) assertThat(commandErrorOutput.toString(UTF_8))
@ -251,7 +259,7 @@ public class RLPSubCommandTest extends CommandTestAbstract {
.startsWith("An error occurred while trying to read the JSON data."); .startsWith("An error occurred while trying to read the JSON data.");
} }
@After @AfterEach
public void restoreStdin() { public void restoreStdin() {
System.setIn(System.in); System.setIn(System.in);
} }

@ -36,17 +36,16 @@ import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.Optional; import java.util.Optional;
import org.junit.Rule; import org.junit.jupiter.api.Test;
import org.junit.Test; import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.rules.TemporaryFolder; import org.junit.jupiter.api.io.TempDir;
import org.junit.runner.RunWith; import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.junit.MockitoJUnitRunner;
import picocli.CommandLine.Model.CommandSpec; import picocli.CommandLine.Model.CommandSpec;
@RunWith(MockitoJUnitRunner.class) @ExtendWith(MockitoExtension.class)
public class BlocksSubCommandTest extends CommandTestAbstract { public class BlocksSubCommandTest extends CommandTestAbstract {
@Rule public final TemporaryFolder folder = new TemporaryFolder(); @TempDir public Path folder;
private static final String EXPECTED_BLOCK_USAGE = private static final String EXPECTED_BLOCK_USAGE =
"Usage: besu blocks [-hV] [COMMAND]" "Usage: besu blocks [-hV] [COMMAND]"
@ -187,10 +186,13 @@ public class BlocksSubCommandTest extends CommandTestAbstract {
} }
@Test @Test
public void callingBlockImportSubCommandWithPathMustImportBlocksWithThisPath() throws Exception { public void callingBlockImportSubCommandWithPathMustImportBlocksWithThisPath(
final File fileToImport = temp.newFile("blocks.file"); final @TempDir File fileToImport) throws Exception {
parseCommand( parseCommand(
BLOCK_SUBCOMMAND_NAME, BLOCK_IMPORT_SUBCOMMAND_NAME, "--from", fileToImport.getPath()); BLOCK_SUBCOMMAND_NAME,
BLOCK_IMPORT_SUBCOMMAND_NAME,
"--from",
fileToImport.getAbsolutePath().toString());
verify(rlpBlockImporter) verify(rlpBlockImporter)
.importBlockchain(pathArgumentCaptor.capture(), any(), anyBoolean(), anyLong(), anyLong()); .importBlockchain(pathArgumentCaptor.capture(), any(), anyBoolean(), anyLong(), anyLong());
@ -202,8 +204,7 @@ public class BlocksSubCommandTest extends CommandTestAbstract {
} }
@Test @Test
public void blocksImport_rlpFormat() throws Exception { public void blocksImport_rlpFormat(final @TempDir File fileToImport) throws Exception {
final File fileToImport = temp.newFile("blocks.file");
parseCommand( parseCommand(
BLOCK_SUBCOMMAND_NAME, BLOCK_SUBCOMMAND_NAME,
BLOCK_IMPORT_SUBCOMMAND_NAME, BLOCK_IMPORT_SUBCOMMAND_NAME,
@ -222,10 +223,11 @@ public class BlocksSubCommandTest extends CommandTestAbstract {
} }
@Test @Test
public void blocksImport_rlpFormatMultiple() throws Exception { public void blocksImport_rlpFormatMultiple(
final File fileToImport = temp.newFile("blocks.file"); final @TempDir File fileToImport,
final File file2ToImport = temp.newFile("blocks2.file"); final @TempDir File file2ToImport,
final File file3ToImport = temp.newFile("blocks3.file"); final @TempDir File file3ToImport)
throws Exception {
parseCommand( parseCommand(
BLOCK_SUBCOMMAND_NAME, BLOCK_SUBCOMMAND_NAME,
BLOCK_IMPORT_SUBCOMMAND_NAME, BLOCK_IMPORT_SUBCOMMAND_NAME,
@ -247,10 +249,10 @@ public class BlocksSubCommandTest extends CommandTestAbstract {
} }
@Test @Test
public void blocksImport_jsonFormat() throws Exception { public void blocksImport_jsonFormat(final @TempDir Path dir) throws Exception {
final String fileContent = "test"; final String fileContent = "test";
final File fileToImport = temp.newFile("blocks.file"); final Path fileToImport = Files.createTempFile(dir, "tmp", "json");
final Writer fileWriter = Files.newBufferedWriter(fileToImport.toPath(), UTF_8); final Writer fileWriter = Files.newBufferedWriter(fileToImport, UTF_8);
fileWriter.write(fileContent); fileWriter.write(fileContent);
fileWriter.close(); fileWriter.close();
@ -260,7 +262,7 @@ public class BlocksSubCommandTest extends CommandTestAbstract {
"--format", "--format",
"JSON", "JSON",
"--from", "--from",
fileToImport.getPath()); fileToImport.toFile().getAbsolutePath());
assertThat(commandOutput.toString(UTF_8)).isEmpty(); assertThat(commandOutput.toString(UTF_8)).isEmpty();
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty(); assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();
@ -274,9 +276,7 @@ public class BlocksSubCommandTest extends CommandTestAbstract {
public void blocksExport_missingFileParam() throws IOException { public void blocksExport_missingFileParam() throws IOException {
createDbDirectory(true); createDbDirectory(true);
parseCommand( parseCommand(
"--data-path=" + folder.getRoot().getAbsolutePath(), "--data-path=" + folder.getRoot(), BLOCK_SUBCOMMAND_NAME, BLOCK_EXPORT_SUBCOMMAND_NAME);
BLOCK_SUBCOMMAND_NAME,
BLOCK_EXPORT_SUBCOMMAND_NAME);
final String expectedErrorOutputStart = "Missing required option: '--to=<FILE>'"; final String expectedErrorOutputStart = "Missing required option: '--to=<FILE>'";
assertThat(commandOutput.toString(UTF_8)).isEmpty(); assertThat(commandOutput.toString(UTF_8)).isEmpty();
assertThat(commandErrorOutput.toString(UTF_8)).startsWith(expectedErrorOutputStart); assertThat(commandErrorOutput.toString(UTF_8)).startsWith(expectedErrorOutputStart);
@ -285,17 +285,17 @@ public class BlocksSubCommandTest extends CommandTestAbstract {
} }
@Test @Test
public void blocksExport_noDbDirectory() throws IOException { public void blocksExport_noDbDirectory(final @TempDir Path noDbDir) throws IOException {
final File outputFile = folder.newFile("blocks.bin"); final File outputFile = noDbDir.resolve("blocks.bin").toFile();
parseCommand( parseCommand(
"--data-path=" + folder.getRoot().getAbsolutePath(), "--data-path=" + noDbDir,
BLOCK_SUBCOMMAND_NAME, BLOCK_SUBCOMMAND_NAME,
BLOCK_EXPORT_SUBCOMMAND_NAME, BLOCK_EXPORT_SUBCOMMAND_NAME,
"--to", "--to",
outputFile.getPath()); outputFile.getAbsolutePath());
final String expectedErrorOutputStart = final String expectedErrorOutputStart =
"Chain is empty. Unable to export blocks from specified data directory: " "Chain is empty. Unable to export blocks from specified data directory: "
+ folder.getRoot().getAbsolutePath() + noDbDir
+ File.separator + File.separator
+ BesuController.DATABASE_PATH; + BesuController.DATABASE_PATH;
assertThat(commandOutput.toString(UTF_8)).isEmpty(); assertThat(commandOutput.toString(UTF_8)).isEmpty();
@ -307,16 +307,16 @@ public class BlocksSubCommandTest extends CommandTestAbstract {
@Test @Test
public void blocksExport_emptyDbDirectory() throws IOException { public void blocksExport_emptyDbDirectory() throws IOException {
createDbDirectory(false); createDbDirectory(false);
final File outputFile = folder.newFile("blocks.bin"); final File outputFile = Files.createFile(folder.resolve("empty")).toFile();
parseCommand( parseCommand(
"--data-path=" + folder.getRoot().getAbsolutePath(), "--data-path=" + folder,
BLOCK_SUBCOMMAND_NAME, BLOCK_SUBCOMMAND_NAME,
BLOCK_EXPORT_SUBCOMMAND_NAME, BLOCK_EXPORT_SUBCOMMAND_NAME,
"--to", "--to",
outputFile.getPath()); outputFile.getPath());
final String expectedErrorOutputStart = final String expectedErrorOutputStart =
"Chain is empty. Unable to export blocks from specified data directory: " "Chain is empty. Unable to export blocks from specified data directory: "
+ folder.getRoot().getAbsolutePath() + folder
+ File.separator + File.separator
+ BesuController.DATABASE_PATH; + BesuController.DATABASE_PATH;
assertThat(commandOutput.toString(UTF_8)).isEmpty(); assertThat(commandOutput.toString(UTF_8)).isEmpty();
@ -328,13 +328,13 @@ public class BlocksSubCommandTest extends CommandTestAbstract {
@Test @Test
public void blocksExport_noStartOrEnd() throws IOException { public void blocksExport_noStartOrEnd() throws IOException {
createDbDirectory(true); createDbDirectory(true);
final File outputFile = folder.newFile("blocks.bin"); final File outputFile = Files.createTempFile(folder, "blocks", "bin").toFile();
parseCommand( parseCommand(
"--data-path=" + folder.getRoot().getAbsolutePath(), "--data-path=" + folder,
BLOCK_SUBCOMMAND_NAME, BLOCK_SUBCOMMAND_NAME,
BLOCK_EXPORT_SUBCOMMAND_NAME, BLOCK_EXPORT_SUBCOMMAND_NAME,
"--to", "--to",
outputFile.getPath()); outputFile.getAbsolutePath());
assertThat(commandOutput.toString(UTF_8)).isEmpty(); assertThat(commandOutput.toString(UTF_8)).isEmpty();
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty(); assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();
@ -344,9 +344,9 @@ public class BlocksSubCommandTest extends CommandTestAbstract {
@Test @Test
public void blocksExport_withStartAndNoEnd() throws IOException { public void blocksExport_withStartAndNoEnd() throws IOException {
createDbDirectory(true); createDbDirectory(true);
final File outputFile = folder.newFile("blocks.bin"); final File outputFile = Files.createFile(folder.resolve("blocks.bin")).toFile();
parseCommand( parseCommand(
"--data-path=" + folder.getRoot().getAbsolutePath(), "--data-path=" + folder,
BLOCK_SUBCOMMAND_NAME, BLOCK_SUBCOMMAND_NAME,
BLOCK_EXPORT_SUBCOMMAND_NAME, BLOCK_EXPORT_SUBCOMMAND_NAME,
"--to", "--to",
@ -361,9 +361,9 @@ public class BlocksSubCommandTest extends CommandTestAbstract {
@Test @Test
public void blocksExport_withEndAndNoStart() throws IOException { public void blocksExport_withEndAndNoStart() throws IOException {
createDbDirectory(true); createDbDirectory(true);
final File outputFile = folder.newFile("blocks.bin"); final File outputFile = Files.createTempFile(folder, "blocks", "bin").toFile();
parseCommand( parseCommand(
"--data-path=" + folder.getRoot().getAbsolutePath(), "--data-path=" + folder,
BLOCK_SUBCOMMAND_NAME, BLOCK_SUBCOMMAND_NAME,
BLOCK_EXPORT_SUBCOMMAND_NAME, BLOCK_EXPORT_SUBCOMMAND_NAME,
"--to", "--to",
@ -378,13 +378,13 @@ public class BlocksSubCommandTest extends CommandTestAbstract {
@Test @Test
public void blocksExport_withStartAndEnd() throws IOException { public void blocksExport_withStartAndEnd() throws IOException {
createDbDirectory(true); createDbDirectory(true);
final File outputFile = folder.newFile("blocks.bin"); final File outputFile = Files.createTempFile(folder, "blocks", "bin").toFile();
parseCommand( parseCommand(
"--data-path=" + folder.getRoot().getAbsolutePath(), "--data-path=" + folder,
BLOCK_SUBCOMMAND_NAME, BLOCK_SUBCOMMAND_NAME,
BLOCK_EXPORT_SUBCOMMAND_NAME, BLOCK_EXPORT_SUBCOMMAND_NAME,
"--to", "--to",
outputFile.getPath(), outputFile.getAbsolutePath(),
"--start-block=1", "--start-block=1",
"--end-block=10"); "--end-block=10");
assertThat(commandOutput.toString(UTF_8)).isEmpty(); assertThat(commandOutput.toString(UTF_8)).isEmpty();
@ -396,13 +396,13 @@ public class BlocksSubCommandTest extends CommandTestAbstract {
@Test @Test
public void blocksExport_withOutOfOrderStartAndEnd() throws IOException { public void blocksExport_withOutOfOrderStartAndEnd() throws IOException {
createDbDirectory(true); createDbDirectory(true);
final File outputFile = folder.newFile("blocks.bin"); final File outputFile = Files.createTempFile(folder, "blocks", "bin").toFile();
parseCommand( parseCommand(
"--data-path=" + folder.getRoot().getAbsolutePath(), "--data-path=" + folder,
BLOCK_SUBCOMMAND_NAME, BLOCK_SUBCOMMAND_NAME,
BLOCK_EXPORT_SUBCOMMAND_NAME, BLOCK_EXPORT_SUBCOMMAND_NAME,
"--to", "--to",
outputFile.getPath(), outputFile.getAbsolutePath(),
"--start-block=10", "--start-block=10",
"--end-block=1"); "--end-block=1");
assertThat(commandErrorOutput.toString(UTF_8)) assertThat(commandErrorOutput.toString(UTF_8))
@ -415,9 +415,9 @@ public class BlocksSubCommandTest extends CommandTestAbstract {
@Test @Test
public void blocksExport_withEmptyRange() throws IOException { public void blocksExport_withEmptyRange() throws IOException {
createDbDirectory(true); createDbDirectory(true);
final File outputFile = folder.newFile("blocks.bin"); final File outputFile = Files.createTempFile(folder, "blocks", "bin").toFile();
parseCommand( parseCommand(
"--data-path=" + folder.getRoot().getAbsolutePath(), "--data-path=" + folder,
BLOCK_SUBCOMMAND_NAME, BLOCK_SUBCOMMAND_NAME,
BLOCK_EXPORT_SUBCOMMAND_NAME, BLOCK_EXPORT_SUBCOMMAND_NAME,
"--to", "--to",
@ -434,9 +434,9 @@ public class BlocksSubCommandTest extends CommandTestAbstract {
@Test @Test
public void blocksExport_withInvalidStart() throws IOException { public void blocksExport_withInvalidStart() throws IOException {
createDbDirectory(true); createDbDirectory(true);
final File outputFile = folder.newFile("blocks.bin"); final File outputFile = Files.createTempFile(folder, "blocks", "bin").toFile();
parseCommand( parseCommand(
"--data-path=" + folder.getRoot().getAbsolutePath(), "--data-path=" + folder.getRoot(),
BLOCK_SUBCOMMAND_NAME, BLOCK_SUBCOMMAND_NAME,
BLOCK_EXPORT_SUBCOMMAND_NAME, BLOCK_EXPORT_SUBCOMMAND_NAME,
"--to", "--to",
@ -452,9 +452,9 @@ public class BlocksSubCommandTest extends CommandTestAbstract {
@Test @Test
public void blocksExport_withInvalidEnd() throws IOException { public void blocksExport_withInvalidEnd() throws IOException {
createDbDirectory(true); createDbDirectory(true);
final File outputFile = folder.newFile("blocks.bin"); final File outputFile = Files.createTempFile(folder, "blocks", "bin").toFile();
parseCommand( parseCommand(
"--data-path=" + folder.getRoot().getAbsolutePath(), "--data-path=" + folder.getRoot(),
BLOCK_SUBCOMMAND_NAME, BLOCK_SUBCOMMAND_NAME,
BLOCK_EXPORT_SUBCOMMAND_NAME, BLOCK_EXPORT_SUBCOMMAND_NAME,
"--to", "--to",
@ -482,17 +482,18 @@ public class BlocksSubCommandTest extends CommandTestAbstract {
} }
private void createDbDirectory(final boolean createDataFiles) throws IOException { private void createDbDirectory(final boolean createDataFiles) throws IOException {
final File dbDir = folder.newFolder(BesuController.DATABASE_PATH); final Path dbDir = Files.createDirectory(folder.resolve(BesuController.DATABASE_PATH));
if (createDataFiles) { if (createDataFiles) {
final Path dataFilePath = Paths.get(dbDir.getAbsolutePath(), "0000001.sst"); final Path dataFilePath = Paths.get(dbDir.toFile().getAbsolutePath(), "0000001.sst");
final boolean success = new File(dataFilePath.toString()).createNewFile(); final boolean success = new File(dataFilePath.toFile().getAbsolutePath()).createNewFile();
assertThat(success).isTrue(); assertThat(success).isTrue();
} }
} }
@Test @Test
public void blocksImportWithNoSyncModeDoesNotRaiseNPE() throws IOException { public void blocksImportWithNoSyncModeDoesNotRaiseNPE(final @TempDir File fileToImport)
final File fileToImport = temp.newFile("blocks.file"); throws IOException {
parseCommand( parseCommand(
BLOCK_SUBCOMMAND_NAME, BLOCK_IMPORT_SUBCOMMAND_NAME, "--from", fileToImport.getPath()); BLOCK_SUBCOMMAND_NAME, BLOCK_IMPORT_SUBCOMMAND_NAME, "--from", fileToImport.getPath());

@ -36,11 +36,11 @@ import org.hyperledger.besu.services.kvstore.SegmentedKeyValueStorageAdapter;
import java.util.List; import java.util.List;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.MockitoJUnitRunner; import org.mockito.junit.jupiter.MockitoExtension;
@RunWith(MockitoJUnitRunner.Silent.class) @ExtendWith(MockitoExtension.class)
public class StorageSubCommandTest extends CommandTestAbstract { public class StorageSubCommandTest extends CommandTestAbstract {
@Test @Test

Loading…
Cancel
Save