예제 #1
0
        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());
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }
예제 #4
0
        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));
        }
예제 #5
0
        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());
        }
예제 #6
0
        public void Decode_V1_Invalid_MultiBase_Code()
        {
            var id = "?";

            Assert.ThrowsException <FormatException>(() => Cid.Decode(id));
        }
예제 #7
0
        public void Decode_V1_Invalid_MultiBase_String()
        {
            var id = "zb2rhj7crUKTQYRGCRATFaQ6YFLTde2YzdqbbhAASkL9uRDX?";

            Assert.ThrowsException <FormatException>(() => Cid.Decode(id));
        }
예제 #8
0
        public void Decode_V0_Invalid()
        {
            var hash = "QmXg9Pp2ytZ14xgmQjYEiHjVjMFXzCVVEcRTWJBmLgR39?";

            Assert.ThrowsException <FormatException>(() => Cid.Decode(hash));
        }
예제 #9
0
 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);
 }