From 327ba1e977561a313100b5d48216607a69f552a1 Mon Sep 17 00:00:00 2001 From: Trent Mohay Date: Tue, 9 Feb 2021 12:46:00 +1100 Subject: [PATCH] Allow BFT tests to be parameterized (#1877) Signed-off-by: Trent Mohay --- .../acceptance/dsl/AcceptanceTestBase.java | 12 +- .../AwaitValidatorSetChange.java | 13 +- .../BftConditions.java} | 28 ++-- .../{ibft2 => bft}/ExpectProposals.java | 13 +- .../{ibft2 => bft}/ExpectValidators.java | 14 +- .../tests/acceptance/dsl/node/BesuNode.java | 12 +- .../dsl/transaction/NodeRequests.java | 12 +- .../Ibft2Discard.java => bft/BftDiscard.java} | 8 +- .../BftGetValidators.java} | 10 +- .../BftGetValidatorsAtHash.java} | 9 +- .../BftProposals.java} | 7 +- .../Ibft2Propose.java => bft/BftPropose.java} | 8 +- .../BftRequestFactory.java} | 26 ++-- .../BftTransactions.java} | 28 ++-- .../dsl/transaction/bft/ConsensusType.java | 30 +++++ .../BftAcceptanceTestParameterization.java | 66 ++++++++++ .../BftMiningAcceptanceTest.java} | 53 ++++---- .../bft/ParameterizedBftTestBase.java | 41 ++++++ .../ibft2/Ibft2DiscardRpcAcceptanceTest.java | 14 +- .../ibft2/Ibft2ProposalRpcAcceptanceTest.java | 14 +- .../ibft2/Ibft2ProposeRpcAcceptanceTest.java | 20 +-- .../qbft/QbftMiningAcceptanceTest.java | 120 ------------------ 22 files changed, 300 insertions(+), 258 deletions(-) rename acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/{ibft2 => bft}/AwaitValidatorSetChange.java (78%) rename acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/{ibft2/Ibft2Conditions.java => bft/BftConditions.java} (76%) rename acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/{ibft2 => bft}/ExpectProposals.java (72%) rename acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/{ibft2 => bft}/ExpectValidators.java (73%) rename acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/{ibft2/Ibft2Discard.java => bft/BftDiscard.java} (81%) rename acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/{ibft2/Ibft2GetValidators.java => bft/BftGetValidators.java} (80%) rename acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/{ibft2/Ibft2GetValidatorsAtHash.java => bft/BftGetValidatorsAtHash.java} (80%) rename acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/{ibft2/Ibft2Proposals.java => bft/BftProposals.java} (79%) rename acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/{ibft2/Ibft2Propose.java => bft/BftPropose.java} (80%) rename acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/{ibft2/Ibft2RequestFactory.java => bft/BftRequestFactory.java} (73%) rename acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/{ibft2/Ibft2Transactions.java => bft/BftTransactions.java} (53%) create mode 100644 acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/bft/ConsensusType.java create mode 100644 acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bft/BftAcceptanceTestParameterization.java rename acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/{ibft2/Ibft2MiningAcceptanceTest.java => bft/BftMiningAcceptanceTest.java} (68%) create mode 100644 acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bft/ParameterizedBftTestBase.java delete mode 100644 acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/qbft/QbftMiningAcceptanceTest.java diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/AcceptanceTestBase.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/AcceptanceTestBase.java index 83ea3eecce..f79856d0fc 100644 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/AcceptanceTestBase.java +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/AcceptanceTestBase.java @@ -20,9 +20,9 @@ import static org.assertj.core.api.Assertions.assertThat; import org.hyperledger.besu.tests.acceptance.dsl.account.Accounts; import org.hyperledger.besu.tests.acceptance.dsl.blockchain.Blockchain; import org.hyperledger.besu.tests.acceptance.dsl.condition.admin.AdminConditions; +import org.hyperledger.besu.tests.acceptance.dsl.condition.bft.BftConditions; import org.hyperledger.besu.tests.acceptance.dsl.condition.clique.CliqueConditions; import org.hyperledger.besu.tests.acceptance.dsl.condition.eth.EthConditions; -import org.hyperledger.besu.tests.acceptance.dsl.condition.ibft2.Ibft2Conditions; import org.hyperledger.besu.tests.acceptance.dsl.condition.login.LoginConditions; import org.hyperledger.besu.tests.acceptance.dsl.condition.net.NetConditions; import org.hyperledger.besu.tests.acceptance.dsl.condition.perm.PermissioningConditions; @@ -37,10 +37,10 @@ import org.hyperledger.besu.tests.acceptance.dsl.node.configuration.BesuNodeFact import org.hyperledger.besu.tests.acceptance.dsl.node.configuration.permissioning.PermissionedNodeBuilder; import org.hyperledger.besu.tests.acceptance.dsl.transaction.account.AccountTransactions; import org.hyperledger.besu.tests.acceptance.dsl.transaction.admin.AdminTransactions; +import org.hyperledger.besu.tests.acceptance.dsl.transaction.bft.BftTransactions; import org.hyperledger.besu.tests.acceptance.dsl.transaction.clique.CliqueTransactions; import org.hyperledger.besu.tests.acceptance.dsl.transaction.contract.ContractTransactions; import org.hyperledger.besu.tests.acceptance.dsl.transaction.eth.EthTransactions; -import org.hyperledger.besu.tests.acceptance.dsl.transaction.ibft2.Ibft2Transactions; import org.hyperledger.besu.tests.acceptance.dsl.transaction.miner.MinerTransactions; import org.hyperledger.besu.tests.acceptance.dsl.transaction.net.NetTransactions; import org.hyperledger.besu.tests.acceptance.dsl.transaction.perm.PermissioningTransactions; @@ -82,8 +82,8 @@ public class AcceptanceTestBase { protected final ContractTransactions contractTransactions; protected final EthConditions eth; protected final EthTransactions ethTransactions; - protected final Ibft2Transactions ibftTwoTransactions; - protected final Ibft2Conditions ibftTwo; + protected final BftTransactions bftTransactions; + protected final BftConditions bft; protected final LoginConditions login; protected final NetConditions net; protected final BesuNodeFactory besu; @@ -105,7 +105,7 @@ public class AcceptanceTestBase { accounts = new Accounts(ethTransactions); adminTransactions = new AdminTransactions(); cliqueTransactions = new CliqueTransactions(); - ibftTwoTransactions = new Ibft2Transactions(); + bftTransactions = new BftTransactions(); accountTransactions = new AccountTransactions(accounts); permissioningTransactions = new PermissioningTransactions(); privacyTransactions = new PrivacyTransactions(); @@ -115,7 +115,7 @@ public class AcceptanceTestBase { blockchain = new Blockchain(ethTransactions); clique = new CliqueConditions(ethTransactions, cliqueTransactions); eth = new EthConditions(ethTransactions); - ibftTwo = new Ibft2Conditions(ibftTwoTransactions); + bft = new BftConditions(bftTransactions); login = new LoginConditions(); net = new NetConditions(new NetTransactions()); cluster = new Cluster(net); diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/ibft2/AwaitValidatorSetChange.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/bft/AwaitValidatorSetChange.java similarity index 78% rename from acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/ibft2/AwaitValidatorSetChange.java rename to acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/bft/AwaitValidatorSetChange.java index 816c3f9851..e794ebe199 100644 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/ibft2/AwaitValidatorSetChange.java +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/bft/AwaitValidatorSetChange.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.tests.acceptance.dsl.condition.ibft2; +package org.hyperledger.besu.tests.acceptance.dsl.condition.bft; import static org.assertj.core.api.Assertions.assertThat; import static org.hyperledger.besu.tests.acceptance.dsl.transaction.clique.CliqueTransactions.LATEST; @@ -21,18 +21,18 @@ import org.hyperledger.besu.ethereum.core.Address; import org.hyperledger.besu.tests.acceptance.dsl.WaitUtils; import org.hyperledger.besu.tests.acceptance.dsl.condition.Condition; import org.hyperledger.besu.tests.acceptance.dsl.node.Node; -import org.hyperledger.besu.tests.acceptance.dsl.transaction.ibft2.Ibft2Transactions; +import org.hyperledger.besu.tests.acceptance.dsl.transaction.bft.BftTransactions; import java.util.List; public class AwaitValidatorSetChange implements Condition { - private final Ibft2Transactions ibft; + private final BftTransactions bft; private final List
initialSigners; - public AwaitValidatorSetChange(final List
initialSigners, final Ibft2Transactions ibft) { + public AwaitValidatorSetChange(final List
initialSigners, final BftTransactions bft) { this.initialSigners = initialSigners; - this.ibft = ibft; + this.bft = bft; } @Override @@ -40,7 +40,6 @@ public class AwaitValidatorSetChange implements Condition { WaitUtils.waitFor( 60, () -> - assertThat(node.execute(ibft.createGetValidators(LATEST))) - .isNotEqualTo(initialSigners)); + assertThat(node.execute(bft.createGetValidators(LATEST))).isNotEqualTo(initialSigners)); } } diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/ibft2/Ibft2Conditions.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/bft/BftConditions.java similarity index 76% rename from acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/ibft2/Ibft2Conditions.java rename to acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/bft/BftConditions.java index 583d90b74a..c59a364173 100644 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/ibft2/Ibft2Conditions.java +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/bft/BftConditions.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.tests.acceptance.dsl.condition.ibft2; +package org.hyperledger.besu.tests.acceptance.dsl.condition.bft; import static org.hyperledger.besu.tests.acceptance.dsl.transaction.clique.CliqueTransactions.LATEST; @@ -20,7 +20,7 @@ import org.hyperledger.besu.ethereum.core.Address; 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.Node; -import org.hyperledger.besu.tests.acceptance.dsl.transaction.ibft2.Ibft2Transactions; +import org.hyperledger.besu.tests.acceptance.dsl.transaction.bft.BftTransactions; import java.util.Arrays; import java.util.Comparator; @@ -31,12 +31,12 @@ import java.util.stream.Collectors; import com.google.common.collect.ImmutableMap; -public class Ibft2Conditions { +public class BftConditions { - private final Ibft2Transactions ibftTwo; + private final BftTransactions bft; - public Ibft2Conditions(final Ibft2Transactions ibftTwo) { - this.ibftTwo = ibftTwo; + public BftConditions(final BftTransactions bft) { + this.bft = bft; } public List validators(final BesuNode[] nodes) { @@ -47,7 +47,7 @@ public class Ibft2Conditions { } public ExpectValidators validatorsEqual(final BesuNode... validators) { - return new ExpectValidators(ibftTwo, validatorAddresses(validators)); + return new ExpectValidators(bft, validatorAddresses(validators)); } private Address[] validatorAddresses(final BesuNode[] validators) { @@ -55,23 +55,23 @@ public class Ibft2Conditions { } public Condition awaitValidatorSetChange(final Node node) { - return new AwaitValidatorSetChange(node.execute(ibftTwo.createGetValidators(LATEST)), ibftTwo); + return new AwaitValidatorSetChange(node.execute(bft.createGetValidators(LATEST)), bft); } public Condition noProposals() { - return new ExpectProposals(ibftTwo, ImmutableMap.of()); + return new ExpectProposals(bft, ImmutableMap.of()); } public PendingVotesConfig pendingVotesEqual() { - return new PendingVotesConfig(ibftTwo); + return new PendingVotesConfig(bft); } public static class PendingVotesConfig { private final Map proposals = new HashMap<>(); - private final Ibft2Transactions ibft; + private final BftTransactions bft; - private PendingVotesConfig(final Ibft2Transactions ibft) { - this.ibft = ibft; + private PendingVotesConfig(final BftTransactions bft) { + this.bft = bft; } public PendingVotesConfig addProposal(final BesuNode node) { @@ -88,7 +88,7 @@ public class Ibft2Conditions { final Map proposalsAsAddress = this.proposals.entrySet().stream() .collect(Collectors.toMap(p -> p.getKey().getAddress(), Map.Entry::getValue)); - return new ExpectProposals(ibft, proposalsAsAddress); + return new ExpectProposals(bft, proposalsAsAddress); } } } diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/ibft2/ExpectProposals.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/bft/ExpectProposals.java similarity index 72% rename from acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/ibft2/ExpectProposals.java rename to acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/bft/ExpectProposals.java index f39ec6f9eb..970aa4216d 100644 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/ibft2/ExpectProposals.java +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/bft/ExpectProposals.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.tests.acceptance.dsl.condition.ibft2; +package org.hyperledger.besu.tests.acceptance.dsl.condition.bft; import static org.assertj.core.api.Assertions.assertThat; @@ -20,22 +20,21 @@ import org.hyperledger.besu.ethereum.core.Address; import org.hyperledger.besu.tests.acceptance.dsl.WaitUtils; import org.hyperledger.besu.tests.acceptance.dsl.condition.Condition; import org.hyperledger.besu.tests.acceptance.dsl.node.Node; -import org.hyperledger.besu.tests.acceptance.dsl.transaction.ibft2.Ibft2Transactions; +import org.hyperledger.besu.tests.acceptance.dsl.transaction.bft.BftTransactions; import java.util.Map; public class ExpectProposals implements Condition { - private final Ibft2Transactions ibftTwo; + private final BftTransactions bft; private final Map proposers; - public ExpectProposals(final Ibft2Transactions ibftTwo, final Map proposers) { - this.ibftTwo = ibftTwo; + public ExpectProposals(final BftTransactions bft, final Map proposers) { + this.bft = bft; this.proposers = proposers; } @Override public void verify(final Node node) { - WaitUtils.waitFor( - () -> assertThat(node.execute(ibftTwo.createProposals())).isEqualTo(proposers)); + WaitUtils.waitFor(() -> assertThat(node.execute(bft.createProposals())).isEqualTo(proposers)); } } diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/ibft2/ExpectValidators.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/bft/ExpectValidators.java similarity index 73% rename from acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/ibft2/ExpectValidators.java rename to acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/bft/ExpectValidators.java index e4a0e7c872..09c1c628d1 100644 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/ibft2/ExpectValidators.java +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/bft/ExpectValidators.java @@ -12,23 +12,23 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.tests.acceptance.dsl.condition.ibft2; +package org.hyperledger.besu.tests.acceptance.dsl.condition.bft; import static org.assertj.core.api.Assertions.assertThat; -import static org.hyperledger.besu.tests.acceptance.dsl.transaction.ibft2.Ibft2Transactions.LATEST; +import static org.hyperledger.besu.tests.acceptance.dsl.transaction.bft.BftTransactions.LATEST; import org.hyperledger.besu.ethereum.core.Address; import org.hyperledger.besu.tests.acceptance.dsl.WaitUtils; import org.hyperledger.besu.tests.acceptance.dsl.condition.Condition; import org.hyperledger.besu.tests.acceptance.dsl.node.Node; -import org.hyperledger.besu.tests.acceptance.dsl.transaction.ibft2.Ibft2Transactions; +import org.hyperledger.besu.tests.acceptance.dsl.transaction.bft.BftTransactions; public class ExpectValidators implements Condition { - private final Ibft2Transactions ibft; + private final BftTransactions bft; private final Address[] validators; - public ExpectValidators(final Ibft2Transactions ibft, final Address... validators) { - this.ibft = ibft; + public ExpectValidators(final BftTransactions bft, final Address... validators) { + this.bft = bft; this.validators = validators; } @@ -36,6 +36,6 @@ public class ExpectValidators implements Condition { public void verify(final Node node) { WaitUtils.waitFor( () -> - assertThat(node.execute(ibft.createGetValidators(LATEST))).containsExactly(validators)); + assertThat(node.execute(bft.createGetValidators(LATEST))).containsExactly(validators)); } } diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/BesuNode.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/BesuNode.java index 5ea854b3fa..49f39505e1 100644 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/BesuNode.java +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/BesuNode.java @@ -35,8 +35,9 @@ import org.hyperledger.besu.tests.acceptance.dsl.node.configuration.genesis.Gene import org.hyperledger.besu.tests.acceptance.dsl.transaction.NodeRequests; import org.hyperledger.besu.tests.acceptance.dsl.transaction.Transaction; import org.hyperledger.besu.tests.acceptance.dsl.transaction.admin.AdminRequestFactory; +import org.hyperledger.besu.tests.acceptance.dsl.transaction.bft.BftRequestFactory; +import org.hyperledger.besu.tests.acceptance.dsl.transaction.bft.ConsensusType; import org.hyperledger.besu.tests.acceptance.dsl.transaction.clique.CliqueRequestFactory; -import org.hyperledger.besu.tests.acceptance.dsl.transaction.ibft2.Ibft2RequestFactory; import org.hyperledger.besu.tests.acceptance.dsl.transaction.login.LoginRequestFactory; import org.hyperledger.besu.tests.acceptance.dsl.transaction.miner.MinerRequestFactory; import org.hyperledger.besu.tests.acceptance.dsl.transaction.net.CustomRequestFactory; @@ -339,11 +340,18 @@ public class BesuNode implements NodeConfiguration, RunnableNode, AutoCloseable } } + final ConsensusType bftType = + getGenesisConfig() + .map( + gc -> + gc.toLowerCase().contains("ibft") ? ConsensusType.IBFT2 : ConsensusType.QBFT) + .orElse(ConsensusType.IBFT2); + nodeRequests = new NodeRequests( new JsonRpc2_0Web3j(web3jService, 2000, Async.defaultExecutorService()), new CliqueRequestFactory(web3jService), - new Ibft2RequestFactory(web3jService), + new BftRequestFactory(web3jService, bftType), new PermissioningJsonRpcRequestFactory(web3jService), new AdminRequestFactory(web3jService), new PrivacyRequestFactory(web3jService), diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/NodeRequests.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/NodeRequests.java index 46cdf61bd0..4741e397dd 100644 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/NodeRequests.java +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/NodeRequests.java @@ -15,8 +15,8 @@ package org.hyperledger.besu.tests.acceptance.dsl.transaction; import org.hyperledger.besu.tests.acceptance.dsl.transaction.admin.AdminRequestFactory; +import org.hyperledger.besu.tests.acceptance.dsl.transaction.bft.BftRequestFactory; import org.hyperledger.besu.tests.acceptance.dsl.transaction.clique.CliqueRequestFactory; -import org.hyperledger.besu.tests.acceptance.dsl.transaction.ibft2.Ibft2RequestFactory; import org.hyperledger.besu.tests.acceptance.dsl.transaction.login.LoginRequestFactory; import org.hyperledger.besu.tests.acceptance.dsl.transaction.miner.MinerRequestFactory; import org.hyperledger.besu.tests.acceptance.dsl.transaction.net.CustomRequestFactory; @@ -33,7 +33,7 @@ public class NodeRequests { private final Web3j netEth; private final CliqueRequestFactory clique; - private final Ibft2RequestFactory ibft; + private final BftRequestFactory bft; private final PermissioningJsonRpcRequestFactory perm; private final AdminRequestFactory admin; private final PrivacyRequestFactory privacy; @@ -46,7 +46,7 @@ public class NodeRequests { public NodeRequests( final Web3j netEth, final CliqueRequestFactory clique, - final Ibft2RequestFactory ibft, + final BftRequestFactory bft, final PermissioningJsonRpcRequestFactory perm, final AdminRequestFactory admin, final PrivacyRequestFactory privacy, @@ -57,7 +57,7 @@ public class NodeRequests { final LoginRequestFactory login) { this.netEth = netEth; this.clique = clique; - this.ibft = ibft; + this.bft = bft; this.perm = perm; this.admin = admin; this.privacy = privacy; @@ -80,8 +80,8 @@ public class NodeRequests { return clique; } - public Ibft2RequestFactory ibft() { - return ibft; + public BftRequestFactory bft() { + return bft; } public PermissioningJsonRpcRequestFactory perm() { diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/ibft2/Ibft2Discard.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/bft/BftDiscard.java similarity index 81% rename from acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/ibft2/Ibft2Discard.java rename to acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/bft/BftDiscard.java index f6d1bcf299..bbf8a754fe 100644 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/ibft2/Ibft2Discard.java +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/bft/BftDiscard.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.tests.acceptance.dsl.transaction.ibft2; +package org.hyperledger.besu.tests.acceptance.dsl.transaction.bft; import static org.assertj.core.api.Assertions.assertThat; @@ -21,17 +21,17 @@ import org.hyperledger.besu.tests.acceptance.dsl.transaction.Transaction; import java.io.IOException; -public class Ibft2Discard implements Transaction { +public class BftDiscard implements Transaction { private final String address; - public Ibft2Discard(final String address) { + public BftDiscard(final String address) { this.address = address; } @Override public Boolean execute(final NodeRequests node) { try { - final Ibft2RequestFactory.DiscardResponse result = node.ibft().discard(address).send(); + final BftRequestFactory.DiscardResponse result = node.bft().discard(address).send(); assertThat(result).isNotNull(); assertThat(result.hasError()).isFalse(); return result.getResult(); diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/ibft2/Ibft2GetValidators.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/bft/BftGetValidators.java similarity index 80% rename from acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/ibft2/Ibft2GetValidators.java rename to acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/bft/BftGetValidators.java index c760866c49..e852954558 100644 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/ibft2/Ibft2GetValidators.java +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/bft/BftGetValidators.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.tests.acceptance.dsl.transaction.ibft2; +package org.hyperledger.besu.tests.acceptance.dsl.transaction.bft; import static org.assertj.core.api.Assertions.assertThat; @@ -23,18 +23,18 @@ import org.hyperledger.besu.tests.acceptance.dsl.transaction.Transaction; import java.io.IOException; import java.util.List; -public class Ibft2GetValidators implements Transaction> { +public class BftGetValidators implements Transaction> { private final String blockNumber; - public Ibft2GetValidators(final String blockNumber) { + public BftGetValidators(final String blockNumber) { this.blockNumber = blockNumber; } @Override public List
execute(final NodeRequests node) { try { - final Ibft2RequestFactory.SignersBlockResponse result = - node.ibft().validatorsAtBlock(blockNumber).send(); + final BftRequestFactory.SignersBlockResponse result = + node.bft().validatorsAtBlock(blockNumber).send(); assertThat(result).isNotNull(); assertThat(result.hasError()).isFalse(); return result.getResult(); diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/ibft2/Ibft2GetValidatorsAtHash.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/bft/BftGetValidatorsAtHash.java similarity index 80% rename from acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/ibft2/Ibft2GetValidatorsAtHash.java rename to acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/bft/BftGetValidatorsAtHash.java index 72e18dbdf1..6aa25ca6a4 100644 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/ibft2/Ibft2GetValidatorsAtHash.java +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/bft/BftGetValidatorsAtHash.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.tests.acceptance.dsl.transaction.ibft2; +package org.hyperledger.besu.tests.acceptance.dsl.transaction.bft; import static org.assertj.core.api.Assertions.assertThat; @@ -24,19 +24,18 @@ import org.hyperledger.besu.tests.acceptance.dsl.transaction.Transaction; import java.io.IOException; import java.util.List; -public class Ibft2GetValidatorsAtHash implements Transaction> { +public class BftGetValidatorsAtHash implements Transaction> { private final Hash hash; - public Ibft2GetValidatorsAtHash(final Hash hash) { + public BftGetValidatorsAtHash(final Hash hash) { this.hash = hash; } @Override public List
execute(final NodeRequests node) { try { - final Ibft2RequestFactory.SignersBlockResponse result = - node.ibft().signersAtHash(hash).send(); + final BftRequestFactory.SignersBlockResponse result = node.bft().signersAtHash(hash).send(); assertThat(result).isNotNull(); assertThat(result.hasError()).isFalse(); return result.getResult(); diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/ibft2/Ibft2Proposals.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/bft/BftProposals.java similarity index 79% rename from acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/ibft2/Ibft2Proposals.java rename to acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/bft/BftProposals.java index 86d596c73c..616798fbf7 100644 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/ibft2/Ibft2Proposals.java +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/bft/BftProposals.java @@ -12,23 +12,24 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.tests.acceptance.dsl.transaction.ibft2; +package org.hyperledger.besu.tests.acceptance.dsl.transaction.bft; import static org.assertj.core.api.Assertions.assertThat; import org.hyperledger.besu.ethereum.core.Address; import org.hyperledger.besu.tests.acceptance.dsl.transaction.NodeRequests; import org.hyperledger.besu.tests.acceptance.dsl.transaction.Transaction; +import org.hyperledger.besu.tests.acceptance.dsl.transaction.bft.BftRequestFactory.ProposalsResponse; import java.io.IOException; import java.util.Map; -public class Ibft2Proposals implements Transaction> { +public class BftProposals implements Transaction> { @Override public Map execute(final NodeRequests node) { try { - final Ibft2RequestFactory.ProposalsResponse result = node.ibft().proposals().send(); + final ProposalsResponse result = node.bft().proposals().send(); assertThat(result).isNotNull(); assertThat(result.hasError()).isFalse(); return result.getResult(); diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/ibft2/Ibft2Propose.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/bft/BftPropose.java similarity index 80% rename from acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/ibft2/Ibft2Propose.java rename to acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/bft/BftPropose.java index fad32a47c1..361d200e56 100644 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/ibft2/Ibft2Propose.java +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/bft/BftPropose.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.tests.acceptance.dsl.transaction.ibft2; +package org.hyperledger.besu.tests.acceptance.dsl.transaction.bft; import static org.assertj.core.api.Assertions.assertThat; @@ -21,11 +21,11 @@ import org.hyperledger.besu.tests.acceptance.dsl.transaction.Transaction; import java.io.IOException; -public class Ibft2Propose implements Transaction { +public class BftPropose implements Transaction { private final String address; private final boolean auth; - public Ibft2Propose(final String address, final boolean auth) { + public BftPropose(final String address, final boolean auth) { this.address = address; this.auth = auth; } @@ -33,7 +33,7 @@ public class Ibft2Propose implements Transaction { @Override public Boolean execute(final NodeRequests node) { try { - final Ibft2RequestFactory.ProposeResponse result = node.ibft().propose(address, auth).send(); + final BftRequestFactory.ProposeResponse result = node.bft().propose(address, auth).send(); assertThat(result).isNotNull(); assertThat(result.hasError()).isFalse(); return result.getResult(); diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/ibft2/Ibft2RequestFactory.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/bft/BftRequestFactory.java similarity index 73% rename from acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/ibft2/Ibft2RequestFactory.java rename to acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/bft/BftRequestFactory.java index ac1de61844..fe6d2f7785 100644 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/ibft2/Ibft2RequestFactory.java +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/bft/BftRequestFactory.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.tests.acceptance.dsl.transaction.ibft2; +package org.hyperledger.besu.tests.acceptance.dsl.transaction.bft; import static java.util.Collections.emptyList; import static java.util.Collections.singletonList; @@ -28,7 +28,7 @@ import org.web3j.protocol.Web3jService; import org.web3j.protocol.core.Request; import org.web3j.protocol.core.Response; -public class Ibft2RequestFactory { +public class BftRequestFactory { public static class ProposeResponse extends Response {} @@ -40,13 +40,20 @@ public class Ibft2RequestFactory { private final Web3jService web3jService; - public Ibft2RequestFactory(final Web3jService web3jService) { + private final ConsensusType bftType; + + public BftRequestFactory(final Web3jService web3jService) { + this(web3jService, ConsensusType.IBFT2); + } + + public BftRequestFactory(final Web3jService web3jService, final ConsensusType bftType) { this.web3jService = web3jService; + this.bftType = bftType; } Request propose(final String address, final Boolean auth) { return new Request<>( - "ibft_proposeValidatorVote", + bftType.getName() + "_proposeValidatorVote", Arrays.asList(address, auth.toString()), web3jService, ProposeResponse.class); @@ -54,17 +61,20 @@ public class Ibft2RequestFactory { Request discard(final String address) { return new Request<>( - "ibft_discardValidatorVote", singletonList(address), web3jService, DiscardResponse.class); + bftType.getName() + "_discardValidatorVote", + singletonList(address), + web3jService, + DiscardResponse.class); } Request proposals() { return new Request<>( - "ibft_getPendingVotes", emptyList(), web3jService, ProposalsResponse.class); + bftType.getName() + "_getPendingVotes", emptyList(), web3jService, ProposalsResponse.class); } Request validatorsAtBlock(final String blockNumber) { return new Request<>( - "ibft_getValidatorsByBlockNumber", + bftType.getName() + "_getValidatorsByBlockNumber", singletonList(blockNumber), web3jService, SignersBlockResponse.class); @@ -72,7 +82,7 @@ public class Ibft2RequestFactory { Request signersAtHash(final Hash hash) { return new Request<>( - "ibft_getValidatorsByBlockHash", + bftType.getName() + "_getValidatorsByBlockHash", singletonList(hash.toString()), web3jService, SignersBlockResponse.class); diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/ibft2/Ibft2Transactions.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/bft/BftTransactions.java similarity index 53% rename from acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/ibft2/Ibft2Transactions.java rename to acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/bft/BftTransactions.java index 7913c7e8d4..9974ad4b4e 100644 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/ibft2/Ibft2Transactions.java +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/bft/BftTransactions.java @@ -12,39 +12,39 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.tests.acceptance.dsl.transaction.ibft2; +package org.hyperledger.besu.tests.acceptance.dsl.transaction.bft; import org.hyperledger.besu.ethereum.core.Hash; import org.hyperledger.besu.tests.acceptance.dsl.node.BesuNode; -public class Ibft2Transactions { +public class BftTransactions { public static final String LATEST = "latest"; - public Ibft2Propose createRemoveProposal(final BesuNode node) { + public BftPropose createRemoveProposal(final BesuNode node) { return propose(node.getAddress().toString(), false); } - public Ibft2Propose createAddProposal(final BesuNode node) { + public BftPropose createAddProposal(final BesuNode node) { return propose(node.getAddress().toString(), true); } - public Ibft2Proposals createProposals() { - return new Ibft2Proposals(); + public BftProposals createProposals() { + return new BftProposals(); } - public Ibft2GetValidators createGetValidators(final String blockNumber) { - return new Ibft2GetValidators(blockNumber); + public BftGetValidators createGetValidators(final String blockNumber) { + return new BftGetValidators(blockNumber); } - public Ibft2GetValidatorsAtHash createGetValidatorsAtHash(final Hash blockHash) { - return new Ibft2GetValidatorsAtHash(blockHash); + public BftGetValidatorsAtHash createGetValidatorsAtHash(final Hash blockHash) { + return new BftGetValidatorsAtHash(blockHash); } - public Ibft2Discard createDiscardProposal(final BesuNode node) { - return new Ibft2Discard(node.getAddress().toString()); + public BftDiscard createDiscardProposal(final BesuNode node) { + return new BftDiscard(node.getAddress().toString()); } - private Ibft2Propose propose(final String address, final boolean auth) { - return new Ibft2Propose(address, auth); + private BftPropose propose(final String address, final boolean auth) { + return new BftPropose(address, auth); } } diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/bft/ConsensusType.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/bft/ConsensusType.java new file mode 100644 index 0000000000..6716947e21 --- /dev/null +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/bft/ConsensusType.java @@ -0,0 +1,30 @@ +/* + * Copyright ConsenSys AG. + * + * 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.tests.acceptance.dsl.transaction.bft; + +public enum ConsensusType { + QBFT("qbft"), + IBFT2("ibft"); + + private final String name; + + ConsensusType(final String name) { + this.name = name; + } + + public String getName() { + return name; + } +} diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bft/BftAcceptanceTestParameterization.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bft/BftAcceptanceTestParameterization.java new file mode 100644 index 0000000000..d2fc906f65 --- /dev/null +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bft/BftAcceptanceTestParameterization.java @@ -0,0 +1,66 @@ +/* + * Copyright 2020 ConsenSys AG. + * + * 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.tests.acceptance.bft; + +import org.hyperledger.besu.tests.acceptance.dsl.node.BesuNode; +import org.hyperledger.besu.tests.acceptance.dsl.node.configuration.BesuNodeFactory; + +import java.util.List; + +public class BftAcceptanceTestParameterization { + + public static List FACTORIES = + List.of( + new Object[] { + "ibft", + new BftAcceptanceTestParameterization( + BesuNodeFactory::createIbft2Node, BesuNodeFactory::createIbft2NodeWithValidators) + }, + new Object[] { + "qbft", + new BftAcceptanceTestParameterization( + BesuNodeFactory::createQbftNode, BesuNodeFactory::createQbftNodeWithValidators) + }); + + @FunctionalInterface + public interface NodeCreator { + + BesuNode create(BesuNodeFactory factory, String name) throws Exception; + } + + @FunctionalInterface + public interface NodeWithValidatorsCreator { + + BesuNode create(BesuNodeFactory factory, String name, String[] validators) throws Exception; + } + + private final NodeCreator creatorFn; + private final NodeWithValidatorsCreator createorWithValidatorFn; + + public BftAcceptanceTestParameterization( + final NodeCreator creatorFn, final NodeWithValidatorsCreator createorWithValidatorFn) { + this.creatorFn = creatorFn; + this.createorWithValidatorFn = createorWithValidatorFn; + } + + public BesuNode createNode(BesuNodeFactory factory, String name) throws Exception { + return creatorFn.create(factory, name); + } + + public BesuNode createNodeWithValidators( + BesuNodeFactory factory, String name, String[] validators) throws Exception { + return createorWithValidatorFn.create(factory, name, validators); + } +} diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/ibft2/Ibft2MiningAcceptanceTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bft/BftMiningAcceptanceTest.java similarity index 68% rename from acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/ibft2/Ibft2MiningAcceptanceTest.java rename to acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bft/BftMiningAcceptanceTest.java index f1f8e441c6..153aca8aa7 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/ibft2/Ibft2MiningAcceptanceTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bft/BftMiningAcceptanceTest.java @@ -12,22 +12,28 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.tests.acceptance.ibft2; +package org.hyperledger.besu.tests.acceptance.bft; -import org.hyperledger.besu.tests.acceptance.dsl.AcceptanceTestBase; import org.hyperledger.besu.tests.acceptance.dsl.account.Account; import org.hyperledger.besu.tests.acceptance.dsl.node.BesuNode; -import java.io.IOException; import java.util.List; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; -public class Ibft2MiningAcceptanceTest extends AcceptanceTestBase { +@RunWith(Parameterized.class) +public class BftMiningAcceptanceTest extends ParameterizedBftTestBase { + + public BftMiningAcceptanceTest( + final String testName, final BftAcceptanceTestParameterization nodeFactory) { + super(testName, nodeFactory); + } @Test - public void shouldMineOnSingleNode() throws IOException { - final BesuNode minerNode = besu.createIbft2Node("miner1"); + public void shouldMineOnSingleNode() throws Exception { + final BesuNode minerNode = nodeFactory.createNode(besu, "miner1"); cluster.start(minerNode); cluster.verify(blockchain.reachesHeight(minerNode, 1)); @@ -46,11 +52,11 @@ public class Ibft2MiningAcceptanceTest extends AcceptanceTestBase { } @Test - public void shouldMineOnMultipleNodes() throws IOException { - final BesuNode minerNode1 = besu.createIbft2Node("miner1"); - final BesuNode minerNode2 = besu.createIbft2Node("miner2"); - final BesuNode minerNode3 = besu.createIbft2Node("miner3"); - final BesuNode minerNode4 = besu.createIbft2Node("miner4"); + public void shouldMineOnMultipleNodes() throws Exception { + final BesuNode minerNode1 = nodeFactory.createNode(besu, "miner1"); + final BesuNode minerNode2 = nodeFactory.createNode(besu, "miner2"); + final BesuNode minerNode3 = nodeFactory.createNode(besu, "miner3"); + final BesuNode minerNode4 = nodeFactory.createNode(besu, "miner4"); cluster.start(minerNode1, minerNode2, minerNode3, minerNode4); cluster.verify(blockchain.reachesHeight(minerNode1, 1, 85)); @@ -72,13 +78,16 @@ public class Ibft2MiningAcceptanceTest extends AcceptanceTestBase { } @Test - public void shouldMineOnMultipleNodesEvenWhenClusterContainsNonValidator() throws IOException { + public void shouldMineOnMultipleNodesEvenWhenClusterContainsNonValidator() throws Exception { final String[] validators = {"validator1", "validator2", "validator3"}; - final BesuNode validator1 = besu.createIbft2NodeWithValidators("validator1", validators); - final BesuNode validator2 = besu.createIbft2NodeWithValidators("validator2", validators); - final BesuNode validator3 = besu.createIbft2NodeWithValidators("validator3", validators); + final BesuNode validator1 = + nodeFactory.createNodeWithValidators(besu, "validator1", validators); + final BesuNode validator2 = + nodeFactory.createNodeWithValidators(besu, "validator2", validators); + final BesuNode validator3 = + nodeFactory.createNodeWithValidators(besu, "validator3", validators); final BesuNode nonValidatorNode = - besu.createIbft2NodeWithValidators("non-validator", validators); + nodeFactory.createNodeWithValidators(besu, "non-validator", validators); cluster.start(validator1, validator2, validator3, nonValidatorNode); cluster.verify(blockchain.reachesHeight(validator1, 1, 85)); @@ -98,13 +107,13 @@ public class Ibft2MiningAcceptanceTest extends AcceptanceTestBase { @Test public void shouldStillMineWhenANonProposerNodeFailsAndHasSufficientValidators() - throws IOException { - final BesuNode minerNode1 = besu.createIbft2Node("miner1"); - final BesuNode minerNode2 = besu.createIbft2Node("miner2"); - final BesuNode minerNode3 = besu.createIbft2Node("miner3"); - final BesuNode minerNode4 = besu.createIbft2Node("miner4"); + throws Exception { + final BesuNode minerNode1 = nodeFactory.createNode(besu, "miner1"); + final BesuNode minerNode2 = nodeFactory.createNode(besu, "miner2"); + final BesuNode minerNode3 = nodeFactory.createNode(besu, "miner3"); + final BesuNode minerNode4 = nodeFactory.createNode(besu, "miner4"); final List validators = - ibftTwo.validators(new BesuNode[] {minerNode1, minerNode2, minerNode3, minerNode4}); + bft.validators(new BesuNode[] {minerNode1, minerNode2, minerNode3, minerNode4}); final BesuNode nonProposerNode = validators.get(validators.size() - 1); cluster.start(validators); diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bft/ParameterizedBftTestBase.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bft/ParameterizedBftTestBase.java new file mode 100644 index 0000000000..3c0e3fc0bf --- /dev/null +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bft/ParameterizedBftTestBase.java @@ -0,0 +1,41 @@ +/* + * Copyright 2020 ConsenSys AG. + * + * 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.tests.acceptance.bft; + +import org.hyperledger.besu.tests.acceptance.dsl.AcceptanceTestBase; + +import java.util.Collection; + +import org.junit.Ignore; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +@RunWith(Parameterized.class) +@Ignore("This is not a test class, it offers BFT parameterization only.") +public abstract class ParameterizedBftTestBase extends AcceptanceTestBase { + + protected final BftAcceptanceTestParameterization nodeFactory; + + @Parameters(name = "{0}") + public static Collection factoryFunctions() { + return BftAcceptanceTestParameterization.FACTORIES; + } + + protected ParameterizedBftTestBase( + final String testname, final BftAcceptanceTestParameterization input) { + this.nodeFactory = input; + } +} diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/ibft2/Ibft2DiscardRpcAcceptanceTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/ibft2/Ibft2DiscardRpcAcceptanceTest.java index 8de0f98467..ebd4d9e8d7 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/ibft2/Ibft2DiscardRpcAcceptanceTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/ibft2/Ibft2DiscardRpcAcceptanceTest.java @@ -31,15 +31,15 @@ public class Ibft2DiscardRpcAcceptanceTest extends AcceptanceTestBase { final BesuNode validator3 = besu.createIbft2NodeWithValidators("validator3", validators); cluster.start(validator1, validator2, validator3); - validator1.execute(ibftTwoTransactions.createAddProposal(validator2)); - validator1.execute(ibftTwoTransactions.createRemoveProposal(validator3)); + validator1.execute(bftTransactions.createAddProposal(validator2)); + validator1.execute(bftTransactions.createRemoveProposal(validator3)); validator1.verify( - ibftTwo.pendingVotesEqual().addProposal(validator2).removeProposal(validator3).build()); + bft.pendingVotesEqual().addProposal(validator2).removeProposal(validator3).build()); - validator1.execute(ibftTwoTransactions.createDiscardProposal(validator2)); - validator1.verify(ibftTwo.pendingVotesEqual().removeProposal(validator3).build()); + validator1.execute(bftTransactions.createDiscardProposal(validator2)); + validator1.verify(bft.pendingVotesEqual().removeProposal(validator3).build()); - validator1.execute(ibftTwoTransactions.createDiscardProposal(validator3)); - cluster.verify(ibftTwo.noProposals()); + validator1.execute(bftTransactions.createDiscardProposal(validator3)); + cluster.verify(bft.noProposals()); } } diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/ibft2/Ibft2ProposalRpcAcceptanceTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/ibft2/Ibft2ProposalRpcAcceptanceTest.java index ff0ce12629..63e69e7504 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/ibft2/Ibft2ProposalRpcAcceptanceTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/ibft2/Ibft2ProposalRpcAcceptanceTest.java @@ -31,14 +31,14 @@ public class Ibft2ProposalRpcAcceptanceTest extends AcceptanceTestBase { final BesuNode validator3 = besu.createIbft2NodeWithValidators("validator3", validators); cluster.start(validator1, validator2, validator3); - cluster.verify(ibftTwo.noProposals()); - validator1.execute(ibftTwoTransactions.createAddProposal(validator3)); - validator1.execute(ibftTwoTransactions.createRemoveProposal(validator2)); - validator2.execute(ibftTwoTransactions.createRemoveProposal(validator3)); + cluster.verify(bft.noProposals()); + validator1.execute(bftTransactions.createAddProposal(validator3)); + validator1.execute(bftTransactions.createRemoveProposal(validator2)); + validator2.execute(bftTransactions.createRemoveProposal(validator3)); validator1.verify( - ibftTwo.pendingVotesEqual().addProposal(validator3).removeProposal(validator2).build()); - validator2.verify(ibftTwo.pendingVotesEqual().removeProposal(validator3).build()); - validator3.verify(ibftTwo.noProposals()); + bft.pendingVotesEqual().addProposal(validator3).removeProposal(validator2).build()); + validator2.verify(bft.pendingVotesEqual().removeProposal(validator3).build()); + validator3.verify(bft.noProposals()); } } diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/ibft2/Ibft2ProposeRpcAcceptanceTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/ibft2/Ibft2ProposeRpcAcceptanceTest.java index 77df0c1917..f205c7ac1e 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/ibft2/Ibft2ProposeRpcAcceptanceTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/ibft2/Ibft2ProposeRpcAcceptanceTest.java @@ -36,19 +36,19 @@ public class Ibft2ProposeRpcAcceptanceTest extends AcceptanceTestBase { besu.createIbft2NodeWithValidators("non-validator", validators); cluster.start(validator1, validator2, validator3, nonValidatorNode); - cluster.verify(ibftTwo.validatorsEqual(validator1, validator2, validator3)); - final Condition addedCondition = ibftTwo.awaitValidatorSetChange(validator1); - validator1.execute(ibftTwoTransactions.createAddProposal(nonValidatorNode)); - validator2.execute(ibftTwoTransactions.createAddProposal(nonValidatorNode)); + cluster.verify(bft.validatorsEqual(validator1, validator2, validator3)); + final Condition addedCondition = bft.awaitValidatorSetChange(validator1); + validator1.execute(bftTransactions.createAddProposal(nonValidatorNode)); + validator2.execute(bftTransactions.createAddProposal(nonValidatorNode)); cluster.verify(addedCondition); - cluster.verify(ibftTwo.validatorsEqual(validator1, validator2, validator3, nonValidatorNode)); + cluster.verify(bft.validatorsEqual(validator1, validator2, validator3, nonValidatorNode)); - final Condition removedCondition = ibftTwo.awaitValidatorSetChange(validator1); - validator2.execute(ibftTwoTransactions.createRemoveProposal(nonValidatorNode)); - validator3.execute(ibftTwoTransactions.createRemoveProposal(nonValidatorNode)); - nonValidatorNode.execute(ibftTwoTransactions.createRemoveProposal(nonValidatorNode)); + final Condition removedCondition = bft.awaitValidatorSetChange(validator1); + validator2.execute(bftTransactions.createRemoveProposal(nonValidatorNode)); + validator3.execute(bftTransactions.createRemoveProposal(nonValidatorNode)); + nonValidatorNode.execute(bftTransactions.createRemoveProposal(nonValidatorNode)); cluster.verify(removedCondition); - cluster.verify(ibftTwo.validatorsEqual(validator1, validator2, validator3)); + cluster.verify(bft.validatorsEqual(validator1, validator2, validator3)); } } diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/qbft/QbftMiningAcceptanceTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/qbft/QbftMiningAcceptanceTest.java deleted file mode 100644 index 59e756502a..0000000000 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/qbft/QbftMiningAcceptanceTest.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright ConsenSys AG. - * - * 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.tests.acceptance.qbft; - -import org.hyperledger.besu.tests.acceptance.dsl.AcceptanceTestBase; -import org.hyperledger.besu.tests.acceptance.dsl.account.Account; -import org.hyperledger.besu.tests.acceptance.dsl.node.BesuNode; - -import java.io.IOException; -import java.util.List; - -import org.junit.Test; - -public class QbftMiningAcceptanceTest extends AcceptanceTestBase { - - @Test - public void shouldMineOnSingleNode() throws IOException { - final BesuNode minerNode = besu.createQbftNode("miner1"); - cluster.start(minerNode); - - cluster.verify(blockchain.reachesHeight(minerNode, 1)); - - final Account sender = accounts.createAccount("account1"); - final Account receiver = accounts.createAccount("account2"); - - minerNode.execute(accountTransactions.createTransfer(sender, 50)); - cluster.verify(sender.balanceEquals(50)); - - minerNode.execute(accountTransactions.createIncrementalTransfers(sender, receiver, 1)); - cluster.verify(receiver.balanceEquals(1)); - - minerNode.execute(accountTransactions.createIncrementalTransfers(sender, receiver, 2)); - cluster.verify(receiver.balanceEquals(3)); - } - - @Test - public void shouldMineOnMultipleNodes() throws IOException { - final BesuNode minerNode1 = besu.createQbftNode("miner1"); - final BesuNode minerNode2 = besu.createQbftNode("miner2"); - final BesuNode minerNode3 = besu.createQbftNode("miner3"); - final BesuNode minerNode4 = besu.createQbftNode("miner4"); - cluster.start(minerNode1, minerNode2, minerNode3, minerNode4); - - cluster.verify(blockchain.reachesHeight(minerNode1, 1, 85)); - - final Account sender = accounts.createAccount("account1"); - final Account receiver = accounts.createAccount("account2"); - - minerNode1.execute(accountTransactions.createTransfer(sender, 50)); - cluster.verify(sender.balanceEquals(50)); - - minerNode2.execute(accountTransactions.createIncrementalTransfers(sender, receiver, 1)); - cluster.verify(receiver.balanceEquals(1)); - - minerNode3.execute(accountTransactions.createIncrementalTransfers(sender, receiver, 2)); - cluster.verify(receiver.balanceEquals(3)); - - minerNode4.execute(accountTransactions.createIncrementalTransfers(sender, receiver, 3)); - cluster.verify(receiver.balanceEquals(6)); - } - - @Test - public void shouldMineOnMultipleNodesEvenWhenClusterContainsNonValidator() throws IOException { - final String[] validators = {"validator1", "validator2", "validator3"}; - final BesuNode validator1 = besu.createQbftNodeWithValidators("validator1", validators); - final BesuNode validator2 = besu.createQbftNodeWithValidators("validator2", validators); - final BesuNode validator3 = besu.createQbftNodeWithValidators("validator3", validators); - final BesuNode nonValidatorNode = - besu.createQbftNodeWithValidators("non-validator", validators); - cluster.start(validator1, validator2, validator3, nonValidatorNode); - - cluster.verify(blockchain.reachesHeight(validator1, 1, 85)); - - final Account sender = accounts.createAccount("account1"); - final Account receiver = accounts.createAccount("account2"); - - validator1.execute(accountTransactions.createTransfer(sender, 50)); - cluster.verify(sender.balanceEquals(50)); - - validator2.execute(accountTransactions.createIncrementalTransfers(sender, receiver, 1)); - cluster.verify(receiver.balanceEquals(1)); - - nonValidatorNode.execute(accountTransactions.createIncrementalTransfers(sender, receiver, 2)); - cluster.verify(receiver.balanceEquals(3)); - } - - @Test - public void shouldStillMineWhenANonProposerNodeFailsAndHasSufficientValidators() - throws IOException { - final BesuNode minerNode1 = besu.createQbftNode("miner1"); - final BesuNode minerNode2 = besu.createQbftNode("miner2"); - final BesuNode minerNode3 = besu.createQbftNode("miner3"); - final BesuNode minerNode4 = besu.createQbftNode("miner4"); - final List validators = - ibftTwo.validators(new BesuNode[] {minerNode1, minerNode2, minerNode3, minerNode4}); - final BesuNode nonProposerNode = validators.get(validators.size() - 1); - cluster.start(validators); - - cluster.verify(blockchain.reachesHeight(minerNode1, 1, 85)); - - final Account receiver = accounts.createAccount("account2"); - - cluster.stopNode(nonProposerNode); - validators.get(0).execute(accountTransactions.createTransfer(receiver, 80)); - - cluster.verifyOnActiveNodes(receiver.balanceEquals(80)); - } -}