Skip to content

Commit

Permalink
instead of Thread.sleep, use scanForResult to get correct results (#…
Browse files Browse the repository at this point in the history
…301)

instead of thread.sleep, use scan for result to get genuine results
  • Loading branch information
mukulljangid authored Sep 6, 2022
1 parent 4ef7e7c commit 4255c50
Showing 1 changed file with 29 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import org.xrpl.xrpl4j.model.client.fees.FeeUtils;
import org.xrpl.xrpl4j.model.client.ledger.LedgerRequestParams;
import org.xrpl.xrpl4j.model.client.transactions.SubmitResult;
import org.xrpl.xrpl4j.model.immutables.FluentCompareTo;
import org.xrpl.xrpl4j.model.transactions.Hash256;
import org.xrpl.xrpl4j.model.transactions.ImmutablePayment;
import org.xrpl.xrpl4j.model.transactions.IssuedCurrencyAmount;
import org.xrpl.xrpl4j.model.transactions.Payment;
Expand Down Expand Up @@ -61,25 +63,30 @@ void setup() throws JsonRpcClientErrorException {
}

@Test
public void simpleIsFinalTest() throws JsonRpcClientErrorException, InterruptedException {
public void simpleIsFinalTest() throws JsonRpcClientErrorException {

Payment builtPayment = payment.build();
SubmitResult response = xrplClient.submit(wallet, builtPayment);
assertThat(response.result()).isEqualTo("tesSUCCESS");
Hash256 txHash = response.transactionResult().hash();

assertThat(
xrplClient.isFinal(
response.transactionResult().hash(),
txHash,
response.validatedLedgerIndex(),
lastLedgerSequence,
accountInfo.accountData().sequence(),
wallet.classicAddress()
).finalityStatus()
).isEqualTo(FinalityStatus.NOT_FINAL);
Thread.sleep(4000);

this.scanForResult(
() -> getValidatedTransaction(txHash, Payment.class)
);

assertThat(
xrplClient.isFinal(
response.transactionResult().hash(),
txHash,
response.validatedLedgerIndex(),
lastLedgerSequence,
accountInfo.accountData().sequence(),
Expand All @@ -89,27 +96,33 @@ public void simpleIsFinalTest() throws JsonRpcClientErrorException, InterruptedE
}

@Test
public void isFinalExpiredTxTest() throws JsonRpcClientErrorException, InterruptedException {
public void isFinalExpiredTxTest() throws JsonRpcClientErrorException {

Payment builtPayment = payment
.sequence(accountInfo.accountData().sequence().minus(UnsignedInteger.ONE))
.build();
SubmitResult response = xrplClient.submit(wallet, builtPayment);
Hash256 txHash = response.transactionResult().hash();

assertThat(
xrplClient.isFinal(
response.transactionResult().hash(),
txHash,
response.validatedLedgerIndex(),
lastLedgerSequence.minus(UnsignedInteger.ONE),
accountInfo.accountData().sequence(),
wallet.classicAddress()
).finalityStatus()
).isEqualTo(FinalityStatus.NOT_FINAL);
Thread.sleep(1000);

this.scanForResult(
() -> this.getValidatedLedger(),
ledger -> FluentCompareTo.is(ledger.ledgerIndexSafe().unsignedIntegerValue())
.greaterThan(lastLedgerSequence.minus(UnsignedInteger.ONE))
);

assertThat(
xrplClient.isFinal(
response.transactionResult().hash(),
txHash,
response.validatedLedgerIndex(),
lastLedgerSequence.minus(UnsignedInteger.ONE),
accountInfo.accountData().sequence(),
Expand All @@ -119,29 +132,32 @@ public void isFinalExpiredTxTest() throws JsonRpcClientErrorException, Interrupt
}

@Test
public void isFinalNoTrustlineIouPayment_ValidatedFailureResponse()
throws JsonRpcClientErrorException, InterruptedException {
public void isFinalNoTrustlineIouPayment_ValidatedFailureResponse() throws JsonRpcClientErrorException {

Payment builtPayment = payment
.amount(IssuedCurrencyAmount.builder().currency("USD").issuer(
wallet.classicAddress()).value("500").build()
).build();
SubmitResult response = xrplClient.submit(wallet, builtPayment);
Hash256 txHash = response.transactionResult().hash();

assertThat(
xrplClient.isFinal(
response.transactionResult().hash(),
txHash,
response.validatedLedgerIndex(),
lastLedgerSequence,
accountInfo.accountData().sequence(),
wallet.classicAddress()
).finalityStatus()
).isEqualTo(FinalityStatus.NOT_FINAL);
Thread.sleep(1000);

this.scanForResult(
() -> getValidatedTransaction(txHash, Payment.class)
);

assertThat(
xrplClient.isFinal(
response.transactionResult().hash(),
txHash,
response.validatedLedgerIndex(),
lastLedgerSequence,
accountInfo.accountData().sequence(),
Expand Down

0 comments on commit 4255c50

Please sign in to comment.