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); }
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 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 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 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 static void ClientSerializeGetBlockInformation(GetBlockInformation getInfo, in Span <byte> toWrite)