use of org.hyperledger.besu.crypto.NodeKey in project besu by hyperledger.
the class QbftBlockHeaderValidationRulesetFactoryTest method bftValidateHeaderFailsOnAncestor.
@Test
public void bftValidateHeaderFailsOnAncestor() {
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, null, Optional.empty()).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 bftValidateHeaderFailsOnMixHash.
@Test
public void bftValidateHeaderFailsOnMixHash() {
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.mixHash(Hash.EMPTY_TRIE_HASH), Optional.empty()).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 bftValidateHeaderFailsOnDifficulty.
@Test
public void bftValidateHeaderFailsOnDifficulty() {
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()).difficulty(Difficulty.of(5)).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 CommitTest method canRoundTripACommitMessage.
@Test
public void canRoundTripACommitMessage() {
final NodeKey nodeKey = NodeKeyUtils.generate();
final Address addr = Util.publicKeyToAddress(nodeKey.getPublicKey());
final CommitPayload commitPayload = new CommitPayload(new ConsensusRoundIdentifier(1, 1), Hash.ZERO, SignatureAlgorithmFactory.getInstance().createSignature(BigInteger.ONE, BigInteger.ONE, (byte) 0));
final SignedData<CommitPayload> signedCommitPayload = SignedData.create(commitPayload, nodeKey.sign(commitPayload.hashForSignature()));
final Commit commitMsg = new Commit(signedCommitPayload);
final Commit decodedPrepare = Commit.decode(commitMsg.encode());
assertThat(decodedPrepare.getMessageType()).isEqualTo(QbftV1.COMMIT);
assertThat(decodedPrepare.getAuthor()).isEqualTo(addr);
assertThat(decodedPrepare.getSignedPayload()).isEqualToComparingFieldByField(signedCommitPayload);
}
use of org.hyperledger.besu.crypto.NodeKey in project besu by hyperledger.
the class ProposalTest method canRoundTripProposalMessage.
@Test
public void canRoundTripProposalMessage() {
final NodeKey nodeKey = NodeKeyUtils.generate();
final Address addr = Util.publicKeyToAddress(nodeKey.getPublicKey());
final ProposalPayload payload = new ProposalPayload(new ConsensusRoundIdentifier(1, 1), BLOCK);
final SignedData<ProposalPayload> signedPayload = SignedData.create(payload, nodeKey.sign(payload.hashForSignature()));
final PreparePayload preparePayload = new PreparePayload(new ConsensusRoundIdentifier(1, 0), BLOCK.getHash());
final SignedData<PreparePayload> prepare = SignedData.create(preparePayload, nodeKey.sign(preparePayload.hashForSignature()));
final RoundChangePayload roundChangePayload = new RoundChangePayload(new ConsensusRoundIdentifier(1, 0), Optional.of(new PreparedRoundMetadata(BLOCK.getHash(), 0)));
final SignedData<RoundChangePayload> roundChange = SignedData.create(roundChangePayload, nodeKey.sign(roundChangePayload.hashForSignature()));
final Proposal proposal = new Proposal(signedPayload, List.of(roundChange), List.of(prepare));
final Proposal decodedProposal = Proposal.decode(proposal.encode(), bftExtraDataCodec);
assertThat(decodedProposal.getAuthor()).isEqualTo(addr);
assertThat(decodedProposal.getMessageType()).isEqualTo(QbftV1.PROPOSAL);
assertThat(decodedProposal.getPrepares()).hasSize(1);
assertThat(decodedProposal.getPrepares().get(0)).isEqualToComparingFieldByField(prepare);
assertThat(decodedProposal.getRoundChanges()).hasSize(1);
assertThat(decodedProposal.getRoundChanges().get(0)).isEqualToComparingFieldByField(roundChange);
assertThat(decodedProposal.getSignedPayload().getPayload().getProposedBlock()).isEqualTo(BLOCK);
assertThat(decodedProposal.getSignedPayload().getPayload().getRoundIdentifier()).isEqualTo(payload.getRoundIdentifier());
}
Aggregations