public void Decode_V0() { var hash = "QmXg9Pp2ytZ14xgmQjYEiHjVjMFXzCVVEcRTWJBmLgR39V"; var cid = Cid.Decode(hash); Assert.AreEqual(0, cid.Version); Assert.AreEqual("dag-pb", cid.ContentType); Assert.AreEqual("base58btc", cid.Encoding); Assert.AreEqual(hash, cid.Encode()); }
public void Decode_V1_Unknown_ContentType() { var id = "zJAFhtPN28kqMxDkZawWCCL52BzaiymqFgX3LA7XzkNRMNAN1T1J"; var hash = "QmaozNR7DZHQK1ZcU9p7QdrshMvXqWK6gpu5rmrkPdT3L4"; var cid = Cid.Decode(id); Assert.AreEqual(1, cid.Version); Assert.AreEqual("base58btc", cid.Encoding); Assert.AreEqual("codec-32767", cid.ContentType); Assert.AreEqual(hash, cid.Hash); }
public void Decode_V1() { var id = "zb2rhj7crUKTQYRGCRATFaQ6YFLTde2YzdqbbhAASkL9uRDXn"; var hash = "QmaozNR7DZHQK1ZcU9p7QdrshMvXqWK6gpu5rmrkPdT3L4"; var cid = Cid.Decode(id); Assert.AreEqual(1, cid.Version); Assert.AreEqual("base58btc", cid.Encoding); Assert.AreEqual("raw", cid.ContentType); Assert.AreEqual(hash, cid.Hash); }
public void Decode_Invalid_Version() { var cid = new Cid { Version = 32767, ContentType = "raw", Encoding = "base58btc", Hash = "QmaozNR7DZHQK1ZcU9p7QdrshMvXqWK6gpu5rmrkPdT3L4" }; var s = cid.Encode(); Assert.ThrowsException <FormatException>(() => Cid.Decode(s)); }
public void Value_Equality() { var a0 = Cid.Decode("zb2rhj7crUKTQYRGCRATFaQ6YFLTde2YzdqbbhAASkL9uRDXn"); var a1 = Cid.Decode("zb2rhj7crUKTQYRGCRATFaQ6YFLTde2YzdqbbhAASkL9uRDXn"); var b = Cid.Decode("QmaozNR7DZHQK1ZcU9p7QdrshMvXqWK6gpu5rmrkPdT3L5"); Cid c = null; Cid 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); 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 <Cid>(a0, a0); Assert.AreEqual <Cid>(a0, a1); Assert.AreNotEqual <Cid>(a0, b); Assert.AreEqual(a0.GetHashCode(), a0.GetHashCode()); Assert.AreEqual(a0.GetHashCode(), a1.GetHashCode()); Assert.AreNotEqual(a0.GetHashCode(), b.GetHashCode()); }
public void Decode_V1_Invalid_MultiBase_Code() { var id = "?"; Assert.ThrowsException <FormatException>(() => Cid.Decode(id)); }
public void Decode_V1_Invalid_MultiBase_String() { var id = "zb2rhj7crUKTQYRGCRATFaQ6YFLTde2YzdqbbhAASkL9uRDX?"; Assert.ThrowsException <FormatException>(() => Cid.Decode(id)); }
public void Decode_V0_Invalid() { var hash = "QmXg9Pp2ytZ14xgmQjYEiHjVjMFXzCVVEcRTWJBmLgR39?"; Assert.ThrowsException <FormatException>(() => Cid.Decode(hash)); }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { var s = reader.Value as string; return s == null ? null : Cid.Decode(s); }