示例#1
0
        public void StartHandShakeTest()
        {
            var pl = new MockSerializableMessagePayload(PayloadType.Version, new byte[3] {
                1, 2, 3
            });
            Message msg = new Message(pl, NetworkType.MainNet);

            byte[] msgSer = Helper.HexToBytes("f9beb4d976657273696f6e00000000000300000019c6197e010203");
            var    repMan = new MockReplyManager()
            {
                verMessage = msg
            };
            MessageManager man = new MessageManager(30, repMan, new NodeStatus(), NetworkType.MainNet);

            using SocketAsyncEventArgs sarg = new SocketAsyncEventArgs();
            sarg.SetBuffer(new byte[30], 0, 30);

            byte[] expBuffer = new byte[30];
            Buffer.BlockCopy(msgSer, 0, expBuffer, 0, msgSer.Length);

            man.StartHandShake(sarg);

            Assert.Equal(expBuffer, sarg.Buffer);
            Assert.Equal(msgSer.Length, sarg.Count);
            Assert.Equal(0, sarg.Offset);
            Assert.Null(man.DataToSend); // StartHandShake sets the SAEA buffer and sets the field to null
            Assert.False(man.HasDataToSend);
            Assert.True(man.IsReceiveCompleted);
        }
示例#2
0
        public void GetReply_UndefinedPayloadTest()
        {
            var pl  = new MockSerializableMessagePayload((PayloadType)10000, new byte[] { 1, 2, 3 });
            var msg = new Message(pl, NetworkType.MainNet);
            var ns  = new MockNodeStatus()
            {
                _handShakeToReturn = HandShakeState.Finished,
                smallViolation     = true,
                updateTime         = true
            };
            var rep = new ReplyManager(ns, new MockBlockchain(), new MockClientSettings());

            var actual = rep.GetReply(msg);

            Assert.Null(actual);
            Assert.False(ns.updateTime);
        }