Skip to content

Commit

Permalink
kubernetes and errorprone - update versions (hyperledger#5013)
Browse files Browse the repository at this point in the history
* update errorprone and kubernetes versions
* fixed errorprone issues in prod cod
* fixed errorprone issues in test code

---------

Signed-off-by: Sally MacFarlane <macfarla.github@gmail.com>
  • Loading branch information
macfarla authored Feb 1, 2023
1 parent a02cacc commit c9de473
Show file tree
Hide file tree
Showing 67 changed files with 441 additions and 273 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void beforeExternalServices() {

if (signingEnabled) {
pluginService.setPrivateMarkerTransactionFactory(privateMarkerTransactionFactory);
privateMarkerTransactionFactory.setSigningKeyEnbaled(signingKey);
privateMarkerTransactionFactory.setSigningKeyEnabled(signingKey);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class TestSigningPrivateMarkerTransactionFactory implements PrivateMarker
KeyPair aliceFixedSigningKey;
Address sender;

public void setSigningKeyEnbaled(final String privateMarkerTransactionSigningKey) {
public void setSigningKeyEnabled(final String privateMarkerTransactionSigningKey) {
final SignatureAlgorithm algorithm = SignatureAlgorithmFactory.getInstance();
final SECPPrivateKey privateKey =
algorithm.createPrivateKey(Bytes32.fromHexString(privateMarkerTransactionSigningKey));
Expand Down
6 changes: 0 additions & 6 deletions besu/src/test/java/org/hyperledger/besu/PrivacyReorgTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.enclave.Enclave;
import org.hyperledger.besu.enclave.EnclaveFactory;
import org.hyperledger.besu.enclave.types.PrivacyGroup;
import org.hyperledger.besu.enclave.types.ReceiveResponse;
import org.hyperledger.besu.ethereum.GasLimitCalculator;
import org.hyperledger.besu.ethereum.ProtocolContext;
Expand All @@ -51,7 +50,6 @@
import org.hyperledger.besu.ethereum.mainnet.HeaderValidationMode;
import org.hyperledger.besu.ethereum.privacy.PrivateStateRootResolver;
import org.hyperledger.besu.ethereum.privacy.PrivateTransaction;
import org.hyperledger.besu.ethereum.privacy.RestrictedDefaultPrivacyController;
import org.hyperledger.besu.ethereum.privacy.storage.PrivacyGroupHeadBlockMap;
import org.hyperledger.besu.ethereum.privacy.storage.PrivacyStorageProvider;
import org.hyperledger.besu.ethereum.privacy.storage.PrivateStateStorage;
Expand Down Expand Up @@ -134,7 +132,6 @@ public class PrivacyReorgTest {
private BesuController besuController;
private PrivateStateRootResolver privateStateRootResolver;
private PrivacyParameters privacyParameters;
private RestrictedDefaultPrivacyController privacyController;
private Enclave mockEnclave;
private Transaction privacyMarkerTransaction;

Expand Down Expand Up @@ -176,9 +173,6 @@ public void setUp() throws IOException {
.build();

privacyParameters.setPrivacyUserId(ENCLAVE_PUBLIC_KEY.toBase64String());
privacyController = mock(RestrictedDefaultPrivacyController.class);
when(privacyController.findPrivacyGroupByGroupId(any(), any()))
.thenReturn(Optional.of(new PrivacyGroup()));

privateStateRootResolver =
new PrivateStateRootResolver(privacyParameters.getPrivateStateStorage());
Expand Down
31 changes: 17 additions & 14 deletions besu/src/test/java/org/hyperledger/besu/RunnerBuilderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,17 @@ public final class RunnerBuilderTest {
@Rule public TemporaryFolder dataDir = new TemporaryFolder();

@Mock BesuController besuController;
@Mock ProtocolSchedule protocolSchedule;
@Mock ProtocolContext protocolContext;
@Mock Vertx vertx;
private NodeKey nodeKey;

@Before
public void setup() {
final SubProtocolConfiguration subProtocolConfiguration = mock(SubProtocolConfiguration.class);
final EthProtocolManager ethProtocolManager = mock(EthProtocolManager.class);
final EthContext ethContext = mock(EthContext.class);
final ProtocolContext protocolContext = mock(ProtocolContext.class);
final NodeKey nodeKey =
new NodeKey(new KeyPairSecurityModule(new SECP256K1().generateKeyPair()));
nodeKey = new NodeKey(new KeyPairSecurityModule(new SECP256K1().generateKeyPair()));

when(subProtocolConfiguration.getProtocolManagers())
.thenReturn(
Expand All @@ -127,7 +128,7 @@ public void setup() {
when(besuController.getProtocolManager()).thenReturn(ethProtocolManager);
when(besuController.getSubProtocolConfiguration()).thenReturn(subProtocolConfiguration);
when(besuController.getProtocolContext()).thenReturn(protocolContext);
when(besuController.getProtocolSchedule()).thenReturn(mock(ProtocolSchedule.class));
when(besuController.getProtocolSchedule()).thenReturn(protocolSchedule);
when(besuController.getNodeKey()).thenReturn(nodeKey);
when(besuController.getMiningParameters()).thenReturn(mock(MiningParameters.class));
when(besuController.getPrivacyParameters()).thenReturn(mock(PrivacyParameters.class));
Expand Down Expand Up @@ -169,14 +170,14 @@ public void enodeUrlShouldHaveAdvertisedHostWhenDiscoveryDisabled() {
.build();
runner.startEthereumMainLoop();

final EnodeURL expectedEodeURL =
final EnodeURL expectedEnodeURL =
EnodeURLImpl.builder()
.ipAddress(p2pAdvertisedHost)
.discoveryPort(0)
.listeningPort(p2pListenPort)
.nodeId(besuController.getNodeKey().getPublicKey().getEncoded())
.nodeId(nodeKey.getPublicKey().getEncoded())
.build();
assertThat(runner.getLocalEnode().orElseThrow()).isEqualTo(expectedEodeURL);
assertThat(runner.getLocalEnode().orElseThrow()).isEqualTo(expectedEnodeURL);
}

@Test
Expand All @@ -186,9 +187,9 @@ public void movingAcrossProtocolSpecsUpdatesNodeRecord() {
final int p2pListenPort = 30301;
final StorageProvider storageProvider = new InMemoryKeyValueStorageProvider();
final Block genesisBlock = gen.genesisBlock();
final MutableBlockchain blockchain =
final MutableBlockchain inMemoryBlockchain =
createInMemoryBlockchain(genesisBlock, new MainnetBlockHeaderFunctions());
when(besuController.getProtocolContext().getBlockchain()).thenReturn(blockchain);
when(protocolContext.getBlockchain()).thenReturn(inMemoryBlockchain);
final Runner runner =
new RunnerBuilder()
.discovery(true)
Expand All @@ -212,15 +213,16 @@ public void movingAcrossProtocolSpecsUpdatesNodeRecord() {
.rpcEndpointService(new RpcEndpointServiceImpl())
.build();
runner.startEthereumMainLoop();
when(besuController.getProtocolSchedule().streamMilestoneBlocks())
.thenAnswer(__ -> Stream.of(1L, 2L));

when(protocolSchedule.streamMilestoneBlocks()).thenAnswer(__ -> Stream.of(1L, 2L));

for (int i = 0; i < 2; ++i) {
final Block block =
gen.block(
BlockDataGenerator.BlockOptions.create()
.setBlockNumber(1 + i)
.setParentHash(blockchain.getChainHeadHash()));
blockchain.appendBlock(block, gen.receipts(block));
.setParentHash(inMemoryBlockchain.getChainHeadHash()));
inMemoryBlockchain.appendBlock(block, gen.receipts(block));
assertThat(
storageProvider
.getStorageBySegmentIdentifier(BLOCKCHAIN)
Expand Down Expand Up @@ -400,7 +402,8 @@ public void assertTransitionStratumConfiguration() {
final EthNetworkConfig mockMainnet = mock(EthNetworkConfig.class);
when(mockMainnet.getNetworkId()).thenReturn(BigInteger.ONE);
MergeConfigOptions.setMergeEnabled(true);
final MiningParameters mockMiningParams = besuController.getMiningParameters();
final MiningParameters mockMiningParams = mock(MiningParameters.class);
when(besuController.getMiningParameters()).thenReturn(mockMiningParams);
when(mockMiningParams.isStratumMiningEnabled()).thenReturn(true);
final TransitionCoordinator mockTransitionCoordinator =
spy(
Expand Down
24 changes: 16 additions & 8 deletions besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1200,7 +1200,8 @@ public void predefinedNetworkIdsMustBeEqualToChainIds() {
public void identityValueTrueMustBeUsed() {
parseCommand("--identity", "test");

verify(mockRunnerBuilder.identityString(eq(Optional.of("test")))).build();
verify(mockRunnerBuilder).identityString(eq(Optional.of("test")));
verify(mockRunnerBuilder).build();

assertThat(commandOutput.toString(UTF_8)).isEmpty();
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();
Expand All @@ -1210,7 +1211,8 @@ public void identityValueTrueMustBeUsed() {
public void p2pEnabledOptionValueTrueMustBeUsed() {
parseCommand("--p2p-enabled", "true");

verify(mockRunnerBuilder.p2pEnabled(eq(true))).build();
verify(mockRunnerBuilder).p2pEnabled(eq(true));
verify(mockRunnerBuilder).build();

assertThat(commandOutput.toString(UTF_8)).isEmpty();
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();
Expand All @@ -1220,7 +1222,8 @@ public void p2pEnabledOptionValueTrueMustBeUsed() {
public void p2pEnabledOptionValueFalseMustBeUsed() {
parseCommand("--p2p-enabled", "false");

verify(mockRunnerBuilder.p2pEnabled(eq(false))).build();
verify(mockRunnerBuilder).p2pEnabled(eq(false));
verify(mockRunnerBuilder).build();

assertThat(commandOutput.toString(UTF_8)).isEmpty();
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();
Expand Down Expand Up @@ -1301,7 +1304,8 @@ public void p2pOptionsRequiresServiceToBeEnabledToml() throws IOException {
public void discoveryOptionValueTrueMustBeUsed() {
parseCommand("--discovery-enabled", "true");

verify(mockRunnerBuilder.discovery(eq(true))).build();
verify(mockRunnerBuilder).discovery(eq(true));
verify(mockRunnerBuilder).build();

assertThat(commandOutput.toString(UTF_8)).isEmpty();
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();
Expand All @@ -1311,7 +1315,8 @@ public void discoveryOptionValueTrueMustBeUsed() {
public void discoveryOptionValueFalseMustBeUsed() {
parseCommand("--discovery-enabled", "false");

verify(mockRunnerBuilder.discovery(eq(false))).build();
verify(mockRunnerBuilder).discovery(eq(false));
verify(mockRunnerBuilder).build();

assertThat(commandOutput.toString(UTF_8)).isEmpty();
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();
Expand Down Expand Up @@ -4397,8 +4402,8 @@ public void privateMarkerTransactionSigningKeyFileRequiredIfMinGasPriceNonZero()
public void
privateMarkerTransactionSigningKeyFileNotCanNotBeUsedWithPluginPrivateMarkerTransactionFactory()
throws IOException {
privacyPluginService.setPrivateMarkerTransactionFactory(
mock(PrivateMarkerTransactionFactory.class));
when(privacyPluginService.getPrivateMarkerTransactionFactory())
.thenReturn(mock(PrivateMarkerTransactionFactory.class));
final Path toml =
createTempFile(
"key",
Expand All @@ -4412,7 +4417,10 @@ public void privateMarkerTransactionSigningKeyFileRequiredIfMinGasPriceNonZero()
toml.toString());

assertThat(commandOutput.toString(UTF_8)).isEmpty();
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();
// assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();
assertThat(commandErrorOutput.toString(UTF_8))
.startsWith(
"--privacy-marker-transaction-signing-key-file can not be used in conjunction with a plugin that specifies");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import picocli.CommandLine;
import picocli.CommandLine.IDefaultValueProvider;
import picocli.CommandLine.IExecutionStrategy;
import picocli.CommandLine.IParameterExceptionHandler;
import picocli.CommandLine.Model.CommandSpec;
import picocli.CommandLine.Model.IGetter;
import picocli.CommandLine.Model.OptionSpec;
Expand All @@ -58,7 +57,6 @@ public class ConfigOptionSearchAndRunHandlerTest {

private LoggingLevelOption levelOption;
private final IExecutionStrategy resultHandler = new RunLast();
private IParameterExceptionHandler parameterExceptionHandler;

private final Map<String, String> environment = singletonMap("BESU_LOGGING", "ERROR");
private ConfigOptionSearchAndRunHandler configParsingHandler;
Expand All @@ -80,12 +78,11 @@ public void initMocks() {
when(mockParseResult.matchedOption(CONFIG_FILE_OPTION_NAME)).thenReturn(mockConfigOptionSpec);
when(mockParseResult.hasMatchedOption(CONFIG_FILE_OPTION_NAME)).thenReturn(true);
when(mockConfigOptionSpec.getter()).thenReturn(mockConfigOptionGetter);
when(mockCommandLine.getParameterExceptionHandler()).thenReturn(mockParameterExceptionHandler);
levelOption = new LoggingLevelOption();
levelOption.setLogLevel("INFO");
parameterExceptionHandler = mockCommandLine.getParameterExceptionHandler();
configParsingHandler =
new ConfigOptionSearchAndRunHandler(resultHandler, parameterExceptionHandler, environment);
new ConfigOptionSearchAndRunHandler(
resultHandler, mockParameterExceptionHandler, environment);
}

@Test
Expand All @@ -94,7 +91,7 @@ public void handleWithCommandLineOption() throws Exception {
final List<Object> result = configParsingHandler.handle(mockParseResult);
verify(mockCommandLine).setDefaultValueProvider(any(IDefaultValueProvider.class));
verify(mockCommandLine).setExecutionStrategy(eq(resultHandler));
verify(mockCommandLine).setParameterExceptionHandler(eq(parameterExceptionHandler));
verify(mockCommandLine).setParameterExceptionHandler(eq(mockParameterExceptionHandler));
verify(mockCommandLine).execute(anyString());

assertThat(result).isEmpty();
Expand All @@ -107,7 +104,7 @@ public void handleWithEnvironmentVariable() throws IOException {
final ConfigOptionSearchAndRunHandler environmentConfigFileParsingHandler =
new ConfigOptionSearchAndRunHandler(
resultHandler,
parameterExceptionHandler,
mockParameterExceptionHandler,
singletonMap("BESU_CONFIG_FILE", temp.newFile().getAbsolutePath()));

when(mockParseResult.hasMatchedOption(CONFIG_FILE_OPTION_NAME)).thenReturn(false);
Expand All @@ -129,7 +126,7 @@ public void handleWithEnvironmentVariableOptionShouldRaiseExceptionIfNoFileParam
final ConfigOptionSearchAndRunHandler environmentConfigFileParsingHandler =
new ConfigOptionSearchAndRunHandler(
resultHandler,
parameterExceptionHandler,
mockParameterExceptionHandler,
singletonMap("BESU_CONFIG_FILE", "not_found.toml"));

when(mockParseResult.hasMatchedOption(CONFIG_FILE_OPTION_NAME)).thenReturn(false);
Expand Down Expand Up @@ -162,7 +159,7 @@ public void handleThrowsErrorWithWithEnvironmentVariableAndCommandLineSpecified(
final ConfigOptionSearchAndRunHandler environmentConfigFileParsingHandler =
new ConfigOptionSearchAndRunHandler(
resultHandler,
parameterExceptionHandler,
mockParameterExceptionHandler,
singletonMap("BESU_CONFIG_FILE", temp.newFile().getAbsolutePath()));

when(mockParseResult.hasMatchedOption(CONFIG_FILE_OPTION_NAME)).thenReturn(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,10 @@ public void insertsNoVoteWhenAtEpoch() {
CliqueExtraData.createWithoutProposerSeal(Bytes.wrap(new byte[32]), validatorList);
final Address a1 = Address.fromHexString("5");
final Address coinbase = AddressHelpers.ofValue(1);
when(validatorProvider.getVoteProviderAtHead().get().getVoteAfterBlock(any(), any()))

final VoteProvider mockVoteProvider = mock(VoteProvider.class);
when(validatorProvider.getVoteProviderAtHead()).thenReturn(Optional.of(mockVoteProvider));
when(mockVoteProvider.getVoteAfterBlock(any(), any()))
.thenReturn(Optional.of(new ValidatorVote(VoteType.ADD, coinbase, a1)));

final CliqueBlockCreator blockCreator =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import org.mockito.junit.jupiter.MockitoExtension;

@ExtendWith(MockitoExtension.class)
@SuppressWarnings("DirectInvocationOnMock")
public class CliqueMiningCoordinatorTest {

private static final Supplier<SignatureAlgorithm> SIGNATURE_ALGORITHM =
Expand All @@ -80,10 +81,10 @@ public class CliqueMiningCoordinatorTest {
@Mock private CliqueBlockMiner blockMiner;
@Mock private SyncState syncState;
@Mock private ValidatorProvider validatorProvider;
@Mock private BlockHeader blockHeader;

@BeforeEach
public void setup() {

headerTestFixture.number(1);
Block genesisBlock = createEmptyBlock(0, Hash.ZERO, proposerKeys); // not normally signed but ok
blockChain = createInMemoryBlockchain(genesisBlock);
Expand All @@ -101,7 +102,7 @@ public void outOfTurnBlockImportedDoesNotInterruptInTurnMiningOperation() {
// As the head of the blockChain is 0 (which effectively doesn't have a signer, all validators
// are able to propose.

when(blockMiner.getParentHeader()).thenReturn(blockChain.getChainHeadHeader());
when(blockMiner.getParentHeader()).thenReturn(blockHeader);

// Note also - validators is an hard-ordered LIST, thus in-turn will follow said list - block_1
// should be created by proposer.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ void discardOutstandingVotes() {
}

/**
* The validator addresses
*
* @return The collection of validators after the voting at the most recent block has been
* finalised.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void createMessageFromGenericMessageData() {
when(messageData.getCode()).thenReturn(IbftV2.COMMIT);
CommitMessageData commitMessage = CommitMessageData.fromMessageData(messageData);

assertThat(commitMessage.getData()).isEqualTo(messageData.getData());
assertThat(commitMessage.getData()).isEqualTo(messageBytes);
assertThat(commitMessage.getCode()).isEqualTo(IbftV2.COMMIT);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void createMessageFromGenericMessageData() {
when(messageData.getCode()).thenReturn(IbftV2.PREPARE);
PrepareMessageData prepareMessage = PrepareMessageData.fromMessageData(messageData);

assertThat(prepareMessage.getData()).isEqualTo(messageData.getData());
assertThat(prepareMessage.getData()).isEqualTo(messageBytes);
assertThat(prepareMessage.getCode()).isEqualTo(IbftV2.PREPARE);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void createMessageFromGenericMessageData() {
when(messageData.getData()).thenReturn(messageBytes);
final ProposalMessageData proposalMessage = ProposalMessageData.fromMessageData(messageData);

assertThat(proposalMessage.getData()).isEqualTo(messageData.getData());
assertThat(proposalMessage.getData()).isEqualTo(messageBytes);
assertThat(proposalMessage.getCode()).isEqualTo(IbftV2.PROPOSAL);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void createMessageFromGenericMessageData() {
when(messageData.getCode()).thenReturn(IbftV2.ROUND_CHANGE);
RoundChangeMessageData roundChangeMessage = RoundChangeMessageData.fromMessageData(messageData);

assertThat(roundChangeMessage.getData()).isEqualTo(messageData.getData());
assertThat(roundChangeMessage.getData()).isEqualTo(messageBytes);
assertThat(roundChangeMessage.getCode()).isEqualTo(IbftV2.ROUND_CHANGE);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,7 @@ public void setup() {
invocation -> {
final int round = invocation.getArgument(1);
final ConsensusRoundIdentifier roundId = new ConsensusRoundIdentifier(1, round);
final RoundState createdRoundState =
new RoundState(roundId, finalState.getQuorum(), messageValidator);
final RoundState createdRoundState = new RoundState(roundId, 3, messageValidator);
return new IbftRound(
createdRoundState,
blockCreator,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public void createsNewBlockHeightManagerAndReplaysFutureMessagesOnNewChainHeadEv
public void newBlockForCurrentOrPreviousHeightTriggersNoChange() {
constructIbftController();
ibftController.start();
long chainHeadHeight = chainHeadBlockHeader.getNumber();
long chainHeadHeight = 3;
when(nextBlock.getNumber()).thenReturn(chainHeadHeight);
when(nextBlock.getHash()).thenReturn(Hash.ZERO);
final NewChainHead sameHeightBlock = new NewChainHead(nextBlock);
Expand Down
Loading

0 comments on commit c9de473

Please sign in to comment.