Esempio n. 1
0
 public void NullTransactionTypeTest()
 {
     AssertTxFormatException(() => {
         TxFormat.Validate(new StObject {
             [Field.TransactionType] = null
         });
     }, "`TransactionType` is set to null");
 }
Esempio n. 2
0
        public void MissingFieldsTest()
        {
            var so = new StObject
            {
                [Field.TransactionType] = TransactionType.Payment
            };

            TxFormat.Validate(so);
        }
Esempio n. 3
0
        private void ComputeFormat()
        {
            var tt = this[UInt.UInt16.TransactionType];

            if (tt != null)
            {
                SetFormat(TxFormat.FromNumber(tt));
            }

            var let = this[UInt.UInt16.LedgerEntryType];

            if (let != null)
            {
                SetFormat(TxFormat.FromNumber(let));
            }
        }
Esempio n. 4
0
        public static SignedTx ValidateAndEncode(StObject tx)
        {
            try
            {
                TxFormat.Validate(tx);
            }
            catch (TxFormatValidationException ex)
            {
                throw new InvalidTxException("Transaction is not valid.", nameof(tx), ex);
            }

            var blob = tx.ToBytes();
            var hash = Utils.TransactionId(blob);

            return(new SignedTx(hash, B16.Encode(blob), tx.ToJsonObject()));
        }
Esempio n. 5
0
        public void testSymbolics()
        {
            Assert.NotNull(TxFormat.FromString("Payment"));

            JObject json = JObject.Parse("{\"Expiration\"        : 21, " + "\"TransactionResult\" : 0,  " + "\"TransactionType\"   : 0  }");

            StObject so = StObject.OutTranslate.FromJObject(json);

            Assert.AreEqual(so.GetFormat, TxFormat.Payment);
            so.SetFormat(null); // Else it (SHOULD) attempt to validate something clearly unFormatted

            JObject obj = StObject.InTranslate.ToJObject(so);

            Assert.AreEqual(obj["TransactionResult"].ToString(), "tesSUCCESS");
            Assert.AreEqual(obj["TransactionType"].ToString(), "Payment");
        }
Esempio n. 6
0
        public void ValidateTest()
        {
            var so = new StObject
            {
                [Field.TransactionType] = TransactionType.Payment,
                [Field.Account]         = "r9kiSEUEw6iSCNksDVKf9k3AyxjW3r1qPf",
                [Field.Sequence]        = 12000,
                [Field.SigningPubKey]   = Blob.FromHex("02517EB0EEB4424BB01D6D9932F8838D8EF4EC989CF5B8097C9CF675F534EF10BF"),
                [Field.Fee]             = "12000",
                [Field.Destination]     = "r9kiSEUEw6iSCNksDVKf9k3AyxjW3r1qPf",
                [Field.Amount]          = "100"
            };

            // No problems here
            TxFormat.Validate(so);
            // But if we set the amount to null
            so[Field.Amount] = null;

            AssertTxFormatException(() =>
            {
                TxFormat.Validate(so);
            }, "`Amount` is set to null");
        }
Esempio n. 7
0
 public void MissingTransactionTypeTest()
 {
     AssertTxFormatException(() => {
         TxFormat.Validate(new StObject());
     }, "Missing `TransactionType` field");
 }