Ejemplo n.º 1
0
        public void TestGetUncommittedBlockHandle()
        {
            // TODO: [vermorel] Remove all inter-test dependencies

            var(_, inbox, outbox, chainController, c5, uncommittedBlockId) = TestOpenBlock();

            // C(0) -> C(1) -> C(2)   -> C(3) -> C(4)
            //             |                 \-> C(4-1)
            //             |                 \-> U(4-2)
            //             \-> C(2-1) -> C(3-1)

            var request = GetBlockHandleRequest.From(_r1, c5, uncommittedBlockId);

            inbox.TryWrite(request.Span);

            chainController.HandleRequest();

            outbox.Next(); // because we did the TestOpenBlock in the beginning
            var result = new GetBlockHandleResponse(outbox.Peek().Span);

            Assert.Equal(MessageKind.BlockHandleResponse, result.MessageHeader.MessageKind);

            Assert.Equal(_r1, result.MessageHeader.RequestId);
            Assert.Equal(c5, result.MessageHeader.ClientId);
            Assert.Equal(_4_2, result.Handle.ConvertToBlockAlias(c5.Mask));
        }
Ejemplo n.º 2
0
        public void terab_utxo_get_uncommitted_block()
        {
            var blockUcid = terab_utxo_open_block();

            _socket.ExpectReceive(data =>
            {
                data.Clear();
                Assert.True(data.Length == MessageHeader.SizeInBytes);

                var header = new MessageHeader(GetBlockHandleRequest.SizeInBytes,
                                               _r1, _c0, MessageKind.GetBlockHandle);
                var headerStorage = new MessageHeader[1];
                headerStorage[0]  = header;
                var headerBytes   = MemoryMarshal.Cast <MessageHeader, byte>(headerStorage);
                headerBytes.CopyTo(data);

                return(MessageHeader.SizeInBytes);
            });

            _socket.ExpectReceive(data =>
            {
                data.Clear();
                Assert.True(data.Length == GetBlockHandleRequest.SizeInBytes - MessageHeader.SizeInBytes);

                // TODO: [vermorel] bytes are off here
                var request = GetBlockHandleRequest.From(_r1, _c0, blockUcid);
                request.Span.Slice(16).CopyTo(data);

                return(GetBlockHandleRequest.SizeInBytes - MessageHeader.SizeInBytes);
            });

            _socket.ExpectConnected(() => true);
            _socket.ExpectConnected(() => true);

            _socket.ExpectSend(data =>
            {
                Assert.Equal(GetBlockHandleResponse.SizeInBytes, data.Length);
                var response = new GetBlockHandleResponse(data);
                Assert.Equal(new BlockAlias(0, 0), response.Handle.ConvertToBlockAlias(_handleMask));
                return(GetBlockHandleResponse.SizeInBytes);
            });

            Assert.True(_clientConn.HandleRequest());

            Assert.True(_dispatcher.HandleRequest());

            Assert.True(_chainController.HandleRequest());

            Assert.True(_dispatcher.HandleRequest());

            Assert.True(_clientConn.HandleResponse());

            _socket.ExpectAllDone();
        }
Ejemplo n.º 3
0
        public void OpenGetBlockHandle()
        {
            var instance = GetInstance();

            instance.Start();

            var localEndpoint = new IPEndPoint(IPAddress.Loopback, instance.Port);
            var rawSocket     = new Socket(localEndpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

            rawSocket.Connect(localEndpoint);

            var socket = new SocketLikeAdapter(rawSocket);

            try
            {
                // Open block
                var openBlockRequest = OpenBlockRequest.ForGenesis(RequestId.MinRequestId);
                socket.Send(openBlockRequest.Span);

                var openBlockResponse = new OpenBlockResponse(new byte[OpenBlockResponse.SizeInBytes]);
                socket.Receive(openBlockResponse.Span);

                Assert.Equal(OpenBlockStatus.Success, openBlockResponse.Status);

                // Get block handle
                var clientId           = new ClientId();
                var blockHandleRequest = GetBlockHandleRequest.From(
                    new RequestId(1), clientId, openBlockResponse.UncommittedBlockId);
                socket.Send(blockHandleRequest.Span);

                var blockHandleResponse = new GetBlockHandleResponse(new byte[GetBlockHandleResponse.SizeInBytes]);
                socket.Receive(blockHandleResponse.Span);

                Assert.Equal(GetBlockHandleStatus.Success, blockHandleResponse.Status);
                Assert.Equal(openBlockResponse.Handle, blockHandleResponse.Handle);
                Assert.Equal(default(ClientId), blockHandleResponse.MessageHeader.ClientId);
                Assert.Equal(new RequestId(1), blockHandleResponse.MessageHeader.RequestId);
            }
            finally
            {
                socket.Close();
                instance.Stop();
            }
        }
Ejemplo n.º 4
0
        public void TestGetCommittedBlockHandle()
        {
            var(_, inbox, outbox, chainController, c5) = Setup();

            var request = GetBlockHandleRequest.From(_r1, c5, _id_2);

            inbox.TryWrite(request.Span);

            chainController.HandleRequest();

            var result = new GetBlockHandleResponse(outbox.Peek().Span);

            Assert.Equal(MessageKind.BlockHandleResponse, result.MessageHeader.MessageKind);

            Assert.Equal(_r1, result.MessageHeader.RequestId);
            Assert.Equal(c5, result.MessageHeader.ClientId);

            Assert.Equal(_2, result.Handle.ConvertToBlockAlias(c5.Mask));
        }