Remove redundant method and associated tests (#3059)

Fixes https://github.com/hyperledger/besu/issues/3038

Signed-off-by: Simon Dudley <simon.dudley@consensys.net>
pull/3061/head
Simon Dudley 3 years ago committed by GitHub
parent 5c0763847d
commit c7e9134ab8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      consensus/common/src/main/java/org/hyperledger/besu/consensus/common/validator/blockbased/BlockValidatorProvider.java
  2. 86
      consensus/common/src/test/java/org/hyperledger/besu/consensus/common/validator/blockbased/BlockValidatorProviderTest.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> 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<VoteProvider> getVoteProviderAtHead() {
return Optional.of(voteProvider);
}
public boolean hasValidatorOverridesForBlockNumber(final long blockNumber) {
return bftValidatorOverrides.map(bvo -> bvo.getForBlock(blockNumber).isPresent()).orElse(false);
}
}

@ -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<Long, List<Address>> 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();
});
}
}
Loading…
Cancel
Save