use of org.hyperledger.besu.ethereum.BlockValidator.BlockProcessingOutputs 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.BlockProcessingOutputs 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.BlockProcessingOutputs 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.BlockProcessingOutputs in project besu by hyperledger.
the class EngineNewPayloadTest method shouldReturnValid.
@Test
public void shouldReturnValid() {
BlockHeader mockHeader = new BlockHeaderTestFixture().baseFeePerGas(Wei.ONE).buildHeader();
when(blockchain.getBlockByHash(any())).thenReturn(Optional.empty());
when(mergeCoordinator.getLatestValidAncestor(any(BlockHeader.class))).thenReturn(Optional.of(mockHash));
when(mergeCoordinator.latestValidAncestorDescendsFromTerminal(any(BlockHeader.class))).thenReturn(true);
when(mergeCoordinator.getOrSyncHeaderByHash(any(Hash.class))).thenReturn(Optional.of(mockHeader));
when(mergeCoordinator.executeBlock(any())).thenReturn(new Result(new BlockProcessingOutputs(null, List.of())));
var resp = resp(mockPayload(mockHeader, Collections.emptyList()));
EnginePayloadStatusResult res = fromSuccessResp(resp);
assertThat(res.getLatestValidHash().get()).isEqualTo(mockHeader.getHash());
assertThat(res.getStatusAsString()).isEqualTo(VALID.name());
assertThat(res.getError()).isNull();
}
use of org.hyperledger.besu.ethereum.BlockValidator.BlockProcessingOutputs in project besu by hyperledger.
the class MessageValidatorTest method setup.
@Before
public void setup() {
when(signedDataValidator.validateProposal(any())).thenReturn(true);
when(signedDataValidator.validatePrepare(any())).thenReturn(true);
when(signedDataValidator.validateCommit(any())).thenReturn(true);
when(proposalBlockConsistencyValidator.validateProposalMatchesBlock(any(), any(), any())).thenReturn(true);
BftContext mockBftCtx = mock(BftContext.class);
when(mockBftCtx.as(Mockito.any())).thenReturn(mockBftCtx);
protocolContext = new ProtocolContext(mock(MutableBlockchain.class), mock(WorldStateArchive.class), mockBftCtx);
when(blockValidator.validateAndProcessBlock(any(), any(), any(), any())).thenReturn(new Result(new BlockProcessingOutputs(null, null)));
when(roundChangeCertificateValidator.validateProposalMessageMatchesLatestPrepareCertificate(any(), any())).thenReturn(true);
when(roundChangeCertificateValidator.validateRoundChangeMessagesAndEnsureTargetRoundMatchesRoot(any(), any())).thenReturn(true);
messageValidator = new MessageValidator(signedDataValidator, proposalBlockConsistencyValidator, blockValidator, protocolContext, roundChangeCertificateValidator);
}
Aggregations