Search in sources :

Example 1 with Result

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();
}
Also used : Proposal(org.hyperledger.besu.consensus.qbft.messagewrappers.Proposal) Result(org.hyperledger.besu.ethereum.BlockValidator.Result) Test(org.junit.Test)

Example 2 with Result

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();
}
Also used : BlockProcessingOutputs(org.hyperledger.besu.ethereum.BlockValidator.BlockProcessingOutputs) RoundChange(org.hyperledger.besu.consensus.qbft.messagewrappers.RoundChange) Block(org.hyperledger.besu.ethereum.core.Block) ValidationTestHelpers.createPreparedCertificate(org.hyperledger.besu.consensus.qbft.validation.ValidationTestHelpers.createPreparedCertificate) PreparedCertificate(org.hyperledger.besu.consensus.qbft.statemachine.PreparedCertificate) Result(org.hyperledger.besu.ethereum.BlockValidator.Result) Test(org.junit.Test)

Example 3 with Result

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();
}
Also used : BlockProcessingOutputs(org.hyperledger.besu.ethereum.BlockValidator.BlockProcessingOutputs) RoundChange(org.hyperledger.besu.consensus.qbft.messagewrappers.RoundChange) Block(org.hyperledger.besu.ethereum.core.Block) ValidationTestHelpers.createPreparedCertificate(org.hyperledger.besu.consensus.qbft.validation.ValidationTestHelpers.createPreparedCertificate) PreparedCertificate(org.hyperledger.besu.consensus.qbft.statemachine.PreparedCertificate) Result(org.hyperledger.besu.ethereum.BlockValidator.Result) Test(org.junit.Test)

Example 4 with Result

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);
}
Also used : BlockProcessingOutputs(org.hyperledger.besu.ethereum.BlockValidator.BlockProcessingOutputs) RoundChangePayloadValidator(org.hyperledger.besu.consensus.ibft.validation.RoundChangePayloadValidator) RoundChangeMessageValidator(org.hyperledger.besu.consensus.ibft.validation.RoundChangeMessageValidator) SignedDataValidator(org.hyperledger.besu.consensus.ibft.validation.SignedDataValidator) BlockValidator(org.hyperledger.besu.ethereum.BlockValidator) Result(org.hyperledger.besu.ethereum.BlockValidator.Result) Before(org.junit.Before)

Example 5 with Result

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();
}
Also used : Proposal(org.hyperledger.besu.consensus.ibft.messagewrappers.Proposal) Result(org.hyperledger.besu.ethereum.BlockValidator.Result) Test(org.junit.Test)

Aggregations

Result (org.hyperledger.besu.ethereum.BlockValidator.Result)28 Block (org.hyperledger.besu.ethereum.core.Block)21 Test (org.junit.Test)21 BlockProcessingOutputs (org.hyperledger.besu.ethereum.BlockValidator.BlockProcessingOutputs)19 RoundChange (org.hyperledger.besu.consensus.qbft.messagewrappers.RoundChange)11 PreparedCertificate (org.hyperledger.besu.consensus.qbft.statemachine.PreparedCertificate)9 ValidationTestHelpers.createPreparedCertificate (org.hyperledger.besu.consensus.qbft.validation.ValidationTestHelpers.createPreparedCertificate)9 Proposal (org.hyperledger.besu.consensus.qbft.messagewrappers.Proposal)7 Before (org.junit.Before)6 Hash (org.hyperledger.besu.datatypes.Hash)4 BlockValidator (org.hyperledger.besu.ethereum.BlockValidator)4 ProtocolContext (org.hyperledger.besu.ethereum.ProtocolContext)4 BlockDataGenerator (org.hyperledger.besu.ethereum.core.BlockDataGenerator)3 TransactionReceipt (org.hyperledger.besu.ethereum.core.TransactionReceipt)3 EthContext (org.hyperledger.besu.ethereum.eth.manager.EthContext)3 EthProtocolManager (org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager)3 ReferenceTestWorldState (org.hyperledger.besu.ethereum.referencetests.ReferenceTestWorldState)3 Bytes (org.apache.tuweni.bytes.Bytes)2 QbftContext (org.hyperledger.besu.consensus.qbft.QbftContext)2 RoundChangePayload (org.hyperledger.besu.consensus.qbft.payload.RoundChangePayload)2