Skip to content

Commit

Permalink
#9427: Revert after INVALID_ACCOUNT_ID static call (#9931)
Browse files Browse the repository at this point in the history
Signed-off-by: ilko-iliev-lime <ilko.iliev@limechain.tech>
  • Loading branch information
ilko-iliev-lime committed Nov 20, 2023
1 parent 791ab23 commit 6582f75
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ protected FullResult resultOfViewingToken(@NonNull final Token token) {
}
final var ownerID = addressIdConverter.convert(owner);
final var ownerAccount = nativeOperations().getAccount(ownerID.accountNumOrThrow());
if (isStaticCall && ownerAccount == null) {
return FullResult.revertResult(
com.hedera.hapi.node.base.ResponseCodeEnum.INVALID_ACCOUNT_ID, gasRequirement);
}
final var spenderID = addressIdConverter.convert(spender);
if (!spenderID.hasAccountNum() && !isStaticCall) {
return FullResult.successResult(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,9 @@

package com.hedera.node.app.service.contract.impl.test.exec.systemcontracts.hts.allowance;

import static com.hedera.hapi.node.base.ResponseCodeEnum.INVALID_ACCOUNT_ID;
import static com.hedera.hapi.node.base.ResponseCodeEnum.INVALID_TOKEN_ID;
import static com.hedera.node.app.service.contract.impl.test.TestHelpers.APPROVED_HEADLONG_ADDRESS;
import static com.hedera.node.app.service.contract.impl.test.TestHelpers.B_NEW_ACCOUNT_ID;
import static com.hedera.node.app.service.contract.impl.test.TestHelpers.FUNGIBLE_TOKEN;
import static com.hedera.node.app.service.contract.impl.test.TestHelpers.NON_FUNGIBLE_TOKEN;
import static com.hedera.node.app.service.contract.impl.test.TestHelpers.OPERATOR;
import static com.hedera.node.app.service.contract.impl.test.TestHelpers.OWNER_HEADLONG_ADDRESS;
import static com.hedera.node.app.service.contract.impl.test.TestHelpers.revertOutputFor;
import static com.hedera.node.app.service.contract.impl.test.TestHelpers.*;
import static com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
Expand Down Expand Up @@ -63,6 +58,25 @@ void revertsWithFungibleToken() {
assertEquals(revertOutputFor(INVALID_TOKEN_ID), result.getOutput());
}

@Test
void revertsWithInvalidAccountId() {
subject = new GetAllowanceCall(
addressIdConverter,
gasCalculator,
mockEnhancement(),
FUNGIBLE_TOKEN,
OWNER_HEADLONG_ADDRESS,
APPROVED_HEADLONG_ADDRESS,
true,
true);
given(addressIdConverter.convert(OWNER_HEADLONG_ADDRESS)).willReturn(A_NEW_ACCOUNT_ID);
given(nativeOperations.getAccount(A_NEW_ACCOUNT_ID.accountNum())).willReturn(null);
final var result = subject.execute().fullResult().result();

assertEquals(MessageFrame.State.REVERT, result.getState());
assertEquals(revertOutputFor(INVALID_ACCOUNT_ID), result.getOutput());
}

@Test
void ERCGetAllowance() {
subject = new GetAllowanceCall(
Expand Down

0 comments on commit 6582f75

Please sign in to comment.