コード例 #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());
        }
コード例 #2
0
ファイル: NetworkAddressTests.cs プロジェクト: sefbkn/ndecred
        public void EncodeDecode_ReturnsInputDataExactly()
        {
            var netAddr = new NetworkAddress(true);

            netAddr.Decode(baseNetAddrEncoded);

            var unixTs    = BitConverter.ToInt32(new byte[] { 0x29, 0xab, 0x5f, 0x49 }, 0);
            var timestamp = DateTimeExtensions.FromUnixTime(unixTs);

            Assert.Equal(timestamp.Date, new DateTime(2009, 1, 3));
            Assert.Equal(timestamp, netAddr.Timestamp);

            Assert.Equal(netAddr.Services, ServiceFlag.NodeNetwork);
            Assert.Equal(netAddr.Port, 8333);

            var bytes = netAddr.Encode();

            Assert.True(bytes.SequenceEqual(baseNetAddrEncoded));
        }
コード例 #3
0
 public List <NetworkAddress> GetAddresses() => NetworkAddress.Decode(_networkAddresses);