Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ protected TokenReadableKVState(

@Override
protected Token readFromDataSource(@Nonnull TokenID key) {
if (key.tokenNum() < 0) {
return null;
}

final var timestamp = ContractCallContext.get().getTimestamp();
final var entity = commonEntityAccessor.get(key, timestamp).orElse(null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import static com.hedera.hapi.node.base.ResponseCodeEnum.CONTRACT_REVERT_EXECUTED;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
import static org.hiero.mirror.common.domain.entity.EntityType.ACCOUNT;
import static org.hiero.mirror.common.domain.entity.EntityType.CONTRACT;
import static org.hiero.mirror.web3.evm.utils.EvmTokenUtils.toAddress;
Expand Down Expand Up @@ -108,6 +109,29 @@
verifyContractCall(functionCall, contract);
}

@Test
void airdropTokenWithInvalidTokenAddress() {
// Given
final var contract = testWeb3jService.deployWithValue(Airdrop::deploy, DEFAULT_DEPLOYED_CONTRACT_BALANCE);
final var sender = accountEntityPersist();
final var receiver = persistAirdropReceiver(EntityType.ACCOUNT, e -> {});

Check notice on line 117 in web3/src/test/java/org/hiero/mirror/web3/service/ContractCallAirdropSystemContractTest.java

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

web3/src/test/java/org/hiero/mirror/web3/service/ContractCallAirdropSystemContractTest.java#L117

'{' is not followed by whitespace.

Check notice on line 117 in web3/src/test/java/org/hiero/mirror/web3/service/ContractCallAirdropSystemContractTest.java

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

web3/src/test/java/org/hiero/mirror/web3/service/ContractCallAirdropSystemContractTest.java#L117

Unnecessary use of fully qualified name 'EntityType.ACCOUNT' due to existing static import 'org.hiero.mirror.common.domain.entity.EntityType.ACCOUNT'

Check notice on line 117 in web3/src/test/java/org/hiero/mirror/web3/service/ContractCallAirdropSystemContractTest.java

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

web3/src/test/java/org/hiero/mirror/web3/service/ContractCallAirdropSystemContractTest.java#L117

Unused lambda parameter 'e' should be unnamed.

final var tokenId = fungibleTokenSetup(sender);
tokenAccountPersist(tokenId, receiver.getId());
final var invalidTokenAddress = "0xa7d9ddbe1f17865597fbd27ec712455208b6b76d";

// When
final var functionCall = contract.send_tokenAirdrop(
invalidTokenAddress,
getAddressFromEntity(sender),
toAddress(receiver).toHexString(),
DEFAULT_TOKEN_AIRDROP_AMOUNT,
DEFAULT_TINYBAR_VALUE);

// Then
assertThatThrownBy(functionCall::send).isInstanceOf(MirrorEvmTransactionException.class);
}

@ParameterizedTest(name = "Airdrop non-fungible token to a(an) {0} that is already associated to it")
@MethodSource("receiverData")
void airdropNFT(final EntityType receiverType) {
Expand Down
Loading