public void TestOpenFirstBlock() { _controller = new ControllerThread(_chain, default(OptimizedLineage), _inbox = BoundedInbox.Create(), _outbox = BoundedInbox.Create()); var messageAllocation = new Span <byte>(new byte[OpenBlock.SizeInBytes]); var openBlock = new OpenBlock(1, 5, BlockAlias.GenesisParent); // Serialize message to put it into the inbox MessageSerializers.ClientSerializeOpenBlock(openBlock, messageAllocation); _inbox.TryWrite(messageAllocation); _controller.DoWork(); var result = _outbox.Peek(); Assert.Equal(MessageType.OpenedBlock, ClientServerMessage.GetMessageType(result)); var response = MessageSerializers.ClientDeserializeOpenedBlock(result); Assert.Equal(1U, response.RequestId); Assert.Equal(5U, response.ClientId); Assert.Equal(_1, response.Alias); var tmpId = response.UncommittedBlockId; Console.WriteLine(tmpId); }
public override void Handle(IMessage message) { var type = message.GetType(); Log.Trace($"Message {message.MsgId} (Type {type.Name}) to be sent over TCP."); if (TcpConnections == null) { Log.Debug($"TCP connection not yet established - Message {message.MsgId} (Type {type.Name}) will be discarded."); return; } try { if (TcpConnections.IsEmpty()) { Log.Error("Cannot send a message without a connection."); return; } var connection = TcpConnections.First(); if (!MessageSerializers.TryGetValue(type, out var serializer)) { serializer = new SimpleJsonSerializer(); } var json = serializer.SerializeMessage(message); var data = Encoder.ToBytes(json, type); var framed = Framer.FrameData(data); connection.EnqueueSend(framed); } catch (Exception ex) { Log.ErrorException(ex, $"Exception caught while handling Message {message.MsgId} (Type {type.Name})"); } }
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 TestGetCommittedBlockInfo() { Setup(); var messageAllocation = new Span <byte>(new byte[GetBlockInformation.SizeInBytes]); var getInfo = new GetBlockInformation(1, 5, _1); // Serialize message to put it into the inbox MessageSerializers.ClientSerializeGetBlockInformation(getInfo, messageAllocation); _inbox.TryWrite(messageAllocation); _controller.DoWork(); var result = _outbox.Peek(); Assert.Equal(MessageType.CommittedBlockInfo, ClientServerMessage.GetMessageType(result)); var response = MessageSerializers.ClientDeserializeCommittedBlockInfo(result); Assert.Equal(1U, response.RequestId); Assert.Equal(5U, response.ClientId); Assert.Equal(BlockId.Genesis, response.BlockId); Assert.Equal(_1, response.Alias); Assert.Equal(0u, response.Parent.Value); Assert.Equal(0, response.BlockHeight); }
public TempBlockId TestOpenBlock() { Setup(); var messageAllocation = new Span <byte>(new byte[OpenBlock.SizeInBytes]); var openBlock = new OpenBlock(1, 5, _3); // Serialize message to put it into the inbox MessageSerializers.ClientSerializeOpenBlock(openBlock, messageAllocation); _inbox.TryWrite(messageAllocation); _controller.DoWork(); var result = _outbox.Peek(); Assert.Equal(MessageType.OpenedBlock, ClientServerMessage.GetMessageType(result)); var response = MessageSerializers.ClientDeserializeOpenedBlock(result); Assert.Equal(1U, response.RequestId); Assert.Equal(5U, response.ClientId); Assert.Equal(_9, response.Alias); return(response.UncommittedBlockId); }
public void TestCommitBlock() { TestOpenBlock(); var messageAllocation = new Span <byte>(new byte[CommitBlock.SizeInBytes]); var commitBlock = new CommitBlock(1, 5, _9, new BlockId(new Hash256(0xFFFFFFFFUL, 0xEEEEEEEEUL, 0xDDDDDDDDUL, 0xCCCCCCCEUL))); // Serialize message to put it into the inbox MessageSerializers.ClientSerializeCommitBlock(commitBlock, messageAllocation); _inbox.TryWrite(messageAllocation); _controller.DoWork(); _outbox.Next(); var result = _outbox.Peek(); Assert.Equal(MessageType.EverythingOk, ClientServerMessage.GetMessageType(result)); var response = MessageSerializers.ClientDeserializeEverythingOk(result); Assert.Equal(1U, response.RequestId); Assert.Equal(5U, response.ClientId); }
public void TestGetUncommittedBlockInfo() { var uncommittedBlockId = TestOpenBlock(); var messageAllocation = new Span <byte>(new byte[GetBlockInformation.SizeInBytes]); var getInfo = new GetBlockInformation(1, 5, _9); // Serialize message to put it into the inbox MessageSerializers.ClientSerializeGetBlockInformation(getInfo, messageAllocation); _inbox.TryWrite(messageAllocation); _controller.DoWork(); _outbox.Next(); var result = _outbox.Peek(); Assert.Equal(MessageType.UncommittedBlockInfo, ClientServerMessage.GetMessageType(result)); var response = MessageSerializers.ClientDeserializeUncommittedBlockInfo(result); Assert.Equal(1U, response.RequestId); Assert.Equal(5U, response.ClientId); Assert.Equal(uncommittedBlockId, response.UncommittedBlockId); Assert.Equal(_9, response.Alias); Assert.Equal(_3, response.Parent); Assert.Equal(3, response.BlockHeight); }
//used to send file names with complete path so that the server may load them and process them. public void Send(string data) { GenericMessage m = new GenericMessage(); m.MessageId = Guid.NewGuid(); m.Recipient = "VS"; m.Originator = "Unity"; m.MessageType = typeof(String); m.MessageDateTime = DateTime.Now; m.Payload = System.Text.Encoding.UTF8.GetBytes(data); byte[] b = MessageSerializers.SerializeMessage(m); pipeClient.SendMessage(b); /*else if((string) cboMessageType.SelectedItem == "DataSet") * { * GenericMessage m = new GenericMessage(); * m.MessageId = Guid.NewGuid(); * m.Recipient = "AppTwo"; * m.Originator = "AppOne"; * m.MessageType = typeof(System.Data.DataSet ); * m.MessageDateTime = DateTime.Now; * byte[] dsBytes = MessageSerializers.SerializeObject(ds); * m.Payload = dsBytes; * * byte[] b = MessageSerializers.SerializeMessage(m); * pipeClient.SendMessage(b); * }*/ }
public void TestGetUncommittedBlockHandle() { var uncommitedBlockId = TestOpenBlock(); var messageAllocation = new Span <byte>(new byte[GetUncommittedBlockHandle.SizeInBytes]); var getHandle = new GetUncommittedBlockHandle(1, 5, uncommitedBlockId); // Serialize message to put it into the inbox MessageSerializers.ClientSerializeGetUncommittedBlockHandle(getHandle, messageAllocation); _inbox.TryWrite(messageAllocation); _controller.DoWork(); _outbox.Next(); // because we did the TestOpenBlock in the beginning 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(_9, response.BlockHandle); }
public void SerializeDeserializeEverythingOk() { var everythinkOkResponse = new EverythingOkResponse(9947832, 89478310); MessageSerializers.SerializeEverythingOk(everythinkOkResponse, _buffer); var newEverythingOkResponse = MessageSerializers.ClientDeserializeEverythingOk(_buffer); Assert.True(everythinkOkResponse.ClientId == newEverythingOkResponse.ClientId && everythinkOkResponse.RequestId == newEverythingOkResponse.RequestId && everythinkOkResponse.ResponseType == newEverythingOkResponse.ResponseType); }
public void SerializeDeserializeIsPruneable() { var isPruneable = new IsPruneable(9947832, 89478310, new BlockAlias(702349)); MessageSerializers.ClientSerializeIsPruneable(isPruneable, _buffer); var newIsPruneable = MessageSerializers.DeserializeIsPruneable(_buffer); Assert.True(isPruneable.ClientId == newIsPruneable.ClientId && isPruneable.RequestId == newIsPruneable.RequestId && isPruneable.RequestType == newIsPruneable.RequestType && isPruneable.BlockHandle == newIsPruneable.BlockHandle); }
public void SerializeDeserializeOpenBlock() { var openBlock = new OpenBlock(3, 4, new BlockAlias(987623)); MessageSerializers.ClientSerializeOpenBlock(openBlock, _buffer); var newOpenBlock = MessageSerializers.DeserializeOpenBlock(_buffer); Assert.True(openBlock.ClientId == newOpenBlock.ClientId && openBlock.RequestId == newOpenBlock.RequestId && openBlock.RequestType == newOpenBlock.RequestType && openBlock.ParentHandle == newOpenBlock.ParentHandle); }
public void SerializeDeserializeGetBlockInfo() { var getBlockInfo = new GetBlockInformation(3, 4, new BlockAlias(70)); MessageSerializers.ClientSerializeGetBlockInformation(getBlockInfo, _buffer); var newGetBlockInfo = MessageSerializers.DeserializeGetBlockInfo(_buffer); Assert.True(getBlockInfo.ClientId == newGetBlockInfo.ClientId && getBlockInfo.RequestId == newGetBlockInfo.RequestId && getBlockInfo.RequestType == newGetBlockInfo.RequestType && getBlockInfo.BlockHandle == newGetBlockInfo.BlockHandle); }
public void SerializeDeserializeGetUBlockHandle() { var getUBlockHandle = new GetUncommittedBlockHandle(3, 4, new TempBlockId(new Hash128(987654321, 123456789))); MessageSerializers.ClientSerializeGetUncommittedBlockHandle(getUBlockHandle, _buffer); var newGetUBlockHandle = MessageSerializers.DeserializeGetUncommittedBlockHandle(_buffer); Assert.True(getUBlockHandle.ClientId == newGetUBlockHandle.ClientId && getUBlockHandle.RequestId == newGetUBlockHandle.RequestId && getUBlockHandle.RequestType == newGetUBlockHandle.RequestType && getUBlockHandle.UncommittedBlockId.Equals(newGetUBlockHandle.UncommittedBlockId)); }
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 void SerializeDeserializePruneableResponse() { var pruneableResponse = new PruneableResponse(9947832, 89478310, false); MessageSerializers.SerializePruneableResponse(pruneableResponse, _buffer); var newpruneableResponse = MessageSerializers.ClientDeserializePruneableResponse(_buffer); Assert.True(pruneableResponse.ClientId == newpruneableResponse.ClientId && pruneableResponse.RequestId == newpruneableResponse.RequestId && pruneableResponse.ResponseType == newpruneableResponse.ResponseType && pruneableResponse.Answer == newpruneableResponse.Answer); }
public void SerializeDeserializeAncestorResponse() { var ancestorResponse = new AncestorResponse(9947832, 89478310, true); MessageSerializers.SerializeAncestorResponse(ancestorResponse, _buffer); var newAncestorResponse = MessageSerializers.ClientDeserializeAncestorResponse(_buffer); Assert.True(ancestorResponse.ClientId == newAncestorResponse.ClientId && ancestorResponse.RequestId == newAncestorResponse.RequestId && ancestorResponse.ResponseType == newAncestorResponse.ResponseType && ancestorResponse.Answer == newAncestorResponse.Answer); }
public void SerializeDeserializeBlockHandleResponse() { var blockHandleResponse = new BlockHandleResponse(9947832, 89478310, new BlockAlias(702349)); MessageSerializers.SerializeBlockHandleResponse(blockHandleResponse, _buffer); var newBlockHandleResponse = MessageSerializers.ClientDeserializeBlockHandleResponse(_buffer); Assert.True(blockHandleResponse.ClientId == newBlockHandleResponse.ClientId && blockHandleResponse.RequestId == newBlockHandleResponse.RequestId && blockHandleResponse.ResponseType == newBlockHandleResponse.ResponseType && blockHandleResponse.BlockHandle == newBlockHandleResponse.BlockHandle); }
public void SerializeDeserializeIsAncestor() { var isAncestor = new IsAncestor(9947832, 89478310, new BlockAlias(702349), new BlockAlias(679)); MessageSerializers.ClientSerializeIsAncestor(isAncestor, _buffer); var newIsAncestor = MessageSerializers.DeserializeIsAncestor(_buffer); Assert.True(isAncestor.ClientId == newIsAncestor.ClientId && isAncestor.RequestId == newIsAncestor.RequestId && isAncestor.RequestType == newIsAncestor.RequestType && isAncestor.BlockHandle == newIsAncestor.BlockHandle && isAncestor.MaybeAncestorHandle == newIsAncestor.MaybeAncestorHandle); }
public void SerializeDeserializeCommitBlock() { var commitBlock = new CommitBlock(3, 4, new BlockAlias(70), new BlockId(new Hash256(987654321, 123456789, 567894321, 432156789))); MessageSerializers.ClientSerializeCommitBlock(commitBlock, _buffer); var newCommitBlock = MessageSerializers.DeserializeCommitBlock(_buffer); Assert.True(commitBlock.ClientId == newCommitBlock.ClientId && commitBlock.RequestId == newCommitBlock.RequestId && commitBlock.RequestType == newCommitBlock.RequestType && commitBlock.BlockId.Equals(newCommitBlock.BlockId) && commitBlock.BlockHandle == newCommitBlock.BlockHandle); }
public void SerializeDeserializeOpenedBlock() { var openedBlock = new OpenedBlock(3, 4, new TempBlockId(new Hash128(987654321, 123456789)), new BlockAlias(326432)); MessageSerializers.SerializeOpenedBlock(openedBlock, _buffer); var newOpenedBlock = MessageSerializers.ClientDeserializeOpenedBlock(_buffer); Assert.True(openedBlock.ClientId == newOpenedBlock.ClientId && openedBlock.RequestId == newOpenedBlock.RequestId && openedBlock.ResponseType == newOpenedBlock.ResponseType && openedBlock.Alias == newOpenedBlock.Alias && openedBlock.UncommittedBlockId.Equals(newOpenedBlock.UncommittedBlockId)); }
public TempBlockId terab_utxo_open_block() { Setup(); TempBlockId?result = null; _socket.ExpectConnected(() => true); _socket.ExpectConnected(() => true); _socket.ExpectConnected(() => true); _socket.ExpectAvailable(() => OpenBlock.SizeInBytes); _socket.ExpectReceive(data => { data.Clear(); Assert.True(data.Length >= OpenBlock.SizeInBytes); var openBlock = new OpenBlock(1, 0, _zero); // Serialize message to put it into the inbox MessageSerializers.ClientSerializeOpenBlock(openBlock, data); return(OpenBlock.SizeInBytes); }); _socket.ExpectConnected(() => true); _socket.ExpectAvailable(() => 0); _socket.ExpectConnected(() => true); _socket.ExpectSend(data => { Assert.Equal(OpenedBlock.SizeInBytes, data.Length); OpenedBlock openedBlock = MessageSerializers.ClientDeserializeOpenedBlock(data); Assert.Equal(OpenedBlock.SizeInBytes, BitConverter.ToInt32(data)); Assert.Equal((uint)1, openedBlock.RequestId); // request ID Assert.Equal((uint)0, openedBlock.ClientId); // client ID field empty result = openedBlock.UncommittedBlockId; return(OpenedBlock.SizeInBytes); }); _dispatcher.ListenToConnections(); _controllerThread.DoWork(); _dispatcher.SendResponses(); _socket.ExpectAllDone(); return(result.Value); }
public void TestIsAncestor() { Setup(); var messageAllocation = new Span <byte>(new byte[IsAncestor.SizeInBytes]); var isAncestorReq = new IsAncestor(1, 5, _3, _1); // Serialize message to put it into the inbox MessageSerializers.ClientSerializeIsAncestor(isAncestorReq, messageAllocation); _inbox.TryWrite(messageAllocation); _controller.DoWork(); var result = _outbox.Peek(); Assert.Equal(MessageType.AncestorResponse, ClientServerMessage.GetMessageType(result)); Assert.True(ClientServerMessage.TryGetLength(result, out int responseSize)); Assert.Equal(AncestorResponse.SizeInBytes, responseSize); var response = MessageSerializers.ClientDeserializeAncestorResponse(result); Assert.Equal(1U, response.RequestId); Assert.Equal(5U, response.ClientId); Assert.True(response.Answer); // get a wrong ancestor isAncestorReq = new IsAncestor(1, 5, _3, _5); // Serialize message to put it into the inbox MessageSerializers.ClientSerializeIsAncestor(isAncestorReq, messageAllocation); _inbox.TryWrite(messageAllocation); _controller.DoWork(); _outbox.Next(); result = _outbox.Peek(); var response2 = MessageSerializers.ClientDeserializeAncestorResponse(result); Assert.Equal(1U, response2.RequestId); Assert.Equal(5U, response2.ClientId); Assert.Equal(MessageType.AncestorResponse, response2.ResponseType); Assert.False(response2.Answer); }
public void SerializeDeserializeCommittedBlockInfo() { var committedBlockInfo = new CommittedBlockInformation(3, 4, new BlockId(new Hash256(987654321, 123456789, 567894321, 432156789)), new BlockAlias(70), 700, new BlockAlias(7000)); MessageSerializers.SerializeCommittedBlockInfo(committedBlockInfo, _buffer); var newCommittedBlockInfo = MessageSerializers.ClientDeserializeCommittedBlockInfo(_buffer); Assert.True(committedBlockInfo.ClientId == newCommittedBlockInfo.ClientId && committedBlockInfo.RequestId == newCommittedBlockInfo.RequestId && committedBlockInfo.ResponseType == newCommittedBlockInfo.ResponseType && committedBlockInfo.Alias == newCommittedBlockInfo.Alias && committedBlockInfo.BlockHeight == newCommittedBlockInfo.BlockHeight && committedBlockInfo.Parent == newCommittedBlockInfo.Parent && committedBlockInfo.BlockId.Equals(newCommittedBlockInfo.BlockId)); }
public void terab_uxto_get_blockinfo_committed() { terab_utxo_commit_block(); _socket.ExpectConnected(() => true); _socket.ExpectConnected(() => true); _socket.ExpectConnected(() => true); _socket.ExpectAvailable(() => GetBlockInformation.SizeInBytes); _socket.ExpectReceive(data => { data.Clear(); Assert.True(data.Length >= GetBlockInformation.SizeInBytes); var getInfo = new GetBlockInformation(1, 0, BlockAlias.Genesis); // Serialize message to put it into the inbox MessageSerializers.ClientSerializeGetBlockInformation(getInfo, data); return(GetBlockInformation.SizeInBytes); }); _socket.ExpectConnected(() => true); _socket.ExpectAvailable(() => 0); _socket.ExpectConnected(() => true); _socket.ExpectSend(data => { Assert.Equal(CommittedBlockInformation.SizeInBytes, data.Length); var commitedInfo = MessageSerializers.ClientDeserializeCommittedBlockInfo(data); Assert.Equal(BlockAlias.Genesis, commitedInfo.Alias); Assert.Equal(BlockAlias.GenesisParent, commitedInfo.Parent); Assert.Equal(0, commitedInfo.BlockHeight); Assert.Equal(BlockId.Genesis, commitedInfo.BlockId); return(CommittedBlockInformation.SizeInBytes); }); _dispatcher.ListenToConnections(); _controllerThread.DoWork(); _dispatcher.SendResponses(); _socket.ExpectAllDone(); }
public override void Handle(IMessage message) { // The server side does not initiate communication. The only messages it will ever send are // CommandResponses back to a client who sent a Command. var type = message.GetType(); if (!(message is CommandResponse cmdResponse)) { Log.Debug($"Cannot send a message of type {type.Name} from a server-side TCP bus."); return; } Log.Trace($"Message {message.MsgId} (Type {type.Name}) to be sent over TCP."); if (TcpConnections.IsEmpty()) { Log.Debug($"TCP connection not yet established - Message {message.MsgId} (Type {type.Name}) will be discarded."); return; } try { // Send the CommandResponse back to the endpoint where the Command originated. var connectionId = _messageRouting[cmdResponse.SourceCommand.MsgId]; var connection = TcpConnections.FirstOrDefault(x => x.ConnectionId == connectionId); if (connection is null) { throw new Exception("Could not find a TCP connection to use for sending the message."); } if (!MessageSerializers.TryGetValue(type, out var serializer)) { serializer = new SimpleJsonSerializer(); } var json = serializer.SerializeMessage(message); var data = Encoder.ToBytes(json, type); var framed = Framer.FrameData(data); connection.EnqueueSend(framed); } catch (Exception ex) { Log.ErrorException(ex, $"An error occurred while handling Message {message.MsgId} (Type {type.Name})"); } }
public void terab_uxto_get_blockinfo_uncommitted() { TempBlockId blockUcid = terab_utxo_open_block(); _socket.ExpectConnected(() => true); _socket.ExpectConnected(() => true); _socket.ExpectConnected(() => true); _socket.ExpectAvailable(() => GetBlockInformation.SizeInBytes); _socket.ExpectReceive(data => { data.Clear(); Assert.True(data.Length >= GetBlockInformation.SizeInBytes); var getInfo = new GetBlockInformation(1, 0, BlockAlias.Genesis); MessageSerializers.ClientSerializeGetBlockInformation(getInfo, data); return(GetBlockInformation.SizeInBytes); }); _socket.ExpectConnected(() => true); _socket.ExpectAvailable(() => 0); _socket.ExpectConnected(() => true); _socket.ExpectSend(data => { Assert.Equal(UncommittedBlockInformation.SizeInBytes, data.Length); var actualBlockInfo = MessageSerializers.ClientDeserializeUncommittedBlockInfo(data); Assert.Equal(BlockAlias.Genesis, actualBlockInfo.Alias); Assert.Equal(BlockAlias.GenesisParent, actualBlockInfo.Parent); Assert.Equal(0, actualBlockInfo.BlockHeight); Assert.Equal(blockUcid, actualBlockInfo.UncommittedBlockId); return(UncommittedBlockInformation.SizeInBytes); }); _dispatcher.ListenToConnections(); _controllerThread.DoWork(); _dispatcher.SendResponses(); _socket.ExpectAllDone(); }
public void TestIsPruneable() { Setup(); var messageAllocation = new Span <byte>(new byte[IsPruneable.SizeInBytes]); var isPruneableReq = new IsPruneable(1, 5, _3); // Serialize message to put it into the inbox MessageSerializers.ClientSerializeIsPruneable(isPruneableReq, messageAllocation); _inbox.TryWrite(messageAllocation); _controller.DoWork(); var result = _outbox.Peek(); var response = MessageSerializers.ClientDeserializePruneableResponse(result); Assert.Equal(MessageType.PruneableResponse, ClientServerMessage.GetMessageType(result)); Assert.Equal(1U, response.RequestId); Assert.Equal(5U, response.ClientId); Assert.False(response.Answer); _outbox.Next(); isPruneableReq = new IsPruneable(1, 5, _4); // Serialize message to put it into the inbox MessageSerializers.ClientSerializeIsPruneable(isPruneableReq, messageAllocation); _inbox.TryWrite(messageAllocation); _controller.DoWork(); result = _outbox.Peek(); Assert.Equal(MessageType.PruneableResponse, ClientServerMessage.GetMessageType(result)); var response2 = MessageSerializers.ClientDeserializePruneableResponse(result); Assert.Equal(1U, response.RequestId); Assert.Equal(5U, response.ClientId); Assert.True(response2.Answer); }
public void terab_utxo_get_uncommitted_block() { var blockUcid = terab_utxo_open_block(); _socket.ExpectConnected(() => true); _socket.ExpectConnected(() => true); _socket.ExpectConnected(() => true); _socket.ExpectAvailable(() => GetUncommittedBlockHandle.SizeInBytes); _socket.ExpectReceive(data => { data.Clear(); Assert.True(data.Length >= GetUncommittedBlockHandle.SizeInBytes); var getUHandle = new GetUncommittedBlockHandle(1, 0, blockUcid); // Serialize message to put it into the inbox MessageSerializers.ClientSerializeGetUncommittedBlockHandle(getUHandle, data); return(GetUncommittedBlockHandle.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(); }
public void terab_utxo_commit_block() { terab_utxo_get_uncommitted_block(); _socket.ExpectConnected(() => true); _socket.ExpectConnected(() => true); _socket.ExpectConnected(() => true); _socket.ExpectAvailable(() => CommitBlock.SizeInBytes); _socket.ExpectReceive(data => { data.Clear(); Assert.True(data.Length >= CommitBlock.SizeInBytes); var commit = new CommitBlock(1, 0, BlockAlias.Genesis, BlockId.Genesis); // Serialize message to put it into the inbox MessageSerializers.ClientSerializeCommitBlock(commit, data); return(CommitBlock.SizeInBytes); }); _socket.ExpectConnected(() => true); _socket.ExpectAvailable(() => 0); _socket.ExpectConnected(() => true); _socket.ExpectSend(data => { Assert.Equal(EverythingOkResponse.SizeInBytes, data.Length); return(EverythingOkResponse.SizeInBytes); }); _dispatcher.ListenToConnections(); _controllerThread.DoWork(); _dispatcher.SendResponses(); _socket.ExpectAllDone(); }