Minor refactorings of IntegrationTest infrastructure (#786)

Signed-off-by: Adrian Sutton <adrian.sutton@consensys.net>
pull/2/head
Trent Mohay 6 years ago committed by GitHub
parent 69f81a9432
commit c04101e59a
  1. 22
      consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/support/IntegrationTestHelpers.java
  2. 16
      consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/support/ValidatorPeer.java
  3. 2
      consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/tests/FutureHeightTest.java
  4. 19
      consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/tests/FutureRoundTest.java
  5. 3
      consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/tests/GossipTest.java
  6. 2
      consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/tests/LocalNodeIsProposerTest.java
  7. 2
      consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/tests/LocalNodeNotProposerTest.java
  8. 36
      consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/tests/ReceivedNewRoundTest.java
  9. 2
      consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/tests/RoundChangeTest.java
  10. 2
      consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/tests/SpuriousBehaviourTest.java

@ -15,13 +15,9 @@ package tech.pegasys.pantheon.consensus.ibft.support;
import tech.pegasys.pantheon.consensus.ibft.ConsensusRoundIdentifier;
import tech.pegasys.pantheon.consensus.ibft.IbftBlockHashing;
import tech.pegasys.pantheon.consensus.ibft.IbftExtraData;
import tech.pegasys.pantheon.consensus.ibft.messagewrappers.NewRound;
import tech.pegasys.pantheon.consensus.ibft.messagewrappers.Prepare;
import tech.pegasys.pantheon.consensus.ibft.messagewrappers.Proposal;
import tech.pegasys.pantheon.consensus.ibft.payload.CommitPayload;
import tech.pegasys.pantheon.consensus.ibft.payload.MessageFactory;
import tech.pegasys.pantheon.consensus.ibft.payload.RoundChangeCertificate;
import tech.pegasys.pantheon.consensus.ibft.payload.RoundChangePayload;
import tech.pegasys.pantheon.consensus.ibft.payload.SignedData;
import tech.pegasys.pantheon.consensus.ibft.statemachine.PreparedRoundArtifacts;
import tech.pegasys.pantheon.crypto.SECP256K1;
@ -29,10 +25,9 @@ import tech.pegasys.pantheon.crypto.SECP256K1.KeyPair;
import tech.pegasys.pantheon.crypto.SECP256K1.Signature;
import tech.pegasys.pantheon.ethereum.core.Block;
import java.util.List;
import java.util.stream.Collectors;
public class TestHelpers {
public class IntegrationTestHelpers {
public static SignedData<CommitPayload> createSignedCommitPayload(
final ConsensusRoundIdentifier roundId, final Block block, final KeyPair signingKeyPair) {
@ -61,19 +56,4 @@ public class TestHelpers {
.map(Prepare::new)
.collect(Collectors.toList()));
}
public static NewRound injectEmptyNewRound(
final ConsensusRoundIdentifier targetRoundId,
final ValidatorPeer proposer,
final List<SignedData<RoundChangePayload>> roundChangePayloads,
final Block blockToPropose) {
final Proposal proposal =
proposer.getMessageFactory().createProposal(targetRoundId, blockToPropose);
return proposer.injectNewRound(
targetRoundId,
new RoundChangeCertificate(roundChangePayloads),
proposal.getSignedPayload());
}
}

@ -26,8 +26,8 @@ import tech.pegasys.pantheon.consensus.ibft.messagewrappers.Prepare;
import tech.pegasys.pantheon.consensus.ibft.messagewrappers.Proposal;
import tech.pegasys.pantheon.consensus.ibft.messagewrappers.RoundChange;
import tech.pegasys.pantheon.consensus.ibft.payload.MessageFactory;
import tech.pegasys.pantheon.consensus.ibft.payload.ProposalPayload;
import tech.pegasys.pantheon.consensus.ibft.payload.RoundChangeCertificate;
import tech.pegasys.pantheon.consensus.ibft.payload.RoundChangePayload;
import tech.pegasys.pantheon.consensus.ibft.payload.SignedData;
import tech.pegasys.pantheon.consensus.ibft.statemachine.PreparedRoundArtifacts;
import tech.pegasys.pantheon.crypto.SECP256K1;
@ -111,14 +111,24 @@ public class ValidatorPeer {
public NewRound injectNewRound(
final ConsensusRoundIdentifier rId,
final RoundChangeCertificate roundChangeCertificate,
final SignedData<ProposalPayload> proposalPayload) {
final Proposal proposal) {
final NewRound payload =
messageFactory.createNewRound(rId, roundChangeCertificate, proposalPayload);
messageFactory.createNewRound(rId, roundChangeCertificate, proposal.getSignedPayload());
injectMessage(NewRoundMessageData.create(payload));
return payload;
}
public NewRound injectEmptyNewRound(
final ConsensusRoundIdentifier targetRoundId,
final List<SignedData<RoundChangePayload>> roundChangePayloads,
final Block blockToPropose) {
final Proposal proposal = messageFactory.createProposal(targetRoundId, blockToPropose);
return injectNewRound(targetRoundId, new RoundChangeCertificate(roundChangePayloads), proposal);
}
public RoundChange injectRoundChange(
final ConsensusRoundIdentifier rId,
final Optional<PreparedRoundArtifacts> preparedRoundArtifacts) {

@ -14,7 +14,7 @@ package tech.pegasys.pantheon.consensus.ibft.tests;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.util.Lists.emptyList;
import static tech.pegasys.pantheon.consensus.ibft.support.TestHelpers.createSignedCommitPayload;
import static tech.pegasys.pantheon.consensus.ibft.support.IntegrationTestHelpers.createSignedCommitPayload;
import tech.pegasys.pantheon.consensus.ibft.ConsensusRoundIdentifier;
import tech.pegasys.pantheon.consensus.ibft.IbftHelpers;

@ -13,7 +13,6 @@
package tech.pegasys.pantheon.consensus.ibft.tests;
import static org.assertj.core.api.Assertions.assertThat;
import static tech.pegasys.pantheon.consensus.ibft.support.TestHelpers.injectEmptyNewRound;
import tech.pegasys.pantheon.consensus.ibft.ConsensusRoundIdentifier;
import tech.pegasys.pantheon.consensus.ibft.IbftHelpers;
@ -92,11 +91,10 @@ public class FutureRoundTest {
// inject a newRound to move to 'futureRoundId', and ensure localnode sends prepare, commit
// and updates blockchain
injectEmptyNewRound(
futureRoundId,
futurePeers.getProposer(),
futurePeers.createSignedRoundChangePayload(futureRoundId),
futureBlock);
futurePeers
.getProposer()
.injectEmptyNewRound(
futureRoundId, futurePeers.createSignedRoundChangePayload(futureRoundId), futureBlock);
final Prepare expectedPrepare =
localNodeMessageFactory.createPrepare(futureRoundId, futureBlock.getHash());
@ -136,11 +134,10 @@ public class FutureRoundTest {
peers.clearReceivedMessages();
injectEmptyNewRound(
futureRoundId,
futurePeers.getProposer(),
futurePeers.createSignedRoundChangePayload(futureRoundId),
futureBlock);
futurePeers
.getProposer()
.injectEmptyNewRound(
futureRoundId, futurePeers.createSignedRoundChangePayload(futureRoundId), futureBlock);
final Prepare expectedFuturePrepare =
localNodeMessageFactory.createPrepare(futureRoundId, futureBlock.getHash());

@ -93,8 +93,7 @@ public class GossipTest {
final RoundChange roundChange = msgFactory.createRoundChange(roundId, Optional.empty());
final RoundChangeCertificate roundChangeCert =
new RoundChangeCertificate(singleton(roundChange.getSignedPayload()));
final NewRound newRound =
sender.injectNewRound(roundId, roundChangeCert, proposal.getSignedPayload());
final NewRound newRound = sender.injectNewRound(roundId, roundChangeCert, proposal);
peers.verifyMessagesReceivedNonPropsing(newRound);
peers.verifyNoMessagesReceivedProposer();

@ -13,7 +13,7 @@
package tech.pegasys.pantheon.consensus.ibft.tests;
import static org.assertj.core.api.Assertions.assertThat;
import static tech.pegasys.pantheon.consensus.ibft.support.TestHelpers.createSignedCommitPayload;
import static tech.pegasys.pantheon.consensus.ibft.support.IntegrationTestHelpers.createSignedCommitPayload;
import tech.pegasys.pantheon.consensus.ibft.ConsensusRoundIdentifier;
import tech.pegasys.pantheon.consensus.ibft.ibftevent.BlockTimerExpiry;

@ -13,7 +13,7 @@
package tech.pegasys.pantheon.consensus.ibft.tests;
import static org.assertj.core.api.Assertions.assertThat;
import static tech.pegasys.pantheon.consensus.ibft.support.TestHelpers.createSignedCommitPayload;
import static tech.pegasys.pantheon.consensus.ibft.support.IntegrationTestHelpers.createSignedCommitPayload;
import tech.pegasys.pantheon.consensus.ibft.ConsensusRoundIdentifier;
import tech.pegasys.pantheon.consensus.ibft.messagewrappers.Commit;

@ -12,7 +12,7 @@
*/
package tech.pegasys.pantheon.consensus.ibft.tests;
import static tech.pegasys.pantheon.consensus.ibft.support.TestHelpers.createValidPreparedRoundArtifacts;
import static tech.pegasys.pantheon.consensus.ibft.support.IntegrationTestHelpers.createValidPreparedRoundArtifacts;
import tech.pegasys.pantheon.consensus.ibft.ConsensusRoundIdentifier;
import tech.pegasys.pantheon.consensus.ibft.messagewrappers.Commit;
@ -23,10 +23,10 @@ import tech.pegasys.pantheon.consensus.ibft.payload.RoundChangeCertificate;
import tech.pegasys.pantheon.consensus.ibft.payload.RoundChangePayload;
import tech.pegasys.pantheon.consensus.ibft.payload.SignedData;
import tech.pegasys.pantheon.consensus.ibft.statemachine.PreparedRoundArtifacts;
import tech.pegasys.pantheon.consensus.ibft.support.IntegrationTestHelpers;
import tech.pegasys.pantheon.consensus.ibft.support.RoundSpecificPeers;
import tech.pegasys.pantheon.consensus.ibft.support.TestContext;
import tech.pegasys.pantheon.consensus.ibft.support.TestContextBuilder;
import tech.pegasys.pantheon.consensus.ibft.support.TestHelpers;
import tech.pegasys.pantheon.consensus.ibft.support.ValidatorPeer;
import tech.pegasys.pantheon.ethereum.core.Block;
@ -71,10 +71,7 @@ public class ReceivedNewRoundTest {
nextProposer.injectNewRound(
targetRound,
new RoundChangeCertificate(roundChanges),
nextProposer
.getMessageFactory()
.createProposal(targetRound, blockToPropose)
.getSignedPayload());
nextProposer.getMessageFactory().createProposal(targetRound, blockToPropose));
final Prepare expectedPrepare =
localNodeMessageFactory.createPrepare(targetRound, blockToPropose.getHash());
@ -97,10 +94,7 @@ public class ReceivedNewRoundTest {
illegalProposer.injectNewRound(
nextRoundId,
new RoundChangeCertificate(roundChanges),
illegalProposer
.getMessageFactory()
.createProposal(nextRoundId, blockToPropose)
.getSignedPayload());
illegalProposer.getMessageFactory().createProposal(nextRoundId, blockToPropose));
peers.verifyNoMessagesReceived();
}
@ -122,11 +116,7 @@ public class ReceivedNewRoundTest {
nextProposer.injectNewRound(
nextRoundId,
new RoundChangeCertificate(roundChanges),
peers
.getNonProposing(0)
.getMessageFactory()
.createProposal(nextRoundId, reproposedBlock)
.getSignedPayload());
peers.getNonProposing(0).getMessageFactory().createProposal(nextRoundId, reproposedBlock));
peers.verifyMessagesReceived(
localNodeMessageFactory.createPrepare(nextRoundId, reproposedBlock.getHash()));
@ -152,7 +142,7 @@ public class ReceivedNewRoundTest {
.createProposal(interimRound, context.createBlockForProposalFromChainHead(1, 30));
interimRoundProposer.injectNewRound(
interimRound, new RoundChangeCertificate(roundChangePayloads), proposal.getSignedPayload());
interimRound, new RoundChangeCertificate(roundChangePayloads), proposal);
peers.verifyNoMessagesReceived();
}
@ -175,11 +165,7 @@ public class ReceivedNewRoundTest {
nextProposer.injectNewRound(
nextRoundId,
new RoundChangeCertificate(roundChanges),
peers
.getNonProposing(0)
.getMessageFactory()
.createProposal(nextRoundId, reproposedBlock)
.getSignedPayload());
peers.getNonProposing(0).getMessageFactory().createProposal(nextRoundId, reproposedBlock));
peers.verifyMessagesReceived(
localNodeMessageFactory.createPrepare(nextRoundId, reproposedBlock.getHash()));
@ -191,11 +177,7 @@ public class ReceivedNewRoundTest {
nextProposer.injectNewRound(
nextRoundId,
new RoundChangeCertificate(roundChanges),
peers
.getNonProposing(0)
.getMessageFactory()
.createProposal(nextRoundId, reproposedBlock)
.getSignedPayload());
peers.getNonProposing(0).getMessageFactory().createProposal(nextRoundId, reproposedBlock));
peers.verifyNoMessagesReceived();
@ -203,7 +185,7 @@ public class ReceivedNewRoundTest {
final Commit expectedCommit =
new Commit(
TestHelpers.createSignedCommitPayload(
IntegrationTestHelpers.createSignedCommitPayload(
nextRoundId, reproposedBlock, context.getLocalNodeParams().getNodeKeyPair()));
peers.verifyMessagesReceived(expectedCommit);

@ -14,7 +14,7 @@ package tech.pegasys.pantheon.consensus.ibft.tests;
import static java.util.Collections.emptyList;
import static java.util.Optional.empty;
import static tech.pegasys.pantheon.consensus.ibft.support.TestHelpers.createValidPreparedRoundArtifacts;
import static tech.pegasys.pantheon.consensus.ibft.support.IntegrationTestHelpers.createValidPreparedRoundArtifacts;
import tech.pegasys.pantheon.consensus.ibft.ConsensusRoundIdentifier;
import tech.pegasys.pantheon.consensus.ibft.IbftHelpers;

@ -13,7 +13,7 @@
package tech.pegasys.pantheon.consensus.ibft.tests;
import static org.assertj.core.api.Assertions.assertThat;
import static tech.pegasys.pantheon.consensus.ibft.support.TestHelpers.createSignedCommitPayload;
import static tech.pegasys.pantheon.consensus.ibft.support.IntegrationTestHelpers.createSignedCommitPayload;
import tech.pegasys.pantheon.consensus.ibft.ConsensusRoundIdentifier;
import tech.pegasys.pantheon.consensus.ibft.messagedata.IbftV2;

Loading…
Cancel
Save