Skip to content

Commit

Permalink
Version upgrades for 22Q1 (#3217)
Browse files Browse the repository at this point in the history
* lots of errorprone fixes
* some license updates
* some mockito updates
* upgrade the rocksdb version
* Prometheus left at 0.9.0 as 0.10.0+ introduces OpenMetrics 
  related changes that break unit tests.

Signed-off-by: Danno Ferrin <danno.ferrin@gmail.com>
  • Loading branch information
shemnon authored Dec 24, 2021
1 parent ebf9737 commit ed9d64d
Show file tree
Hide file tree
Showing 55 changed files with 899 additions and 856 deletions.
2 changes: 1 addition & 1 deletion acceptance-tests/tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/

plugins {
id 'org.web3j' version '4.8.8'
id 'org.web3j' version '4.8.9'
id 'org.web3j.solidity' version '0.3.2'
}

Expand Down
1,103 changes: 555 additions & 548 deletions besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
package org.hyperledger.besu.cli;

import static java.nio.charset.StandardCharsets.UTF_8;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyFloat;
Expand Down Expand Up @@ -320,8 +321,8 @@ public void initMocks() throws Exception {
// Display outputs for debug purpose
@After
public void displayOutput() throws IOException {
TEST_LOGGER.info("Standard output {}", commandOutput.toString());
TEST_LOGGER.info("Standard error {}", commandErrorOutput.toString());
TEST_LOGGER.info("Standard output {}", commandOutput.toString(UTF_8));
TEST_LOGGER.info("Standard error {}", commandErrorOutput.toString(UTF_8));

outPrintStream.close();
commandOutput.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
package org.hyperledger.besu.cli;

import static java.nio.charset.StandardCharsets.UTF_8;
import static org.assertj.core.api.Assertions.assertThat;

import org.junit.Test;
Expand All @@ -26,34 +27,35 @@ public void passwordSubCommandExistsWithHashSubCommand() {
final CommandSpec spec = parseCommand().getSpec();
assertThat(spec.subcommands()).containsKeys("password");
assertThat(spec.subcommands().get("password").getSubcommands()).containsKeys("hash");
assertThat(commandOutput.toString()).isEmpty();
assertThat(commandErrorOutput.toString()).isEmpty();
assertThat(commandOutput.toString(UTF_8)).isEmpty();
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();
}

@Test
public void passwordSubCommandExists() {
parseCommand("password");

assertThat(commandOutput.toString()).contains("This command provides password related actions");
assertThat(commandErrorOutput.toString()).isEmpty();
assertThat(commandOutput.toString(UTF_8))
.contains("This command provides password related actions");
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();
}

@Test
public void passwordHashSubCommandExists() {
parseCommand("password", "hash");

assertThat(commandOutput.toString()).isEmpty();
assertThat(commandErrorOutput.toString())
assertThat(commandOutput.toString(UTF_8)).isEmpty();
assertThat(commandErrorOutput.toString(UTF_8))
.contains("Missing required option: '--password=<password>'");
}

@Test
public void passwordHashSubCommandHelpDisplaysHelp() {
parseCommand("password", "hash", "--help");

assertThat(commandOutput.toString())
assertThat(commandOutput.toString(UTF_8))
.contains("Usage: besu password hash [-hV] --password=<password>");
assertThat(commandOutput.toString())
assertThat(commandOutput.toString(UTF_8))
.contains("This command generates the hash of a given password");
}

Expand All @@ -62,7 +64,7 @@ public void passwordHashSubCommandHashesPassword() {
parseCommand("password", "hash", "--password", "foo");

// we can't predict the final value so we are only checking if it starts with the hash marker
assertThat(commandOutput.toString()).startsWith("$2");
assertThat(commandErrorOutput.toString()).isEmpty();
assertThat(commandOutput.toString(UTF_8)).startsWith("$2");
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
package org.hyperledger.besu.cli;

import static java.nio.charset.StandardCharsets.UTF_8;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.contentOf;

Expand Down Expand Up @@ -121,30 +122,30 @@ public void publicKeySubCommandExistsAndHasSubCommands() {
assertThat(spec.subcommands().get(PUBLIC_KEY_SUBCOMMAND_NAME).getSubcommands())
.containsKeys(PUBLIC_KEY_EXPORT_SUBCOMMAND_NAME)
.containsKeys(PUBLIC_KEY_EXPORT_ADDRESS_SUBCOMMAND_NAME);
assertThat(commandOutput.toString()).isEmpty();
assertThat(commandErrorOutput.toString()).isEmpty();
assertThat(commandOutput.toString(UTF_8)).isEmpty();
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();
}

@Test
public void callingPublicKeySubCommandWithoutSubSubcommandMustDisplayUsage() {
parseCommand(PUBLIC_KEY_SUBCOMMAND_NAME);
assertThat(commandOutput.toString()).startsWith(EXPECTED_PUBLIC_KEY_USAGE);
assertThat(commandErrorOutput.toString()).isEmpty();
assertThat(commandOutput.toString(UTF_8)).startsWith(EXPECTED_PUBLIC_KEY_USAGE);
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();
}

@Test
public void callingPublicKeySubCommandHelpMustDisplayUsage() {
parseCommand(PUBLIC_KEY_SUBCOMMAND_NAME, "--help");
assertThat(commandOutput.toString()).startsWith(EXPECTED_PUBLIC_KEY_USAGE);
assertThat(commandErrorOutput.toString()).isEmpty();
assertThat(commandOutput.toString(UTF_8)).startsWith(EXPECTED_PUBLIC_KEY_USAGE);
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();
}

// Export public key sub-sub-command
@Test
public void callingPublicKeyExportSubCommandHelpMustDisplayUsage() {
parseCommand(PUBLIC_KEY_SUBCOMMAND_NAME, PUBLIC_KEY_EXPORT_SUBCOMMAND_NAME, "--help");
assertThat(commandOutput.toString()).startsWith(EXPECTED_PUBLIC_KEY_EXPORT_USAGE);
assertThat(commandErrorOutput.toString()).isEmpty();
assertThat(commandOutput.toString(UTF_8)).startsWith(EXPECTED_PUBLIC_KEY_EXPORT_USAGE);
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();
}

@Test
Expand All @@ -154,8 +155,8 @@ public void callingPublicKeyExportSubCommandWithoutPathMustWriteKeyToStandardOut
parseCommand(PUBLIC_KEY_SUBCOMMAND_NAME, PUBLIC_KEY_EXPORT_SUBCOMMAND_NAME);

final String expectedOutputStart = nodeKey.getPublicKey().toString();
assertThat(commandOutput.toString()).startsWith(expectedOutputStart);
assertThat(commandErrorOutput.toString()).isEmpty();
assertThat(commandOutput.toString(UTF_8)).startsWith(expectedOutputStart);
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();
}

@Test
Expand All @@ -173,8 +174,8 @@ public void callingPublicKeyExportSubCommandWithFilePathMustWritePublicKeyInThis
.startsWith(nodeKey.getPublicKey().toString())
.endsWith(nodeKey.getPublicKey().toString());

assertThat(commandOutput.toString()).isEmpty();
assertThat(commandErrorOutput.toString()).isEmpty();
assertThat(commandOutput.toString(UTF_8)).isEmpty();
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();
}

@Test
Expand All @@ -197,8 +198,8 @@ public void callingPublicKeyExportSubCommandWithPrivateKeyFileMustWriteKeyToStan
privateKeyFile.toString());

final String expectedOutputStart = keyPair.getPublicKey().toString();
assertThat(commandOutput.toString()).startsWith(expectedOutputStart);
assertThat(commandErrorOutput.toString()).isEmpty();
assertThat(commandOutput.toString(UTF_8)).startsWith(expectedOutputStart);
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();
}

@Test
Expand All @@ -208,8 +209,8 @@ public void callingPublicKeyExportSubCommandWithNonExistentMustDisplayError() {
PUBLIC_KEY_EXPORT_SUBCOMMAND_NAME,
"--node-private-key-file",
"/non/existent/file");
assertThat(commandOutput.toString()).isEmpty();
assertThat(commandErrorOutput.toString()).startsWith("Private key file doesn't exist");
assertThat(commandOutput.toString(UTF_8)).isEmpty();
assertThat(commandErrorOutput.toString(UTF_8)).startsWith("Private key file doesn't exist");
}

@Test
Expand All @@ -222,16 +223,17 @@ public void callingPublicKeyExportSubCommandWithInvalidFileMustDisplayError() th
PUBLIC_KEY_EXPORT_SUBCOMMAND_NAME,
"--node-private-key-file",
privateKeyFile.toString());
assertThat(commandOutput.toString()).isEmpty();
assertThat(commandErrorOutput.toString()).startsWith("Private key cannot be loaded from file");
assertThat(commandOutput.toString(UTF_8)).isEmpty();
assertThat(commandErrorOutput.toString(UTF_8))
.startsWith("Private key cannot be loaded from file");
}

// Export address sub-sub-command
@Test
public void callingPublicKeyExportAddressSubCommandHelpMustDisplayUsage() {
parseCommand(PUBLIC_KEY_SUBCOMMAND_NAME, PUBLIC_KEY_EXPORT_ADDRESS_SUBCOMMAND_NAME, "--help");
assertThat(commandOutput.toString()).startsWith(EXPECTED_PUBLIC_KEY_EXPORT_ADDRESS_USAGE);
assertThat(commandErrorOutput.toString()).isEmpty();
assertThat(commandOutput.toString(UTF_8)).startsWith(EXPECTED_PUBLIC_KEY_EXPORT_ADDRESS_USAGE);
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();
}

@Test
Expand All @@ -241,8 +243,8 @@ public void callingPublicKeyExportAddressSubCommandWithoutPathMustWriteAddressTo
parseCommand(PUBLIC_KEY_SUBCOMMAND_NAME, PUBLIC_KEY_EXPORT_ADDRESS_SUBCOMMAND_NAME);

final String expectedOutputStart = Util.publicKeyToAddress(nodeKey.getPublicKey()).toString();
assertThat(commandOutput.toString()).startsWith(expectedOutputStart);
assertThat(commandErrorOutput.toString()).isEmpty();
assertThat(commandOutput.toString(UTF_8)).startsWith(expectedOutputStart);
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();
}

@Test
Expand All @@ -263,8 +265,8 @@ public void callingPublicKeyExportAddressSubCommandWithFilePathMustWriteAddressI
.startsWith(Util.publicKeyToAddress(nodeKey.getPublicKey()).toString())
.endsWith(Util.publicKeyToAddress(nodeKey.getPublicKey()).toString());

assertThat(commandOutput.toString()).isEmpty();
assertThat(commandErrorOutput.toString()).isEmpty();
assertThat(commandOutput.toString(UTF_8)).isEmpty();
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();
}

@Test
Expand All @@ -288,8 +290,8 @@ public void callingPublicKeyExportAddressSubCommandWithFilePathMustWriteAddressI
privateKeyFile.toString());

final String expectedOutputStart = Util.publicKeyToAddress(keyPair.getPublicKey()).toString();
assertThat(commandOutput.toString()).startsWith(expectedOutputStart);
assertThat(commandErrorOutput.toString()).isEmpty();
assertThat(commandOutput.toString(UTF_8)).startsWith(expectedOutputStart);
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();
}

@Test
Expand All @@ -299,8 +301,8 @@ public void callingPublicKeyExportAddressSubCommandWithNonExistentMustDisplayErr
PUBLIC_KEY_EXPORT_ADDRESS_SUBCOMMAND_NAME,
"--node-private-key-file",
"/non/existent/file");
assertThat(commandOutput.toString()).isEmpty();
assertThat(commandErrorOutput.toString()).startsWith("Private key file doesn't exist");
assertThat(commandOutput.toString(UTF_8)).isEmpty();
assertThat(commandErrorOutput.toString(UTF_8)).startsWith("Private key file doesn't exist");
}

@Test
Expand All @@ -314,7 +316,8 @@ public void callingPublicKeyExportAddressSubCommandWithInvalidFileMustDisplayErr
PUBLIC_KEY_EXPORT_ADDRESS_SUBCOMMAND_NAME,
"--node-private-key-file",
privateKeyFile.toString());
assertThat(commandOutput.toString()).isEmpty();
assertThat(commandErrorOutput.toString()).startsWith("Private key cannot be loaded from file");
assertThat(commandOutput.toString(UTF_8)).isEmpty();
assertThat(commandErrorOutput.toString(UTF_8))
.startsWith("Private key cannot be loaded from file");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
package org.hyperledger.besu.cli;

import static java.nio.charset.StandardCharsets.UTF_8;
import static org.assertj.core.api.Assertions.assertThat;

import java.io.IOException;
Expand Down Expand Up @@ -45,23 +46,23 @@ public class ValidateConfigSubCommandTest extends CommandTestAbstract {
public void validateConfigSubCommandExists() {
CommandSpec spec = parseCommand().getSpec();
assertThat(spec.subcommands()).containsKeys(VALIDATE_CONFIG_SUBCOMMAND_NAME);
assertThat(commandOutput.toString()).isEmpty();
assertThat(commandErrorOutput.toString()).isEmpty();
assertThat(commandOutput.toString(UTF_8)).isEmpty();
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();
}

@Test
public void callingValidateConfigSubCommandHelpMustDisplayUsage() {
parseCommand(VALIDATE_CONFIG_SUBCOMMAND_NAME, "--help");
assertThat(commandOutput.toString()).startsWith(EXPECTED_PUBLIC_KEY_USAGE);
assertThat(commandErrorOutput.toString()).isEmpty();
assertThat(commandOutput.toString(UTF_8)).startsWith(EXPECTED_PUBLIC_KEY_USAGE);
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();
}

@Test
public void callingValidateConfigSubCommandWithNonExistentMustDisplayError() {
parseCommand(VALIDATE_CONFIG_SUBCOMMAND_NAME, "--config-file", "/non/existent/file");
assertThat(commandOutput.toString())
assertThat(commandOutput.toString(UTF_8))
.contains("Unable to read TOML configuration, file not found.");
assertThat(commandErrorOutput.toString()).isEmpty();
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();
}

@Test
Expand All @@ -71,8 +72,8 @@ public void callingValidateConfigSubCommandWithInvalidFileMustDisplayError() thr
invalidToml.toFile().deleteOnExit();

parseCommand(VALIDATE_CONFIG_SUBCOMMAND_NAME, "--config-file", invalidToml.toString());
assertThat(commandOutput.toString()).contains("Invalid TOML configuration");
assertThat(commandErrorOutput.toString()).isEmpty();
assertThat(commandOutput.toString(UTF_8)).contains("Invalid TOML configuration");
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();
}

@Test
Expand All @@ -84,7 +85,7 @@ public void callingValidateConfigSubCommandWithValidTomlFileSucceeds() throws IO
validToml.toFile().deleteOnExit();

parseCommand(VALIDATE_CONFIG_SUBCOMMAND_NAME, "--config-file", validToml.toString());
assertThat(commandOutput.toString()).startsWith("TOML config file is valid");
assertThat(commandErrorOutput.toString()).isEmpty();
assertThat(commandOutput.toString(UTF_8)).startsWith("TOML config file is valid");
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,22 +90,22 @@ public void operatorSubCommandExistAndHaveSubCommands() {
assertThat(spec.subcommands()).containsKeys(OperatorSubCommand.COMMAND_NAME);
assertThat(spec.subcommands().get(OperatorSubCommand.COMMAND_NAME).getSubcommands())
.containsKeys(OperatorSubCommand.GENERATE_BLOCKCHAIN_CONFIG_SUBCOMMAND_NAME);
assertThat(commandOutput.toString()).isEmpty();
assertThat(commandErrorOutput.toString()).isEmpty();
assertThat(commandOutput.toString(UTF_8)).isEmpty();
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();
}

@Test
public void callingOperatorSubCommandWithoutSubSubcommandMustDisplayUsage() {
parseCommand(OperatorSubCommand.COMMAND_NAME);
assertThat(commandOutput.toString()).startsWith(EXPECTED_OPERATOR_USAGE);
assertThat(commandErrorOutput.toString()).isEmpty();
assertThat(commandOutput.toString(UTF_8)).startsWith(EXPECTED_OPERATOR_USAGE);
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();
}

@Test
public void callingOperatorCommandHelpMustDisplayUsage() {
parseCommand(OperatorSubCommand.COMMAND_NAME, "--help");
assertThat(commandOutput.toString()).startsWith(EXPECTED_OPERATOR_USAGE);
assertThat(commandErrorOutput.toString()).isEmpty();
assertThat(commandOutput.toString(UTF_8)).startsWith(EXPECTED_OPERATOR_USAGE);
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();
}

@Test
Expand Down Expand Up @@ -367,7 +367,7 @@ private void runCmdAndCheckOutput(
outputDirectoryPath.toString())
.args(cmd.argsArray())
.argsArray());
assertThat(commandErrorOutput.toString()).isEmpty();
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();

final Path outputGenesisExpectedPath = outputDirectoryPath.resolve(genesisFileName);
final File outputGenesisFile = new File(outputGenesisExpectedPath.toUri());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
package org.hyperledger.besu.cli.options;

import static java.nio.charset.StandardCharsets.UTF_8;
import static org.assertj.core.api.Assertions.assertThat;

import org.hyperledger.besu.cli.CommandTestAbstract;
Expand Down Expand Up @@ -63,8 +64,8 @@ private void getCLIOptions(final D domainObject) {

assertThat(optionsFromCommand).usingRecursiveComparison().isEqualTo(options);

assertThat(commandOutput.toString()).isEmpty();
assertThat(commandErrorOutput.toString()).isEmpty();
assertThat(commandOutput.toString(UTF_8)).isEmpty();
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();
}

@Test
Expand Down
Loading

0 comments on commit ed9d64d

Please sign in to comment.