use of org.hyperledger.besu.ethereum.rlp.RLPInput in project besu by hyperledger.
the class RoundChangePayloadTest method roundTripRlpWithEmptyPreparedCertificate.
@Test
public void roundTripRlpWithEmptyPreparedCertificate() {
final SignedData<ProposalPayload> signedProposal = signedProposal();
final PreparedCertificate preparedCertificate = new PreparedCertificate(signedProposal, Collections.emptyList());
final RoundChangePayload roundChangePayload = new RoundChangePayload(ROUND_IDENTIFIER, Optional.of(preparedCertificate));
final BytesValueRLPOutput rlpOut = new BytesValueRLPOutput();
roundChangePayload.writeTo(rlpOut);
final RLPInput rlpInput = RLP.input(rlpOut.encoded());
RoundChangePayload actualRoundChangePayload = RoundChangePayload.readFrom(rlpInput);
assertThat(actualRoundChangePayload.getRoundIdentifier()).isEqualTo(ROUND_IDENTIFIER);
assertThat(actualRoundChangePayload.getPreparedCertificate()).isEqualTo(Optional.of(preparedCertificate));
assertThat(actualRoundChangePayload.getMessageType()).isEqualTo(IbftV2.ROUND_CHANGE);
}
use of org.hyperledger.besu.ethereum.rlp.RLPInput in project besu by hyperledger.
the class RoundChangePayloadTest method roundTripRlpWithNoPreparedCertificate.
@Test
public void roundTripRlpWithNoPreparedCertificate() {
final RoundChangePayload roundChangePayload = new RoundChangePayload(ROUND_IDENTIFIER, empty());
final BytesValueRLPOutput rlpOut = new BytesValueRLPOutput();
roundChangePayload.writeTo(rlpOut);
final RLPInput rlpInput = RLP.input(rlpOut.encoded());
RoundChangePayload actualRoundChangePayload = RoundChangePayload.readFrom(rlpInput);
assertThat(actualRoundChangePayload.getRoundIdentifier()).isEqualTo(ROUND_IDENTIFIER);
assertThat(actualRoundChangePayload.getPreparedCertificate()).isEqualTo(Optional.empty());
assertThat(actualRoundChangePayload.getMessageType()).isEqualTo(IbftV2.ROUND_CHANGE);
}
use of org.hyperledger.besu.ethereum.rlp.RLPInput in project besu by hyperledger.
the class RoundChange method decode.
public static RoundChange decode(final Bytes data) {
final RLPInput rlpIn = RLP.input(data);
rlpIn.enterList();
final SignedData<RoundChangePayload> payload = PayloadDeserializers.readSignedRoundChangePayloadFrom(rlpIn);
Optional<Block> block = Optional.empty();
if (!rlpIn.nextIsNull()) {
block = Optional.of(Block.readFrom(rlpIn, BftBlockHeaderFunctions.forCommittedSeal(BFT_EXTRA_DATA_ENCODER)));
} else {
rlpIn.skipNext();
}
rlpIn.leaveList();
return new RoundChange(payload, block);
}
use of org.hyperledger.besu.ethereum.rlp.RLPInput in project besu by hyperledger.
the class CommitPayloadTest method roundTripRlp.
@Test
public void roundTripRlp() {
final SECPSignature signature = SignatureAlgorithmFactory.getInstance().createSignature(BigInteger.ONE, BigInteger.TEN, (byte) 0);
final Hash hash = Hash.fromHexStringLenient("0x8523ba6e7c5f59ae87");
final CommitPayload expectedCommitPayload = new CommitPayload(ROUND_IDENTIFIER, hash, signature);
final BytesValueRLPOutput rlpOut = new BytesValueRLPOutput();
expectedCommitPayload.writeTo(rlpOut);
final RLPInput rlpInput = RLP.input(rlpOut.encoded());
final CommitPayload commitPayload = CommitPayload.readFrom(rlpInput);
assertThat(commitPayload.getRoundIdentifier()).isEqualTo(ROUND_IDENTIFIER);
assertThat(commitPayload.getCommitSeal()).isEqualTo(signature);
assertThat(commitPayload.getDigest()).isEqualTo(hash);
assertThat(commitPayload.getMessageType()).isEqualTo(IbftV2.COMMIT);
}
use of org.hyperledger.besu.ethereum.rlp.RLPInput in project besu by hyperledger.
the class ProposalPayloadTest method roundTripRlp.
@Test
public void roundTripRlp() {
final Block block = ProposedBlockHelpers.createProposalBlock(singletonList(AddressHelpers.ofValue(1)), ROUND_IDENTIFIER);
final ProposalPayload expectedProposalPayload = new ProposalPayload(ROUND_IDENTIFIER, block.getHash());
final BytesValueRLPOutput rlpOut = new BytesValueRLPOutput();
expectedProposalPayload.writeTo(rlpOut);
final RLPInput rlpInput = RLP.input(rlpOut.encoded());
final ProposalPayload proposalPayload = ProposalPayload.readFrom(rlpInput);
assertThat(proposalPayload.getRoundIdentifier()).isEqualTo(ROUND_IDENTIFIER);
assertThat(proposalPayload.getDigest()).isEqualTo(block.getHash());
assertThat(proposalPayload.getMessageType()).isEqualTo(IbftV2.PROPOSAL);
}
Aggregations