Skip to content

Commit

Permalink
Updated Tests (#9672)
Browse files Browse the repository at this point in the history
Signed-off-by: ilko-iliev-lime <ilko.iliev@limechain.tech> <matt.hess@swirldslabs.com>
  • Loading branch information
mhess-swl authored and ilko-iliev-lime committed Nov 6, 2023
1 parent 3adfc8b commit ad5b939
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,18 @@

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

import static com.hedera.hapi.node.base.ResponseCodeEnum.INVALID_TOKEN_ID;
import static com.hedera.hapi.node.base.ResponseCodeEnum.SUCCESS;
import static com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.ReturnTypes.ZERO_ACCOUNT_ID;
import static com.hedera.node.app.service.contract.impl.test.TestHelpers.CIVILIAN_OWNED_NFT;
import static com.hedera.node.app.service.contract.impl.test.TestHelpers.EXPECTED_FIXED_CUSTOM_FEES;
import static com.hedera.node.app.service.contract.impl.test.TestHelpers.EXPECTED_FRACTIONAL_CUSTOM_FEES;
import static com.hedera.node.app.service.contract.impl.test.TestHelpers.EXPECTED_ROYALTY_CUSTOM_FEES;
import static com.hedera.node.app.service.contract.impl.test.TestHelpers.EXPECTE_DEFAULT_KEYLIST;
import static com.hedera.node.app.service.contract.impl.test.TestHelpers.EXPECTE_KEYLIST;
import static com.hedera.node.app.service.contract.impl.test.TestHelpers.FUNGIBLE_EVERYTHING_TOKEN;
import static com.hedera.node.app.service.contract.impl.test.TestHelpers.LEDGER_ID;
import static com.hedera.node.app.service.contract.impl.test.TestHelpers.SENDER_ID;
import static com.hedera.node.app.service.contract.impl.test.TestHelpers.revertOutputFor;
import static com.hedera.hapi.node.base.ResponseCodeEnum.*;
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.mockito.Mockito.when;

import com.esaulpaugh.headlong.abi.Tuple;
import com.hedera.hapi.node.base.Timestamp;
import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.nfttokeninfo.NftTokenInfoCall;
import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.nfttokeninfo.NftTokenInfoTranslator;
import com.hedera.node.app.service.contract.impl.test.exec.systemcontracts.hts.HtsCallTestBase;
import com.hedera.node.config.data.LedgerConfig;
import com.swirlds.config.api.Configuration;
import java.util.Collections;
import org.apache.tuweni.bytes.Bytes;
import org.hyperledger.besu.evm.frame.MessageFrame;
import org.junit.jupiter.api.Test;
Expand All @@ -59,14 +46,14 @@ class NftTokenInfoCallTest extends HtsCallTestBase {
@Test
void returnsNftTokenInfoStatusForPresentToken() {
when(config.getConfigData(LedgerConfig.class)).thenReturn(ledgerConfig);
final var expectedLedgerId = com.hedera.pbj.runtime.io.buffer.Bytes.fromHex(LEDGER_ID);
when(ledgerConfig.id()).thenReturn(expectedLedgerId);
when(ledgerConfig.id()).thenReturn(com.hedera.pbj.runtime.io.buffer.Bytes.fromHex(LEDGER_ID));
when(nativeOperations.getNft(FUNGIBLE_EVERYTHING_TOKEN.tokenId().tokenNum(), 2L))
.thenReturn(CIVILIAN_OWNED_NFT);
when(nativeOperations.getAccount(A_NEW_ACCOUNT_ID.accountNum())).thenReturn(A_NEW_ACCOUNT);

final var subject =
new NftTokenInfoCall(gasCalculator, mockEnhancement(), false, FUNGIBLE_EVERYTHING_TOKEN, 2L, config);

String ledgerIdBytes = com.hedera.pbj.runtime.io.buffer.Bytes.fromHex(LEDGER_ID).toString();
final var result = subject.execute().fullResult().result();

assertEquals(MessageFrame.State.COMPLETED_SUCCESS, result.getState());
Expand Down Expand Up @@ -94,66 +81,31 @@ void returnsNftTokenInfoStatusForPresentToken() {
EXPECTED_FIXED_CUSTOM_FEES.toArray(new Tuple[0]),
EXPECTED_FRACTIONAL_CUSTOM_FEES.toArray(new Tuple[0]),
EXPECTED_ROYALTY_CUSTOM_FEES.toArray(new Tuple[0]),
Bytes.wrap(expectedLedgerId.toByteArray())
.toString()),
ledgerIdBytes),
2L,
headlongAddressOf(CIVILIAN_OWNED_NFT.ownerId()),
headlongAddressOf(A_NEW_ACCOUNT),
1000000L,
com.hedera.pbj.runtime.io.buffer.Bytes.wrap("SOLD")
.toByteArray(),
headlongAddressOf(CIVILIAN_OWNED_NFT.spenderId())))
headlongAddressOf(B_NEW_ACCOUNT)))
.array()),
result.getOutput());
}

@Test
void returnsNftTokenInfoStatusForMissingToken() {
void revertsWhenTryingToFetchMissingTokenNonStaticCall() {
when(config.getConfigData(LedgerConfig.class)).thenReturn(ledgerConfig);
final var expectedLedgerId = com.hedera.pbj.runtime.io.buffer.Bytes.fromHex("01");
when(ledgerConfig.id()).thenReturn(expectedLedgerId);
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.COMPLETED_SUCCESS, result.getState());
assertEquals(
Bytes.wrap(NftTokenInfoTranslator.NON_FUNGIBLE_TOKEN_INFO
.getOutputs()
.encodeElements(
INVALID_TOKEN_ID.protoOrdinal(),
Tuple.of(
Tuple.of(
Tuple.of(
"",
"",
headlongAddressOf(ZERO_ACCOUNT_ID),
"",
false,
0L,
false,
EXPECTE_DEFAULT_KEYLIST.toArray(new Tuple[0]),
Tuple.of(0L, headlongAddressOf(ZERO_ACCOUNT_ID), 0L)),
0L,
false,
false,
false,
Collections.emptyList().toArray(new Tuple[0]),
Collections.emptyList().toArray(new Tuple[0]),
Collections.emptyList().toArray(new Tuple[0]),
Bytes.wrap(expectedLedgerId.toByteArray())
.toString()),
0L,
headlongAddressOf(ZERO_ACCOUNT_ID),
new Timestamp(0, 0).seconds(),
com.hedera.pbj.runtime.io.buffer.Bytes.EMPTY.toByteArray(),
headlongAddressOf(ZERO_ACCOUNT_ID)))
.array()),
result.getOutput());
assertEquals(MessageFrame.State.REVERT, result.getState());
assertEquals(revertOutputFor(INVALID_TOKEN_ID), result.getOutput());
}

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

Expand All @@ -164,4 +116,19 @@ void returnsNftTokenInfoStatusForMissingTokenStaticCall() {
assertEquals(MessageFrame.State.REVERT, result.getState());
assertEquals(revertOutputFor(INVALID_TOKEN_ID), result.getOutput());
}

@Test
void revertsWhenFetchingTokenWithNoOwnerAccount() {
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(CIVILIAN_OWNED_NFT);

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

assertEquals(MessageFrame.State.REVERT, result.getState());
assertEquals(revertOutputFor(INVALID_ACCOUNT_ID), result.getOutput());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public List<HapiSpec> getSpecsInSuite() {
htsOwnershipCheckWorksWithAliasAddress());
}

@HapiTest
private HapiSpec htsOwnershipCheckWorksWithAliasAddress() {
final AtomicReference<AccountID> ecdsaAccountId = new AtomicReference<>();
final AtomicReference<ByteString> ecdsaAccountIdLongZeroAddress = new AtomicReference<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

/* ! WARNING - Requires a RecordCache TTL of 3s to pass ! */
/**
* ! WARNING - Requires a RecordCache TTL of 3s to pass !
*
* <p>Even with a 3s TTL, a number of these tests fail. FUTURE: revisit
* */
@HapiTestSuite
public class TxnRecordRegression extends HapiSuite {
static final Logger log = LogManager.getLogger(TxnRecordRegression.class);
Expand All @@ -67,6 +71,7 @@ public List<HapiSpec> getSpecsInSuite() {
});
}

// FUTURE: revisit this test, which isn't passing in modular or mono code (even with a 3 second TTL)
private HapiSpec recordAvailableInPayerState() {
return defaultHapiSpec("RecordAvailableInPayerState")
.given(
Expand All @@ -80,6 +85,7 @@ private HapiSpec recordAvailableInPayerState() {
getTxnRecord("recordTxn").hasPriority(recordWith().status(SUCCESS)));
}

// FUTURE: revisit this test, which isn't passing in modular or mono code (even with a 3 second TTL)
private HapiSpec deletedAccountRecordsUnavailableAfterTtl() {
return defaultHapiSpec("DeletedAccountRecordsUnavailableAfterTtl")
.given(
Expand Down Expand Up @@ -121,6 +127,7 @@ private HapiSpec recordUnavailableBeforeConsensus() {
getTxnRecord("success").hasAnswerOnlyPrecheck(RECORD_NOT_FOUND));
}

// FUTURE: revisit this test, which isn't passing in modular or mono code (even with a 3 second TTL)
private HapiSpec recordUnavailableIfRejectedInPrecheck() {
return defaultHapiSpec("RecordUnavailableIfRejectedInPrecheck")
.given(usableTxnIdNamed("failingTxn"), cryptoCreate("misc").balance(1_000L))
Expand Down

0 comments on commit ad5b939

Please sign in to comment.