Ejemplo n.º 1
0
        public void NodeAnnouncementMessageTest()
        {
            List <NetworkAddress> addresses = new List <NetworkAddress>();

            addresses.Add(new NetworkAddress(AddressType.IpV4, "10.11.22.33", 6677));

            var message = new NodeAnnouncementMessage(
                "111e45454b0978a623f36a10626ef17b27d9ad44e2760f98cfa3efb37924f0220220bd8acd43ecaa916a80bd4f919c495a2c58982ce7c8625112456464451111".HexToByteArray(),
                "1122".HexToByteArray(),
                DateTime.Parse("1979-01-28T01:25:53.0000000+01:00"),
                new ECKeyPair("032c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991", false),
                "223366",
                "my test node",
                addresses);

            Assert.Equal(257, message.Definition.TypeId);

            Assert.Equal("111e45454b0978a623f36a10626ef17b27d9ad44e2760f98cfa3efb37924f0220220bd8acd43ecaa916a80bd4f919c495a2c58982ce7c8625112456464451111", message.Signature.ToHex());
            Assert.Equal("1122", message.Features.ToHex());
            Assert.Equal(DateTime.Parse("1979-01-28T01:25:53.0000000+01:00"), message.Timestamp);
            Assert.Equal("032c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991", message.NodeId.PublicKeyCompressed.ToHex());
            Assert.Equal("223366", message.Color);
            Assert.Equal("my test node", message.Alias);
            Assert.Single(message.GetAddresses());
            Assert.Equal("10.11.22.33", message.GetAddresses()[0].Address);
            Assert.Equal(6677, message.GetAddresses()[0].Port);
            Assert.Equal(AddressType.IpV4, message.GetAddresses()[0].Type);

            var properties = message.GetProperties();

            Assert.Equal("111e45454b0978a623f36a10626ef17b27d9ad44e2760f98cfa3efb37924f0220220bd8acd43ecaa916a80bd4f919c495a2c58982ce7c8625112456464451111", properties[0].ToHex());
            Assert.Equal("1122", properties[1].ToHex());
            Assert.Equal("11111111", properties[2].ToHex());
            Assert.Equal("032c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991", properties[3].ToHex());
            Assert.Equal("223366", properties[4].ToHex());
            Assert.Equal("6d792074657374206e6f64652020202020202020202020202020202020202020", properties[5].ToHex());
            Assert.Equal("010a0b16211a15", properties[6].ToHex());

            var address = NetworkAddress.Decode("010a0b16211a15".HexToByteArray())[0];

            Assert.Equal("10.11.22.33", address.Address);
            Assert.Equal(6677, address.Port);
            Assert.Equal(AddressType.IpV4, address.Type);

            Assert.Equal("0101" +
                         "111e45454b0978a623f36a10626ef17b27d9ad44e2760f98cfa3efb37924f0220220bd8acd43ecaa916a80bd4f919c495a2c58982ce7c8625112456464451111" +
                         "00021122" +
                         "11111111" +
                         "032c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991" +
                         "223366" +
                         "6d792074657374206e6f64652020202020202020202020202020202020202020" +
                         "0007010a0b16211a15", message.GetBytes().ToHex());
        }