|
|
|
@ -25,7 +25,7 @@ import tech.pegasys.pantheon.consensus.ibft.messagewrappers.Prepare; |
|
|
|
|
import tech.pegasys.pantheon.consensus.ibft.messagewrappers.RoundChange; |
|
|
|
|
import tech.pegasys.pantheon.consensus.ibft.payload.MessageFactory; |
|
|
|
|
import tech.pegasys.pantheon.consensus.ibft.payload.PreparedCertificate; |
|
|
|
|
import tech.pegasys.pantheon.consensus.ibft.statemachine.TerminatedRoundArtefacts; |
|
|
|
|
import tech.pegasys.pantheon.consensus.ibft.statemachine.PreparedRoundArtefacts; |
|
|
|
|
import tech.pegasys.pantheon.consensus.ibft.validation.RoundChangePayloadValidator.MessageValidatorForHeightFactory; |
|
|
|
|
import tech.pegasys.pantheon.crypto.SECP256K1.KeyPair; |
|
|
|
|
import tech.pegasys.pantheon.ethereum.core.Address; |
|
|
|
@ -95,16 +95,14 @@ public class RoundChangeSignedDataValidatorTest { |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void roundChangeContainingInvalidProposalFails() { |
|
|
|
|
final TerminatedRoundArtefacts terminatedRoundArtefacts = |
|
|
|
|
new TerminatedRoundArtefacts( |
|
|
|
|
final PreparedRoundArtefacts preparedRoundArtefacts = |
|
|
|
|
new PreparedRoundArtefacts( |
|
|
|
|
proposerMessageFactory.createProposal(currentRound, block), Collections.emptyList()); |
|
|
|
|
|
|
|
|
|
final PreparedCertificate prepareCertificate = |
|
|
|
|
terminatedRoundArtefacts.getPreparedCertificate(); |
|
|
|
|
final PreparedCertificate prepareCertificate = preparedRoundArtefacts.getPreparedCertificate(); |
|
|
|
|
|
|
|
|
|
final RoundChange msg = |
|
|
|
|
proposerMessageFactory.createRoundChange( |
|
|
|
|
targetRound, Optional.of(terminatedRoundArtefacts)); |
|
|
|
|
proposerMessageFactory.createRoundChange(targetRound, Optional.of(preparedRoundArtefacts)); |
|
|
|
|
|
|
|
|
|
when(basicValidator.addSignedProposalPayload(any())).thenReturn(false); |
|
|
|
|
|
|
|
|
@ -119,13 +117,12 @@ public class RoundChangeSignedDataValidatorTest { |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void roundChangeContainingValidProposalButNoPrepareMessagesFails() { |
|
|
|
|
final TerminatedRoundArtefacts terminatedRoundArtefacts = |
|
|
|
|
new TerminatedRoundArtefacts( |
|
|
|
|
final PreparedRoundArtefacts preparedRoundArtefacts = |
|
|
|
|
new PreparedRoundArtefacts( |
|
|
|
|
proposerMessageFactory.createProposal(currentRound, block), Collections.emptyList()); |
|
|
|
|
|
|
|
|
|
final RoundChange msg = |
|
|
|
|
proposerMessageFactory.createRoundChange( |
|
|
|
|
targetRound, Optional.of(terminatedRoundArtefacts)); |
|
|
|
|
proposerMessageFactory.createRoundChange(targetRound, Optional.of(preparedRoundArtefacts)); |
|
|
|
|
|
|
|
|
|
when(basicValidator.addSignedProposalPayload(any())).thenReturn(true); |
|
|
|
|
assertThat(validator.validateRoundChange(msg.getSignedPayload())).isFalse(); |
|
|
|
@ -134,8 +131,8 @@ public class RoundChangeSignedDataValidatorTest { |
|
|
|
|
@Test |
|
|
|
|
public void roundChangeInvalidPrepareMessageFromProposerFails() { |
|
|
|
|
final Prepare prepareMsg = validatorMessageFactory.createPrepare(currentRound, block.getHash()); |
|
|
|
|
final TerminatedRoundArtefacts terminatedRoundArtefacts = |
|
|
|
|
new TerminatedRoundArtefacts( |
|
|
|
|
final PreparedRoundArtefacts preparedRoundArtefacts = |
|
|
|
|
new PreparedRoundArtefacts( |
|
|
|
|
proposerMessageFactory.createProposal(currentRound, block), |
|
|
|
|
Lists.newArrayList(prepareMsg)); |
|
|
|
|
|
|
|
|
@ -143,8 +140,7 @@ public class RoundChangeSignedDataValidatorTest { |
|
|
|
|
when(basicValidator.validatePrepareMessage(any())).thenReturn(false); |
|
|
|
|
|
|
|
|
|
final RoundChange msg = |
|
|
|
|
proposerMessageFactory.createRoundChange( |
|
|
|
|
targetRound, Optional.of(terminatedRoundArtefacts)); |
|
|
|
|
proposerMessageFactory.createRoundChange(targetRound, Optional.of(preparedRoundArtefacts)); |
|
|
|
|
|
|
|
|
|
assertThat(validator.validateRoundChange(msg.getSignedPayload())).isFalse(); |
|
|
|
|
|
|
|
|
@ -171,14 +167,13 @@ public class RoundChangeSignedDataValidatorTest { |
|
|
|
|
currentRound.getSequenceNumber(), currentRound.getRoundNumber() + 2); |
|
|
|
|
|
|
|
|
|
final Prepare prepareMsg = validatorMessageFactory.createPrepare(futureRound, block.getHash()); |
|
|
|
|
final TerminatedRoundArtefacts terminatedRoundArtefacts = |
|
|
|
|
new TerminatedRoundArtefacts( |
|
|
|
|
final PreparedRoundArtefacts preparedRoundArtefacts = |
|
|
|
|
new PreparedRoundArtefacts( |
|
|
|
|
proposerMessageFactory.createProposal(futureRound, block), |
|
|
|
|
Lists.newArrayList(prepareMsg)); |
|
|
|
|
|
|
|
|
|
final RoundChange msg = |
|
|
|
|
proposerMessageFactory.createRoundChange( |
|
|
|
|
targetRound, Optional.of(terminatedRoundArtefacts)); |
|
|
|
|
proposerMessageFactory.createRoundChange(targetRound, Optional.of(preparedRoundArtefacts)); |
|
|
|
|
|
|
|
|
|
assertThat(validator.validateRoundChange(msg.getSignedPayload())).isFalse(); |
|
|
|
|
verify(validatorFactory, never()).createAt(any()); |
|
|
|
@ -189,17 +184,15 @@ public class RoundChangeSignedDataValidatorTest { |
|
|
|
|
@Test |
|
|
|
|
public void roundChangeWithPastProposalForCurrentHeightIsSuccessful() { |
|
|
|
|
final Prepare prepareMsg = validatorMessageFactory.createPrepare(currentRound, block.getHash()); |
|
|
|
|
final TerminatedRoundArtefacts terminatedRoundArtefacts = |
|
|
|
|
new TerminatedRoundArtefacts( |
|
|
|
|
final PreparedRoundArtefacts preparedRoundArtefacts = |
|
|
|
|
new PreparedRoundArtefacts( |
|
|
|
|
proposerMessageFactory.createProposal(currentRound, block), |
|
|
|
|
Lists.newArrayList(prepareMsg)); |
|
|
|
|
|
|
|
|
|
final PreparedCertificate prepareCertificate = |
|
|
|
|
terminatedRoundArtefacts.getPreparedCertificate(); |
|
|
|
|
final PreparedCertificate prepareCertificate = preparedRoundArtefacts.getPreparedCertificate(); |
|
|
|
|
|
|
|
|
|
final RoundChange msg = |
|
|
|
|
proposerMessageFactory.createRoundChange( |
|
|
|
|
targetRound, Optional.of(terminatedRoundArtefacts)); |
|
|
|
|
proposerMessageFactory.createRoundChange(targetRound, Optional.of(preparedRoundArtefacts)); |
|
|
|
|
|
|
|
|
|
when(basicValidator.addSignedProposalPayload(prepareCertificate.getProposalPayload())) |
|
|
|
|
.thenReturn(true); |
|
|
|
|