Skip to content

Commit f61750f

Browse files
authored
Fix broken automation tests (#582)
* 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
1 parent 9cc99a3 commit f61750f

20 files changed

+609
-274
lines changed

xrpl4j-client/src/main/java/org/xrpl/xrpl4j/client/XrplClient.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -287,15 +287,18 @@ protected Optional<? extends TransactionResult<? extends Transaction>> getValida
287287
* Check if there missing ledgers in rippled in the given range.
288288
*
289289
* @param submittedLedgerSequence {@link LedgerIndex} at which the {@link Transaction} was submitted on.
290-
* @param lastLedgerSequence he ledger index/sequence of type {@link UnsignedInteger} after which the transaction
291-
* will expire and won't be applied to the ledger.
290+
* @param lastLedgerSequence The ledger index/sequence of type {@link UnsignedInteger} after which the
291+
* transaction will expire and won't be applied to the ledger.
292292
*
293293
* @return {@link Boolean} to indicate if there are gaps in the ledger range.
294294
*/
295295
protected boolean ledgerGapsExistBetween(
296296
final UnsignedLong submittedLedgerSequence,
297-
final UnsignedLong lastLedgerSequence
297+
UnsignedLong lastLedgerSequence
298298
) {
299+
Objects.requireNonNull(submittedLedgerSequence);
300+
Objects.requireNonNull(lastLedgerSequence);
301+
299302
final ServerInfoResult serverInfo;
300303
try {
301304
serverInfo = this.serverInformation();
@@ -304,6 +307,11 @@ protected boolean ledgerGapsExistBetween(
304307
return true; // Assume ledger gaps exist so this can be retried.
305308
}
306309

310+
// Ensure the lastLedgerSequence is (at least) as large as submittedLedgerSequence
311+
if (FluentCompareTo.is(lastLedgerSequence).lessThan(submittedLedgerSequence)) {
312+
lastLedgerSequence = submittedLedgerSequence;
313+
}
314+
307315
Range<UnsignedLong> submittedToLast = Range.closed(submittedLedgerSequence, lastLedgerSequence);
308316
return serverInfo.info().completeLedgers().stream()
309317
.noneMatch(range -> range.encloses(submittedToLast));
@@ -369,8 +377,10 @@ public Finality isFinal(
369377
LOGGER.debug("Transaction with hash: {} has not expired yet, check again", transactionHash);
370378
return Finality.builder().finalityStatus(FinalityStatus.NOT_FINAL).build();
371379
} else {
372-
boolean isMissingLedgers = ledgerGapsExistBetween(UnsignedLong.valueOf(submittedOnLedgerIndex.toString()),
373-
UnsignedLong.valueOf(lastLedgerSequence.toString()));
380+
boolean isMissingLedgers = ledgerGapsExistBetween(
381+
UnsignedLong.valueOf(submittedOnLedgerIndex.toString()),
382+
UnsignedLong.valueOf(lastLedgerSequence.toString())
383+
);
374384
if (isMissingLedgers) {
375385
LOGGER.debug("Transaction with hash: {} has expired and rippled is missing some to confirm if it" +
376386
" was validated", transactionHash);

xrpl4j-integration-tests/src/test/java/org/xrpl/xrpl4j/tests/AbstractIT.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
import java.security.KeyStore;
8686
import java.time.Duration;
8787
import java.time.Instant;
88+
import java.time.temporal.ChronoUnit;
8889
import java.util.List;
8990
import java.util.Objects;
9091
import java.util.UUID;
@@ -98,10 +99,10 @@
9899
public abstract class AbstractIT {
99100

100101
public static final Duration POLL_INTERVAL = Durations.ONE_HUNDRED_MILLISECONDS;
101-
102+
public static final Duration AT_MOST_INTERVAL = Duration.of(30, ChronoUnit.SECONDS);
102103
public static final String SUCCESS_STATUS = TransactionResultCodes.TES_SUCCESS;
103104

104-
protected static XrplEnvironment xrplEnvironment = XrplEnvironment.getConfiguredEnvironment();
105+
protected static XrplEnvironment xrplEnvironment = XrplEnvironment.getNewConfiguredEnvironment();
105106

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

@@ -245,7 +246,7 @@ protected Finality scanForFinality(
245246
) {
246247
return given()
247248
.pollInterval(POLL_INTERVAL)
248-
.atMost(Durations.ONE_MINUTE.dividedBy(2))
249+
.atMost(AT_MOST_INTERVAL)
249250
.ignoreException(RuntimeException.class)
250251
.await()
251252
.until(
@@ -268,7 +269,7 @@ protected Finality scanForFinality(
268269

269270
protected <T> T scanForResult(Supplier<T> resultSupplier, Predicate<T> condition) {
270271
return given()
271-
.atMost(Durations.ONE_MINUTE.dividedBy(2))
272+
.atMost(AT_MOST_INTERVAL)
272273
.pollInterval(POLL_INTERVAL)
273274
.await()
274275
.until(() -> {
@@ -284,7 +285,7 @@ protected <T extends XrplResult> T scanForResult(Supplier<T> resultSupplier) {
284285
Objects.requireNonNull(resultSupplier);
285286
return given()
286287
.pollInterval(POLL_INTERVAL)
287-
.atMost(Durations.ONE_MINUTE.dividedBy(2))
288+
.atMost(AT_MOST_INTERVAL)
288289
.ignoreException(RuntimeException.class)
289290
.await()
290291
.until(resultSupplier::get, is(notNullValue()));
@@ -294,7 +295,7 @@ protected <T extends LedgerObject> T scanForLedgerObject(Supplier<T> ledgerObjec
294295
Objects.requireNonNull(ledgerObjectSupplier);
295296
return given()
296297
.pollInterval(POLL_INTERVAL)
297-
.atMost(Durations.ONE_MINUTE.dividedBy(2))
298+
.atMost(AT_MOST_INTERVAL)
298299
.ignoreException(RuntimeException.class)
299300
.await()
300301
.until(ledgerObjectSupplier::get, is(notNullValue()));
@@ -722,7 +723,7 @@ protected Instant getMinExpirationTime() {
722723
Instant now = Instant.now();
723724
return closeTime.isBefore(now) ? now : closeTime;
724725
}
725-
726+
726727
private void logAccountCreation(Address address) {
727728
logger.info("Generated wallet with ClassicAddress={})", address);
728729
}

0 commit comments

Comments
 (0)