From b373230947940d6ab2f1a31269f9fb36f47d1855 Mon Sep 17 00:00:00 2001 From: nkramer44 Date: Sat, 2 Nov 2024 17:51:42 -0400 Subject: [PATCH] Revert "Revert "unknown transaction"" This reverts commit 18f9dabc006712ebdb000519d7fd2ef4ef746b33. --- .../xrpl4j/model/flags/TransactionFlags.java | 4 + ...ntTransactionsTransactionDeserializer.java | 17 ++- .../modules/TransactionDeserializer.java | 1 + .../TransactionResultDeserializer.java | 15 ++- .../xrpl4j/model/transactions/AmmBid.java | 6 + .../model/transactions/Transaction.java | 10 ++ .../model/transactions/TransactionType.java | 6 +- .../transactions/UnknownTransaction.java | 48 ++++++++ .../xrpl4j/model/transactions/UnlModify.java | 4 +- .../xrpl4j/model/transactions/AmmBidTest.java | 54 +++++++++ .../model/transactions/AmmCreateTest.java | 40 +++++++ .../model/transactions/AmmDeleteTest.java | 38 ++++++ .../model/transactions/AmmDepositTest.java | 57 +++++++++ .../model/transactions/AmmVoteTest.java | 40 +++++++ .../model/transactions/AmmWithdrawTest.java | 26 ++++- .../model/transactions/ClawbackTest.java | 36 ++++++ .../model/transactions/DidDeleteTest.java | 18 +++ .../xrpl4j/model/transactions/DidSetTest.java | 28 +++++ .../model/transactions/OracleDeleteTest.java | 19 +++ .../model/transactions/OracleSetTest.java | 20 ++++ .../xrpl4j/model/transactions/SetFeeTest.java | 34 ++++++ .../transactions/TransactionTypeTests.java | 31 ++--- .../transactions/UnknownTransactionTest.java | 76 ++++++++++++ .../XChainAccountCreateCommitTest.java | 52 +++++++++ ...XChainAddAccountCreateAttestationTest.java | 38 ++++++ .../XChainAddClaimAttestationTest.java | 40 +++++++ .../model/transactions/XChainClaimTest.java | 33 ++++++ .../model/transactions/XChainCommitTest.java | 41 +++++++ .../transactions/XChainCreateBridgeTest.java | 32 +++++ .../transactions/XChainCreateClaimIdTest.java | 31 +++++ .../transactions/XChainModifyBridgeTest.java | 29 +++++ .../json/AccountDeleteJsonTests.java | 30 +++++ .../json/AccountSetJsonTests.java | 48 ++++++++ .../transactions/json/CheckJsonTests.java | 94 +++++++++++++++ .../json/EnableAmendmentJsonTests.java | 24 ++++ .../transactions/json/EscrowJsonTests.java | 110 ++++++++++++++++++ .../json/NfTokenAcceptOfferJsonTests.java | 35 ++++++ .../json/NfTokenBurnJsonTests.java | 30 +++++ .../json/NfTokenCancelOfferJsonTests.java | 33 ++++++ .../json/NfTokenCreateOfferJsonTests.java | 32 +++++ .../json/NfTokenMintJsonTests.java | 34 ++++++ .../transactions/json/OfferJsonTests.java | 62 ++++++++++ .../json/PaymentChannelJsonTests.java | 109 +++++++++++++++++ .../transactions/json/PaymentJsonTests.java | 32 +++++ .../json/SetRegularKeyJsonTest.java | 28 +++++ .../json/SignerListSetJsonTests.java | 30 +++++ .../json/TicketCreateJsonTest.java | 28 +++++ .../transactions/json/TrustSetJsonTests.java | 40 +++++++ .../transactions/json/UnlModifyJsonTests.java | 3 + 49 files changed, 1692 insertions(+), 34 deletions(-) create mode 100644 xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/transactions/UnknownTransaction.java create mode 100644 xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/UnknownTransactionTest.java diff --git a/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/flags/TransactionFlags.java b/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/flags/TransactionFlags.java index a79f04ce0..8c03379a7 100644 --- a/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/flags/TransactionFlags.java +++ b/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/flags/TransactionFlags.java @@ -49,6 +49,10 @@ public class TransactionFlags extends Flags { TransactionFlags() { } + public static TransactionFlags of(long value) { + return new TransactionFlags(value); + } + /** * Flags indicating that a fully-canonical signature is required. This flag is highly recommended. * diff --git a/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/jackson/modules/AccountTransactionsTransactionDeserializer.java b/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/jackson/modules/AccountTransactionsTransactionDeserializer.java index e4256eba6..4c2d0cd23 100644 --- a/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/jackson/modules/AccountTransactionsTransactionDeserializer.java +++ b/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/jackson/modules/AccountTransactionsTransactionDeserializer.java @@ -25,6 +25,9 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.deser.std.StdDeserializer; +import com.fasterxml.jackson.databind.node.ObjectNode; +import com.google.common.collect.Lists; +import com.google.common.collect.Sets; import com.google.common.primitives.UnsignedInteger; import com.google.common.primitives.UnsignedLong; import org.xrpl.xrpl4j.model.client.accounts.AccountTransactionsTransaction; @@ -33,7 +36,9 @@ import org.xrpl.xrpl4j.model.transactions.Transaction; import java.io.IOException; +import java.util.ArrayList; import java.util.Optional; +import java.util.Set; /** * Custom Jackson Deserializer for {@link AccountTransactionsTransaction}s. This is necessary because Jackson @@ -41,6 +46,8 @@ */ public class AccountTransactionsTransactionDeserializer extends StdDeserializer> { + public static final Set EXTRA_TRANSACTION_FIELDS = Sets.newHashSet("ledger_index", "date", "hash"); + /** * No-args constructor. */ @@ -54,14 +61,20 @@ public AccountTransactionsTransaction deserialize( DeserializationContext ctxt ) throws IOException { ObjectMapper objectMapper = (ObjectMapper) jsonParser.getCodec(); - JsonNode node = objectMapper.readTree(jsonParser); + ObjectNode node = objectMapper.readTree(jsonParser); - Transaction transaction = objectMapper.readValue(node.toString(), Transaction.class); long ledgerIndex = node.get("ledger_index").asLong(-1L); String hash = node.get("hash").asText(); Optional closeDate = Optional.ofNullable(node.get("date")) .map(JsonNode::asLong) .map(UnsignedLong::valueOf); + + // The Transaction is @JsonUnwrapped in AccountTransactionsTransaction, which means these three fields + // get added to the Transaction.unknownFields Map. To prevent that, we simply remove them from the JSON, because + // they should only show up in AccountTransactionsTransaction + node.remove(EXTRA_TRANSACTION_FIELDS); + Transaction transaction = objectMapper.readValue(node.toString(), Transaction.class); + return AccountTransactionsTransaction.builder() .transaction(transaction) .ledgerIndex(LedgerIndex.of(UnsignedInteger.valueOf(ledgerIndex))) diff --git a/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/jackson/modules/TransactionDeserializer.java b/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/jackson/modules/TransactionDeserializer.java index c4cb3a483..1eccf82a6 100644 --- a/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/jackson/modules/TransactionDeserializer.java +++ b/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/jackson/modules/TransactionDeserializer.java @@ -27,6 +27,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode; import org.xrpl.xrpl4j.model.transactions.Transaction; import org.xrpl.xrpl4j.model.transactions.TransactionType; +import org.xrpl.xrpl4j.model.transactions.UnknownTransaction; import java.io.IOException; diff --git a/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/jackson/modules/TransactionResultDeserializer.java b/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/jackson/modules/TransactionResultDeserializer.java index 7ab4c6795..932a9f277 100644 --- a/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/jackson/modules/TransactionResultDeserializer.java +++ b/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/jackson/modules/TransactionResultDeserializer.java @@ -27,6 +27,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.deser.std.StdDeserializer; import com.fasterxml.jackson.databind.node.ObjectNode; +import com.google.common.collect.Sets; import com.google.common.primitives.UnsignedInteger; import com.google.common.primitives.UnsignedLong; import org.xrpl.xrpl4j.model.client.common.LedgerIndex; @@ -37,6 +38,7 @@ import java.io.IOException; import java.util.Optional; +import java.util.Set; /** * Custom deserializer for {@link TransactionResult}, which wraps the {@link Transaction} fields in the result JSON. @@ -48,6 +50,10 @@ */ public class TransactionResultDeserializer extends StdDeserializer> { + public static final Set EXTRA_TRANSACTION_FIELDS = Sets.newHashSet( + "ledger_index", "date", "hash", "status", "validated", "meta", "metaData" + ); + /** * No-args constructor. */ @@ -60,10 +66,6 @@ public TransactionResult deserialize(JsonParser jsonParser, DeserializationCo ObjectMapper objectMapper = (ObjectMapper) jsonParser.getCodec(); ObjectNode objectNode = objectMapper.readTree(jsonParser); - JavaType javaType = objectMapper.getTypeFactory().constructType(new TypeReference() { - }); - T transaction = objectMapper.convertValue(objectNode, javaType); - LedgerIndex ledgerIndex = objectNode.has("ledger_index") ? LedgerIndex.of(UnsignedInteger.valueOf(objectNode.get("ledger_index").asInt())) : null; @@ -73,6 +75,11 @@ public TransactionResult deserialize(JsonParser jsonParser, DeserializationCo Optional metadata = getTransactionMetadata(objectMapper, objectNode); UnsignedLong closeDate = objectNode.has("date") ? UnsignedLong.valueOf(objectNode.get("date").asLong()) : null; + objectNode.remove(EXTRA_TRANSACTION_FIELDS); + JavaType javaType = objectMapper.getTypeFactory().constructType(new TypeReference() { + }); + T transaction = objectMapper.convertValue(objectNode, javaType); + return TransactionResult.builder() .transaction(transaction) .ledgerIndex(Optional.ofNullable(ledgerIndex)) diff --git a/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/transactions/AmmBid.java b/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/transactions/AmmBid.java index b52da0635..3bc9261d1 100644 --- a/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/transactions/AmmBid.java +++ b/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/transactions/AmmBid.java @@ -1,5 +1,7 @@ package org.xrpl.xrpl4j.model.transactions; +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize; @@ -10,6 +12,7 @@ import org.xrpl.xrpl4j.model.ledger.Issue; import java.util.List; +import java.util.Map; import java.util.Optional; /** @@ -107,4 +110,7 @@ default TransactionFlags flags() { @JsonProperty("AuthAccounts") List authAccounts(); + /*@Override + @JsonAnyGetter + Map unknownFields();*/ } diff --git a/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/transactions/Transaction.java b/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/transactions/Transaction.java index 9f4f1acaf..fb96cd14a 100644 --- a/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/transactions/Transaction.java +++ b/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/transactions/Transaction.java @@ -20,7 +20,10 @@ * =========================LICENSE_END================================== */ +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; import com.google.common.collect.BiMap; import com.google.common.collect.ImmutableBiMap; @@ -30,6 +33,7 @@ import org.xrpl.xrpl4j.crypto.signing.Signature; import java.util.List; +import java.util.Map; import java.util.Optional; /** @@ -90,6 +94,7 @@ public interface Transaction { .put(ImmutableDidDelete.class, TransactionType.DID_DELETE) .put(ImmutableOracleSet.class, TransactionType.ORACLE_SET) .put(ImmutableOracleDelete.class, TransactionType.ORACLE_DELETE) + .put(ImmutableUnknownTransaction.class, TransactionType.UNKNOWN) .build(); /** @@ -106,6 +111,7 @@ public interface Transaction { * @return A {@link TransactionType}. */ @JsonProperty("TransactionType") + @Value.Default // must be Default rather than Derived, otherwise Jackson treats "TransactionType" as an unknownField default TransactionType transactionType() { return typeMap.get(this.getClass()); } @@ -220,4 +226,8 @@ default PublicKey signingPublicKey() { @JsonProperty("NetworkID") Optional networkId(); + @JsonAnyGetter + @JsonInclude(Include.NON_ABSENT) + Map unknownFields(); + } diff --git a/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/transactions/TransactionType.java b/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/transactions/TransactionType.java index bc19f8dbf..92cd912f1 100644 --- a/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/transactions/TransactionType.java +++ b/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/transactions/TransactionType.java @@ -336,7 +336,9 @@ public enum TransactionType { * is subject to change.

*/ @Beta - ORACLE_DELETE("OracleDelete"); + ORACLE_DELETE("OracleDelete"), + + UNKNOWN("Unknown"); private final String value; @@ -358,7 +360,7 @@ public static TransactionType forValue(String value) { } } - throw new IllegalArgumentException("No matching TransactionType enum value for String value " + value); + return UNKNOWN; } /** diff --git a/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/transactions/UnknownTransaction.java b/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/transactions/UnknownTransaction.java new file mode 100644 index 000000000..1c8f1dbdc --- /dev/null +++ b/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/transactions/UnknownTransaction.java @@ -0,0 +1,48 @@ +package org.xrpl.xrpl4j.model.transactions; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import org.immutables.value.Value; +import org.immutables.value.Value.Immutable; +import org.xrpl.xrpl4j.model.flags.TransactionFlags; + +@Immutable +@JsonSerialize(as = ImmutableUnknownTransaction.class) +@JsonDeserialize(as = ImmutableUnknownTransaction.class) +public interface UnknownTransaction extends Transaction { + + /** + * Construct a {@code UnknownTransaction} builder. + * + * @return An {@link ImmutableUnknownTransaction.Builder}. + */ + static ImmutableUnknownTransaction.Builder builder() { + return ImmutableUnknownTransaction.builder(); + } + + /** + * This has to be a {@link String} because {@link Transaction#transactionType()} is a {@link TransactionType}, + * which only has an UNKNOWN variant. Because this method is also annotated with {@link JsonProperty} of + * "TransactionType", this essentially overrides the "TransactionType" field in JSON, but {@link #transactionType()} + * will always be {@link TransactionType#UNKNOWN} and this field will contain the actual "TransactionType" field. + * + * @return A {@link String} containing the transaction type from JSON. + */ + @JsonProperty("TransactionType") + String unknownTransactionType(); + + @Override + @JsonIgnore + default TransactionType transactionType() { + return Transaction.super.transactionType(); + } + + @JsonProperty("Flags") + @Value.Default + default TransactionFlags flags() { + return TransactionFlags.EMPTY; + } + +} diff --git a/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/transactions/UnlModify.java b/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/transactions/UnlModify.java index e171a22e0..9ad15e842 100644 --- a/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/transactions/UnlModify.java +++ b/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/transactions/UnlModify.java @@ -62,7 +62,9 @@ static ImmutableUnlModify.Builder builder() { */ @Override @JsonProperty("Account") - @Value.Derived + // FIXME: Have to make this Default, otherwise JsonAnySetter adds this field to unknownFields. Other option + // is that's totally fine, which i think it is -- we should let the JSON set this field if it's there + @Value.Default default Address account() { return ACCOUNT_ZERO; } diff --git a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/AmmBidTest.java b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/AmmBidTest.java index 0975e3aa0..9cfab3080 100644 --- a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/AmmBidTest.java +++ b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/AmmBidTest.java @@ -312,4 +312,58 @@ void testJsonWithXrpAmountBidMinAndMax() throws JSONException, JsonProcessingExc "}"; assertCanSerializeAndDeserialize(ammBid, json); } + + @Test + void testJsonWithUnknownFields() throws JSONException, JsonProcessingException { + AmmBid bid = AmmBid.builder() + .account(Address.of("rJVUeRqDFNs2xqA7ncVE6ZoAhPUoaJJSQm")) + .signingPublicKey( + PublicKey.fromBase16EncodedPublicKey("02356E89059A75438887F9FEE2056A2890DB82A68353BE9C0C0C8F89C0018B37FC") + ) + .asset(Issue.XRP) + .asset2( + Issue.builder() + .issuer(Address.of("rP9jPyP5kyvFRb6ZiRghAGw5u8SGAmU4bd")) + .currency("TST") + .build() + ) + .addAuthAccounts( + AuthAccountWrapper.of(AuthAccount.of(Address.of("rMKXGCbJ5d8LbrqthdG46q3f969MVK2Qeg"))), + AuthAccountWrapper.of(AuthAccount.of(Address.of("rBepJuTLFJt3WmtLXYAxSjtBWAeQxVbncv"))) + ) + .fee(XrpCurrencyAmount.ofDrops(10)) + .sequence(UnsignedInteger.valueOf(9)) + .putUnknownFields("Foo", "Bar") + .build(); + + String json = "{\n" + + " \"Foo\" : \"Bar\",\n" + + " \"Account\" : \"rJVUeRqDFNs2xqA7ncVE6ZoAhPUoaJJSQm\",\n" + + " \"Asset\" : {\n" + + " \"currency\" : \"XRP\"\n" + + " },\n" + + " \"Asset2\" : {\n" + + " \"currency\" : \"TST\",\n" + + " \"issuer\" : \"rP9jPyP5kyvFRb6ZiRghAGw5u8SGAmU4bd\"\n" + + " },\n" + + " \"AuthAccounts\" : [\n" + + " {\n" + + " \"AuthAccount\" : {\n" + + " \"Account\" : \"rMKXGCbJ5d8LbrqthdG46q3f969MVK2Qeg\"\n" + + " }\n" + + " },\n" + + " {\n" + + " \"AuthAccount\" : {\n" + + " \"Account\" : \"rBepJuTLFJt3WmtLXYAxSjtBWAeQxVbncv\"\n" + + " }\n" + + " }\n" + + " ],\n" + + " \"Fee\" : \"10\",\n" + + " \"Sequence\" : 9,\n" + + " \"SigningPubKey\" : \"02356E89059A75438887F9FEE2056A2890DB82A68353BE9C0C0C8F89C0018B37FC\",\n" + + " \"TransactionType\" : \"AMMBid\"\n" + + "}"; + + assertCanSerializeAndDeserialize(bid, json); + } } \ No newline at end of file diff --git a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/AmmCreateTest.java b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/AmmCreateTest.java index 275582f17..927f1820a 100644 --- a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/AmmCreateTest.java +++ b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/AmmCreateTest.java @@ -127,4 +127,44 @@ void testJsonWithNonZeroFlags() throws JSONException, JsonProcessingException { assertCanSerializeAndDeserialize(ammCreate, json); } + + @Test + void testJsonWithUnknownFields() throws JSONException, JsonProcessingException { + AmmCreate ammCreate = AmmCreate.builder() + .account(Address.of("rJVUeRqDFNs2xqA7ncVE6ZoAhPUoaJJSQm")) + .amount( + IssuedCurrencyAmount.builder() + .currency("TST") + .issuer(Address.of("rP9jPyP5kyvFRb6ZiRghAGw5u8SGAmU4bd")) + .value("25") + .build() + ) + .amount2(XrpCurrencyAmount.ofDrops(250000000)) + .fee(XrpCurrencyAmount.ofDrops(10)) + .sequence(UnsignedInteger.valueOf(6)) + .tradingFee(TradingFee.of(UnsignedInteger.valueOf(500))) + .signingPublicKey( + PublicKey.fromBase16EncodedPublicKey("02356E89059A75438887F9FEE2056A2890DB82A68353BE9C0C0C8F89C0018B37FC") + ) + .putUnknownFields("Foo", "Bar") + .build(); + + String json = "{\n" + + " \"Foo\" : \"Bar\",\n" + + " \"Account\" : \"rJVUeRqDFNs2xqA7ncVE6ZoAhPUoaJJSQm\",\n" + + " \"Amount\" : {\n" + + " \"currency\" : \"TST\",\n" + + " \"issuer\" : \"rP9jPyP5kyvFRb6ZiRghAGw5u8SGAmU4bd\",\n" + + " \"value\" : \"25\"\n" + + " },\n" + + " \"Amount2\" : \"250000000\",\n" + + " \"Fee\" : \"10\",\n" + + " \"Sequence\" : 6,\n" + + " \"TradingFee\" : 500,\n" + + " \"SigningPubKey\" : \"02356E89059A75438887F9FEE2056A2890DB82A68353BE9C0C0C8F89C0018B37FC\",\n" + + " \"TransactionType\" : \"AMMCreate\"\n" + + "}"; + + assertCanSerializeAndDeserialize(ammCreate, json); + } } \ No newline at end of file diff --git a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/AmmDeleteTest.java b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/AmmDeleteTest.java index 2889e572e..83681dfc7 100644 --- a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/AmmDeleteTest.java +++ b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/AmmDeleteTest.java @@ -46,4 +46,42 @@ void testJson() throws JSONException, JsonProcessingException { assertCanSerializeAndDeserialize(ammDelete, json); } + + @Test + void testJsonWithUnknownFields() throws JSONException, JsonProcessingException { + AmmDelete ammDelete = AmmDelete.builder() + .asset(Issue.XRP) + .asset2( + Issue.builder() + .issuer(Address.of("rP9jPyP5kyvFRb6ZiRghAGw5u8SGAmU4bd")) + .currency("TST") + .build() + ) + .account(Address.of("rJVUeRqDFNs2xqA7ncVE6ZoAhPUoaJJSQm")) + .fee(XrpCurrencyAmount.ofDrops(10)) + .sequence(UnsignedInteger.valueOf(9)) + .signingPublicKey(PublicKey.fromBase16EncodedPublicKey( + "EDD299D60BCE7980F6082945B5597FFFD35223F1950673BFA4D4AED6FDE5097156" + )) + .putUnknownFields("Foo", "Bar") + .build(); + + String json = "{\n" + + " \"Foo\" : \"Bar\",\n" + + " \"Account\" : \"rJVUeRqDFNs2xqA7ncVE6ZoAhPUoaJJSQm\",\n" + + " \"Asset\" : {\n" + + " \"currency\" : \"XRP\"\n" + + " },\n" + + " \"Asset2\" : {\n" + + " \"currency\" : \"TST\",\n" + + " \"issuer\" : \"rP9jPyP5kyvFRb6ZiRghAGw5u8SGAmU4bd\"\n" + + " },\n" + + " \"Fee\" : \"10\",\n" + + " \"Sequence\" : 9,\n" + + " \"SigningPubKey\" : \"EDD299D60BCE7980F6082945B5597FFFD35223F1950673BFA4D4AED6FDE5097156\",\n" + + " \"TransactionType\" : \"AMMDelete\"\n" + + "}"; + + assertCanSerializeAndDeserialize(ammDelete, json); + } } \ No newline at end of file diff --git a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/AmmDepositTest.java b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/AmmDepositTest.java index 004816e7d..247367fd1 100644 --- a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/AmmDepositTest.java +++ b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/AmmDepositTest.java @@ -385,4 +385,61 @@ void constructTwoAssetIfEmptyDepositTestJson() throws JSONException, JsonProcess assertCanSerializeAndDeserialize(deposit, json); } + + @Test + void testJsonWithUnknownFields() throws JSONException, JsonProcessingException { + AmmDeposit deposit = AmmDeposit.builder() + .account(Address.of("rJVUeRqDFNs2xqA7ncVE6ZoAhPUoaJJSQm")) + .fee(XrpCurrencyAmount.ofDrops(10)) + .signingPublicKey( + PublicKey.fromBase16EncodedPublicKey("02356E89059A75438887F9FEE2056A2890DB82A68353BE9C0C0C8F89C0018B37FC") + ) + .flags(AmmDepositFlags.TWO_ASSET_IF_EMPTY) + .asset(Issue.XRP) + .asset2( + Issue.builder() + .issuer(Address.of("rP9jPyP5kyvFRb6ZiRghAGw5u8SGAmU4bd")) + .currency("TST") + .build() + ) + .amount( + IssuedCurrencyAmount.builder() + .currency("039C99CD9AB0B70B32ECDA51EAAE471625608EA2") + .issuer(Address.of("rE54zDvgnghAoPopCgvtiqWNq3dU5y836S")) + .value("100") + .build() + ) + .amount2(XrpCurrencyAmount.ofDrops(10)) + .effectivePrice(XrpCurrencyAmount.ofDrops(10)) + .putUnknownFields("Foo", "Bar") + .build(); + + assertThat(deposit.flags()).isEqualTo(AmmDepositFlags.TWO_ASSET_IF_EMPTY); + + String json = "{\n" + + " \"Foo\" : \"Bar\",\n" + + " \"Account\" : \"" + deposit.account() + "\",\n" + + " \"Amount\" : {\n" + + " \"currency\" : \"039C99CD9AB0B70B32ECDA51EAAE471625608EA2\",\n" + + " \"issuer\" : \"rE54zDvgnghAoPopCgvtiqWNq3dU5y836S\",\n" + + " \"value\" : \"100\"\n" + + " },\n" + + " \"Amount2\" : \"10\",\n" + + " \"EPrice\" : \"10\",\n" + + " \"Asset2\" : {\n" + + " \"currency\" : \"TST\",\n" + + " \"issuer\" : \"rP9jPyP5kyvFRb6ZiRghAGw5u8SGAmU4bd\"\n" + + " },\n" + + " \"Asset\" : {\n" + + " \"currency\" : \"XRP\"\n" + + " },\n" + + " \"Fee\" : \"10\",\n" + + " \"Flags\" : " + AmmDepositFlags.TWO_ASSET_IF_EMPTY + ",\n" + + " \"Sequence\" : 0,\n" + + " \"SigningPubKey\" : \"02356E89059A75438887F9FEE2056A2890DB82A68353BE9C0C0C8F89C0018B37FC\",\n" + + " \"TransactionType\" : \"AMMDeposit\"\n" + + "}"; + + assertCanSerializeAndDeserialize(deposit, json); + } } \ No newline at end of file diff --git a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/AmmVoteTest.java b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/AmmVoteTest.java index e0fee4500..8c285f51f 100644 --- a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/AmmVoteTest.java +++ b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/AmmVoteTest.java @@ -128,4 +128,44 @@ void testJsonWithNonZeroFlags() throws JSONException, JsonProcessingException { assertCanSerializeAndDeserialize(vote, json); } + + @Test + void testJsonWithUnknownFields() throws JSONException, JsonProcessingException { + AmmVote vote = AmmVote.builder() + .account(Address.of("rJVUeRqDFNs2xqA7ncVE6ZoAhPUoaJJSQm")) + .asset(Issue.XRP) + .asset2( + Issue.builder() + .currency("TST") + .issuer(Address.of("rP9jPyP5kyvFRb6ZiRghAGw5u8SGAmU4bd")) + .build() + ) + .fee(XrpCurrencyAmount.ofDrops(10)) + .sequence(UnsignedInteger.valueOf(8)) + .tradingFee(TradingFee.of(UnsignedInteger.valueOf(600))) + .signingPublicKey( + PublicKey.fromBase16EncodedPublicKey("02356E89059A75438887F9FEE2056A2890DB82A68353BE9C0C0C8F89C0018B37FC") + ) + .putUnknownFields("Foo", "Bar") + .build(); + + String json = "{\n" + + " \"Foo\" : \"Bar\",\n" + + " \"Account\" : \"rJVUeRqDFNs2xqA7ncVE6ZoAhPUoaJJSQm\",\n" + + " \"Asset\" : {\n" + + " \"currency\" : \"XRP\"\n" + + " },\n" + + " \"Asset2\" : {\n" + + " \"currency\" : \"TST\",\n" + + " \"issuer\" : \"rP9jPyP5kyvFRb6ZiRghAGw5u8SGAmU4bd\"\n" + + " },\n" + + " \"Fee\" : \"10\",\n" + + " \"Sequence\" : 8,\n" + + " \"TradingFee\" : 600,\n" + + " \"SigningPubKey\" : \"02356E89059A75438887F9FEE2056A2890DB82A68353BE9C0C0C8F89C0018B37FC\",\n" + + " \"TransactionType\" : \"AMMVote\"\n" + + "}"; + + assertCanSerializeAndDeserialize(vote, json); + } } \ No newline at end of file diff --git a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/AmmWithdrawTest.java b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/AmmWithdrawTest.java index 8f89e64ff..b59ed7cc7 100644 --- a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/AmmWithdrawTest.java +++ b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/AmmWithdrawTest.java @@ -1,7 +1,5 @@ package org.xrpl.xrpl4j.model.transactions; -import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; - import com.fasterxml.jackson.core.JsonProcessingException; import org.json.JSONException; import org.junit.jupiter.api.Test; @@ -212,6 +210,30 @@ void constructLimitLpTokenAndTestJson() throws JSONException, JsonProcessingExce assertCanSerializeAndDeserialize(withdraw, json); } + @Test + void testJsonWithUnknownFields() throws JSONException, JsonProcessingException { + AmmWithdraw withdraw = baseBuilder() + .flags(AmmWithdrawFlags.LP_TOKEN) + .lpTokensIn(lpTokensIn()) + .putUnknownFields("Foo", "Bar") + .build(); + + String json = "{\n" + + " \"Foo\" : \"Bar\",\n" + + " \"Account\" : \"rJVUeRqDFNs2xqA7ncVE6ZoAhPUoaJJSQm\",\n" + + " \"LPTokensIn\" : " + objectMapper.writeValueAsString(withdraw.lpTokensIn()) + "," + + " \"Asset\" : " + objectMapper.writeValueAsString(withdraw.asset()) + "," + + " \"Asset2\" : " + objectMapper.writeValueAsString(withdraw.asset2()) + "," + + " \"Fee\" : \"10\",\n" + + " \"Flags\" : " + AmmWithdrawFlags.LP_TOKEN + ",\n" + + " \"Sequence\" : 0,\n" + + " \"SigningPubKey\" : \"02356E89059A75438887F9FEE2056A2890DB82A68353BE9C0C0C8F89C0018B37FC\",\n" + + " \"TransactionType\" : \"AMMWithdraw\"\n" + + "}"; + + assertCanSerializeAndDeserialize(withdraw, json); + } + private ImmutableIssuedCurrencyAmount amount() { return IssuedCurrencyAmount.builder() .currency("TST") diff --git a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/ClawbackTest.java b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/ClawbackTest.java index 5eeb0410a..8eac63ea1 100644 --- a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/ClawbackTest.java +++ b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/ClawbackTest.java @@ -115,4 +115,40 @@ void testJsonWithNonZeroFlags() throws JSONException, JsonProcessingException { assertCanSerializeAndDeserialize(clawback, json); } + + @Test + void testJsonWithUnknownFields() throws JSONException, JsonProcessingException { + Clawback clawback = Clawback.builder() + .account(Address.of("rp6abvbTbjoce8ZDJkT6snvxTZSYMBCC9S")) + .fee(XrpCurrencyAmount.ofDrops(10)) + .sequence(UnsignedInteger.ONE) + .signingPublicKey(PublicKey.fromBase16EncodedPublicKey( + "02356E89059A75438887F9FEE2056A2890DB82A68353BE9C0C0C8F89C0018B37FC" + )) + .amount( + IssuedCurrencyAmount.builder() + .currency("FOO") + .issuer(Address.of("rsA2LpzuawewSBQXkiju3YQTMzW13pAAdW")) + .value("314.159") + .build() + ) + .putUnknownFields("Foo", "Bar") + .build(); + + String json = "{\n" + + " \"Foo\" : \"Bar\",\n" + + " \"TransactionType\": \"Clawback\",\n" + + " \"Account\": \"rp6abvbTbjoce8ZDJkT6snvxTZSYMBCC9S\",\n" + + " \"Amount\": {\n" + + " \"currency\": \"FOO\",\n" + + " \"issuer\": \"rsA2LpzuawewSBQXkiju3YQTMzW13pAAdW\",\n" + + " \"value\": \"314.159\"\n" + + " },\n" + + " \"Fee\": \"10\",\n" + + " \"Sequence\": 1,\n" + + " \"SigningPubKey\": \"02356E89059A75438887F9FEE2056A2890DB82A68353BE9C0C0C8F89C0018B37FC\"\n" + + "}"; + + assertCanSerializeAndDeserialize(clawback, json); + } } \ No newline at end of file diff --git a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/DidDeleteTest.java b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/DidDeleteTest.java index 739963267..b9d5951dd 100644 --- a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/DidDeleteTest.java +++ b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/DidDeleteTest.java @@ -62,6 +62,24 @@ void testJsonWithSetFlags() throws JSONException, JsonProcessingException { assertCanSerializeAndDeserialize(transaction, json); } + @Test + void testJsonWithUnknownFields() throws JSONException, JsonProcessingException { + DidDelete transaction = baseBuilder() + .putUnknownFields("Foo", "Bar") + .build(); + + String json = String.format("{\n" + + " \"Foo\" : \"Bar\",\n" + + " \"TransactionType\": \"DIDDelete\", \n" + + " \"Account\": \"rp4pqYgrTAtdPHuZd1ZQWxrzx45jxYcZex\",\n" + + " \"Fee\": \"12\",\n" + + " \"Sequence\": 391,\n" + + " \"SigningPubKey\":\"%s\"\n" + + "}", ED_PUBLIC_KEY.base16Value()); + + assertCanSerializeAndDeserialize(transaction, json); + } + private ImmutableDidDelete.Builder baseBuilder() { return DidDelete.builder() .account(Address.of("rp4pqYgrTAtdPHuZd1ZQWxrzx45jxYcZex")) diff --git a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/DidSetTest.java b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/DidSetTest.java index 09051f8c9..8541f0040 100644 --- a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/DidSetTest.java +++ b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/DidSetTest.java @@ -113,4 +113,32 @@ void testJsonWithSetFlags() throws JSONException, JsonProcessingException { assertCanSerializeAndDeserialize(transaction, json); } + + @Test + void testJsonWithUnknownFields() throws JSONException, JsonProcessingException { + DidSet transaction = DidSet.builder() + .account(Address.of("rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh")) + .fee(XrpCurrencyAmount.ofDrops(10)) + .sequence(UnsignedInteger.valueOf(391)) + .didDocument(DidDocument.of("")) + .uri(DidUri.of("")) + .data(DidData.of("")) + .signingPublicKey(ED_PUBLIC_KEY) + .putUnknownFields("Foo", "Bar") + .build(); + + String json = String.format("{\n" + + " \"Foo\" : \"Bar\",\n" + + " \"TransactionType\": \"DIDSet\",\n" + + " \"Account\": \"rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh\",\n" + + " \"Fee\": \"10\",\n" + + " \"Sequence\": 391,\n" + + " \"DIDDocument\": \"\",\n" + + " \"URI\": \"\",\n" + + " \"Data\": \"\",\n" + + " \"SigningPubKey\":\"%s\"\n" + + "}", ED_PUBLIC_KEY.base16Value()); + + assertCanSerializeAndDeserialize(transaction, json); + } } \ No newline at end of file diff --git a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/OracleDeleteTest.java b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/OracleDeleteTest.java index 54e54264a..fbdcdf222 100644 --- a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/OracleDeleteTest.java +++ b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/OracleDeleteTest.java @@ -37,6 +37,25 @@ void testJson() throws JSONException, JsonProcessingException { assertCanSerializeAndDeserialize(oracleDelete, json); } + @Test + void testJsonWithUnknownFields() throws JSONException, JsonProcessingException { + OracleDelete oracleDelete = baseBuilder() + .putUnknownFields("Foo", "Bar") + .build(); + String json = "\n" + + "{\n" + + " \"Foo\" : \"Bar\",\n" + + " \"TransactionType\": \"OracleDelete\",\n" + + " \"Account\": \"rp4pqYgrTAtdPHuZd1ZQWxrzx45jxYcZex\",\n" + + " \"OracleDocumentID\": 1,\n" + + " \"Fee\": \"12\",\n" + + " \"Sequence\": 391,\n" + + " \"SigningPubKey\": \"" + ED_PUBLIC_KEY_HEX + "\"\n" + + "}"; + + assertCanSerializeAndDeserialize(oracleDelete, json); + } + private static ImmutableOracleDelete.Builder baseBuilder() { return OracleDelete.builder() .account(Address.of("rp4pqYgrTAtdPHuZd1ZQWxrzx45jxYcZex")) diff --git a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/OracleSetTest.java b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/OracleSetTest.java index 05bdb2733..859417cb0 100644 --- a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/OracleSetTest.java +++ b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/OracleSetTest.java @@ -82,6 +82,26 @@ void testFullJson() throws JSONException, JsonProcessingException { assertCanSerializeAndDeserialize(oracleSet, json); } + @Test + void testJsonWithUnknownFields() throws JSONException, JsonProcessingException { + OracleSet oracleSet = baseBuilder() + .putUnknownFields("Foo", "Bar") + .build(); + String json = "\n" + + "{\n" + + " \"Foo\" : \"Bar\",\n" + + " \"TransactionType\": \"OracleSet\",\n" + + " \"Account\": \"rp4pqYgrTAtdPHuZd1ZQWxrzx45jxYcZex\",\n" + + " \"OracleDocumentID\": 1,\n" + + " \"Fee\": \"12\",\n" + + " \"Sequence\": 391,\n" + + " \"SigningPubKey\": \"" + ED_PUBLIC_KEY_HEX + "\",\n" + + " \"LastUpdateTime\": 1\n" + + "}"; + + assertCanSerializeAndDeserialize(oracleSet, json); + } + private static ImmutableOracleSet.Builder baseBuilder() { return OracleSet.builder() .account(Address.of("rp4pqYgrTAtdPHuZd1ZQWxrzx45jxYcZex")) diff --git a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/SetFeeTest.java b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/SetFeeTest.java index 42018706f..49a83f717 100644 --- a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/SetFeeTest.java +++ b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/SetFeeTest.java @@ -155,4 +155,38 @@ public void testDeserializePostXrpFeesTransaction() throws JsonProcessingExcepti assertThat(redeserialized).isEqualTo(expected); } + + @Test + public void testJsonWithUnknownFields() throws JsonProcessingException { + SetFee expected = SetFee.builder() + .account(Address.of("rrrrrrrrrrrrrrrrrrrrrhoLvTp")) + .fee(XrpCurrencyAmount.ofDrops(0)) + .sequence(UnsignedInteger.valueOf(0)) + .baseFeeDrops(XrpCurrencyAmount.ofDrops(10)) + .reserveBaseDrops(XrpCurrencyAmount.ofDrops(10000000)) + .reserveIncrementDrops(XrpCurrencyAmount.ofDrops(2000000)) + .ledgerSequence(Optional.of(LedgerIndex.of(UnsignedInteger.valueOf(66462465)))) + .putUnknownFields("Foo", "Bar") + .build(); + + String json = "{\n" + + " \"Foo\" : \"Bar\",\n" + + " \"Account\": \"rrrrrrrrrrrrrrrrrrrrrhoLvTp\",\n" + + " \"BaseFeeDrops\": \"10\",\n" + + " \"Fee\": \"0\",\n" + + " \"LedgerSequence\": 66462465,\n" + + " \"ReserveBaseDrops\": \"10000000\",\n" + + " \"ReserveIncrementDrops\": \"2000000\",\n" + + " \"Sequence\": 0,\n" + + " \"SigningPubKey\": \"\",\n" + + " \"TransactionType\": \"SetFee\"}"; + + Transaction actual = objectMapper.readValue(json, Transaction.class); + assertThat(actual).isEqualTo(expected); + + String reserialized = objectMapper.writeValueAsString(actual); + Transaction redeserialized = objectMapper.readValue(reserialized, Transaction.class); + + assertThat(redeserialized).isEqualTo(expected); + } } diff --git a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/TransactionTypeTests.java b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/TransactionTypeTests.java index 77beee833..af5e049c2 100644 --- a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/TransactionTypeTests.java +++ b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/TransactionTypeTests.java @@ -32,7 +32,9 @@ import org.junit.jupiter.params.provider.ArgumentsProvider; import org.junit.jupiter.params.provider.ArgumentsSource; import org.junit.jupiter.params.provider.EmptySource; +import org.junit.jupiter.params.provider.EnumSource; import org.junit.jupiter.params.provider.NullSource; +import org.junit.jupiter.params.provider.ValueSource; /** * Unit tests for {@link TransactionType}. @@ -40,8 +42,9 @@ public class TransactionTypeTests { @ParameterizedTest - @ArgumentsSource(value = TransactionTypeValidArgumentProvider.class) - public void shouldReturnTransactionTypeForValidValues(String value) { + @EnumSource + public void shouldReturnTransactionTypeForValidValues(TransactionType type) { + String value = type.value(); TransactionType transactionType = TransactionType.forValue(value); assertNotNull(transactionType); assertTrue(transactionType instanceof TransactionType); @@ -50,28 +53,9 @@ public void shouldReturnTransactionTypeForValidValues(String value) { @EmptySource @NullSource @ParameterizedTest - @ArgumentsSource(value = TransactionTypeInvalidArgumentProvider.class) + @ValueSource(strings = {"bla", "blaaa", "123"}) public void shouldThrowIllegalArgumentExceptionForInvalidValues(String value) { - assertThrows(IllegalArgumentException.class, () -> TransactionType.forValue(value), - "No matching TransactionType enum value for String value " + value); - } - - public static class TransactionTypeValidArgumentProvider implements ArgumentsProvider { - - @Override - public java.util.stream.Stream provideArguments(ExtensionContext context) { - return java.util.stream.Stream.of(TransactionType.values()).map(TransactionType::value).map(Arguments::of); - } - - } - - public static class TransactionTypeInvalidArgumentProvider implements ArgumentsProvider { - - @Override - public java.util.stream.Stream provideArguments(ExtensionContext context) { - return java.util.stream.Stream.of("bla", "blaaa", "123").map(Arguments::of); - } - + assertThat(TransactionType.forValue(value)).isEqualTo(TransactionType.UNKNOWN); } @Test @@ -114,5 +98,6 @@ public void testTxTypeCapitalization() { assertThat(TransactionType.XCHAIN_CREATE_BRIDGE.value()).isEqualTo("XChainCreateBridge"); assertThat(TransactionType.XCHAIN_CREATE_CLAIM_ID.value()).isEqualTo("XChainCreateClaimID"); assertThat(TransactionType.XCHAIN_MODIFY_BRIDGE.value()).isEqualTo("XChainModifyBridge"); + assertThat(TransactionType.UNKNOWN.value()).isEqualTo("Unknown"); } } \ No newline at end of file diff --git a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/UnknownTransactionTest.java b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/UnknownTransactionTest.java new file mode 100644 index 000000000..aeacb2a42 --- /dev/null +++ b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/UnknownTransactionTest.java @@ -0,0 +1,76 @@ +package org.xrpl.xrpl4j.model.transactions; + +import static org.assertj.core.api.Assertions.assertThat; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.google.common.base.Strings; +import com.google.common.collect.Maps; +import com.google.common.primitives.UnsignedInteger; +import org.immutables.value.Value.Immutable; +import org.json.JSONException; +import org.junit.jupiter.api.Test; +import org.xrpl.xrpl4j.crypto.keys.PublicKey; +import org.xrpl.xrpl4j.model.AbstractJsonTest; +import org.xrpl.xrpl4j.model.flags.TransactionFlags; +import org.xrpl.xrpl4j.model.transactions.AccountSet.AccountSetFlag; + +import java.util.HashMap; +import java.util.Optional; + +class UnknownTransactionTest extends AbstractJsonTest { + + @Test + void testJson() throws JSONException, JsonProcessingException { + HashMap unknownFields = Maps.newHashMap(); + unknownFields.put("Domain", ""); + unknownFields.put("SetFlag", 5); + unknownFields.put("MessageKey", ""); + unknownFields.put("TransferRate", 1000000001); + unknownFields.put("TickSize", 15); + unknownFields.put("ClearFlag", 8); + unknownFields.put("NFTokenMinter", "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn"); + unknownFields.put("WalletLocator", Strings.repeat("0", 64)); + unknownFields.put("EmailHash", Strings.repeat("0", 32)); + Transaction transaction = UnknownTransaction.builder() + .unknownTransactionType("AccountSet2") + .account(Address.of("rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn")) + .fee(XrpCurrencyAmount.ofDrops(12)) + .sequence(UnsignedInteger.valueOf(5)) + .flags(TransactionFlags.of(2147483648L)) + .signingPublicKey( + PublicKey.fromBase16EncodedPublicKey("02356E89059A75438887F9FEE2056A2890DB82A68353BE9C0C0C8F89C0018B37FC")) + .unknownFields( + unknownFields + ) + .networkId(NetworkId.of(UnsignedInteger.valueOf(1024))) + .build(); + + // Same properties as AccountSet, but TransactionType is AccountSet2 + String json = "{\n" + + " \"TransactionType\":\"AccountSet2\",\n" + + " \"Account\":\"rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn\",\n" + + " \"Fee\":\"12\",\n" + + " \"Sequence\":5,\n" + + " \"Flags\":2147483648,\n" + + " \"Domain\":\"\",\n" + + " \"SetFlag\":5,\n" + + " \"MessageKey\":\"\",\n" + + " \"TransferRate\":1000000001,\n" + + " \"TickSize\":15,\n" + + " \"ClearFlag\":8,\n" + + " \"SigningPubKey\" : \"02356E89059A75438887F9FEE2056A2890DB82A68353BE9C0C0C8F89C0018B37FC\",\n" + + " \"NFTokenMinter\" : \"rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn\",\n" + + " \"WalletLocator\" : \"" + Strings.repeat("0", 64) + "\",\n" + + " \"EmailHash\" : \"" + Strings.repeat("0", 32) + "\",\n" + + " \"NetworkID\": 1024\n" + + "}"; + + assertCanSerializeAndDeserialize(transaction, json); + } + +} \ No newline at end of file diff --git a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/XChainAccountCreateCommitTest.java b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/XChainAccountCreateCommitTest.java index 9996af22a..05e79d8d5 100644 --- a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/XChainAccountCreateCommitTest.java +++ b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/XChainAccountCreateCommitTest.java @@ -213,4 +213,56 @@ void testJsonWithEmptySignatureReward() throws JSONException, JsonProcessingExce assertCanSerializeAndDeserialize(commit, json); } + + @Test + void testJsonWithUnknownFields() throws JSONException, JsonProcessingException { + XChainAccountCreateCommit commit = XChainAccountCreateCommit.builder() + .account(Address.of("rwEqJ2UaQHe7jihxGqmx6J4xdbGiiyMaGa")) + .fee(XrpCurrencyAmount.ofDrops(1)) + .sequence(UnsignedInteger.ONE) + .destination(Address.of("rD323VyRjgzzhY4bFpo44rmyh2neB5d8Mo")) + .amount(XrpCurrencyAmount.ofDrops(20000000)) + .signatureReward(XrpCurrencyAmount.ofDrops(100)) + .signingPublicKey(ED_PUBLIC_KEY) + .xChainBridge( + XChainBridge.builder() + .lockingChainDoor(Address.of("rMAXACCrp3Y8PpswXcg3bKggHX76V3F8M4")) + .lockingChainIssue(Issue.XRP) + .issuingChainDoor(Address.of("rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh")) + .issuingChainIssue( + Issue.builder() + .currency("TST") + .issuer(Address.of("rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh")) + .build() + ) + .build() + ) + .putUnknownFields("Foo", "Bar") + .build(); + + String json = String.format("{\n" + + " \"Foo\" : \"Bar\",\n" + + " \"Account\": \"rwEqJ2UaQHe7jihxGqmx6J4xdbGiiyMaGa\",\n" + + " \"Fee\": \"1\",\n" + + " \"Sequence\": 1,\n" + + " \"Destination\": \"rD323VyRjgzzhY4bFpo44rmyh2neB5d8Mo\",\n" + + " \"TransactionType\": \"XChainAccountCreateCommit\",\n" + + " \"Amount\": \"20000000\",\n" + + " \"SignatureReward\": \"100\",\n" + + " \"SigningPubKey\": \"%s\",\n" + + " \"XChainBridge\": {\n" + + " \"LockingChainDoor\": \"rMAXACCrp3Y8PpswXcg3bKggHX76V3F8M4\",\n" + + " \"LockingChainIssue\": {\n" + + " \"currency\": \"XRP\"\n" + + " },\n" + + " \"IssuingChainDoor\": \"rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh\",\n" + + " \"IssuingChainIssue\": {\n" + + " \"currency\": \"TST\",\n" + + " \"issuer\": \"rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh\"\n" + + " }\n" + + " }\n" + + "}", ED_PUBLIC_KEY.base16Value()); + + assertCanSerializeAndDeserialize(commit, json); + } } \ No newline at end of file diff --git a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/XChainAddAccountCreateAttestationTest.java b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/XChainAddAccountCreateAttestationTest.java index dbb05e850..da41a745d 100644 --- a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/XChainAddAccountCreateAttestationTest.java +++ b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/XChainAddAccountCreateAttestationTest.java @@ -230,4 +230,42 @@ private ImmutableXChainAddAccountCreateAttestation.Builder baseBuilder() { .sequence(UnsignedInteger.ONE) .signingPublicKey(ED_PUBLIC_KEY); } + + @Test + void testJsonWithUnknownFields() throws JSONException, JsonProcessingException { + XChainAddAccountCreateAttestation transaction = baseBuilder() + .putUnknownFields("Foo", "Bar") + .build(); + String json = String.format("{\n" + + " \"Foo\" : \"Bar\",\n" + + " \"Account\": \"rDr5okqGKmMpn44Bbhe5WAfDQx8e9XquEv\",\n" + + " \"TransactionType\": \"XChainAddAccountCreateAttestation\",\n" + + " \"OtherChainSource\": \"rUzB7yg1LcFa7m3q1hfrjr5w53vcWzNh3U\",\n" + + " \"Destination\": \"rJMfWNVbyjcCtds8kpoEjEbYQ41J5B6MUd\",\n" + + " \"Amount\": \"2000000000\",\n" + + " \"PublicKey\": \"EDF7C3F9C80C102AF6D241752B37356E91ED454F26A35C567CF6F8477960F66614\",\n" + + " \"Signature\": \"F95675BA8FDA21030DE1B687937A79E8491CE51832D6BEEBC071484FA5AF5B8A0E9AFF11A4AA46F09EC" + + "FFB04C6A8DAE8284AF3ED8128C7D0046D842448478500\",\n" + + " \"WasLockingChainSend\": 1,\n" + + " \"AttestationRewardAccount\": \"rpFp36UHW6FpEcZjZqq5jSJWY6UCj3k4Es\",\n" + + " \"AttestationSignerAccount\": \"rpWLegmW9WrFBzHUj7brhQNZzrxgLj9oxw\",\n" + + " \"XChainAccountCreateCount\": \"2\",\n" + + " \"SignatureReward\": \"204\",\n" + + " \"Sequence\": 1,\n" + + " \"SigningPubKey\": %s,\n" + + " \"XChainBridge\": {\n" + + " \"LockingChainDoor\": \"r3nCVTbZGGYoWvZ58BcxDmiMUU7ChMa1eC\",\n" + + " \"LockingChainIssue\": {\n" + + " \"currency\": \"XRP\"\n" + + " },\n" + + " \"IssuingChainDoor\": \"rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh\",\n" + + " \"IssuingChainIssue\": {\n" + + " \"currency\": \"XRP\"\n" + + " }\n" + + " },\n" + + " \"Fee\": \"20\"\n" + + "}", ED_PUBLIC_KEY.base16Value()); + + assertCanSerializeAndDeserialize(transaction, json); + } } \ No newline at end of file diff --git a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/XChainAddClaimAttestationTest.java b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/XChainAddClaimAttestationTest.java index d1c158446..09711426e 100644 --- a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/XChainAddClaimAttestationTest.java +++ b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/XChainAddClaimAttestationTest.java @@ -236,4 +236,44 @@ private ImmutableXChainAddClaimAttestation.Builder baseBuilder() { ) .xChainClaimId(XChainClaimId.of(UnsignedLong.ONE)); } + + @Test + void testJsonWithUnknownFields() throws JSONException, JsonProcessingException { + XChainAddClaimAttestation attestation = baseBuilder() + .wasLockingChainSend(false) + .putUnknownFields("Foo", "Bar") + .build(); + + String json = "{\n" + + " \"Foo\" : \"Bar\",\n" + + " \"Account\": \"rsqvD8WFFEBBv4nztpoW9YYXJ7eRzLrtc3\",\n" + + " \"Amount\": \"10000000\",\n" + + " \"AttestationRewardAccount\": \"rsqvD8WFFEBBv4nztpoW9YYXJ7eRzLrtc3\",\n" + + " \"AttestationSignerAccount\": \"rsqvD8WFFEBBv4nztpoW9YYXJ7eRzLrtc3\",\n" + + " \"Destination\": \"rJdTJRJZ6GXCCRaamHJgEqVzB7Zy4557Pi\",\n" + + " \"Fee\": \"20\",\n" + + " \"LastLedgerSequence\": 19,\n" + + " \"OtherChainSource\": \"raFcdz1g8LWJDJWJE2ZKLRGdmUmsTyxaym\",\n" + + " \"PublicKey\": \"ED7541DEC700470F54276C90C333A13CDBB5D341FD43C60CEA12170F6D6D4E1136\",\n" + + " \"Sequence\": 9,\n" + + " \"Signature\": \"7C175050B08000AD35EEB2D87E16CD3F95A0AEEBF2A049474275153D9D4DD44528FE99AA5" + + "0E71660A15B0B768E1B90E609BBD5DC7AFAFD45D9705D72D40EA10C\",\n" + + " \"SigningPubKey\": \"ED0406B134786FE0751717226657F7BF8AFE96442C05D28ACEC66FB64852BA604C\",\n" + + " \"TransactionType\": \"XChainAddClaimAttestation\",\n" + + " \"WasLockingChainSend\": 0,\n" + + " \"XChainBridge\": {\n" + + " \"IssuingChainDoor\": \"rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh\",\n" + + " \"IssuingChainIssue\": {\n" + + " \"currency\": \"XRP\"\n" + + " },\n" + + " \"LockingChainDoor\": \"rDJVtEuDKr4rj1B3qtW7R5TVWdXV2DY7Qg\",\n" + + " \"LockingChainIssue\": {\n" + + " \"currency\": \"XRP\"\n" + + " }\n" + + " },\n" + + " \"XChainClaimID\": \"1\"\n" + + " }"; + + assertCanSerializeAndDeserialize(attestation, json); + } } \ No newline at end of file diff --git a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/XChainClaimTest.java b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/XChainClaimTest.java index 4426f54dd..494223c60 100644 --- a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/XChainClaimTest.java +++ b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/XChainClaimTest.java @@ -134,6 +134,39 @@ void testJsonWithFullyCanonicalSigFlags() throws JSONException, JsonProcessingEx assertCanSerializeAndDeserialize(attestation, json); } + @Test + void testJsonWithUnknownFields() throws JSONException, JsonProcessingException { + XChainClaim attestation = baseBuilder() + .destinationTag(UnsignedInteger.ONE) + .putUnknownFields("Foo", "Bar") + .build(); + + String json = String.format("{\n" + + " \"Foo\" : \"Bar\",\n" + + " \"Account\": \"rahDmoXrtPdh7sUdrPjini3gcnTVYjbjjw\",\n" + + " \"Amount\": \"10000\",\n" + + " \"Fee\": \"12\",\n" + + " \"Sequence\": 1,\n" + + " \"SigningPubKey\": %s,\n" + + " \"TransactionType\": \"XChainClaim\",\n" + + " \"XChainClaimID\": \"13f\",\n" + + " \"Destination\": \"rahDmoXrtPdh7sUdrPjini3gcnTVYjbjjw\",\n" + + " \"DestinationTag\": 1,\n" + + " \"XChainBridge\": {\n" + + " \"LockingChainDoor\": \"rMAXACCrp3Y8PpswXcg3bKggHX76V3F8M4\",\n" + + " \"LockingChainIssue\": {\n" + + " \"currency\": \"XRP\"\n" + + " },\n" + + " \"IssuingChainDoor\": \"rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh\",\n" + + " \"IssuingChainIssue\": {\n" + + " \"currency\": \"XRP\"\n" + + " }\n" + + " }\n" + + "}", ED_PUBLIC_KEY.base16Value()); + + assertCanSerializeAndDeserialize(attestation, json); + } + private ImmutableXChainClaim.Builder baseBuilder() { return XChainClaim.builder() .account(Address.of("rahDmoXrtPdh7sUdrPjini3gcnTVYjbjjw")) diff --git a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/XChainCommitTest.java b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/XChainCommitTest.java index 270229447..832812cd0 100644 --- a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/XChainCommitTest.java +++ b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/XChainCommitTest.java @@ -139,6 +139,47 @@ void testJsonWithFullyCanonicalSigFlags() throws JSONException, JsonProcessingEx assertCanSerializeAndDeserialize(commit, json); } + @Test + void testJsonWithUnknownFields() throws JSONException, JsonProcessingException { + XChainCommit commit = baseBuilder() + .amount( + IssuedCurrencyAmount.builder() + .currency("CNY") + .issuer(Address.of("r45dBj4S3VvMMYXxr9vHX4Z4Ma6ifPMCkK")) + .value("5000") + .build() + ) + .putUnknownFields("Foo", "Bar") + .build(); + + String json = String.format("{\n" + + " \"Foo\" : \"Bar\",\n" + + " \"Account\": \"rMTi57fNy2UkUb4RcdoUeJm7gjxVQvxzUo\",\n" + + " \"TransactionType\": \"XChainCommit\",\n" + + " \"XChainBridge\": {\n" + + " \"LockingChainDoor\": \"rMAXACCrp3Y8PpswXcg3bKggHX76V3F8M4\",\n" + + " \"LockingChainIssue\": {\n" + + " \"currency\": \"XRP\"\n" + + " },\n" + + " \"IssuingChainDoor\": \"rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh\",\n" + + " \"IssuingChainIssue\": {\n" + + " \"currency\": \"XRP\"\n" + + " }\n" + + " },\n" + + " \"Amount\": {" + + " \"currency\": \"CNY\",\n" + + " \"value\": \"5000\",\n" + + " \"issuer\": \"r45dBj4S3VvMMYXxr9vHX4Z4Ma6ifPMCkK\"\n" + + " },\n" + + " \"Fee\": \"10\",\n" + + " \"Sequence\": 1,\n" + + " \"SigningPubKey\": %s,\n" + + " \"XChainClaimID\": \"13f\"\n" + + "}", ED_PUBLIC_KEY.base16Value()); + + assertCanSerializeAndDeserialize(commit, json); + } + private ImmutableXChainCommit.Builder baseBuilder() { return XChainCommit.builder() .fee(XrpCurrencyAmount.ofDrops(10)) diff --git a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/XChainCreateBridgeTest.java b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/XChainCreateBridgeTest.java index f4bc61714..d15eb7937 100644 --- a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/XChainCreateBridgeTest.java +++ b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/XChainCreateBridgeTest.java @@ -103,6 +103,38 @@ void testJsonWithFullyCanonicalSigFlags() throws JSONException, JsonProcessingEx assertCanSerializeAndDeserialize(createBridge, json); } + @Test + void testJsonWithUnknownFields() throws JSONException, JsonProcessingException { + XChainCreateBridge createBridge = baseBuilder() + .minAccountCreateAmount(XrpCurrencyAmount.ofDrops(1000000)) + .putUnknownFields("Foo", "Bar") + .build(); + + String json = String.format("\n" + + "{\n" + + " \"Foo\" : \"Bar\",\n" + + " \"TransactionType\": \"XChainCreateBridge\",\n" + + " \"Account\": \"rhWQzvdmhf5vFS35vtKUSUwNZHGT53qQsg\",\n" + + " \"XChainBridge\": {\n" + + " \"LockingChainDoor\": \"rhWQzvdmhf5vFS35vtKUSUwNZHGT53qQsg\",\n" + + " \"LockingChainIssue\": {\n" + + " \"currency\": \"XRP\"\n" + + " },\n" + + " \"IssuingChainDoor\": \"rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh\",\n" + + " \"IssuingChainIssue\": {\n" + + " \"currency\": \"XRP\"\n" + + " }\n" + + " },\n" + + " \"SignatureReward\": \"200\",\n" + + " \"MinAccountCreateAmount\": \"1000000\",\n" + + " \"Fee\": \"10\",\n" + + " \"Sequence\": 1,\n" + + " \"SigningPubKey\": %s\n" + + "}", ED_PUBLIC_KEY.base16Value()); + + assertCanSerializeAndDeserialize(createBridge, json); + } + private ImmutableXChainCreateBridge.Builder baseBuilder() { return XChainCreateBridge.builder() .fee(XrpCurrencyAmount.ofDrops(10)) diff --git a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/XChainCreateClaimIdTest.java b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/XChainCreateClaimIdTest.java index ec1824104..ac5983c39 100644 --- a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/XChainCreateClaimIdTest.java +++ b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/XChainCreateClaimIdTest.java @@ -102,6 +102,37 @@ void testJsonWithFullyCanonicalSigFlags() throws JSONException, JsonProcessingEx assertCanSerializeAndDeserialize(claimId, json); } + @Test + void testJsonWithUnknownFields() throws JSONException, JsonProcessingException { + XChainCreateClaimId claimId = baseBuilder() + .putUnknownFields("Foo", "Bar") + .build(); + + String json = String.format("\n" + + "{\n" + + " \"Foo\" : \"Bar\",\n" + + " \"Account\": \"rahDmoXrtPdh7sUdrPjini3gcnTVYjbjjw\",\n" + + " \"OtherChainSource\": \"rMTi57fNy2UkUb4RcdoUeJm7gjxVQvxzUo\",\n" + + " \"TransactionType\": \"XChainCreateClaimID\",\n" + + " \"SignatureReward\": \"100\",\n" + + " \"XChainBridge\": {\n" + + " \"LockingChainDoor\": \"rMAXACCrp3Y8PpswXcg3bKggHX76V3F8M4\",\n" + + " \"LockingChainIssue\": {\n" + + " \"currency\": \"XRP\"\n" + + " },\n" + + " \"IssuingChainDoor\": \"rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh\",\n" + + " \"IssuingChainIssue\": {\n" + + " \"currency\": \"XRP\"\n" + + " }\n" + + " },\n" + + " \"Fee\": \"10\",\n" + + " \"Sequence\": 1,\n" + + " \"SigningPubKey\": %s\n" + + "}", ED_PUBLIC_KEY.base16Value()); + + assertCanSerializeAndDeserialize(claimId, json); + } + private ImmutableXChainCreateClaimId.Builder baseBuilder() { return XChainCreateClaimId.builder() .fee(XrpCurrencyAmount.ofDrops(10)) diff --git a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/XChainModifyBridgeTest.java b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/XChainModifyBridgeTest.java index caa0a86d3..bbcce697c 100644 --- a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/XChainModifyBridgeTest.java +++ b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/XChainModifyBridgeTest.java @@ -127,6 +127,35 @@ void testWithSigRewardAndMinAccountCreateAmount() throws JSONException, JsonProc assertCanSerializeAndDeserialize(modify, json); } + @Test + void testJsonWithUnknownFields() throws JSONException, JsonProcessingException { + XChainModifyBridge modify = baseBuilder() + .putUnknownFields("Foo", "Bar") + .build(); + + String json = String.format("\n" + + "{\n" + + " \"Foo\" : \"Bar\",\n" + + " \"TransactionType\": \"XChainModifyBridge\",\n" + + " \"Account\": \"rhWQzvdmhf5vFS35vtKUSUwNZHGT53qQsg\",\n" + + " \"XChainBridge\": {\n" + + " \"LockingChainDoor\": \"rhWQzvdmhf5vFS35vtKUSUwNZHGT53qQsg\",\n" + + " \"LockingChainIssue\": {\n" + + " \"currency\": \"XRP\"\n" + + " },\n" + + " \"IssuingChainDoor\": \"rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh\",\n" + + " \"IssuingChainIssue\": {\n" + + " \"currency\": \"XRP\"\n" + + " }\n" + + " },\n" + + " \"Fee\": \"10\",\n" + + " \"Sequence\": 1,\n" + + " \"SigningPubKey\": %s\n" + + "}", ED_PUBLIC_KEY.base16Value()); + + assertCanSerializeAndDeserialize(modify, json); + } + private ImmutableXChainModifyBridge.Builder baseBuilder() { return XChainModifyBridge.builder() .fee(XrpCurrencyAmount.ofDrops(10)) diff --git a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/AccountDeleteJsonTests.java b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/AccountDeleteJsonTests.java index 8177a0b61..674bb6f2e 100644 --- a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/AccountDeleteJsonTests.java +++ b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/AccountDeleteJsonTests.java @@ -117,4 +117,34 @@ public void testJsonWithNonZeroFlags() throws JsonProcessingException, JSONExcep assertCanSerializeAndDeserialize(accountDelete, json); } + + @Test + public void testJsonWithUnknownFields() throws JsonProcessingException, JSONException { + AccountDelete accountDelete = AccountDelete.builder() + .account(Address.of("rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm")) + .fee(XrpCurrencyAmount.ofDrops(5000000)) + .sequence(UnsignedInteger.valueOf(2470665)) + .destination(Address.of("rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe")) + .destinationTag(UnsignedInteger.valueOf(13)) + .signingPublicKey( + PublicKey.fromBase16EncodedPublicKey("02356E89059A75438887F9FEE2056A2890DB82A68353BE9C0C0C8F89C0018B37FC") + ) + .networkId(NetworkId.of(1024)) + .putUnknownFields("Foo", "Bar") + .build(); + + String json = "{\n" + + " \"Foo\" : \"Bar\",\n" + + " \"TransactionType\": \"AccountDelete\",\n" + + " \"Account\": \"rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm\",\n" + + " \"Destination\": \"rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe\",\n" + + " \"DestinationTag\": 13,\n" + + " \"Fee\": \"5000000\",\n" + + " \"Sequence\": 2470665,\n" + + " \"NetworkID\": 1024,\n" + + " \"SigningPubKey\" : \"02356E89059A75438887F9FEE2056A2890DB82A68353BE9C0C0C8F89C0018B37FC\"\n" + + "}"; + + assertCanSerializeAndDeserialize(accountDelete, json); + } } diff --git a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/AccountSetJsonTests.java b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/AccountSetJsonTests.java index 4f38e2afc..25f16a2b1 100644 --- a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/AccountSetJsonTests.java +++ b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/AccountSetJsonTests.java @@ -310,4 +310,52 @@ void testJsonWithUnrecognizedClearAndSetFlag() throws JSONException, JsonProcess assertCanSerializeAndDeserialize(accountSet, json); } + + @Test + public void testJsonWithUnknownFields() throws JSONException, JsonProcessingException { + AccountSet accountSet = AccountSet.builder() + .account(Address.of("rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn")) + .fee(XrpCurrencyAmount.ofDrops(12)) + .sequence(UnsignedInteger.valueOf(5)) + .domain("6578616D706C652E636F6D") + .setFlag(AccountSetFlag.ACCOUNT_TXN_ID) + .messageKey("03AB40A0490F9B7ED8DF29D246BF2D6269820A0EE7742ACDD457BEA7C7D0931EDB") + .transferRate(UnsignedInteger.valueOf(1000000001)) + .tickSize(UnsignedInteger.valueOf(15)) + .clearFlag(AccountSetFlag.DEFAULT_RIPPLE) + .emailHash("f9879d71855b5ff21e4963273a886bfc") + .signingPublicKey( + PublicKey.fromBase16EncodedPublicKey("02356E89059A75438887F9FEE2056A2890DB82A68353BE9C0C0C8F89C0018B37FC") + ) + .flags(AccountSetTransactionFlags.of(TransactionFlags.FULLY_CANONICAL_SIG.getValue())) + .mintAccount(Address.of("rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn")) + .networkId(NetworkId.of(1024)) + .walletLocator("ABCD") + .walletSize(UnsignedInteger.ONE) + .putUnknownFields("Foo", "Bar") + .build(); + + String json = "{\n" + + " \"Foo\" : \"Bar\",\n" + + " \"TransactionType\":\"AccountSet\",\n" + + " \"Account\":\"rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn\",\n" + + " \"Fee\":\"12\",\n" + + " \"Sequence\":5,\n" + + " \"Flags\":2147483648,\n" + + " \"Domain\":\"6578616D706C652E636F6D\",\n" + + " \"SetFlag\":5,\n" + + " \"MessageKey\":\"03AB40A0490F9B7ED8DF29D246BF2D6269820A0EE7742ACDD457BEA7C7D0931EDB\",\n" + + " \"TransferRate\":1000000001,\n" + + " \"TickSize\":15,\n" + + " \"ClearFlag\":8,\n" + + " \"SigningPubKey\" : \"02356E89059A75438887F9FEE2056A2890DB82A68353BE9C0C0C8F89C0018B37FC\",\n" + + " \"NFTokenMinter\" : \"rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn\",\n" + + " \"NetworkID\": 1024,\n" + + " \"WalletSize\": 1,\n" + + " \"WalletLocator\": \"ABCD\",\n" + + " \"EmailHash\":\"f9879d71855b5ff21e4963273a886bfc\"\n" + + "}"; + + assertCanSerializeAndDeserialize(accountSet, json); + } } diff --git a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/CheckJsonTests.java b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/CheckJsonTests.java index b20288ed3..056979430 100644 --- a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/CheckJsonTests.java +++ b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/CheckJsonTests.java @@ -115,6 +115,34 @@ public void testCheckCancelJsonWithNonZeroFlags() throws JsonProcessingException assertCanSerializeAndDeserialize(checkCancel, json); } + @Test + public void testCheckCancelJsonWithUnknownFields() throws JsonProcessingException, JSONException { + CheckCancel checkCancel = CheckCancel.builder() + .account(Address.of("rUn84CUYbNjRoTQ6mSW7BVJPSVJNLb1QLo")) + .checkId(Hash256.of("49647F0D748DC3FE26BDACBC57F251AADEFFF391403EC9BF87C97F67E9977FB0")) + .sequence(UnsignedInteger.valueOf(12)) + .fee(XrpCurrencyAmount.ofDrops(12)) + .signingPublicKey( + PublicKey.fromBase16EncodedPublicKey( "02356E89059A75438887F9FEE2056A2890DB82A68353BE9C0C0C8F89C0018B37FC") + ) + .networkId(NetworkId.of(1024)) + .putUnknownFields("Foo", "Bar") + .build(); + + String json = "{\n" + + " \"Foo\" : \"Bar\",\n" + + " \"Account\": \"rUn84CUYbNjRoTQ6mSW7BVJPSVJNLb1QLo\",\n" + + " \"TransactionType\": \"CheckCancel\",\n" + + " \"CheckID\": \"49647F0D748DC3FE26BDACBC57F251AADEFFF391403EC9BF87C97F67E9977FB0\",\n" + + " \"Sequence\": 12,\n" + + " \"SigningPubKey\" : \"02356E89059A75438887F9FEE2056A2890DB82A68353BE9C0C0C8F89C0018B37FC\",\n" + + " \"NetworkID\": 1024,\n" + + " \"Fee\": \"12\"\n" + + "}"; + + assertCanSerializeAndDeserialize(checkCancel, json); + } + @Test public void testCheckCashJsonWithDeliverMin() throws JsonProcessingException, JSONException { CheckCash checkCash = CheckCash.builder() @@ -225,6 +253,36 @@ public void testCheckCashJsonWithNonZeroFlags() throws JsonProcessingException, assertCanSerializeAndDeserialize(checkCash, json); } + @Test + public void testCheckCashJsonWithUnknownFields() throws JsonProcessingException, JSONException { + CheckCash checkCash = CheckCash.builder() + .account(Address.of("rfkE1aSy9G8Upk4JssnwBxhEv5p4mn2KTy")) + .checkId(Hash256.of("838766BA2B995C00744175F69A1B11E32C3DBC40E64801A4056FCBD657F57334")) + .sequence(UnsignedInteger.ONE) + .fee(XrpCurrencyAmount.ofDrops(12)) + .deliverMin(XrpCurrencyAmount.ofDrops(100)) + .signingPublicKey( + PublicKey.fromBase16EncodedPublicKey("02356E89059A75438887F9FEE2056A2890DB82A68353BE9C0C0C8F89C0018B37FC") + ) + .networkId(NetworkId.of(1024)) + .putUnknownFields("Foo", "Bar") + .build(); + + String json = "{\n" + + " \"Foo\" : \"Bar\",\n" + + " \"Account\": \"rfkE1aSy9G8Upk4JssnwBxhEv5p4mn2KTy\",\n" + + " \"TransactionType\": \"CheckCash\",\n" + + " \"DeliverMin\": \"100\",\n" + + " \"CheckID\": \"838766BA2B995C00744175F69A1B11E32C3DBC40E64801A4056FCBD657F57334\",\n" + + " \"Sequence\": 1,\n" + + " \"SigningPubKey\" : \"02356E89059A75438887F9FEE2056A2890DB82A68353BE9C0C0C8F89C0018B37FC\",\n" + + " \"NetworkID\": 1024,\n" + + " \"Fee\": \"12\"\n" + + "}"; + + assertCanSerializeAndDeserialize(checkCash, json); + } + @Test public void testCheckCreateJson() throws JsonProcessingException, JSONException { CheckCreate checkCreate = CheckCreate.builder() @@ -340,4 +398,40 @@ public void testCheckCreateJsonWithNonZeroFlags() throws JsonProcessingException assertCanSerializeAndDeserialize(checkCreate, json); } + + @Test + public void testCheckCreateJsonWithUnknownFields() throws JsonProcessingException, JSONException { + CheckCreate checkCreate = CheckCreate.builder() + .account(Address.of("rUn84CUYbNjRoTQ6mSW7BVJPSVJNLb1QLo")) + .sequence(UnsignedInteger.ONE) + .fee(XrpCurrencyAmount.ofDrops(12)) + .destination(Address.of("rfkE1aSy9G8Upk4JssnwBxhEv5p4mn2KTy")) + .destinationTag(UnsignedInteger.ONE) + .sendMax(XrpCurrencyAmount.ofDrops(100000000)) + .expiration(UnsignedInteger.valueOf(570113521)) + .invoiceId(Hash256.of("6F1DFD1D0FE8A32E40E1F2C05CF1C15545BAB56B617F9C6C2D63A6B704BEF59B")) + .signingPublicKey( + PublicKey.fromBase16EncodedPublicKey("02356E89059A75438887F9FEE2056A2890DB82A68353BE9C0C0C8F89C0018B37FC") + ) + .networkId(NetworkId.of(1024)) + .putUnknownFields("Foo", "Bar") + .build(); + + String json = "{\n" + + " \"Foo\" : \"Bar\",\n" + + " \"TransactionType\": \"CheckCreate\",\n" + + " \"Account\": \"rUn84CUYbNjRoTQ6mSW7BVJPSVJNLb1QLo\",\n" + + " \"Destination\": \"rfkE1aSy9G8Upk4JssnwBxhEv5p4mn2KTy\",\n" + + " \"SendMax\": \"100000000\",\n" + + " \"Expiration\": 570113521,\n" + + " \"InvoiceID\": \"6F1DFD1D0FE8A32E40E1F2C05CF1C15545BAB56B617F9C6C2D63A6B704BEF59B\",\n" + + " \"DestinationTag\": 1,\n" + + " \"Sequence\": 1,\n" + + " \"SigningPubKey\" : \"02356E89059A75438887F9FEE2056A2890DB82A68353BE9C0C0C8F89C0018B37FC\",\n" + + " \"NetworkID\": 1024,\n" + + " \"Fee\": \"12\"\n" + + "}"; + + assertCanSerializeAndDeserialize(checkCreate, json); + } } diff --git a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/EnableAmendmentJsonTests.java b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/EnableAmendmentJsonTests.java index 372360b7e..85486ade3 100644 --- a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/EnableAmendmentJsonTests.java +++ b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/EnableAmendmentJsonTests.java @@ -56,4 +56,28 @@ public void testJson() throws JsonProcessingException, JSONException { assertCanSerializeAndDeserialize(enableAmendment, json); } + + @Test + public void testJsonWithUnknownFields() throws JsonProcessingException, JSONException { + EnableAmendment enableAmendment = EnableAmendment.builder() + .account(Address.of("rrrrrrrrrrrrrrrrrrrrrhoLvTp")) + .fee(XrpCurrencyAmount.ofDrops(12)) + .sequence(UnsignedInteger.valueOf(2470665)) + .amendment(Hash256.of("42426C4D4F1009EE67080A9B7965B44656D7714D104A72F9B4369F97ABF044EE")) + .ledgerSequence(Optional.of(LedgerIndex.of(UnsignedInteger.valueOf(67850752)))) + .putUnknownFields("Foo", "Bar") + .build(); + + String json = "{" + + "\"Foo\" : \"Bar\",\n" + + "\"Account\":\"rrrrrrrrrrrrrrrrrrrrrhoLvTp\"," + + "\"Fee\":\"12\"," + + "\"LedgerSequence\":67850752," + + "\"Sequence\":2470665," + + "\"SigningPubKey\":\"\"," + + "\"TransactionType\":\"EnableAmendment\"," + + "\"Amendment\":\"42426C4D4F1009EE67080A9B7965B44656D7714D104A72F9B4369F97ABF044EE\"}"; + + assertCanSerializeAndDeserialize(enableAmendment, json); + } } diff --git a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/EscrowJsonTests.java b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/EscrowJsonTests.java index 6c7c39f87..c9b1b7aaa 100644 --- a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/EscrowJsonTests.java +++ b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/EscrowJsonTests.java @@ -166,6 +166,50 @@ public void testEscrowCreateJsonWithNonZeroFlags() assertCanSerializeAndDeserialize(escrowCreate, json); } + @Test + public void testEscrowCreateJsonWithUnknownFields() + throws JsonProcessingException, JSONException, DerEncodingException { + EscrowCreate escrowCreate = EscrowCreate.builder() + .account(Address.of("rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn")) + .fee(XrpCurrencyAmount.ofDrops(12)) + .sequence(UnsignedInteger.ONE) + .amount(XrpCurrencyAmount.ofDrops(10000)) + .destination(Address.of("rsA2LpzuawewSBQXkiju3YQTMzW13pAAdW")) + .destinationTag(UnsignedInteger.valueOf(23480)) + .cancelAfter(UnsignedLong.valueOf(533257958)) + .finishAfter(UnsignedLong.valueOf(533171558)) + .condition(CryptoConditionReader.readCondition( + BaseEncoding.base16() + .decode("A0258020E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855810100")) + ) + .sourceTag(UnsignedInteger.valueOf(11747)) + .signingPublicKey( + PublicKey.fromBase16EncodedPublicKey("02356E89059A75438887F9FEE2056A2890DB82A68353BE9C0C0C8F89C0018B37FC") + ) + .networkId(NetworkId.of(1024)) + .putUnknownFields("Foo", "Bar") + .build(); + + String json = "{\n" + + " \"Foo\" : \"Bar\",\n" + + " \"Account\": \"rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn\",\n" + + " \"TransactionType\": \"EscrowCreate\",\n" + + " \"Amount\": \"10000\",\n" + + " \"Destination\": \"rsA2LpzuawewSBQXkiju3YQTMzW13pAAdW\",\n" + + " \"CancelAfter\": 533257958,\n" + + " \"FinishAfter\": 533171558,\n" + + " \"Condition\": \"A0258020E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855810100\",\n" + + " \"DestinationTag\": 23480,\n" + + " \"SourceTag\": 11747,\n" + + " \"Sequence\": 1,\n" + + " \"SigningPubKey\" : \"02356E89059A75438887F9FEE2056A2890DB82A68353BE9C0C0C8F89C0018B37FC\",\n" + + " \"NetworkID\": 1024,\n" + + " \"Fee\": \"12\"\n" + + "}"; + + assertCanSerializeAndDeserialize(escrowCreate, json); + } + @Test public void testEscrowCancelJson() throws JsonProcessingException, JSONException { EscrowCancel escrowCancel = EscrowCancel.builder() @@ -247,6 +291,35 @@ public void testEscrowCancelJsonWithNonZeroFlags() throws JsonProcessingExceptio assertCanSerializeAndDeserialize(escrowCancel, json); } + @Test + public void testEscrowCancelJsonWithUnknownFields() throws JsonProcessingException, JSONException { + EscrowCancel escrowCancel = EscrowCancel.builder() + .account(Address.of("rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn")) + .fee(XrpCurrencyAmount.ofDrops(12)) + .sequence(UnsignedInteger.ONE) + .owner(Address.of("rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn")) + .offerSequence(UnsignedInteger.valueOf(7)) + .signingPublicKey( + PublicKey.fromBase16EncodedPublicKey("02356E89059A75438887F9FEE2056A2890DB82A68353BE9C0C0C8F89C0018B37FC") + ) + .networkId(NetworkId.of(1024)) + .putUnknownFields("Foo", "Bar") + .build(); + + String json = "{\n" + + " \"Foo\" : \"Bar\",\n" + + " \"Account\": \"rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn\",\n" + + " \"TransactionType\": \"EscrowCancel\",\n" + + " \"Owner\": \"rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn\",\n" + + " \"OfferSequence\": 7,\n" + + " \"Sequence\": 1,\n" + + " \"SigningPubKey\" : \"02356E89059A75438887F9FEE2056A2890DB82A68353BE9C0C0C8F89C0018B37FC\",\n" + + " \"NetworkID\": 1024,\n" + + " \"Fee\": \"12\"\n" + + "}"; + assertCanSerializeAndDeserialize(escrowCancel, json); + } + @Test public void testEscrowFinishJson() throws JsonProcessingException, JSONException, DerEncodingException { EscrowFinish escrowFinish = EscrowFinish.builder() @@ -393,4 +466,41 @@ void testEscrowFinishJsonWithMalformedFulfillment() throws JsonProcessingExcepti assertThat(escrowFinish.fulfillmentRawValue()).isNotEmpty().get() .isEqualTo("123"); } + + @Test + public void testEscrowFinishJsonWithUnknownFields() + throws JsonProcessingException, JSONException, DerEncodingException { + EscrowFinish escrowFinish = EscrowFinish.builder() + .account(Address.of("rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn")) + .fee(XrpCurrencyAmount.ofDrops(330)) + .sequence(UnsignedInteger.ONE) + .owner(Address.of("rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn")) + .offerSequence(UnsignedInteger.valueOf(7)) + .condition(CryptoConditionReader.readCondition(BaseEncoding.base16().decode( + "A0258020E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855810100")) + ) + .fulfillment(CryptoConditionReader.readFulfillment(BaseEncoding.base16().decode("A0028000"))) + .signingPublicKey( + PublicKey.fromBase16EncodedPublicKey("02356E89059A75438887F9FEE2056A2890DB82A68353BE9C0C0C8F89C0018B37FC") + ) + .networkId(NetworkId.of(1024)) + .putUnknownFields("Foo", "Bar") + .build(); + + String json = "{\n" + + " \"Foo\" : \"Bar\",\n" + + " \"Account\": \"rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn\",\n" + + " \"TransactionType\": \"EscrowFinish\",\n" + + " \"Owner\": \"rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn\",\n" + + " \"OfferSequence\": 7,\n" + + " \"Condition\": \"A0258020E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855810100\",\n" + + " \"Fulfillment\": \"A0028000\",\n" + + " \"Sequence\": 1,\n" + + " \"SigningPubKey\" : \"02356E89059A75438887F9FEE2056A2890DB82A68353BE9C0C0C8F89C0018B37FC\",\n" + + " \"NetworkID\": 1024,\n" + + " \"Fee\": \"330\"\n" + + "}"; + + assertCanSerializeAndDeserialize(escrowFinish, json); + } } diff --git a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/NfTokenAcceptOfferJsonTests.java b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/NfTokenAcceptOfferJsonTests.java index 0c4b82073..d9216d18f 100644 --- a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/NfTokenAcceptOfferJsonTests.java +++ b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/NfTokenAcceptOfferJsonTests.java @@ -156,4 +156,39 @@ public void testNfTokenAcceptOfferWithOnlyBuyOffer() throws JsonProcessingExcept assertCanSerializeAndDeserialize(nfTokenAcceptOffer, json); } + + @Test + public void testJsonWithUnknownFields() throws JsonProcessingException, JSONException { + + Hash256 offer = Hash256.of("000B013A95F14B0044F78A264E41713C64B5F89242540EE208C3098E00000D65"); + NfTokenAcceptOffer nfTokenAcceptOffer = NfTokenAcceptOffer.builder() + .fee(XrpCurrencyAmount.ofDrops(12)) + .account(Address.of("rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59Ba")) + .sequence(UnsignedInteger.valueOf(12)) + .brokerFee(XrpCurrencyAmount.ofDrops(10)) + .buyOffer(offer) + .sellOffer(offer) + .signingPublicKey( + PublicKey.fromBase16EncodedPublicKey("02356E89059A75438887F9FEE2056A2890DB82A68353BE9C0C0C8F89C0018B37FC") + ) + .networkId(NetworkId.of(1024)) + .putUnknownFields("Foo", "Bar") + .build(); + + String json = "{\n" + + " \"Foo\" : \"Bar\",\n" + + " \"TransactionType\": \"NFTokenAcceptOffer\",\n" + + " \"Account\": \"rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59Ba\",\n" + + " \"Fee\": \"12\",\n" + + " \"Sequence\": 12,\n" + + " \"NFTokenBuyOffer\": \"000B013A95F14B0044F78A264E41713C64B5F89242540EE208C3098E00000D65\",\n" + + " \"NFTokenSellOffer\": \"000B013A95F14B0044F78A264E41713C64B5F89242540EE208C3098E00000D65\",\n" + + " \"SigningPubKey\" : \"02356E89059A75438887F9FEE2056A2890DB82A68353BE9C0C0C8F89C0018B37FC\",\n" + + " \"NetworkID\": 1024,\n" + + " \"NFTokenBrokerFee\": \"10\"\n" + + "}"; + + assertCanSerializeAndDeserialize(nfTokenAcceptOffer, json); + } + } diff --git a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/NfTokenBurnJsonTests.java b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/NfTokenBurnJsonTests.java index 51d734f08..27bacd498 100644 --- a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/NfTokenBurnJsonTests.java +++ b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/NfTokenBurnJsonTests.java @@ -116,4 +116,34 @@ public void testNfTokenBurnJsonWithNonZeroFlags() throws JsonProcessingException assertCanSerializeAndDeserialize(nfTokenBurn, json); } + + @Test + public void testJsonWithUnknownFields() throws JsonProcessingException, JSONException { + + NfTokenId id = NfTokenId.of("000B013A95F14B0044F78A264E41713C64B5F89242540EE208C3098E00000D65"); + NfTokenBurn nfTokenBurn = NfTokenBurn.builder() + .fee(XrpCurrencyAmount.ofDrops(12)) + .account(Address.of("rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59Ba")) + .sequence(UnsignedInteger.valueOf(12)) + .nfTokenId(id) + .signingPublicKey( + PublicKey.fromBase16EncodedPublicKey("02356E89059A75438887F9FEE2056A2890DB82A68353BE9C0C0C8F89C0018B37FC") + ) + .networkId(NetworkId.of(1024)) + .putUnknownFields("Foo", "Bar") + .build(); + + String json = "{\n" + + " \"Foo\" : \"Bar\",\n" + + " \"TransactionType\": \"NFTokenBurn\",\n" + + " \"Account\": \"rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59Ba\",\n" + + " \"Fee\": \"12\",\n" + + " \"Sequence\": 12,\n" + + " \"NFTokenID\": \"000B013A95F14B0044F78A264E41713C64B5F89242540EE208C3098E00000D65\",\n" + + " \"NetworkID\": 1024,\n" + + " \"SigningPubKey\" : \"02356E89059A75438887F9FEE2056A2890DB82A68353BE9C0C0C8F89C0018B37FC\"\n" + + "}"; + + assertCanSerializeAndDeserialize(nfTokenBurn, json); + } } diff --git a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/NfTokenCancelOfferJsonTests.java b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/NfTokenCancelOfferJsonTests.java index 5bc21ef08..d4f1a02d4 100644 --- a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/NfTokenCancelOfferJsonTests.java +++ b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/NfTokenCancelOfferJsonTests.java @@ -130,4 +130,37 @@ public void testNfTokenCancelOfferJsonWithNonZeroFlags() throws JsonProcessingEx assertCanSerializeAndDeserialize(nfTokenCancelOffer, json); } + + @Test + public void testJsonWithUnknownFields() throws JsonProcessingException, JSONException { + Hash256 offer = Hash256.of("000B013A95F14B0044F78A264E41713C64B5F89242540EE208C3098E00000D65"); + List offers = new ArrayList<>(); + offers.add(offer); + NfTokenCancelOffer nfTokenCancelOffer = NfTokenCancelOffer.builder() + .account(Address.of("rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn")) + .fee(XrpCurrencyAmount.ofDrops(12)) + .sequence(UnsignedInteger.valueOf(12)) + .tokenOffers(offers) + .signingPublicKey( + PublicKey.fromBase16EncodedPublicKey("02356E89059A75438887F9FEE2056A2890DB82A68353BE9C0C0C8F89C0018B37FC") + ) + .networkId(NetworkId.of(1024)) + .putUnknownFields("Foo", "Bar") + .build(); + + String json = "{\n" + + " \"Foo\" : \"Bar\",\n" + + " \"TransactionType\": \"NFTokenCancelOffer\",\n" + + " \"Account\": \"rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn\",\n" + + " \"Fee\": \"12\",\n" + + " \"Sequence\": 12,\n" + + " \"NetworkID\": 1024,\n" + + " \"NFTokenOffers\": [" + + " \"000B013A95F14B0044F78A264E41713C64B5F89242540EE208C3098E00000D65\"" + + " ],\n" + + " \"SigningPubKey\" : \"02356E89059A75438887F9FEE2056A2890DB82A68353BE9C0C0C8F89C0018B37FC\"\n" + + "}"; + + assertCanSerializeAndDeserialize(nfTokenCancelOffer, json); + } } diff --git a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/NfTokenCreateOfferJsonTests.java b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/NfTokenCreateOfferJsonTests.java index 880cfa734..832a7ff3c 100644 --- a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/NfTokenCreateOfferJsonTests.java +++ b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/NfTokenCreateOfferJsonTests.java @@ -94,4 +94,36 @@ public void testJsonWithFlags() throws JsonProcessingException, JSONException { assertCanSerializeAndDeserialize(nfTokenCreateOffer, json); } + + @Test + public void testJsonWithUnknownFields() throws JsonProcessingException, JSONException { + + NfTokenId id = NfTokenId.of("000B013A95F14B0044F78A264E41713C64B5F89242540EE208C3098E00000D65"); + NfTokenCreateOffer nfTokenCreateOffer = NfTokenCreateOffer.builder() + .account(Address.of("rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn")) + .fee(XrpCurrencyAmount.ofDrops(12)) + .nfTokenId(id) + .sequence(UnsignedInteger.valueOf(12)) + .amount(XrpCurrencyAmount.ofDrops(2000L)) + .signingPublicKey( + PublicKey.fromBase16EncodedPublicKey("02356E89059A75438887F9FEE2056A2890DB82A68353BE9C0C0C8F89C0018B37FC") + ) + .networkId(NetworkId.of(1024)) + .putUnknownFields("Foo", "Bar") + .build(); + + String json = "{\n" + + " \"Foo\" : \"Bar\",\n" + + " \"TransactionType\": \"NFTokenCreateOffer\",\n" + + " \"Account\": \"rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn\",\n" + + " \"Fee\": \"12\",\n" + + " \"Sequence\": 12,\n" + + " \"Amount\": \"2000\",\n" + + " \"NetworkID\": 1024,\n" + + " \"NFTokenID\": \"000B013A95F14B0044F78A264E41713C64B5F89242540EE208C3098E00000D65\",\n" + + " \"SigningPubKey\" : \"02356E89059A75438887F9FEE2056A2890DB82A68353BE9C0C0C8F89C0018B37FC\"\n" + + "}"; + + assertCanSerializeAndDeserialize(nfTokenCreateOffer, json); + } } diff --git a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/NfTokenMintJsonTests.java b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/NfTokenMintJsonTests.java index 662baeb6c..f52801b0a 100644 --- a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/NfTokenMintJsonTests.java +++ b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/NfTokenMintJsonTests.java @@ -127,4 +127,38 @@ public void testMinimalNfTokenMintWithUriJson() throws JsonProcessingException, assertCanSerializeAndDeserialize(nfTokenMint, json); } + + @Test + public void testJsonWithUnknownFields() throws JsonProcessingException, JSONException { + NfTokenMint nfTokenMint = NfTokenMint.builder() + .fee(XrpCurrencyAmount.ofDrops(12)) + .account(Address.of("rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59Ba")) + .tokenTaxon(UnsignedLong.valueOf(146999694L)) + .sequence(UnsignedInteger.valueOf(12)) + .transferFee(TransferFee.of(UnsignedInteger.valueOf(1000))) + .flags(NfTokenMintFlags.builder() + .tfTransferable(true) + .build()) + .signingPublicKey( + PublicKey.fromBase16EncodedPublicKey("02356E89059A75438887F9FEE2056A2890DB82A68353BE9C0C0C8F89C0018B37FC") + ) + .networkId(NetworkId.of(1024)) + .putUnknownFields("Foo", "Bar") + .build(); + + String json = "{\n" + + " \"Foo\" : \"Bar\",\n" + + " \"TransactionType\": \"NFTokenMint\",\n" + + " \"Account\": \"rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59Ba\",\n" + + " \"Fee\": \"12\",\n" + + " \"Flags\": 2147483656,\n" + + " \"Sequence\": 12,\n" + + " \"TransferFee\": 1000,\n" + + " \"NetworkID\": 1024,\n" + + " \"SigningPubKey\" : \"02356E89059A75438887F9FEE2056A2890DB82A68353BE9C0C0C8F89C0018B37FC\",\n" + + " \"NFTokenTaxon\": 146999694\n" + + "}"; + + assertCanSerializeAndDeserialize(nfTokenMint, json); + } } diff --git a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/OfferJsonTests.java b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/OfferJsonTests.java index 6f7ec73b8..0d3ef0c9d 100644 --- a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/OfferJsonTests.java +++ b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/OfferJsonTests.java @@ -114,6 +114,34 @@ public void testOfferCancelJsonWithNonZeroFlags() throws JsonProcessingException assertCanSerializeAndDeserialize(offerCancel, json); } + @Test + public void testOfferCancelJsonWithUnknownFields() throws JsonProcessingException, JSONException { + OfferCancel offerCancel = OfferCancel.builder() + .account(Address.of("rUn84CUYbNjRoTQ6mSW7BVJPSVJNLb1QLo")) + .sequence(UnsignedInteger.valueOf(12)) + .offerSequence(UnsignedInteger.valueOf(13)) + .fee(XrpCurrencyAmount.ofDrops(14)) + .signingPublicKey( + PublicKey.fromBase16EncodedPublicKey("02356E89059A75438887F9FEE2056A2890DB82A68353BE9C0C0C8F89C0018B37FC") + ) + .networkId(NetworkId.of(1024)) + .putUnknownFields("Foo", "Bar") + .build(); + + String json = "{\n" + + " \"Foo\" : \"Bar\",\n" + + " \"Account\": \"rUn84CUYbNjRoTQ6mSW7BVJPSVJNLb1QLo\",\n" + + " \"TransactionType\": \"OfferCancel\",\n" + + " \"Sequence\": 12,\n" + + " \"OfferSequence\": 13,\n" + + " \"SigningPubKey\" : \"02356E89059A75438887F9FEE2056A2890DB82A68353BE9C0C0C8F89C0018B37FC\",\n" + + " \"NetworkID\": 1024,\n" + + " \"Fee\": \"14\"\n" + + "}"; + + assertCanSerializeAndDeserialize(offerCancel, json); + } + @Test public void testOfferCreateJson() throws JsonProcessingException, JSONException { OfferCreate offerCreate = OfferCreate.builder() @@ -178,4 +206,38 @@ public void testOfferCreateJsonWithFlags() throws JsonProcessingException, JSONE assertCanSerializeAndDeserialize(offerCreate, json); } + @Test + public void testOfferCreateJsonWithUnknownFields() throws JsonProcessingException, JSONException { + OfferCreate offerCreate = OfferCreate.builder() + .account(Address.of("rfkE1aSy9G8Upk4JssnwBxhEv5p4mn2KTy")) + .sequence(UnsignedInteger.ONE) + .fee(XrpCurrencyAmount.ofDrops(12)) + .offerSequence(UnsignedInteger.valueOf(13)) + .takerPays(XrpCurrencyAmount.ofDrops(14)) + .takerGets(XrpCurrencyAmount.ofDrops(15)) + .expiration(UnsignedInteger.valueOf(16)) + .signingPublicKey( + PublicKey.fromBase16EncodedPublicKey("02356E89059A75438887F9FEE2056A2890DB82A68353BE9C0C0C8F89C0018B37FC") + ) + .networkId(NetworkId.of(1024)) + .putUnknownFields("Foo", "Bar") + .build(); + + String json = "{\n" + + " \"Foo\" : \"Bar\",\n" + + " \"Account\": \"rfkE1aSy9G8Upk4JssnwBxhEv5p4mn2KTy\",\n" + + " \"TransactionType\": \"OfferCreate\",\n" + + " \"Sequence\": 1,\n" + + " \"OfferSequence\": 13,\n" + + " \"TakerPays\": \"14\",\n" + + " \"TakerGets\": \"15\",\n" + + " \"Fee\": \"12\",\n" + + " \"SigningPubKey\" : \"02356E89059A75438887F9FEE2056A2890DB82A68353BE9C0C0C8F89C0018B37FC\",\n" + + " \"NetworkID\": 1024,\n" + + " \"Expiration\": 16\n" + + "}"; + + assertCanSerializeAndDeserialize(offerCreate, json); + } + } diff --git a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/PaymentChannelJsonTests.java b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/PaymentChannelJsonTests.java index c0541fd10..251e65df8 100644 --- a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/PaymentChannelJsonTests.java +++ b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/PaymentChannelJsonTests.java @@ -153,6 +153,46 @@ public void testPaymentChannelCreateJsonWithNonZeroFlags() throws JsonProcessing assertCanSerializeAndDeserialize(create, json); } + @Test + public void testPaymentChannelCreateJsonWithUnknownFields() throws JsonProcessingException, JSONException { + PaymentChannelCreate create = PaymentChannelCreate.builder() + .account(Address.of("rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn")) + .sourceTag(UnsignedInteger.valueOf(11747)) + .fee(XrpCurrencyAmount.ofDrops(10)) + .sequence(UnsignedInteger.ONE) + .amount(XrpCurrencyAmount.ofDrops(10000)) + .destination(Address.of("rsA2LpzuawewSBQXkiju3YQTMzW13pAAdW")) + .destinationTag(UnsignedInteger.valueOf(23480)) + .settleDelay(UnsignedInteger.valueOf(86400)) + .publicKey("32D2471DB72B27E3310F355BB33E339BF26F8392D5A93D3BC0FC3B566612DA0F0A") + .cancelAfter(UnsignedLong.valueOf(533171558)) + .signingPublicKey( + PublicKey.fromBase16EncodedPublicKey("02356E89059A75438887F9FEE2056A2890DB82A68353BE9C0C0C8F89C0018B37FC") + ) + .networkId(NetworkId.of(1024)) + .putUnknownFields("Foo", "Bar") + .build(); + + String json = "{\n" + + " \"Foo\" : \"Bar\",\n" + + " \"Account\": \"rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn\",\n" + + " \"Fee\": \"10\",\n" + + " \"Sequence\": 1,\n" + + " \"TransactionType\": \"PaymentChannelCreate\",\n" + + " \"Amount\": \"10000\",\n" + + " \"Destination\": \"rsA2LpzuawewSBQXkiju3YQTMzW13pAAdW\",\n" + + " \"SettleDelay\": 86400,\n" + + " \"PublicKey\": \"32D2471DB72B27E3310F355BB33E339BF26F8392D5A93D3BC0FC3B566612DA0F0A\",\n" + + " \"CancelAfter\": 533171558,\n" + + " \"DestinationTag\": 23480,\n" + + " \"SigningPubKey\" : \"02356E89059A75438887F9FEE2056A2890DB82A68353BE9C0C0C8F89C0018B37FC\",\n" + + " \"NetworkID\": 1024,\n" + + " \"SourceTag\": 11747\n" + + "}"; + + assertCanSerializeAndDeserialize(create, json); + } + @Test public void testPaymentChannelClaimJson() throws JsonProcessingException, JSONException { PaymentChannelClaim claim = PaymentChannelClaim.builder() @@ -223,6 +263,43 @@ public void testPaymentChannelClaimJsonWithFlags() throws JsonProcessingExceptio assertCanSerializeAndDeserialize(claim, json); } + @Test + public void testPaymentChannelClaimJsonWithUnknownFields() throws JsonProcessingException, JSONException { + PaymentChannelClaim claim = PaymentChannelClaim.builder() + .account(Address.of("rsA2LpzuawewSBQXkiju3YQTMzW13pAAdW")) + .fee(XrpCurrencyAmount.ofDrops(10)) + .sequence(UnsignedInteger.ONE) + .channel(Hash256.of("C1AE6DDDEEC05CF2978C0BAD6FE302948E9533691DC749DCDD3B9E5992CA6198")) + .balance(XrpCurrencyAmount.ofDrops(1000000)) + .amount(XrpCurrencyAmount.ofDrops(1000000)) + .signature("30440220718D264EF05CAED7C781FF6DE298DCAC68D002562C9BF3A07C1E721B420C0DAB02203A5A4779E" + + "F4D2CCC7BC3EF886676D803A9981B928D3B8ACA483B80ECA3CD7B9B") + .publicKey("32D2471DB72B27E3310F355BB33E339BF26F8392D5A93D3BC0FC3B566612DA0F0A") + .signingPublicKey( + PublicKey.fromBase16EncodedPublicKey("02356E89059A75438887F9FEE2056A2890DB82A68353BE9C0C0C8F89C0018B37FC") + ) + .networkId(NetworkId.of(1024)) + .putUnknownFields("Foo", "Bar") + .build(); + + String json = "{\n" + + " \"Foo\" : \"Bar\",\n" + + " \"Account\": \"rsA2LpzuawewSBQXkiju3YQTMzW13pAAdW\",\n" + + " \"Fee\": \"10\",\n" + + " \"Sequence\": 1,\n" + + " \"TransactionType\": \"PaymentChannelClaim\",\n" + + " \"Channel\": \"C1AE6DDDEEC05CF2978C0BAD6FE302948E9533691DC749DCDD3B9E5992CA6198\",\n" + + " \"Balance\": \"1000000\",\n" + + " \"Amount\": \"1000000\",\n" + + " \"NetworkID\": 1024,\n" + + " \"Signature\": \"30440220718D264EF05CAED7C781FF6DE298DCAC68D002562C9BF3A07C1E721B420C0DAB02203A5A4" + + "779EF4D2CCC7BC3EF886676D803A9981B928D3B8ACA483B80ECA3CD7B9B\",\n" + + " \"SigningPubKey\" : \"02356E89059A75438887F9FEE2056A2890DB82A68353BE9C0C0C8F89C0018B37FC\",\n" + + " \"PublicKey\": \"32D2471DB72B27E3310F355BB33E339BF26F8392D5A93D3BC0FC3B566612DA0F0A\"\n" + + "}"; + assertCanSerializeAndDeserialize(claim, json); + } + @Test public void testPaymentChannelFundJson() throws JsonProcessingException, JSONException { PaymentChannelFund fund = PaymentChannelFund.builder() @@ -312,4 +389,36 @@ public void testPaymentChannelFundJsonWithNonZeroFlags() throws JsonProcessingEx assertCanSerializeAndDeserialize(fund, json); } + + @Test + public void testPaymentChannelFundJsonWithUnknownFields() throws JsonProcessingException, JSONException { + PaymentChannelFund fund = PaymentChannelFund.builder() + .account(Address.of("rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn")) + .fee(XrpCurrencyAmount.ofDrops(10)) + .sequence(UnsignedInteger.ONE) + .channel(Hash256.of("C1AE6DDDEEC05CF2978C0BAD6FE302948E9533691DC749DCDD3B9E5992CA6198")) + .amount(XrpCurrencyAmount.ofDrops(200000)) + .expiration(UnsignedLong.valueOf(543171558)) + .signingPublicKey( + PublicKey.fromBase16EncodedPublicKey("02356E89059A75438887F9FEE2056A2890DB82A68353BE9C0C0C8F89C0018B37FC") + ) + .networkId(NetworkId.of(1024)) + .putUnknownFields("Foo", "Bar") + .build(); + + String json = "{\n" + + " \"Foo\" : \"Bar\",\n" + + " \"Account\": \"rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn\",\n" + + " \"Fee\": \"10\",\n" + + " \"Sequence\": 1,\n" + + " \"TransactionType\": \"PaymentChannelFund\",\n" + + " \"Channel\": \"C1AE6DDDEEC05CF2978C0BAD6FE302948E9533691DC749DCDD3B9E5992CA6198\",\n" + + " \"Amount\": \"200000\",\n" + + " \"NetworkID\": 1024,\n" + + " \"SigningPubKey\" : \"02356E89059A75438887F9FEE2056A2890DB82A68353BE9C0C0C8F89C0018B37FC\",\n" + + " \"Expiration\": 543171558\n" + + "}"; + + assertCanSerializeAndDeserialize(fund, json); + } } diff --git a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/PaymentJsonTests.java b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/PaymentJsonTests.java index a5713e920..16b2f7543 100644 --- a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/PaymentJsonTests.java +++ b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/PaymentJsonTests.java @@ -157,4 +157,36 @@ public void testComplicatedJson() throws JsonProcessingException, JSONException assertCanSerializeAndDeserialize(payment, json); } + + @Test + public void testJsonWithUnknownFields() throws JsonProcessingException, JSONException { + Payment payment = Payment.builder() + .account(Address.of("r9TeThyi5xiuUUrFjtPKZiHcDxs7K9H6Rb")) + .destination(Address.of("r4BPgS7DHebQiU31xWELvZawwSG2fSPJ7C")) + .amount(XrpCurrencyAmount.ofDrops(25000000)) + .fee(XrpCurrencyAmount.ofDrops(10)) + .flags(PaymentFlags.UNSET) + .sequence(UnsignedInteger.valueOf(2)) + .signingPublicKey( + PublicKey.fromBase16EncodedPublicKey("02356E89059A75438887F9FEE2056A2890DB82A68353BE9C0C0C8F89C0018B37FC") + ) + .networkId(NetworkId.of(1024)) + .putUnknownFields("Foo", "Bar") + .build(); + + String json = "{\n" + + " \"Foo\" : \"Bar\",\n" + + " \"Account\": \"r9TeThyi5xiuUUrFjtPKZiHcDxs7K9H6Rb\",\n" + + " \"Destination\": \"r4BPgS7DHebQiU31xWELvZawwSG2fSPJ7C\",\n" + + " \"TransactionType\": \"Payment\",\n" + + " \"Amount\": \"25000000\",\n" + + " \"Fee\": \"10\",\n" + + " \"Flags\": 0,\n" + + " \"NetworkID\": 1024,\n" + + " \"SigningPubKey\" : \"02356E89059A75438887F9FEE2056A2890DB82A68353BE9C0C0C8F89C0018B37FC\",\n" + + " \"Sequence\": 2\n" + + " }"; + + assertCanSerializeAndDeserialize(payment, json); + } } diff --git a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/SetRegularKeyJsonTest.java b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/SetRegularKeyJsonTest.java index 54b8e5cd5..074f8984c 100644 --- a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/SetRegularKeyJsonTest.java +++ b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/SetRegularKeyJsonTest.java @@ -111,4 +111,32 @@ public void testSetRegularKeyJsonWithNonZeroFlags() throws JsonProcessingExcepti assertCanSerializeAndDeserialize(setRegularKey, json); } + + @Test + public void testJsonWithUnknownFields() throws JsonProcessingException, JSONException { + SetRegularKey setRegularKey = SetRegularKey.builder() + .account(Address.of("rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn")) + .fee(XrpCurrencyAmount.ofDrops(12)) + .sequence(UnsignedInteger.ONE) + .regularKey(Address.of("rAR8rR8sUkBoCZFawhkWzY4Y5YoyuznwD")) + .signingPublicKey( + PublicKey.fromBase16EncodedPublicKey("02356E89059A75438887F9FEE2056A2890DB82A68353BE9C0C0C8F89C0018B37FC") + ) + .networkId(NetworkId.of(1024)) + .putUnknownFields("Foo", "Bar") + .build(); + + String json = "{\n" + + " \"Foo\" : \"Bar\",\n" + + " \"Sequence\": 1,\n" + + " \"TransactionType\": \"SetRegularKey\",\n" + + " \"Account\": \"rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn\",\n" + + " \"Fee\": \"12\",\n" + + " \"SigningPubKey\" : \"02356E89059A75438887F9FEE2056A2890DB82A68353BE9C0C0C8F89C0018B37FC\",\n" + + " \"NetworkID\": 1024,\n" + + " \"RegularKey\": \"rAR8rR8sUkBoCZFawhkWzY4Y5YoyuznwD\"\n" + + "}"; + + assertCanSerializeAndDeserialize(setRegularKey, json); + } } diff --git a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/SignerListSetJsonTests.java b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/SignerListSetJsonTests.java index 749f60883..c59eef731 100644 --- a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/SignerListSetJsonTests.java +++ b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/SignerListSetJsonTests.java @@ -177,4 +177,34 @@ public void testSignerListSetJsonWithNonZeroFlags() throws JsonProcessingExcepti assertCanSerializeAndDeserialize(signerListSet, json); } + + @Test + public void testSignerListSetJsonWithNonZeroFlagstestJsonWithUnknownFields() + throws JsonProcessingException, JSONException { + SignerListSet signerListSet = SignerListSet.builder() + .account(Address.of("rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn")) + .fee(XrpCurrencyAmount.ofDrops(12)) + .sequence(UnsignedInteger.ONE) + .signerQuorum(UnsignedInteger.ZERO) + .signingPublicKey( + PublicKey.fromBase16EncodedPublicKey("02356E89059A75438887F9FEE2056A2890DB82A68353BE9C0C0C8F89C0018B37FC") + ) + .flags(TransactionFlags.FULLY_CANONICAL_SIG) + .putUnknownFields("Foo", "Bar") + .build(); + + String json = String.format("{\n" + + " \"Foo\" : \"Bar\",\n" + + " \"Sequence\": 1,\n" + + " \"TransactionType\": \"SignerListSet\",\n" + + " \"Account\": \"rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn\",\n" + + " \"Fee\": \"12\",\n" + + " \"Flags\": %s,\n" + + " \"SigningPubKey\" : \"02356E89059A75438887F9FEE2056A2890DB82A68353BE9C0C0C8F89C0018B37FC\",\n" + + " \"SignerQuorum\": 0\n" + + "}", TransactionFlags.FULLY_CANONICAL_SIG.getValue()); + + assertCanSerializeAndDeserialize(signerListSet, json); + } + } diff --git a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/TicketCreateJsonTest.java b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/TicketCreateJsonTest.java index 23403cc91..f7ea93204 100644 --- a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/TicketCreateJsonTest.java +++ b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/TicketCreateJsonTest.java @@ -111,4 +111,32 @@ void testJsonWithNonZeroFlags() throws JSONException, JsonProcessingException { assertCanSerializeAndDeserialize(ticketCreate, json); } + + @Test + void testJsonWithUnknownFields() throws JSONException, JsonProcessingException { + TicketCreate ticketCreate = TicketCreate.builder() + .account(Address.of("rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn")) + .fee(XrpCurrencyAmount.ofDrops(12)) + .sequence(UnsignedInteger.ONE) + .ticketCount(UnsignedInteger.valueOf(200)) + .signingPublicKey( + PublicKey.fromBase16EncodedPublicKey("02356E89059A75438887F9FEE2056A2890DB82A68353BE9C0C0C8F89C0018B37FC") + ) + .networkId(NetworkId.of(1024)) + .putUnknownFields("Foo", "Bar") + .build(); + + String json = "{\n" + + " \"Foo\" : \"Bar\",\n" + + " \"TransactionType\": \"TicketCreate\",\n" + + " \"Account\": \"rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn\",\n" + + " \"Fee\": \"12\",\n" + + " \"Sequence\": 1,\n" + + " \"NetworkID\": 1024,\n" + + " \"SigningPubKey\" : \"02356E89059A75438887F9FEE2056A2890DB82A68353BE9C0C0C8F89C0018B37FC\",\n" + + " \"TicketCount\": 200\n" + + "}"; + + assertCanSerializeAndDeserialize(ticketCreate, json); + } } diff --git a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/TrustSetJsonTests.java b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/TrustSetJsonTests.java index 157d93be4..09452f983 100644 --- a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/TrustSetJsonTests.java +++ b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/TrustSetJsonTests.java @@ -144,4 +144,44 @@ public void testTrustSetWithQualityJson() throws JsonProcessingException, JSONEx assertCanSerializeAndDeserialize(trustSet, json); } + + @Test + public void testJsonWithUnknownFields() throws JsonProcessingException, JSONException { + TrustSet trustSet = TrustSet.builder() + .account(Address.of("ra5nK24KXen9AHvsdFTKHSANinZseWnPcX")) + .fee(XrpCurrencyAmount.ofDrops(12)) + .flags(TrustSetFlags.builder() + .tfClearNoRipple() + .build()) + .sequence(UnsignedInteger.valueOf(12)) + .limitAmount(IssuedCurrencyAmount.builder() + .currency("USD") + .issuer(Address.of("rsP3mgGb2tcYUrxiLFiHJiQXhsziegtwBc")) + .value("100") + .build()) + .signingPublicKey( + PublicKey.fromBase16EncodedPublicKey("02356E89059A75438887F9FEE2056A2890DB82A68353BE9C0C0C8F89C0018B37FC") + ) + .networkId(NetworkId.of(1024)) + .putUnknownFields("Foo", "Bar") + .build(); + + String json = "{\n" + + " \"Foo\" : \"Bar\",\n" + + " \"TransactionType\": \"TrustSet\",\n" + + " \"Account\": \"ra5nK24KXen9AHvsdFTKHSANinZseWnPcX\",\n" + + " \"Fee\": \"12\",\n" + + " \"Flags\": 2147745792,\n" + + " \"SigningPubKey\" : \"02356E89059A75438887F9FEE2056A2890DB82A68353BE9C0C0C8F89C0018B37FC\",\n" + + " \"LimitAmount\": {\n" + + " \"currency\": \"USD\",\n" + + " \"issuer\": \"rsP3mgGb2tcYUrxiLFiHJiQXhsziegtwBc\",\n" + + " \"value\": \"100\"\n" + + " },\n" + + " \"NetworkID\": 1024,\n" + + " \"Sequence\": 12\n" + + "}"; + + assertCanSerializeAndDeserialize(trustSet, json); + } } diff --git a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/UnlModifyJsonTests.java b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/UnlModifyJsonTests.java index 3b9646413..3226642b2 100644 --- a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/UnlModifyJsonTests.java +++ b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/UnlModifyJsonTests.java @@ -20,12 +20,15 @@ * =========================LICENSE_END================================== */ +import static org.assertj.core.api.Assertions.assertThat; + import com.fasterxml.jackson.core.JsonProcessingException; import com.google.common.primitives.UnsignedInteger; import org.json.JSONException; import org.junit.jupiter.api.Test; import org.xrpl.xrpl4j.model.AbstractJsonTest; import org.xrpl.xrpl4j.model.client.common.LedgerIndex; +import org.xrpl.xrpl4j.model.transactions.Transaction; import org.xrpl.xrpl4j.model.transactions.UnlModify; import org.xrpl.xrpl4j.model.transactions.XrpCurrencyAmount;