Rename Ibft MessageFactory methods (#779)

Renamed MessageFactory method names from createSignedXPayload, to simply
createX.
Signed-off-by: Adrian Sutton <adrian.sutton@consensys.net>
pull/2/head
tmohay 6 years ago committed by GitHub
parent e3bdc13edb
commit 53510a14cf
  1. 14
      consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/support/RoundSpecificPeers.java
  2. 8
      consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/support/TestHelpers.java
  3. 11
      consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/support/ValidatorPeer.java
  4. 11
      consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/tests/FutureHeightTest.java
  5. 6
      consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/tests/FutureRoundTest.java
  6. 11
      consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/tests/GossipTest.java
  7. 3
      consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/tests/LocalNodeIsProposerTest.java
  8. 3
      consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/tests/LocalNodeNotProposerTest.java
  9. 19
      consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/tests/ReceivedNewRoundTest.java
  10. 31
      consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/tests/RoundChangeTest.java
  11. 4
      consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/tests/SpuriousBehaviourTest.java
  12. 12
      consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/network/IbftMessageTransmitter.java
  13. 11
      consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/payload/MessageFactory.java
  14. 2
      consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/statemachine/IbftBlockHeightManager.java
  15. 11
      consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/statemachine/IbftRound.java
  16. 22
      consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/IbftHelpersTest.java
  17. 11
      consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/TestHelpers.java
  18. 18
      consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/statemachine/IbftBlockHeightManagerTest.java
  19. 38
      consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/statemachine/IbftRoundTest.java
  20. 9
      consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/statemachine/RoundChangeManagerTest.java
  21. 44
      consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/statemachine/RoundStateTest.java
  22. 7
      consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/validation/MessageValidatorTest.java
  23. 4
      consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/validation/NewRoundMessageValidatorTest.java
  24. 53
      consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/validation/NewRoundSignedDataValidatorTest.java
  25. 3
      consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/validation/RoundChangeMessageValidatorTest.java
  26. 39
      consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/validation/RoundChangeSignedDataValidatorTest.java
  27. 61
      consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/validation/SignedDataValidatorTest.java

@ -104,11 +104,7 @@ public class RoundSpecificPeers {
final ConsensusRoundIdentifier roundId) { final ConsensusRoundIdentifier roundId) {
return peers return peers
.stream() .stream()
.map( .map(p -> p.getMessageFactory().createRoundChange(roundId, empty()).getSignedPayload())
p ->
p.getMessageFactory()
.createSignedRoundChangePayload(roundId, empty())
.getSignedPayload())
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
@ -120,7 +116,7 @@ public class RoundSpecificPeers {
.map( .map(
p -> p ->
p.getMessageFactory() p.getMessageFactory()
.createSignedRoundChangePayload(roundId, Optional.of(terminatedRoundArtefacts)) .createRoundChange(roundId, Optional.of(terminatedRoundArtefacts))
.getSignedPayload()) .getSignedPayload())
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
@ -137,11 +133,7 @@ public class RoundSpecificPeers {
final ConsensusRoundIdentifier preparedRound, final Hash hash) { final ConsensusRoundIdentifier preparedRound, final Hash hash) {
return nonProposingPeers return nonProposingPeers
.stream() .stream()
.map( .map(role -> role.getMessageFactory().createPrepare(preparedRound, hash).getSignedPayload())
role ->
role.getMessageFactory()
.createSignedPreparePayload(preparedRound, hash)
.getSignedPayload())
.collect(Collectors.toList()); .collect(Collectors.toList());
} }

@ -46,9 +46,7 @@ public class TestHelpers {
final MessageFactory messageFactory = new MessageFactory(signingKeyPair); final MessageFactory messageFactory = new MessageFactory(signingKeyPair);
return messageFactory return messageFactory.createCommit(roundId, block.getHash(), commitSeal).getSignedPayload();
.createSignedCommitPayload(roundId, block.getHash(), commitSeal)
.getSignedPayload();
} }
public static TerminatedRoundArtefacts createValidTerminatedRoundArtefacts( public static TerminatedRoundArtefacts createValidTerminatedRoundArtefacts(
@ -56,7 +54,7 @@ public class TestHelpers {
final RoundSpecificPeers peers = context.roundSpecificPeers(preparedRound); final RoundSpecificPeers peers = context.roundSpecificPeers(preparedRound);
return new TerminatedRoundArtefacts( return new TerminatedRoundArtefacts(
peers.getProposer().getMessageFactory().createSignedProposalPayload(preparedRound, block), peers.getProposer().getMessageFactory().createProposal(preparedRound, block),
peers peers
.createSignedPreparePayloadOfNonProposing(preparedRound, block.getHash()) .createSignedPreparePayloadOfNonProposing(preparedRound, block.getHash())
.stream() .stream()
@ -71,7 +69,7 @@ public class TestHelpers {
final Block blockToPropose) { final Block blockToPropose) {
final Proposal proposal = final Proposal proposal =
proposer.getMessageFactory().createSignedProposalPayload(targetRoundId, blockToPropose); proposer.getMessageFactory().createProposal(targetRoundId, blockToPropose);
return proposer.injectNewRound( return proposer.injectNewRound(
targetRoundId, targetRoundId,

@ -79,14 +79,14 @@ public class ValidatorPeer {
} }
public Proposal injectProposal(final ConsensusRoundIdentifier rId, final Block block) { public Proposal injectProposal(final ConsensusRoundIdentifier rId, final Block block) {
final Proposal payload = messageFactory.createSignedProposalPayload(rId, block); final Proposal payload = messageFactory.createProposal(rId, block);
injectMessage(ProposalMessageData.create(payload)); injectMessage(ProposalMessageData.create(payload));
return payload; return payload;
} }
public Prepare injectPrepare(final ConsensusRoundIdentifier rId, final Hash digest) { public Prepare injectPrepare(final ConsensusRoundIdentifier rId, final Hash digest) {
final Prepare payload = messageFactory.createSignedPreparePayload(rId, digest); final Prepare payload = messageFactory.createPrepare(rId, digest);
injectMessage(PrepareMessageData.create(payload)); injectMessage(PrepareMessageData.create(payload));
return payload; return payload;
} }
@ -103,7 +103,7 @@ public class ValidatorPeer {
public Commit injectCommit( public Commit injectCommit(
final ConsensusRoundIdentifier rId, final Hash digest, final Signature commitSeal) { final ConsensusRoundIdentifier rId, final Hash digest, final Signature commitSeal) {
final Commit payload = messageFactory.createSignedCommitPayload(rId, digest, commitSeal); final Commit payload = messageFactory.createCommit(rId, digest, commitSeal);
injectMessage(CommitMessageData.create(payload)); injectMessage(CommitMessageData.create(payload));
return payload; return payload;
} }
@ -114,7 +114,7 @@ public class ValidatorPeer {
final SignedData<ProposalPayload> proposalPayload) { final SignedData<ProposalPayload> proposalPayload) {
final NewRound payload = final NewRound payload =
messageFactory.createSignedNewRoundPayload(rId, roundChangeCertificate, proposalPayload); messageFactory.createNewRound(rId, roundChangeCertificate, proposalPayload);
injectMessage(NewRoundMessageData.create(payload)); injectMessage(NewRoundMessageData.create(payload));
return payload; return payload;
} }
@ -122,8 +122,7 @@ public class ValidatorPeer {
public RoundChange injectRoundChange( public RoundChange injectRoundChange(
final ConsensusRoundIdentifier rId, final ConsensusRoundIdentifier rId,
final Optional<TerminatedRoundArtefacts> terminatedRoundArtefacts) { final Optional<TerminatedRoundArtefacts> terminatedRoundArtefacts) {
final RoundChange payload = final RoundChange payload = messageFactory.createRoundChange(rId, terminatedRoundArtefacts);
messageFactory.createSignedRoundChangePayload(rId, terminatedRoundArtefacts);
injectMessage(RoundChangeMessageData.create(payload)); injectMessage(RoundChangeMessageData.create(payload));
return payload; return payload;
} }

@ -89,8 +89,7 @@ public class FutureHeightTest {
.handleNewBlockEvent(new NewChainHead(signedCurrentHeightBlock.getHeader())); .handleNewBlockEvent(new NewChainHead(signedCurrentHeightBlock.getHeader()));
final Prepare expectedPrepareMessage = final Prepare expectedPrepareMessage =
localNodeMessageFactory.createSignedPreparePayload( localNodeMessageFactory.createPrepare(futureHeightRoundId, futureHeightBlock.getHash());
futureHeightRoundId, futureHeightBlock.getHash());
final Commit expectedCommitMessage = final Commit expectedCommitMessage =
new Commit( new Commit(
@ -113,7 +112,7 @@ public class FutureHeightTest {
peers.getNonProposing(0).injectPrepare(roundId, currentHeightBlock.getHash()); peers.getNonProposing(0).injectPrepare(roundId, currentHeightBlock.getHash());
final Prepare expectedPrepareMessage = final Prepare expectedPrepareMessage =
localNodeMessageFactory.createSignedPreparePayload(roundId, currentHeightBlock.getHash()); localNodeMessageFactory.createPrepare(roundId, currentHeightBlock.getHash());
peers.verifyMessagesReceived(expectedPrepareMessage); peers.verifyMessagesReceived(expectedPrepareMessage);
@ -189,8 +188,7 @@ public class FutureHeightTest {
peers.getProposer().injectProposal(nextHeightRoundId, nextHeightBlock); peers.getProposer().injectProposal(nextHeightRoundId, nextHeightBlock);
final Prepare expectedPrepareMessage = final Prepare expectedPrepareMessage =
localNodeMessageFactory.createSignedPreparePayload( localNodeMessageFactory.createPrepare(nextHeightRoundId, nextHeightBlock.getHash());
nextHeightRoundId, nextHeightBlock.getHash());
// Assert ONLY a prepare message was received, not any commits (i.e. futureHeightRoundId // Assert ONLY a prepare message was received, not any commits (i.e. futureHeightRoundId
// messages have not been used. // messages have not been used.
@ -206,8 +204,7 @@ public class FutureHeightTest {
.handleNewBlockEvent(new NewChainHead(signedNextHeightBlock.getHeader())); .handleNewBlockEvent(new NewChainHead(signedNextHeightBlock.getHeader()));
final Prepare expectedFuturePrepareMessage = final Prepare expectedFuturePrepareMessage =
localNodeMessageFactory.createSignedPreparePayload( localNodeMessageFactory.createPrepare(futureHeightRoundId, futureHeightBlock.getHash());
futureHeightRoundId, futureHeightBlock.getHash());
final Commit expectedCommitMessage = final Commit expectedCommitMessage =
new Commit( new Commit(

@ -99,7 +99,7 @@ public class FutureRoundTest {
futureBlock); futureBlock);
final Prepare expectedPrepare = final Prepare expectedPrepare =
localNodeMessageFactory.createSignedPreparePayload(futureRoundId, futureBlock.getHash()); localNodeMessageFactory.createPrepare(futureRoundId, futureBlock.getHash());
peers.verifyMessagesReceived(expectedPrepare); peers.verifyMessagesReceived(expectedPrepare);
@ -107,7 +107,7 @@ public class FutureRoundTest {
futurePeers.getNonProposing(quorum - 3).injectPrepare(futureRoundId, futureBlock.getHash()); futurePeers.getNonProposing(quorum - 3).injectPrepare(futureRoundId, futureBlock.getHash());
final Commit expectedCommit = final Commit expectedCommit =
localNodeMessageFactory.createSignedCommitPayload( localNodeMessageFactory.createCommit(
futureRoundId, futureRoundId,
futureBlock.getHash(), futureBlock.getHash(),
SECP256K1.sign(futureBlock.getHash(), context.getLocalNodeParams().getNodeKeyPair())); SECP256K1.sign(futureBlock.getHash(), context.getLocalNodeParams().getNodeKeyPair()));
@ -143,7 +143,7 @@ public class FutureRoundTest {
futureBlock); futureBlock);
final Prepare expectedFuturePrepare = final Prepare expectedFuturePrepare =
localNodeMessageFactory.createSignedPreparePayload(futureRoundId, futureBlock.getHash()); localNodeMessageFactory.createPrepare(futureRoundId, futureBlock.getHash());
peers.verifyMessagesReceived(expectedFuturePrepare); peers.verifyMessagesReceived(expectedFuturePrepare);
// attempt to complete the previous round // attempt to complete the previous round

@ -74,7 +74,7 @@ public class GossipTest {
@Test @Test
public void gossipMessagesToPeers() { public void gossipMessagesToPeers() {
final Prepare localPrepare = final Prepare localPrepare =
context.getLocalNodeMessageFactory().createSignedPreparePayload(roundId, block.getHash()); context.getLocalNodeMessageFactory().createPrepare(roundId, block.getHash());
peers.verifyNoMessagesReceivedNonProposing(); peers.verifyNoMessagesReceivedNonProposing();
final Proposal proposal = sender.injectProposal(roundId, block); final Proposal proposal = sender.injectProposal(roundId, block);
@ -90,8 +90,7 @@ public class GossipTest {
peers.verifyMessagesReceivedNonPropsing(commit); peers.verifyMessagesReceivedNonPropsing(commit);
peers.verifyNoMessagesReceivedProposer(); peers.verifyNoMessagesReceivedProposer();
final RoundChange roundChange = final RoundChange roundChange = msgFactory.createRoundChange(roundId, Optional.empty());
msgFactory.createSignedRoundChangePayload(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 =
@ -120,7 +119,7 @@ public class GossipTest {
public void messageWithUnknownValidatorIsNotGossiped() { public void messageWithUnknownValidatorIsNotGossiped() {
final KeyPair unknownKeyPair = KeyPair.generate(); final KeyPair unknownKeyPair = KeyPair.generate();
final MessageFactory unknownMsgFactory = new MessageFactory(unknownKeyPair); final MessageFactory unknownMsgFactory = new MessageFactory(unknownKeyPair);
final Proposal unknownProposal = unknownMsgFactory.createSignedProposalPayload(roundId, block); final Proposal unknownProposal = unknownMsgFactory.createProposal(roundId, block);
sender.injectMessage( sender.injectMessage(
ProposalMessageData.create(new Proposal(unknownProposal.getSignedPayload()))); ProposalMessageData.create(new Proposal(unknownProposal.getSignedPayload())));
@ -131,7 +130,7 @@ public class GossipTest {
public void messageIsNotGossipedToSenderOrCreator() { public void messageIsNotGossipedToSenderOrCreator() {
final ValidatorPeer msgCreator = peers.getFirstNonProposer(); final ValidatorPeer msgCreator = peers.getFirstNonProposer();
final MessageFactory peerMsgFactory = msgCreator.getMessageFactory(); final MessageFactory peerMsgFactory = msgCreator.getMessageFactory();
final Proposal proposalFromPeer = peerMsgFactory.createSignedProposalPayload(roundId, block); final Proposal proposalFromPeer = peerMsgFactory.createProposal(roundId, block);
sender.injectMessage(ProposalMessageData.create(proposalFromPeer)); sender.injectMessage(ProposalMessageData.create(proposalFromPeer));
@ -142,7 +141,7 @@ public class GossipTest {
@Test @Test
public void futureMessageIsNotGossipedImmediately() { public void futureMessageIsNotGossipedImmediately() {
ConsensusRoundIdentifier futureRoundId = new ConsensusRoundIdentifier(2, 0); ConsensusRoundIdentifier futureRoundId = new ConsensusRoundIdentifier(2, 0);
msgFactory.createSignedProposalPayload(futureRoundId, block); msgFactory.createProposal(futureRoundId, block);
sender.injectProposal(futureRoundId, block); sender.injectProposal(futureRoundId, block);
peers.verifyNoMessagesReceived(); peers.verifyNoMessagesReceived();

@ -63,8 +63,7 @@ public class LocalNodeIsProposerTest {
@Before @Before
public void setup() { public void setup() {
expectedProposedBlock = context.createBlockForProposalFromChainHead(0, blockTimeStamp); expectedProposedBlock = context.createBlockForProposalFromChainHead(0, blockTimeStamp);
expectedTxProposal = expectedTxProposal = localNodeMessageFactory.createProposal(roundId, expectedProposedBlock);
localNodeMessageFactory.createSignedProposalPayload(roundId, expectedProposedBlock);
expectedTxCommit = expectedTxCommit =
new Commit( new Commit(

@ -50,8 +50,7 @@ public class LocalNodeNotProposerTest {
@Before @Before
public void setup() { public void setup() {
expectedTxPrepare = expectedTxPrepare = localNodeMessageFactory.createPrepare(roundId, blockToPropose.getHash());
localNodeMessageFactory.createSignedPreparePayload(roundId, blockToPropose.getHash());
expectedTxCommit = expectedTxCommit =
new Commit( new Commit(

@ -73,11 +73,11 @@ public class ReceivedNewRoundTest {
new RoundChangeCertificate(roundChanges), new RoundChangeCertificate(roundChanges),
nextProposer nextProposer
.getMessageFactory() .getMessageFactory()
.createSignedProposalPayload(targetRound, blockToPropose) .createProposal(targetRound, blockToPropose)
.getSignedPayload()); .getSignedPayload());
final Prepare expectedPrepare = final Prepare expectedPrepare =
localNodeMessageFactory.createSignedPreparePayload(targetRound, blockToPropose.getHash()); localNodeMessageFactory.createPrepare(targetRound, blockToPropose.getHash());
peers.verifyMessagesReceived(expectedPrepare); peers.verifyMessagesReceived(expectedPrepare);
} }
@ -99,7 +99,7 @@ public class ReceivedNewRoundTest {
new RoundChangeCertificate(roundChanges), new RoundChangeCertificate(roundChanges),
illegalProposer illegalProposer
.getMessageFactory() .getMessageFactory()
.createSignedProposalPayload(nextRoundId, blockToPropose) .createProposal(nextRoundId, blockToPropose)
.getSignedPayload()); .getSignedPayload());
peers.verifyNoMessagesReceived(); peers.verifyNoMessagesReceived();
@ -125,11 +125,11 @@ public class ReceivedNewRoundTest {
peers peers
.getNonProposing(0) .getNonProposing(0)
.getMessageFactory() .getMessageFactory()
.createSignedProposalPayload(nextRoundId, reproposedBlock) .createProposal(nextRoundId, reproposedBlock)
.getSignedPayload()); .getSignedPayload());
peers.verifyMessagesReceived( peers.verifyMessagesReceived(
localNodeMessageFactory.createSignedPreparePayload(nextRoundId, reproposedBlock.getHash())); localNodeMessageFactory.createPrepare(nextRoundId, reproposedBlock.getHash()));
} }
@Test @Test
@ -149,8 +149,7 @@ public class ReceivedNewRoundTest {
final Proposal proposal = final Proposal proposal =
interimRoundProposer interimRoundProposer
.getMessageFactory() .getMessageFactory()
.createSignedProposalPayload( .createProposal(interimRound, context.createBlockForProposalFromChainHead(1, 30));
interimRound, context.createBlockForProposalFromChainHead(1, 30));
interimRoundProposer.injectNewRound( interimRoundProposer.injectNewRound(
interimRound, new RoundChangeCertificate(roundChangePayloads), proposal.getSignedPayload()); interimRound, new RoundChangeCertificate(roundChangePayloads), proposal.getSignedPayload());
@ -179,11 +178,11 @@ public class ReceivedNewRoundTest {
peers peers
.getNonProposing(0) .getNonProposing(0)
.getMessageFactory() .getMessageFactory()
.createSignedProposalPayload(nextRoundId, reproposedBlock) .createProposal(nextRoundId, reproposedBlock)
.getSignedPayload()); .getSignedPayload());
peers.verifyMessagesReceived( peers.verifyMessagesReceived(
localNodeMessageFactory.createSignedPreparePayload(nextRoundId, reproposedBlock.getHash())); localNodeMessageFactory.createPrepare(nextRoundId, reproposedBlock.getHash()));
// Inject a prepare, then re-inject the newRound - then ensure only a single prepare is enough // Inject a prepare, then re-inject the newRound - then ensure only a single prepare is enough
// to trigger a Commit transmission from the local node // to trigger a Commit transmission from the local node
@ -195,7 +194,7 @@ public class ReceivedNewRoundTest {
peers peers
.getNonProposing(0) .getNonProposing(0)
.getMessageFactory() .getMessageFactory()
.createSignedProposalPayload(nextRoundId, reproposedBlock) .createProposal(nextRoundId, reproposedBlock)
.getSignedPayload()); .getSignedPayload());
peers.verifyNoMessagesReceived(); peers.verifyNoMessagesReceived();

@ -77,7 +77,7 @@ public class RoundChangeTest {
// NOTE: The prepare certificate will be empty as insufficient Prepare msgs have been received. // NOTE: The prepare certificate will be empty as insufficient Prepare msgs have been received.
final ConsensusRoundIdentifier targetRound = new ConsensusRoundIdentifier(1, 1); final ConsensusRoundIdentifier targetRound = new ConsensusRoundIdentifier(1, 1);
final RoundChange expectedTxRoundChange = final RoundChange expectedTxRoundChange =
localNodeMessageFactory.createSignedRoundChangePayload(targetRound, empty()); localNodeMessageFactory.createRoundChange(targetRound, empty());
context.getController().handleRoundExpiry(new RoundExpiry(roundId)); context.getController().handleRoundExpiry(new RoundExpiry(roundId));
peers.verifyMessagesReceived(expectedTxRoundChange); peers.verifyMessagesReceived(expectedTxRoundChange);
} }
@ -86,7 +86,7 @@ public class RoundChangeTest {
public void roundChangeHasEmptyCertificateIfNoPrepareMessagesReceived() { public void roundChangeHasEmptyCertificateIfNoPrepareMessagesReceived() {
final ConsensusRoundIdentifier targetRound = new ConsensusRoundIdentifier(1, 1); final ConsensusRoundIdentifier targetRound = new ConsensusRoundIdentifier(1, 1);
final RoundChange expectedTxRoundChange = final RoundChange expectedTxRoundChange =
localNodeMessageFactory.createSignedRoundChangePayload(targetRound, empty()); localNodeMessageFactory.createRoundChange(targetRound, empty());
peers.getProposer().injectProposal(roundId, blockToPropose); peers.getProposer().injectProposal(roundId, blockToPropose);
peers.clearReceivedMessages(); peers.clearReceivedMessages();
@ -101,7 +101,7 @@ public class RoundChangeTest {
// receiving only a single Prepare msg will result in no PreparedCert. // receiving only a single Prepare msg will result in no PreparedCert.
final ConsensusRoundIdentifier targetRound = new ConsensusRoundIdentifier(1, 1); final ConsensusRoundIdentifier targetRound = new ConsensusRoundIdentifier(1, 1);
final RoundChange expectedTxRoundChange = final RoundChange expectedTxRoundChange =
localNodeMessageFactory.createSignedRoundChangePayload(targetRound, empty()); localNodeMessageFactory.createRoundChange(targetRound, empty());
peers.getProposer().injectProposal(roundId, blockToPropose); peers.getProposer().injectProposal(roundId, blockToPropose);
peers.getNonProposing(1).injectPrepare(roundId, blockToPropose.getHash()); peers.getNonProposing(1).injectPrepare(roundId, blockToPropose.getHash());
@ -115,7 +115,7 @@ public class RoundChangeTest {
public void roundChangeHasPopulatedCertificateIfQuorumPrepareMessagesAndProposalAreReceived() { public void roundChangeHasPopulatedCertificateIfQuorumPrepareMessagesAndProposalAreReceived() {
final ConsensusRoundIdentifier targetRound = new ConsensusRoundIdentifier(1, 1); final ConsensusRoundIdentifier targetRound = new ConsensusRoundIdentifier(1, 1);
final Prepare localPrepareMessage = final Prepare localPrepareMessage =
localNodeMessageFactory.createSignedPreparePayload(roundId, blockToPropose.getHash()); localNodeMessageFactory.createPrepare(roundId, blockToPropose.getHash());
final Proposal proposal = peers.getProposer().injectProposal(roundId, blockToPropose); final Proposal proposal = peers.getProposer().injectProposal(roundId, blockToPropose);
peers.clearReceivedMessages(); peers.clearReceivedMessages();
@ -127,7 +127,7 @@ public class RoundChangeTest {
peers.clearReceivedMessages(); peers.clearReceivedMessages();
final RoundChange expectedTxRoundChange = final RoundChange expectedTxRoundChange =
localNodeMessageFactory.createSignedRoundChangePayload( localNodeMessageFactory.createRoundChange(
targetRound, targetRound,
Optional.of( Optional.of(
new TerminatedRoundArtefacts( new TerminatedRoundArtefacts(
@ -150,7 +150,7 @@ public class RoundChangeTest {
final RoundChange rc4 = peers.getProposer().injectRoundChange(targetRound, empty()); final RoundChange rc4 = peers.getProposer().injectRoundChange(targetRound, empty());
final NewRound expectedNewRound = final NewRound expectedNewRound =
localNodeMessageFactory.createSignedNewRoundPayload( localNodeMessageFactory.createNewRound(
targetRound, targetRound,
new RoundChangeCertificate( new RoundChangeCertificate(
Lists.newArrayList( Lists.newArrayList(
@ -159,7 +159,7 @@ public class RoundChangeTest {
rc3.getSignedPayload(), rc3.getSignedPayload(),
rc4.getSignedPayload())), rc4.getSignedPayload())),
localNodeMessageFactory localNodeMessageFactory
.createSignedProposalPayload(targetRound, locallyProposedBlock) .createProposal(targetRound, locallyProposedBlock)
.getSignedPayload()); .getSignedPayload());
peers.verifyMessagesReceived(expectedNewRound); peers.verifyMessagesReceived(expectedNewRound);
@ -204,7 +204,7 @@ public class RoundChangeTest {
targetRound.getRoundNumber(), ARBITRARY_BLOCKTIME); targetRound.getRoundNumber(), ARBITRARY_BLOCKTIME);
final NewRound expectedNewRound = final NewRound expectedNewRound =
localNodeMessageFactory.createSignedNewRoundPayload( localNodeMessageFactory.createNewRound(
targetRound, targetRound,
new RoundChangeCertificate( new RoundChangeCertificate(
Lists.newArrayList( Lists.newArrayList(
@ -213,7 +213,7 @@ public class RoundChangeTest {
rc3.getSignedPayload(), rc3.getSignedPayload(),
rc4.getSignedPayload())), rc4.getSignedPayload())),
localNodeMessageFactory localNodeMessageFactory
.createSignedProposalPayload(targetRound, expectedBlockToPropose) .createProposal(targetRound, expectedBlockToPropose)
.getSignedPayload()); .getSignedPayload());
peers.verifyMessagesReceived(expectedNewRound); peers.verifyMessagesReceived(expectedNewRound);
@ -233,11 +233,11 @@ public class RoundChangeTest {
context.createBlockForProposalFromChainHead(futureRound.getRoundNumber(), blockTimeStamp); context.createBlockForProposalFromChainHead(futureRound.getRoundNumber(), blockTimeStamp);
final NewRound expectedNewRound = final NewRound expectedNewRound =
localNodeMessageFactory.createSignedNewRoundPayload( localNodeMessageFactory.createNewRound(
futureRound, futureRound,
new RoundChangeCertificate(roundChangeMessages), new RoundChangeCertificate(roundChangeMessages),
localNodeMessageFactory localNodeMessageFactory
.createSignedProposalPayload(futureRound, locallyProposedBlock) .createProposal(futureRound, locallyProposedBlock)
.getSignedPayload()); .getSignedPayload());
peers.verifyMessagesReceived(expectedNewRound); peers.verifyMessagesReceived(expectedNewRound);
@ -287,11 +287,11 @@ public class RoundChangeTest {
targetRound.getRoundNumber(), ARBITRARY_BLOCKTIME); targetRound.getRoundNumber(), ARBITRARY_BLOCKTIME);
final NewRound expectedNewRound = final NewRound expectedNewRound =
localNodeMessageFactory.createSignedNewRoundPayload( localNodeMessageFactory.createNewRound(
targetRound, targetRound,
new RoundChangeCertificate(Lists.newArrayList(roundChangeMessages)), new RoundChangeCertificate(Lists.newArrayList(roundChangeMessages)),
localNodeMessageFactory localNodeMessageFactory
.createSignedProposalPayload(targetRound, expectedBlockToPropose) .createProposal(targetRound, expectedBlockToPropose)
.getSignedPayload()); .getSignedPayload());
peers.verifyMessagesReceived(expectedNewRound); peers.verifyMessagesReceived(expectedNewRound);
@ -331,10 +331,7 @@ public class RoundChangeTest {
// create illegal RoundChangeMessage // create illegal RoundChangeMessage
final TerminatedRoundArtefacts illegalTerminatedRoundArtefacts = final TerminatedRoundArtefacts illegalTerminatedRoundArtefacts =
new TerminatedRoundArtefacts( new TerminatedRoundArtefacts(
peers peers.getNonProposing(0).getMessageFactory().createProposal(roundId, blockToPropose),
.getNonProposing(0)
.getMessageFactory()
.createSignedProposalPayload(roundId, blockToPropose),
emptyList()); emptyList());
peers peers

@ -70,9 +70,7 @@ public class SpuriousBehaviourTest {
context.getController().start(); context.getController().start();
expectedPrepare = expectedPrepare =
context context.getLocalNodeMessageFactory().createPrepare(roundId, proposedBlock.getHash());
.getLocalNodeMessageFactory()
.createSignedPreparePayload(roundId, proposedBlock.getHash());
expectedCommit = expectedCommit =
new Commit( new Commit(
createSignedCommitPayload( createSignedCommitPayload(

@ -46,7 +46,7 @@ public class IbftMessageTransmitter {
} }
public void multicastProposal(final ConsensusRoundIdentifier roundIdentifier, final Block block) { public void multicastProposal(final ConsensusRoundIdentifier roundIdentifier, final Block block) {
final Proposal data = messageFactory.createSignedProposalPayload(roundIdentifier, block); final Proposal data = messageFactory.createProposal(roundIdentifier, block);
final ProposalMessageData message = ProposalMessageData.create(data); final ProposalMessageData message = ProposalMessageData.create(data);
@ -54,7 +54,7 @@ public class IbftMessageTransmitter {
} }
public void multicastPrepare(final ConsensusRoundIdentifier roundIdentifier, final Hash digest) { public void multicastPrepare(final ConsensusRoundIdentifier roundIdentifier, final Hash digest) {
final Prepare data = messageFactory.createSignedPreparePayload(roundIdentifier, digest); final Prepare data = messageFactory.createPrepare(roundIdentifier, digest);
final PrepareMessageData message = PrepareMessageData.create(data); final PrepareMessageData message = PrepareMessageData.create(data);
@ -65,8 +65,7 @@ public class IbftMessageTransmitter {
final ConsensusRoundIdentifier roundIdentifier, final ConsensusRoundIdentifier roundIdentifier,
final Hash digest, final Hash digest,
final Signature commitSeal) { final Signature commitSeal) {
final Commit data = final Commit data = messageFactory.createCommit(roundIdentifier, digest, commitSeal);
messageFactory.createSignedCommitPayload(roundIdentifier, digest, commitSeal);
final CommitMessageData message = CommitMessageData.create(data); final CommitMessageData message = CommitMessageData.create(data);
@ -78,7 +77,7 @@ public class IbftMessageTransmitter {
final Optional<TerminatedRoundArtefacts> terminatedRoundArtefacts) { final Optional<TerminatedRoundArtefacts> terminatedRoundArtefacts) {
final RoundChange data = final RoundChange data =
messageFactory.createSignedRoundChangePayload(roundIdentifier, terminatedRoundArtefacts); messageFactory.createRoundChange(roundIdentifier, terminatedRoundArtefacts);
final RoundChangeMessageData message = RoundChangeMessageData.create(data); final RoundChangeMessageData message = RoundChangeMessageData.create(data);
@ -91,8 +90,7 @@ public class IbftMessageTransmitter {
final SignedData<ProposalPayload> proposalPayload) { final SignedData<ProposalPayload> proposalPayload) {
final NewRound signedPayload = final NewRound signedPayload =
messageFactory.createSignedNewRoundPayload( messageFactory.createNewRound(roundIdentifier, roundChangeCertificate, proposalPayload);
roundIdentifier, roundChangeCertificate, proposalPayload);
final NewRoundMessageData message = NewRoundMessageData.create(signedPayload); final NewRoundMessageData message = NewRoundMessageData.create(signedPayload);

@ -37,7 +37,7 @@ public class MessageFactory {
this.validatorKeyPair = validatorKeyPair; this.validatorKeyPair = validatorKeyPair;
} }
public Proposal createSignedProposalPayload( public Proposal createProposal(
final ConsensusRoundIdentifier roundIdentifier, final Block block) { final ConsensusRoundIdentifier roundIdentifier, final Block block) {
final ProposalPayload payload = new ProposalPayload(roundIdentifier, block); final ProposalPayload payload = new ProposalPayload(roundIdentifier, block);
@ -45,15 +45,14 @@ public class MessageFactory {
return new Proposal(createSignedMessage(payload)); return new Proposal(createSignedMessage(payload));
} }
public Prepare createSignedPreparePayload( public Prepare createPrepare(final ConsensusRoundIdentifier roundIdentifier, final Hash digest) {
final ConsensusRoundIdentifier roundIdentifier, final Hash digest) {
final PreparePayload payload = new PreparePayload(roundIdentifier, digest); final PreparePayload payload = new PreparePayload(roundIdentifier, digest);
return new Prepare(createSignedMessage(payload)); return new Prepare(createSignedMessage(payload));
} }
public Commit createSignedCommitPayload( public Commit createCommit(
final ConsensusRoundIdentifier roundIdentifier, final ConsensusRoundIdentifier roundIdentifier,
final Hash digest, final Hash digest,
final Signature commitSeal) { final Signature commitSeal) {
@ -63,7 +62,7 @@ public class MessageFactory {
return new Commit(createSignedMessage(payload)); return new Commit(createSignedMessage(payload));
} }
public RoundChange createSignedRoundChangePayload( public RoundChange createRoundChange(
final ConsensusRoundIdentifier roundIdentifier, final ConsensusRoundIdentifier roundIdentifier,
final Optional<TerminatedRoundArtefacts> terminatedRoundArtefacts) { final Optional<TerminatedRoundArtefacts> terminatedRoundArtefacts) {
@ -75,7 +74,7 @@ public class MessageFactory {
return new RoundChange(createSignedMessage(payload)); return new RoundChange(createSignedMessage(payload));
} }
public NewRound createSignedNewRoundPayload( public NewRound createNewRound(
final ConsensusRoundIdentifier roundIdentifier, final ConsensusRoundIdentifier roundIdentifier,
final RoundChangeCertificate roundChangeCertificate, final RoundChangeCertificate roundChangeCertificate,
final SignedData<ProposalPayload> proposalPayload) { final SignedData<ProposalPayload> proposalPayload) {

@ -143,7 +143,7 @@ public class IbftBlockHeightManager implements BlockHeightManager {
startNewRound(currentRound.getRoundIdentifier().getRoundNumber() + 1); startNewRound(currentRound.getRoundIdentifier().getRoundNumber() + 1);
final RoundChange localRoundChange = final RoundChange localRoundChange =
messageFactory.createSignedRoundChangePayload( messageFactory.createRoundChange(
currentRound.getRoundIdentifier(), latesteTerminatedRoundArtefacts); currentRound.getRoundIdentifier(), latesteTerminatedRoundArtefacts);
transmitter.multicastRoundChange( transmitter.multicastRoundChange(
currentRound.getRoundIdentifier(), latesteTerminatedRoundArtefacts); currentRound.getRoundIdentifier(), latesteTerminatedRoundArtefacts);

@ -89,7 +89,7 @@ public class IbftRound {
transmitter.multicastProposal(roundState.getRoundIdentifier(), block); transmitter.multicastProposal(roundState.getRoundIdentifier(), block);
updateStateWithProposedBlock( updateStateWithProposedBlock(
messageFactory.createSignedProposalPayload(roundState.getRoundIdentifier(), block)); messageFactory.createProposal(roundState.getRoundIdentifier(), block));
} }
public void startRoundWith( public void startRoundWith(
@ -100,7 +100,7 @@ public class IbftRound {
if (!bestBlockFromRoundChange.isPresent()) { if (!bestBlockFromRoundChange.isPresent()) {
LOG.trace("Multicasting NewRound with new block. round={}", roundState.getRoundIdentifier()); LOG.trace("Multicasting NewRound with new block. round={}", roundState.getRoundIdentifier());
final Block block = blockCreator.createBlock(headerTimestamp); final Block block = blockCreator.createBlock(headerTimestamp);
proposal = messageFactory.createSignedProposalPayload(getRoundIdentifier(), block); proposal = messageFactory.createProposal(getRoundIdentifier(), block);
} else { } else {
LOG.trace( LOG.trace(
"Multicasting NewRound from PreparedCertificate. round={}", "Multicasting NewRound from PreparedCertificate. round={}",
@ -120,7 +120,7 @@ public class IbftRound {
block, block,
getRoundIdentifier().getRoundNumber(), getRoundIdentifier().getRoundNumber(),
IbftBlockHashing::calculateDataHashForCommittedSeal); IbftBlockHashing::calculateDataHashForCommittedSeal);
return messageFactory.createSignedProposalPayload(getRoundIdentifier(), blockToPublish); return messageFactory.createProposal(getRoundIdentifier(), blockToPublish);
} }
public void handleProposalMessage(final Proposal msg) { public void handleProposalMessage(final Proposal msg) {
@ -150,8 +150,7 @@ public class IbftRound {
LOG.info("Sending prepare message."); LOG.info("Sending prepare message.");
transmitter.multicastPrepare(getRoundIdentifier(), block.getHash()); transmitter.multicastPrepare(getRoundIdentifier(), block.getHash());
final Prepare localPrepareMessage = final Prepare localPrepareMessage =
messageFactory.createSignedPreparePayload( messageFactory.createPrepare(roundState.getRoundIdentifier(), block.getHash());
roundState.getRoundIdentifier(), block.getHash());
peerIsPrepared(localPrepareMessage); peerIsPrepared(localPrepareMessage);
} }
} }
@ -186,7 +185,7 @@ public class IbftRound {
} }
final Commit localCommitMessage = final Commit localCommitMessage =
messageFactory.createSignedCommitPayload( messageFactory.createCommit(
roundState.getRoundIdentifier(), roundState.getRoundIdentifier(),
msg.getBlock().getHash(), msg.getBlock().getHash(),
createCommitSeal(roundState.getProposedBlock().get())); createCommitSeal(roundState.getProposedBlock().get()));

@ -91,16 +91,15 @@ public class IbftHelpersTest {
final ConsensusRoundIdentifier preparedRound = TestHelpers.createFrom(roundIdentifier, 0, -1); final ConsensusRoundIdentifier preparedRound = TestHelpers.createFrom(roundIdentifier, 0, -1);
final Proposal differentProposal = final Proposal differentProposal =
proposerMessageFactory.createSignedProposalPayload(preparedRound, proposedBlock); proposerMessageFactory.createProposal(preparedRound, proposedBlock);
final Optional<TerminatedRoundArtefacts> latterTerminatedRoundArtefacts = final Optional<TerminatedRoundArtefacts> latterTerminatedRoundArtefacts =
Optional.of( Optional.of(
new TerminatedRoundArtefacts( new TerminatedRoundArtefacts(
differentProposal, differentProposal,
Lists.newArrayList( Lists.newArrayList(
proposerMessageFactory.createSignedPreparePayload( proposerMessageFactory.createPrepare(roundIdentifier, proposedBlock.getHash()),
roundIdentifier, proposedBlock.getHash()), proposerMessageFactory.createPrepare(
proposerMessageFactory.createSignedPreparePayload(
roundIdentifier, proposedBlock.getHash())))); roundIdentifier, proposedBlock.getHash()))));
// An earlier PrepareCert is added to ensure the path to find the latest PrepareCert // An earlier PrepareCert is added to ensure the path to find the latest PrepareCert
@ -108,26 +107,25 @@ public class IbftHelpersTest {
final ConsensusRoundIdentifier earlierPreparedRound = final ConsensusRoundIdentifier earlierPreparedRound =
TestHelpers.createFrom(roundIdentifier, 0, -2); TestHelpers.createFrom(roundIdentifier, 0, -2);
final Proposal earlierProposal = final Proposal earlierProposal =
proposerMessageFactory.createSignedProposalPayload(earlierPreparedRound, proposedBlock); proposerMessageFactory.createProposal(earlierPreparedRound, proposedBlock);
final Optional<TerminatedRoundArtefacts> earlierTerminatedRoundArtefacts = final Optional<TerminatedRoundArtefacts> earlierTerminatedRoundArtefacts =
Optional.of( Optional.of(
new TerminatedRoundArtefacts( new TerminatedRoundArtefacts(
earlierProposal, earlierProposal,
Lists.newArrayList( Lists.newArrayList(
proposerMessageFactory.createSignedPreparePayload( proposerMessageFactory.createPrepare(
earlierPreparedRound, proposedBlock.getHash()), earlierPreparedRound, proposedBlock.getHash()),
proposerMessageFactory.createSignedPreparePayload( proposerMessageFactory.createPrepare(
earlierPreparedRound, proposedBlock.getHash())))); earlierPreparedRound, proposedBlock.getHash()))));
final Optional<PreparedCertificate> newestCert = final Optional<PreparedCertificate> newestCert =
IbftHelpers.findLatestPreparedCertificate( IbftHelpers.findLatestPreparedCertificate(
Lists.newArrayList( Lists.newArrayList(
proposerMessageFactory proposerMessageFactory
.createSignedRoundChangePayload( .createRoundChange(roundIdentifier, earlierTerminatedRoundArtefacts)
roundIdentifier, earlierTerminatedRoundArtefacts)
.getSignedPayload(), .getSignedPayload(),
proposerMessageFactory proposerMessageFactory
.createSignedRoundChangePayload(roundIdentifier, latterTerminatedRoundArtefacts) .createRoundChange(roundIdentifier, latterTerminatedRoundArtefacts)
.getSignedPayload())); .getSignedPayload()));
assertThat(newestCert.get()) assertThat(newestCert.get())
@ -144,10 +142,10 @@ public class IbftHelpersTest {
IbftHelpers.findLatestPreparedCertificate( IbftHelpers.findLatestPreparedCertificate(
Lists.newArrayList( Lists.newArrayList(
proposerMessageFactory proposerMessageFactory
.createSignedRoundChangePayload(roundIdentifier, Optional.empty()) .createRoundChange(roundIdentifier, Optional.empty())
.getSignedPayload(), .getSignedPayload(),
proposerMessageFactory proposerMessageFactory
.createSignedRoundChangePayload(roundIdentifier, Optional.empty()) .createRoundChange(roundIdentifier, Optional.empty())
.getSignedPayload())); .getSignedPayload()));
assertThat(newestCert).isEmpty(); assertThat(newestCert).isEmpty();

@ -72,22 +72,21 @@ public class TestHelpers {
new ConsensusRoundIdentifier(0x1234567890ABCDEFL, round); new ConsensusRoundIdentifier(0x1234567890ABCDEFL, round);
final Block block = final Block block =
TestHelpers.createProposalBlock(singletonList(AddressHelpers.ofValue(1)), 0); TestHelpers.createProposalBlock(singletonList(AddressHelpers.ofValue(1)), 0);
return messageFactory.createSignedProposalPayload(roundIdentifier, block); return messageFactory.createProposal(roundIdentifier, block);
} }
public static Prepare createSignedPreparePayload(final KeyPair signerKeys) { public static Prepare createSignedPreparePayload(final KeyPair signerKeys) {
final MessageFactory messageFactory = new MessageFactory(signerKeys); final MessageFactory messageFactory = new MessageFactory(signerKeys);
final ConsensusRoundIdentifier roundIdentifier = final ConsensusRoundIdentifier roundIdentifier =
new ConsensusRoundIdentifier(0x1234567890ABCDEFL, 0xFEDCBA98); new ConsensusRoundIdentifier(0x1234567890ABCDEFL, 0xFEDCBA98);
return messageFactory.createSignedPreparePayload( return messageFactory.createPrepare(roundIdentifier, Hash.fromHexStringLenient("0"));
roundIdentifier, Hash.fromHexStringLenient("0"));
} }
public static Commit createSignedCommitPayload(final KeyPair signerKeys) { public static Commit createSignedCommitPayload(final KeyPair signerKeys) {
final MessageFactory messageFactory = new MessageFactory(signerKeys); final MessageFactory messageFactory = new MessageFactory(signerKeys);
final ConsensusRoundIdentifier roundIdentifier = final ConsensusRoundIdentifier roundIdentifier =
new ConsensusRoundIdentifier(0x1234567890ABCDEFL, 0xFEDCBA98); new ConsensusRoundIdentifier(0x1234567890ABCDEFL, 0xFEDCBA98);
return messageFactory.createSignedCommitPayload( return messageFactory.createCommit(
roundIdentifier, roundIdentifier,
Hash.fromHexStringLenient("0"), Hash.fromHexStringLenient("0"),
Signature.create(BigInteger.ONE, BigInteger.TEN, (byte) 0)); Signature.create(BigInteger.ONE, BigInteger.TEN, (byte) 0));
@ -97,7 +96,7 @@ public class TestHelpers {
final MessageFactory messageFactory = new MessageFactory(signerKeys); final MessageFactory messageFactory = new MessageFactory(signerKeys);
final ConsensusRoundIdentifier roundIdentifier = final ConsensusRoundIdentifier roundIdentifier =
new ConsensusRoundIdentifier(0x1234567890ABCDEFL, 0xFEDCBA98); new ConsensusRoundIdentifier(0x1234567890ABCDEFL, 0xFEDCBA98);
return messageFactory.createSignedRoundChangePayload(roundIdentifier, Optional.empty()); return messageFactory.createRoundChange(roundIdentifier, Optional.empty());
} }
public static NewRound createSignedNewRoundPayload(final KeyPair signerKeys) { public static NewRound createSignedNewRoundPayload(final KeyPair signerKeys) {
@ -105,7 +104,7 @@ public class TestHelpers {
final ConsensusRoundIdentifier roundIdentifier = final ConsensusRoundIdentifier roundIdentifier =
new ConsensusRoundIdentifier(0x1234567890ABCDEFL, 0xFEDCBA98); new ConsensusRoundIdentifier(0x1234567890ABCDEFL, 0xFEDCBA98);
final Proposal proposalPayload = createSignedProposalPayload(signerKeys); final Proposal proposalPayload = createSignedProposalPayload(signerKeys);
return messageFactory.createSignedNewRoundPayload( return messageFactory.createNewRound(
roundIdentifier, roundIdentifier,
new RoundChangeCertificate(newArrayList()), new RoundChangeCertificate(newArrayList()),
proposalPayload.getSignedPayload()); proposalPayload.getSignedPayload());

@ -216,7 +216,7 @@ public class IbftBlockHeightManagerTest {
public void onRoundChangeReceptionRoundChangeManagerIsInvokedAndNewRoundStarted() { public void onRoundChangeReceptionRoundChangeManagerIsInvokedAndNewRoundStarted() {
final ConsensusRoundIdentifier futureRoundIdentifier = createFrom(roundIdentifier, 0, +2); final ConsensusRoundIdentifier futureRoundIdentifier = createFrom(roundIdentifier, 0, +2);
final RoundChange roundChange = final RoundChange roundChange =
messageFactory.createSignedRoundChangePayload(futureRoundIdentifier, Optional.empty()); messageFactory.createRoundChange(futureRoundIdentifier, Optional.empty());
when(roundChangeManager.appendRoundChangeMessage(any())) when(roundChangeManager.appendRoundChangeMessage(any()))
.thenReturn(Optional.of(singletonList(roundChange))); .thenReturn(Optional.of(singletonList(roundChange)));
when(finalState.isLocalNodeProposerForRound(any())).thenReturn(false); when(finalState.isLocalNodeProposerForRound(any())).thenReturn(false);
@ -260,7 +260,7 @@ public class IbftBlockHeightManagerTest {
public void whenSufficientRoundChangesAreReceivedANewRoundMessageIsTransmitted() { public void whenSufficientRoundChangesAreReceivedANewRoundMessageIsTransmitted() {
final ConsensusRoundIdentifier futureRoundIdentifier = createFrom(roundIdentifier, 0, +2); final ConsensusRoundIdentifier futureRoundIdentifier = createFrom(roundIdentifier, 0, +2);
final RoundChange roundChange = final RoundChange roundChange =
messageFactory.createSignedRoundChangePayload(futureRoundIdentifier, Optional.empty()); messageFactory.createRoundChange(futureRoundIdentifier, Optional.empty());
final RoundChangeCertificate roundChangCert = final RoundChangeCertificate roundChangCert =
new RoundChangeCertificate(singletonList(roundChange.getSignedPayload())); new RoundChangeCertificate(singletonList(roundChange.getSignedPayload()));
@ -301,11 +301,11 @@ public class IbftBlockHeightManagerTest {
final Prepare prepare = final Prepare prepare =
validatorMessageFactory validatorMessageFactory
.get(0) .get(0)
.createSignedPreparePayload(futureRoundIdentifier, Hash.fromHexStringLenient("0")); .createPrepare(futureRoundIdentifier, Hash.fromHexStringLenient("0"));
final Commit commit = final Commit commit =
validatorMessageFactory validatorMessageFactory
.get(1) .get(1)
.createSignedCommitPayload( .createCommit(
futureRoundIdentifier, futureRoundIdentifier,
Hash.fromHexStringLenient("0"), Hash.fromHexStringLenient("0"),
Signature.create(BigInteger.ONE, BigInteger.ONE, (byte) 1)); Signature.create(BigInteger.ONE, BigInteger.ONE, (byte) 1));
@ -315,12 +315,10 @@ public class IbftBlockHeightManagerTest {
// Force a new round to be started at new round number. // Force a new round to be started at new round number.
final NewRound newRound = final NewRound newRound =
messageFactory.createSignedNewRoundPayload( messageFactory.createNewRound(
futureRoundIdentifier, futureRoundIdentifier,
new RoundChangeCertificate(Collections.emptyList()), new RoundChangeCertificate(Collections.emptyList()),
messageFactory messageFactory.createProposal(futureRoundIdentifier, createdBlock).getSignedPayload());
.createSignedProposalPayload(futureRoundIdentifier, createdBlock)
.getSignedPayload());
manager.handleNewRoundPayload(newRound); manager.handleNewRoundPayload(newRound);
@ -345,11 +343,11 @@ public class IbftBlockHeightManagerTest {
final Prepare firstPrepare = final Prepare firstPrepare =
validatorMessageFactory validatorMessageFactory
.get(0) .get(0)
.createSignedPreparePayload(roundIdentifier, Hash.fromHexStringLenient("0")); .createPrepare(roundIdentifier, Hash.fromHexStringLenient("0"));
final Prepare secondPrepare = final Prepare secondPrepare =
validatorMessageFactory validatorMessageFactory
.get(1) .get(1)
.createSignedPreparePayload(roundIdentifier, Hash.fromHexStringLenient("0")); .createPrepare(roundIdentifier, Hash.fromHexStringLenient("0"));
manager.handlePreparePayload(firstPrepare); manager.handlePreparePayload(firstPrepare);
manager.handlePreparePayload(secondPrepare); manager.handlePreparePayload(secondPrepare);

@ -131,8 +131,7 @@ public class IbftRoundTest {
messageFactory, messageFactory,
transmitter); transmitter);
round.handleProposalMessage( round.handleProposalMessage(messageFactory.createProposal(roundIdentifier, proposedBlock));
messageFactory.createSignedProposalPayload(roundIdentifier, proposedBlock));
verify(transmitter, times(1)).multicastPrepare(roundIdentifier, proposedBlock.getHash()); verify(transmitter, times(1)).multicastPrepare(roundIdentifier, proposedBlock.getHash());
verify(transmitter, never()).multicastCommit(any(), any(), any()); verify(transmitter, never()).multicastCommit(any(), any(), any());
} }
@ -197,8 +196,7 @@ public class IbftRoundTest {
final Signature localCommitSeal = SECP256K1.sign(commitSealHash, localNodeKeys); final Signature localCommitSeal = SECP256K1.sign(commitSealHash, localNodeKeys);
// Receive Proposal Message // Receive Proposal Message
round.handleProposalMessage( round.handleProposalMessage(messageFactory.createProposal(roundIdentifier, proposedBlock));
messageFactory.createSignedProposalPayload(roundIdentifier, proposedBlock));
verify(transmitter, times(1)).multicastPrepare(roundIdentifier, proposedBlock.getHash()); verify(transmitter, times(1)).multicastPrepare(roundIdentifier, proposedBlock.getHash());
verify(transmitter, times(1)) verify(transmitter, times(1))
.multicastCommit(roundIdentifier, proposedBlock.getHash(), localCommitSeal); .multicastCommit(roundIdentifier, proposedBlock.getHash(), localCommitSeal);
@ -207,8 +205,7 @@ public class IbftRoundTest {
// Receive Commit Message // Receive Commit Message
round.handleCommitMessage( round.handleCommitMessage(
messageFactory.createSignedCommitPayload( messageFactory.createCommit(roundIdentifier, proposedBlock.getHash(), remoteCommitSeal));
roundIdentifier, proposedBlock.getHash(), remoteCommitSeal));
// Should import block when both commit seals are available. // Should import block when both commit seals are available.
ArgumentCaptor<Block> capturedBlock = ArgumentCaptor.forClass(Block.class); ArgumentCaptor<Block> capturedBlock = ArgumentCaptor.forClass(Block.class);
@ -244,15 +241,14 @@ public class IbftRoundTest {
verify(blockImporter, never()).importBlock(any(), any(), any()); verify(blockImporter, never()).importBlock(any(), any(), any());
round.handlePrepareMessage( round.handlePrepareMessage(
messageFactory.createSignedPreparePayload(roundIdentifier, proposedBlock.getHash())); messageFactory.createPrepare(roundIdentifier, proposedBlock.getHash()));
verify(transmitter, times(1)) verify(transmitter, times(1))
.multicastCommit(roundIdentifier, proposedBlock.getHash(), localCommitSeal); .multicastCommit(roundIdentifier, proposedBlock.getHash(), localCommitSeal);
verify(blockImporter, never()).importBlock(any(), any(), any()); verify(blockImporter, never()).importBlock(any(), any(), any());
round.handleCommitMessage( round.handleCommitMessage(
messageFactory.createSignedCommitPayload( messageFactory.createCommit(roundIdentifier, proposedBlock.getHash(), remoteCommitSeal));
roundIdentifier, proposedBlock.getHash(), remoteCommitSeal));
verify(blockImporter, times(1)).importBlock(any(), any(), any()); verify(blockImporter, times(1)).importBlock(any(), any(), any());
} }
@ -295,12 +291,11 @@ public class IbftRoundTest {
final RoundChangeArtefacts roundChangeArtefacts = final RoundChangeArtefacts roundChangeArtefacts =
RoundChangeArtefacts.create( RoundChangeArtefacts.create(
Collections.singletonList( Collections.singletonList(
messageFactory.createSignedRoundChangePayload( messageFactory.createRoundChange(
roundIdentifier, roundIdentifier,
Optional.of( Optional.of(
new TerminatedRoundArtefacts( new TerminatedRoundArtefacts(
messageFactory.createSignedProposalPayload( messageFactory.createProposal(priorRoundChange, proposedBlock),
priorRoundChange, proposedBlock),
emptyList()))))); emptyList())))));
// NOTE: IbftRound assumes the prepare's are valid // NOTE: IbftRound assumes the prepare's are valid
@ -320,7 +315,7 @@ public class IbftRoundTest {
// Inject a single Prepare message, and confirm the roundState has gone to Prepared (which // Inject a single Prepare message, and confirm the roundState has gone to Prepared (which
// indicates the block has entered the roundState (note: all msgs are deemed valid due to mocks) // indicates the block has entered the roundState (note: all msgs are deemed valid due to mocks)
round.handlePrepareMessage( round.handlePrepareMessage(
messageFactory.createSignedPreparePayload(roundIdentifier, proposedBlock.getHash())); messageFactory.createPrepare(roundIdentifier, proposedBlock.getHash()));
assertThat(roundState.isPrepared()).isTrue(); assertThat(roundState.isPrepared()).isTrue();
} }
@ -340,8 +335,7 @@ public class IbftRoundTest {
final RoundChangeArtefacts roundChangeArtefacts = final RoundChangeArtefacts roundChangeArtefacts =
RoundChangeArtefacts.create( RoundChangeArtefacts.create(
Collections.singletonList( Collections.singletonList(messageFactory.createRoundChange(roundIdentifier, empty())));
messageFactory.createSignedRoundChangePayload(roundIdentifier, empty())));
round.startRoundWith(roundChangeArtefacts, 15); round.startRoundWith(roundChangeArtefacts, 15);
verify(transmitter, times(1)) verify(transmitter, times(1))
@ -353,7 +347,7 @@ public class IbftRoundTest {
// Inject a single Prepare message, and confirm the roundState has gone to Prepared (which // Inject a single Prepare message, and confirm the roundState has gone to Prepared (which
// indicates the block has entered the roundState (note: all msgs are deemed valid due to mocks) // indicates the block has entered the roundState (note: all msgs are deemed valid due to mocks)
round.handlePrepareMessage( round.handlePrepareMessage(
messageFactory.createSignedPreparePayload(roundIdentifier, proposedBlock.getHash())); messageFactory.createPrepare(roundIdentifier, proposedBlock.getHash()));
assertThat(roundState.isPrepared()).isTrue(); assertThat(roundState.isPrepared()).isTrue();
} }
@ -391,11 +385,9 @@ public class IbftRoundTest {
transmitter); transmitter);
round.handleCommitMessage( round.handleCommitMessage(
messageFactory.createSignedCommitPayload( messageFactory.createCommit(roundIdentifier, proposedBlock.getHash(), remoteCommitSeal));
roundIdentifier, proposedBlock.getHash(), remoteCommitSeal));
round.handleProposalMessage( round.handleProposalMessage(messageFactory.createProposal(roundIdentifier, proposedBlock));
messageFactory.createSignedProposalPayload(roundIdentifier, proposedBlock));
verify(blockImporter, times(1)).importBlock(any(), any(), any()); verify(blockImporter, times(1)).importBlock(any(), any(), any());
} }
@ -416,11 +408,9 @@ public class IbftRoundTest {
transmitter); transmitter);
round.handleCommitMessage( round.handleCommitMessage(
messageFactory.createSignedCommitPayload( messageFactory.createCommit(roundIdentifier, proposedBlock.getHash(), remoteCommitSeal));
roundIdentifier, proposedBlock.getHash(), remoteCommitSeal));
round.handleProposalMessage( round.handleProposalMessage(messageFactory.createProposal(roundIdentifier, proposedBlock));
messageFactory.createSignedProposalPayload(roundIdentifier, proposedBlock));
verify(blockImporter, times(1)).importBlock(any(), any(), any()); verify(blockImporter, times(1)).importBlock(any(), any(), any());
} }

@ -126,7 +126,7 @@ public class RoundChangeManagerTest {
private RoundChange makeRoundChangeMessage( private RoundChange makeRoundChangeMessage(
final KeyPair key, final ConsensusRoundIdentifier round) { final KeyPair key, final ConsensusRoundIdentifier round) {
MessageFactory messageFactory = new MessageFactory(key); MessageFactory messageFactory = new MessageFactory(key);
return messageFactory.createSignedRoundChangePayload(round, Optional.empty()); return messageFactory.createRoundChange(round, Optional.empty());
} }
private RoundChange makeRoundChangeMessageWithPreparedCert( private RoundChange makeRoundChangeMessageWithPreparedCert(
@ -140,7 +140,7 @@ public class RoundChangeManagerTest {
final ConsensusRoundIdentifier proposalRound = TestHelpers.createFrom(round, 0, -1); final ConsensusRoundIdentifier proposalRound = TestHelpers.createFrom(round, 0, -1);
final Block block = TestHelpers.createProposalBlock(validators, proposalRound.getRoundNumber()); final Block block = TestHelpers.createProposalBlock(validators, proposalRound.getRoundNumber());
// Proposal must come from an earlier round. // Proposal must come from an earlier round.
final Proposal proposal = messageFactory.createSignedProposalPayload(proposalRound, block); final Proposal proposal = messageFactory.createProposal(proposalRound, block);
final List<Prepare> preparePayloads = final List<Prepare> preparePayloads =
prepareProviders prepareProviders
@ -148,15 +148,14 @@ public class RoundChangeManagerTest {
.map( .map(
k -> { k -> {
final MessageFactory prepareFactory = new MessageFactory(k); final MessageFactory prepareFactory = new MessageFactory(k);
return prepareFactory.createSignedPreparePayload(proposalRound, block.getHash()); return prepareFactory.createPrepare(proposalRound, block.getHash());
}) })
.collect(Collectors.toList()); .collect(Collectors.toList());
final TerminatedRoundArtefacts terminatedRoundArtects = final TerminatedRoundArtefacts terminatedRoundArtects =
new TerminatedRoundArtefacts(proposal, preparePayloads); new TerminatedRoundArtefacts(proposal, preparePayloads);
return messageFactory.createSignedRoundChangePayload( return messageFactory.createRoundChange(round, Optional.of(terminatedRoundArtects));
round, Optional.of(terminatedRoundArtects));
} }
@Test @Test

@ -80,7 +80,7 @@ public class RoundStateTest {
final RoundState roundState = new RoundState(roundIdentifier, 1, messageValidator); final RoundState roundState = new RoundState(roundIdentifier, 1, messageValidator);
final Proposal proposal = final Proposal proposal =
validatorMessageFactories.get(0).createSignedProposalPayload(roundIdentifier, block); validatorMessageFactories.get(0).createProposal(roundIdentifier, block);
assertThat(roundState.setProposedBlock(proposal)).isFalse(); assertThat(roundState.setProposedBlock(proposal)).isFalse();
assertThat(roundState.isPrepared()).isFalse(); assertThat(roundState.isPrepared()).isFalse();
@ -94,7 +94,7 @@ public class RoundStateTest {
final RoundState roundState = new RoundState(roundIdentifier, 1, messageValidator); final RoundState roundState = new RoundState(roundIdentifier, 1, messageValidator);
final Proposal proposal = final Proposal proposal =
validatorMessageFactories.get(0).createSignedProposalPayload(roundIdentifier, block); validatorMessageFactories.get(0).createProposal(roundIdentifier, block);
assertThat(roundState.setProposedBlock(proposal)).isTrue(); assertThat(roundState.setProposedBlock(proposal)).isTrue();
assertThat(roundState.isPrepared()).isTrue(); assertThat(roundState.isPrepared()).isTrue();
@ -117,7 +117,7 @@ public class RoundStateTest {
final RoundState roundState = new RoundState(roundIdentifier, 1, messageValidator); final RoundState roundState = new RoundState(roundIdentifier, 1, messageValidator);
final Proposal proposal = final Proposal proposal =
validatorMessageFactories.get(0).createSignedProposalPayload(roundIdentifier, block); validatorMessageFactories.get(0).createProposal(roundIdentifier, block);
assertThat(roundState.setProposedBlock(proposal)).isTrue(); assertThat(roundState.setProposedBlock(proposal)).isTrue();
assertThat(roundState.isPrepared()).isTrue(); assertThat(roundState.isPrepared()).isTrue();
@ -126,7 +126,7 @@ public class RoundStateTest {
final Commit commit = final Commit commit =
validatorMessageFactories validatorMessageFactories
.get(0) .get(0)
.createSignedCommitPayload( .createCommit(
roundIdentifier, roundIdentifier,
block.getHash(), block.getHash(),
Signature.create(BigInteger.ONE, BigInteger.ONE, (byte) 1)); Signature.create(BigInteger.ONE, BigInteger.ONE, (byte) 1));
@ -145,14 +145,10 @@ public class RoundStateTest {
final RoundState roundState = new RoundState(roundIdentifier, 3, messageValidator); final RoundState roundState = new RoundState(roundIdentifier, 3, messageValidator);
final Prepare firstPrepare = final Prepare firstPrepare =
validatorMessageFactories validatorMessageFactories.get(1).createPrepare(roundIdentifier, block.getHash());
.get(1)
.createSignedPreparePayload(roundIdentifier, block.getHash());
final Prepare secondPrepare = final Prepare secondPrepare =
validatorMessageFactories validatorMessageFactories.get(2).createPrepare(roundIdentifier, block.getHash());
.get(2)
.createSignedPreparePayload(roundIdentifier, block.getHash());
roundState.addPrepareMessage(firstPrepare); roundState.addPrepareMessage(firstPrepare);
assertThat(roundState.isPrepared()).isFalse(); assertThat(roundState.isPrepared()).isFalse();
@ -165,7 +161,7 @@ public class RoundStateTest {
assertThat(roundState.constructTerminatedRoundArtefacts()).isEmpty(); assertThat(roundState.constructTerminatedRoundArtefacts()).isEmpty();
final Proposal proposal = final Proposal proposal =
validatorMessageFactories.get(0).createSignedProposalPayload(roundIdentifier, block); validatorMessageFactories.get(0).createProposal(roundIdentifier, block);
assertThat(roundState.setProposedBlock(proposal)).isTrue(); assertThat(roundState.setProposedBlock(proposal)).isTrue();
assertThat(roundState.isPrepared()).isTrue(); assertThat(roundState.isPrepared()).isTrue();
assertThat(roundState.isCommitted()).isFalse(); assertThat(roundState.isCommitted()).isFalse();
@ -175,14 +171,10 @@ public class RoundStateTest {
@Test @Test
public void invalidPriorPrepareMessagesAreDiscardedUponSubsequentProposal() { public void invalidPriorPrepareMessagesAreDiscardedUponSubsequentProposal() {
final Prepare firstPrepare = final Prepare firstPrepare =
validatorMessageFactories validatorMessageFactories.get(1).createPrepare(roundIdentifier, block.getHash());
.get(1)
.createSignedPreparePayload(roundIdentifier, block.getHash());
final Prepare secondPrepare = final Prepare secondPrepare =
validatorMessageFactories validatorMessageFactories.get(2).createPrepare(roundIdentifier, block.getHash());
.get(2)
.createSignedPreparePayload(roundIdentifier, block.getHash());
// RoundState has a quorum size of 3, meaning 1 proposal and 2 prepare are required to be // RoundState has a quorum size of 3, meaning 1 proposal and 2 prepare are required to be
// 'prepared'. // 'prepared'.
@ -197,7 +189,7 @@ public class RoundStateTest {
verify(messageValidator, never()).validatePrepareMessage(any()); verify(messageValidator, never()).validatePrepareMessage(any());
final Proposal proposal = final Proposal proposal =
validatorMessageFactories.get(0).createSignedProposalPayload(roundIdentifier, block); validatorMessageFactories.get(0).createProposal(roundIdentifier, block);
assertThat(roundState.setProposedBlock(proposal)).isTrue(); assertThat(roundState.setProposedBlock(proposal)).isTrue();
assertThat(roundState.isPrepared()).isFalse(); assertThat(roundState.isPrepared()).isFalse();
@ -210,17 +202,13 @@ public class RoundStateTest {
final RoundState roundState = new RoundState(roundIdentifier, 2, messageValidator); final RoundState roundState = new RoundState(roundIdentifier, 2, messageValidator);
final Prepare firstPrepare = final Prepare firstPrepare =
validatorMessageFactories validatorMessageFactories.get(1).createPrepare(roundIdentifier, block.getHash());
.get(1)
.createSignedPreparePayload(roundIdentifier, block.getHash());
final Prepare secondPrepare = final Prepare secondPrepare =
validatorMessageFactories validatorMessageFactories.get(2).createPrepare(roundIdentifier, block.getHash());
.get(2)
.createSignedPreparePayload(roundIdentifier, block.getHash());
final Proposal proposal = final Proposal proposal =
validatorMessageFactories.get(0).createSignedProposalPayload(roundIdentifier, block); validatorMessageFactories.get(0).createProposal(roundIdentifier, block);
when(messageValidator.addSignedProposalPayload(any())).thenReturn(true); when(messageValidator.addSignedProposalPayload(any())).thenReturn(true);
when(messageValidator.validatePrepareMessage(firstPrepare)).thenReturn(false); when(messageValidator.validatePrepareMessage(firstPrepare)).thenReturn(false);
@ -246,7 +234,7 @@ public class RoundStateTest {
final Commit firstCommit = final Commit firstCommit =
validatorMessageFactories validatorMessageFactories
.get(1) .get(1)
.createSignedCommitPayload( .createCommit(
roundIdentifier, roundIdentifier,
block.getHash(), block.getHash(),
Signature.create(BigInteger.ONE, BigInteger.TEN, (byte) 1)); Signature.create(BigInteger.ONE, BigInteger.TEN, (byte) 1));
@ -254,13 +242,13 @@ public class RoundStateTest {
final Commit secondCommit = final Commit secondCommit =
validatorMessageFactories validatorMessageFactories
.get(2) .get(2)
.createSignedCommitPayload( .createCommit(
roundIdentifier, roundIdentifier,
block.getHash(), block.getHash(),
Signature.create(BigInteger.TEN, BigInteger.TEN, (byte) 1)); Signature.create(BigInteger.TEN, BigInteger.TEN, (byte) 1));
final Proposal proposal = final Proposal proposal =
validatorMessageFactories.get(0).createSignedProposalPayload(roundIdentifier, block); validatorMessageFactories.get(0).createProposal(roundIdentifier, block);
roundState.setProposedBlock(proposal); roundState.setProposedBlock(proposal);
roundState.addCommitMessage(firstCommit); roundState.addCommitMessage(firstCommit);

@ -65,13 +65,12 @@ public class MessageValidatorTest {
@Test @Test
public void messageValidatorDefersToUnderlyingSignedDataValidator() { public void messageValidatorDefersToUnderlyingSignedDataValidator() {
final Proposal proposal = messageFactory.createSignedProposalPayload(roundIdentifier, block); final Proposal proposal = messageFactory.createProposal(roundIdentifier, block);
final Prepare prepare = final Prepare prepare = messageFactory.createPrepare(roundIdentifier, block.getHash());
messageFactory.createSignedPreparePayload(roundIdentifier, block.getHash());
final Commit commit = final Commit commit =
messageFactory.createSignedCommitPayload( messageFactory.createCommit(
roundIdentifier, block.getHash(), SECP256K1.sign(block.getHash(), keyPair)); roundIdentifier, block.getHash(), SECP256K1.sign(block.getHash(), keyPair));
messageValidator.addSignedProposalPayload(proposal); messageValidator.addSignedProposalPayload(proposal);

@ -41,10 +41,10 @@ public class NewRoundMessageValidatorTest {
@Test @Test
public void underlyingPayloadValidatorIsInvokedWithCorrectParameters() { public void underlyingPayloadValidatorIsInvokedWithCorrectParameters() {
final NewRound message = final NewRound message =
messageFactory.createSignedNewRoundPayload( messageFactory.createNewRound(
roundIdentifier, roundIdentifier,
new RoundChangeCertificate(emptyList()), new RoundChangeCertificate(emptyList()),
messageFactory.createSignedProposalPayload(roundIdentifier, block).getSignedPayload()); messageFactory.createProposal(roundIdentifier, block).getSignedPayload());
validator.validateNewRoundMessage(message); validator.validateNewRoundMessage(message);
verify(payloadValidator, times(1)).validateNewRoundMessage(message.getSignedPayload()); verify(payloadValidator, times(1)).validateNewRoundMessage(message.getSignedPayload());

@ -96,21 +96,19 @@ public class NewRoundSignedDataValidatorTest {
final RoundChangeCertificate.Builder builder = new RoundChangeCertificate.Builder(); final RoundChangeCertificate.Builder builder = new RoundChangeCertificate.Builder();
builder.appendRoundChangeMessage( builder.appendRoundChangeMessage(
proposerMessageFactory.createSignedRoundChangePayload(roundIdentifier, Optional.empty())); proposerMessageFactory.createRoundChange(roundIdentifier, Optional.empty()));
return messageCreator.createSignedNewRoundPayload( return messageCreator.createNewRound(
roundIdentifier, roundIdentifier,
builder.buildCertificate(), builder.buildCertificate(),
messageCreator messageCreator.createProposal(roundIdentifier, proposedBlock).getSignedPayload());
.createSignedProposalPayload(roundIdentifier, proposedBlock)
.getSignedPayload());
} }
private NewRound signPayload(final NewRoundPayload payload, final KeyPair signingKey) { private NewRound signPayload(final NewRoundPayload payload, final KeyPair signingKey) {
final MessageFactory messageCreator = new MessageFactory(signingKey); final MessageFactory messageCreator = new MessageFactory(signingKey);
return messageCreator.createSignedNewRoundPayload( return messageCreator.createNewRound(
payload.getRoundIdentifier(), payload.getRoundIdentifier(),
payload.getRoundChangeCertificate(), payload.getRoundChangeCertificate(),
payload.getProposalPayload()); payload.getProposalPayload());
@ -167,17 +165,15 @@ public class NewRoundSignedDataValidatorTest {
final TerminatedRoundArtefacts mismatchedRoundArtefacts = final TerminatedRoundArtefacts mismatchedRoundArtefacts =
new TerminatedRoundArtefacts( new TerminatedRoundArtefacts(
proposerMessageFactory.createSignedProposalPayload(preparedRound, prevProposedBlock), proposerMessageFactory.createProposal(preparedRound, prevProposedBlock),
singletonList( singletonList(
validatorMessageFactory.createSignedPreparePayload( validatorMessageFactory.createPrepare(preparedRound, prevProposedBlock.getHash())));
preparedRound, prevProposedBlock.getHash())));
msgBuilder.setRoundChangeCertificate( msgBuilder.setRoundChangeCertificate(
new RoundChangeCertificate( new RoundChangeCertificate(
singletonList( singletonList(
validatorMessageFactory validatorMessageFactory
.createSignedRoundChangePayload( .createRoundChange(roundIdentifier, Optional.of(mismatchedRoundArtefacts))
roundIdentifier, Optional.of(mismatchedRoundArtefacts))
.getSignedPayload()))); .getSignedPayload())));
final NewRound invalidMsg = signPayload(msgBuilder.build(), proposerKey); final NewRound invalidMsg = signPayload(msgBuilder.build(), proposerKey);
@ -191,9 +187,9 @@ public class NewRoundSignedDataValidatorTest {
final RoundChangeCertificate.Builder roundChangeBuilder = new RoundChangeCertificate.Builder(); final RoundChangeCertificate.Builder roundChangeBuilder = new RoundChangeCertificate.Builder();
roundChangeBuilder.appendRoundChangeMessage( roundChangeBuilder.appendRoundChangeMessage(
proposerMessageFactory.createSignedRoundChangePayload(roundIdentifier, Optional.empty())); proposerMessageFactory.createRoundChange(roundIdentifier, Optional.empty()));
roundChangeBuilder.appendRoundChangeMessage( roundChangeBuilder.appendRoundChangeMessage(
proposerMessageFactory.createSignedRoundChangePayload(prevRound, Optional.empty())); proposerMessageFactory.createRoundChange(prevRound, Optional.empty()));
msgBuilder.setRoundChangeCertificate(roundChangeBuilder.buildCertificate()); msgBuilder.setRoundChangeCertificate(roundChangeBuilder.buildCertificate());
@ -208,13 +204,13 @@ public class NewRoundSignedDataValidatorTest {
final RoundChangeCertificate.Builder roundChangeBuilder = new RoundChangeCertificate.Builder(); final RoundChangeCertificate.Builder roundChangeBuilder = new RoundChangeCertificate.Builder();
roundChangeBuilder.appendRoundChangeMessage( roundChangeBuilder.appendRoundChangeMessage(
proposerMessageFactory.createSignedRoundChangePayload( proposerMessageFactory.createRoundChange(
roundIdentifier, roundIdentifier,
Optional.of( Optional.of(
new TerminatedRoundArtefacts( new TerminatedRoundArtefacts(
proposerMessageFactory.createSignedProposalPayload(prevRound, proposedBlock), proposerMessageFactory.createProposal(prevRound, proposedBlock),
Lists.newArrayList( Lists.newArrayList(
validatorMessageFactory.createSignedPreparePayload( validatorMessageFactory.createPrepare(
prevRound, proposedBlock.getHash())))))); prevRound, proposedBlock.getHash()))))));
msgBuilder.setRoundChangeCertificate(roundChangeBuilder.buildCertificate()); msgBuilder.setRoundChangeCertificate(roundChangeBuilder.buildCertificate());
@ -233,13 +229,13 @@ public class NewRoundSignedDataValidatorTest {
new ConsensusRoundIdentifier( new ConsensusRoundIdentifier(
roundIdentifier.getSequenceNumber(), roundIdentifier.getRoundNumber() - 1); roundIdentifier.getSequenceNumber(), roundIdentifier.getRoundNumber() - 1);
final Proposal latterProposal = final Proposal latterProposal =
proposerMessageFactory.createSignedProposalPayload(latterPrepareRound, proposedBlock); proposerMessageFactory.createProposal(latterPrepareRound, proposedBlock);
final Optional<TerminatedRoundArtefacts> preparedCert = final Optional<TerminatedRoundArtefacts> preparedCert =
Optional.of( Optional.of(
new TerminatedRoundArtefacts( new TerminatedRoundArtefacts(
latterProposal, latterProposal,
Lists.newArrayList( Lists.newArrayList(
validatorMessageFactory.createSignedPreparePayload( validatorMessageFactory.createPrepare(
roundIdentifier, proposedBlock.getHash())))); roundIdentifier, proposedBlock.getHash()))));
// An earlier PrepareCert is added to ensure the path to find the latest PrepareCert // An earlier PrepareCert is added to ensure the path to find the latest PrepareCert
@ -250,34 +246,34 @@ public class NewRoundSignedDataValidatorTest {
new ConsensusRoundIdentifier( new ConsensusRoundIdentifier(
roundIdentifier.getSequenceNumber(), roundIdentifier.getRoundNumber() - 2); roundIdentifier.getSequenceNumber(), roundIdentifier.getRoundNumber() - 2);
final Proposal earlierProposal = final Proposal earlierProposal =
proposerMessageFactory.createSignedProposalPayload(earlierPreparedRound, earlierBlock); proposerMessageFactory.createProposal(earlierPreparedRound, earlierBlock);
final Optional<TerminatedRoundArtefacts> earlierPreparedCert = final Optional<TerminatedRoundArtefacts> earlierPreparedCert =
Optional.of( Optional.of(
new TerminatedRoundArtefacts( new TerminatedRoundArtefacts(
earlierProposal, earlierProposal,
Lists.newArrayList( Lists.newArrayList(
validatorMessageFactory.createSignedPreparePayload( validatorMessageFactory.createPrepare(
earlierPreparedRound, earlierBlock.getHash())))); earlierPreparedRound, earlierBlock.getHash()))));
final RoundChangeCertificate roundChangeCert = final RoundChangeCertificate roundChangeCert =
new RoundChangeCertificate( new RoundChangeCertificate(
Lists.newArrayList( Lists.newArrayList(
proposerMessageFactory proposerMessageFactory
.createSignedRoundChangePayload(roundIdentifier, earlierPreparedCert) .createRoundChange(roundIdentifier, earlierPreparedCert)
.getSignedPayload(), .getSignedPayload(),
validatorMessageFactory validatorMessageFactory
.createSignedRoundChangePayload(roundIdentifier, preparedCert) .createRoundChange(roundIdentifier, preparedCert)
.getSignedPayload())); .getSignedPayload()));
// Ensure a message containing the earlier proposal fails // Ensure a message containing the earlier proposal fails
final NewRound newRoundWithEarlierProposal = final NewRound newRoundWithEarlierProposal =
proposerMessageFactory.createSignedNewRoundPayload( proposerMessageFactory.createNewRound(
roundIdentifier, roundChangeCert, earlierProposal.getSignedPayload()); roundIdentifier, roundChangeCert, earlierProposal.getSignedPayload());
assertThat(validator.validateNewRoundMessage(newRoundWithEarlierProposal.getSignedPayload())) assertThat(validator.validateNewRoundMessage(newRoundWithEarlierProposal.getSignedPayload()))
.isFalse(); .isFalse();
final NewRound newRoundWithLatterProposal = final NewRound newRoundWithLatterProposal =
proposerMessageFactory.createSignedNewRoundPayload( proposerMessageFactory.createNewRound(
roundIdentifier, roundChangeCert, latterProposal.getSignedPayload()); roundIdentifier, roundChangeCert, latterProposal.getSignedPayload());
assertThat(validator.validateNewRoundMessage(newRoundWithLatterProposal.getSignedPayload())) assertThat(validator.validateNewRoundMessage(newRoundWithLatterProposal.getSignedPayload()))
.isTrue(); .isTrue();
@ -287,19 +283,18 @@ public class NewRoundSignedDataValidatorTest {
public void embeddedProposalFailsValidation() { public void embeddedProposalFailsValidation() {
when(signedDataValidator.addSignedProposalPayload(any())).thenReturn(false, true); when(signedDataValidator.addSignedProposalPayload(any())).thenReturn(false, true);
final Proposal proposal = final Proposal proposal = proposerMessageFactory.createProposal(roundIdentifier, proposedBlock);
proposerMessageFactory.createSignedProposalPayload(roundIdentifier, proposedBlock);
final NewRound msg = final NewRound msg =
proposerMessageFactory.createSignedNewRoundPayload( proposerMessageFactory.createNewRound(
roundIdentifier, roundIdentifier,
new RoundChangeCertificate( new RoundChangeCertificate(
Lists.newArrayList( Lists.newArrayList(
proposerMessageFactory proposerMessageFactory
.createSignedRoundChangePayload(roundIdentifier, Optional.empty()) .createRoundChange(roundIdentifier, Optional.empty())
.getSignedPayload(), .getSignedPayload(),
validatorMessageFactory validatorMessageFactory
.createSignedRoundChangePayload(roundIdentifier, Optional.empty()) .createRoundChange(roundIdentifier, Optional.empty())
.getSignedPayload())), .getSignedPayload())),
proposal.getSignedPayload()); proposal.getSignedPayload());

@ -42,8 +42,7 @@ public class RoundChangeMessageValidatorTest {
@Test @Test
public void underlyingPayloadValidatorIsInvokedWithCorrectParameters() { public void underlyingPayloadValidatorIsInvokedWithCorrectParameters() {
final RoundChange message = final RoundChange message = messageFactory.createRoundChange(roundIdentifier, empty());
messageFactory.createSignedRoundChangePayload(roundIdentifier, empty());
validator.validateRoundChange(message); validator.validateRoundChange(message);
verify(payloadValidator, times(1)).validateRoundChange(message.getSignedPayload()); verify(payloadValidator, times(1)).validateRoundChange(message.getSignedPayload());

@ -82,14 +82,13 @@ public class RoundChangeSignedDataValidatorTest {
@Test @Test
public void roundChangeSentByNonValidatorFails() { public void roundChangeSentByNonValidatorFails() {
final RoundChange msg = final RoundChange msg =
nonValidatorMessageFactory.createSignedRoundChangePayload(targetRound, Optional.empty()); nonValidatorMessageFactory.createRoundChange(targetRound, Optional.empty());
assertThat(validator.validateRoundChange(msg.getSignedPayload())).isFalse(); assertThat(validator.validateRoundChange(msg.getSignedPayload())).isFalse();
} }
@Test @Test
public void roundChangeContainingNoCertificateIsSuccessful() { public void roundChangeContainingNoCertificateIsSuccessful() {
final RoundChange msg = final RoundChange msg = proposerMessageFactory.createRoundChange(targetRound, Optional.empty());
proposerMessageFactory.createSignedRoundChangePayload(targetRound, Optional.empty());
assertThat(validator.validateRoundChange(msg.getSignedPayload())).isTrue(); assertThat(validator.validateRoundChange(msg.getSignedPayload())).isTrue();
} }
@ -98,14 +97,13 @@ public class RoundChangeSignedDataValidatorTest {
public void roundChangeContainingInvalidProposalFails() { public void roundChangeContainingInvalidProposalFails() {
final TerminatedRoundArtefacts terminatedRoundArtefacts = final TerminatedRoundArtefacts terminatedRoundArtefacts =
new TerminatedRoundArtefacts( new TerminatedRoundArtefacts(
proposerMessageFactory.createSignedProposalPayload(currentRound, block), proposerMessageFactory.createProposal(currentRound, block), Collections.emptyList());
Collections.emptyList());
final PreparedCertificate prepareCertificate = final PreparedCertificate prepareCertificate =
terminatedRoundArtefacts.getPreparedCertificate(); terminatedRoundArtefacts.getPreparedCertificate();
final RoundChange msg = final RoundChange msg =
proposerMessageFactory.createSignedRoundChangePayload( proposerMessageFactory.createRoundChange(
targetRound, Optional.of(terminatedRoundArtefacts)); targetRound, Optional.of(terminatedRoundArtefacts));
when(basicValidator.addSignedProposalPayload(any())).thenReturn(false); when(basicValidator.addSignedProposalPayload(any())).thenReturn(false);
@ -123,11 +121,10 @@ public class RoundChangeSignedDataValidatorTest {
public void roundChangeContainingValidProposalButNoPrepareMessagesFails() { public void roundChangeContainingValidProposalButNoPrepareMessagesFails() {
final TerminatedRoundArtefacts terminatedRoundArtefacts = final TerminatedRoundArtefacts terminatedRoundArtefacts =
new TerminatedRoundArtefacts( new TerminatedRoundArtefacts(
proposerMessageFactory.createSignedProposalPayload(currentRound, block), proposerMessageFactory.createProposal(currentRound, block), Collections.emptyList());
Collections.emptyList());
final RoundChange msg = final RoundChange msg =
proposerMessageFactory.createSignedRoundChangePayload( proposerMessageFactory.createRoundChange(
targetRound, Optional.of(terminatedRoundArtefacts)); targetRound, Optional.of(terminatedRoundArtefacts));
when(basicValidator.addSignedProposalPayload(any())).thenReturn(true); when(basicValidator.addSignedProposalPayload(any())).thenReturn(true);
@ -136,18 +133,17 @@ public class RoundChangeSignedDataValidatorTest {
@Test @Test
public void roundChangeInvalidPrepareMessageFromProposerFails() { public void roundChangeInvalidPrepareMessageFromProposerFails() {
final Prepare prepareMsg = final Prepare prepareMsg = validatorMessageFactory.createPrepare(currentRound, block.getHash());
validatorMessageFactory.createSignedPreparePayload(currentRound, block.getHash());
final TerminatedRoundArtefacts terminatedRoundArtefacts = final TerminatedRoundArtefacts terminatedRoundArtefacts =
new TerminatedRoundArtefacts( new TerminatedRoundArtefacts(
proposerMessageFactory.createSignedProposalPayload(currentRound, block), proposerMessageFactory.createProposal(currentRound, block),
Lists.newArrayList(prepareMsg)); Lists.newArrayList(prepareMsg));
when(basicValidator.addSignedProposalPayload(any())).thenReturn(true); when(basicValidator.addSignedProposalPayload(any())).thenReturn(true);
when(basicValidator.validatePrepareMessage(any())).thenReturn(false); when(basicValidator.validatePrepareMessage(any())).thenReturn(false);
final RoundChange msg = final RoundChange msg =
proposerMessageFactory.createSignedRoundChangePayload( proposerMessageFactory.createRoundChange(
targetRound, Optional.of(terminatedRoundArtefacts)); targetRound, Optional.of(terminatedRoundArtefacts));
assertThat(validator.validateRoundChange(msg.getSignedPayload())).isFalse(); assertThat(validator.validateRoundChange(msg.getSignedPayload())).isFalse();
@ -162,8 +158,7 @@ public class RoundChangeSignedDataValidatorTest {
new ConsensusRoundIdentifier(currentRound.getSequenceNumber() + 1, 1); new ConsensusRoundIdentifier(currentRound.getSequenceNumber() + 1, 1);
final RoundChange msg = final RoundChange msg =
proposerMessageFactory.createSignedRoundChangePayload( proposerMessageFactory.createRoundChange(latterRoundIdentifier, Optional.empty());
latterRoundIdentifier, Optional.empty());
assertThat(validator.validateRoundChange(msg.getSignedPayload())).isFalse(); assertThat(validator.validateRoundChange(msg.getSignedPayload())).isFalse();
verify(basicValidator, never()).validatePrepareMessage(any()); verify(basicValidator, never()).validatePrepareMessage(any());
@ -175,15 +170,14 @@ public class RoundChangeSignedDataValidatorTest {
new ConsensusRoundIdentifier( new ConsensusRoundIdentifier(
currentRound.getSequenceNumber(), currentRound.getRoundNumber() + 2); currentRound.getSequenceNumber(), currentRound.getRoundNumber() + 2);
final Prepare prepareMsg = final Prepare prepareMsg = validatorMessageFactory.createPrepare(futureRound, block.getHash());
validatorMessageFactory.createSignedPreparePayload(futureRound, block.getHash());
final TerminatedRoundArtefacts terminatedRoundArtefacts = final TerminatedRoundArtefacts terminatedRoundArtefacts =
new TerminatedRoundArtefacts( new TerminatedRoundArtefacts(
proposerMessageFactory.createSignedProposalPayload(futureRound, block), proposerMessageFactory.createProposal(futureRound, block),
Lists.newArrayList(prepareMsg)); Lists.newArrayList(prepareMsg));
final RoundChange msg = final RoundChange msg =
proposerMessageFactory.createSignedRoundChangePayload( proposerMessageFactory.createRoundChange(
targetRound, Optional.of(terminatedRoundArtefacts)); targetRound, Optional.of(terminatedRoundArtefacts));
assertThat(validator.validateRoundChange(msg.getSignedPayload())).isFalse(); assertThat(validator.validateRoundChange(msg.getSignedPayload())).isFalse();
@ -194,18 +188,17 @@ public class RoundChangeSignedDataValidatorTest {
@Test @Test
public void roundChangeWithPastProposalForCurrentHeightIsSuccessful() { public void roundChangeWithPastProposalForCurrentHeightIsSuccessful() {
final Prepare prepareMsg = final Prepare prepareMsg = validatorMessageFactory.createPrepare(currentRound, block.getHash());
validatorMessageFactory.createSignedPreparePayload(currentRound, block.getHash());
final TerminatedRoundArtefacts terminatedRoundArtefacts = final TerminatedRoundArtefacts terminatedRoundArtefacts =
new TerminatedRoundArtefacts( new TerminatedRoundArtefacts(
proposerMessageFactory.createSignedProposalPayload(currentRound, block), proposerMessageFactory.createProposal(currentRound, block),
Lists.newArrayList(prepareMsg)); Lists.newArrayList(prepareMsg));
final PreparedCertificate prepareCertificate = final PreparedCertificate prepareCertificate =
terminatedRoundArtefacts.getPreparedCertificate(); terminatedRoundArtefacts.getPreparedCertificate();
final RoundChange msg = final RoundChange msg =
proposerMessageFactory.createSignedRoundChangePayload( proposerMessageFactory.createRoundChange(
targetRound, Optional.of(terminatedRoundArtefacts)); targetRound, Optional.of(terminatedRoundArtefacts));
when(basicValidator.addSignedProposalPayload(prepareCertificate.getProposalPayload())) when(basicValidator.addSignedProposalPayload(prepareCertificate.getProposalPayload()))

@ -103,8 +103,7 @@ public class SignedDataValidatorTest {
@Test @Test
public void receivingAPrepareMessageBeforeProposalFails() { public void receivingAPrepareMessageBeforeProposalFails() {
final Prepare prepareMsg = final Prepare prepareMsg = proposerMessageFactory.createPrepare(roundIdentifier, Hash.ZERO);
proposerMessageFactory.createSignedPreparePayload(roundIdentifier, Hash.ZERO);
assertThat(validator.validatePrepareMessage(prepareMsg.getSignedPayload())).isFalse(); assertThat(validator.validatePrepareMessage(prepareMsg.getSignedPayload())).isFalse();
} }
@ -112,7 +111,7 @@ public class SignedDataValidatorTest {
@Test @Test
public void receivingACommitMessageBeforeProposalFails() { public void receivingACommitMessageBeforeProposalFails() {
final Commit commitMsg = final Commit commitMsg =
proposerMessageFactory.createSignedCommitPayload( proposerMessageFactory.createCommit(
roundIdentifier, Hash.ZERO, SECP256K1.sign(block.getHash(), proposerKey)); roundIdentifier, Hash.ZERO, SECP256K1.sign(block.getHash(), proposerKey));
assertThat(validator.validateCommmitMessage(commitMsg.getSignedPayload())).isFalse(); assertThat(validator.validateCommmitMessage(commitMsg.getSignedPayload())).isFalse();
@ -121,7 +120,7 @@ public class SignedDataValidatorTest {
@Test @Test
public void receivingProposalMessageFromNonProposerFails() { public void receivingProposalMessageFromNonProposerFails() {
final Proposal proposalMsg = final Proposal proposalMsg =
validatorMessageFactory.createSignedProposalPayload(roundIdentifier, mock(Block.class)); validatorMessageFactory.createProposal(roundIdentifier, mock(Block.class));
assertThat(validator.addSignedProposalPayload(proposalMsg.getSignedPayload())).isFalse(); assertThat(validator.addSignedProposalPayload(proposalMsg.getSignedPayload())).isFalse();
} }
@ -130,18 +129,17 @@ public class SignedDataValidatorTest {
public void receivingProposalMessageWithIllegalBlockFails() { public void receivingProposalMessageWithIllegalBlockFails() {
when(blockValidator.validateAndProcessBlock(any(), any(), any(), any())).thenReturn(empty()); when(blockValidator.validateAndProcessBlock(any(), any(), any(), any())).thenReturn(empty());
final Proposal proposalMsg = final Proposal proposalMsg =
proposerMessageFactory.createSignedProposalPayload(roundIdentifier, mock(Block.class)); proposerMessageFactory.createProposal(roundIdentifier, mock(Block.class));
assertThat(validator.addSignedProposalPayload(proposalMsg.getSignedPayload())).isFalse(); assertThat(validator.addSignedProposalPayload(proposalMsg.getSignedPayload())).isFalse();
} }
@Test @Test
public void receivingPrepareFromProposerFails() { public void receivingPrepareFromProposerFails() {
final Proposal proposalMsg = final Proposal proposalMsg = proposerMessageFactory.createProposal(roundIdentifier, block);
proposerMessageFactory.createSignedProposalPayload(roundIdentifier, block);
final Prepare prepareMsg = final Prepare prepareMsg =
proposerMessageFactory.createSignedPreparePayload(roundIdentifier, block.getHash()); proposerMessageFactory.createPrepare(roundIdentifier, block.getHash());
assertThat(validator.addSignedProposalPayload(proposalMsg.getSignedPayload())).isTrue(); assertThat(validator.addSignedProposalPayload(proposalMsg.getSignedPayload())).isTrue();
assertThat(validator.validatePrepareMessage(prepareMsg.getSignedPayload())).isFalse(); assertThat(validator.validatePrepareMessage(prepareMsg.getSignedPayload())).isFalse();
@ -149,11 +147,10 @@ public class SignedDataValidatorTest {
@Test @Test
public void receivingPrepareFromNonValidatorFails() { public void receivingPrepareFromNonValidatorFails() {
final Proposal proposalMsg = final Proposal proposalMsg = proposerMessageFactory.createProposal(roundIdentifier, block);
proposerMessageFactory.createSignedProposalPayload(roundIdentifier, block);
final Prepare prepareMsg = final Prepare prepareMsg =
nonValidatorMessageFactory.createSignedPreparePayload(roundIdentifier, block.getHash()); nonValidatorMessageFactory.createPrepare(roundIdentifier, block.getHash());
assertThat(validator.addSignedProposalPayload(proposalMsg.getSignedPayload())).isTrue(); assertThat(validator.addSignedProposalPayload(proposalMsg.getSignedPayload())).isTrue();
assertThat(validator.validatePrepareMessage(prepareMsg.getSignedPayload())).isFalse(); assertThat(validator.validatePrepareMessage(prepareMsg.getSignedPayload())).isFalse();
@ -161,16 +158,15 @@ public class SignedDataValidatorTest {
@Test @Test
public void receivingMessagesWithDifferentRoundIdFromProposalFails() { public void receivingMessagesWithDifferentRoundIdFromProposalFails() {
final Proposal proposalMsg = final Proposal proposalMsg = proposerMessageFactory.createProposal(roundIdentifier, block);
proposerMessageFactory.createSignedProposalPayload(roundIdentifier, block);
final ConsensusRoundIdentifier invalidRoundIdentifier = final ConsensusRoundIdentifier invalidRoundIdentifier =
new ConsensusRoundIdentifier( new ConsensusRoundIdentifier(
roundIdentifier.getSequenceNumber(), roundIdentifier.getRoundNumber() + 1); roundIdentifier.getSequenceNumber(), roundIdentifier.getRoundNumber() + 1);
final Prepare prepareMsg = final Prepare prepareMsg =
validatorMessageFactory.createSignedPreparePayload(invalidRoundIdentifier, block.getHash()); validatorMessageFactory.createPrepare(invalidRoundIdentifier, block.getHash());
final Commit commitMsg = final Commit commitMsg =
validatorMessageFactory.createSignedCommitPayload( validatorMessageFactory.createCommit(
invalidRoundIdentifier, block.getHash(), SECP256K1.sign(block.getHash(), proposerKey)); invalidRoundIdentifier, block.getHash(), SECP256K1.sign(block.getHash(), proposerKey));
assertThat(validator.addSignedProposalPayload(proposalMsg.getSignedPayload())).isTrue(); assertThat(validator.addSignedProposalPayload(proposalMsg.getSignedPayload())).isTrue();
@ -180,10 +176,9 @@ public class SignedDataValidatorTest {
@Test @Test
public void receivingPrepareNonProposerValidatorWithCorrectRoundIsSuccessful() { public void receivingPrepareNonProposerValidatorWithCorrectRoundIsSuccessful() {
final Proposal proposalMsg = final Proposal proposalMsg = proposerMessageFactory.createProposal(roundIdentifier, block);
proposerMessageFactory.createSignedProposalPayload(roundIdentifier, block);
final Prepare prepareMsg = final Prepare prepareMsg =
validatorMessageFactory.createSignedPreparePayload(roundIdentifier, block.getHash()); validatorMessageFactory.createPrepare(roundIdentifier, block.getHash());
assertThat(validator.addSignedProposalPayload(proposalMsg.getSignedPayload())).isTrue(); assertThat(validator.addSignedProposalPayload(proposalMsg.getSignedPayload())).isTrue();
assertThat(validator.validatePrepareMessage(prepareMsg.getSignedPayload())).isTrue(); assertThat(validator.validatePrepareMessage(prepareMsg.getSignedPayload())).isTrue();
@ -191,11 +186,10 @@ public class SignedDataValidatorTest {
@Test @Test
public void receivingACommitMessageWithAnInvalidCommitSealFails() { public void receivingACommitMessageWithAnInvalidCommitSealFails() {
final Proposal proposalMsg = final Proposal proposalMsg = proposerMessageFactory.createProposal(roundIdentifier, block);
proposerMessageFactory.createSignedProposalPayload(roundIdentifier, block);
final Commit commitMsg = final Commit commitMsg =
proposerMessageFactory.createSignedCommitPayload( proposerMessageFactory.createCommit(
roundIdentifier, block.getHash(), SECP256K1.sign(block.getHash(), nonValidatorKey)); roundIdentifier, block.getHash(), SECP256K1.sign(block.getHash(), nonValidatorKey));
assertThat(validator.addSignedProposalPayload(proposalMsg.getSignedPayload())).isTrue(); assertThat(validator.addSignedProposalPayload(proposalMsg.getSignedPayload())).isTrue();
@ -204,15 +198,14 @@ public class SignedDataValidatorTest {
@Test @Test
public void commitMessageContainingValidSealFromValidatorIsSuccessful() { public void commitMessageContainingValidSealFromValidatorIsSuccessful() {
final Proposal proposalMsg = final Proposal proposalMsg = proposerMessageFactory.createProposal(roundIdentifier, block);
proposerMessageFactory.createSignedProposalPayload(roundIdentifier, block);
final Commit proposerCommitMsg = final Commit proposerCommitMsg =
proposerMessageFactory.createSignedCommitPayload( proposerMessageFactory.createCommit(
roundIdentifier, block.getHash(), SECP256K1.sign(block.getHash(), proposerKey)); roundIdentifier, block.getHash(), SECP256K1.sign(block.getHash(), proposerKey));
final Commit validatorCommitMsg = final Commit validatorCommitMsg =
validatorMessageFactory.createSignedCommitPayload( validatorMessageFactory.createCommit(
roundIdentifier, block.getHash(), SECP256K1.sign(block.getHash(), validatorKey)); roundIdentifier, block.getHash(), SECP256K1.sign(block.getHash(), validatorKey));
assertThat(validator.addSignedProposalPayload(proposalMsg.getSignedPayload())).isTrue(); assertThat(validator.addSignedProposalPayload(proposalMsg.getSignedPayload())).isTrue();
@ -222,35 +215,32 @@ public class SignedDataValidatorTest {
@Test @Test
public void subsequentProposalHasDifferentSenderFails() { public void subsequentProposalHasDifferentSenderFails() {
final Proposal proposalMsg = final Proposal proposalMsg = proposerMessageFactory.createProposal(roundIdentifier, block);
proposerMessageFactory.createSignedProposalPayload(roundIdentifier, block);
assertThat(validator.addSignedProposalPayload(proposalMsg.getSignedPayload())).isTrue(); assertThat(validator.addSignedProposalPayload(proposalMsg.getSignedPayload())).isTrue();
final Proposal secondProposalMsg = final Proposal secondProposalMsg =
validatorMessageFactory.createSignedProposalPayload(roundIdentifier, block); validatorMessageFactory.createProposal(roundIdentifier, block);
assertThat(validator.addSignedProposalPayload(secondProposalMsg.getSignedPayload())).isFalse(); assertThat(validator.addSignedProposalPayload(secondProposalMsg.getSignedPayload())).isFalse();
} }
@Test @Test
public void subsequentProposalHasDifferentContentFails() { public void subsequentProposalHasDifferentContentFails() {
final Proposal proposalMsg = final Proposal proposalMsg = proposerMessageFactory.createProposal(roundIdentifier, block);
proposerMessageFactory.createSignedProposalPayload(roundIdentifier, block);
assertThat(validator.addSignedProposalPayload(proposalMsg.getSignedPayload())).isTrue(); assertThat(validator.addSignedProposalPayload(proposalMsg.getSignedPayload())).isTrue();
final ConsensusRoundIdentifier newRoundIdentifier = new ConsensusRoundIdentifier(3, 0); final ConsensusRoundIdentifier newRoundIdentifier = new ConsensusRoundIdentifier(3, 0);
final Proposal secondProposalMsg = final Proposal secondProposalMsg =
proposerMessageFactory.createSignedProposalPayload(newRoundIdentifier, block); proposerMessageFactory.createProposal(newRoundIdentifier, block);
assertThat(validator.addSignedProposalPayload(secondProposalMsg.getSignedPayload())).isFalse(); assertThat(validator.addSignedProposalPayload(secondProposalMsg.getSignedPayload())).isFalse();
} }
@Test @Test
public void subsequentProposalHasIdenticalSenderAndContentIsSuccessful() { public void subsequentProposalHasIdenticalSenderAndContentIsSuccessful() {
final Proposal proposalMsg = final Proposal proposalMsg = proposerMessageFactory.createProposal(roundIdentifier, block);
proposerMessageFactory.createSignedProposalPayload(roundIdentifier, block);
assertThat(validator.addSignedProposalPayload(proposalMsg.getSignedPayload())).isTrue(); assertThat(validator.addSignedProposalPayload(proposalMsg.getSignedPayload())).isTrue();
final Proposal secondProposalMsg = final Proposal secondProposalMsg =
proposerMessageFactory.createSignedProposalPayload(roundIdentifier, block); proposerMessageFactory.createProposal(roundIdentifier, block);
assertThat(validator.addSignedProposalPayload(secondProposalMsg.getSignedPayload())).isTrue(); assertThat(validator.addSignedProposalPayload(secondProposalMsg.getSignedPayload())).isTrue();
} }
@ -258,8 +248,7 @@ public class SignedDataValidatorTest {
public void blockRoundMisMatchWithMessageRoundFails() { public void blockRoundMisMatchWithMessageRoundFails() {
insertRoundToBlockHeader(roundIdentifier.getRoundNumber() + 1); insertRoundToBlockHeader(roundIdentifier.getRoundNumber() + 1);
final Proposal proposalMsg = final Proposal proposalMsg = proposerMessageFactory.createProposal(roundIdentifier, block);
proposerMessageFactory.createSignedProposalPayload(roundIdentifier, block);
assertThat(validator.addSignedProposalPayload(proposalMsg.getSignedPayload())).isFalse(); assertThat(validator.addSignedProposalPayload(proposalMsg.getSignedPayload())).isFalse();
} }

Loading…
Cancel
Save