Rename functions in Ibft MessageValidator (#800)

Signed-off-by: Adrian Sutton <adrian.sutton@consensys.net>
pull/2/head
Trent Mohay 6 years ago committed by GitHub
parent e6729b23a0
commit 308985ef8d
  1. 10
      consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/statemachine/RoundState.java
  2. 12
      consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/validation/MessageValidator.java
  3. 2
      consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/validation/NewRoundPayloadValidator.java
  4. 4
      consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/validation/RoundChangePayloadValidator.java
  5. 10
      consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/validation/SignedDataValidator.java
  6. 6
      consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/statemachine/IbftBlockHeightManagerTest.java
  7. 6
      consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/statemachine/IbftRoundTest.java
  8. 30
      consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/statemachine/RoundStateTest.java
  9. 18
      consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/validation/MessageValidatorTest.java
  10. 8
      consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/validation/NewRoundSignedDataValidatorTest.java
  11. 39
      consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/validation/RoundChangeSignedDataValidatorTest.java
  12. 50
      consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/validation/SignedDataValidatorTest.java

@ -65,10 +65,10 @@ public class RoundState {
public boolean setProposedBlock(final Proposal msg) {
if (!proposalMessage.isPresent()) {
if (validator.addSignedProposalPayload(msg)) {
if (validator.validateProposal(msg)) {
proposalMessage = Optional.of(msg);
prepareMessages.removeIf(p -> !validator.validatePrepareMessage(p));
commitMessages.removeIf(p -> !validator.validateCommitMessage(p));
prepareMessages.removeIf(p -> !validator.validatePrepare(p));
commitMessages.removeIf(p -> !validator.validateCommit(p));
updateState();
return true;
}
@ -78,7 +78,7 @@ public class RoundState {
}
public void addPrepareMessage(final Prepare msg) {
if (!proposalMessage.isPresent() || validator.validatePrepareMessage(msg)) {
if (!proposalMessage.isPresent() || validator.validatePrepare(msg)) {
prepareMessages.add(msg);
LOG.debug("Round state added prepare message prepare={}", msg);
}
@ -86,7 +86,7 @@ public class RoundState {
}
public void addCommitMessage(final Commit msg) {
if (!proposalMessage.isPresent() || validator.validateCommitMessage(msg)) {
if (!proposalMessage.isPresent() || validator.validateCommit(msg)) {
commitMessages.add(msg);
LOG.debug("Round state added commit message commit={}", msg);
}

@ -24,15 +24,15 @@ public class MessageValidator {
this.signedDataValidator = signedDataValidator;
}
public boolean addSignedProposalPayload(final Proposal msg) {
return signedDataValidator.addSignedProposalPayload(msg.getSignedPayload());
public boolean validateProposal(final Proposal msg) {
return signedDataValidator.validateProposal(msg.getSignedPayload());
}
public boolean validatePrepareMessage(final Prepare msg) {
return signedDataValidator.validatePrepareMessage(msg.getSignedPayload());
public boolean validatePrepare(final Prepare msg) {
return signedDataValidator.validatePrepare(msg.getSignedPayload());
}
public boolean validateCommitMessage(final Commit msg) {
return signedDataValidator.validateCommmitMessage(msg.getSignedPayload());
public boolean validateCommit(final Commit msg) {
return signedDataValidator.validateCommit(msg.getSignedPayload());
}
}

@ -82,7 +82,7 @@ public class NewRoundPayloadValidator {
final SignedData<ProposalPayload> proposalPayload = payload.getProposalPayload();
final SignedDataValidator proposalValidator =
messageValidatorFactory.createAt(rootRoundIdentifier);
if (!proposalValidator.addSignedProposalPayload(proposalPayload)) {
if (!proposalValidator.validateProposal(proposalPayload)) {
LOG.info("Invalid NewRound message, embedded proposal failed validation");
return false;
}

@ -89,7 +89,7 @@ public class RoundChangePayloadValidator {
private boolean validateConsistencyOfPrepareCertificateMessages(
final PreparedCertificate certificate, final SignedDataValidator signedDataValidator) {
if (!signedDataValidator.addSignedProposalPayload(certificate.getProposalPayload())) {
if (!signedDataValidator.validateProposal(certificate.getProposalPayload())) {
LOG.info("Invalid RoundChange message, embedded Proposal message failed validation.");
return false;
}
@ -102,7 +102,7 @@ public class RoundChangePayloadValidator {
}
for (final SignedData<PreparePayload> prepareMsg : certificate.getPreparePayloads()) {
if (!signedDataValidator.validatePrepareMessage(prepareMsg)) {
if (!signedDataValidator.validatePrepare(prepareMsg)) {
LOG.info("Invalid RoundChange message, embedded Prepare message failed validation.");
return false;
}

@ -60,13 +60,13 @@ public class SignedDataValidator {
this.protocolContext = protocolContext;
}
public boolean addSignedProposalPayload(final SignedData<ProposalPayload> msg) {
public boolean validateProposal(final SignedData<ProposalPayload> msg) {
if (proposal.isPresent()) {
return handleSubsequentProposal(proposal.get(), msg);
}
if (!validateSignedProposalPayload(msg)) {
if (!validateProposalSignedDataPayload(msg)) {
return false;
}
@ -78,7 +78,7 @@ public class SignedDataValidator {
return true;
}
private boolean validateSignedProposalPayload(final SignedData<ProposalPayload> msg) {
private boolean validateProposalSignedDataPayload(final SignedData<ProposalPayload> msg) {
if (!msg.getPayload().getRoundIdentifier().equals(roundIdentifier)) {
LOG.info("Invalid Proposal message, does not match current round.");
@ -124,7 +124,7 @@ public class SignedDataValidator {
return true;
}
public boolean validatePrepareMessage(final SignedData<PreparePayload> msg) {
public boolean validatePrepare(final SignedData<PreparePayload> msg) {
final String msgType = "Prepare";
if (!isMessageForCurrentRoundFromValidatorAndProposalAvailable(msg, msgType)) {
@ -139,7 +139,7 @@ public class SignedDataValidator {
return validateDigestMatchesProposal(msg.getPayload().getDigest(), msgType);
}
public boolean validateCommmitMessage(final SignedData<CommitPayload> msg) {
public boolean validateCommit(final SignedData<CommitPayload> msg) {
final String msgType = "Commit";
if (!isMessageForCurrentRoundFromValidatorAndProposalAvailable(msg, msgType)) {

@ -125,9 +125,9 @@ public class IbftBlockHeightManagerTest {
buildCreatedBlock();
final MessageValidator messageValidator = mock(MessageValidator.class);
when(messageValidator.addSignedProposalPayload(any())).thenReturn(true);
when(messageValidator.validateCommitMessage(any())).thenReturn(true);
when(messageValidator.validatePrepareMessage(any())).thenReturn(true);
when(messageValidator.validateProposal(any())).thenReturn(true);
when(messageValidator.validateCommit(any())).thenReturn(true);
when(messageValidator.validatePrepare(any())).thenReturn(true);
when(finalState.getTransmitter()).thenReturn(messageTransmitter);
when(finalState.getBlockTimer()).thenReturn(blockTimer);
when(finalState.getRoundTimer()).thenReturn(roundTimer);

@ -97,9 +97,9 @@ public class IbftRoundTest {
worldStateArchive,
new IbftContext(new VoteTally(emptyList()), new VoteProposer()));
when(messageValidator.addSignedProposalPayload(any())).thenReturn(true);
when(messageValidator.validatePrepareMessage(any())).thenReturn(true);
when(messageValidator.validateCommitMessage(any())).thenReturn(true);
when(messageValidator.validateProposal(any())).thenReturn(true);
when(messageValidator.validatePrepare(any())).thenReturn(true);
when(messageValidator.validateCommit(any())).thenReturn(true);
proposedExtraData =
new IbftExtraData(BytesValue.wrap(new byte[32]), emptyList(), empty(), 0, emptyList());

@ -76,7 +76,7 @@ public class RoundStateTest {
@Test
public void ifProposalMessageFailsValidationMethodReturnsFalse() {
when(messageValidator.addSignedProposalPayload(any())).thenReturn(false);
when(messageValidator.validateProposal(any())).thenReturn(false);
final RoundState roundState = new RoundState(roundIdentifier, 1, messageValidator);
final Proposal proposal =
@ -90,7 +90,7 @@ public class RoundStateTest {
@Test
public void singleValidatorIsPreparedWithJustProposal() {
when(messageValidator.addSignedProposalPayload(any())).thenReturn(true);
when(messageValidator.validateProposal(any())).thenReturn(true);
final RoundState roundState = new RoundState(roundIdentifier, 1, messageValidator);
final Proposal proposal =
@ -111,8 +111,8 @@ public class RoundStateTest {
@Test
public void singleValidatorRequiresCommitMessageToBeCommitted() {
when(messageValidator.addSignedProposalPayload(any())).thenReturn(true);
when(messageValidator.validateCommitMessage(any())).thenReturn(true);
when(messageValidator.validateProposal(any())).thenReturn(true);
when(messageValidator.validateCommit(any())).thenReturn(true);
final RoundState roundState = new RoundState(roundIdentifier, 1, messageValidator);
@ -139,8 +139,8 @@ public class RoundStateTest {
@Test
public void prepareMessagesCanBeReceivedPriorToProposal() {
when(messageValidator.addSignedProposalPayload(any())).thenReturn(true);
when(messageValidator.validatePrepareMessage(any())).thenReturn(true);
when(messageValidator.validateProposal(any())).thenReturn(true);
when(messageValidator.validatePrepare(any())).thenReturn(true);
final RoundState roundState = new RoundState(roundIdentifier, 3, messageValidator);
@ -180,13 +180,13 @@ public class RoundStateTest {
// 'prepared'.
final RoundState roundState = new RoundState(roundIdentifier, 3, messageValidator);
when(messageValidator.addSignedProposalPayload(any())).thenReturn(true);
when(messageValidator.validatePrepareMessage(firstPrepare)).thenReturn(true);
when(messageValidator.validatePrepareMessage(secondPrepare)).thenReturn(false);
when(messageValidator.validateProposal(any())).thenReturn(true);
when(messageValidator.validatePrepare(firstPrepare)).thenReturn(true);
when(messageValidator.validatePrepare(secondPrepare)).thenReturn(false);
roundState.addPrepareMessage(firstPrepare);
roundState.addPrepareMessage(secondPrepare);
verify(messageValidator, never()).validatePrepareMessage(any());
verify(messageValidator, never()).validatePrepare(any());
final Proposal proposal =
validatorMessageFactories.get(0).createProposal(roundIdentifier, block);
@ -210,9 +210,9 @@ public class RoundStateTest {
final Proposal proposal =
validatorMessageFactories.get(0).createProposal(roundIdentifier, block);
when(messageValidator.addSignedProposalPayload(any())).thenReturn(true);
when(messageValidator.validatePrepareMessage(firstPrepare)).thenReturn(false);
when(messageValidator.validatePrepareMessage(secondPrepare)).thenReturn(true);
when(messageValidator.validateProposal(any())).thenReturn(true);
when(messageValidator.validatePrepare(firstPrepare)).thenReturn(false);
when(messageValidator.validatePrepare(secondPrepare)).thenReturn(true);
roundState.setProposedBlock(proposal);
assertThat(roundState.isPrepared()).isFalse();
@ -226,8 +226,8 @@ public class RoundStateTest {
@Test
public void commitSealsAreExtractedFromReceivedMessages() {
when(messageValidator.addSignedProposalPayload(any())).thenReturn(true);
when(messageValidator.validateCommitMessage(any())).thenReturn(true);
when(messageValidator.validateProposal(any())).thenReturn(true);
when(messageValidator.validateCommit(any())).thenReturn(true);
final RoundState roundState = new RoundState(roundIdentifier, 2, messageValidator);

@ -58,9 +58,9 @@ public class MessageValidatorTest {
@Before
public void setup() {
when(signedDataValidator.addSignedProposalPayload(any())).thenReturn(true);
when(signedDataValidator.validatePrepareMessage(any())).thenReturn(true);
when(signedDataValidator.validateCommmitMessage(any())).thenReturn(true);
when(signedDataValidator.validateProposal(any())).thenReturn(true);
when(signedDataValidator.validatePrepare(any())).thenReturn(true);
when(signedDataValidator.validateCommit(any())).thenReturn(true);
}
@Test
@ -73,13 +73,13 @@ public class MessageValidatorTest {
messageFactory.createCommit(
roundIdentifier, block.getHash(), SECP256K1.sign(block.getHash(), keyPair));
messageValidator.addSignedProposalPayload(proposal);
verify(signedDataValidator, times(1)).addSignedProposalPayload(proposal.getSignedPayload());
messageValidator.validateProposal(proposal);
verify(signedDataValidator, times(1)).validateProposal(proposal.getSignedPayload());
messageValidator.validatePrepareMessage(prepare);
verify(signedDataValidator, times(1)).validatePrepareMessage(prepare.getSignedPayload());
messageValidator.validatePrepare(prepare);
verify(signedDataValidator, times(1)).validatePrepare(prepare.getSignedPayload());
messageValidator.validateCommitMessage(commit);
verify(signedDataValidator, times(1)).validateCommmitMessage(commit.getSignedPayload());
messageValidator.validateCommit(commit);
verify(signedDataValidator, times(1)).validateCommit(commit.getSignedPayload());
}
}

@ -79,8 +79,8 @@ public class NewRoundSignedDataValidatorTest {
when(proposerSelector.selectProposerForRound(any())).thenReturn(proposerAddress);
when(validatorFactory.createAt(any())).thenReturn(signedDataValidator);
when(signedDataValidator.addSignedProposalPayload(any())).thenReturn(true);
when(signedDataValidator.validatePrepareMessage(any())).thenReturn(true);
when(signedDataValidator.validateProposal(any())).thenReturn(true);
when(signedDataValidator.validatePrepare(any())).thenReturn(true);
validator =
new NewRoundPayloadValidator(
@ -216,7 +216,7 @@ public class NewRoundSignedDataValidatorTest {
msgBuilder.setRoundChangeCertificate(roundChangeBuilder.buildCertificate());
// The prepare Message in the RoundChange Cert will be deemed illegal.
when(signedDataValidator.validatePrepareMessage(any())).thenReturn(false);
when(signedDataValidator.validatePrepare(any())).thenReturn(false);
final NewRound msg = signPayload(msgBuilder.build(), proposerKey);
@ -281,7 +281,7 @@ public class NewRoundSignedDataValidatorTest {
@Test
public void embeddedProposalFailsValidation() {
when(signedDataValidator.addSignedProposalPayload(any())).thenReturn(false, true);
when(signedDataValidator.validateProposal(any())).thenReturn(false, true);
final Proposal proposal = proposerMessageFactory.createProposal(roundIdentifier, proposedBlock);

@ -75,8 +75,8 @@ public class RoundChangeSignedDataValidatorTest {
// By default, have all basic messages being valid thus any failures are attributed to logic
// in the RoundChangePayloadValidator
when(basicValidator.addSignedProposalPayload(any())).thenReturn(true);
when(basicValidator.validatePrepareMessage(any())).thenReturn(true);
when(basicValidator.validateProposal(any())).thenReturn(true);
when(basicValidator.validatePrepare(any())).thenReturn(true);
}
@Test
@ -104,15 +104,14 @@ public class RoundChangeSignedDataValidatorTest {
final RoundChange msg =
proposerMessageFactory.createRoundChange(targetRound, Optional.of(preparedRoundArtifacts));
when(basicValidator.addSignedProposalPayload(any())).thenReturn(false);
when(basicValidator.validateProposal(any())).thenReturn(false);
assertThat(validator.validateRoundChange(msg.getSignedPayload())).isFalse();
verify(validatorFactory, times(1))
.createAt(prepareCertificate.getProposalPayload().getPayload().getRoundIdentifier());
verify(basicValidator, times(1))
.addSignedProposalPayload(prepareCertificate.getProposalPayload());
verify(basicValidator, never()).validatePrepareMessage(any());
verify(basicValidator, never()).validateCommmitMessage(any());
verify(basicValidator, times(1)).validateProposal(prepareCertificate.getProposalPayload());
verify(basicValidator, never()).validatePrepare(any());
verify(basicValidator, never()).validateCommit(any());
}
@Test
@ -124,7 +123,7 @@ public class RoundChangeSignedDataValidatorTest {
final RoundChange msg =
proposerMessageFactory.createRoundChange(targetRound, Optional.of(preparedRoundArtifacts));
when(basicValidator.addSignedProposalPayload(any())).thenReturn(true);
when(basicValidator.validateProposal(any())).thenReturn(true);
assertThat(validator.validateRoundChange(msg.getSignedPayload())).isFalse();
}
@ -136,16 +135,16 @@ public class RoundChangeSignedDataValidatorTest {
proposerMessageFactory.createProposal(currentRound, block),
Lists.newArrayList(prepareMsg));
when(basicValidator.addSignedProposalPayload(any())).thenReturn(true);
when(basicValidator.validatePrepareMessage(any())).thenReturn(false);
when(basicValidator.validateProposal(any())).thenReturn(true);
when(basicValidator.validatePrepare(any())).thenReturn(false);
final RoundChange msg =
proposerMessageFactory.createRoundChange(targetRound, Optional.of(preparedRoundArtifacts));
assertThat(validator.validateRoundChange(msg.getSignedPayload())).isFalse();
verify(basicValidator, times(1)).validatePrepareMessage(prepareMsg.getSignedPayload());
verify(basicValidator, never()).validateCommmitMessage(any());
verify(basicValidator, times(1)).validatePrepare(prepareMsg.getSignedPayload());
verify(basicValidator, never()).validateCommit(any());
}
@Test
@ -157,7 +156,7 @@ public class RoundChangeSignedDataValidatorTest {
proposerMessageFactory.createRoundChange(latterRoundIdentifier, Optional.empty());
assertThat(validator.validateRoundChange(msg.getSignedPayload())).isFalse();
verify(basicValidator, never()).validatePrepareMessage(any());
verify(basicValidator, never()).validatePrepare(any());
}
@Test
@ -177,8 +176,8 @@ public class RoundChangeSignedDataValidatorTest {
assertThat(validator.validateRoundChange(msg.getSignedPayload())).isFalse();
verify(validatorFactory, never()).createAt(any());
verify(basicValidator, never()).validatePrepareMessage(prepareMsg.getSignedPayload());
verify(basicValidator, never()).validateCommmitMessage(any());
verify(basicValidator, never()).validatePrepare(prepareMsg.getSignedPayload());
verify(basicValidator, never()).validateCommit(any());
}
@Test
@ -194,15 +193,13 @@ public class RoundChangeSignedDataValidatorTest {
final RoundChange msg =
proposerMessageFactory.createRoundChange(targetRound, Optional.of(preparedRoundArtifacts));
when(basicValidator.addSignedProposalPayload(prepareCertificate.getProposalPayload()))
.thenReturn(true);
when(basicValidator.validatePrepareMessage(prepareMsg.getSignedPayload())).thenReturn(true);
when(basicValidator.validateProposal(prepareCertificate.getProposalPayload())).thenReturn(true);
when(basicValidator.validatePrepare(prepareMsg.getSignedPayload())).thenReturn(true);
assertThat(validator.validateRoundChange(msg.getSignedPayload())).isTrue();
verify(validatorFactory, times(1))
.createAt(prepareCertificate.getProposalPayload().getPayload().getRoundIdentifier());
verify(basicValidator, times(1))
.addSignedProposalPayload(prepareCertificate.getProposalPayload());
verify(basicValidator, times(1)).validatePrepareMessage(prepareMsg.getSignedPayload());
verify(basicValidator, times(1)).validateProposal(prepareCertificate.getProposalPayload());
verify(basicValidator, times(1)).validatePrepare(prepareMsg.getSignedPayload());
}
}

@ -105,7 +105,7 @@ public class SignedDataValidatorTest {
public void receivingAPrepareMessageBeforeProposalFails() {
final Prepare prepareMsg = proposerMessageFactory.createPrepare(roundIdentifier, Hash.ZERO);
assertThat(validator.validatePrepareMessage(prepareMsg.getSignedPayload())).isFalse();
assertThat(validator.validatePrepare(prepareMsg.getSignedPayload())).isFalse();
}
@Test
@ -114,7 +114,7 @@ public class SignedDataValidatorTest {
proposerMessageFactory.createCommit(
roundIdentifier, Hash.ZERO, SECP256K1.sign(block.getHash(), proposerKey));
assertThat(validator.validateCommmitMessage(commitMsg.getSignedPayload())).isFalse();
assertThat(validator.validateCommit(commitMsg.getSignedPayload())).isFalse();
}
@Test
@ -122,7 +122,7 @@ public class SignedDataValidatorTest {
final Proposal proposalMsg =
validatorMessageFactory.createProposal(roundIdentifier, mock(Block.class));
assertThat(validator.addSignedProposalPayload(proposalMsg.getSignedPayload())).isFalse();
assertThat(validator.validateProposal(proposalMsg.getSignedPayload())).isFalse();
}
@Test
@ -131,7 +131,7 @@ public class SignedDataValidatorTest {
final Proposal proposalMsg =
proposerMessageFactory.createProposal(roundIdentifier, mock(Block.class));
assertThat(validator.addSignedProposalPayload(proposalMsg.getSignedPayload())).isFalse();
assertThat(validator.validateProposal(proposalMsg.getSignedPayload())).isFalse();
}
@Test
@ -141,8 +141,8 @@ public class SignedDataValidatorTest {
final Prepare prepareMsg =
proposerMessageFactory.createPrepare(roundIdentifier, block.getHash());
assertThat(validator.addSignedProposalPayload(proposalMsg.getSignedPayload())).isTrue();
assertThat(validator.validatePrepareMessage(prepareMsg.getSignedPayload())).isFalse();
assertThat(validator.validateProposal(proposalMsg.getSignedPayload())).isTrue();
assertThat(validator.validatePrepare(prepareMsg.getSignedPayload())).isFalse();
}
@Test
@ -152,8 +152,8 @@ public class SignedDataValidatorTest {
final Prepare prepareMsg =
nonValidatorMessageFactory.createPrepare(roundIdentifier, block.getHash());
assertThat(validator.addSignedProposalPayload(proposalMsg.getSignedPayload())).isTrue();
assertThat(validator.validatePrepareMessage(prepareMsg.getSignedPayload())).isFalse();
assertThat(validator.validateProposal(proposalMsg.getSignedPayload())).isTrue();
assertThat(validator.validatePrepare(prepareMsg.getSignedPayload())).isFalse();
}
@Test
@ -169,9 +169,9 @@ public class SignedDataValidatorTest {
validatorMessageFactory.createCommit(
invalidRoundIdentifier, block.getHash(), SECP256K1.sign(block.getHash(), proposerKey));
assertThat(validator.addSignedProposalPayload(proposalMsg.getSignedPayload())).isTrue();
assertThat(validator.validatePrepareMessage(prepareMsg.getSignedPayload())).isFalse();
assertThat(validator.validateCommmitMessage(commitMsg.getSignedPayload())).isFalse();
assertThat(validator.validateProposal(proposalMsg.getSignedPayload())).isTrue();
assertThat(validator.validatePrepare(prepareMsg.getSignedPayload())).isFalse();
assertThat(validator.validateCommit(commitMsg.getSignedPayload())).isFalse();
}
@Test
@ -180,8 +180,8 @@ public class SignedDataValidatorTest {
final Prepare prepareMsg =
validatorMessageFactory.createPrepare(roundIdentifier, block.getHash());
assertThat(validator.addSignedProposalPayload(proposalMsg.getSignedPayload())).isTrue();
assertThat(validator.validatePrepareMessage(prepareMsg.getSignedPayload())).isTrue();
assertThat(validator.validateProposal(proposalMsg.getSignedPayload())).isTrue();
assertThat(validator.validatePrepare(prepareMsg.getSignedPayload())).isTrue();
}
@Test
@ -192,8 +192,8 @@ public class SignedDataValidatorTest {
proposerMessageFactory.createCommit(
roundIdentifier, block.getHash(), SECP256K1.sign(block.getHash(), nonValidatorKey));
assertThat(validator.addSignedProposalPayload(proposalMsg.getSignedPayload())).isTrue();
assertThat(validator.validateCommmitMessage(commitMsg.getSignedPayload())).isFalse();
assertThat(validator.validateProposal(proposalMsg.getSignedPayload())).isTrue();
assertThat(validator.validateCommit(commitMsg.getSignedPayload())).isFalse();
}
@Test
@ -208,40 +208,40 @@ public class SignedDataValidatorTest {
validatorMessageFactory.createCommit(
roundIdentifier, block.getHash(), SECP256K1.sign(block.getHash(), validatorKey));
assertThat(validator.addSignedProposalPayload(proposalMsg.getSignedPayload())).isTrue();
assertThat(validator.validateCommmitMessage(proposerCommitMsg.getSignedPayload())).isTrue();
assertThat(validator.validateCommmitMessage(validatorCommitMsg.getSignedPayload())).isTrue();
assertThat(validator.validateProposal(proposalMsg.getSignedPayload())).isTrue();
assertThat(validator.validateCommit(proposerCommitMsg.getSignedPayload())).isTrue();
assertThat(validator.validateCommit(validatorCommitMsg.getSignedPayload())).isTrue();
}
@Test
public void subsequentProposalHasDifferentSenderFails() {
final Proposal proposalMsg = proposerMessageFactory.createProposal(roundIdentifier, block);
assertThat(validator.addSignedProposalPayload(proposalMsg.getSignedPayload())).isTrue();
assertThat(validator.validateProposal(proposalMsg.getSignedPayload())).isTrue();
final Proposal secondProposalMsg =
validatorMessageFactory.createProposal(roundIdentifier, block);
assertThat(validator.addSignedProposalPayload(secondProposalMsg.getSignedPayload())).isFalse();
assertThat(validator.validateProposal(secondProposalMsg.getSignedPayload())).isFalse();
}
@Test
public void subsequentProposalHasDifferentContentFails() {
final Proposal proposalMsg = proposerMessageFactory.createProposal(roundIdentifier, block);
assertThat(validator.addSignedProposalPayload(proposalMsg.getSignedPayload())).isTrue();
assertThat(validator.validateProposal(proposalMsg.getSignedPayload())).isTrue();
final ConsensusRoundIdentifier newRoundIdentifier = new ConsensusRoundIdentifier(3, 0);
final Proposal secondProposalMsg =
proposerMessageFactory.createProposal(newRoundIdentifier, block);
assertThat(validator.addSignedProposalPayload(secondProposalMsg.getSignedPayload())).isFalse();
assertThat(validator.validateProposal(secondProposalMsg.getSignedPayload())).isFalse();
}
@Test
public void subsequentProposalHasIdenticalSenderAndContentIsSuccessful() {
final Proposal proposalMsg = proposerMessageFactory.createProposal(roundIdentifier, block);
assertThat(validator.addSignedProposalPayload(proposalMsg.getSignedPayload())).isTrue();
assertThat(validator.validateProposal(proposalMsg.getSignedPayload())).isTrue();
final Proposal secondProposalMsg =
proposerMessageFactory.createProposal(roundIdentifier, block);
assertThat(validator.addSignedProposalPayload(secondProposalMsg.getSignedPayload())).isTrue();
assertThat(validator.validateProposal(secondProposalMsg.getSignedPayload())).isTrue();
}
@Test
@ -250,6 +250,6 @@ public class SignedDataValidatorTest {
final Proposal proposalMsg = proposerMessageFactory.createProposal(roundIdentifier, block);
assertThat(validator.addSignedProposalPayload(proposalMsg.getSignedPayload())).isFalse();
assertThat(validator.validateProposal(proposalMsg.getSignedPayload())).isFalse();
}
}

Loading…
Cancel
Save