|
| 1 | +// SPDX-License-Identifier: Apache-2.0 |
| 2 | + |
| 3 | +package org.hiero.mirror.test.e2e.acceptance.steps; |
| 4 | + |
| 5 | +import static org.assertj.core.api.Assertions.assertThat; |
| 6 | + |
| 7 | +import com.hedera.hashgraph.sdk.AccountId; |
| 8 | +import com.hedera.hashgraph.sdk.PrivateKey; |
| 9 | +import io.cucumber.java.en.Then; |
| 10 | +import io.cucumber.java.en.When; |
| 11 | +import lombok.CustomLog; |
| 12 | +import lombok.RequiredArgsConstructor; |
| 13 | +import org.hiero.mirror.common.CommonProperties; |
| 14 | +import org.hiero.mirror.rest.model.TransactionTypes; |
| 15 | +import org.hiero.mirror.test.e2e.acceptance.client.AccountClient; |
| 16 | +import org.hiero.mirror.test.e2e.acceptance.client.MirrorNodeClient; |
| 17 | +import org.hiero.mirror.test.e2e.acceptance.props.ExpandedAccountId; |
| 18 | + |
| 19 | +@CustomLog |
| 20 | +@RequiredArgsConstructor |
| 21 | +public class BatchTransactionFeature { |
| 22 | + |
| 23 | + private final MirrorNodeClient mirrorClient; |
| 24 | + private final AccountClient accountClient; |
| 25 | + private final CommonProperties commonProperties; |
| 26 | + private final PrivateKey hollowAccountPrivateKey = PrivateKey.generateECDSA(); |
| 27 | + |
| 28 | + private String batchTransactionId; |
| 29 | + private AccountId hollowResolvedAccountId; |
| 30 | + private String completionTransactionId; |
| 31 | + private ExpandedAccountId batchSigner; |
| 32 | + private AccountId hollowAliasAccountId; |
| 33 | + |
| 34 | + @When( |
| 35 | + "I submit a batch transaction containing transfer {long} tℏ to {string} and a hollow account create with {long} tℏ with batch signed by {string}") |
| 36 | + public void submitBatchWithHollowAndNormalTransfer( |
| 37 | + long normalTransferAmount, |
| 38 | + String recipientAccountName, |
| 39 | + long hollowFundingAmount, |
| 40 | + String batchSignerAccountName) { |
| 41 | + log.debug("Submitting batch transaction (hollow auto-create + normal crypto transfer)"); |
| 42 | + batchSigner = accountClient.getAccount(AccountClient.AccountNameEnum.valueOf(batchSignerAccountName)); |
| 43 | + |
| 44 | + hollowAliasAccountId = AccountId.fromEvmAddress( |
| 45 | + hollowAccountPrivateKey.getPublicKey().toEvmAddress().toString(), |
| 46 | + commonProperties.getShard(), |
| 47 | + commonProperties.getRealm()); |
| 48 | + |
| 49 | + final var batchResult = accountClient.submitBatchWithHollowAutoCreateAndNormalTransfer( |
| 50 | + batchSigner, |
| 51 | + hollowAliasAccountId, |
| 52 | + AccountClient.AccountNameEnum.valueOf(recipientAccountName), |
| 53 | + hollowFundingAmount, |
| 54 | + normalTransferAmount); |
| 55 | + |
| 56 | + assertThat(batchResult).isNotNull(); |
| 57 | + assertThat(batchResult.getTransactionIdStringNoCheckSum()).isNotNull(); |
| 58 | + |
| 59 | + batchTransactionId = batchResult.getTransactionIdStringNoCheckSum(); |
| 60 | + } |
| 61 | + |
| 62 | + @When("I submit a transaction that completes the hollow account") |
| 63 | + public void completeHollow() { |
| 64 | + assertThat(hollowResolvedAccountId).isNotNull(); |
| 65 | + log.debug("Submitting completion transaction for hollow account {}", hollowResolvedAccountId); |
| 66 | + |
| 67 | + var completionResponse = |
| 68 | + accountClient.submitCompletionTransaction(hollowResolvedAccountId, hollowAccountPrivateKey); |
| 69 | + |
| 70 | + assertThat(completionResponse).isNotNull(); |
| 71 | + assertThat(completionResponse.getTransactionId()).isNotNull(); |
| 72 | + |
| 73 | + completionTransactionId = completionResponse.getTransactionIdStringNoCheckSum(); |
| 74 | + } |
| 75 | + |
| 76 | + @Then("I should be able to resolve the hollow account id") |
| 77 | + public void resolveHollowAccountId() { |
| 78 | + final var accountDetails = mirrorClient.getAccountDetailsUsingEvmAddress(hollowAliasAccountId); |
| 79 | + |
| 80 | + hollowResolvedAccountId = AccountId.fromString(accountDetails.getAccount()); |
| 81 | + |
| 82 | + assertThat(hollowResolvedAccountId).isNotNull(); |
| 83 | + assertThat(accountDetails.getKey()).isNull(); |
| 84 | + } |
| 85 | + |
| 86 | + @Then("I should see the batch transaction in mirror node") |
| 87 | + public void verifyBatchTransactionInRecordStream() { |
| 88 | + assertThat(batchTransactionId).isNotNull(); |
| 89 | + |
| 90 | + final var transactions = |
| 91 | + mirrorClient.getTransactions(batchTransactionId).getTransactions(); |
| 92 | + assertThat(transactions).isNotNull(); |
| 93 | + assertThat(transactions).hasSize(4); // batch + 2 inner + hollow create |
| 94 | + |
| 95 | + final var atomicBatch = transactions.stream() |
| 96 | + .filter(t -> TransactionTypes.ATOMICBATCH.equals(t.getName())) |
| 97 | + .findFirst() |
| 98 | + .orElse(null); |
| 99 | + assertThat(atomicBatch); |
| 100 | + |
| 101 | + // Matches inner transactions and hollow create. All should have parent timestamp of ATOMIC_BATCH consensus |
| 102 | + // timestamp |
| 103 | + final var innerTransactions = transactions.stream() |
| 104 | + .filter(t -> atomicBatch.getConsensusTimestamp().equals(t.getParentConsensusTimestamp())) |
| 105 | + .toList(); |
| 106 | + assertThat(innerTransactions).hasSize(3); |
| 107 | + assertThat(innerTransactions) |
| 108 | + .filteredOn(t -> TransactionTypes.CRYPTOTRANSFER.equals(t.getName())) |
| 109 | + .hasSize(2) |
| 110 | + .allMatch(t -> batchSigner |
| 111 | + .getPublicKey() |
| 112 | + .toStringRaw() |
| 113 | + .equals(t.getBatchKey().getKey())); |
| 114 | + assertThat(innerTransactions) |
| 115 | + .filteredOn(t -> TransactionTypes.CRYPTOCREATEACCOUNT.equals(t.getName())) |
| 116 | + .hasSize(1) |
| 117 | + .allMatch(t -> t.getBatchKey() == null); |
| 118 | + } |
| 119 | + |
| 120 | + @Then("I should see the completion transaction in mirror node") |
| 121 | + public void verifyCompletionTransaction() { |
| 122 | + assertThat(completionTransactionId).isNotNull(); |
| 123 | + |
| 124 | + var completionTransactions = |
| 125 | + mirrorClient.getTransactions(completionTransactionId).getTransactions(); |
| 126 | + assertThat(completionTransactions).hasSize(2); |
| 127 | + |
| 128 | + assertThat(completionTransactions) |
| 129 | + .filteredOn(t -> TransactionTypes.CRYPTOTRANSFER.equals(t.getName())) |
| 130 | + .hasSize(1); |
| 131 | + |
| 132 | + assertThat(completionTransactions) |
| 133 | + .filteredOn(t -> TransactionTypes.CRYPTOUPDATEACCOUNT.equals(t.getName())) |
| 134 | + .hasSize(1); |
| 135 | + } |
| 136 | +} |
0 commit comments