-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(BREAKING CHANGE) Make fields in LedgerResult and LedgerHeader Option…
…al (#91) * Make LedgerHeader.closeTimeHuman and LedgerHeader.parentCloseTime optional. Make LedgerResult.ledgerHash and LedgerResult.ledgerIndex optional. Add LedgerResult.ledgerCurrentIndex for current ledgers. Add a LedgerResult IT and an extra JSON test. * test LedgerIndex and ser/deser
- Loading branch information
Showing
11 changed files
with
267 additions
and
11 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
xrpl4j-integration-tests/src/test/java/org/xrpl/xrpl4j/tests/LedgerResultIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package org.xrpl.xrpl4j.tests; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.xrpl.xrpl4j.client.JsonRpcClientErrorException; | ||
import org.xrpl.xrpl4j.model.client.common.LedgerIndex; | ||
import org.xrpl.xrpl4j.model.client.ledger.LedgerRequestParams; | ||
import org.xrpl.xrpl4j.model.client.ledger.LedgerResult; | ||
|
||
/** | ||
* These tests ensure {@link LedgerResult}s can be constructed from all of the different JSON responses | ||
* rippled sends back. | ||
*/ | ||
public class LedgerResultIT extends AbstractIT { | ||
|
||
@Test | ||
void getValidatedLedgerResult() throws JsonRpcClientErrorException { | ||
final LedgerResult ledgerResult = xrplClient.ledger(LedgerRequestParams.builder() | ||
.ledgerIndex(LedgerIndex.VALIDATED) | ||
.build()); | ||
assertThat(ledgerResult.ledgerIndex()).isNotEmpty(); | ||
assertThat(ledgerResult.ledgerHash()).isNotEmpty(); | ||
assertThat(ledgerResult.ledgerCurrentIndex()).isEmpty(); | ||
assertThat(ledgerResult.ledger().closeTimeHuman()).isNotEmpty(); | ||
assertThat(ledgerResult.ledger().parentCloseTime()).isNotEmpty(); | ||
} | ||
|
||
@Test | ||
void getCurrentLedgerResult() throws JsonRpcClientErrorException { | ||
final LedgerResult ledgerResult = xrplClient.ledger(LedgerRequestParams.builder() | ||
.ledgerIndex(LedgerIndex.CURRENT) | ||
.build()); | ||
assertThat(ledgerResult.ledgerIndex()).isEmpty(); | ||
assertThat(ledgerResult.ledgerHash()).isEmpty(); | ||
assertThat(ledgerResult.ledgerCurrentIndex()).isNotEmpty(); | ||
assertThat(ledgerResult.ledger().closeTimeHuman()).isEmpty(); | ||
assertThat(ledgerResult.ledger().parentCloseTime()).isEmpty(); | ||
} | ||
|
||
@Test | ||
void getClosedLedgerResult() throws JsonRpcClientErrorException { | ||
final LedgerResult ledgerResult = xrplClient.ledger(LedgerRequestParams.builder() | ||
.ledgerIndex(LedgerIndex.CLOSED) | ||
.build()); | ||
assertThat(ledgerResult.ledgerIndex()).isNotEmpty(); | ||
assertThat(ledgerResult.ledgerHash()).isNotEmpty(); | ||
assertThat(ledgerResult.ledgerCurrentIndex()).isEmpty(); | ||
assertThat(ledgerResult.ledger().closeTimeHuman()).isNotEmpty(); | ||
assertThat(ledgerResult.ledger().parentCloseTime()).isNotEmpty(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
xrpl4j-model/src/test/java/org/xrpl/xrpl4j/model/client/common/LedgerIndexTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package org.xrpl.xrpl4j.model.client.common; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import com.google.common.primitives.UnsignedLong; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class LedgerIndexTest { | ||
|
||
@Test | ||
void createValidNumericalLedgerIndex() { | ||
LedgerIndex ledgerIndex = LedgerIndex.of("1"); | ||
assertThat(ledgerIndex.value()).isEqualTo("1"); | ||
|
||
final LedgerIndex fromUnsignedLong = LedgerIndex.of(UnsignedLong.ONE); | ||
assertThat(ledgerIndex).isEqualTo(fromUnsignedLong); | ||
|
||
UnsignedLong unsignedLongFromString = ledgerIndex.unsignedLongValue(); | ||
UnsignedLong unsignedLongFromUnsignedLong = fromUnsignedLong.unsignedLongValue(); | ||
assertThat(unsignedLongFromString).isEqualTo(unsignedLongFromUnsignedLong); | ||
|
||
final LedgerIndex added = ledgerIndex.plus(fromUnsignedLong); | ||
assertThat(added).isEqualTo(LedgerIndex.of("2")); | ||
} | ||
|
||
@Test | ||
void createInvalidNumericalLedgerIndex() { | ||
final LedgerIndex fooLedgerIndex = LedgerIndex.of("foo"); | ||
assertThrows( | ||
NumberFormatException.class, | ||
fooLedgerIndex::unsignedLongValue | ||
); | ||
|
||
final LedgerIndex negativeLedgerIndex = LedgerIndex.of("-1"); | ||
assertThrows( | ||
NumberFormatException.class, | ||
negativeLedgerIndex::unsignedLongValue | ||
); | ||
|
||
assertThrows( | ||
NumberFormatException.class, | ||
() -> fooLedgerIndex.plus(negativeLedgerIndex) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...4j-model/src/test/java/org/xrpl/xrpl4j/model/jackson/modules/AbstractLedgerIndexTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.xrpl.xrpl4j.model.jackson.modules; | ||
|
||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
import com.fasterxml.jackson.databind.annotation.JsonSerialize; | ||
import org.immutables.value.Value; | ||
import org.xrpl.xrpl4j.model.client.common.LedgerIndex; | ||
|
||
public class AbstractLedgerIndexTest { | ||
|
||
@Value.Immutable | ||
@JsonSerialize(as = ImmutableLedgerIndexContainer.class) | ||
@JsonDeserialize(as = ImmutableLedgerIndexContainer.class) | ||
interface LedgerIndexContainer { | ||
|
||
static LedgerIndexContainer of(LedgerIndex ledgerIndex) { | ||
return ImmutableLedgerIndexContainer.builder() | ||
.ledgerIndex(ledgerIndex) | ||
.build(); | ||
} | ||
|
||
LedgerIndex ledgerIndex(); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...odel/src/test/java/org/xrpl/xrpl4j/model/jackson/modules/LedgerIndexDeserializerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package org.xrpl.xrpl4j.model.jackson.modules; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.junit.jupiter.api.Test; | ||
import org.xrpl.xrpl4j.model.client.common.LedgerIndex; | ||
import org.xrpl.xrpl4j.model.jackson.ObjectMapperFactory; | ||
|
||
class LedgerIndexDeserializerTest extends AbstractLedgerIndexTest { | ||
|
||
private final ObjectMapper objectMapper = ObjectMapperFactory.create(); | ||
|
||
@Test | ||
void deserializeCharacterLedgerIndex() throws JsonProcessingException { | ||
final LedgerIndex current = LedgerIndex.CURRENT; | ||
final LedgerIndex validated = LedgerIndex.VALIDATED; | ||
final LedgerIndex closed = LedgerIndex.CLOSED; | ||
final LedgerIndex foo = LedgerIndex.of("foo"); | ||
|
||
final LedgerIndex currentDeserialized = objectMapper.readValue("\"" + current.value() + "\"", LedgerIndex.class); | ||
assertThat(currentDeserialized).isEqualTo(current); | ||
|
||
final LedgerIndex validatedDeserialized = objectMapper.readValue("\"" + validated.value() + "\"", LedgerIndex.class); | ||
assertThat(validatedDeserialized).isEqualTo(validated); | ||
|
||
final LedgerIndex closedDeserialized = objectMapper.readValue("\"" + closed.value() + "\"", LedgerIndex.class); | ||
assertThat(closedDeserialized).isEqualTo(closed); | ||
|
||
final LedgerIndex fooDeserialized = objectMapper.readValue("\"" + foo.value() + "\"", LedgerIndex.class); | ||
assertThat(fooDeserialized).isEqualTo(foo); | ||
} | ||
|
||
@Test | ||
void deserializeNumericalLedgerIndex() throws JsonProcessingException { | ||
final LedgerIndex ledgerIndex = LedgerIndex.of("1"); | ||
|
||
final LedgerIndex deserialized = objectMapper.readValue("\"1\"", LedgerIndex.class); | ||
assertThat(deserialized).isEqualTo(ledgerIndex); | ||
|
||
LedgerIndexContainer container = LedgerIndexContainer.of(ledgerIndex); | ||
final LedgerIndexContainer deserializedContainer = objectMapper.readValue("{\"ledgerIndex\": 1}", LedgerIndexContainer.class); | ||
assertThat(deserializedContainer).isEqualTo(container); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...-model/src/test/java/org/xrpl/xrpl4j/model/jackson/modules/LedgerIndexSerializerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package org.xrpl.xrpl4j.model.jackson.modules; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.google.common.primitives.UnsignedLong; | ||
import org.junit.jupiter.api.Test; | ||
import org.xrpl.xrpl4j.model.client.common.LedgerIndex; | ||
import org.xrpl.xrpl4j.model.jackson.ObjectMapperFactory; | ||
|
||
class LedgerIndexSerializerTest extends AbstractLedgerIndexTest { | ||
|
||
private final ObjectMapper objectMapper = ObjectMapperFactory.create(); | ||
|
||
@Test | ||
void serializeCharacterLedgerIndex() throws JsonProcessingException { | ||
final LedgerIndex current = LedgerIndex.CURRENT; | ||
final LedgerIndex validated = LedgerIndex.VALIDATED; | ||
final LedgerIndex closed = LedgerIndex.CLOSED; | ||
final LedgerIndex foo = LedgerIndex.of("foo"); | ||
|
||
final String currentSerialized = objectMapper.writeValueAsString(current); | ||
assertThat(currentSerialized).isEqualTo("\"" + current.value() + "\""); | ||
|
||
final String validatedSerialized = objectMapper.writeValueAsString(validated); | ||
assertThat(validatedSerialized).isEqualTo("\"" + validated.value() + "\""); | ||
|
||
final String closedSerialized = objectMapper.writeValueAsString(closed); | ||
assertThat(closedSerialized).isEqualTo("\"" + closed.value() + "\""); | ||
|
||
final String fooSerialized = objectMapper.writeValueAsString(foo); | ||
assertThat(fooSerialized).isEqualTo("\"" + foo.value() + "\""); | ||
} | ||
|
||
@Test | ||
void serializeNumericalLedgerIndex() throws JsonProcessingException { | ||
final LedgerIndexContainer fromUnsignedLong = LedgerIndexContainer.of(LedgerIndex.of(UnsignedLong.ONE)); | ||
final LedgerIndexContainer fromString = LedgerIndexContainer.of(LedgerIndex.of("1")); | ||
|
||
final String serializedFromUnsignedLong = objectMapper.writeValueAsString(fromUnsignedLong); | ||
assertThat(serializedFromUnsignedLong).isEqualTo("{\"ledgerIndex\":1}"); | ||
|
||
final String serializedFromString = objectMapper.writeValueAsString(fromString); | ||
assertThat(serializedFromString).isEqualTo("{\"ledgerIndex\":1}"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters