public void NullTransactionTypeTest() { AssertTxFormatException(() => { TxFormat.Validate(new StObject { [Field.TransactionType] = null }); }, "`TransactionType` is set to null"); }
public void MissingFieldsTest() { var so = new StObject { [Field.TransactionType] = TransactionType.Payment }; TxFormat.Validate(so); }
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)); } }
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())); }
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"); }
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"); }
public void MissingTransactionTypeTest() { AssertTxFormatException(() => { TxFormat.Validate(new StObject()); }, "Missing `TransactionType` field"); }