Ejemplo n.º 1
0
        public void Roundtrip()
        {
            NewBlockHashesMessage message = new NewBlockHashesMessage((Keccak.Compute("1"), 1), (Keccak.Compute("2"), 2));

            NewBlockHashesMessageSerializer serializer = new NewBlockHashesMessageSerializer();

            byte[] bytes = serializer.Serialize(message);
            NewBlockHashesMessage deserialized = serializer.Deserialize(bytes);

            Assert.AreEqual(message.PacketType, deserialized.PacketType, $"{nameof(message.PacketType)}");
            Assert.AreEqual(message.Protocol, deserialized.Protocol, $"{nameof(message.Protocol)}");
            Assert.AreEqual(message.BlockHashes.Length, deserialized.BlockHashes.Length, $"number of block hashes");
            for (int i = 0; i < message.BlockHashes.Length; i++)
            {
                Assert.AreEqual(message.BlockHashes[i].Item1, deserialized.BlockHashes[i].Item1, $"{i} hash");
                Assert.AreEqual(message.BlockHashes[i].Item2, deserialized.BlockHashes[i].Item2, $"{i} number");
            }
        }
        public void Roundtrip()
        {
            NewBlockHashesMessage message = new NewBlockHashesMessage((Keccak.Compute("1"), 1), (Keccak.Compute("2"), 2));

            NewBlockHashesMessageSerializer serializer = new NewBlockHashesMessageSerializer();

            byte[] bytes         = serializer.Serialize(message);
            byte[] expectedBytes = Bytes.FromHexString("f846e2a0c89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc601e2a0ad7c5bef027816a800da1736444fb58a807ef4c9603b7848673f7e3a68eb14a502");

            Assert.True(Bytes.AreEqual(bytes, expectedBytes), "bytes");

            NewBlockHashesMessage deserialized = serializer.Deserialize(bytes);

            Assert.AreEqual(message.PacketType, deserialized.PacketType, $"{nameof(message.PacketType)}");
            Assert.AreEqual(message.Protocol, deserialized.Protocol, $"{nameof(message.Protocol)}");
            Assert.AreEqual(message.BlockHashes.Length, deserialized.BlockHashes.Length, $"number of block hashes");
            for (int i = 0; i < message.BlockHashes.Length; i++)
            {
                Assert.AreEqual(message.BlockHashes[i].Item1, deserialized.BlockHashes[i].Item1, $"{i} hash");
                Assert.AreEqual(message.BlockHashes[i].Item2, deserialized.BlockHashes[i].Item2, $"{i} number");
            }
        }