Beispiel #1
0
        public void Can_do_roundtrip()
        {
            HelloMessage helloMessage = new HelloMessage();

            helloMessage.P2PVersion   = 1;
            helloMessage.Capabilities = new List <Capability>();
            helloMessage.Capabilities.Add(new Capability(Protocol.Eth, 1));
            helloMessage.ClientId   = "Nethermind/alpha";
            helloMessage.ListenPort = 8002;
            helloMessage.NodeId     = NetTestVectors.StaticKeyA.PublicKey;

            HelloMessageSerializer serializer = new HelloMessageSerializer();

            byte[] serialized    = serializer.Serialize(helloMessage);
            byte[] expectedBytes = Bytes.FromHexString("f85e01904e65746865726d696e642f616c706861c6c58365746801821f42b840fda1cff674c90c9a197539fe3dfb53086ace64f83ed7c6eabec741f7f381cc803e52ab2cd55d5569bce4347107a310dfd5f88a010cd2ffd1005ca406f1842877");

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

            HelloMessage deserialized = serializer.Deserialize(serialized);

            Assert.AreEqual(helloMessage.P2PVersion, deserialized.P2PVersion);
            Assert.AreEqual(helloMessage.ClientId, deserialized.ClientId);
            Assert.AreEqual(helloMessage.NodeId, deserialized.NodeId);
            Assert.AreEqual(helloMessage.ListenPort, deserialized.ListenPort);
            Assert.AreEqual(helloMessage.Capabilities.Count, deserialized.Capabilities.Count);
            Assert.AreEqual(helloMessage.Capabilities[0].ProtocolCode, deserialized.Capabilities[0].ProtocolCode);
            Assert.AreEqual(helloMessage.Capabilities[0].Version, deserialized.Capabilities[0].Version);
        }
Beispiel #2
0
        public void Can_do_roundtrip()
        {
            HelloMessage helloMessage = new HelloMessage();

            helloMessage.P2PVersion   = 1;
            helloMessage.Capabilities = new List <Capability>();
            helloMessage.Capabilities.Add(new Capability(Protocol.Eth, 1));
            helloMessage.ClientId   = "Nethermind/alpha";
            helloMessage.ListenPort = 8002;
            helloMessage.NodeId     = new NodeId(NetTestVectors.StaticKeyA.PublicKey);

            HelloMessageSerializer serializer = new HelloMessageSerializer();

            byte[]       serialized   = serializer.Serialize(helloMessage);
            HelloMessage deserialized = serializer.Deserialize(serialized);

            Assert.AreEqual(helloMessage.P2PVersion, deserialized.P2PVersion);
            Assert.AreEqual(helloMessage.ClientId, deserialized.ClientId);
            Assert.AreEqual(helloMessage.NodeId, deserialized.NodeId);
            Assert.AreEqual(helloMessage.ListenPort, deserialized.ListenPort);
            Assert.AreEqual(helloMessage.Capabilities.Count, deserialized.Capabilities.Count);
            Assert.AreEqual(helloMessage.Capabilities[0].ProtocolCode, deserialized.Capabilities[0].ProtocolCode);
            Assert.AreEqual(helloMessage.Capabilities[0].Version, deserialized.Capabilities[0].Version);
        }