public void Bad_IPAddress() { var ipv4 = new MultiAddress("/ip4/127.0.0.1"); ExceptionAssert.Throws <FormatException>(() => new MultiAddress("/ip4/x")); ExceptionAssert.Throws <FormatException>(() => new MultiAddress("/ip4/127.")); ExceptionAssert.Throws <FormatException>(() => new MultiAddress("/ip4/::1")); var ipv6 = new MultiAddress("/ip6/::1"); ExceptionAssert.Throws <FormatException>(() => new MultiAddress("/ip6/x")); ExceptionAssert.Throws <FormatException>(() => new MultiAddress("/ip6/03:")); ExceptionAssert.Throws <FormatException>(() => new MultiAddress("/ip6/127.0.0.1")); }
public void WithoutPeerId() { var id = "QmQusTXc1Z9C1mzxsqC9ZTFXCgSkpBRGgW4Jk2QYHxKE22"; var ma1 = new MultiAddress("/ip4/127.0.0.1/tcp/4001"); Assert.AreSame(ma1, ma1.WithoutPeerId()); ma1 = new MultiAddress($"/ip4/127.0.0.1/tcp/4001/ipfs/{id}"); Assert.AreEqual("/ip4/127.0.0.1/tcp/4001", ma1.WithoutPeerId()); ma1 = new MultiAddress($"/ip4/127.0.0.1/tcp/4001/p2p/{id}"); Assert.AreEqual("/ip4/127.0.0.1/tcp/4001", ma1.WithoutPeerId()); }
public void JsonSerialization() { var a = new MultiAddress("/ip6/fe80::7573:b0a8:46b0:0bad/tcp/4009"); string json = JsonConvert.SerializeObject(a); Assert.AreEqual($"\"{a.ToString()}\"", json); var b = JsonConvert.DeserializeObject <MultiAddress>(json); Assert.AreEqual(a.ToString(), b.ToString()); a = null; json = JsonConvert.SerializeObject(a); b = JsonConvert.DeserializeObject <MultiAddress>(json); Assert.IsNull(b); }
public void PeerID_ipfs_p2p_are_equal() { var ipfs = new MultiAddress("/ip4/10.1.10.10/tcp/29087/ipfs/QmVcSqVEsvm5RR9mBLjwpb2XjFVn5bPdPL69mL8PH45pPC"); var p2p = new MultiAddress("/ip4/10.1.10.10/tcp/29087/p2p/QmVcSqVEsvm5RR9mBLjwpb2XjFVn5bPdPL69mL8PH45pPC"); Assert.AreEqual(ipfs, p2p); var p2p1 = new MultiAddress("/ip4/10.1.10.10/tcp/29087/p2p/QmVCSqVEsvm5RR9mBLjwpb2XjFVn5bPdPL69mL8PH45pPC"); Assert.AreNotEqual(p2p, p2p1); var p2p2 = new MultiAddress("/p2p/QmVcSqVEsvm5RR9mBLjwpb2XjFVn5bPdPL69mL8PH45pPC"); Assert.AreNotEqual(p2p, p2p2); }
public void Parsing() { var a = new MultiAddress(somewhere); Assert.AreEqual(3, a.Protocols.Count); Assert.AreEqual("ip4", a.Protocols[0].Name); Assert.AreEqual("10.1.10.10", a.Protocols[0].Value); Assert.AreEqual("tcp", a.Protocols[1].Name); Assert.AreEqual("29087", a.Protocols[1].Value); Assert.AreEqual("ipfs", a.Protocols[2].Name); Assert.AreEqual("QmVcSqVEsvm5RR9mBLjwpb2XjFVn5bPdPL69mL8PH45pPC", a.Protocols[2].Value); ExceptionAssert.Throws<ArgumentNullException>(() => new MultiAddress((string)null)); ExceptionAssert.Throws<ArgumentNullException>(() => new MultiAddress("")); ExceptionAssert.Throws<ArgumentNullException>(() => new MultiAddress(" ")); }
public void Cloning() { var ma1 = new MultiAddress("/ip4/10.1.10.10/tcp/29087"); var ma2 = ma1.Clone(); Assert.AreEqual(ma1, ma2); Assert.AreNotSame(ma1, ma2); Assert.AreNotSame(ma1.Protocols, ma2.Protocols); for (int i = 0; i < ma1.Protocols.Count; ++i) { var p1 = ma1.Protocols[i]; var p2 = ma2.Protocols[i]; Assert.AreEqual(p1.Code, p2.Code); Assert.AreEqual(p1.Name, p2.Name); Assert.AreEqual(p1.Value, p2.Value); Assert.AreNotSame(p1, p2); } }
public void RoundTripping() { var addresses = new[] { somewhere, "/ip4/1.2.3.4/tcp/80/http", "/ip6/3ffe:1900:4545:3:200:f8ff:fe21:67cf/tcp/443/https", "/ip6/3ffe:1900:4545:3:200:f8ff:fe21:67cf/udp/8001", "/ip6/3ffe:1900:4545:3:200:f8ff:fe21:67cf/sctp/8001", "/ip6/3ffe:1900:4545:3:200:f8ff:fe21:67cf/dccp/8001", "/ip4/1.2.3.4/tcp/80/ws", "/libp2p-webrtc-star/ip4/127.0.0.1/tcp/9090/ws/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC", "/ip4/127.0.0.1/tcp/1234/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC", "/ip4/1.2.3.4/tcp/80/udt", "/ip4/1.2.3.4/tcp/80/utp", "/onion/aaimaq4ygg2iegci:80", "/onion/timaq4ygg2iegci7:80/http", "/p2p-circuit/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC", "/dns/ipfs.io", "/dns4/ipfs.io", "/dns6/ipfs.io", "/dns4/wss0.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmZMxNdpMkewiVZLMRxaNxUeZpDUb34pWjZ1kZvsd16Zic", "/ip4/127.0.0.0/ipcidr/16", "/p2p/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN", "/ip4/127.0.0.1/udp/4023/quic", }; foreach (var a in addresses) { var ma0 = new MultiAddress(a); var ms = new MemoryStream(); ma0.Write(ms); ms.Position = 0; var ma1 = new MultiAddress(ms); Assert.AreEqual <MultiAddress>(ma0, ma1); var ma2 = new MultiAddress(ma0.ToString()); Assert.AreEqual <MultiAddress>(ma0, ma2); var ma3 = new MultiAddress(ma0.ToArray()); Assert.AreEqual <MultiAddress>(ma0, ma3); } }
public void Value_Equality() { var a0 = new MultiAddress(somewhere); var a1 = new MultiAddress(somewhere); var b = new MultiAddress(nowhere); MultiAddress c = null; MultiAddress d = null; Assert.IsTrue(c == d); Assert.IsFalse(c == b); Assert.IsFalse(b == c); Assert.IsFalse(c != d); Assert.IsTrue(c != b); Assert.IsTrue(b != c); #pragma warning disable 1718 Assert.IsTrue(a0 == a0); Assert.IsTrue(a0 == a1); Assert.IsFalse(a0 == b); #pragma warning disable 1718 Assert.IsFalse(a0 != a0); Assert.IsFalse(a0 != a1); Assert.IsTrue(a0 != b); Assert.IsTrue(a0.Equals(a0)); Assert.IsTrue(a0.Equals(a1)); Assert.IsFalse(a0.Equals(b)); Assert.AreEqual(a0, a0); Assert.AreEqual(a0, a1); Assert.AreNotEqual(a0, b); Assert.AreEqual <MultiAddress>(a0, a0); Assert.AreEqual <MultiAddress>(a0, a1); Assert.AreNotEqual <MultiAddress>(a0, b); Assert.AreEqual(a0.GetHashCode(), a0.GetHashCode()); Assert.AreEqual(a0.GetHashCode(), a1.GetHashCode()); Assert.AreNotEqual(a0.GetHashCode(), b.GetHashCode()); }
public void WithPeerId() { var id = "QmQusTXc1Z9C1mzxsqC9ZTFXCgSkpBRGgW4Jk2QYHxKE22"; var id3 = "QmQusTXc1Z9C1mzxsqC9ZTFXCgSkpBRGgW4Jk2QYHxKE33"; var ma1 = new MultiAddress("/ip4/127.0.0.1/tcp/4001"); Assert.AreEqual($"{ma1}/p2p/{id}", ma1.WithPeerId(id)); ma1 = new MultiAddress($"/ip4/127.0.0.1/tcp/4001/ipfs/{id}"); Assert.AreSame(ma1, ma1.WithPeerId(id)); ma1 = new MultiAddress($"/ip4/127.0.0.1/tcp/4001/p2p/{id}"); Assert.AreSame(ma1, ma1.WithPeerId(id)); ExceptionAssert.Throws <Exception>(() => { ma1 = new MultiAddress($"/ip4/127.0.0.1/tcp/4001/ipfs/{id3}"); Assert.AreSame(ma1, ma1.WithPeerId(id)); }); }
public void RoundTripping() { var addresses = new[] { somewhere, "/ip4/1.2.3.4/tcp/80/http", "/ip6/3ffe:1900:4545:3:200:f8ff:fe21:67cf/tcp/443/https", "/ip6/3ffe:1900:4545:3:200:f8ff:fe21:67cf/udp/8001", "/ip6/3ffe:1900:4545:3:200:f8ff:fe21:67cf/sctp/8001", "/ip6/3ffe:1900:4545:3:200:f8ff:fe21:67cf/dccp/8001", "/ip4/1.2.3.4/tcp/80/ws", "/libp2p-webrtc-star/ip4/127.0.0.1/tcp/9090/ws/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC", "/ip4/127.0.0.1/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC/tcp/1234", "/ip4/1.2.3.4/tcp/80/udt", "/ip4/1.2.3.4/tcp/80/utp", "/onion/aaimaq4ygg2iegci:80", "/onion/timaq4ygg2iegci7:80/http", }; foreach (var a in addresses) { var ma0 = new MultiAddress(a); var ms = new MemoryStream(); ma0.Write(ms); ms.Position = 0; var ma1 = new MultiAddress(ms); Assert.AreEqual <MultiAddress>(ma0, ma1); var ma2 = new MultiAddress(ma0.ToString()); Assert.AreEqual <MultiAddress>(ma0, ma2); var ma3 = new MultiAddress(ma0.ToArray()); Assert.AreEqual <MultiAddress>(ma0, ma3); } }
public void Implicit_Conversion_From_String() { MultiAddress a = somewhere; Assert.IsInstanceOfType(a, typeof(MultiAddress)); }
public void GetHashCode_NullValue() { var a = new MultiAddress("/ip4/139.178.69.3/udp/4001/quic/p2p/QmdGQoGuK3pao6bRDqGSDvux5SFHa4kC2XNFfHFcvcbydY/p2p-circuit/ipfs/QmPJkpfUedzahgVAj6tTUa3DHKVkfTSyvUmnn1USFpiCaF"); var _ = a.GetHashCode(); }
public void TryCreate_FromString() { Assert.IsNotNull(MultiAddress.TryCreate("/ip4/1.2.3.4/tcp/80")); Assert.IsNull(MultiAddress.TryCreate("/tcp/alpha")); // bad port Assert.IsNull(MultiAddress.TryCreate("/foobar")); // bad protocol }
public void PeerID_With_p2p() { var ma = new MultiAddress("/ip4/10.1.10.10/tcp/29087/p2p/QmVcSqVEsvm5RR9mBLjwpb2XjFVn5bPdPL69mL8PH45pPC"); Assert.AreEqual("QmVcSqVEsvm5RR9mBLjwpb2XjFVn5bPdPL69mL8PH45pPC", ma.PeerId.ToBase58()); }