diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/nfttokeninfo/NftTokenInfoCall.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/nfttokeninfo/NftTokenInfoCall.java index 24162a49239f..6393ebbdc2cd 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/nfttokeninfo/NftTokenInfoCall.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/nfttokeninfo/NftTokenInfoCall.java @@ -41,7 +41,6 @@ import edu.umd.cs.findbugs.annotations.Nullable; public class NftTokenInfoCall extends AbstractNonRevertibleTokenViewCall { - private static final long TREASURY_OWNER_NUM = 0L; private final Configuration configuration; private final boolean isStaticCall; private final long serialNumber; @@ -65,25 +64,29 @@ public NftTokenInfoCall( @Override protected @NonNull FullResult resultOfViewingToken(@NonNull final Token token) { requireNonNull(token); - return fullResultsFor(SUCCESS, gasCalculator.viewGasRequirement(), token); + final var nft = enhancement + .nativeOperations() + .getNft(token.tokenIdOrElse(ZERO_TOKEN_ID).tokenNum(), serialNumber); + final var status = nft != null ? SUCCESS : ResponseCodeEnum.INVALID_TOKEN_NFT_SERIAL_NUMBER; + return fullResultsFor(status, gasCalculator.viewGasRequirement(), token, nft); } @Override protected @NonNull FullResult viewCallResultWith( @NonNull final ResponseCodeEnum status, final long gasRequirement) { - return fullResultsFor(status, gasRequirement, Token.DEFAULT); + return fullResultsFor(status, gasRequirement, Token.DEFAULT, null); } private @NonNull FullResult fullResultsFor( - @NonNull final ResponseCodeEnum status, final long gasRequirement, @NonNull final Token token) { + @NonNull final ResponseCodeEnum status, + final long gasRequirement, + @NonNull final Token token, + @Nullable final Nft nft) { requireNonNull(status); requireNonNull(token); final var ledgerConfig = configuration.getConfigData(LedgerConfig.class); final var ledgerId = Bytes.wrap(ledgerConfig.id().toByteArray()).toString(); - final var nft = enhancement - .nativeOperations() - .getNft(token.tokenIdOrElse(ZERO_TOKEN_ID).tokenNum(), serialNumber); // @Future remove to revert #9074 after modularization is completed if (isStaticCall && (status != SUCCESS || nft == null)) { return revertResult(status, gasCalculator.viewGasRequirement()); @@ -105,9 +108,6 @@ public NftTokenInfoCall( private Account getOwnerAccount(Nft nft, Token token) { final var explicitId = nft.ownerIdOrElse(AccountID.DEFAULT); - if (explicitId.account().kind() == AccountID.AccountOneOfType.UNSET) { - return null; - } final long ownerNum; if (explicitId.hasAccountNum()) { ownerNum = explicitId.accountNumOrThrow(); diff --git a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/nfttokeninfo/NftTokenInfoCallTest.java b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/nfttokeninfo/NftTokenInfoCallTest.java index 5d5aeb604fa8..f47b9873925e 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/nfttokeninfo/NftTokenInfoCallTest.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/nfttokeninfo/NftTokenInfoCallTest.java @@ -93,6 +93,20 @@ void returnsNftTokenInfoStatusForPresentToken() { result.getOutput()); } + @Test + void returnsWhenTryingToFetchTokenWithInvalidSerialNumber() { + when(config.getConfigData(LedgerConfig.class)).thenReturn(ledgerConfig); + when(ledgerConfig.id()).thenReturn(com.hedera.pbj.runtime.io.buffer.Bytes.fromHex(LEDGER_ID)); + when(nativeOperations.getNft(FUNGIBLE_EVERYTHING_TOKEN.tokenId().tokenNum(), 2L)) + .thenReturn(null); + when(nativeOperations.getAccount(1234L)).thenReturn(A_NEW_ACCOUNT); + + final var subject = + new NftTokenInfoCall(gasCalculator, mockEnhancement(), false, FUNGIBLE_EVERYTHING_TOKEN, 2L, config); + final var result = subject.execute().fullResult().result(); + assertEquals(MessageFrame.State.COMPLETED_SUCCESS, result.getState()); + } + @Test void revertsWhenTryingToFetchMissingTokenStaticCall() { when(config.getConfigData(LedgerConfig.class)).thenReturn(ledgerConfig); @@ -107,7 +121,7 @@ void revertsWhenTryingToFetchMissingTokenStaticCall() { } @Test - void revertsWhenFetchingTokenWithNoOwnerAccount() { + void revertsWhenTryingToFetchTokenWithNoOwnerAccount() { when(config.getConfigData(LedgerConfig.class)).thenReturn(ledgerConfig); when(ledgerConfig.id()).thenReturn(com.hedera.pbj.runtime.io.buffer.Bytes.fromHex(LEDGER_ID)); when(nativeOperations.getNft(FUNGIBLE_EVERYTHING_TOKEN.tokenId().tokenNum(), 2L))