Skip to content

Commit

Permalink
Tightly control AccountDelete
Browse files Browse the repository at this point in the history
  • Loading branch information
sappenin committed Nov 28, 2024
1 parent 3d2b4b5 commit f7e76f9
Showing 1 changed file with 35 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.google.common.primitives.UnsignedInteger;
import com.google.common.primitives.UnsignedLong;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIf;
import org.xrpl.xrpl4j.client.JsonRpcClientErrorException;
Expand Down Expand Up @@ -67,11 +69,33 @@ private static boolean shouldRun() {
System.getProperty("useClioTestnet") == null;
}

/**
* This test requires the Ledger Acceptor to be disabled, in order to tightly control advancement of ledgers. Because
* of this, some of the tests do not execute when running against real networks (because controlling ledger
* advancement is not possible).
*/
@BeforeAll
static void setupTest() {
// Turn the LedgerAcceptor off
xrplEnvironment.stopLedgerAcceptor();
}

/**
* Because this test requires the Ledger Acceptor to be disabled, once the test completes, the Ledger Acceptor must be
* enabled again so that follow-on tests execute as expected.
*/
@AfterAll
static void cleanupTest() {
// Turn the LedgerAcceptor off
xrplEnvironment.startLedgerAcceptor(POLL_INTERVAL);
}

@Test
void testAccountDeleteItFailsWith_TooSoon() throws JsonRpcClientErrorException, JsonProcessingException {
// create two accounts, one will be the destination in the tx
KeyPair senderAccount = constructRandomAccount();
KeyPair receiverAccount = constructRandomAccount();
xrplEnvironment.acceptLedger(); // <-- Progress the ledger to ensure the above tx becomes Validated.

// get sender account info for the sequence number
AccountInfoResult accountInfo = this.scanForResult(
Expand Down Expand Up @@ -101,6 +125,7 @@ void testAccountDeleteItFailsWith_TooSoon() throws JsonRpcClientErrorException,
void testAccountDeleteItFailsWith_DestinationIsSource() throws JsonRpcClientErrorException, JsonProcessingException {
// create one account, will be the sender & destination in the tx
KeyPair senderAccount = constructRandomAccount();
xrplEnvironment.acceptLedger(); // <-- Progress the ledger to ensure the above tx becomes Validated.

// get sender account info for the sequence number
AccountInfoResult accountInfo = this.scanForResult(
Expand Down Expand Up @@ -131,6 +156,7 @@ void testAccountDeleteItFailsWith_DestinationTagNeeded() throws JsonRpcClientErr
// create two accounts, one will be the destination in the tx
KeyPair senderAccount = constructRandomAccount();
KeyPair receiverAccount = constructRandomAccount();
xrplEnvironment.acceptLedger(); // <-- Progress the ledger to ensure the above tx becomes Validated.

// get receiver account info for the sequence number
AccountInfoResult receiverAccountInfo = this.scanForResult(
Expand All @@ -151,10 +177,11 @@ void testAccountDeleteItFailsWith_DestinationTagNeeded() throws JsonRpcClientErr
receiverAccount.privateKey(), accountSet
);
SubmitResult<AccountSet> accountSetSubmitResult = xrplClient.submit(signedAccountSet);

assertThat(accountSetSubmitResult.engineResult()).isEqualTo("tesSUCCESS");
assertThat(signedAccountSet.hash()).isEqualTo(accountSetSubmitResult.transactionResult().hash());

xrplEnvironment.acceptLedger(); // <-- Progress the ledger to ensure the above tx becomes Validated.

// confirm flag was set
TransactionResult<AccountSet> accountSetTransactionResult = this.scanForResult(() ->
this.getValidatedTransaction(signedAccountSet.hash(), AccountSet.class)
Expand Down Expand Up @@ -196,6 +223,7 @@ void testAccountDeleteItFailsWith_NoPermission() throws JsonRpcClientErrorExcept
// create two accounts, one will be the destination in the tx
KeyPair senderAccount = constructRandomAccount();
KeyPair receiverAccount = constructRandomAccount();
xrplEnvironment.acceptLedger(); // <-- Progress the ledger to ensure the above tx becomes Validated.

// get receiver account info for the sequence number
AccountInfoResult receiverAccountInfo = this.scanForResult(
Expand All @@ -216,26 +244,21 @@ void testAccountDeleteItFailsWith_NoPermission() throws JsonRpcClientErrorExcept
receiverAccount.privateKey(), accountSet
);
SubmitResult<AccountSet> accountSetSubmitResult = xrplClient.submit(signedAccountSet);

assertThat(accountSetSubmitResult.engineResult()).isEqualTo("tesSUCCESS");
assertThat(signedAccountSet.hash()).isEqualTo(accountSetSubmitResult.transactionResult().hash());
xrplEnvironment.acceptLedger(); // <-- Progress the ledger to ensure the above tx becomes Validated.

// confirm flag was set
TransactionResult<AccountSet> accountSetTransactionResult = this.scanForResult(
() -> this.getValidatedTransaction(signedAccountSet.hash(), AccountSet.class)
);

AccountInfoResult updatedReceiverAccountInfo = this.scanForResult(
() -> this.getValidatedAccountInfo(receiverAccount.publicKey().deriveAddress())
);

assertThat(accountSetTransactionResult.transaction().setFlag().orElse(null))
.isEqualTo(AccountSet.AccountSetFlag.DEPOSIT_AUTH);
assertThat(updatedReceiverAccountInfo.accountData().flags().lsfDepositAuth()).isTrue();

receiverAccountInfo = this.scanForResult(
AccountInfoResult updatedReceiverAccountInfo = this.scanForResult(
() -> this.getValidatedAccountInfo(receiverAccount.publicKey().deriveAddress())
);
assertThat(updatedReceiverAccountInfo.accountData().flags().lsfDepositAuth()).isTrue();

// get sender account info for the sequence number
AccountInfoResult senderAccountInfo = this.scanForResult(
Expand Down Expand Up @@ -266,6 +289,7 @@ void testAccountDeleteItFailsWith_NoDestination() throws JsonRpcClientErrorExcep
// create one account and a random key pair that will be used for the destination
KeyPair senderAccount = constructRandomAccount();
KeyPair randomDestinationKeyPair = Seed.ed25519Seed().deriveKeyPair();
xrplEnvironment.acceptLedger(); // <-- Progress the ledger to ensure the above tx becomes Validated.

// get sender account info for the sequence number
AccountInfoResult senderAccountInfoResult = this.scanForResult(
Expand Down Expand Up @@ -295,6 +319,7 @@ void testAccountDeleteItFailsWith_NoDestination() throws JsonRpcClientErrorExcep
void testAccountDeleteItFailsWith_HasObligations() throws JsonRpcClientErrorException, JsonProcessingException {
// create sender account
KeyPair senderAccount = constructRandomAccount();
xrplEnvironment.acceptLedger(); // <-- Progress the ledger to ensure the above tx becomes Validated.

// get account info for the sequence number
AccountInfoResult accountInfo = this.scanForResult(
Expand Down Expand Up @@ -362,6 +387,7 @@ void testAccountDeleteIt() throws JsonRpcClientErrorException, JsonProcessingExc
// create two accounts, one will be the destination in the tx
KeyPair senderAccount = constructRandomAccount();
KeyPair receiverAccount = constructRandomAccount();
xrplEnvironment.acceptLedger(); // <-- Progress the ledger to ensure the above tx becomes Validated.

// get account info for the sequence number
AccountInfoResult accountInfo = this.scanForResult(
Expand Down

0 comments on commit f7e76f9

Please sign in to comment.