Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        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();
        }