Exemple #1
0
        public void TestMemoHashEquality()
        {
            var memo  = Memo.Hash("4142434445464748494a4b4c");
            var memo2 = Memo.Hash("4142434445464748494a4b4c");

            Assert.AreEqual(memo.GetHashCode(), memo2.GetHashCode());
            Assert.AreEqual(memo, memo2);
        }
        public void TestMemoHashBytesSuccess()
        {
            var bytes = Enumerable.Repeat((byte)'A', 10).ToArray();
            var memo  = Memo.Hash(bytes);

            Assert.AreEqual(sdkxdr.MemoType.MemoTypeEnum.MEMO_HASH, memo.ToXdr().Discriminant.InnerValue);
            Assert.AreEqual("AAAAAAAAAA", Util.PaddedByteArrayToString(memo.MemoBytes));
            Assert.AreEqual("4141414141414141414100000000000000000000000000000000000000000000", memo.GetHexValue());
            Assert.AreEqual("41414141414141414141", memo.GetTrimmedHexValue());
        }
        public void TestMemoHashSuccess()
        {
            var memo = Memo.Hash("4142434445464748494a4b4c");

            Assert.AreEqual(sdkxdr.MemoType.MemoTypeEnum.MEMO_HASH, memo.ToXdr().Discriminant.InnerValue);
            var test = "ABCDEFGHIJKL";

            Assert.AreEqual(test, Util.PaddedByteArrayToString(memo.MemoBytes));
            Assert.AreEqual("4142434445464748494a4b4c", memo.GetTrimmedHexValue());
        }
 public void TestMemoHashInvalidHex()
 {
     try
     {
         Memo.Hash("test");
         Assert.Fail();
     }
     catch (FormatException)
     {
     }
 }
        public void TestMemoHashTooLong()
        {
            var longer = Enumerable.Repeat((byte)0, 33).ToArray();

            try
            {
                Memo.Hash(longer);
                Assert.Fail();
            }
            catch (MemoTooLongException exception)
            {
                Assert.IsTrue(exception.Message.Contains("MEMO_HASH can contain 32 bytes at max."));
            }
        }
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            reader.DateParseHandling = DateParseHandling.None;

            var jsonObject = JObject.Load(reader);

            TransactionResponse transaction = jsonObject.ToObject <TransactionResponse>();


            var memoType = jsonObject.GetValue("memo_type").ToObject <string>();

            Memo memo;

            if (memoType.Equals("none"))
            {
                memo = Memo.None();
            }
            else
            {
                String memoValue = transaction.MemoStr;

                if (memoType.Equals("text"))
                {
                    memo = Memo.Text(memoValue);
                }
                else if (memoType.Equals("id"))
                {
                    memo = Memo.Id(long.Parse(memoValue));
                }
                else if (memoType.Equals("hash"))
                {
                    memo = Memo.Hash(Convert.FromBase64String(memoValue));
                }
                else if (memoType.Equals("return"))
                {
                    memo = Memo.ReturnHash(Convert.FromBase64String(memoValue));
                }
                else
                {
                    throw new JsonException("Unknown memo type.");
                }
            }

            transaction.Memo = memo;
            return(transaction);
        }