Skip to content

Commit

Permalink
Fix broken automation tests (#582)
Browse files Browse the repository at this point in the history
* Add waitForLedgerTimeToSync()
* Remove new environment call
* Make all tests go fast
* Fix IsFinalITs
* Tightly control AccountDelete
* Tightly control ledger accepts for PriceOracle
* Fix time lookup to use ledger time instead of Clock time
* Fix AT_MOST interval to leave time for real networks
* Fix checkstyle
* Misc Cleanup
  • Loading branch information
sappenin authored Dec 12, 2024
1 parent 9cc99a3 commit f61750f
Show file tree
Hide file tree
Showing 20 changed files with 609 additions and 274 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.
}

// Ensure the lastLedgerSequence is (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 @@ -85,6 +85,7 @@
import java.security.KeyStore;
import java.time.Duration;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
Expand All @@ -98,10 +99,10 @@
public abstract class AbstractIT {

public static final Duration POLL_INTERVAL = Durations.ONE_HUNDRED_MILLISECONDS;

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

protected static XrplEnvironment xrplEnvironment = XrplEnvironment.getConfiguredEnvironment();
protected static XrplEnvironment xrplEnvironment = XrplEnvironment.getNewConfiguredEnvironment();

protected final Logger logger = LoggerFactory.getLogger(this.getClass());

Expand Down Expand Up @@ -245,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 @@ -268,7 +269,7 @@ protected Finality scanForFinality(

protected <T> T scanForResult(Supplier<T> resultSupplier, Predicate<T> condition) {
return given()
.atMost(Durations.ONE_MINUTE.dividedBy(2))
.atMost(AT_MOST_INTERVAL)
.pollInterval(POLL_INTERVAL)
.await()
.until(() -> {
Expand All @@ -284,7 +285,7 @@ protected <T extends XrplResult> T scanForResult(Supplier<T> resultSupplier) {
Objects.requireNonNull(resultSupplier);
return given()
.pollInterval(POLL_INTERVAL)
.atMost(Durations.ONE_MINUTE.dividedBy(2))
.atMost(AT_MOST_INTERVAL)
.ignoreException(RuntimeException.class)
.await()
.until(resultSupplier::get, is(notNullValue()));
Expand All @@ -294,7 +295,7 @@ protected <T extends LedgerObject> T scanForLedgerObject(Supplier<T> ledgerObjec
Objects.requireNonNull(ledgerObjectSupplier);
return given()
.pollInterval(POLL_INTERVAL)
.atMost(Durations.ONE_MINUTE.dividedBy(2))
.atMost(AT_MOST_INTERVAL)
.ignoreException(RuntimeException.class)
.await()
.until(ledgerObjectSupplier::get, is(notNullValue()));
Expand Down Expand Up @@ -722,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 f61750f

Please sign in to comment.