Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        public static void ClientSerializeCommitBlock(CommitBlock commitBlock, Span <byte> toWrite)
        {
            var editor = new SpanBinaryEditor(toWrite);

            var messageHeader = new MessageHeader(CommitBlock.SizeInBytes, commitBlock.RequestId,
                                                  commitBlock.ClientId, MessageInfo.FromType(commitBlock.RequestType));

            WriteMessageHeader(ref messageHeader, ref editor);

            editor.WriteUInt32(commitBlock.BlockHandle.Value);
            commitBlock.BlockId.WriteTo(ref editor);
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        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();
        }