[MINOR] switch QBFT tests to Junit5 (#5525)

* junit5

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

* lenient mocking

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

* remove junit4

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

---------

Signed-off-by: Sally MacFarlane <macfarla.github@gmail.com>
pull/5531/head
Sally MacFarlane 1 year ago committed by GitHub
parent 890e8cde14
commit 186d38b81d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      consensus/qbft/build.gradle
  2. 2
      consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/MutableQbftConfigOptionsTest.java
  3. 2
      consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/QbftBlockHeaderValidationRulesetFactoryTest.java
  4. 2
      consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/QbftExtraDataCodecTest.java
  5. 2
      consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/QbftProtocolScheduleTest.java
  6. 6
      consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/blockcreation/PkiQbftBlockCreatorTest.java
  7. 6
      consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/blockcreation/QbftBlockCreatorFactoryTest.java
  8. 2
      consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/headervalidationrules/QbftValidatorsValidationRuleTest.java
  9. 6
      consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftDiscardValidatorVoteTest.java
  10. 6
      consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftGetSignerMetricsTest.java
  11. 12
      consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftGetValidatorsByBlockHashTest.java
  12. 12
      consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftGetValidatorsByBlockNumberTest.java
  13. 6
      consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/jsonrpc/methods/QbftProposeValidatorVoteTest.java
  14. 2
      consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/messagewrappers/CommitTest.java
  15. 2
      consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/messagewrappers/PrepareTest.java
  16. 2
      consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/messagewrappers/ProposalTest.java
  17. 2
      consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/messagewrappers/RoundChangeTest.java
  18. 2
      consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/payload/QbftPayloadTest.java
  19. 8
      consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/pki/DefaultKeyStoreWrapperProviderTest.java
  20. 8
      consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/pki/PkiBlockCreationConfigurationProviderTest.java
  21. 6
      consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/pki/PkiQbftBlockHashingTest.java
  22. 2
      consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/pki/PkiQbftExtraDataCodecTest.java
  23. 2
      consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/protocol/Istanbul100SubProtocolTest.java
  24. 15
      consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/statemachine/QbftBlockHeightManagerTest.java
  25. 17
      consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/statemachine/QbftControllerTest.java
  26. 15
      consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/statemachine/QbftRoundTest.java
  27. 12
      consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/statemachine/RoundStateTest.java
  28. 2
      consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validation/CommitValidatorTest.java
  29. 2
      consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validation/PrepareValidatorTest.java
  30. 12
      consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validation/ProposalPayloadValidatorTest.java
  31. 14
      consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validation/ProposalValidatorTest.java
  32. 12
      consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validation/RoundChangeMessageValidatorTest.java
  33. 2
      consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validation/RoundChangePayloadValidatorTest.java
  34. 26
      consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validator/ForkingValidatorProviderTest.java
  35. 2
      consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validator/QbftForksSchedulesFactoryTest.java
  36. 12
      consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validator/TransactionValidatorProviderTest.java
  37. 6
      consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validator/ValidatorContractControllerTest.java
  38. 8
      consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validator/ValidatorModeTransitionLoggerTest.java

@ -63,11 +63,11 @@ dependencies {
testImplementation project(':metrics:core')
testImplementation project(':testutil')
testImplementation 'junit:junit'
testImplementation 'org.assertj:assertj-core'
testImplementation 'org.awaitility:awaitility'
testImplementation 'org.junit.jupiter:junit-jupiter'
testImplementation 'org.mockito:mockito-core'
testImplementation 'org.mockito:mockito-junit-jupiter'
testRuntimeOnly 'org.junit.vintage:junit-vintage-engine'

@ -26,7 +26,7 @@ import org.hyperledger.besu.config.QbftConfigOptions;
import java.util.Optional;
import org.junit.Test;
import org.junit.jupiter.api.Test;
public class MutableQbftConfigOptionsTest {

@ -36,7 +36,7 @@ import java.util.Collection;
import java.util.List;
import java.util.Optional;
import org.junit.Test;
import org.junit.jupiter.api.Test;
public class QbftBlockHeaderValidationRulesetFactoryTest {

@ -40,7 +40,7 @@ import java.util.function.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.Lists;
import org.apache.tuweni.bytes.Bytes;
import org.junit.Test;
import org.junit.jupiter.api.Test;
public class QbftExtraDataCodecTest {

@ -44,7 +44,7 @@ import java.util.Collection;
import java.util.List;
import java.util.Optional;
import org.junit.Test;
import org.junit.jupiter.api.Test;
public class QbftProtocolScheduleTest {
private final BftExtraDataCodec bftExtraDataCodec = mock(BftExtraDataCodec.class);

@ -42,8 +42,8 @@ import org.hyperledger.besu.pki.cms.CmsCreator;
import java.util.Collections;
import org.apache.tuweni.bytes.Bytes;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
public class PkiQbftBlockCreatorTest {
@ -54,7 +54,7 @@ public class PkiQbftBlockCreatorTest {
private PkiQbftBlockCreator pkiQbftBlockCreator;
private BlockHeaderTestFixture blockHeaderBuilder;
@Before
@BeforeEach
public void before() {
blockCreator = mock(BlockCreator.class);
cmsCreator = mock(CmsCreator.class);

@ -37,14 +37,14 @@ import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import java.util.Optional;
import org.apache.tuweni.bytes.Bytes;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
public class QbftBlockCreatorFactoryTest {
private final QbftExtraDataCodec extraDataCodec = new QbftExtraDataCodec();
private QbftBlockCreatorFactory qbftBlockCreatorFactory;
@Before
@BeforeEach
@SuppressWarnings("unchecked")
public void setUp() throws Exception {
final MiningParameters miningParams = mock(MiningParameters.class);

@ -32,7 +32,7 @@ import java.util.List;
import java.util.Optional;
import com.google.common.collect.Lists;
import org.junit.Test;
import org.junit.jupiter.api.Test;
public class QbftValidatorsValidationRuleTest {
private final BftExtraData bftExtraData = mock(BftExtraData.class);

@ -33,8 +33,8 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSucces
import java.util.Optional;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
public class QbftDiscardValidatorVoteTest {
private final ValidatorProvider validatorProvider = mock(ValidatorProvider.class);
@ -43,7 +43,7 @@ public class QbftDiscardValidatorVoteTest {
private final String JSON_RPC_VERSION = "2.0";
private QbftDiscardValidatorVote method;
@Before
@BeforeEach
public void setup() {
method = new QbftDiscardValidatorVote(validatorProvider);
when(validatorProvider.getVoteProviderAtHead()).thenReturn(Optional.of(voteProvider));

@ -41,8 +41,8 @@ import java.util.List;
import java.util.Optional;
import java.util.stream.LongStream;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
public class QbftGetSignerMetricsTest {
@ -58,7 +58,7 @@ public class QbftGetSignerMetricsTest {
private BlockchainQueries blockchainQueries;
private BlockInterface blockInterface;
@Before
@BeforeEach
public void setup() {
validatorProvider = mock(ValidatorProvider.class);
blockchainQueries = mock(BlockchainQueries.class);

@ -31,13 +31,13 @@ import java.util.List;
import java.util.Optional;
import org.assertj.core.api.Assertions;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;
@RunWith(MockitoJUnitRunner.class)
@ExtendWith(MockitoExtension.class)
public class QbftGetValidatorsByBlockHashTest {
private static final String ETH_METHOD = "qbft_getValidatorsByBlockHash";
@ -51,7 +51,7 @@ public class QbftGetValidatorsByBlockHashTest {
private QbftGetValidatorsByBlockHash method;
@Before
@BeforeEach
public void setUp() {
method = new QbftGetValidatorsByBlockHash(blockchain, validatorProvider);
}

@ -30,13 +30,13 @@ import java.util.Collections;
import java.util.List;
import java.util.Optional;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;
@RunWith(MockitoJUnitRunner.class)
@ExtendWith(MockitoExtension.class)
public class QbftGetValidatorsByBlockNumberTest {
@Mock private BlockchainQueries blockchainQueries;
@ -46,7 +46,7 @@ public class QbftGetValidatorsByBlockNumberTest {
private QbftGetValidatorsByBlockNumber method;
@Before
@BeforeEach
public void setUp() {
method = new QbftGetValidatorsByBlockNumber(blockchainQueries, validatorProvider);
}

@ -33,8 +33,8 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSucces
import java.util.Optional;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
public class QbftProposeValidatorVoteTest {
private final ValidatorProvider validatorProvider = mock(ValidatorProvider.class);
@ -43,7 +43,7 @@ public class QbftProposeValidatorVoteTest {
private final String JSON_RPC_VERSION = "2.0";
private QbftProposeValidatorVote method;
@Before
@BeforeEach
public void setup() {
method = new QbftProposeValidatorVote(validatorProvider);
when(validatorProvider.getVoteProviderAtHead()).thenReturn(Optional.of(voteProvider));

@ -29,7 +29,7 @@ import org.hyperledger.besu.ethereum.core.Util;
import java.math.BigInteger;
import org.junit.Test;
import org.junit.jupiter.api.Test;
public class CommitTest {

@ -26,7 +26,7 @@ import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.ethereum.core.Util;
import org.junit.Test;
import org.junit.jupiter.api.Test;
public class PrepareTest {

@ -39,7 +39,7 @@ import java.util.List;
import java.util.Optional;
import org.apache.tuweni.bytes.Bytes32;
import org.junit.Test;
import org.junit.jupiter.api.Test;
public class ProposalTest {
private static final BftExtraDataCodec bftExtraDataCodec = new QbftExtraDataCodec();

@ -38,7 +38,7 @@ import java.util.List;
import java.util.Optional;
import org.apache.tuweni.bytes.Bytes32;
import org.junit.Test;
import org.junit.jupiter.api.Test;
public class RoundChangeTest {
private static final BftExtraDataCodec bftExtraDataCodec = new QbftExtraDataCodec();

@ -22,7 +22,7 @@ import org.hyperledger.besu.ethereum.rlp.RLP;
import org.hyperledger.besu.ethereum.rlp.RLPInput;
import org.hyperledger.besu.ethereum.rlp.RLPOutput;
import org.junit.Test;
import org.junit.jupiter.api.Test;
public class QbftPayloadTest {

@ -28,13 +28,13 @@ import org.hyperledger.besu.pki.keystore.KeyStoreWrapper;
import java.nio.file.Path;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;
@RunWith(MockitoJUnitRunner.class)
@ExtendWith(MockitoExtension.class)
public class DefaultKeyStoreWrapperProviderTest {
@Mock private HardwareKeyStoreWrapperProvider hardwareKeyStoreWrapperProvider;

@ -28,12 +28,12 @@ import org.hyperledger.besu.pki.keystore.KeyStoreWrapper;
import java.nio.file.Path;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;
@RunWith(MockitoJUnitRunner.class)
@ExtendWith(MockitoExtension.class)
public class PkiBlockCreationConfigurationProviderTest {
@Mock KeyStoreWrapperProvider keyStoreWrapperProvider;

@ -32,15 +32,15 @@ import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture;
import org.apache.tuweni.bytes.Bytes;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
public class PkiQbftBlockHashingTest {
private PkiQbftExtraDataCodec pkiExtraDataCodec = new PkiQbftExtraDataCodec();
private PkiQbftBlockHashing pkiQbftBlockHashing;
@Before
@BeforeEach
public void before() {
pkiExtraDataCodec = spy(new PkiQbftExtraDataCodec());
pkiQbftBlockHashing = new PkiQbftBlockHashing(pkiExtraDataCodec);

@ -35,7 +35,7 @@ import java.util.function.Supplier;
import com.google.common.base.Suppliers;
import org.apache.tuweni.bytes.Bytes;
import org.junit.Test;
import org.junit.jupiter.api.Test;
public class PkiQbftExtraDataCodecTest {

@ -16,7 +16,7 @@ package org.hyperledger.besu.consensus.qbft.protocol;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
import org.junit.jupiter.api.Test;
public class Istanbul100SubProtocolTest {

@ -78,15 +78,18 @@ import java.util.Optional;
import com.google.common.collect.Lists;
import org.apache.tuweni.bytes.Bytes;
import org.assertj.core.api.Assertions;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
@RunWith(MockitoJUnitRunner.class)
@ExtendWith(MockitoExtension.class)
@MockitoSettings(strictness = Strictness.LENIENT)
public class QbftBlockHeightManagerTest {
private final NodeKey nodeKey = NodeKeyUtils.generate();
@ -126,7 +129,7 @@ public class QbftBlockHeightManagerTest {
createdBlock = new Block(header, new BlockBody(emptyList(), emptyList()));
}
@Before
@BeforeEach
public void setup() {
for (int i = 0; i < 3; i++) {
final NodeKey nodeKey = NodeKeyUtils.generate();

@ -57,13 +57,16 @@ import java.util.Collections;
import java.util.List;
import com.google.common.collect.ImmutableList;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
@RunWith(MockitoJUnitRunner.class)
@ExtendWith(MockitoExtension.class)
@MockitoSettings(strictness = Strictness.LENIENT)
public class QbftControllerTest {
private static final BftExtraDataCodec bftExtraDataCodec = new QbftExtraDataCodec();
@ -100,7 +103,7 @@ public class QbftControllerTest {
@Mock private FutureMessageBuffer futureMessageBuffer;
private QbftController qbftController;
@Before
@BeforeEach
public void setup() {
when(blockChain.getChainHeadHeader()).thenReturn(chainHeadBlockHeader);
when(blockChain.getChainHeadBlockNumber()).thenReturn(3L);
@ -111,7 +114,7 @@ public class QbftControllerTest {
when(chainHeadBlockHeader.getHash()).thenReturn(Hash.ZERO);
when(blockHeightManager.getParentBlockHeader()).thenReturn(chainHeadBlockHeader);
when(blockHeightManager.getChainHeight()).thenReturn(4L); // one great than blockchain
when(blockHeightManager.getChainHeight()).thenReturn(4L); // one greater than blockchain
when(nextBlock.getNumber()).thenReturn(5L);

@ -69,15 +69,18 @@ import java.util.List;
import java.util.Optional;
import org.apache.tuweni.bytes.Bytes;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
@RunWith(MockitoJUnitRunner.class)
@ExtendWith(MockitoExtension.class)
@MockitoSettings(strictness = Strictness.LENIENT)
public class QbftRoundTest {
private final NodeKey nodeKey = NodeKeyUtils.generate();
@ -107,7 +110,7 @@ public class QbftRoundTest {
SignatureAlgorithmFactory.getInstance()
.createSignature(BigInteger.ONE, BigInteger.ONE, (byte) 1);
@Before
@BeforeEach
public void setup() {
protocolContext =
new ProtocolContext(

@ -47,13 +47,13 @@ import java.util.stream.Collectors;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.Lists;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;
@RunWith(MockitoJUnitRunner.class)
@ExtendWith(MockitoExtension.class)
public class RoundStateTest {
private static final Supplier<SignatureAlgorithm> SIGNATURE_ALGORITHM =
@ -70,7 +70,7 @@ public class RoundStateTest {
@Mock private Block block;
@Before
@BeforeEach
public void setup() {
for (int i = 0; i < 3; i++) {
final NodeKey newNodeKey = NodeKeyUtils.generate();

@ -22,7 +22,7 @@ import org.hyperledger.besu.consensus.qbft.messagewrappers.Commit;
import org.hyperledger.besu.crypto.SECPSignature;
import org.hyperledger.besu.datatypes.Hash;
import org.junit.Test;
import org.junit.jupiter.api.Test;
public class CommitValidatorTest {

@ -21,7 +21,7 @@ import org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier;
import org.hyperledger.besu.consensus.qbft.messagewrappers.Prepare;
import org.hyperledger.besu.datatypes.Hash;
import org.junit.Test;
import org.junit.jupiter.api.Test;
public class PrepareValidatorTest {

@ -54,13 +54,13 @@ import java.util.List;
import java.util.Optional;
import org.apache.tuweni.bytes.Bytes;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;
@RunWith(MockitoJUnitRunner.class)
@ExtendWith(MockitoExtension.class)
public class ProposalPayloadValidatorTest {
@Mock private BlockValidator blockValidator;
@ -80,7 +80,7 @@ public class ProposalPayloadValidatorTest {
ConsensusRoundHelpers.createFrom(targetRound, 1, 0);
final QbftExtraDataCodec bftExtraDataCodec = new QbftExtraDataCodec();
@Before
@BeforeEach
public void setup() {
protocolContext =
new ProtocolContext(

@ -21,6 +21,7 @@ import static org.hyperledger.besu.consensus.qbft.validation.ValidationTestHelpe
import static org.hyperledger.besu.consensus.qbft.validation.ValidationTestHelpers.createPreparePayloads;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.when;
import org.hyperledger.besu.consensus.common.bft.BftHelpers;
@ -50,13 +51,13 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;
@RunWith(MockitoJUnitRunner.class)
@ExtendWith(MockitoExtension.class)
public class ProposalValidatorTest {
private enum ROUND_ID {
@ -90,7 +91,7 @@ public class ProposalValidatorTest {
private final Map<ROUND_ID, RoundSpecificItems> roundItems = new HashMap<>();
final QbftExtraDataCodec bftExtraDataEncoder = new QbftExtraDataCodec();
@Before
@BeforeEach
public void setup() {
protocolContext =
new ProtocolContext(
@ -152,6 +153,7 @@ public class ProposalValidatorTest {
final RoundSpecificItems roundItem = roundItems.get(ROUND_ID.ZERO);
final Proposal proposal = createProposal(roundItem, emptyList(), emptyList());
reset(blockValidator);
when(blockValidator.validateAndProcessBlock(
eq(protocolContext),
any(),

@ -49,13 +49,13 @@ import java.util.Collections;
import java.util.Optional;
import java.util.stream.Collectors;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;
@RunWith(MockitoJUnitRunner.class)
@ExtendWith(MockitoExtension.class)
public class RoundChangeMessageValidatorTest {
@Mock private RoundChangePayloadValidator payloadValidator;
@ -74,7 +74,7 @@ public class RoundChangeMessageValidatorTest {
ConsensusRoundHelpers.createFrom(targetRound, 0, -1);
private final QbftExtraDataCodec bftExtraDataEncoder = new QbftExtraDataCodec();
@Before
@BeforeEach
public void setup() {
protocolContext =
new ProtocolContext(

@ -27,7 +27,7 @@ import org.hyperledger.besu.datatypes.Hash;
import java.util.Optional;
import org.junit.Test;
import org.junit.jupiter.api.Test;
public class RoundChangePayloadValidatorTest {

@ -43,14 +43,14 @@ import java.util.Optional;
import org.apache.tuweni.bytes.Bytes;
import org.assertj.core.api.SoftAssertions;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;
@RunWith(MockitoJUnitRunner.class)
@ExtendWith(MockitoExtension.class)
public class ForkingValidatorProviderTest {
private static final Address CONTRACT_ADDRESS_1 = Address.fromHexString("0x888");
@ -71,7 +71,7 @@ public class ForkingValidatorProviderTest {
private BlockHeader header2;
private final BlockHeaderTestFixture headerBuilder = new BlockHeaderTestFixture();
@Before
@BeforeEach
public void setup() {
headerBuilder.extraData(Bytes.wrap(new byte[32]));
Block genesisBlock = createEmptyBlock(0, Hash.ZERO);
@ -84,10 +84,6 @@ public class ForkingValidatorProviderTest {
blockChain = createInMemoryBlockchain(genesisBlock);
blockChain.appendBlock(block_1, emptyList());
blockChain.appendBlock(block_2, emptyList());
when(blockValidatorProvider.getValidatorsForBlock(any())).thenReturn(BLOCK_ADDRESSES);
when(contractValidatorProvider.getValidatorsForBlock(header1)).thenReturn(CONTRACT_ADDRESSES_1);
when(contractValidatorProvider.getValidatorsForBlock(header2)).thenReturn(CONTRACT_ADDRESSES_2);
}
private Block createEmptyBlock(final long blockNumber, final Hash parentHash) {
@ -106,6 +102,7 @@ public class ForkingValidatorProviderTest {
when(blockValidatorProvider.getValidatorsAfterBlock(header2)).thenReturn(BLOCK_ADDRESSES);
when(blockValidatorProvider.getValidatorsAfterBlock(header1)).thenReturn(BLOCK_ADDRESSES);
when(blockValidatorProvider.getValidatorsForBlock(any())).thenReturn(BLOCK_ADDRESSES);
assertThat(validatorProvider.getValidatorsAtHead()).isEqualTo(BLOCK_ADDRESSES);
assertThat(validatorProvider.getValidatorsForBlock(header1)).isEqualTo(BLOCK_ADDRESSES);
@ -114,6 +111,9 @@ public class ForkingValidatorProviderTest {
@Test
public void migratesFromBlockToContractValidatorProvider() {
when(blockValidatorProvider.getValidatorsForBlock(any())).thenReturn(BLOCK_ADDRESSES);
when(contractValidatorProvider.getValidatorsForBlock(header1)).thenReturn(CONTRACT_ADDRESSES_1);
final ForksSchedule<QbftConfigOptions> forksSchedule =
new ForksSchedule<>(
List.of(createBlockForkSpec(0), createContractForkSpec(1L, CONTRACT_ADDRESS_1)));
@ -127,6 +127,8 @@ public class ForkingValidatorProviderTest {
@Test
public void migratesFromContractToBlockValidatorProvider() {
when(blockValidatorProvider.getValidatorsForBlock(any())).thenReturn(BLOCK_ADDRESSES);
final ForksSchedule<QbftConfigOptions> forksSchedule =
new ForksSchedule<>(
List.of(createContractForkSpec(0, CONTRACT_ADDRESS_1), createBlockForkSpec(1)));
@ -145,6 +147,10 @@ public class ForkingValidatorProviderTest {
@Test
public void migratesFromContractToContractValidatorProvider() {
when(blockValidatorProvider.getValidatorsForBlock(any())).thenReturn(BLOCK_ADDRESSES);
when(contractValidatorProvider.getValidatorsForBlock(header1)).thenReturn(CONTRACT_ADDRESSES_1);
when(contractValidatorProvider.getValidatorsForBlock(header2)).thenReturn(CONTRACT_ADDRESSES_2);
final ForksSchedule<QbftConfigOptions> forksSchedule =
new ForksSchedule<>(
List.of(

@ -44,7 +44,7 @@ import java.util.stream.Collectors;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.node.TextNode;
import org.junit.Test;
import org.junit.jupiter.api.Test;
public class QbftForksSchedulesFactoryTest
extends BaseForksSchedulesFactoryTest<QbftConfigOptions, MutableQbftConfigOptions> {

@ -39,13 +39,13 @@ import java.util.stream.Collectors;
import com.google.common.collect.Lists;
import org.apache.tuweni.bytes.Bytes;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;
@RunWith(MockitoJUnitRunner.class)
@ExtendWith(MockitoExtension.class)
public class TransactionValidatorProviderTest {
@Mock private ValidatorContractController validatorContractController;
@ -59,7 +59,7 @@ public class TransactionValidatorProviderTest {
private final BlockHeaderTestFixture headerBuilder = new BlockHeaderTestFixture();
private static final Address CONTRACT_ADDRESS = Address.fromHexString("1");
@Before
@BeforeEach
public void setup() {
forksSchedule = new ForksSchedule<>(List.of(createContractForkSpec(0L, CONTRACT_ADDRESS)));
genesisBlock = createEmptyBlock(0, Hash.ZERO);

@ -38,8 +38,8 @@ import java.util.Optional;
import org.apache.tuweni.bytes.Bytes;
import org.assertj.core.api.Assertions;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.web3j.abi.FunctionEncoder;
import org.web3j.abi.TypeReference;
@ -64,7 +64,7 @@ public class ValidatorContractControllerTest {
private final Transaction transaction = Mockito.mock(Transaction.class);
private CallParameter callParameter;
@Before
@BeforeEach
public void setup() {
final Function getValidatorsFunction =
new Function(

@ -32,13 +32,13 @@ import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture;
import java.util.Optional;
import java.util.function.Consumer;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;
@RunWith(MockitoJUnitRunner.class)
@ExtendWith(MockitoExtension.class)
public class ValidatorModeTransitionLoggerTest {
@Mock private ForksSchedule<BftConfigOptions> forksSchedule;

Loading…
Cancel
Save