|
|
@ -25,6 +25,7 @@ import tech.pegasys.pantheon.consensus.ibft.messagewrappers.Prepare; |
|
|
|
import tech.pegasys.pantheon.consensus.ibft.messagewrappers.RoundChange; |
|
|
|
import tech.pegasys.pantheon.consensus.ibft.messagewrappers.RoundChange; |
|
|
|
import tech.pegasys.pantheon.consensus.ibft.payload.MessageFactory; |
|
|
|
import tech.pegasys.pantheon.consensus.ibft.payload.MessageFactory; |
|
|
|
import tech.pegasys.pantheon.consensus.ibft.payload.PreparedCertificate; |
|
|
|
import tech.pegasys.pantheon.consensus.ibft.payload.PreparedCertificate; |
|
|
|
|
|
|
|
import tech.pegasys.pantheon.consensus.ibft.statemachine.TerminatedRoundArtefacts; |
|
|
|
import tech.pegasys.pantheon.consensus.ibft.validation.RoundChangeMessageValidator.MessageValidatorForHeightFactory; |
|
|
|
import tech.pegasys.pantheon.consensus.ibft.validation.RoundChangeMessageValidator.MessageValidatorForHeightFactory; |
|
|
|
import tech.pegasys.pantheon.crypto.SECP256K1.KeyPair; |
|
|
|
import tech.pegasys.pantheon.crypto.SECP256K1.KeyPair; |
|
|
|
import tech.pegasys.pantheon.ethereum.core.Address; |
|
|
|
import tech.pegasys.pantheon.ethereum.core.Address; |
|
|
@ -95,16 +96,17 @@ public class RoundChangeSignedDataValidatorTest { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void roundChangeContainingInvalidProposalFails() { |
|
|
|
public void roundChangeContainingInvalidProposalFails() { |
|
|
|
final PreparedCertificate prepareCertificate = |
|
|
|
final TerminatedRoundArtefacts terminatedRoundArtefacts = |
|
|
|
new PreparedCertificate( |
|
|
|
new TerminatedRoundArtefacts( |
|
|
|
proposerMessageFactory |
|
|
|
proposerMessageFactory.createSignedProposalPayload(currentRound, block), |
|
|
|
.createSignedProposalPayload(currentRound, block) |
|
|
|
|
|
|
|
.getSignedPayload(), |
|
|
|
|
|
|
|
Collections.emptyList()); |
|
|
|
Collections.emptyList()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final PreparedCertificate prepareCertificate = |
|
|
|
|
|
|
|
terminatedRoundArtefacts.getPreparedCertificate(); |
|
|
|
|
|
|
|
|
|
|
|
final RoundChange msg = |
|
|
|
final RoundChange msg = |
|
|
|
proposerMessageFactory.createSignedRoundChangePayload( |
|
|
|
proposerMessageFactory.createSignedRoundChangePayload( |
|
|
|
targetRound, Optional.of(prepareCertificate)); |
|
|
|
targetRound, Optional.of(terminatedRoundArtefacts)); |
|
|
|
|
|
|
|
|
|
|
|
when(basicValidator.addSignedProposalPayload(any())).thenReturn(false); |
|
|
|
when(basicValidator.addSignedProposalPayload(any())).thenReturn(false); |
|
|
|
|
|
|
|
|
|
|
@ -119,16 +121,14 @@ public class RoundChangeSignedDataValidatorTest { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void roundChangeContainingValidProposalButNoPrepareMessagesFails() { |
|
|
|
public void roundChangeContainingValidProposalButNoPrepareMessagesFails() { |
|
|
|
final PreparedCertificate prepareCertificate = |
|
|
|
final TerminatedRoundArtefacts terminatedRoundArtefacts = |
|
|
|
new PreparedCertificate( |
|
|
|
new TerminatedRoundArtefacts( |
|
|
|
proposerMessageFactory |
|
|
|
proposerMessageFactory.createSignedProposalPayload(currentRound, block), |
|
|
|
.createSignedProposalPayload(currentRound, block) |
|
|
|
|
|
|
|
.getSignedPayload(), |
|
|
|
|
|
|
|
Collections.emptyList()); |
|
|
|
Collections.emptyList()); |
|
|
|
|
|
|
|
|
|
|
|
final RoundChange msg = |
|
|
|
final RoundChange msg = |
|
|
|
proposerMessageFactory.createSignedRoundChangePayload( |
|
|
|
proposerMessageFactory.createSignedRoundChangePayload( |
|
|
|
targetRound, Optional.of(prepareCertificate)); |
|
|
|
targetRound, Optional.of(terminatedRoundArtefacts)); |
|
|
|
|
|
|
|
|
|
|
|
when(basicValidator.addSignedProposalPayload(any())).thenReturn(true); |
|
|
|
when(basicValidator.addSignedProposalPayload(any())).thenReturn(true); |
|
|
|
assertThat(validator.validateMessage(msg.getSignedPayload())).isFalse(); |
|
|
|
assertThat(validator.validateMessage(msg.getSignedPayload())).isFalse(); |
|
|
@ -138,19 +138,17 @@ public class RoundChangeSignedDataValidatorTest { |
|
|
|
public void roundChangeInvalidPrepareMessageFromProposerFails() { |
|
|
|
public void roundChangeInvalidPrepareMessageFromProposerFails() { |
|
|
|
final Prepare prepareMsg = |
|
|
|
final Prepare prepareMsg = |
|
|
|
validatorMessageFactory.createSignedPreparePayload(currentRound, block.getHash()); |
|
|
|
validatorMessageFactory.createSignedPreparePayload(currentRound, block.getHash()); |
|
|
|
final PreparedCertificate prepareCertificate = |
|
|
|
final TerminatedRoundArtefacts terminatedRoundArtefacts = |
|
|
|
new PreparedCertificate( |
|
|
|
new TerminatedRoundArtefacts( |
|
|
|
proposerMessageFactory |
|
|
|
proposerMessageFactory.createSignedProposalPayload(currentRound, block), |
|
|
|
.createSignedProposalPayload(currentRound, block) |
|
|
|
Lists.newArrayList(prepareMsg)); |
|
|
|
.getSignedPayload(), |
|
|
|
|
|
|
|
Lists.newArrayList(prepareMsg.getSignedPayload())); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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.createSignedRoundChangePayload( |
|
|
|
targetRound, Optional.of(prepareCertificate)); |
|
|
|
targetRound, Optional.of(terminatedRoundArtefacts)); |
|
|
|
|
|
|
|
|
|
|
|
assertThat(validator.validateMessage(msg.getSignedPayload())).isFalse(); |
|
|
|
assertThat(validator.validateMessage(msg.getSignedPayload())).isFalse(); |
|
|
|
|
|
|
|
|
|
|
@ -179,16 +177,14 @@ public class RoundChangeSignedDataValidatorTest { |
|
|
|
|
|
|
|
|
|
|
|
final Prepare prepareMsg = |
|
|
|
final Prepare prepareMsg = |
|
|
|
validatorMessageFactory.createSignedPreparePayload(futureRound, block.getHash()); |
|
|
|
validatorMessageFactory.createSignedPreparePayload(futureRound, block.getHash()); |
|
|
|
final PreparedCertificate prepareCertificate = |
|
|
|
final TerminatedRoundArtefacts terminatedRoundArtefacts = |
|
|
|
new PreparedCertificate( |
|
|
|
new TerminatedRoundArtefacts( |
|
|
|
proposerMessageFactory |
|
|
|
proposerMessageFactory.createSignedProposalPayload(futureRound, block), |
|
|
|
.createSignedProposalPayload(futureRound, block) |
|
|
|
Lists.newArrayList(prepareMsg)); |
|
|
|
.getSignedPayload(), |
|
|
|
|
|
|
|
Lists.newArrayList(prepareMsg.getSignedPayload())); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final RoundChange msg = |
|
|
|
final RoundChange msg = |
|
|
|
proposerMessageFactory.createSignedRoundChangePayload( |
|
|
|
proposerMessageFactory.createSignedRoundChangePayload( |
|
|
|
targetRound, Optional.of(prepareCertificate)); |
|
|
|
targetRound, Optional.of(terminatedRoundArtefacts)); |
|
|
|
|
|
|
|
|
|
|
|
assertThat(validator.validateMessage(msg.getSignedPayload())).isFalse(); |
|
|
|
assertThat(validator.validateMessage(msg.getSignedPayload())).isFalse(); |
|
|
|
verify(validatorFactory, never()).createAt(any()); |
|
|
|
verify(validatorFactory, never()).createAt(any()); |
|
|
@ -200,16 +196,17 @@ public class RoundChangeSignedDataValidatorTest { |
|
|
|
public void roundChangeWithPastProposalForCurrentHeightIsSuccessful() { |
|
|
|
public void roundChangeWithPastProposalForCurrentHeightIsSuccessful() { |
|
|
|
final Prepare prepareMsg = |
|
|
|
final Prepare prepareMsg = |
|
|
|
validatorMessageFactory.createSignedPreparePayload(currentRound, block.getHash()); |
|
|
|
validatorMessageFactory.createSignedPreparePayload(currentRound, block.getHash()); |
|
|
|
|
|
|
|
final TerminatedRoundArtefacts terminatedRoundArtefacts = |
|
|
|
|
|
|
|
new TerminatedRoundArtefacts( |
|
|
|
|
|
|
|
proposerMessageFactory.createSignedProposalPayload(currentRound, block), |
|
|
|
|
|
|
|
Lists.newArrayList(prepareMsg)); |
|
|
|
|
|
|
|
|
|
|
|
final PreparedCertificate prepareCertificate = |
|
|
|
final PreparedCertificate prepareCertificate = |
|
|
|
new PreparedCertificate( |
|
|
|
terminatedRoundArtefacts.getPreparedCertificate(); |
|
|
|
proposerMessageFactory |
|
|
|
|
|
|
|
.createSignedProposalPayload(currentRound, block) |
|
|
|
|
|
|
|
.getSignedPayload(), |
|
|
|
|
|
|
|
Lists.newArrayList(prepareMsg.getSignedPayload())); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final RoundChange msg = |
|
|
|
final RoundChange msg = |
|
|
|
proposerMessageFactory.createSignedRoundChangePayload( |
|
|
|
proposerMessageFactory.createSignedRoundChangePayload( |
|
|
|
targetRound, Optional.of(prepareCertificate)); |
|
|
|
targetRound, Optional.of(terminatedRoundArtefacts)); |
|
|
|
|
|
|
|
|
|
|
|
when(basicValidator.addSignedProposalPayload(prepareCertificate.getProposalPayload())) |
|
|
|
when(basicValidator.addSignedProposalPayload(prepareCertificate.getProposalPayload())) |
|
|
|
.thenReturn(true); |
|
|
|
.thenReturn(true); |
|
|
|