public void TestGetCommittedBlockHandle() { Setup(); var messageAllocation = new Span <byte>(new byte[GetBlockHandle.SizeInBytes]); var getHandle = new GetBlockHandle(1, 5, new BlockId(new Hash256(0xFFFFFFFFUL, 0xEEEEEEEEUL, 0xDDDDDDDDUL, 0xCCCCCCCCUL))); // Serialize message to put it into the inbox MessageSerializers.ClientSerializeGetBlockHandle(getHandle, messageAllocation); _inbox.TryWrite(messageAllocation); _controller.DoWork(); var result = _outbox.Peek(); Assert.Equal(MessageType.BlockHandle, ClientServerMessage.GetMessageType(result)); var response = MessageSerializers.ClientDeserializeBlockHandleResponse(result); Assert.Equal(1U, response.RequestId); Assert.Equal(5U, response.ClientId); Assert.Equal(_3, response.BlockHandle); }
public void SerializeDeserializeGetBlockHandle() { var getBlockHandle = new GetBlockHandle(3, 4, new BlockId(new Hash256(987654321, 123456789, 567894321, 432156789))); MessageSerializers.ClientSerializeGetBlockHandle(getBlockHandle, _buffer); var newGetBlockHandle = MessageSerializers.DeserializeGetBlockHandle(_buffer); Assert.True(getBlockHandle.ClientId == newGetBlockHandle.ClientId && getBlockHandle.RequestId == newGetBlockHandle.RequestId && getBlockHandle.RequestType == newGetBlockHandle.RequestType && getBlockHandle.BlockId.Equals(newGetBlockHandle.BlockId)); }
public static void ClientSerializeGetBlockHandle(GetBlockHandle getBlockHandle, Span <byte> toWrite) { if (toWrite.Length < GetBlockHandle.SizeInBytes) { throw new ArgumentException( $"Given Span of length {toWrite.Length} too short to write {OpenBlock.SizeInBytes} bytes of {nameof(OpenBlock)} request"); } var editor = new SpanBinaryEditor(toWrite); var messageHeader = new MessageHeader(GetBlockHandle.SizeInBytes, getBlockHandle.RequestId, getBlockHandle.ClientId, MessageInfo.FromType(getBlockHandle.RequestType)); WriteMessageHeader(ref messageHeader, ref editor); getBlockHandle.BlockId.WriteTo(ref editor); }
public void terab_utxo_get_block() { terab_utxo_commit_block(); _socket.ExpectConnected(() => true); _socket.ExpectConnected(() => true); _socket.ExpectConnected(() => true); _socket.ExpectAvailable(() => GetBlockHandle.SizeInBytes); _socket.ExpectReceive(data => { data.Clear(); Assert.True(data.Length >= GetBlockHandle.SizeInBytes); var getHandle = new GetBlockHandle(1, 0, BlockId.Genesis); MessageSerializers.ClientSerializeGetBlockHandle(getHandle, data); return(GetBlockHandle.SizeInBytes); }); _socket.ExpectConnected(() => true); _socket.ExpectAvailable(() => 0); _socket.ExpectConnected(() => true); _socket.ExpectSend(data => { Assert.Equal(BlockHandleResponse.SizeInBytes, data.Length); BlockHandleResponse response = MessageSerializers.ClientDeserializeBlockHandleResponse(data); Assert.Equal(BlockAlias.Genesis, response.BlockHandle); return(BlockHandleResponse.SizeInBytes); }); _dispatcher.ListenToConnections(); _controllerThread.DoWork(); _dispatcher.SendResponses(); _socket.ExpectAllDone(); }