Skip to content

Commit 9a6a687

Browse files
authored
fix: Enable pureChecks in TokenAssociateToAccountHandler (#12590)
Signed-off-by: Michael Heinrichs <[email protected]>
1 parent a8ec9d1 commit 9a6a687

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

hedera-node/hedera-token-service-impl/src/main/java/com/hedera/node/app/service/token/impl/handlers/TokenAssociateToAccountHandler.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
import com.hedera.hapi.node.base.TokenID;
3636
import com.hedera.hapi.node.state.token.Account;
3737
import com.hedera.hapi.node.state.token.Token;
38-
import com.hedera.hapi.node.token.TokenAssociateTransactionBody;
38+
import com.hedera.hapi.node.transaction.TransactionBody;
3939
import com.hedera.node.app.service.mono.fees.calculation.token.txns.TokenAssociateResourceUsage;
4040
import com.hedera.node.app.service.token.ReadableAccountStore;
4141
import com.hedera.node.app.service.token.ReadableTokenStore;
@@ -72,7 +72,6 @@ public TokenAssociateToAccountHandler() {}
7272
public void preHandle(@NonNull final PreHandleContext context) throws PreCheckException {
7373
requireNonNull(context);
7474
final var op = context.body().tokenAssociateOrThrow();
75-
pureChecks(op);
7675

7776
final var target = op.accountOrElse(AccountID.DEFAULT);
7877
context.requireKeyOrThrow(target, INVALID_ACCOUNT_ID);
@@ -101,7 +100,10 @@ public void handle(@NonNull final HandleContext context) throws HandleException
101100
/**
102101
* Performs checks independent of state or context
103102
*/
104-
private void pureChecks(@NonNull final TokenAssociateTransactionBody op) throws PreCheckException {
103+
@Override
104+
public void pureChecks(@NonNull final TransactionBody txn) throws PreCheckException {
105+
final var op = txn.tokenAssociateOrThrow();
106+
105107
if (!op.hasAccount()) {
106108
throw new PreCheckException(ResponseCodeEnum.INVALID_ACCOUNT_ID);
107109
}

hedera-node/hedera-token-service-impl/src/test/java/com/hedera/node/app/service/token/impl/test/handlers/TokenAssociateToAccountHandlerTest.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,8 @@ void txnWithoutAccountThrows() throws PreCheckException {
114114
@Test
115115
void txnWithRepeatedTokenIdsThrows() throws PreCheckException {
116116
final var txn = newAssociateTxn(ACCOUNT_888, List.of(TOKEN_300, TOKEN_400, TOKEN_300));
117-
final var context = new FakePreHandleContext(readableAccountStore, txn);
118117

119-
assertThatThrownBy(() -> subject.preHandle(context))
118+
assertThatThrownBy(() -> subject.pureChecks(txn))
120119
.isInstanceOf(PreCheckException.class)
121120
.has(responseCode(TOKEN_ID_REPEATED_IN_TOKEN_LIST));
122121
}

0 commit comments

Comments
 (0)