use of org.hyperledger.besu.consensus.ibft.payload.MessageFactory in project besu by hyperledger.
the class RoundChangeArtifactsTest method setup.
@Before
public void setup() {
for (int i = 0; i < 4; i++) {
final NodeKey nodeKey = NodeKeyUtils.generate();
final MessageFactory messageFactory = new MessageFactory(nodeKey);
messageFactories.add(messageFactory);
}
}
use of org.hyperledger.besu.consensus.ibft.payload.MessageFactory in project besu by hyperledger.
the class RoundStateTest method setup.
@Before
public void setup() {
for (int i = 0; i < 3; i++) {
final NodeKey newNodeKey = NodeKeyUtils.generate();
validatorKeys.add(newNodeKey);
validators.add(Util.publicKeyToAddress(newNodeKey.getPublicKey()));
validatorMessageFactories.add(new MessageFactory(newNodeKey));
}
when(block.getHash()).thenReturn(Hash.fromHexStringLenient("1"));
}
use of org.hyperledger.besu.consensus.ibft.payload.MessageFactory in project besu by hyperledger.
the class RoundChangeCertificateValidatorTest method latestPreparedCertificateIsExtractedFromRoundChangeCertificate.
@Test
public void latestPreparedCertificateIsExtractedFromRoundChangeCertificate() {
// NOTE: This function does not validate that all RoundCHanges/Prepares etc. come from valid
// sources, it is only responsible for determine which of the list or RoundChange messages
// contains the newest
// NOTE: This capability is tested as part of the NewRoundMessageValidationTests.
final NodeKey proposerKey = NodeKeyUtils.generate();
final MessageFactory proposerMessageFactory = new MessageFactory(proposerKey);
final Block proposedBlock = mock(Block.class);
when(proposedBlock.getHash()).thenReturn(Hash.fromHexStringLenient("1"));
final ConsensusRoundIdentifier roundIdentifier = new ConsensusRoundIdentifier(1, 4);
final ConsensusRoundIdentifier preparedRound = ConsensusRoundHelpers.createFrom(roundIdentifier, 0, -1);
final Proposal differentProposal = proposerMessageFactory.createProposal(preparedRound, proposedBlock, Optional.empty());
final Optional<PreparedRoundArtifacts> latterPreparedRoundArtifacts = Optional.of(new PreparedRoundArtifacts(differentProposal, Lists.newArrayList(proposerMessageFactory.createPrepare(roundIdentifier, proposedBlock.getHash()), proposerMessageFactory.createPrepare(roundIdentifier, proposedBlock.getHash()))));
// An earlier PrepareCert is added to ensure the path to find the latest PrepareCert
// is correctly followed.
final ConsensusRoundIdentifier earlierPreparedRound = ConsensusRoundHelpers.createFrom(roundIdentifier, 0, -2);
final Proposal earlierProposal = proposerMessageFactory.createProposal(earlierPreparedRound, proposedBlock, Optional.empty());
final Optional<PreparedRoundArtifacts> earlierPreparedRoundArtifacts = Optional.of(new PreparedRoundArtifacts(earlierProposal, Lists.newArrayList(proposerMessageFactory.createPrepare(earlierPreparedRound, proposedBlock.getHash()), proposerMessageFactory.createPrepare(earlierPreparedRound, proposedBlock.getHash()))));
final Optional<PreparedCertificate> newestCert = RoundChangeCertificateValidator.findLatestPreparedCertificate(Lists.newArrayList(proposerMessageFactory.createRoundChange(roundIdentifier, earlierPreparedRoundArtifacts).getSignedPayload(), proposerMessageFactory.createRoundChange(roundIdentifier, latterPreparedRoundArtifacts).getSignedPayload()));
assertThat(newestCert.get()).isEqualTo(latterPreparedRoundArtifacts.get().getPreparedCertificate());
}
use of org.hyperledger.besu.consensus.ibft.payload.MessageFactory in project besu by hyperledger.
the class RoundChangeCertificateValidatorTest method allRoundChangeHaveNoPreparedReturnsEmptyOptional.
@Test
public void allRoundChangeHaveNoPreparedReturnsEmptyOptional() {
final NodeKey proposerKey = NodeKeyUtils.generate();
final MessageFactory proposerMessageFactory = new MessageFactory(proposerKey);
final ConsensusRoundIdentifier roundIdentifier = new ConsensusRoundIdentifier(1, 4);
final Optional<PreparedCertificate> newestCert = RoundChangeCertificateValidator.findLatestPreparedCertificate(Lists.newArrayList(proposerMessageFactory.createRoundChange(roundIdentifier, Optional.empty()).getSignedPayload(), proposerMessageFactory.createRoundChange(roundIdentifier, Optional.empty()).getSignedPayload()));
assertThat(newestCert).isEmpty();
}
use of org.hyperledger.besu.consensus.ibft.payload.MessageFactory in project besu by hyperledger.
the class TestHelpers method createSignedProposalPayloadWithRound.
public static Proposal createSignedProposalPayloadWithRound(final NodeKey signerNodeKey, final int round) {
final MessageFactory messageFactory = new MessageFactory(signerNodeKey);
final ConsensusRoundIdentifier roundIdentifier = new ConsensusRoundIdentifier(0x1234567890ABCDEFL, round);
final Block block = ProposedBlockHelpers.createProposalBlock(singletonList(AddressHelpers.ofValue(1)), roundIdentifier);
return messageFactory.createProposal(roundIdentifier, block, Optional.empty());
}
Aggregations