From c7e9134ab88eb010247aff0e59b6ca11705fec15 Mon Sep 17 00:00:00 2001 From: Simon Dudley Date: Mon, 15 Nov 2021 06:28:34 +0100 Subject: [PATCH] Remove redundant method and associated tests (#3059) Fixes https://github.com/hyperledger/besu/issues/3038 Signed-off-by: Simon Dudley --- .../blockbased/BlockValidatorProvider.java | 6 -- .../BlockValidatorProviderTest.java | 86 ------------------- 2 files changed, 92 deletions(-) delete mode 100644 consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/BlockValidatorProviderTest.java diff --git a/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/validator/blockbased/BlockValidatorProvider.java b/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/validator/blockbased/BlockValidatorProvider.java index 7593ca3234..5586dea301 100644 --- a/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/validator/blockbased/BlockValidatorProvider.java +++ b/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/validator/blockbased/BlockValidatorProvider.java @@ -32,7 +32,6 @@ public class BlockValidatorProvider implements ValidatorProvider { private final VoteTallyCache voteTallyCache; private final VoteProvider voteProvider; private final BlockInterface blockInterface; - private final Optional bftValidatorOverrides; public static BlockValidatorProvider forkingValidatorProvider( final Blockchain blockchain, @@ -68,7 +67,6 @@ public class BlockValidatorProvider implements ValidatorProvider { : new VoteTallyCache(blockchain, voteTallyUpdater, epochManager, blockInterface); this.voteProvider = new BlockVoteProvider(voteTallyCache, voteProposer); this.blockInterface = blockInterface; - this.bftValidatorOverrides = bftValidatorOverrides; } @Override @@ -90,8 +88,4 @@ public class BlockValidatorProvider implements ValidatorProvider { public Optional getVoteProviderAtHead() { return Optional.of(voteProvider); } - - public boolean hasValidatorOverridesForBlockNumber(final long blockNumber) { - return bftValidatorOverrides.map(bvo -> bvo.getForBlock(blockNumber).isPresent()).orElse(false); - } } diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/BlockValidatorProviderTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/BlockValidatorProviderTest.java deleted file mode 100644 index c8c1a3873b..0000000000 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/BlockValidatorProviderTest.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright Hyperledger Besu contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ -package org.hyperledger.besu.consensus.common.validator.blockbased; - -import static java.util.Collections.emptyMap; -import static org.assertj.core.api.Assertions.assertThat; - -import org.hyperledger.besu.consensus.common.BftValidatorOverrides; -import org.hyperledger.besu.consensus.common.BlockInterface; -import org.hyperledger.besu.consensus.common.EpochManager; -import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.ethereum.chain.Blockchain; - -import java.util.List; -import java.util.Map; - -import org.assertj.core.api.SoftAssertions; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; - -@RunWith(MockitoJUnitRunner.class) -public class BlockValidatorProviderTest { - - @Mock private BlockInterface blockInterface; - @Mock private Blockchain blockchain; - @Mock private EpochManager epochManager; - - @Test - public void nonForkingValidatorProviderHasNoOverrides() { - final BlockValidatorProvider blockValidatorProvider = - BlockValidatorProvider.nonForkingValidatorProvider( - blockchain, epochManager, blockInterface); - - assertThat(blockValidatorProvider.hasValidatorOverridesForBlockNumber(0)).isFalse(); - } - - @Test - public void forkingValidatorProviderHasNoOverrides() { - final BlockValidatorProvider blockValidatorProvider = - BlockValidatorProvider.forkingValidatorProvider( - blockchain, epochManager, blockInterface, new BftValidatorOverrides(emptyMap())); - - assertThat(blockValidatorProvider.hasValidatorOverridesForBlockNumber(0)).isFalse(); - } - - @Test - public void forkingValidatorProviderHasOverridesForBlock1() { - final Map> overriddenValidators = - Map.of(1L, List.of(Address.fromHexString("0"))); - final BftValidatorOverrides bftValidatorOverrides = - new BftValidatorOverrides(overriddenValidators); - final BlockValidatorProvider blockValidatorProvider = - BlockValidatorProvider.forkingValidatorProvider( - blockchain, epochManager, blockInterface, bftValidatorOverrides); - - SoftAssertions.assertSoftly( - (softly) -> { - softly - .assertThat(blockValidatorProvider.hasValidatorOverridesForBlockNumber(0)) - .as("Block 0 should have no overridden validators") - .isFalse(); - softly - .assertThat(blockValidatorProvider.hasValidatorOverridesForBlockNumber(1)) - .as("Block 1 should have some overridden validators") - .isTrue(); - softly - .assertThat(blockValidatorProvider.hasValidatorOverridesForBlockNumber(2)) - .as("Block 2 should have no overridden validators") - .isFalse(); - }); - } -}