Allow BFT tests to be parameterized (#1877)

Signed-off-by: Trent Mohay <trent.mohay@consensys.net>
pull/1893/head
Trent Mohay 4 years ago committed by GitHub
parent c63e9192f3
commit 327ba1e977
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/AcceptanceTestBase.java
  2. 13
      acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/bft/AwaitValidatorSetChange.java
  3. 28
      acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/bft/BftConditions.java
  4. 13
      acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/bft/ExpectProposals.java
  5. 14
      acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/condition/bft/ExpectValidators.java
  6. 12
      acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/BesuNode.java
  7. 12
      acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/NodeRequests.java
  8. 8
      acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/bft/BftDiscard.java
  9. 10
      acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/bft/BftGetValidators.java
  10. 9
      acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/bft/BftGetValidatorsAtHash.java
  11. 7
      acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/bft/BftProposals.java
  12. 8
      acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/bft/BftPropose.java
  13. 26
      acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/bft/BftRequestFactory.java
  14. 28
      acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/bft/BftTransactions.java
  15. 30
      acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/transaction/bft/ConsensusType.java
  16. 66
      acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bft/BftAcceptanceTestParameterization.java
  17. 53
      acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bft/BftMiningAcceptanceTest.java
  18. 41
      acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bft/ParameterizedBftTestBase.java
  19. 14
      acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/ibft2/Ibft2DiscardRpcAcceptanceTest.java
  20. 14
      acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/ibft2/Ibft2ProposalRpcAcceptanceTest.java
  21. 20
      acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/ibft2/Ibft2ProposeRpcAcceptanceTest.java
  22. 120
      acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/qbft/QbftMiningAcceptanceTest.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);

@ -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<Address> initialSigners;
public AwaitValidatorSetChange(final List<Address> initialSigners, final Ibft2Transactions ibft) {
public AwaitValidatorSetChange(final List<Address> 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));
}
}

@ -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<BesuNode> 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<BesuNode, Boolean> 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<Address, Boolean> 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);
}
}
}

@ -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<Address, Boolean> proposers;
public ExpectProposals(final Ibft2Transactions ibftTwo, final Map<Address, Boolean> proposers) {
this.ibftTwo = ibftTwo;
public ExpectProposals(final BftTransactions bft, final Map<Address, Boolean> 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));
}
}

@ -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));
}
}

@ -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),

@ -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() {

@ -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<Boolean> {
public class BftDiscard implements Transaction<Boolean> {
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();

@ -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<List<Address>> {
public class BftGetValidators implements Transaction<List<Address>> {
private final String blockNumber;
public Ibft2GetValidators(final String blockNumber) {
public BftGetValidators(final String blockNumber) {
this.blockNumber = blockNumber;
}
@Override
public List<Address> 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();

@ -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<List<Address>> {
public class BftGetValidatorsAtHash implements Transaction<List<Address>> {
private final Hash hash;
public Ibft2GetValidatorsAtHash(final Hash hash) {
public BftGetValidatorsAtHash(final Hash hash) {
this.hash = hash;
}
@Override
public List<Address> 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();

@ -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<Map<Address, Boolean>> {
public class BftProposals implements Transaction<Map<Address, Boolean>> {
@Override
public Map<Address, Boolean> 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();

@ -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<Boolean> {
public class BftPropose implements Transaction<Boolean> {
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<Boolean> {
@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();

@ -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<Boolean> {}
@ -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<?, ProposeResponse> 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<?, DiscardResponse> discard(final String address) {
return new Request<>(
"ibft_discardValidatorVote", singletonList(address), web3jService, DiscardResponse.class);
bftType.getName() + "_discardValidatorVote",
singletonList(address),
web3jService,
DiscardResponse.class);
}
Request<?, ProposalsResponse> proposals() {
return new Request<>(
"ibft_getPendingVotes", emptyList(), web3jService, ProposalsResponse.class);
bftType.getName() + "_getPendingVotes", emptyList(), web3jService, ProposalsResponse.class);
}
Request<?, SignersBlockResponse> 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<?, SignersBlockResponse> signersAtHash(final Hash hash) {
return new Request<>(
"ibft_getValidatorsByBlockHash",
bftType.getName() + "_getValidatorsByBlockHash",
singletonList(hash.toString()),
web3jService,
SignersBlockResponse.class);

@ -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);
}
}

@ -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;
}
}

@ -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<Object[]> 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);
}
}

@ -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<BesuNode> 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);

@ -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<Object[]> factoryFunctions() {
return BftAcceptanceTestParameterization.FACTORIES;
}
protected ParameterizedBftTestBase(
final String testname, final BftAcceptanceTestParameterization input) {
this.nodeFactory = input;
}
}

@ -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());
}
}

@ -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());
}
}

@ -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));
}
}

@ -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<BesuNode> 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));
}
}
Loading…
Cancel
Save