use of tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.StatusMessage in project teku by ConsenSys.
the class AbstractSyncTest method withPeerHeadSlot.
protected PeerStatus withPeerHeadSlot(final UInt64 peerHeadSlot, final UInt64 peerFinalizedEpoch, final Bytes32 peerHeadBlockRoot) {
final PeerStatus peer_status = PeerStatus.fromStatusMessage(new StatusMessage(Bytes4.leftPad(Bytes.EMPTY), Bytes32.ZERO, peerFinalizedEpoch, peerHeadBlockRoot, peerHeadSlot));
when(peer.getStatus()).thenReturn(peer_status);
return peer_status;
}
use of tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.StatusMessage in project teku by ConsenSys.
the class BeaconChainMethods method createStatus.
private static Eth2RpcMethod<StatusMessage, StatusMessage> createStatus(final AsyncRunner asyncRunner, final StatusMessageFactory statusMessageFactory, final PeerLookup peerLookup, final RpcEncoding rpcEncoding) {
final StatusMessageHandler statusHandler = new StatusMessageHandler(statusMessageFactory);
final RpcContextCodec<?, StatusMessage> contextCodec = RpcContextCodec.noop(StatusMessage.SSZ_SCHEMA);
return new SingleProtocolEth2RpcMethod<>(asyncRunner, BeaconChainMethodIds.STATUS, 1, rpcEncoding, StatusMessage.SSZ_SCHEMA, true, contextCodec, statusHandler, peerLookup);
}
use of tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.StatusMessage in project teku by ConsenSys.
the class LengthPrefixedEncodingTest method decodePayload_shouldReturnErrorWhenNoPayloadIsPresent.
@Test
public void decodePayload_shouldReturnErrorWhenNoPayloadIsPresent() {
final Bytes statusMessageLengthPrefix = Bytes.fromHexString("0x54");
List<List<ByteBuf>> testByteBufSlices = Utils.generateTestSlices(statusMessageLengthPrefix);
for (Iterable<ByteBuf> bufSlices : testByteBufSlices) {
RpcByteBufDecoder<StatusMessage> decoder = encoding.createDecoder(StatusMessage.SSZ_SCHEMA);
List<ByteBuf> usedBufs = new ArrayList<>();
assertThatThrownBy(() -> {
for (ByteBuf bufSlice : bufSlices) {
assertThat(decoder.decodeOneMessage(bufSlice)).isEmpty();
bufSlice.release();
usedBufs.add(bufSlice);
}
decoder.complete();
}).isInstanceOf(PayloadTruncatedException.class);
assertThat(usedBufs).allMatch(b -> b.refCnt() == 0);
}
}
use of tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.StatusMessage in project teku by ConsenSys.
the class LengthPrefixedEncodingTest method decodePayload_shouldReadPayloadWhenExtraDataIsAppended.
@Test
public void decodePayload_shouldReadPayloadWhenExtraDataIsAppended() throws RpcException {
final StatusMessage originalMessage = StatusMessage.createPreGenesisStatus(spec);
final Bytes encoded = encoding.encodePayload(originalMessage);
final Bytes extraData = Bytes.of(1, 2, 3, 4);
List<List<ByteBuf>> testByteBufSlices = Utils.generateTestSlices(encoded, extraData);
for (Iterable<ByteBuf> bufSlices : testByteBufSlices) {
RpcByteBufDecoder<StatusMessage> decoder = encoding.createDecoder(StatusMessage.SSZ_SCHEMA);
Optional<StatusMessage> result = Optional.empty();
int unreadBytes = 0;
for (ByteBuf bufSlice : bufSlices) {
if (result.isEmpty()) {
result = decoder.decodeOneMessage(bufSlice);
}
if (result.isPresent()) {
unreadBytes += bufSlice.readableBytes();
}
bufSlice.release();
}
decoder.complete();
assertThat(result).contains(originalMessage);
assertThat(unreadBytes).isEqualTo(4);
assertThat(bufSlices).allMatch(b -> b.refCnt() == 0);
}
}
use of tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.StatusMessage in project teku by ConsenSys.
the class LengthPrefixedEncodingTest method decodePayload_shouldThrowRpcExceptionIfMessageLengthPrefixIsMoreThanThreeBytes.
@Test
public void decodePayload_shouldThrowRpcExceptionIfMessageLengthPrefixIsMoreThanThreeBytes() {
final ByteBuf input = inputByteBuffer("0x80808001");
RpcByteBufDecoder<StatusMessage> decoder = encoding.createDecoder(StatusMessage.SSZ_SCHEMA);
assertThatThrownBy(() -> decoder.decodeOneMessage(input)).isInstanceOf(ChunkTooLongException.class);
input.release();
assertThat(input.refCnt()).isEqualTo(0);
}
Aggregations