Search in sources :

Example 1 with ENRResponsePacketData

use of org.hyperledger.besu.ethereum.p2p.discovery.internal.ENRResponsePacketData in project besu by hyperledger.

the class PeerDiscoveryPacketPcapSedesTest method testUDPENRResponseSerializeDeserialize.

@Test
public void testUDPENRResponseSerializeDeserialize() {
    final byte[] data = Hex.decode(enrResponseHexData);
    final Packet packet = Packet.decode(Buffer.buffer(data));
    assertThat(packet.getType()).isNotNull();
    assertThat(packet.getNodeId()).isNotNull();
    assertThat(packet.getNodeId().toArray()).hasSize(64);
    assertThat(packet.getType()).isEqualTo(PacketType.ENR_RESPONSE);
    final ENRResponsePacketData enrResponsePacketData = packet.getPacketData(ENRResponsePacketData.class).orElse(null);
    assertThat(enrResponsePacketData).isNotNull();
    assertThat(enrResponsePacketData.getEnr()).isNotNull();
    assertThat(enrResponsePacketData.getEnr().getSeq()).isGreaterThan(UInt64.ZERO);
    assertThat(enrResponsePacketData.getEnr().getSignature()).isNotNull();
    assertThat(enrResponsePacketData.getRequestHash()).isNotNull();
    assertThat(enrResponsePacketData.getRequestHash().toArray()).hasSize(32);
    final byte[] encoded = packet.encode().getBytes();
    assertThat(encoded).isEqualTo(data);
}
Also used : Packet(org.hyperledger.besu.ethereum.p2p.discovery.internal.Packet) ENRResponsePacketData(org.hyperledger.besu.ethereum.p2p.discovery.internal.ENRResponsePacketData) Test(org.junit.Test)

Aggregations

ENRResponsePacketData (org.hyperledger.besu.ethereum.p2p.discovery.internal.ENRResponsePacketData)1 Packet (org.hyperledger.besu.ethereum.p2p.discovery.internal.Packet)1 Test (org.junit.Test)1