diff --git a/hedera-node/hedera-token-service-impl/src/main/java/com/hedera/node/app/service/token/impl/handlers/TokenCancelAirdropHandler.java b/hedera-node/hedera-token-service-impl/src/main/java/com/hedera/node/app/service/token/impl/handlers/TokenCancelAirdropHandler.java index c0e7ae1675a4..74aacb92ba20 100644 --- a/hedera-node/hedera-token-service-impl/src/main/java/com/hedera/node/app/service/token/impl/handlers/TokenCancelAirdropHandler.java +++ b/hedera-node/hedera-token-service-impl/src/main/java/com/hedera/node/app/service/token/impl/handlers/TokenCancelAirdropHandler.java @@ -17,8 +17,8 @@ package com.hedera.node.app.service.token.impl.handlers; import static com.hedera.hapi.node.base.ResponseCodeEnum.EMPTY_PENDING_AIRDROP_ID_LIST; -import static com.hedera.hapi.node.base.ResponseCodeEnum.INVALID_ACCOUNT_ID; import static com.hedera.hapi.node.base.ResponseCodeEnum.INVALID_NFT_ID; +import static com.hedera.hapi.node.base.ResponseCodeEnum.INVALID_PENDING_AIRDROP_ID; import static com.hedera.hapi.node.base.ResponseCodeEnum.INVALID_TOKEN_ID; import static com.hedera.hapi.node.base.ResponseCodeEnum.INVALID_TOKEN_NFT_SERIAL_NUMBER; import static com.hedera.hapi.node.base.ResponseCodeEnum.NOT_SUPPORTED; @@ -78,7 +78,7 @@ public void preHandle(@NonNull final PreHandleContext context) throws PreCheckEx final var op = txn.tokenCancelAirdropOrThrow(); final var allPendingAirdrops = op.pendingAirdrops(); for (final var airdrop : allPendingAirdrops) { - context.requireAliasedKeyOrThrow(airdrop.senderIdOrThrow(), INVALID_ACCOUNT_ID); + context.requireAliasedKeyOrThrow(airdrop.senderIdOrThrow(), INVALID_PENDING_AIRDROP_ID); } } @@ -93,8 +93,8 @@ public void pureChecks(@NonNull final TransactionBody txn) throws PreCheckExcept if (!uniquePendingAirdrops.add(airdrop)) { throw new PreCheckException(PENDING_AIRDROP_ID_REPEATED); } - validateAccountID(airdrop.receiverId(), null); - validateAccountID(airdrop.senderId(), null); + validateAccountID(airdrop.receiverId(), INVALID_PENDING_AIRDROP_ID); + validateAccountID(airdrop.senderId(), INVALID_PENDING_AIRDROP_ID); if (airdrop.hasFungibleTokenType()) { final var tokenID = airdrop.fungibleTokenType(); diff --git a/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/suites/hip904/TokenCancelAirdropTest.java b/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/suites/hip904/TokenCancelAirdropTest.java index a0cdb2336ac2..1d48c78231c7 100644 --- a/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/suites/hip904/TokenCancelAirdropTest.java +++ b/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/suites/hip904/TokenCancelAirdropTest.java @@ -36,6 +36,8 @@ import static com.hedera.services.bdd.spec.transactions.token.TokenMovement.moving; import static com.hedera.services.bdd.spec.transactions.token.TokenMovement.movingUnique; import static com.hedera.services.bdd.spec.utilops.UtilVerbs.newKeyNamed; +import static com.hedera.services.bdd.spec.utilops.UtilVerbs.submitModified; +import static com.hedera.services.bdd.spec.utilops.mod.ModificationUtils.withSuccessivelyVariedBodyIds; import static com.hedera.services.bdd.suites.HapiSuite.FIVE_HBARS; import static com.hederahashgraph.api.proto.java.ResponseCodeEnum.ACCOUNT_HAS_PENDING_AIRDROPS; import static com.hederahashgraph.api.proto.java.ResponseCodeEnum.EMPTY_PENDING_AIRDROP_ID_LIST; @@ -78,6 +80,21 @@ static void beforeAll(@NonNull final TestLifecycle lifecycle) { lifecycle.doAdhoc(setUpTokensAndAllReceivers()); } + @HapiTest + @DisplayName("fails gracefully with null parameters") + final Stream idVariantsTreatedAsExpected() { + final var account = "account"; + return hapiTest( + cryptoCreate(account), + tokenAssociate(account, FUNGIBLE_TOKEN), + cryptoTransfer(moving(10, FUNGIBLE_TOKEN).between(OWNER, account)), + tokenAirdrop(moving(10, FUNGIBLE_TOKEN).between(account, RECEIVER_WITH_0_AUTO_ASSOCIATIONS)) + .payingWith(account), + submitModified(withSuccessivelyVariedBodyIds(), () -> tokenCancelAirdrop( + pendingAirdrop(account, RECEIVER_WITH_0_AUTO_ASSOCIATIONS, FUNGIBLE_TOKEN)) + .payingWith(account))); + } + @HapiTest @DisplayName("not created NFT pending airdrop") final Stream cancelNotCreatedNFTPendingAirdrop() {