use of tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.BeaconBlocksByRootRequestMessage in project teku by ConsenSys.
the class RpcRequestDecoderTest method shouldParseSingleResponse.
@Test
public void shouldParseSingleResponse() throws Exception {
List<List<ByteBuf>> testByteBufSlices = testByteBufSlices(LENGTH_PREFIX, MESSAGE_DATA);
for (Iterable<ByteBuf> bufSlices : testByteBufSlices) {
RpcRequestDecoder<BeaconBlocksByRootRequestMessage> decoder = METHOD.createRequestDecoder();
List<BeaconBlocksByRootRequestMessage> msgs = new ArrayList<>();
for (ByteBuf bufSlice : bufSlices) {
decoder.decodeRequest(bufSlice).ifPresent(msgs::add);
bufSlice.release();
}
assertThat(decoder.complete()).isEmpty();
for (ByteBuf bufSlice : bufSlices) {
assertThat(bufSlice.refCnt()).isEqualTo(0);
}
assertThat(msgs).containsExactly(MESSAGE);
}
}
use of tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.BeaconBlocksByRootRequestMessage in project teku by ConsenSys.
the class RpcResponseDecoderTest method decodeNextResponse_shouldParseMultipleResponses.
@Test
public void decodeNextResponse_shouldParseMultipleResponses() throws Exception {
final BeaconBlocksByRootRequestMessage secondMessage = createRequestMessage(2);
final Bytes secondMessageData = secondMessage.sszSerialize();
final Bytes compressedPayload = COMPRESSOR.compress(secondMessageData);
for (Iterable<ByteBuf> testByteBufSlice : testByteBufSlices(SUCCESS_CODE, LENGTH_PREFIX, MESSAGE_DATA, SUCCESS_CODE, getLengthPrefix(secondMessageData.size()), compressedPayload)) {
List<BeaconBlocksByRootRequestMessage> results = new ArrayList<>();
for (ByteBuf byteBuf : testByteBufSlice) {
results.addAll(decoder.decodeNextResponses(byteBuf));
byteBuf.release();
}
decoder.complete();
assertThat(results).containsExactly(MESSAGE, secondMessage);
assertThat(testByteBufSlice).allSatisfy(b -> assertThat(b.refCnt()).isEqualTo(0));
}
}
use of tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.BeaconBlocksByRootRequestMessage in project teku by ConsenSys.
the class RpcResponseDecoderTest method decodeNextResponse_shouldParseSingleResponse.
@Test
public void decodeNextResponse_shouldParseSingleResponse() throws Exception {
for (Iterable<ByteBuf> testByteBufSlice : testByteBufSlices(SUCCESS_CODE, LENGTH_PREFIX, MESSAGE_DATA)) {
List<BeaconBlocksByRootRequestMessage> results = new ArrayList<>();
for (ByteBuf byteBuf : testByteBufSlice) {
results.addAll(decoder.decodeNextResponses(byteBuf));
byteBuf.release();
}
decoder.complete();
assertThat(results).containsExactly(MESSAGE);
assertThat(testByteBufSlice).allSatisfy(b -> assertThat(b.refCnt()).isEqualTo(0));
}
}
use of tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.BeaconBlocksByRootRequestMessage in project teku by ConsenSys.
the class LengthPrefixedEncodingTest method encodePayload_shouldEncodeBlocksByRootRequest.
@Test
public void encodePayload_shouldEncodeBlocksByRootRequest() {
final Bytes encoded = encoding.encodePayload(new BeaconBlocksByRootRequestMessage(singletonList(Bytes32.ZERO)));
// Just the length prefix and the hash itself.
assertThat(encoded).isEqualTo(Bytes.wrap(Bytes.fromHexString("0x20"), new SnappyFramedCompressor().compress(Bytes32.ZERO)));
}
use of tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.BeaconBlocksByRootRequestMessage in project teku by ConsenSys.
the class BeaconBlocksByRootMessageHandlerTest method onIncomingMessage_interruptedByClosedStream.
@ParameterizedTest(name = "protocol={0}")
@MethodSource("protocolIdParams")
public void onIncomingMessage_interruptedByClosedStream(final String protocolId) {
final List<SignedBeaconBlock> blocks = buildChain(5);
// Mock callback to appear to be closed
doThrow(new StreamClosedException()).when(callback).respond(any());
final BeaconBlocksByRootRequestMessage message = createRequest(blocks);
handler.onIncomingMessage(protocolId, peer, message, callback);
// Check that we only asked for the first block
verify(store, times(1)).retrieveSignedBlock(any());
verify(callback, times(1)).respond(any());
}
Aggregations