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