use of org.hyperledger.besu.consensus.qbft.messagewrappers.Proposal in project besu by hyperledger.
the class RoundStateTest method invalidPriorPrepareMessagesAreDiscardedUponSubsequentProposal.
@Test
public void invalidPriorPrepareMessagesAreDiscardedUponSubsequentProposal() {
final Prepare firstPrepare = validatorMessageFactories.get(1).createPrepare(roundIdentifier, block.getHash());
final Prepare secondPrepare = validatorMessageFactories.get(2).createPrepare(roundIdentifier, block.getHash());
// RoundState has a quorum size of 3, meaning 1 proposal and 2 prepare are required to be
// 'prepared'.
final RoundState roundState = new RoundState(roundIdentifier, 3, messageValidator);
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()).validatePrepare(any());
final Proposal proposal = validatorMessageFactories.get(0).createProposal(roundIdentifier, block, Collections.emptyList(), Collections.emptyList());
assertThat(roundState.setProposedBlock(proposal)).isTrue();
assertThat(roundState.isPrepared()).isFalse();
assertThat(roundState.isCommitted()).isFalse();
assertThat(roundState.constructPreparedCertificate()).isEmpty();
}
use of org.hyperledger.besu.consensus.qbft.messagewrappers.Proposal in project besu by hyperledger.
the class RoundStateTest method ifProposalMessageFailsValidationMethodReturnsFalse.
@Test
public void ifProposalMessageFailsValidationMethodReturnsFalse() {
when(messageValidator.validateProposal(any())).thenReturn(false);
final RoundState roundState = new RoundState(roundIdentifier, 1, messageValidator);
final Proposal proposal = validatorMessageFactories.get(0).createProposal(roundIdentifier, block, Collections.emptyList(), Collections.emptyList());
assertThat(roundState.setProposedBlock(proposal)).isFalse();
assertThat(roundState.isPrepared()).isFalse();
assertThat(roundState.isCommitted()).isFalse();
assertThat(roundState.constructPreparedCertificate()).isEmpty();
}
use of org.hyperledger.besu.consensus.qbft.messagewrappers.Proposal in project besu by hyperledger.
the class ProposalPayloadValidatorTest method validationFailsWhenExpectedProposerDoesNotMatchPayloadsAuthor.
@Test
public void validationFailsWhenExpectedProposerDoesNotMatchPayloadsAuthor() {
final ProposalPayloadValidator payloadValidator = new ProposalPayloadValidator(Address.fromHexString("0x1"), roundIdentifier, blockValidator, protocolContext, bftExtraDataCodec);
final Block block = ProposedBlockHelpers.createProposalBlock(emptyList(), roundIdentifier);
final Proposal proposal = messageFactory.createProposal(roundIdentifier, block, emptyList(), emptyList());
assertThat(payloadValidator.validate(proposal.getSignedPayload())).isFalse();
verifyNoMoreInteractions(blockValidator);
}
use of org.hyperledger.besu.consensus.qbft.messagewrappers.Proposal in project besu by hyperledger.
the class ProposalPayloadValidatorTest method validationFailsWhenMessageMismatchesExpectedHeight.
@Test
public void validationFailsWhenMessageMismatchesExpectedHeight() {
final ProposalPayloadValidator payloadValidator = new ProposalPayloadValidator(expectedProposer, roundIdentifier, blockValidator, protocolContext, bftExtraDataCodec);
final Block block = ProposedBlockHelpers.createProposalBlock(emptyList(), roundIdentifier);
final Proposal proposal = messageFactory.createProposal(ConsensusRoundHelpers.createFrom(roundIdentifier, +1, 0), block, emptyList(), emptyList());
assertThat(payloadValidator.validate(proposal.getSignedPayload())).isFalse();
verifyNoMoreInteractions(blockValidator);
}
use of org.hyperledger.besu.consensus.qbft.messagewrappers.Proposal in project besu by hyperledger.
the class ProposalValidatorTest method validationFailsIfPiggybackedRoundChangePayloadHasDuplicatedAuthors.
@Test
public void validationFailsIfPiggybackedRoundChangePayloadHasDuplicatedAuthors() {
final RoundSpecificItems roundItem = roundItems.get(ROUND_ID.ONE);
final List<SignedData<RoundChangePayload>> roundChanges = createEmptyRoundChangePayloads(roundItem.roundIdentifier, validators.getNode(0), validators.getNode(1), validators.getNode(1));
final Proposal proposal = validators.getMessageFactory(0).createProposal(roundItem.roundIdentifier, roundItem.block, roundChanges, emptyList());
assertThat(roundItem.messageValidator.validate(proposal)).isFalse();
}
Aggregations