use of org.hyperledger.besu.ethereum.BlockValidator.Result in project besu by hyperledger.
the class ProposalValidatorTest method validationFailsIfBlockIsInvalid.
@Test
public void validationFailsIfBlockIsInvalid() {
final RoundSpecificItems roundItem = roundItems.get(ROUND_ID.ZERO);
final Proposal proposal = createProposal(roundItem, emptyList(), emptyList());
when(blockValidator.validateAndProcessBlock(eq(protocolContext), any(), eq(HeaderValidationMode.LIGHT), eq(HeaderValidationMode.FULL))).thenReturn(new Result("Failed"));
assertThat(roundItem.messageValidator.validate(proposal)).isFalse();
}
use of org.hyperledger.besu.ethereum.BlockValidator.Result 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.ethereum.BlockValidator.Result 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();
}
use of org.hyperledger.besu.ethereum.BlockValidator.Result in project besu by hyperledger.
the class RoundChangeManagerTest method setup.
@Before
public void setup() {
validators.add(Util.publicKeyToAddress(proposerKey.getPublicKey()));
validators.add(Util.publicKeyToAddress(validator1Key.getPublicKey()));
validators.add(Util.publicKeyToAddress(validator2Key.getPublicKey()));
final BlockValidator blockValidator = mock(BlockValidator.class);
when(blockValidator.validateAndProcessBlock(any(), any(), any(), any())).thenReturn(new Result(new BlockProcessingOutputs(null, null)));
final RoundChangePayloadValidator.MessageValidatorForHeightFactory messageValidatorFactory = mock(RoundChangePayloadValidator.MessageValidatorForHeightFactory.class);
when(messageValidatorFactory.createAt(ri1)).thenAnswer(invocation -> new SignedDataValidator(validators, Util.publicKeyToAddress(proposerKey.getPublicKey()), ri1));
when(messageValidatorFactory.createAt(ri2)).thenAnswer(invocation -> new SignedDataValidator(validators, Util.publicKeyToAddress(validator1Key.getPublicKey()), ri2));
when(messageValidatorFactory.createAt(ri3)).thenAnswer(invocation -> new SignedDataValidator(validators, Util.publicKeyToAddress(validator2Key.getPublicKey()), ri3));
final RoundChangeMessageValidator roundChangeMessageValidator = new RoundChangeMessageValidator(new RoundChangePayloadValidator(messageValidatorFactory, validators, BftHelpers.calculateRequiredValidatorQuorum(BftHelpers.calculateRequiredValidatorQuorum(validators.size())), 2), proposalConsistencyValidator, bftBlockInterface);
manager = new RoundChangeManager(2, roundChangeMessageValidator);
when(proposalConsistencyValidator.validateProposalMatchesBlock(any(), any(), any())).thenReturn(true);
}
use of org.hyperledger.besu.ethereum.BlockValidator.Result in project besu by hyperledger.
the class MessageValidatorTest method blockValidationFailureFailsValidation.
@Test
public void blockValidationFailureFailsValidation() {
when(blockValidator.validateAndProcessBlock(any(), any(), any(), any())).thenReturn(new Result("Failed"));
final Proposal proposalMsg = messageFactory.createProposal(roundIdentifier, block, Optional.empty());
assertThat(messageValidator.validateProposal(proposalMsg)).isFalse();
}
Aggregations