use of org.hyperledger.besu.crypto.NodeKey in project besu by hyperledger.
the class RoundChangePayloadValidatorTest method roundChangePayloadSignedByNonValidatorFails.
@Test
public void roundChangePayloadSignedByNonValidatorFails() {
final RoundChangePayload payload = new RoundChangePayload(new ConsensusRoundIdentifier(chainHeight, 1), Optional.of(new PreparedRoundMetadata(preparedBlockHash, 0)));
final NodeKey nonValidatorKey = NodeKeyUtils.generate();
final SignedData<RoundChangePayload> signedPayload = createSignedPayload(payload, nonValidatorKey);
assertThat(messageValidator.validate(signedPayload)).isFalse();
}
use of org.hyperledger.besu.crypto.NodeKey in project besu by hyperledger.
the class QbftRoundTest method exceptionDuringNodeKeySigningDoesNotEscape.
@Test
public void exceptionDuringNodeKeySigningDoesNotEscape() {
final int QUORUM_SIZE = 1;
final RoundState roundState = new RoundState(roundIdentifier, QUORUM_SIZE, messageValidator);
final NodeKey throwingNodeKey = mock(NodeKey.class);
final MessageFactory throwingMessageFactory = new MessageFactory(throwingNodeKey);
when(throwingNodeKey.sign(any())).thenThrow(new SecurityModuleException("Hsm is Offline"));
final QbftRound round = new QbftRound(roundState, blockCreator, protocolContext, blockImporter, subscribers, throwingNodeKey, throwingMessageFactory, transmitter, roundTimer, bftExtraDataCodec);
round.handleProposalMessage(messageFactory.createProposal(roundIdentifier, proposedBlock, Collections.emptyList(), Collections.emptyList()));
// Verify that no prepare message was constructed by the QbftRound
assertThat(roundState.constructPreparedCertificate()).isEmpty();
verifyNoInteractions(transmitter);
}
use of org.hyperledger.besu.crypto.NodeKey in project besu by hyperledger.
the class QbftBlockHeaderValidationRulesetFactoryTest method bftValidateHeaderFailsOnCoinbaseData.
@Test
public void bftValidateHeaderFailsOnCoinbaseData() {
final NodeKey proposerNodeKey = NodeKeyUtils.generate();
final Address proposerAddress = Util.publicKeyToAddress(proposerNodeKey.getPublicKey());
final Address nonProposerAddress = Util.publicKeyToAddress(NodeKeyUtils.generate().getPublicKey());
final List<Address> validators = singletonList(proposerAddress);
final BlockHeader parentHeader = QbftBlockHeaderUtils.createPresetHeaderBuilder(1, proposerNodeKey, validators, null, Optional.empty()).buildHeader();
final BlockHeader blockHeader = QbftBlockHeaderUtils.createPresetHeaderBuilder(2, proposerNodeKey, validators, parentHeader, Optional.empty()).coinbase(nonProposerAddress).buildHeader();
final BlockHeaderValidator validator = getBlockHeaderValidator();
assertThat(validator.validateHeader(blockHeader, parentHeader, protocolContext(validators), HeaderValidationMode.FULL)).isFalse();
}
use of org.hyperledger.besu.crypto.NodeKey in project besu by hyperledger.
the class QbftBlockHeaderValidationRulesetFactoryTest method bftValidateHeaderIgnoresOmmersValue.
@Test
public void bftValidateHeaderIgnoresOmmersValue() {
final NodeKey proposerNodeKey = NodeKeyUtils.generate();
final Address proposerAddress = Util.publicKeyToAddress(proposerNodeKey.getPublicKey());
final List<Address> validators = singletonList(proposerAddress);
final BlockHeader parentHeader = QbftBlockHeaderUtils.createPresetHeaderBuilder(1, proposerNodeKey, validators, null, Optional.empty()).buildHeader();
final BlockHeader blockHeader = QbftBlockHeaderUtils.createPresetHeaderBuilder(2, proposerNodeKey, validators, parentHeader, builder -> builder.ommersHash(Hash.EMPTY_TRIE_HASH), Optional.empty()).buildHeader();
final BlockHeaderValidator validator = getBlockHeaderValidator();
assertThat(validator.validateHeader(blockHeader, parentHeader, protocolContext(validators), HeaderValidationMode.FULL)).isTrue();
}
use of org.hyperledger.besu.crypto.NodeKey in project besu by hyperledger.
the class QbftBlockHeaderValidationRulesetFactoryTest method bftValidateHeaderFailsOnGasUsage.
@Test
public void bftValidateHeaderFailsOnGasUsage() {
final NodeKey proposerNodeKey = NodeKeyUtils.generate();
final Address proposerAddress = Util.publicKeyToAddress(proposerNodeKey.getPublicKey());
final List<Address> validators = singletonList(proposerAddress);
final BlockHeader parentHeader = QbftBlockHeaderUtils.createPresetHeaderBuilder(1, proposerNodeKey, validators, null, Optional.empty()).buildHeader();
final BlockHeader blockHeader = QbftBlockHeaderUtils.createPresetHeaderBuilder(2, proposerNodeKey, validators, parentHeader, Optional.empty()).gasLimit(5_000).gasUsed(6_000).buildHeader();
final BlockHeaderValidator validator = getBlockHeaderValidator();
assertThat(validator.validateHeader(blockHeader, parentHeader, protocolContext(validators), HeaderValidationMode.FULL)).isFalse();
}
Aggregations