Search in sources :

Example 26 with RLPInput

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);
}
Also used : RLPInput(org.hyperledger.besu.ethereum.rlp.RLPInput) BytesValueRLPOutput(org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput) Test(org.junit.Test)

Example 27 with RLPInput

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);
}
Also used : RLPInput(org.hyperledger.besu.ethereum.rlp.RLPInput) BytesValueRLPOutput(org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput) Test(org.junit.Test)

Example 28 with RLPInput

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);
}
Also used : RLPInput(org.hyperledger.besu.ethereum.rlp.RLPInput) RoundChangePayload(org.hyperledger.besu.consensus.ibft.payload.RoundChangePayload) Block(org.hyperledger.besu.ethereum.core.Block)

Example 29 with RLPInput

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);
}
Also used : RLPInput(org.hyperledger.besu.ethereum.rlp.RLPInput) SECPSignature(org.hyperledger.besu.crypto.SECPSignature) Hash(org.hyperledger.besu.datatypes.Hash) BytesValueRLPOutput(org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput) Test(org.junit.Test)

Example 30 with RLPInput

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);
}
Also used : RLPInput(org.hyperledger.besu.ethereum.rlp.RLPInput) Block(org.hyperledger.besu.ethereum.core.Block) BytesValueRLPOutput(org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput) Test(org.junit.Test)

Aggregations

RLPInput (org.hyperledger.besu.ethereum.rlp.RLPInput)68 BytesValueRLPInput (org.hyperledger.besu.ethereum.rlp.BytesValueRLPInput)34 Bytes (org.apache.tuweni.bytes.Bytes)24 Test (org.junit.Test)21 BytesValueRLPOutput (org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput)15 Hash (org.hyperledger.besu.datatypes.Hash)12 ArrayList (java.util.ArrayList)11 SECPSignature (org.hyperledger.besu.crypto.SECPSignature)11 Block (org.hyperledger.besu.ethereum.core.Block)9 BigInteger (java.math.BigInteger)8 Address (org.hyperledger.besu.datatypes.Address)8 BlockHeader (org.hyperledger.besu.ethereum.core.BlockHeader)7 Transaction (org.hyperledger.besu.ethereum.core.Transaction)7 ArrayDeque (kotlin.collections.ArrayDeque)6 Bytes32 (org.apache.tuweni.bytes.Bytes32)6 ByteBuffer (java.nio.ByteBuffer)5 Optional (java.util.Optional)5 Wei (org.hyperledger.besu.datatypes.Wei)5 MainnetBlockHeaderFunctions (org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions)5 MessageData (org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData)5