Skip to content

Commit

Permalink
Make all tests go fast
Browse files Browse the repository at this point in the history
  • Loading branch information
sappenin committed Nov 27, 2024
1 parent 502be9e commit 8c4d11d
Show file tree
Hide file tree
Showing 17 changed files with 379 additions and 207 deletions.
20 changes: 15 additions & 5 deletions xrpl4j-client/src/main/java/org/xrpl/xrpl4j/client/XrplClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -287,15 +287,18 @@ protected Optional<? extends TransactionResult<? extends Transaction>> getValida
* Check if there missing ledgers in rippled in the given range.
*
* @param submittedLedgerSequence {@link LedgerIndex} at which the {@link Transaction} was submitted on.
* @param lastLedgerSequence he ledger index/sequence of type {@link UnsignedInteger} after which the transaction
* will expire and won't be applied to the ledger.
* @param lastLedgerSequence The ledger index/sequence of type {@link UnsignedInteger} after which the
* transaction will expire and won't be applied to the ledger.
*
* @return {@link Boolean} to indicate if there are gaps in the ledger range.
*/
protected boolean ledgerGapsExistBetween(
final UnsignedLong submittedLedgerSequence,
final UnsignedLong lastLedgerSequence
UnsignedLong lastLedgerSequence
) {
Objects.requireNonNull(submittedLedgerSequence);
Objects.requireNonNull(lastLedgerSequence);

final ServerInfoResult serverInfo;
try {
serverInfo = this.serverInformation();
Expand All @@ -304,6 +307,11 @@ protected boolean ledgerGapsExistBetween(
return true; // Assume ledger gaps exist so this can be retried.
}

// Clamp the lastLedgerSequence to be at least as large as submittedLedgerSequence
if (FluentCompareTo.is(lastLedgerSequence).lessThan(submittedLedgerSequence)) {
lastLedgerSequence = submittedLedgerSequence;
}

Range<UnsignedLong> submittedToLast = Range.closed(submittedLedgerSequence, lastLedgerSequence);
return serverInfo.info().completeLedgers().stream()
.noneMatch(range -> range.encloses(submittedToLast));
Expand Down Expand Up @@ -369,8 +377,10 @@ public Finality isFinal(
LOGGER.debug("Transaction with hash: {} has not expired yet, check again", transactionHash);
return Finality.builder().finalityStatus(FinalityStatus.NOT_FINAL).build();
} else {
boolean isMissingLedgers = ledgerGapsExistBetween(UnsignedLong.valueOf(submittedOnLedgerIndex.toString()),
UnsignedLong.valueOf(lastLedgerSequence.toString()));
boolean isMissingLedgers = ledgerGapsExistBetween(
UnsignedLong.valueOf(submittedOnLedgerIndex.toString()),
UnsignedLong.valueOf(lastLedgerSequence.toString())
);
if (isMissingLedgers) {
LOGGER.debug("Transaction with hash: {} has expired and rippled is missing some to confirm if it" +
" was validated", transactionHash);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
public abstract class AbstractIT {

public static final Duration POLL_INTERVAL = Durations.ONE_HUNDRED_MILLISECONDS;

public static final Duration AT_MOST_INTERVAL = Duration.of(50, ChronoUnit.SECONDS);
public static final String SUCCESS_STATUS = TransactionResultCodes.TES_SUCCESS;

protected static XrplEnvironment xrplEnvironment = XrplEnvironment.getNewConfiguredEnvironment();
Expand Down Expand Up @@ -246,7 +246,7 @@ protected Finality scanForFinality(
) {
return given()
.pollInterval(POLL_INTERVAL)
.atMost(Durations.ONE_MINUTE.dividedBy(2))
.atMost(AT_MOST_INTERVAL)
.ignoreException(RuntimeException.class)
.await()
.until(
Expand All @@ -269,7 +269,7 @@ protected Finality scanForFinality(

protected <T> T scanForResult(Supplier<T> resultSupplier, Predicate<T> condition) {
return given()
.atMost(Duration.of(30, ChronoUnit.SECONDS))
.atMost(AT_MOST_INTERVAL)
.pollInterval(POLL_INTERVAL)
.await()
.until(() -> {
Expand All @@ -285,7 +285,7 @@ protected <T extends XrplResult> T scanForResult(Supplier<T> resultSupplier) {
Objects.requireNonNull(resultSupplier);
return given()
.pollInterval(POLL_INTERVAL)
.atMost(Duration.of(30, ChronoUnit.SECONDS))
.atMost(AT_MOST_INTERVAL)
.ignoreException(RuntimeException.class)
.await()
.until(resultSupplier::get, is(notNullValue()));
Expand All @@ -295,7 +295,7 @@ protected <T extends LedgerObject> T scanForLedgerObject(Supplier<T> ledgerObjec
Objects.requireNonNull(ledgerObjectSupplier);
return given()
.pollInterval(POLL_INTERVAL)
.atMost(Duration.of(30, ChronoUnit.SECONDS))
.atMost(AT_MOST_INTERVAL)
.ignoreException(RuntimeException.class)
.await()
.until(ledgerObjectSupplier::get, is(notNullValue()));
Expand Down Expand Up @@ -723,7 +723,7 @@ protected Instant getMinExpirationTime() {
Instant now = Instant.now();
return closeTime.isBefore(now) ? now : closeTime;
}

private void logAccountCreation(Address address) {
logger.info("Generated wallet with ClassicAddress={})", address);
}
Expand Down
Loading

0 comments on commit 8c4d11d

Please sign in to comment.