use of org.hyperledger.besu.consensus.ibft.messagewrappers.Proposal in project besu by hyperledger.
the class IbftBlockHeightManagerTest method illegalFutureRoundProposalDoesNotTriggerNewRound.
@Test
public void illegalFutureRoundProposalDoesNotTriggerNewRound() {
when(futureRoundProposalMessageValidator.validateProposalMessage(any())).thenReturn(false);
final ConsensusRoundIdentifier futureRoundIdentifier = createFrom(roundIdentifier, 0, +2);
final IbftBlockHeightManager manager = new IbftBlockHeightManager(headerTestFixture.buildHeader(), finalState, roundChangeManager, roundFactory, clock, messageValidatorFactory, messageFactory);
// Force a new round to be started at new round number.
final Proposal futureRoundProposal = messageFactory.createProposal(futureRoundIdentifier, createdBlock, Optional.of(new RoundChangeCertificate(Collections.emptyList())));
// Discard the existing createNewRound invocation.
reset(roundFactory);
manager.handleProposalPayload(futureRoundProposal);
verify(roundFactory, never()).createNewRound(any(), anyInt());
}
use of org.hyperledger.besu.consensus.ibft.messagewrappers.Proposal 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.Proposal 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.Proposal in project besu by hyperledger.
the class RoundStateTest method singleValidatorIsPreparedWithJustProposal.
@Test
public void singleValidatorIsPreparedWithJustProposal() {
when(messageValidator.validateProposal(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();
assertThat(roundState.constructPreparedRoundArtifacts()).isNotEmpty();
assertThat(roundState.constructPreparedRoundArtifacts().get().getPreparedCertificate().getProposalPayload()).isEqualTo(proposal.getSignedPayload());
}
use of org.hyperledger.besu.consensus.ibft.messagewrappers.Proposal in project besu by hyperledger.
the class FutureRoundProposalMessageValidatorTest method validProposalMatchingCurrentChainHeightPassesValidation.
@Test
public void validProposalMatchingCurrentChainHeightPassesValidation() {
final Proposal proposal = messageFactoy.createProposal(roundIdentifier, proposedBlock, Optional.empty());
assertThat(validator.validateProposalMessage(proposal)).isTrue();
}
Aggregations