Skip to content

Commit

Permalink
Addressed PR comments (#9672)
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 7, 2023
1 parent 57016d5 commit 79cdc9f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ public NftTokenInfoCall(
.nativeOperations()
.getNft(token.tokenIdOrElse(ZERO_TOKEN_ID).tokenNum(), serialNumber);
// @Future remove to revert #9074 after modularization is completed
if ((isStaticCall && (status != SUCCESS)) || nft == null) {
if (isStaticCall && (status != SUCCESS || nft == null)) {
return revertResult(status, gasCalculator.viewGasRequirement());
}

Account ownerAccount = getOwnerAccount(nft, token);
final var ownerAccount = getOwnerAccount(nft, token);
if (ownerAccount == null) {
return revertResult(INVALID_ACCOUNT_ID, gasCalculator.viewGasRequirement());
}
Expand All @@ -102,16 +102,17 @@ public NftTokenInfoCall(
gasRequirement);
}

private Account getOwnerAccount(Nft nft, Token token) {
private Account getOwnerAccount(@NonNull Nft nft, Token token) {
requireNonNull(nft);
final var explicitId = nft.ownerIdOrElse(AccountID.DEFAULT);
if (explicitId.account().kind() == AccountID.AccountOneOfType.UNSET) {
return null;
}
final long ownerNum;
if (explicitId.accountNumOrElse(TREASURY_OWNER_NUM) == TREASURY_OWNER_NUM) {
ownerNum = token.treasuryAccountIdOrThrow().accountNumOrThrow();
} else {
if (explicitId.hasAccountNum()) {
ownerNum = explicitId.accountNumOrThrow();
} else {
ownerNum = token.treasuryAccountIdOrThrow().accountNumOrThrow();
}
return nativeOperations().getAccount(ownerNum);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static com.hedera.node.app.service.contract.impl.test.TestHelpers.*;
import static com.hedera.node.app.service.contract.impl.utils.ConversionUtils.headlongAddressOf;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.when;

import com.esaulpaugh.headlong.abi.Tuple;
Expand Down Expand Up @@ -93,18 +94,6 @@ void returnsNftTokenInfoStatusForPresentToken() {
result.getOutput());
}

@Test
void revertsWhenTryingToFetchMissingTokenNonStaticCall() {
when(config.getConfigData(LedgerConfig.class)).thenReturn(ledgerConfig);
when(ledgerConfig.id()).thenReturn(com.hedera.pbj.runtime.io.buffer.Bytes.fromHex("01"));

final var subject = new NftTokenInfoCall(gasCalculator, mockEnhancement(), false, null, 0L, config);
final var result = subject.execute().fullResult().result();

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

@Test
void revertsWhenTryingToFetchMissingTokenStaticCall() {
when(config.getConfigData(LedgerConfig.class)).thenReturn(ledgerConfig);
Expand Down

0 comments on commit 79cdc9f

Please sign in to comment.