use of org.hyperledger.besu.consensus.ibft.messagewrappers.Commit in project besu by hyperledger.
the class RoundStateTest method singleValidatorRequiresCommitMessageToBeCommitted.
@Test
public void singleValidatorRequiresCommitMessageToBeCommitted() {
when(messageValidator.validateProposal(any())).thenReturn(true);
when(messageValidator.validateCommit(any())).thenReturn(true);
final RoundState roundState = new RoundState(roundIdentifier, 1, messageValidator);
final Proposal proposal = validatorMessageFactories.get(0).createProposal(roundIdentifier, block, Optional.empty());
assertThat(roundState.setProposedBlock(proposal)).isTrue();
assertThat(roundState.isPrepared()).isTrue();
assertThat(roundState.isCommitted()).isFalse();
final Commit commit = validatorMessageFactories.get(0).createCommit(roundIdentifier, block.getHash(), SignatureAlgorithmFactory.getInstance().createSignature(BigInteger.ONE, BigInteger.ONE, (byte) 1));
roundState.addCommitMessage(commit);
assertThat(roundState.isPrepared()).isTrue();
assertThat(roundState.isCommitted()).isTrue();
assertThat(roundState.constructPreparedRoundArtifacts()).isNotEmpty();
}
use of org.hyperledger.besu.consensus.ibft.messagewrappers.Commit in project besu by hyperledger.
the class RoundStateTest method commitSealsAreExtractedFromReceivedMessages.
@Test
public void commitSealsAreExtractedFromReceivedMessages() {
when(messageValidator.validateProposal(any())).thenReturn(true);
when(messageValidator.validateCommit(any())).thenReturn(true);
final RoundState roundState = new RoundState(roundIdentifier, 2, messageValidator);
final SignatureAlgorithm signatureAlgorithm = SignatureAlgorithmFactory.getInstance();
final Commit firstCommit = validatorMessageFactories.get(1).createCommit(roundIdentifier, block.getHash(), signatureAlgorithm.createSignature(BigInteger.ONE, BigInteger.TEN, (byte) 1));
final Commit secondCommit = validatorMessageFactories.get(2).createCommit(roundIdentifier, block.getHash(), signatureAlgorithm.createSignature(BigInteger.TEN, BigInteger.TEN, (byte) 1));
final Proposal proposal = validatorMessageFactories.get(0).createProposal(roundIdentifier, block, Optional.empty());
roundState.setProposedBlock(proposal);
roundState.addCommitMessage(firstCommit);
assertThat(roundState.isCommitted()).isFalse();
roundState.addCommitMessage(secondCommit);
assertThat(roundState.isCommitted()).isTrue();
assertThat(roundState.getCommitSeals()).containsOnly(firstCommit.getCommitSeal(), secondCommit.getCommitSeal());
}
use of org.hyperledger.besu.consensus.ibft.messagewrappers.Commit in project besu by hyperledger.
the class SignedDataValidatorTest method receivingACommitMessageBeforeProposalFails.
@Test
public void receivingACommitMessageBeforeProposalFails() {
final Commit commitMsg = proposerMessageFactory.createCommit(roundIdentifier, Hash.ZERO, proposerKey.sign(block.getHash()));
assertThat(validator.validateCommit(commitMsg.getSignedPayload())).isFalse();
}
use of org.hyperledger.besu.consensus.ibft.messagewrappers.Commit in project besu by hyperledger.
the class SignedDataValidatorTest method commitMessageContainingValidSealFromValidatorIsSuccessful.
@Test
public void commitMessageContainingValidSealFromValidatorIsSuccessful() {
final Proposal proposalMsg = proposerMessageFactory.createProposal(roundIdentifier, block, Optional.empty());
final Commit proposerCommitMsg = proposerMessageFactory.createCommit(roundIdentifier, block.getHash(), proposerKey.sign(block.getHash()));
final Commit validatorCommitMsg = validatorMessageFactory.createCommit(roundIdentifier, block.getHash(), validatorKey.sign(block.getHash()));
assertThat(validator.validateProposal(proposalMsg.getSignedPayload())).isTrue();
assertThat(validator.validateCommit(proposerCommitMsg.getSignedPayload())).isTrue();
assertThat(validator.validateCommit(validatorCommitMsg.getSignedPayload())).isTrue();
}
use of org.hyperledger.besu.consensus.ibft.messagewrappers.Commit in project besu by hyperledger.
the class SignedDataValidatorTest method receivingACommitMessageWithAnInvalidCommitSealFails.
@Test
public void receivingACommitMessageWithAnInvalidCommitSealFails() {
final Proposal proposalMsg = proposerMessageFactory.createProposal(roundIdentifier, block, Optional.empty());
final Commit commitMsg = proposerMessageFactory.createCommit(roundIdentifier, block.getHash(), nonValidatorKey.sign(block.getHash()));
assertThat(validator.validateProposal(proposalMsg.getSignedPayload())).isTrue();
assertThat(validator.validateCommit(commitMsg.getSignedPayload())).isFalse();
}
Aggregations