Skip to content

Commit

Permalink
Allow BFT tests to be parameterized (#1877)
Browse files Browse the repository at this point in the history
Signed-off-by: Trent Mohay <trent.mohay@consensys.net>
  • Loading branch information
Trent Mohay authored Feb 9, 2021
1 parent c63e919 commit 327ba1e
Show file tree
Hide file tree
Showing 22 changed files with 300 additions and 258 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
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;
Expand All @@ -37,10 +37,10 @@
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;
Expand Down Expand Up @@ -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;
Expand All @@ -105,7 +105,7 @@ protected 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();
Expand All @@ -115,7 +115,7 @@ protected 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -21,26 +21,25 @@
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
public void verify(final Node node) {
WaitUtils.waitFor(
60,
() ->
assertThat(node.execute(ibft.createGetValidators(LATEST)))
.isNotEqualTo(initialSigners));
assertThat(node.execute(bft.createGetValidators(LATEST))).isNotEqualTo(initialSigners));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
*
* 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;

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;
Expand All @@ -31,12 +31,12 @@

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) {
Expand All @@ -47,31 +47,31 @@ public List<BesuNode> validators(final BesuNode[] nodes) {
}

public ExpectValidators validatorsEqual(final BesuNode... validators) {
return new ExpectValidators(ibftTwo, validatorAddresses(validators));
return new ExpectValidators(bft, validatorAddresses(validators));
}

private Address[] validatorAddresses(final BesuNode[] validators) {
return Arrays.stream(validators).map(BesuNode::getAddress).sorted().toArray(Address[]::new);
}

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) {
Expand All @@ -88,7 +88,7 @@ public Condition build() {
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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,29 @@
*
* 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 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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,30 @@
*
* 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;
}

@Override
public void verify(final Node node) {
WaitUtils.waitFor(
() ->
assertThat(node.execute(ibft.createGetValidators(LATEST))).containsExactly(validators));
assertThat(node.execute(bft.createGetValidators(LATEST))).containsExactly(validators));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@
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;
Expand Down Expand Up @@ -339,11 +340,18 @@ private NodeRequests nodeRequests() {
}
}

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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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,
Expand All @@ -57,7 +57,7 @@ public 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;
Expand All @@ -80,8 +80,8 @@ public CliqueRequestFactory clique() {
return clique;
}

public Ibft2RequestFactory ibft() {
return ibft;
public BftRequestFactory bft() {
return bft;
}

public PermissioningJsonRpcRequestFactory perm() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -21,17 +21,17 @@

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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -23,18 +23,18 @@
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();
Expand Down
Loading

0 comments on commit 327ba1e

Please sign in to comment.