示例#1
0
        public void GetReplyTest(MockNodeStatus ns, IClientSettings cs, IBlockchain bc, Message msg, Message[] expected)
        {
            var rep = new ReplyManager(ns, bc, cs);

            Message[] actual = rep.GetReply(msg);

            if (expected is null)
            {
                Assert.Null(actual);
            }
            else
            {
                Assert.NotNull(actual);
                Assert.Equal(expected.Length, actual.Length);
                for (int i = 0; i < expected.Length; i++)
                {
                    var actualStream   = new FastStream(Constants.MessageHeaderSize + actual[i].PayloadData.Length);
                    var expectedStream = new FastStream(Constants.MessageHeaderSize + expected[i].PayloadData.Length);
                    actual[i].Serialize(actualStream);
                    expected[i].Serialize(expectedStream);

                    Assert.Equal(expectedStream.ToByteArray(), actualStream.ToByteArray());
                }
            }

            // Mock will change the following bools to false if it were called.
            Assert.False(ns.updateTime, "UpdateTime() was never called");
            Assert.False(ns.smallViolation, "AddSmallViolation() was never called");
            Assert.False(ns.mediumViolation, "AddMediumViolation() was never called");
            Assert.False(ns.bigViolation, "AddBigViolation() was never called");
        }
示例#2
0
        public void CheckVersionTest(MockNodeStatus ns, IClientSettings cs, IBlockchain bc, Message msg, Message[] expected)
        {
            var rep = new ReplyManager(ns, bc, cs)
            {
                rng = new MockNonceRng(0x0158a8e8ba5f3ed3)
            };

            Message[] actual = rep.GetReply(msg);

            if (expected is null)
            {
                Assert.Null(actual);
            }
            else
            {
                Assert.NotNull(actual);
                Assert.Equal(expected.Length, actual.Length);
                for (int i = 0; i < expected.Length; i++)
                {
                    var actualStream   = new FastStream(Constants.MessageHeaderSize + actual[i].PayloadData.Length);
                    var expectedStream = new FastStream(Constants.MessageHeaderSize + expected[i].PayloadData.Length);
                    actual[i].Serialize(actualStream);
                    expected[i].Serialize(expectedStream);

                    Assert.Equal(expectedStream.ToByteArray(), actualStream.ToByteArray());
                }
            }

            // Mock will change the following bool to false if it were called.
            Assert.False(ns.updateTime, "UpdateTime() was never called");

            // Mock either doesn't have any h.s. to set or if it did set h.s. it was checked and then turned to null
            Assert.Null(ns._handShakeToSet);
        }
示例#3
0
        public DisplayReplyPagination GetMyReply(int count = 25, string token = null, bool keepUnread = false)
        {
            string me = whoami();

            if (!keepUnread && token == null)
            {
                _notifManager.clearReplyNotifCount(me);
            }
            return(_replyManager.GetReply(me, count, Utils.String2Token(token)));
        }
示例#4
0
        public void CheckVerackTest(MockNodeStatus ns)
        {
            var rep = new ReplyManager(ns, new MockBlockchain(), new MockClientSettings());
            var msg = new Message(new VerackPayload(), NetworkType.MainNet);

            Message[] actual = rep.GetReply(msg);
            Assert.Null(actual);

            // Mock will change the following bool to false if it were called.
            Assert.False(ns.updateTime, "UpdateTime() was never called");

            // Mock either doesn't have any h.s. to set or if it did set h.s. it was checked and then turned to null
            Assert.Null(ns._handShakeToSet);
        }
示例#5
0
        public void GetReply_IgnoredMessagesTest(Message msg)
        {
            var ns = new MockNodeStatus()
            {
                _handShakeToReturn = HandShakeState.Finished,
                updateTime         = true
            };
            var rep = new ReplyManager(ns, new MockBlockchain(), new MockClientSettings());

            var actual = rep.GetReply(msg);

            Assert.Null(actual);
            Assert.False(ns.updateTime);
        }
示例#6
0
        public void GetReply_NoHandShakeTest()
        {
            var msg = new Message(new GetAddrPayload(), NetworkType.MainNet);
            var ns  = new MockNodeStatus()
            {
                _handShakeToReturn = HandShakeState.None,
                mediumViolation    = true,
                updateTime         = true
            };
            var rep = new ReplyManager(ns, new MockBlockchain(), new MockClientSettings());

            var actual = rep.GetReply(msg);

            Assert.Null(actual);
            Assert.False(ns.updateTime);
        }
示例#7
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);
        }
示例#8
0
        public void GetReply_FailToDeserializeTest(PayloadType plt)
        {
            var msg = new Message(new MockSerializableMessagePayload(plt, new byte[] { 255, 255, 255 }), NetworkType.MainNet);
            var ns  = new MockNodeStatus()
            {
                _handShakeToReturn = HandShakeState.Finished,
                smallViolation     = true,
                updateTime         = true
            };
            var rep = new ReplyManager(ns, new MockBlockchain(), new ClientSettings());

            Message[] actual = rep.GetReply(msg);
            Assert.Null(actual);

            Assert.False(ns.updateTime);
            Assert.False(ns.smallViolation);
        }