Beispiel #1
0
        public void TryParse_ErrorTest(string toParse)
        {
            bool b = BIP0014.TryParse(toParse, out BIP0014[] actualBips);

            Assert.False(b);
            Assert.Null(actualBips);
        }
Beispiel #2
0
        public void ToString_VerFieldCount_Test(Version ver, int count, string exp)
        {
            var    bip      = new BIP0014("Foo", ver);
            string actual   = bip.ToString(count);
            string expected = $"/Foo:{exp}/";

            Assert.Equal(expected, actual);
        }
Beispiel #3
0
        public void SerializeList_ExceptionTest()
        {
            BIP0014[] bips =
            {
                new BIP0014("Satoshi", new Version(0,  9, 3), null),
                null,
                new BIP0014("Satoshi", new Version(0, 12, 3), "comment")
            };

            Assert.Throws <ArgumentNullException>(() => BIP0014.ToByteArrayMulti(bips));
            Assert.Throws <ArgumentNullException>(() => BIP0014.ToByteArrayMulti(null));
        }
Beispiel #4
0
        public void TryParseTest(string name, Version ver, string cmt, string serializedString)
        {
            bool b = BIP0014.TryParse(serializedString, out BIP0014[] bips);

            Assert.True(b);
            Assert.Single(bips);
            Assert.Equal(name, bips[0].ClientName);
            Assert.Equal(ver ?? new Version(0, 0), bips[0].ClientVersion);
            // TryParse returns null comment
            string expCmt = (cmt == "") ? null : cmt;

            Assert.Equal(expCmt, bips[0].Comment);
        }
Beispiel #5
0
        public void ToByteArrayMultiTest()
        {
            BIP0014[] bips =
            {
                new BIP0014("Satoshi",      new Version(0,  9,                      3)),
                new BIP0014("BitcoinJ",     new Version(0, 2), "iPad; U; CPU OS 3_2_1"),
                new BIP0014("AndroidBuild", new Version(0, 8))
            };

            byte[] actual   = BIP0014.ToByteArrayMulti(bips);
            byte[] expected = Encoding.UTF8.GetBytes("/Satoshi:0.9.3/BitcoinJ:0.2(iPad; U; CPU OS 3_2_1)/AndroidBuild:0.8/");

            Assert.Equal(expected, actual);
        }
Beispiel #6
0
        public void ConstructorTest(string name, Version ver, string cmt, string expected)
        {
            BIP0014 bip = new BIP0014(name, ver, cmt);

            string actualStr = bip.ToString();

            byte[] actualBa = bip.ToByteArray();

            Assert.Equal(name, bip.ClientName);
            Assert.Equal(ver ?? new Version(0, 0), bip.ClientVersion);
            Assert.Equal(cmt, bip.Comment);

            Assert.Equal(expected, actualStr);
            Assert.Equal(Encoding.UTF8.GetBytes(expected), actualBa);
        }
Beispiel #7
0
        public Configuration(NetworkType network)
        {
            Version ver = Assembly.GetExecutingAssembly().GetName().Version;

            Network = network;
            SetPeerList();
            UserAgent          = new BIP0014("Denovo", ver).ToString(3);
            MaxConnectionCount = 8;
            ListenPort         = network switch
            {
                NetworkType.MainNet => Constants.MainNetPort,
                NetworkType.TestNet => Constants.TestNetPort,
                NetworkType.RegTest => Constants.RegTestPort,
                _ => throw new ArgumentException("Undefined network type.")
            };
        }
Beispiel #8
0
        public void TryParse_MultiTest()
        {
            bool b = BIP0014.TryParse("/BitcoinJ:0.2(iPad; U; CPU OS 3_2_1)/AndroidBuild:0.8.6/", out BIP0014[] bips);

            Assert.True(b);
            Assert.Equal(2, bips.Length);

            Assert.Equal("BitcoinJ", bips[0].ClientName);
            Assert.Equal("AndroidBuild", bips[1].ClientName);

            Assert.Equal(new Version(0, 2), bips[0].ClientVersion);
            Assert.Equal(new Version(0, 8, 6), bips[1].ClientVersion);

            Assert.Equal("iPad; U; CPU OS 3_2_1", bips[0].Comment);
            Assert.Null(bips[1].Comment);
        }
Beispiel #9
0
 /// <summary>
 /// Initializes a new instance of <see cref="ClientSettings"/> with the given parameters.
 /// </summary>
 /// <param name="pver">Protocol version</param>
 /// <param name="relay">True to relay blocks and transactions; false otherwise</param>
 /// <param name="ua">User agent</param>
 /// <param name="netType">Network type</param>
 /// <param name="servs">Services supported by this node</param>
 public ClientSettings(int pver, bool relay, BIP0014 ua, NetworkType netType, NodeServiceFlags servs)
     : this(pver, relay, ua.ToString(), netType, servs)
 {
 }