|
|
@ -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(); |
|
|
|
} |
|
|
|
} |
|
|
|