use of org.hyperledger.besu.consensus.qbft.messagewrappers.RoundChange in project besu by hyperledger.
the class ProposalValidatorTest method validationFailsIfRoundZeroHasNonEmptyRoundChanges.
@Test
public void validationFailsIfRoundZeroHasNonEmptyRoundChanges() {
final RoundChange roundChange = validators.getMessageFactory(1).createRoundChange(roundItems.get(ROUND_ID.ZERO).roundIdentifier, Optional.empty());
final Proposal proposal = validators.getMessageFactory(0).createProposal(roundItems.get(ROUND_ID.ZERO).roundIdentifier, roundItems.get(ROUND_ID.ZERO).block, List.of(roundChange.getSignedPayload()), emptyList());
assertThat(roundItems.get(ROUND_ID.ZERO).messageValidator.validate(proposal)).isFalse();
}
use of org.hyperledger.besu.consensus.qbft.messagewrappers.RoundChange in project besu by hyperledger.
the class RoundChangeMessageValidatorTest method roundChangeWithNoPiggyBackedDataIsValid.
@Test
public void roundChangeWithNoPiggyBackedDataIsValid() {
when(payloadValidator.validate(any())).thenReturn(true);
messageValidator = new RoundChangeMessageValidator(payloadValidator, BftHelpers.calculateRequiredValidatorQuorum(VALIDATOR_COUNT), CHAIN_HEIGHT, validators.getNodeAddresses(), blockValidator, protocolContext);
for (int i = 0; i < VALIDATOR_COUNT; i++) {
final RoundChange message = validators.getMessageFactory(i).createRoundChange(targetRound, Optional.empty());
assertThat(messageValidator.validate(message)).isTrue();
}
}
use of org.hyperledger.besu.consensus.qbft.messagewrappers.RoundChange in project besu by hyperledger.
the class RoundChangeMessageValidatorTest method invalidEmbeddedPayloadFailsValidation.
@Test
public void invalidEmbeddedPayloadFailsValidation() {
when(payloadValidator.validate(any())).thenReturn(false);
messageValidator = new RoundChangeMessageValidator(payloadValidator, BftHelpers.calculateRequiredValidatorQuorum(VALIDATOR_COUNT), CHAIN_HEIGHT, validators.getNodeAddresses(), blockValidator, protocolContext);
final RoundChange message = validators.getMessageFactory(0).createRoundChange(targetRound, Optional.empty());
assertThat(messageValidator.validate(message)).isFalse();
}
use of org.hyperledger.besu.consensus.qbft.messagewrappers.RoundChange in project besu by hyperledger.
the class RoundChangeMessageValidatorTest method validationFailsIfPreparesContainsDifferentRoundToBlock.
@Test
public void validationFailsIfPreparesContainsDifferentRoundToBlock() {
when(blockValidator.validateAndProcessBlock(any(), any(), eq(HeaderValidationMode.LIGHT), eq(HeaderValidationMode.FULL))).thenReturn(new Result(new BlockProcessingOutputs(null, null)));
when(payloadValidator.validate(any())).thenReturn(true);
messageValidator = new RoundChangeMessageValidator(payloadValidator, BftHelpers.calculateRequiredValidatorQuorum(VALIDATOR_COUNT), CHAIN_HEIGHT, validators.getNodeAddresses(), blockValidator, protocolContext);
final Block block = ProposedBlockHelpers.createProposalBlock(Collections.emptyList(), roundIdentifier, bftExtraDataEncoder);
final PreparedCertificate prepCert = new PreparedCertificate(block, validators.getNodes().stream().map(n -> n.getMessageFactory().createPrepare(ConsensusRoundHelpers.createFrom(roundIdentifier, 0, -1), block.getHash()).getSignedPayload()).collect(Collectors.toList()), roundIdentifier.getRoundNumber());
final RoundChange message = validators.getMessageFactory(0).createRoundChange(targetRound, Optional.of(prepCert));
assertThat(messageValidator.validate(message)).isFalse();
}
use of org.hyperledger.besu.consensus.qbft.messagewrappers.RoundChange in project besu by hyperledger.
the class RoundChangeMessageValidatorTest method prepareFromNonValidatorFails.
@Test
public void prepareFromNonValidatorFails() {
when(blockValidator.validateAndProcessBlock(any(), any(), eq(HeaderValidationMode.LIGHT), eq(HeaderValidationMode.FULL))).thenReturn(new Result(new BlockProcessingOutputs(null, null)));
when(payloadValidator.validate(any())).thenReturn(true);
messageValidator = new RoundChangeMessageValidator(payloadValidator, BftHelpers.calculateRequiredValidatorQuorum(VALIDATOR_COUNT), CHAIN_HEIGHT, validators.getNodeAddresses(), blockValidator, protocolContext);
final QbftNode nonValidator = QbftNode.create();
final Block block = ProposedBlockHelpers.createProposalBlock(Collections.emptyList(), roundIdentifier, bftExtraDataEncoder);
final PreparedCertificate prepCert = createPreparedCertificate(block, roundIdentifier, validators.getNode(0), validators.getNode(1), nonValidator);
final RoundChange message = validators.getMessageFactory(0).createRoundChange(targetRound, Optional.of(prepCert));
assertThat(messageValidator.validate(message)).isFalse();
}
Aggregations