Migrate BFT tests to junit 5 (#6350)

* bft tests to junit 5
* base class for pki extend AcceptanceTestBaseJunit5
* try/catch in case of empty optionals
* fixed parameterization method

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

---------

Signed-off-by: Sally MacFarlane <macfarla.github@gmail.com>
pull/6362/head
Sally MacFarlane 11 months ago committed by GitHub
parent b1dab0e50a
commit ac81a8f6e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/AcceptanceTestBaseTestWatcher.java
  2. 22
      acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bft/BftAcceptanceTestParameterization.java
  3. 38
      acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bft/BftBlockRewardPaymentAcceptanceTest.java
  4. 15
      acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bft/BftDiscardRpcAcceptanceTest.java
  5. 58
      acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bft/BftMiningAcceptanceTest.java
  6. 15
      acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bft/BftProposalRpcAcceptanceTest.java
  7. 15
      acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bft/BftProposeRpcAcceptanceTest.java
  8. 17
      acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bft/BftZeroValidatorsAcceptanceTest.java
  9. 26
      acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bft/ParameterizedBftTestBase.java
  10. 26
      acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bft/pki/ParameterizedPkiQbftTestBase.java
  11. 29
      acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bft/pki/PkiQbftAcceptanceTest.java
  12. 51
      acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bft/pki/PkiQbftAcceptanceTestParameterization.java

@ -38,6 +38,7 @@ public class AcceptanceTestBaseTestWatcher implements TestWatcher {
public void testSuccessful(final ExtensionContext extensionContext) { public void testSuccessful(final ExtensionContext extensionContext) {
// if so configured, delete logs of successful tests // if so configured, delete logs of successful tests
if (!Boolean.getBoolean("acctests.keepLogsOfPassingTests")) { if (!Boolean.getBoolean("acctests.keepLogsOfPassingTests")) {
try {
// log4j is configured to create a file per test // log4j is configured to create a file per test
// build/acceptanceTestLogs/${ctx:class}.${ctx:test}.log // build/acceptanceTestLogs/${ctx:class}.${ctx:test}.log
String pathname = String pathname =
@ -47,8 +48,11 @@ public class AcceptanceTestBaseTestWatcher implements TestWatcher {
+ extensionContext.getTestMethod().get().getName() + extensionContext.getTestMethod().get().getName()
+ ".log"; + ".log";
LOG.info("Test successful, deleting log at {}", pathname); LOG.info("Test successful, deleting log at {}", pathname);
File file = new File(pathname); final File file = new File(pathname);
file.delete(); file.delete();
} catch (final Exception e) {
LOG.error("could not delete test file", e);
}
} }
} }
} }

@ -17,26 +17,22 @@ package org.hyperledger.besu.tests.acceptance.bft;
import org.hyperledger.besu.tests.acceptance.dsl.node.BesuNode; import org.hyperledger.besu.tests.acceptance.dsl.node.BesuNode;
import org.hyperledger.besu.tests.acceptance.dsl.node.configuration.BesuNodeFactory; import org.hyperledger.besu.tests.acceptance.dsl.node.configuration.BesuNodeFactory;
import java.util.ArrayList; import java.util.stream.Stream;
import java.util.List;
import org.junit.jupiter.params.provider.Arguments;
public class BftAcceptanceTestParameterization { public class BftAcceptanceTestParameterization {
public static List<Object[]> getFactories() { public static Stream<Arguments> getFactories() {
final List<Object[]> ret = new ArrayList<>(); return Stream.of(
ret.addAll( Arguments.of(
List.of(
new Object[] {
"ibft2", "ibft2",
new BftAcceptanceTestParameterization( new BftAcceptanceTestParameterization(
BesuNodeFactory::createIbft2Node, BesuNodeFactory::createIbft2NodeWithValidators) BesuNodeFactory::createIbft2Node, BesuNodeFactory::createIbft2NodeWithValidators)),
}, Arguments.of(
new Object[] {
"qbft", "qbft",
new BftAcceptanceTestParameterization( new BftAcceptanceTestParameterization(
BesuNodeFactory::createQbftNode, BesuNodeFactory::createQbftNodeWithValidators) BesuNodeFactory::createQbftNode, BesuNodeFactory::createQbftNodeWithValidators)));
}));
return ret;
} }
@FunctionalInterface @FunctionalInterface

@ -32,19 +32,18 @@ import java.util.NavigableMap;
import java.util.Optional; import java.util.Optional;
import java.util.TreeMap; import java.util.TreeMap;
import org.junit.Test; import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
public class BftBlockRewardPaymentAcceptanceTest extends ParameterizedBftTestBase { public class BftBlockRewardPaymentAcceptanceTest extends ParameterizedBftTestBase {
private static final Amount BLOCK_REWARD = Amount.wei(new BigInteger("5000000000000000000", 10)); private static final Amount BLOCK_REWARD = Amount.wei(new BigInteger("5000000000000000000", 10));
public BftBlockRewardPaymentAcceptanceTest( @ParameterizedTest(name = "{0} bft node factory type")
final String testName, final BftAcceptanceTestParameterization nodeFactory) { @MethodSource("factoryFunctions")
super(testName, nodeFactory); public void validatorsArePaidBlockReward(
} final String testName, final BftAcceptanceTestParameterization nodeFactory) throws Exception {
setUp(testName, nodeFactory);
@Test
public void validatorsArePaidBlockReward() throws Exception {
final String[] validators = {"validator"}; final String[] validators = {"validator"};
final BesuNode validator = nodeFactory.createNodeWithValidators(besu, "validator", validators); final BesuNode validator = nodeFactory.createNodeWithValidators(besu, "validator", validators);
final BesuNode nonValidator = final BesuNode nonValidator =
@ -61,8 +60,11 @@ public class BftBlockRewardPaymentAcceptanceTest extends ParameterizedBftTestBas
Amount.ether(blockRewardEth * blockToCheck), BigInteger.valueOf(blockToCheck))); Amount.ether(blockRewardEth * blockToCheck), BigInteger.valueOf(blockToCheck)));
} }
@Test @ParameterizedTest(name = "{0} bft node factory type")
public void payBlockRewardToConfiguredNode() throws Exception { @MethodSource("factoryFunctions")
public void payBlockRewardToConfiguredNode(
final String testName, final BftAcceptanceTestParameterization nodeFactory) throws Exception {
setUp(testName, nodeFactory);
final String[] validators = {"validator1"}; final String[] validators = {"validator1"};
final BesuNode validator1 = final BesuNode validator1 =
nodeFactory.createNodeWithValidators(besu, "validator1", validators); nodeFactory.createNodeWithValidators(besu, "validator1", validators);
@ -90,9 +92,11 @@ public class BftBlockRewardPaymentAcceptanceTest extends ParameterizedBftTestBas
Amount.ether(blockRewardEth * blockToCheck), BigInteger.valueOf(blockToCheck))); Amount.ether(blockRewardEth * blockToCheck), BigInteger.valueOf(blockToCheck)));
} }
@Test @ParameterizedTest(name = "{0} bft node factory type")
public void payBlockRewardAccordingToTransitions_defaultInitialMiningBeneficiary() @MethodSource("factoryFunctions")
throws Exception { public void payBlockRewardAccordingToTransitions_defaultInitialMiningBeneficiary(
final String testName, final BftAcceptanceTestParameterization nodeFactory) throws Exception {
setUp(testName, nodeFactory);
final List<Address> addresses = generateAddresses(2); final List<Address> addresses = generateAddresses(2);
final Map<Long, Optional<Address>> transitions = final Map<Long, Optional<Address>> transitions =
Map.of( Map.of(
@ -103,9 +107,11 @@ public class BftBlockRewardPaymentAcceptanceTest extends ParameterizedBftTestBas
testMiningBeneficiaryTransitions(Optional.empty(), transitions); testMiningBeneficiaryTransitions(Optional.empty(), transitions);
} }
@Test @ParameterizedTest(name = "{0} bft node factory type")
public void payBlockRewardAccordingToTransitions_customInitialMiningBeneficiary() @MethodSource("factoryFunctions")
throws Exception { public void payBlockRewardAccordingToTransitions_customInitialMiningBeneficiary(
final String testName, final BftAcceptanceTestParameterization nodeFactory) throws Exception {
setUp(testName, nodeFactory);
final List<Address> addresses = generateAddresses(4); final List<Address> addresses = generateAddresses(4);
final Map<Long, Optional<Address>> transitions = final Map<Long, Optional<Address>> transitions =
Map.of( Map.of(

@ -16,17 +16,16 @@ package org.hyperledger.besu.tests.acceptance.bft;
import org.hyperledger.besu.tests.acceptance.dsl.node.BesuNode; import org.hyperledger.besu.tests.acceptance.dsl.node.BesuNode;
import org.junit.Test; import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
public class BftDiscardRpcAcceptanceTest extends ParameterizedBftTestBase { public class BftDiscardRpcAcceptanceTest extends ParameterizedBftTestBase {
public BftDiscardRpcAcceptanceTest( @ParameterizedTest(name = "{index}: {0}")
final String testName, final BftAcceptanceTestParameterization nodeFactory) { @MethodSource("factoryFunctions")
super(testName, nodeFactory); public void shouldDiscardVotes(
} final String testName, final BftAcceptanceTestParameterization nodeFactory) throws Exception {
setUp(testName, nodeFactory);
@Test
public void shouldDiscardVotes() throws Exception {
final String[] validators = {"validator1", "validator3"}; final String[] validators = {"validator1", "validator3"};
final BesuNode validator1 = final BesuNode validator1 =
nodeFactory.createNodeWithValidators(besu, "validator1", validators); nodeFactory.createNodeWithValidators(besu, "validator1", validators);

@ -28,17 +28,16 @@ import java.util.List;
import java.util.Optional; import java.util.Optional;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
import org.junit.Test; import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
public class BftMiningAcceptanceTest extends ParameterizedBftTestBase { public class BftMiningAcceptanceTest extends ParameterizedBftTestBase {
public BftMiningAcceptanceTest( @ParameterizedTest(name = "{index}: {0}")
final String testName, final BftAcceptanceTestParameterization nodeFactory) { @MethodSource("factoryFunctions")
super(testName, nodeFactory); public void shouldMineOnSingleNodeWithPaidGas_Berlin(
} final String testName, final BftAcceptanceTestParameterization nodeFactory) throws Exception {
setUp(testName, nodeFactory);
@Test
public void shouldMineOnSingleNodeWithPaidGas_Berlin() throws Exception {
final BesuNode minerNode = nodeFactory.createNode(besu, "miner1"); final BesuNode minerNode = nodeFactory.createNode(besu, "miner1");
cluster.start(minerNode); cluster.start(minerNode);
@ -57,8 +56,11 @@ public class BftMiningAcceptanceTest extends ParameterizedBftTestBase {
cluster.verify(receiver.balanceEquals(3)); cluster.verify(receiver.balanceEquals(3));
} }
@Test @ParameterizedTest(name = "{index}: {0}")
public void shouldMineOnSingleNodeWithFreeGas_Berlin() throws Exception { @MethodSource("factoryFunctions")
public void shouldMineOnSingleNodeWithFreeGas_Berlin(
final String testName, final BftAcceptanceTestParameterization nodeFactory) throws Exception {
setUp(testName, nodeFactory);
final BesuNode minerNode = nodeFactory.createNode(besu, "miner1"); final BesuNode minerNode = nodeFactory.createNode(besu, "miner1");
final MiningParameters zeroGasMiningParams = final MiningParameters zeroGasMiningParams =
ImmutableMiningParameters.builder() ImmutableMiningParameters.builder()
@ -90,8 +92,11 @@ public class BftMiningAcceptanceTest extends ParameterizedBftTestBase {
cluster.verify(receiver.balanceEquals(3)); cluster.verify(receiver.balanceEquals(3));
} }
@Test @ParameterizedTest(name = "{index}: {0}")
public void shouldMineOnSingleNodeWithPaidGas_London() throws Exception { @MethodSource("factoryFunctions")
public void shouldMineOnSingleNodeWithPaidGas_London(
final String testName, final BftAcceptanceTestParameterization nodeFactory) throws Exception {
setUp(testName, nodeFactory);
final BesuNode minerNode = nodeFactory.createNode(besu, "miner1"); final BesuNode minerNode = nodeFactory.createNode(besu, "miner1");
updateGenesisConfigToLondon(minerNode, false); updateGenesisConfigToLondon(minerNode, false);
@ -115,8 +120,11 @@ public class BftMiningAcceptanceTest extends ParameterizedBftTestBase {
cluster.verify(receiver.balanceEquals(3)); cluster.verify(receiver.balanceEquals(3));
} }
@Test @ParameterizedTest(name = "{index}: {0}")
public void shouldMineOnSingleNodeWithFreeGas_London() throws Exception { @MethodSource("factoryFunctions")
public void shouldMineOnSingleNodeWithFreeGas_London(
final String testName, final BftAcceptanceTestParameterization nodeFactory) throws Exception {
setUp(testName, nodeFactory);
final BesuNode minerNode = nodeFactory.createNode(besu, "miner1"); final BesuNode minerNode = nodeFactory.createNode(besu, "miner1");
updateGenesisConfigToLondon(minerNode, true); updateGenesisConfigToLondon(minerNode, true);
@ -142,8 +150,11 @@ public class BftMiningAcceptanceTest extends ParameterizedBftTestBase {
cluster.verify(receiver.balanceEquals(3)); cluster.verify(receiver.balanceEquals(3));
} }
@Test @ParameterizedTest(name = "{index}: {0}")
public void shouldMineOnMultipleNodes() throws Exception { @MethodSource("factoryFunctions")
public void shouldMineOnMultipleNodes(
final String testName, final BftAcceptanceTestParameterization nodeFactory) throws Exception {
setUp(testName, nodeFactory);
final BesuNode minerNode1 = nodeFactory.createNode(besu, "miner1"); final BesuNode minerNode1 = nodeFactory.createNode(besu, "miner1");
final BesuNode minerNode2 = nodeFactory.createNode(besu, "miner2"); final BesuNode minerNode2 = nodeFactory.createNode(besu, "miner2");
final BesuNode minerNode3 = nodeFactory.createNode(besu, "miner3"); final BesuNode minerNode3 = nodeFactory.createNode(besu, "miner3");
@ -168,8 +179,11 @@ public class BftMiningAcceptanceTest extends ParameterizedBftTestBase {
cluster.verify(receiver.balanceEquals(6)); cluster.verify(receiver.balanceEquals(6));
} }
@Test @ParameterizedTest(name = "{index}: {0}")
public void shouldMineOnMultipleNodesEvenWhenClusterContainsNonValidator() throws Exception { @MethodSource("factoryFunctions")
public void shouldMineOnMultipleNodesEvenWhenClusterContainsNonValidator(
final String testName, final BftAcceptanceTestParameterization nodeFactory) throws Exception {
setUp(testName, nodeFactory);
final String[] validators = {"validator1", "validator2", "validator3"}; final String[] validators = {"validator1", "validator2", "validator3"};
final BesuNode validator1 = final BesuNode validator1 =
nodeFactory.createNodeWithValidators(besu, "validator1", validators); nodeFactory.createNodeWithValidators(besu, "validator1", validators);
@ -196,9 +210,11 @@ public class BftMiningAcceptanceTest extends ParameterizedBftTestBase {
cluster.verify(receiver.balanceEquals(3)); cluster.verify(receiver.balanceEquals(3));
} }
@Test @ParameterizedTest(name = "{index}: {0}")
public void shouldStillMineWhenANonProposerNodeFailsAndHasSufficientValidators() @MethodSource("factoryFunctions")
throws Exception { public void shouldStillMineWhenANonProposerNodeFailsAndHasSufficientValidators(
final String testName, final BftAcceptanceTestParameterization nodeFactory) throws Exception {
setUp(testName, nodeFactory);
final BesuNode minerNode1 = nodeFactory.createNode(besu, "miner1"); final BesuNode minerNode1 = nodeFactory.createNode(besu, "miner1");
final BesuNode minerNode2 = nodeFactory.createNode(besu, "miner2"); final BesuNode minerNode2 = nodeFactory.createNode(besu, "miner2");
final BesuNode minerNode3 = nodeFactory.createNode(besu, "miner3"); final BesuNode minerNode3 = nodeFactory.createNode(besu, "miner3");

@ -16,17 +16,16 @@ package org.hyperledger.besu.tests.acceptance.bft;
import org.hyperledger.besu.tests.acceptance.dsl.node.BesuNode; import org.hyperledger.besu.tests.acceptance.dsl.node.BesuNode;
import org.junit.Test; import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
public class BftProposalRpcAcceptanceTest extends ParameterizedBftTestBase { public class BftProposalRpcAcceptanceTest extends ParameterizedBftTestBase {
public BftProposalRpcAcceptanceTest( @ParameterizedTest(name = "{index}: {0}")
final String testName, final BftAcceptanceTestParameterization nodeFactory) { @MethodSource("factoryFunctions")
super(testName, nodeFactory); public void shouldReturnProposals(
} final String testName, final BftAcceptanceTestParameterization nodeFactory) throws Exception {
setUp(testName, nodeFactory);
@Test
public void shouldReturnProposals() throws Exception {
final String[] validators = {"validator1", "validator2", "validator3"}; final String[] validators = {"validator1", "validator2", "validator3"};
final BesuNode validator1 = final BesuNode validator1 =
nodeFactory.createNodeWithValidators(besu, "validator1", validators); nodeFactory.createNodeWithValidators(besu, "validator1", validators);

@ -17,19 +17,18 @@ package org.hyperledger.besu.tests.acceptance.bft;
import org.hyperledger.besu.tests.acceptance.dsl.condition.Condition; import org.hyperledger.besu.tests.acceptance.dsl.condition.Condition;
import org.hyperledger.besu.tests.acceptance.dsl.node.BesuNode; import org.hyperledger.besu.tests.acceptance.dsl.node.BesuNode;
import org.junit.Test; import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
// These tests prove the ibft_proposeValidatorVote and ibft_getValidatorsByBlockNumber (implicitly) // These tests prove the ibft_proposeValidatorVote and ibft_getValidatorsByBlockNumber (implicitly)
// JSON RPC calls. // JSON RPC calls.
public class BftProposeRpcAcceptanceTest extends ParameterizedBftTestBase { public class BftProposeRpcAcceptanceTest extends ParameterizedBftTestBase {
public BftProposeRpcAcceptanceTest( @ParameterizedTest(name = "{index}: {0}")
final String testName, final BftAcceptanceTestParameterization nodeFactory) { @MethodSource("factoryFunctions")
super(testName, nodeFactory); public void validatorsCanBeAddedAndThenRemoved(
} final String testName, final BftAcceptanceTestParameterization nodeFactory) throws Exception {
setUp(testName, nodeFactory);
@Test
public void validatorsCanBeAddedAndThenRemoved() throws Exception {
final String[] validators = {"validator1", "validator2", "validator3"}; final String[] validators = {"validator1", "validator2", "validator3"};
final BesuNode validator1 = final BesuNode validator1 =
nodeFactory.createNodeWithValidators(besu, "validator1", validators); nodeFactory.createNodeWithValidators(besu, "validator1", validators);

@ -16,17 +16,16 @@ package org.hyperledger.besu.tests.acceptance.bft;
import org.hyperledger.besu.tests.acceptance.dsl.node.BesuNode; import org.hyperledger.besu.tests.acceptance.dsl.node.BesuNode;
import org.junit.Test; import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
public class BftZeroValidators extends ParameterizedBftTestBase { public class BftZeroValidatorsAcceptanceTest extends ParameterizedBftTestBase {
public BftZeroValidators( @ParameterizedTest(name = "{0} bft node factory type")
final String testName, final BftAcceptanceTestParameterization nodeFactory) { @MethodSource("factoryFunctions")
super(testName, nodeFactory); public void zeroValidatorsFormValidCluster(
} final String testName, final BftAcceptanceTestParameterization nodeFactory) throws Exception {
setUp(testName, nodeFactory);
@Test
public void zeroValidatorsFormValidCluster() throws Exception {
final String[] validators = {}; final String[] validators = {};
final BesuNode node1 = nodeFactory.createNodeWithValidators(besu, "node1", validators); final BesuNode node1 = nodeFactory.createNodeWithValidators(besu, "node1", validators);
final BesuNode node2 = nodeFactory.createNodeWithValidators(besu, "node2", validators); final BesuNode node2 = nodeFactory.createNodeWithValidators(besu, "node2", validators);

@ -14,29 +14,23 @@
*/ */
package org.hyperledger.besu.tests.acceptance.bft; package org.hyperledger.besu.tests.acceptance.bft;
import org.hyperledger.besu.tests.acceptance.dsl.AcceptanceTestBase; import org.hyperledger.besu.tests.acceptance.dsl.AcceptanceTestBaseJunit5;
import java.util.Collection; import java.util.stream.Stream;
import org.junit.Ignore; import org.junit.jupiter.api.Disabled;
import org.junit.runner.RunWith; import org.junit.jupiter.params.provider.Arguments;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
@RunWith(Parameterized.class) @Disabled("This is not a test class, it offers BFT parameterization only.")
@Ignore("This is not a test class, it offers BFT parameterization only.") public abstract class ParameterizedBftTestBase extends AcceptanceTestBaseJunit5 {
public abstract class ParameterizedBftTestBase extends AcceptanceTestBase { protected String bftType;
protected BftAcceptanceTestParameterization nodeFactory;
protected final String bftType; public static Stream<Arguments> factoryFunctions() {
protected final BftAcceptanceTestParameterization nodeFactory;
@Parameters(name = "{0}")
public static Collection<Object[]> factoryFunctions() {
return BftAcceptanceTestParameterization.getFactories(); return BftAcceptanceTestParameterization.getFactories();
} }
protected ParameterizedBftTestBase( protected void setUp(final String bftType, final BftAcceptanceTestParameterization input) {
final String bftType, final BftAcceptanceTestParameterization input) {
this.bftType = bftType; this.bftType = bftType;
this.nodeFactory = input; this.nodeFactory = input;
} }

@ -14,28 +14,16 @@
*/ */
package org.hyperledger.besu.tests.acceptance.bft.pki; package org.hyperledger.besu.tests.acceptance.bft.pki;
import org.hyperledger.besu.tests.acceptance.dsl.AcceptanceTestBase; import org.hyperledger.besu.tests.acceptance.dsl.AcceptanceTestBaseJunit5;
import java.util.Collection; import java.util.stream.Stream;
import org.junit.Ignore; import org.junit.jupiter.api.Disabled;
import org.junit.runner.RunWith; import org.junit.jupiter.params.provider.Arguments;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
@RunWith(Parameterized.class) @Disabled("This is not a test class, it offers PKI QBFT parameterization only.")
@Ignore("This is not a test class, it offers PKI QBFT parameterization only.") public abstract class ParameterizedPkiQbftTestBase extends AcceptanceTestBaseJunit5 {
public abstract class ParameterizedPkiQbftTestBase extends AcceptanceTestBase { public static Stream<Arguments> factoryFunctions() {
protected final PkiQbftAcceptanceTestParameterization nodeFactory;
@Parameters(name = "{0}")
public static Collection<Object[]> factoryFunctions() {
return PkiQbftAcceptanceTestParameterization.getFactories(); return PkiQbftAcceptanceTestParameterization.getFactories();
} }
protected ParameterizedPkiQbftTestBase(
final String testName, final PkiQbftAcceptanceTestParameterization input) {
this.nodeFactory = input;
}
} }

@ -20,17 +20,16 @@ package org.hyperledger.besu.tests.acceptance.bft.pki;
import org.hyperledger.besu.tests.acceptance.dsl.account.Account; import org.hyperledger.besu.tests.acceptance.dsl.account.Account;
import org.hyperledger.besu.tests.acceptance.dsl.node.BesuNode; import org.hyperledger.besu.tests.acceptance.dsl.node.BesuNode;
import org.junit.Test; import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
public class PkiQbftAcceptanceTest extends ParameterizedPkiQbftTestBase { public class PkiQbftAcceptanceTest extends ParameterizedPkiQbftTestBase {
public PkiQbftAcceptanceTest( @ParameterizedTest(name = "{index}: {0}")
final String testName, final PkiQbftAcceptanceTestParameterization input) { @MethodSource("factoryFunctions")
super(testName, input); public void shouldMineOnSingleNode(
} final String testName, final PkiQbftAcceptanceTestParameterization nodeFactory)
throws Exception {
@Test
public void shouldMineOnSingleNode() throws Exception {
final BesuNode minerNode = nodeFactory.createNode(besu, "miner1"); final BesuNode minerNode = nodeFactory.createNode(besu, "miner1");
cluster.start(minerNode); cluster.start(minerNode);
@ -49,8 +48,11 @@ public class PkiQbftAcceptanceTest extends ParameterizedPkiQbftTestBase {
cluster.verify(receiver.balanceEquals(3)); cluster.verify(receiver.balanceEquals(3));
} }
@Test @ParameterizedTest(name = "{index}: {0}")
public void shouldMineOnMultipleNodes() throws Exception { @MethodSource("factoryFunctions")
public void shouldMineOnMultipleNodes(
final String testName, final PkiQbftAcceptanceTestParameterization nodeFactory)
throws Exception {
final BesuNode minerNode1 = nodeFactory.createNode(besu, "miner1"); final BesuNode minerNode1 = nodeFactory.createNode(besu, "miner1");
final BesuNode minerNode2 = nodeFactory.createNode(besu, "miner2"); final BesuNode minerNode2 = nodeFactory.createNode(besu, "miner2");
final BesuNode minerNode3 = nodeFactory.createNode(besu, "miner3"); final BesuNode minerNode3 = nodeFactory.createNode(besu, "miner3");
@ -75,8 +77,11 @@ public class PkiQbftAcceptanceTest extends ParameterizedPkiQbftTestBase {
cluster.verify(receiver.balanceEquals(6)); cluster.verify(receiver.balanceEquals(6));
} }
@Test @ParameterizedTest(name = "{index}: {0}")
public void shouldMineWithIgnoringANodeInCRL() throws Exception { @MethodSource("factoryFunctions")
public void shouldMineWithIgnoringANodeInCRL(
final String testName, final PkiQbftAcceptanceTestParameterization nodeFactory)
throws Exception {
final BesuNode minerNode1 = nodeFactory.createNode(besu, "miner1"); final BesuNode minerNode1 = nodeFactory.createNode(besu, "miner1");
final BesuNode minerNode2 = nodeFactory.createNode(besu, "miner2"); final BesuNode minerNode2 = nodeFactory.createNode(besu, "miner2");
final BesuNode minerNode3 = nodeFactory.createNode(besu, "miner3"); final BesuNode minerNode3 = nodeFactory.createNode(besu, "miner3");

@ -22,73 +22,70 @@ import org.hyperledger.besu.tests.acceptance.dsl.node.configuration.BesuNodeFact
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.Stream;
import org.junit.jupiter.params.provider.Arguments;
public class PkiQbftAcceptanceTestParameterization { public class PkiQbftAcceptanceTestParameterization {
public static List<Object[]> getFactories() { public static Stream<Arguments> getFactories() {
final List<Object[]> ret = new ArrayList<>(); List<Arguments> args = new ArrayList<>();
/* /*
BLOCK CREATION BLOCK CREATION
*/ */
ret.add( args.add(
new Object[] { Arguments.of(
"qbft-pki-jks", "qbft-pki-jks",
new PkiQbftAcceptanceTestParameterization( new PkiQbftAcceptanceTestParameterization(
BesuNodeFactory::createPkiQbftJKSNode, BesuNodeFactory::createPkiQbftJKSNode,
BesuNodeFactory::createPkiQbftJKSNodeWithValidators) BesuNodeFactory::createPkiQbftJKSNodeWithValidators)));
});
ret.add( args.add(
new Object[] { Arguments.of(
"qbft-pki-pkcs12", "qbft-pki-pkcs12",
new PkiQbftAcceptanceTestParameterization( new PkiQbftAcceptanceTestParameterization(
BesuNodeFactory::createPkiQbftPKCS12Node, BesuNodeFactory::createPkiQbftPKCS12Node,
BesuNodeFactory::createPkiQbftPKCS12NodeWithValidators) BesuNodeFactory::createPkiQbftPKCS12NodeWithValidators)));
});
if (Boolean.getBoolean("acctests.runBesuAsProcess")) { if (Boolean.getBoolean("acctests.runBesuAsProcess")) {
ret.add( args.add(
new Object[] { Arguments.of(
"qbft-pki-pkcs11", "qbft-pki-pkcs11",
new PkiQbftAcceptanceTestParameterization( new PkiQbftAcceptanceTestParameterization(
BesuNodeFactory::createPkiQbftPKCS11Node, BesuNodeFactory::createPkiQbftPKCS11Node,
BesuNodeFactory::createPkiQbftPKCS11NodeWithValidators) BesuNodeFactory::createPkiQbftPKCS11NodeWithValidators)));
});
} }
/* /*
TLS TLS
*/ */
ret.add( args.add(
new Object[] { Arguments.of(
"qbft-tls-jks", "qbft-tls-jks",
new PkiQbftAcceptanceTestParameterization( new PkiQbftAcceptanceTestParameterization(
BesuNodeFactory::createQbftNodeWithTLSJKS, BesuNodeFactory::createQbftNodeWithTLSJKS,
BesuNodeFactory::createQbftTLSJKSNodeWithValidators) BesuNodeFactory::createQbftTLSJKSNodeWithValidators)));
});
ret.add( args.add(
new Object[] { Arguments.of(
"qbft-tls-pkcs12", "qbft-tls-pkcs12",
new PkiQbftAcceptanceTestParameterization( new PkiQbftAcceptanceTestParameterization(
BesuNodeFactory::createQbftNodeWithTLSPKCS12, BesuNodeFactory::createQbftNodeWithTLSPKCS12,
BesuNodeFactory::createQbftTLSPKCS12NodeWithValidators) BesuNodeFactory::createQbftTLSPKCS12NodeWithValidators)));
});
if (Boolean.getBoolean("acctests.runBesuAsProcess")) { if (Boolean.getBoolean("acctests.runBesuAsProcess")) {
ret.add( args.add(
new Object[] { Arguments.of(
"qbft-tls-pkcs11", "qbft-tls-pkcs11",
new PkiQbftAcceptanceTestParameterization( new PkiQbftAcceptanceTestParameterization(
BesuNodeFactory::createQbftNodeWithTLSPKCS11, BesuNodeFactory::createQbftNodeWithTLSPKCS11,
BesuNodeFactory::createQbftTLSPKCS11NodeWithValidators) BesuNodeFactory::createQbftTLSPKCS11NodeWithValidators)));
});
} }
return ret; return args.stream();
} }
@FunctionalInterface @FunctionalInterface

Loading…
Cancel
Save