From 6ecfcd7e8e6f837c03756d4686f1c400c8060404 Mon Sep 17 00:00:00 2001 From: tmohay Date: Wed, 6 Feb 2019 21:09:51 +1100 Subject: [PATCH] Minor refactorings of IntegrationTest infrastructure --- ...lpers.java => IntegrationTestHelpers.java} | 22 +----------- .../consensus/ibft/support/ValidatorPeer.java | 16 +++++++-- .../ibft/tests/FutureHeightTest.java | 2 +- .../consensus/ibft/tests/FutureRoundTest.java | 19 +++++----- .../consensus/ibft/tests/GossipTest.java | 3 +- .../ibft/tests/LocalNodeIsProposerTest.java | 2 +- .../ibft/tests/LocalNodeNotProposerTest.java | 2 +- .../ibft/tests/ReceivedNewRoundTest.java | 36 +++++-------------- .../consensus/ibft/tests/RoundChangeTest.java | 2 +- .../ibft/tests/SpuriousBehaviourTest.java | 2 +- 10 files changed, 37 insertions(+), 69 deletions(-) rename consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/support/{TestHelpers.java => IntegrationTestHelpers.java} (75%) diff --git a/consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/support/TestHelpers.java b/consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/support/IntegrationTestHelpers.java similarity index 75% rename from consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/support/TestHelpers.java rename to consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/support/IntegrationTestHelpers.java index 772f18b471..0956ed01b4 100644 --- a/consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/support/TestHelpers.java +++ b/consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/support/IntegrationTestHelpers.java @@ -15,13 +15,9 @@ 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.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 createSignedCommitPayload( final ConsensusRoundIdentifier roundId, final Block block, final KeyPair signingKeyPair) { @@ -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> roundChangePayloads, - final Block blockToPropose) { - - final Proposal proposal = - proposer.getMessageFactory().createProposal(targetRoundId, blockToPropose); - - return proposer.injectNewRound( - targetRoundId, - new RoundChangeCertificate(roundChangePayloads), - proposal.getSignedPayload()); - } } diff --git a/consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/support/ValidatorPeer.java b/consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/support/ValidatorPeer.java index 8aab83bcd9..80a2412c1b 100644 --- a/consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/support/ValidatorPeer.java +++ b/consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/support/ValidatorPeer.java @@ -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; @@ -111,14 +111,24 @@ public Commit injectCommit( public NewRound injectNewRound( final ConsensusRoundIdentifier rId, final RoundChangeCertificate roundChangeCertificate, - final SignedData 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> 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) { diff --git a/consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/tests/FutureHeightTest.java b/consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/tests/FutureHeightTest.java index 0ec2f01a6b..24982190b4 100644 --- a/consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/tests/FutureHeightTest.java +++ b/consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/tests/FutureHeightTest.java @@ -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; diff --git a/consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/tests/FutureRoundTest.java b/consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/tests/FutureRoundTest.java index 1e956cae67..93f05f7d5d 100644 --- a/consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/tests/FutureRoundTest.java +++ b/consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/tests/FutureRoundTest.java @@ -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 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()); @@ -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()); diff --git a/consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/tests/GossipTest.java b/consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/tests/GossipTest.java index b3981bcd55..12f97a3781 100644 --- a/consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/tests/GossipTest.java +++ b/consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/tests/GossipTest.java @@ -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(); diff --git a/consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/tests/LocalNodeIsProposerTest.java b/consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/tests/LocalNodeIsProposerTest.java index 420789a093..51573d81ac 100644 --- a/consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/tests/LocalNodeIsProposerTest.java +++ b/consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/tests/LocalNodeIsProposerTest.java @@ -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; diff --git a/consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/tests/LocalNodeNotProposerTest.java b/consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/tests/LocalNodeNotProposerTest.java index 67f870ab24..d905ee3e69 100644 --- a/consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/tests/LocalNodeNotProposerTest.java +++ b/consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/tests/LocalNodeNotProposerTest.java @@ -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; diff --git a/consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/tests/ReceivedNewRoundTest.java b/consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/tests/ReceivedNewRoundTest.java index 6646a5e21c..0301fe9969 100644 --- a/consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/tests/ReceivedNewRoundTest.java +++ b/consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/tests/ReceivedNewRoundTest.java @@ -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.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 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()); @@ -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(); } @@ -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())); @@ -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(); } @@ -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())); @@ -191,11 +177,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.verifyNoMessagesReceived(); @@ -203,7 +185,7 @@ public void receiveRoundStateIsNotLostIfASecondNewRoundMessageIsReceivedForCurre final Commit expectedCommit = new Commit( - TestHelpers.createSignedCommitPayload( + IntegrationTestHelpers.createSignedCommitPayload( nextRoundId, reproposedBlock, context.getLocalNodeParams().getNodeKeyPair())); peers.verifyMessagesReceived(expectedCommit); diff --git a/consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/tests/RoundChangeTest.java b/consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/tests/RoundChangeTest.java index decd357238..1b041f7d93 100644 --- a/consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/tests/RoundChangeTest.java +++ b/consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/tests/RoundChangeTest.java @@ -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; diff --git a/consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/tests/SpuriousBehaviourTest.java b/consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/tests/SpuriousBehaviourTest.java index eb048942c4..03b10c2ff5 100644 --- a/consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/tests/SpuriousBehaviourTest.java +++ b/consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/tests/SpuriousBehaviourTest.java @@ -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;