Skip to content

Commit 0faf14c

Browse files
committed
Fix checkstyle
1 parent 04e700c commit 0faf14c

File tree

1 file changed

+55
-28
lines changed
  • xrpl4j-integration-tests/src/test/java/org/xrpl/xrpl4j/tests

1 file changed

+55
-28
lines changed

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

Lines changed: 55 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -95,17 +95,6 @@ public void createAndFinishTimeBasedEscrow() throws JsonRpcClientErrorException,
9595
createResult.transactionResult().hash()
9696
);
9797

98-
//////////////////////
99-
// Then wait until the transaction gets committed to a validated ledger
100-
TransactionResult<EscrowCreate> result = this.scanForResult(
101-
() -> this.getValidatedTransaction(createResult.transactionResult().hash(), EscrowCreate.class)
102-
);
103-
104-
assertEntryEqualsObjectFromAccountObjects(
105-
senderKeyPair.publicKey().deriveAddress(),
106-
escrowCreate.sequence()
107-
);
108-
10998
//////////////////////
11099
// Wait until the close time on the current validated ledger is after the finishAfter time on the Escrow
111100
this.scanForResult(
@@ -119,6 +108,12 @@ public void createAndFinishTimeBasedEscrow() throws JsonRpcClientErrorException,
119108
)
120109
);
121110

111+
assertEntryEqualsObjectFromAccountObjects(
112+
senderKeyPair.publicKey().deriveAddress(),
113+
escrowCreate.sequence()
114+
);
115+
116+
122117
//////////////////////
123118
// Receiver submits an EscrowFinish transaction to release the Escrow funds
124119
AccountInfoResult receiverAccountInfo = this.scanForResult(
@@ -129,7 +124,7 @@ public void createAndFinishTimeBasedEscrow() throws JsonRpcClientErrorException,
129124
.fee(feeResult.drops().openLedgerFee())
130125
.sequence(receiverAccountInfo.accountData().sequence())
131126
.owner(senderKeyPair.publicKey().deriveAddress())
132-
.offerSequence(result.transaction().sequence())
127+
.offerSequence(createResult.transactionResult().transaction().sequence())
133128
.signingPublicKey(receiverKeyPair.publicKey())
134129
.build();
135130

@@ -270,8 +265,46 @@ public void createAndFinishTimeBasedEscrowToSelf() throws JsonRpcClientErrorExce
270265
infoResult -> infoResult.accountData().balance().equals(
271266
preEscrowFinishSenderAccountInfo.accountData().balance()
272267
.plus(escrowCreate.amount())
273-
.minus(feeResult.drops().openLedgerFee()))
274-
&& infoResult.accountData().balance().equals(XrpCurrencyAmount.ofDrops(999999980))
268+
.minus(feeResult.drops().openLedgerFee())) &&
269+
infoResult.accountData().balance().equals(XrpCurrencyAmount.ofDrops(999999980))
270+
);
271+
}
272+
273+
@Test
274+
public void createEscrowWithInsufficientFunds() throws JsonRpcClientErrorException, JsonProcessingException {
275+
//////////////////////
276+
// Create random sender accounts
277+
KeyPair senderKeyPair = createRandomAccountEd25519();
278+
279+
//////////////////////
280+
// Sender account creates an Escrow with the receiver account
281+
FeeResult feeResult = xrplClient.fee();
282+
final AccountInfoResult senderAccountInfo = this.scanForResult(
283+
() -> this.getValidatedAccountInfo(senderKeyPair.publicKey().deriveAddress())
284+
);
285+
assertThat(senderAccountInfo.accountData().balance()).isEqualTo(XrpCurrencyAmount.ofDrops(1000000000));
286+
287+
EscrowCreate escrowCreate = EscrowCreate.builder()
288+
.account(senderKeyPair.publicKey().deriveAddress())
289+
.sequence(senderAccountInfo.accountData().sequence())
290+
.fee(feeResult.drops().openLedgerFee())
291+
.amount(XrpCurrencyAmount.ofDrops(1000000001))
292+
.destination(senderKeyPair.publicKey().deriveAddress())
293+
.cancelAfter(instantToXrpTimestamp(getMinExpirationTime().plus(Duration.ofSeconds(100))))
294+
.finishAfter(instantToXrpTimestamp(getMinExpirationTime().plus(Duration.ofSeconds(5))))
295+
.signingPublicKey(senderKeyPair.publicKey())
296+
.build();
297+
298+
//////////////////////
299+
// Submit the EscrowCreate transaction and validate that it was successful
300+
SingleSignedTransaction<EscrowCreate> signedEscrowCreate = signatureService.sign(
301+
senderKeyPair.privateKey(), escrowCreate
302+
);
303+
SubmitResult<EscrowCreate> createResult = xrplClient.submit(signedEscrowCreate);
304+
assertThat(createResult.engineResult()).isEqualTo("tecUNFUNDED");
305+
logger.info(
306+
"EscrowCreate transaction successful: https://testnet.xrpl.org/transactions/{}",
307+
createResult.transactionResult().hash()
275308
);
276309
}
277310

@@ -490,8 +523,8 @@ public void createAndCancelTimeBasedEscrowToSelf() throws JsonRpcClientErrorExce
490523
infoResult -> infoResult.accountData().balance().equals(
491524
preEscrowFinishSenderAccountInfo.accountData().balance()
492525
.plus(escrowCreate.amount())
493-
.minus(feeResult.drops().openLedgerFee()))
494-
&& infoResult.accountData().balance().equals(XrpCurrencyAmount.ofDrops(999999980))
526+
.minus(feeResult.drops().openLedgerFee())) &&
527+
infoResult.accountData().balance().equals(XrpCurrencyAmount.ofDrops(999999980))
495528
);
496529
}
497530

@@ -537,17 +570,6 @@ public void createAndFinishCryptoConditionBasedEscrow() throws JsonRpcClientErro
537570
createResult.transactionResult().hash()
538571
);
539572

540-
//////////////////////
541-
// Then wait until the transaction gets committed to a validated ledger
542-
TransactionResult<EscrowCreate> result = this.scanForResult(
543-
() -> this.getValidatedTransaction(createResult.transactionResult().hash(), EscrowCreate.class)
544-
);
545-
546-
assertEntryEqualsObjectFromAccountObjects(
547-
senderKeyPair.publicKey().deriveAddress(),
548-
escrowCreate.sequence()
549-
);
550-
551573
//////////////////////
552574
// Wait until the close time on the current validated ledger is after the finishAfter time on the Escrow
553575
this.scanForResult(
@@ -561,6 +583,11 @@ public void createAndFinishCryptoConditionBasedEscrow() throws JsonRpcClientErro
561583
)
562584
);
563585

586+
assertEntryEqualsObjectFromAccountObjects(
587+
senderKeyPair.publicKey().deriveAddress(),
588+
escrowCreate.sequence()
589+
);
590+
564591
//////////////////////
565592
// Execute the escrow using the secret fulfillment known only to the appropriate party.
566593
AccountInfoResult receiverAccountInfo = this.scanForResult(
@@ -575,7 +602,7 @@ public void createAndFinishCryptoConditionBasedEscrow() throws JsonRpcClientErro
575602
.fee(EscrowFinish.computeFee(feeResult.drops().openLedgerFee(), executeEscrowFulfillment))
576603
.sequence(receiverAccountInfo.accountData().sequence())
577604
.owner(senderKeyPair.publicKey().deriveAddress())
578-
.offerSequence(result.transaction().sequence())
605+
.offerSequence(createResult.transactionResult().transaction().sequence())
579606
.signingPublicKey(receiverKeyPair.publicKey())
580607
.condition(executeEscrowFulfillment.getDerivedCondition()) // <-- condition and fulfillment are required.
581608
.fulfillment(executeEscrowFulfillment) // <-- condition and fulfillment are required to finish an escrow

0 commit comments

Comments
 (0)