Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Minor refactorings of IntegrationTest infrastructure #786

Merged
merged 2 commits into from
Feb 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,19 @@
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;
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) {
Expand Down Expand Up @@ -61,19 +56,4 @@ public static PreparedRoundArtifacts createValidPreparedRoundArtifacts(
.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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
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;
Expand Down Expand Up @@ -111,14 +111,24 @@ public Commit injectCommit(
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -92,11 +91,10 @@ public void messagesForFutureRoundAreNotActionedUntilRoundIsActive() {

// 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());
Expand Down Expand Up @@ -136,11 +134,10 @@ public void priorRoundsCannotBeCompletedAfterReceptionOfNewRound() {

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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ public void gossipMessagesToPeers() {
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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -23,10 +23,10 @@
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;

Expand Down Expand Up @@ -71,10 +71,7 @@ public void newRoundMessageWithEmptyPrepareCertificatesOfferNewBlock() {
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());
Expand All @@ -97,10 +94,7 @@ public void newRoundMessageFromIllegalSenderIsDiscardedAndNoPrepareForNewRoundIs
illegalProposer.injectNewRound(
nextRoundId,
new RoundChangeCertificate(roundChanges),
illegalProposer
.getMessageFactory()
.createProposal(nextRoundId, blockToPropose)
.getSignedPayload());
illegalProposer.getMessageFactory().createProposal(nextRoundId, blockToPropose));

peers.verifyNoMessagesReceived();
}
Expand All @@ -122,11 +116,7 @@ public void newRoundWithPrepareCertificateResultsInNewRoundStartingWithExpectedB
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()));
Expand All @@ -152,7 +142,7 @@ public void newRoundMessageForPriorRoundIsNotActioned() {
.createProposal(interimRound, context.createBlockForProposalFromChainHead(1, 30));

interimRoundProposer.injectNewRound(
interimRound, new RoundChangeCertificate(roundChangePayloads), proposal.getSignedPayload());
interimRound, new RoundChangeCertificate(roundChangePayloads), proposal);

peers.verifyNoMessagesReceived();
}
Expand All @@ -175,11 +165,7 @@ public void receiveRoundStateIsNotLostIfASecondNewRoundMessageIsReceivedForCurre
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()));
Expand All @@ -191,19 +177,15 @@ public void receiveRoundStateIsNotLostIfASecondNewRoundMessageIsReceivedForCurre
nextProposer.injectNewRound(
nextRoundId,
new RoundChangeCertificate(roundChanges),
peers
.getNonProposing(0)
.getMessageFactory()
.createProposal(nextRoundId, reproposedBlock)
.getSignedPayload());
peers.getNonProposing(0).getMessageFactory().createProposal(nextRoundId, reproposedBlock));

peers.verifyNoMessagesReceived();

nextRoles.getNonProposing(1).injectPrepare(nextRoundId, reproposedBlock.getHash());

final Commit expectedCommit =
new Commit(
TestHelpers.createSignedCommitPayload(
IntegrationTestHelpers.createSignedCommitPayload(
nextRoundId, reproposedBlock, context.getLocalNodeParams().getNodeKeyPair()));

peers.verifyMessagesReceived(expectedCommit);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

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