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.ConsensusRoundIdentifier;
import tech.pegasys.pantheon.consensus.ibft.IbftBlockHashing; import tech.pegasys.pantheon.consensus.ibft.IbftBlockHashing;
import tech.pegasys.pantheon.consensus.ibft.IbftExtraData; 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.Prepare;
import tech.pegasys.pantheon.consensus.ibft.messagewrappers.Proposal;
import tech.pegasys.pantheon.consensus.ibft.payload.CommitPayload; import tech.pegasys.pantheon.consensus.ibft.payload.CommitPayload;
import tech.pegasys.pantheon.consensus.ibft.payload.MessageFactory; 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.payload.SignedData;
import tech.pegasys.pantheon.consensus.ibft.statemachine.PreparedRoundArtifacts; import tech.pegasys.pantheon.consensus.ibft.statemachine.PreparedRoundArtifacts;
import tech.pegasys.pantheon.crypto.SECP256K1; 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.crypto.SECP256K1.Signature;
import tech.pegasys.pantheon.ethereum.core.Block; import tech.pegasys.pantheon.ethereum.core.Block;
import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class TestHelpers { public class IntegrationTestHelpers {
public static SignedData<CommitPayload> createSignedCommitPayload( public static SignedData<CommitPayload> createSignedCommitPayload(
final ConsensusRoundIdentifier roundId, final Block block, final KeyPair signingKeyPair) { final ConsensusRoundIdentifier roundId, final Block block, final KeyPair signingKeyPair) {
@ -61,19 +56,4 @@ public class TestHelpers {
.map(Prepare::new) .map(Prepare::new)
.collect(Collectors.toList())); .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.Proposal;
import tech.pegasys.pantheon.consensus.ibft.messagewrappers.RoundChange; import tech.pegasys.pantheon.consensus.ibft.messagewrappers.RoundChange;
import tech.pegasys.pantheon.consensus.ibft.payload.MessageFactory; 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.RoundChangeCertificate;
import tech.pegasys.pantheon.consensus.ibft.payload.RoundChangePayload;
import tech.pegasys.pantheon.consensus.ibft.payload.SignedData; import tech.pegasys.pantheon.consensus.ibft.payload.SignedData;
import tech.pegasys.pantheon.consensus.ibft.statemachine.PreparedRoundArtifacts; import tech.pegasys.pantheon.consensus.ibft.statemachine.PreparedRoundArtifacts;
import tech.pegasys.pantheon.crypto.SECP256K1; import tech.pegasys.pantheon.crypto.SECP256K1;
@ -111,14 +111,24 @@ public class ValidatorPeer {
public NewRound injectNewRound( public NewRound injectNewRound(
final ConsensusRoundIdentifier rId, final ConsensusRoundIdentifier rId,
final RoundChangeCertificate roundChangeCertificate, final RoundChangeCertificate roundChangeCertificate,
final SignedData<ProposalPayload> proposalPayload) { final Proposal proposal) {
final NewRound payload = final NewRound payload =
messageFactory.createNewRound(rId, roundChangeCertificate, proposalPayload); messageFactory.createNewRound(rId, roundChangeCertificate, proposal.getSignedPayload());
injectMessage(NewRoundMessageData.create(payload)); injectMessage(NewRoundMessageData.create(payload));
return 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( public RoundChange injectRoundChange(
final ConsensusRoundIdentifier rId, final ConsensusRoundIdentifier rId,
final Optional<PreparedRoundArtifacts> preparedRoundArtifacts) { 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.api.Assertions.assertThat;
import static org.assertj.core.util.Lists.emptyList; 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.ConsensusRoundIdentifier;
import tech.pegasys.pantheon.consensus.ibft.IbftHelpers; import tech.pegasys.pantheon.consensus.ibft.IbftHelpers;

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

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

@ -13,7 +13,7 @@
package tech.pegasys.pantheon.consensus.ibft.tests; package tech.pegasys.pantheon.consensus.ibft.tests;
import static org.assertj.core.api.Assertions.assertThat; 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.ConsensusRoundIdentifier;
import tech.pegasys.pantheon.consensus.ibft.ibftevent.BlockTimerExpiry; import tech.pegasys.pantheon.consensus.ibft.ibftevent.BlockTimerExpiry;

@ -13,7 +13,7 @@
package tech.pegasys.pantheon.consensus.ibft.tests; package tech.pegasys.pantheon.consensus.ibft.tests;
import static org.assertj.core.api.Assertions.assertThat; 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.ConsensusRoundIdentifier;
import tech.pegasys.pantheon.consensus.ibft.messagewrappers.Commit; import tech.pegasys.pantheon.consensus.ibft.messagewrappers.Commit;

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

@ -14,7 +14,7 @@ package tech.pegasys.pantheon.consensus.ibft.tests;
import static java.util.Collections.emptyList; import static java.util.Collections.emptyList;
import static java.util.Optional.empty; 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.ConsensusRoundIdentifier;
import tech.pegasys.pantheon.consensus.ibft.IbftHelpers; import tech.pegasys.pantheon.consensus.ibft.IbftHelpers;

@ -13,7 +13,7 @@
package tech.pegasys.pantheon.consensus.ibft.tests; package tech.pegasys.pantheon.consensus.ibft.tests;
import static org.assertj.core.api.Assertions.assertThat; 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.ConsensusRoundIdentifier;
import tech.pegasys.pantheon.consensus.ibft.messagedata.IbftV2; import tech.pegasys.pantheon.consensus.ibft.messagedata.IbftV2;

Loading…
Cancel
Save