From f9074f1f5c98e3086447ce90d058f7872ceedc4c Mon Sep 17 00:00:00 2001 From: Bilyana Gospodinova Date: Fri, 13 Sep 2024 15:05:43 +0300 Subject: [PATCH 1/3] Add some historical negative tests Signed-off-by: Bilyana Gospodinova --- hedera-mirror-web3/build.gradle.kts | 3 +- ...ractContractCallServiceHistoricalTest.java | 313 +++++++++++++++++ ...ractCallServiceHistoricalNegativeTest.java | 322 ++++++++++++++++++ ...ctCallServicePrecompileHistoricalTest.java | 154 +-------- .../web3/utils/ContractCallTestUtil.java | 2 + .../solidity/EvmCodesHistorical.sol | 5 + ...cationPrecompileTestContractHistorical.sol | 20 ++ 7 files changed, 667 insertions(+), 152 deletions(-) create mode 100644 hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/AbstractContractCallServiceHistoricalTest.java create mode 100644 hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallServiceHistoricalNegativeTest.java create mode 100644 hedera-mirror-web3/src/testHistorical/solidity/ModificationPrecompileTestContractHistorical.sol diff --git a/hedera-mirror-web3/build.gradle.kts b/hedera-mirror-web3/build.gradle.kts index 7b2b22181b7..fc8351277ca 100644 --- a/hedera-mirror-web3/build.gradle.kts +++ b/hedera-mirror-web3/build.gradle.kts @@ -138,7 +138,7 @@ tasks.register("resolveSolidityHistorical", SolidityResolve::class) { group = "historical" description = "Resolves the historical solidity version $historicalSolidityVersion" sources = fileTree("src/testHistorical/solidity") - allowPaths = setOf("src/testHistorical/solidity") + setAllowPaths(setOf("src/testHistorical/solidity")) val packageJsonFile = "./build/node_modules/@openzeppelin/contracts/package.json" packageJson = file(packageJsonFile) @@ -153,6 +153,7 @@ afterEvaluate { version = historicalSolidityVersion source = fileTree("src/testHistorical/solidity") { include("*.sol") } dependsOn("extractContracts") + dependsOn("resolveSolidityHistorical") } } diff --git a/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/AbstractContractCallServiceHistoricalTest.java b/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/AbstractContractCallServiceHistoricalTest.java new file mode 100644 index 00000000000..49db0da3180 --- /dev/null +++ b/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/AbstractContractCallServiceHistoricalTest.java @@ -0,0 +1,313 @@ +/* + * Copyright (C) 2024 Hedera Hashgraph, LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.hedera.mirror.web3.service; + +import static com.hedera.mirror.web3.utils.ContractCallTestUtil.SENDER_ALIAS; +import static com.hedera.mirror.web3.utils.ContractCallTestUtil.SENDER_PUBLIC_KEY; + +import com.google.common.collect.Range; +import com.hedera.mirror.common.domain.balance.AccountBalance; +import com.hedera.mirror.common.domain.balance.TokenBalance; +import com.hedera.mirror.common.domain.entity.Entity; +import com.hedera.mirror.common.domain.entity.EntityId; +import com.hedera.mirror.common.domain.entity.EntityType; +import com.hedera.mirror.common.domain.token.AbstractCustomFee; +import com.hedera.mirror.common.domain.token.FallbackFee; +import com.hedera.mirror.common.domain.token.FractionalFee; +import com.hedera.mirror.common.domain.token.RoyaltyFee; +import com.hedera.mirror.common.domain.token.TokenFreezeStatusEnum; +import com.hedera.mirror.common.domain.token.TokenKycStatusEnum; +import com.hedera.mirror.common.domain.token.TokenTypeEnum; +import com.hedera.mirror.common.domain.transaction.RecordFile; +import com.hedera.mirror.web3.viewmodel.BlockType; +import java.util.ArrayList; +import java.util.List; +import org.apache.commons.lang3.tuple.Pair; + +public abstract class AbstractContractCallServiceHistoricalTest extends AbstractContractCallServiceTest { + + protected Range setUpHistoricalContext(final long blockNumber) { + final var recordFile = persistRecordFile(blockNumber); + return setupHistoricalStateInService(blockNumber, recordFile); + } + + protected RecordFile persistRecordFile(final long blockNumber) { + return domainBuilder.recordFile().customize(f -> f.index(blockNumber)).persist(); + } + + protected Range setupHistoricalStateInService(final long blockNumber, final RecordFile recordFile) { + testWeb3jService.setBlockType(BlockType.of(String.valueOf(blockNumber))); + final var historicalRange = Range.closedOpen(recordFile.getConsensusStart(), recordFile.getConsensusEnd()); + testWeb3jService.setHistoricalRange(historicalRange); + return historicalRange; + } + + protected void setupHistoricalStateInService(final long blockNumber, final Range timestampRange) { + testWeb3jService.setBlockType(BlockType.of(String.valueOf(blockNumber))); + testWeb3jService.setHistoricalRange(timestampRange); + } + + protected Pair persistAccountTokenRelationshipHistorical( + final boolean isFrozen, final Range historicalRange) { + final var account = persistAccountEntityHistoricalWithAlias(historicalRange); + final var tokenEntity = persistTokenEntityHistorical(historicalRange); + persistFungibleTokenHistorical(tokenEntity, historicalRange); + domainBuilder + .tokenAccountHistory() + .customize(ta -> ta.tokenId(tokenEntity.getId()) + .accountId(account.getId()) + .kycStatus(TokenKycStatusEnum.GRANTED) + .freezeStatus(isFrozen ? TokenFreezeStatusEnum.FROZEN : TokenFreezeStatusEnum.UNFROZEN) + .associated(true) + .timestampRange(historicalRange)) + .persist(); + return Pair.of(account, tokenEntity); + } + + protected void persistTokenAccountFrozenRelationshipHistorical( + final Entity tokenEntity, final Entity accountEntity, final Range historicalRange) { + domainBuilder + .tokenAccountHistory() + .customize(ta -> ta.tokenId(tokenEntity.getId()) + .accountId(accountEntity.getId()) + .kycStatus(TokenKycStatusEnum.GRANTED) + .freezeStatus(TokenFreezeStatusEnum.FROZEN) + .associated(true) + .timestampRange(historicalRange)) + .persist(); + } + + protected Entity persistAccountEntityHistorical(final Range timestampRange) { + return domainBuilder + .entity() + .customize(e -> e.type(EntityType.ACCOUNT) + .deleted(false) + .balance(1_000_000_000_000L) + .timestampRange(timestampRange) + .createdTimestamp(timestampRange.lowerEndpoint())) + .persist(); + } + + protected Entity persistAccountEntityNoEvmAddressHistorical(final Range timestampRange) { + return domainBuilder + .entity() + .customize(e -> e.type(EntityType.ACCOUNT) + .deleted(false) + .evmAddress(null) + .balance(1_000_000_000_000L) + .timestampRange(timestampRange) + .createdTimestamp(timestampRange.lowerEndpoint())) + .persist(); + } + + protected Entity persistAccountEntityHistoricalWithAlias(final Range timestampRange) { + return domainBuilder + .entity() + .customize(e -> e.type(EntityType.ACCOUNT) + .alias(SENDER_PUBLIC_KEY.toByteArray()) + .deleted(false) + .evmAddress(SENDER_ALIAS.toArray()) + .balance(1_000_000_000_000L) + .createdTimestamp(timestampRange.lowerEndpoint()) + .timestampRange(timestampRange)) + .persist(); + } + + protected Entity persistAccountWithBalanceHistorical(final long balance, final Range timestampRange) { + final var entity = domainBuilder + .entity() + .customize(e -> e.balance(balance) + .timestampRange(timestampRange) + .createdTimestamp(timestampRange.lowerEndpoint())) + .persist(); + persistAccountBalanceHistorical(entity.toEntityId(), balance, timestampRange); + + return entity; + } + + protected void persistAccountBalanceHistorical( + final EntityId entityId, final long balance, final Range timestampRange) { + // There needs to be an entry for account 0.0.2 in order for the account balance query to return the correct + // result + domainBuilder + .accountBalance() + .customize(ab -> ab.id(new AccountBalance.Id(timestampRange.lowerEndpoint(), EntityId.of(2))) + .balance(balance)) + .persist(); + domainBuilder + .accountBalance() + .customize(ab -> ab.id(new AccountBalance.Id(timestampRange.lowerEndpoint(), entityId)) + .balance(balance)) + .persist(); + } + + protected void persistTokenBalanceHistorical( + final EntityId accountId, final EntityId tokenId, final long balance, final Range timestampRange) { + // There needs to be an entry for account 0.0.2 in order for the token balance query to return the correct + // result + domainBuilder + .accountBalance() + .customize(ab -> ab.id(new AccountBalance.Id(timestampRange.lowerEndpoint(), EntityId.of(2))) + .balance(balance)) + .persist(); + domainBuilder + .tokenBalance() + .customize(ab -> ab.id(new TokenBalance.Id(timestampRange.lowerEndpoint(), accountId, tokenId)) + .balance(balance)) + .persist(); + } + + protected Entity persistTokenEntityHistorical(final Range timestampRange) { + return domainBuilder + .entity() + .customize(e -> e.type(EntityType.TOKEN).timestampRange(timestampRange)) + .persist(); + } + + protected void persistFungibleTokenHistorical(Entity tokenEntity, final Range timestampRange) { + domainBuilder + .tokenHistory() + .customize(t -> t.tokenId(tokenEntity.getId()) + .type(TokenTypeEnum.FUNGIBLE_COMMON) + .timestampRange(timestampRange) + .createdTimestamp(timestampRange.lowerEndpoint())) + .persist(); + } + + protected Entity persistFungibleTokenHistorical(final Range timestampRange) { + final var entity = persistTokenEntityHistorical(timestampRange); + persistFungibleTokenHistorical(entity, timestampRange); + return entity; + } + + protected Entity persistNftHistorical(final Range timestampRange) { + final var tokenEntity = persistTokenEntityHistorical(timestampRange); + domainBuilder + .tokenHistory() + .customize(t -> t.tokenId(tokenEntity.getId()) + .type(TokenTypeEnum.NON_FUNGIBLE_UNIQUE) + .timestampRange(timestampRange)) + .persist(); + domainBuilder + .nftHistory() + .customize(n -> n.tokenId(tokenEntity.getId()).serialNumber(1L).timestampRange(timestampRange)) + .persist(); + + return tokenEntity; + } + + protected void persistTokenAllowanceHistorical( + final Entity tokenEntity, + final Entity owner, + final Entity spender, + final long amount, + final Range timestampRange) { + domainBuilder + .tokenAllowanceHistory() + .customize(a -> a.tokenId(tokenEntity.getId()) + .owner(owner.getNum()) + .spender(spender.getNum()) + .amount(amount) + .amountGranted(amount) + .timestampRange(timestampRange)) + .persist(); + } + + protected void persistNftAllowanceHistorical( + final Entity tokenEntity, final Entity owner, final Entity spender, final Range timestampRange) { + domainBuilder + .nftAllowanceHistory() + .customize(a -> a.tokenId(tokenEntity.getId()) + .owner(owner.getNum()) + .spender(spender.getNum()) + .timestampRange(timestampRange)) + .persist(); + } + + protected void persistCryptoAllowanceHistorical( + final Entity owner, final EntityId spender, final long amount, final Range timestampRange) { + domainBuilder + .cryptoAllowanceHistory() + .customize(ca -> ca.owner(owner.toEntityId().getId()) + .spender(spender.getId()) + .payerAccountId(owner.toEntityId()) + .amount(amount) + .amountGranted(amount) + .timestampRange(timestampRange)) + .persist(); + } + + protected AbstractCustomFee persistCustomFeesWithFeeCollectorHistorical( + final Entity feeCollector, + final Entity tokenEntity, + final TokenTypeEnum tokenType, + final Range timestampRange) { + final var fixedFee = com.hedera.mirror.common.domain.token.FixedFee.builder() + .allCollectorsAreExempt(true) + .amount(domainBuilder.number()) + .collectorAccountId(feeCollector.toEntityId()) + .denominatingTokenId(tokenEntity.toEntityId()) + .build(); + + final var fractionalFee = TokenTypeEnum.FUNGIBLE_COMMON.equals(tokenType) + ? FractionalFee.builder() + .allCollectorsAreExempt(true) + .collectorAccountId(feeCollector.toEntityId()) + .denominator(domainBuilder.number()) + .maximumAmount(domainBuilder.number()) + .minimumAmount(1L) + .numerator(domainBuilder.number()) + .netOfTransfers(true) + .build() + : null; + + final var fallbackFee = FallbackFee.builder() + .amount(domainBuilder.number()) + .denominatingTokenId(tokenEntity.toEntityId()) + .build(); + + final var royaltyFee = TokenTypeEnum.NON_FUNGIBLE_UNIQUE.equals(tokenType) + ? RoyaltyFee.builder() + .allCollectorsAreExempt(true) + .collectorAccountId(feeCollector.toEntityId()) + .denominator(domainBuilder.number()) + .fallbackFee(fallbackFee) + .numerator(domainBuilder.number()) + .build() + : null; + + if (TokenTypeEnum.FUNGIBLE_COMMON.equals(tokenType)) { + return domainBuilder + .customFeeHistory() + .customize(f -> f.tokenId(tokenEntity.getId()) + .fixedFees(List.of(fixedFee)) + .fractionalFees(List.of(fractionalFee)) + .royaltyFees(new ArrayList<>()) + .timestampRange(timestampRange)) + .persist(); + } else { + return domainBuilder + .customFeeHistory() + .customize(f -> f.tokenId(tokenEntity.getId()) + .fixedFees(List.of(fixedFee)) + .royaltyFees(List.of(royaltyFee)) + .fractionalFees(new ArrayList<>()) + .timestampRange(timestampRange)) + .persist(); + } + } +} diff --git a/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallServiceHistoricalNegativeTest.java b/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallServiceHistoricalNegativeTest.java new file mode 100644 index 00000000000..67ce0cdd222 --- /dev/null +++ b/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallServiceHistoricalNegativeTest.java @@ -0,0 +1,322 @@ +/* + * Copyright (C) 2024 Hedera Hashgraph, LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.hedera.mirror.web3.service; + +import static com.hedera.mirror.web3.evm.utils.EvmTokenUtils.entityIdFromEvmAddress; +import static com.hedera.mirror.web3.utils.ContractCallTestUtil.EVM_V_30_BLOCK; +import static com.hedera.mirror.web3.utils.ContractCallTestUtil.EVM_V_34_BLOCK; +import static com.hedera.mirror.web3.utils.ContractCallTestUtil.EVM_V_38_BLOCK; +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; + +import com.hedera.mirror.common.domain.token.TokenTypeEnum; +import com.hedera.mirror.web3.exception.MirrorEvmTransactionException; +import com.hedera.mirror.web3.web3j.generated.EvmCodesHistorical; +import com.hedera.mirror.web3.web3j.generated.ModificationPrecompileTestContract; +import com.hedera.mirror.web3.web3j.generated.ModificationPrecompileTestContract.AccountAmount; +import com.hedera.mirror.web3.web3j.generated.ModificationPrecompileTestContract.TransferList; +import com.hedera.mirror.web3.web3j.generated.PrecompileTestContractHistorical; +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.List; +import org.hyperledger.besu.datatypes.Address; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +class ContractCallServiceHistoricalNegativeTest extends AbstractContractCallServiceHistoricalTest { + + @Test + void contractNotPersistedYetThrowsException() { + // Given + final var evm30RecordFile = persistRecordFile(EVM_V_30_BLOCK); + final var historicalRangeAfterEvm34 = setUpHistoricalContext(EVM_V_34_BLOCK); + final var tokenEntity = persistNftHistorical(historicalRangeAfterEvm34); + + // Deploy the contract against block X, make the contract call against block (X-1) -> throw an exception as the + // contract does not exist yet. + final var contract = testWeb3jService.deploy(PrecompileTestContractHistorical::deploy); + setupHistoricalStateInService(EVM_V_30_BLOCK, evm30RecordFile); + + // When + final var functionCall = contract.call_isTokenAddress(getAddressFromEntity(tokenEntity)); + + // Then + assertThatThrownBy(functionCall::send).isInstanceOf(MirrorEvmTransactionException.class); + } + + // Tests TokenRepository and NftRepository + @ParameterizedTest + @ValueSource(booleans = {false, true}) + void tokenNotPersistedYetThrowsException(final boolean isNft) { + // Given + final var evm30RecordFile = persistRecordFile(EVM_V_30_BLOCK); + final var historicalRangeAfterEvm34 = setUpHistoricalContext(EVM_V_34_BLOCK); + final var tokenEntity = isNft + ? persistNftHistorical(historicalRangeAfterEvm34) + : persistFungibleTokenHistorical(historicalRangeAfterEvm34); + + setupHistoricalStateInService(EVM_V_30_BLOCK, evm30RecordFile); + final var contract = testWeb3jService.deploy(PrecompileTestContractHistorical::deploy); + + // Persist the token against block X, make the call against block (X-1) -> throw an exception as the token does + // not exist yet. + // When + final var functionCall = contract.call_isTokenAddress(getAddressFromEntity(tokenEntity)); + + // Then + assertThatThrownBy(functionCall::send).isInstanceOf(MirrorEvmTransactionException.class); + } + + // Tests TokenAccountRepository + @Test + void tokenAccountRelationshipNotPersistedYetReturnsFalse() throws Exception { + // Given + final var evm30RecordFile = persistRecordFile(EVM_V_30_BLOCK); + final var evm30HistoricalRange = setupHistoricalStateInService(EVM_V_30_BLOCK, evm30RecordFile); + final var historicalRangeAfterEvm34 = setUpHistoricalContext(EVM_V_34_BLOCK); + final var tokenEntity = persistTokenEntityHistorical(evm30HistoricalRange); + persistFungibleTokenHistorical(tokenEntity, evm30HistoricalRange); + final var accountEntity = persistAccountEntityHistoricalWithAlias(evm30HistoricalRange); + persistTokenAccountFrozenRelationshipHistorical(tokenEntity, accountEntity, historicalRangeAfterEvm34); + + setupHistoricalStateInService(EVM_V_30_BLOCK, evm30RecordFile); + final var contract = testWeb3jService.deploy(PrecompileTestContractHistorical::deploy); + + // Persist the token and the account in block (X-1), but the relationship in block X. The call against block + // (X-1) + // should fail as the association is not available yet. + // When + final var functionCall = + contract.call_isTokenFrozen(getAddressFromEntity(tokenEntity), getAddressFromEntity(accountEntity)); + + // Then + assertThat(functionCall.send()).isFalse(); + } + + // Tests TokenAllowanceRepository + @Test + void getAllowanceForFungibleTokenNotPersistedYetReturnsZero() throws Exception { + // Given + final var evm30RecordFile = persistRecordFile(EVM_V_30_BLOCK); + final var evm30HistoricalRange = setupHistoricalStateInService(EVM_V_30_BLOCK, evm30RecordFile); + final var historicalRangeAfterEvm34 = setUpHistoricalContext(EVM_V_34_BLOCK); + final var amountGranted = 50L; + final var owner = persistAccountEntityHistorical(evm30HistoricalRange); + final var spender = persistAccountEntityHistorical(evm30HistoricalRange); + final var tokenEntity = persistTokenEntityHistorical(evm30HistoricalRange); + persistFungibleTokenHistorical(tokenEntity, evm30HistoricalRange); + + // Persist the token and the accounts in block (X-1), but the token allowance in block X. The call against block + // (X-1) should fail as the allowance is not available yet. + persistTokenAllowanceHistorical(tokenEntity, owner, spender, amountGranted, historicalRangeAfterEvm34); + + setupHistoricalStateInService(EVM_V_30_BLOCK, evm30RecordFile); + final var contract = testWeb3jService.deploy(PrecompileTestContractHistorical::deploy); + + // When + final var functionCall = contract.call_htsAllowance( + getAddressFromEntity(tokenEntity), getAddressFromEntity(owner), getAddressFromEntity(spender)); + + // Then + assertThat(functionCall.send()).isEqualTo(BigInteger.ZERO); + } + + // Tests NftAllowanceRepository + @Test + void getAllowanceForNftNotPersistedYetReturnsZero() throws Exception { + // Given + final var evm30RecordFile = persistRecordFile(EVM_V_30_BLOCK); + final var evm30HistoricalRange = setupHistoricalStateInService(EVM_V_30_BLOCK, evm30RecordFile); + final var historicalRangeAfterEvm34 = setUpHistoricalContext(EVM_V_34_BLOCK); + final var owner = persistAccountEntityHistorical(evm30HistoricalRange); + final var spender = persistAccountEntityHistorical(evm30HistoricalRange); + final var tokenEntity = persistNftHistorical(evm30HistoricalRange); + + // Persist the token and the accounts in block (X-1), but the nft allowance in block X. The call against block + // (X-1) + // should fail as the allowance is not available yet. + persistNftAllowanceHistorical(tokenEntity, owner, spender, historicalRangeAfterEvm34); + + setupHistoricalStateInService(EVM_V_30_BLOCK, evm30RecordFile); + final var contract = testWeb3jService.deploy(PrecompileTestContractHistorical::deploy); + + // When + final var functionCall = contract.call_htsAllowance( + getAddressFromEntity(tokenEntity), getAddressFromEntity(owner), getAddressFromEntity(spender)); + + // Then + assertThat(functionCall.send()).isEqualTo(BigInteger.ZERO); + } + + // Tests CustomFeeRepository + @Test + void getFungibleTokenInfoCustomFeesNotPersistedYetReturnsZero() throws Exception { + // Given + final var evm30RecordFile = persistRecordFile(EVM_V_30_BLOCK); + final var evm30HistoricalRange = setupHistoricalStateInService(EVM_V_30_BLOCK, evm30RecordFile); + final var historicalRangeAfterEvm34 = setUpHistoricalContext(EVM_V_34_BLOCK); + + final var tokenEntity = persistFungibleTokenHistorical(evm30HistoricalRange); + final var feeCollector = persistAccountEntityHistorical(evm30HistoricalRange); + + // Persist the token and the account in block (X-1), but the custom fees in block X. The call against block + // (X-1) + // should fail as the custom fees are not available yet. + persistCustomFeesWithFeeCollectorHistorical( + feeCollector, tokenEntity, TokenTypeEnum.FUNGIBLE_COMMON, historicalRangeAfterEvm34); + + setupHistoricalStateInService(EVM_V_30_BLOCK, evm30RecordFile); + final var contract = testWeb3jService.deploy(PrecompileTestContractHistorical::deploy); + + // When + final var result = contract.call_getInformationForFungibleToken(getAddressFromEntity(tokenEntity)) + .send(); + + // Then + assertThat(result.tokenInfo.fixedFees).usingRecursiveComparison().isEqualTo(List.of()); + assertThat(result.tokenInfo.fractionalFees).usingRecursiveComparison().isEqualTo(List.of()); + assertThat(result.tokenInfo.royaltyFees).usingRecursiveComparison().isEqualTo(List.of()); + } + + // Tests CustomFeeRepository + @Test + void getNftInfoCustomFeesNotPersistedYetReturnsZero() throws Exception { + // Given + final var evm30RecordFile = persistRecordFile(EVM_V_30_BLOCK); + final var evm30HistoricalRange = setupHistoricalStateInService(EVM_V_30_BLOCK, evm30RecordFile); + final var historicalRangeAfterEvm34 = setUpHistoricalContext(EVM_V_34_BLOCK); + + final var tokenEntity = persistNftHistorical(evm30HistoricalRange); + final var feeCollector = persistAccountEntityHistorical(evm30HistoricalRange); + + // Persist the token and the account in block (X-1), but the custom fees in block X. The call against block + // (X-1) + // should fail as the custom fees are not available yet. + persistCustomFeesWithFeeCollectorHistorical( + feeCollector, tokenEntity, TokenTypeEnum.NON_FUNGIBLE_UNIQUE, historicalRangeAfterEvm34); + + setupHistoricalStateInService(EVM_V_30_BLOCK, evm30RecordFile); + final var contract = testWeb3jService.deploy(PrecompileTestContractHistorical::deploy); + + // When + final var result = contract.call_getInformationForToken(getAddressFromEntity(tokenEntity)) + .send(); + + // Then + assertThat(result.fixedFees).usingRecursiveComparison().isEqualTo(List.of()); + assertThat(result.fractionalFees).usingRecursiveComparison().isEqualTo(List.of()); + assertThat(result.royaltyFees).usingRecursiveComparison().isEqualTo(List.of()); + } + + // Tests TokenBalanceRepository + @Test + void tokenBalanceNotPersistedYetThrowsException() { + // Given + final var evm38RecordFile = persistRecordFile(EVM_V_38_BLOCK); + final var evm38HistoricalRange = setupHistoricalStateInService(EVM_V_38_BLOCK, evm38RecordFile); + final var historicalRangeAfterEvm38 = setUpHistoricalContext(EVM_V_38_BLOCK + 1); + + final var accountEntity = persistAccountEntityHistorical(evm38HistoricalRange); + final var receiverEntity = persistAccountEntityHistorical(evm38HistoricalRange); + final var tokenEntity = persistTokenEntityHistorical(evm38HistoricalRange); + domainBuilder + .tokenHistory() + .customize(t -> t.tokenId(tokenEntity.getId()) + .type(TokenTypeEnum.FUNGIBLE_COMMON) + .kycKey(null) + .treasuryAccountId(accountEntity.toEntityId()) + .timestampRange(evm38HistoricalRange)) + .persist(); + persistTokenBalanceHistorical(accountEntity.toEntityId(), tokenEntity.toEntityId(), 1L, evm38HistoricalRange); + + // Persist the token, the account, balance1 in block (X-1) and balance2 in block X, where balance1 < balance2. + // The call against block (X-1) + // should fail with balance2, since the bigger balance is not available at this point. + persistTokenBalanceHistorical( + accountEntity.toEntityId(), tokenEntity.toEntityId(), 2L, historicalRangeAfterEvm38); + + setupHistoricalStateInService(EVM_V_38_BLOCK, evm38HistoricalRange); + final var contract = testWeb3jService.deploy(ModificationPrecompileTestContract::deploy); + + // When + final var functionCall = contract.call_transferTokenExternal( + getAddressFromEntity(tokenEntity), + getAddressFromEntity(accountEntity), + getAddressFromEntity(receiverEntity), + BigInteger.valueOf(2)); + + // Then + assertThatThrownBy(functionCall::send).isInstanceOf(MirrorEvmTransactionException.class); + } + + @Test + void transferWithNoPersistedCryptoAllowanceThrowsException() { + // Given + final var evm38RecordFile = persistRecordFile(EVM_V_38_BLOCK); + final var evm38HistoricalRange = setupHistoricalStateInService(EVM_V_38_BLOCK, evm38RecordFile); + final var historicalRangeAfterEvm38 = setUpHistoricalContext(EVM_V_38_BLOCK + 1); + + final var sender = persistAccountEntityHistorical(evm38HistoricalRange); + final var receiver = persistAccountEntityHistorical(evm38HistoricalRange); + + setupHistoricalStateInService(EVM_V_38_BLOCK, evm38HistoricalRange); + final var contract = testWeb3jService.deploy(ModificationPrecompileTestContract::deploy); + final var contractAddress = Address.fromHexString(contract.getContractAddress()); + final var contractEntityId = entityIdFromEvmAddress(contractAddress); + + // The accounts are persisted against block (X-1) but the crypto allowance is persisted in + // block X, so the call against block (X-1) fails as there is no allowance yet. + persistCryptoAllowanceHistorical(sender, contractEntityId, 5L, historicalRangeAfterEvm38); + + testWeb3jService.setSender(getAddressFromEntity(sender)); + final var transferList = new TransferList(List.of( + new AccountAmount(getAddressFromEntity(sender), BigInteger.valueOf(-5L), true), + new AccountAmount(getAddressFromEntity(receiver), BigInteger.valueOf(5L), true))); + + // When + final var functionCall = contract.call_cryptoTransferExternal(transferList, new ArrayList<>()); + + // Then + assertThatThrownBy(functionCall::send).isInstanceOf(MirrorEvmTransactionException.class); + } + + // Tests AccountBalanceRepository + @Test + void accountBalanceNotPersistedYetReturnsPreviousBalance() throws Exception { + // Given + final var evm30RecordFile = persistRecordFile(EVM_V_30_BLOCK); + final var evm30HistoricalRange = setupHistoricalStateInService(EVM_V_30_BLOCK, evm30RecordFile); + final var historicalRangeAfterEvm34 = setUpHistoricalContext(EVM_V_34_BLOCK); + final var feeCollector = persistAccountWithBalanceHistorical(100L, evm30HistoricalRange); + + setupHistoricalStateInService(EVM_V_30_BLOCK, evm30RecordFile); + final var contract = testWeb3jService.deploy(EvmCodesHistorical::deploy); + + // Persist the token, the account and the account balance in block 49. In block 50 enter another + // account balance. The call against block 49 should return the first balance as the second + // balance is not available at that point yet. + persistAccountBalanceHistorical(feeCollector.toEntityId(), 200L, historicalRangeAfterEvm34); + + // When + final var result = contract.call_getAccountBalance(getAddressFromEntity(feeCollector)) + .send(); + + // Then + assertThat(result).isEqualTo(BigInteger.valueOf(100L)); + } +} diff --git a/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallServicePrecompileHistoricalTest.java b/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallServicePrecompileHistoricalTest.java index 871692cd280..908747b59e6 100644 --- a/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallServicePrecompileHistoricalTest.java +++ b/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallServicePrecompileHistoricalTest.java @@ -29,7 +29,6 @@ import static com.hedera.mirror.web3.utils.ContractCallTestUtil.KEY_WITH_ED_25519_TYPE; import static com.hedera.mirror.web3.utils.ContractCallTestUtil.LEDGER_ID; import static com.hedera.mirror.web3.utils.ContractCallTestUtil.SENDER_ALIAS; -import static com.hedera.mirror.web3.utils.ContractCallTestUtil.SENDER_PUBLIC_KEY; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; @@ -40,12 +39,10 @@ import com.hedera.mirror.common.domain.entity.Entity; import com.hedera.mirror.common.domain.entity.EntityId; import com.hedera.mirror.common.domain.entity.EntityType; -import com.hedera.mirror.common.domain.token.CustomFee; import com.hedera.mirror.common.domain.token.FallbackFee; import com.hedera.mirror.common.domain.token.FractionalFee; import com.hedera.mirror.common.domain.token.RoyaltyFee; import com.hedera.mirror.common.domain.token.Token; -import com.hedera.mirror.common.domain.token.TokenFreezeStatusEnum; import com.hedera.mirror.common.domain.token.TokenKycStatusEnum; import com.hedera.mirror.common.domain.token.TokenSupplyTypeEnum; import com.hedera.mirror.common.domain.token.TokenTransfer; @@ -64,7 +61,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -import org.apache.commons.lang3.tuple.Pair; import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.datatypes.Address; import org.junit.jupiter.params.ParameterizedTest; @@ -72,14 +68,14 @@ import org.junit.jupiter.params.provider.ValueSource; import org.web3j.tx.Contract; -class ContractCallServicePrecompileHistoricalTest extends AbstractContractCallServiceTest { +class ContractCallServicePrecompileHistoricalTest extends AbstractContractCallServiceHistoricalTest { @ParameterizedTest @ValueSource(longs = {50, 49}) void isTokenFrozen(long blockNumber) throws Exception { // Given final var historicalRange = setUpHistoricalContext(blockNumber); - final var accountAndToken = persistAccountTokenAndFrozenRelationshipHistorical(historicalRange); + final var accountAndToken = persistAccountTokenRelationshipHistorical(true, historicalRange); final var contract = testWeb3jService.deploy(PrecompileTestContractHistorical::deploy); @@ -96,7 +92,7 @@ void isTokenFrozen(long blockNumber) throws Exception { void isTokenFrozenWithAlias(long blockNumber) throws Exception { // Given final var historicalRange = setUpHistoricalContext(blockNumber); - final var accountAndToken = persistAccountTokenAndFrozenRelationshipHistorical(historicalRange); + final var accountAndToken = persistAccountTokenRelationshipHistorical(true, historicalRange); final var contract = testWeb3jService.deploy(PrecompileTestContractHistorical::deploy); // When @@ -1019,125 +1015,6 @@ private KeyValue getKeyValueForType(final KeyValueType keyValueType, final Strin }; } - private Entity persistTokenEntityHistorical(final Range timestampRange) { - return domainBuilder - .entity() - .customize(e -> e.type(EntityType.TOKEN).timestampRange(timestampRange)) - .persist(); - } - - private void persistFungibleTokenHistorical(Entity tokenEntity, final Range timestampRange) { - domainBuilder - .token() - .customize(t -> t.tokenId(tokenEntity.getId()) - .type(TokenTypeEnum.FUNGIBLE_COMMON) - .timestampRange(timestampRange) - .createdTimestamp(timestampRange.lowerEndpoint())) - .persist(); - } - - private Entity persistNftHistorical(final Range timestampRange) { - final var tokenEntity = persistTokenEntityHistorical(timestampRange); - domainBuilder - .token() - .customize(t -> t.tokenId(tokenEntity.getId()) - .type(TokenTypeEnum.NON_FUNGIBLE_UNIQUE) - .timestampRange(timestampRange)) - .persist(); - domainBuilder - .nft() - .customize(n -> n.tokenId(tokenEntity.getId()).serialNumber(1L).timestampRange(timestampRange)) - .persist(); - - return tokenEntity; - } - - private Entity persistAccountEntityHistorical(final Range timestampRange) { - return domainBuilder - .entity() - .customize(e -> e.type(EntityType.ACCOUNT) - .deleted(false) - .balance(1_000_000_000_000L) - .timestampRange(timestampRange) - .createdTimestamp(timestampRange.lowerEndpoint())) - .persist(); - } - - private Entity persistAccountEntityHistoricalWithAlias(final Range timestampRange) { - return domainBuilder - .entity() - .customize(e -> e.type(EntityType.ACCOUNT) - .alias(SENDER_PUBLIC_KEY.toByteArray()) - .deleted(false) - .evmAddress(SENDER_ALIAS.toArray()) - .balance(1_000_000_000_000L) - .createdTimestamp(timestampRange.lowerEndpoint()) - .timestampRange(timestampRange)) - .persist(); - } - - private CustomFee persistCustomFeesWithFeeCollectorHistorical( - final Entity feeCollector, - final Entity tokenEntity, - final TokenTypeEnum tokenType, - final Range timestampRange) { - final var fixedFee = com.hedera.mirror.common.domain.token.FixedFee.builder() - .allCollectorsAreExempt(true) - .amount(domainBuilder.number()) - .collectorAccountId(feeCollector.toEntityId()) - .denominatingTokenId(tokenEntity.toEntityId()) - .build(); - - final var fractionalFee = TokenTypeEnum.FUNGIBLE_COMMON.equals(tokenType) - ? FractionalFee.builder() - .allCollectorsAreExempt(true) - .collectorAccountId(feeCollector.toEntityId()) - .denominator(domainBuilder.number()) - .maximumAmount(domainBuilder.number()) - .minimumAmount(1L) - .numerator(domainBuilder.number()) - .netOfTransfers(true) - .build() - : null; - - final var fallbackFee = FallbackFee.builder() - .amount(domainBuilder.number()) - .denominatingTokenId(tokenEntity.toEntityId()) - .build(); - - final var royaltyFee = TokenTypeEnum.NON_FUNGIBLE_UNIQUE.equals(tokenType) - ? RoyaltyFee.builder() - .allCollectorsAreExempt(true) - .collectorAccountId(feeCollector.toEntityId()) - .denominator(domainBuilder.number()) - .fallbackFee(fallbackFee) - .numerator(domainBuilder.number()) - .build() - : null; - - if (TokenTypeEnum.FUNGIBLE_COMMON.equals(tokenType)) { - return domainBuilder - .customFee() - .customize(f -> f.tokenId(tokenEntity.getId()) - .fixedFees(List.of(fixedFee)) - .fractionalFees(List.of(fractionalFee)) - .royaltyFees(new ArrayList<>()) - .timestampRange(timestampRange)) - .persist(); - } else if (TokenTypeEnum.NON_FUNGIBLE_UNIQUE.equals(tokenType)) { - return domainBuilder - .customFee() - .customize(f -> f.tokenId(tokenEntity.getId()) - .fixedFees(List.of(fixedFee)) - .royaltyFees(List.of(royaltyFee)) - .fractionalFees(new ArrayList<>()) - .timestampRange(timestampRange)) - .persist(); - } - - return CustomFee.builder().build(); - } - private List getExpectedTokenKeys( final Entity tokenEntity, final Token token) { final var expectedTokenKeys = new ArrayList(); @@ -1245,15 +1122,6 @@ private Entity accountPersistWithBalanceHistorical( return entity; } - private Range setUpHistoricalContext(final long blockNumber) { - final var recordFile = - domainBuilder.recordFile().customize(f -> f.index(blockNumber)).persist(); - testWeb3jService.setBlockType(BlockType.of(String.valueOf(blockNumber))); - final var historicalRange = Range.closedOpen(recordFile.getConsensusStart(), recordFile.getConsensusEnd()); - testWeb3jService.setHistoricalRange(historicalRange); - return historicalRange; - } - private PrecompileTestContractHistorical.HederaToken createExpectedHederaToken( final Entity tokenEntity, final Token token, final Entity treasury) { final var expectedTokenKeys = getExpectedTokenKeys(tokenEntity, token); @@ -1304,20 +1172,4 @@ private void persistTokenRelationshipWithKycGrantedHistorical( .timestampRange(historicalRange)) .persist(); } - - private Pair persistAccountTokenAndFrozenRelationshipHistorical(final Range historicalRange) { - final var account = persistAccountEntityHistoricalWithAlias(historicalRange); - final var tokenEntity = persistTokenEntityHistorical(historicalRange); - persistFungibleTokenHistorical(tokenEntity, historicalRange); - domainBuilder - .tokenAccount() - .customize(ta -> ta.tokenId(tokenEntity.getId()) - .accountId(account.getId()) - .kycStatus(TokenKycStatusEnum.GRANTED) - .freezeStatus(TokenFreezeStatusEnum.FROZEN) - .associated(true) - .timestampRange(historicalRange)) - .persist(); - return Pair.of(account, tokenEntity); - } } diff --git a/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/utils/ContractCallTestUtil.java b/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/utils/ContractCallTestUtil.java index 6820568614d..af92625e0f9 100644 --- a/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/utils/ContractCallTestUtil.java +++ b/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/utils/ContractCallTestUtil.java @@ -75,6 +75,8 @@ public class ContractCallTestUtil { }; public static final long EVM_V_34_BLOCK = 50L; + public static final long EVM_V_30_BLOCK = EVM_V_34_BLOCK - 1; + public static final long EVM_V_38_BLOCK = 100L; /** * Checks if the *actual* gas usage is within 5-20% greater than the *expected* gas used from the initial call. diff --git a/hedera-mirror-web3/src/testHistorical/solidity/EvmCodesHistorical.sol b/hedera-mirror-web3/src/testHistorical/solidity/EvmCodesHistorical.sol index 62eaeef65cf..b8bb0e6e029 100644 --- a/hedera-mirror-web3/src/testHistorical/solidity/EvmCodesHistorical.sol +++ b/hedera-mirror-web3/src/testHistorical/solidity/EvmCodesHistorical.sol @@ -22,4 +22,9 @@ contract EvmCodesHistorical { function getLatestBlockHash() public view returns (bytes32) { return blockhash(block.number); } + + // External view function that retrieves the hbar balance of a given account + function getAccountBalance(address _owner) external view returns (uint) { + return _owner.balance; + } } \ No newline at end of file diff --git a/hedera-mirror-web3/src/testHistorical/solidity/ModificationPrecompileTestContractHistorical.sol b/hedera-mirror-web3/src/testHistorical/solidity/ModificationPrecompileTestContractHistorical.sol new file mode 100644 index 00000000000..cd8092fc51e --- /dev/null +++ b/hedera-mirror-web3/src/testHistorical/solidity/ModificationPrecompileTestContractHistorical.sol @@ -0,0 +1,20 @@ +// SPDX-License-Identifier: Apache-2.0 +pragma solidity >=0.5.0 <0.9.0; +pragma experimental ABIEncoderV2; + + +import "./HederaTokenService.sol"; +import "./HederaResponseCodes.sol"; + +contract ModificationPrecompileTestContractHistorical is HederaTokenService { + + function cryptoTransferExternal(IHederaTokenService.TransferList memory transferList, IHederaTokenService.TokenTransferList[] memory tokenTransfers) external + returns (int responseCode) + { + responseCode = HederaTokenService.cryptoTransfer(transferList, tokenTransfers); + if (responseCode != HederaResponseCodes.SUCCESS) { + revert(); + } + } + +} From f9b3f1db57af279852db249b68a8b7559625a8d4 Mon Sep 17 00:00:00 2001 From: Bilyana Gospodinova Date: Fri, 13 Sep 2024 16:49:18 +0300 Subject: [PATCH 2/3] Some cleanup Signed-off-by: Bilyana Gospodinova --- hedera-mirror-web3/build.gradle.kts | 2 +- ...ractContractCallServiceHistoricalTest.java | 106 +++++---- ...ctContractCallServiceOpcodeTracerTest.java | 2 +- .../AbstractContractCallServiceTest.java | 18 +- .../ContractCallEvmCodesHistoricalTest.java | 16 +- ...ractCallServiceERCTokenHistoricalTest.java | 202 ++++++---------- ...lServiceERCTokenReadOnlyFunctionsTest.java | 44 ++-- ...ractCallServiceHistoricalNegativeTest.java | 114 +++++---- ...ctCallServicePrecompileHistoricalTest.java | 126 +++++----- ...CallServicePrecompileModificationTest.java | 218 +++++++++--------- ...ractCallServicePrecompileReadonlyTest.java | 68 +++--- .../web3/utils/ContractCallTestUtil.java | 1 - 12 files changed, 407 insertions(+), 510 deletions(-) diff --git a/hedera-mirror-web3/build.gradle.kts b/hedera-mirror-web3/build.gradle.kts index fc8351277ca..8475e20338e 100644 --- a/hedera-mirror-web3/build.gradle.kts +++ b/hedera-mirror-web3/build.gradle.kts @@ -138,7 +138,7 @@ tasks.register("resolveSolidityHistorical", SolidityResolve::class) { group = "historical" description = "Resolves the historical solidity version $historicalSolidityVersion" sources = fileTree("src/testHistorical/solidity") - setAllowPaths(setOf("src/testHistorical/solidity")) + allowPaths = setOf("src/testHistorical/solidity") val packageJsonFile = "./build/node_modules/@openzeppelin/contracts/package.json" packageJson = file(packageJsonFile) diff --git a/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/AbstractContractCallServiceHistoricalTest.java b/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/AbstractContractCallServiceHistoricalTest.java index 49db0da3180..7e82d2b3ef0 100644 --- a/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/AbstractContractCallServiceHistoricalTest.java +++ b/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/AbstractContractCallServiceHistoricalTest.java @@ -20,6 +20,7 @@ import static com.hedera.mirror.web3.utils.ContractCallTestUtil.SENDER_PUBLIC_KEY; import com.google.common.collect.Range; +import com.google.protobuf.ByteString; import com.hedera.mirror.common.domain.balance.AccountBalance; import com.hedera.mirror.common.domain.balance.TokenBalance; import com.hedera.mirror.common.domain.entity.Entity; @@ -37,15 +38,16 @@ import java.util.ArrayList; import java.util.List; import org.apache.commons.lang3.tuple.Pair; +import org.hyperledger.besu.datatypes.Address; public abstract class AbstractContractCallServiceHistoricalTest extends AbstractContractCallServiceTest { protected Range setUpHistoricalContext(final long blockNumber) { - final var recordFile = persistRecordFile(blockNumber); + final var recordFile = recordFilePersist(blockNumber); return setupHistoricalStateInService(blockNumber, recordFile); } - protected RecordFile persistRecordFile(final long blockNumber) { + protected RecordFile recordFilePersist(final long blockNumber) { return domainBuilder.recordFile().customize(f -> f.index(blockNumber)).persist(); } @@ -61,24 +63,7 @@ protected void setupHistoricalStateInService(final long blockNumber, final Range testWeb3jService.setHistoricalRange(timestampRange); } - protected Pair persistAccountTokenRelationshipHistorical( - final boolean isFrozen, final Range historicalRange) { - final var account = persistAccountEntityHistoricalWithAlias(historicalRange); - final var tokenEntity = persistTokenEntityHistorical(historicalRange); - persistFungibleTokenHistorical(tokenEntity, historicalRange); - domainBuilder - .tokenAccountHistory() - .customize(ta -> ta.tokenId(tokenEntity.getId()) - .accountId(account.getId()) - .kycStatus(TokenKycStatusEnum.GRANTED) - .freezeStatus(isFrozen ? TokenFreezeStatusEnum.FROZEN : TokenFreezeStatusEnum.UNFROZEN) - .associated(true) - .timestampRange(historicalRange)) - .persist(); - return Pair.of(account, tokenEntity); - } - - protected void persistTokenAccountFrozenRelationshipHistorical( + protected void tokenAccountFrozenRelationshipPersistHistorical( final Entity tokenEntity, final Entity accountEntity, final Range historicalRange) { domainBuilder .tokenAccountHistory() @@ -91,7 +76,7 @@ protected void persistTokenAccountFrozenRelationshipHistorical( .persist(); } - protected Entity persistAccountEntityHistorical(final Range timestampRange) { + protected Entity accountEntityPersistHistorical(final Range timestampRange) { return domainBuilder .entity() .customize(e -> e.type(EntityType.ACCOUNT) @@ -102,7 +87,24 @@ protected Entity persistAccountEntityHistorical(final Range timestampRange .persist(); } - protected Entity persistAccountEntityNoEvmAddressHistorical(final Range timestampRange) { + protected Pair accountTokenAndFrozenRelationshipPersistHistorical( + final Range historicalRange) { + final var account = accountEntityWithAliasPersistHistorical(historicalRange); + final var tokenEntity = tokenEntityPersistHistorical(historicalRange); + fungibleTokenPersistHistorical(tokenEntity, historicalRange); + domainBuilder + .tokenAccount() + .customize(ta -> ta.tokenId(tokenEntity.getId()) + .accountId(account.getId()) + .kycStatus(TokenKycStatusEnum.GRANTED) + .freezeStatus(TokenFreezeStatusEnum.FROZEN) + .associated(true) + .timestampRange(historicalRange)) + .persist(); + return Pair.of(account, tokenEntity); + } + + protected Entity accountEntityNoEvmAddressPersistHistorical(final Range timestampRange) { return domainBuilder .entity() .customize(e -> e.type(EntityType.ACCOUNT) @@ -114,32 +116,37 @@ protected Entity persistAccountEntityNoEvmAddressHistorical(final Range ti .persist(); } - protected Entity persistAccountEntityHistoricalWithAlias(final Range timestampRange) { + protected Entity accountEntityWithAliasPersistHistorical(final Range timestampRange) { + return accountEntityWithAliasPersistHistorical(SENDER_ALIAS, SENDER_PUBLIC_KEY, timestampRange); + } + + protected Entity accountEntityWithAliasPersistHistorical( + final Address evmAddress, final ByteString alias, final Range timestampRange) { return domainBuilder .entity() .customize(e -> e.type(EntityType.ACCOUNT) - .alias(SENDER_PUBLIC_KEY.toByteArray()) + .alias(alias.toByteArray()) .deleted(false) - .evmAddress(SENDER_ALIAS.toArray()) + .evmAddress(evmAddress.toArray()) .balance(1_000_000_000_000L) .createdTimestamp(timestampRange.lowerEndpoint()) .timestampRange(timestampRange)) .persist(); } - protected Entity persistAccountWithBalanceHistorical(final long balance, final Range timestampRange) { + protected Entity accountWithBalancePersistHistorical(final long balance, final Range timestampRange) { final var entity = domainBuilder .entity() .customize(e -> e.balance(balance) .timestampRange(timestampRange) .createdTimestamp(timestampRange.lowerEndpoint())) .persist(); - persistAccountBalanceHistorical(entity.toEntityId(), balance, timestampRange); + accountBalancePersistHistorical(entity.toEntityId(), balance, timestampRange); return entity; } - protected void persistAccountBalanceHistorical( + protected void accountBalancePersistHistorical( final EntityId entityId, final long balance, final Range timestampRange) { // There needs to be an entry for account 0.0.2 in order for the account balance query to return the correct // result @@ -155,7 +162,7 @@ protected void persistAccountBalanceHistorical( .persist(); } - protected void persistTokenBalanceHistorical( + protected void tokenBalancePersistHistorical( final EntityId accountId, final EntityId tokenId, final long balance, final Range timestampRange) { // There needs to be an entry for account 0.0.2 in order for the token balance query to return the correct // result @@ -171,14 +178,14 @@ protected void persistTokenBalanceHistorical( .persist(); } - protected Entity persistTokenEntityHistorical(final Range timestampRange) { + protected Entity tokenEntityPersistHistorical(final Range timestampRange) { return domainBuilder .entity() .customize(e -> e.type(EntityType.TOKEN).timestampRange(timestampRange)) .persist(); } - protected void persistFungibleTokenHistorical(Entity tokenEntity, final Range timestampRange) { + protected void fungibleTokenPersistHistorical(Entity tokenEntity, final Range timestampRange) { domainBuilder .tokenHistory() .customize(t -> t.tokenId(tokenEntity.getId()) @@ -188,14 +195,14 @@ protected void persistFungibleTokenHistorical(Entity tokenEntity, final Range timestampRange) { - final var entity = persistTokenEntityHistorical(timestampRange); - persistFungibleTokenHistorical(entity, timestampRange); + protected Entity fungibleTokenPersistHistorical(final Range timestampRange) { + final var entity = tokenEntityPersistHistorical(timestampRange); + fungibleTokenPersistHistorical(entity, timestampRange); return entity; } - protected Entity persistNftHistorical(final Range timestampRange) { - final var tokenEntity = persistTokenEntityHistorical(timestampRange); + protected Entity nftPersistHistorical(final Range timestampRange) { + final var tokenEntity = tokenEntityPersistHistorical(timestampRange); domainBuilder .tokenHistory() .customize(t -> t.tokenId(tokenEntity.getId()) @@ -210,35 +217,32 @@ protected Entity persistNftHistorical(final Range timestampRange) { return tokenEntity; } - protected void persistTokenAllowanceHistorical( - final Entity tokenEntity, - final Entity owner, - final Entity spender, - final long amount, - final Range timestampRange) { + protected void tokenAllowancePersistHistorical( + final Entity tokenEntity, final Entity owner, final Entity spender, final Range timestampRange) { domainBuilder .tokenAllowanceHistory() .customize(a -> a.tokenId(tokenEntity.getId()) - .owner(owner.getNum()) - .spender(spender.getNum()) - .amount(amount) - .amountGranted(amount) + .owner(owner.getId()) + .spender(spender.getId()) + .amount(50L) + .amountGranted(50L) .timestampRange(timestampRange)) .persist(); } - protected void persistNftAllowanceHistorical( + protected void nftAllowancePersistHistorical( final Entity tokenEntity, final Entity owner, final Entity spender, final Range timestampRange) { domainBuilder .nftAllowanceHistory() .customize(a -> a.tokenId(tokenEntity.getId()) - .owner(owner.getNum()) - .spender(spender.getNum()) + .owner(owner.getId()) + .spender(spender.getId()) + .approvedForAll(true) .timestampRange(timestampRange)) .persist(); } - protected void persistCryptoAllowanceHistorical( + protected void cryptoAllowancePersistHistorical( final Entity owner, final EntityId spender, final long amount, final Range timestampRange) { domainBuilder .cryptoAllowanceHistory() @@ -251,7 +255,7 @@ protected void persistCryptoAllowanceHistorical( .persist(); } - protected AbstractCustomFee persistCustomFeesWithFeeCollectorHistorical( + protected AbstractCustomFee customFeesWithFeeCollectorPersistHistorical( final Entity feeCollector, final Entity tokenEntity, final TokenTypeEnum tokenType, diff --git a/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/AbstractContractCallServiceOpcodeTracerTest.java b/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/AbstractContractCallServiceOpcodeTracerTest.java index c0d215be812..3951dfc91ce 100644 --- a/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/AbstractContractCallServiceOpcodeTracerTest.java +++ b/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/AbstractContractCallServiceOpcodeTracerTest.java @@ -50,7 +50,7 @@ import org.mockito.Captor; import org.web3j.tx.Contract; -abstract class AbstractContractCallServiceOpcodeTracerTest extends AbstractContractCallServiceTest { +abstract class AbstractContractCallServiceOpcodeTracerTest extends AbstractContractCallServiceHistoricalTest { @Resource protected ContractDebugService contractDebugService; diff --git a/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/AbstractContractCallServiceTest.java b/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/AbstractContractCallServiceTest.java index 77e1643d012..c97ee6ad582 100644 --- a/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/AbstractContractCallServiceTest.java +++ b/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/AbstractContractCallServiceTest.java @@ -183,24 +183,22 @@ protected ContractExecutionParameters getContractExecutionParameters( value); } - protected Entity persistAccountEntity() { + protected Entity tokenEntityPersist() { + return domainBuilder.entity().customize(e -> e.type(EntityType.TOKEN)).persist(); + } + + protected Entity accountEntityPersist() { return domainBuilder .entity() .customize(e -> e.type(EntityType.ACCOUNT).deleted(false).balance(1_000_000_000_000L)) .persist(); } - protected void persistAssociation(final Entity token, final Entity account) { - domainBuilder - .tokenAccount() - .customize(ta -> ta.tokenId(token.getId()) - .accountId(account.getId()) - .kycStatus(TokenKycStatusEnum.GRANTED) - .associated(true)) - .persist(); + protected void tokenAccountPersist(final Entity token, final Entity account) { + tokenAccountPersist(token, account.toEntityId().getId()); } - protected void persistAssociation(final Entity token, final Long accountId) { + protected void tokenAccountPersist(final Entity token, final Long accountId) { domainBuilder .tokenAccount() .customize(ta -> ta.tokenId(token.getId()) diff --git a/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallEvmCodesHistoricalTest.java b/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallEvmCodesHistoricalTest.java index 429a7b8f210..7eeebe0baf2 100644 --- a/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallEvmCodesHistoricalTest.java +++ b/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallEvmCodesHistoricalTest.java @@ -16,8 +16,6 @@ package com.hedera.mirror.web3.service; -import static com.google.common.collect.Range.closedOpen; -import static com.hedera.mirror.common.domain.entity.EntityType.ACCOUNT; import static com.hedera.mirror.web3.evm.utils.EvmTokenUtils.toAddress; import static com.hedera.mirror.web3.utils.ContractCallTestUtil.EVM_V_34_BLOCK; import static com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_SOLIDITY_ADDRESS; @@ -38,7 +36,7 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; -public class ContractCallEvmCodesHistoricalTest extends AbstractContractCallServiceTest { +public class ContractCallEvmCodesHistoricalTest extends AbstractContractCallServiceHistoricalTest { private RecordFile recordFileAfterEvm34; @BeforeEach @@ -102,16 +100,8 @@ void getLatestBlockHashReturnsCorrectValue() throws Exception { } private void senderPersistHistorical(RecordFile recordFileHistorical) { - final var senderHistorical = domainBuilder - .entity() - .customize(e -> e.type(ACCOUNT) - .deleted(false) - .balance(10000 * 100_000_000L) - .createdTimestamp(recordFileHistorical.getConsensusStart()) - .timestampRange(closedOpen( - recordFileHistorical.getConsensusStart(), recordFileHistorical.getConsensusEnd()))) - .persist(); - + final var senderHistorical = accountEntityPersistHistorical( + Range.closedOpen(recordFileHistorical.getConsensusStart(), recordFileHistorical.getConsensusEnd())); testWeb3jService.setSender(toAddress(senderHistorical.toEntityId()).toHexString()); } } diff --git a/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallServiceERCTokenHistoricalTest.java b/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallServiceERCTokenHistoricalTest.java index 984834c1131..80e523b225b 100644 --- a/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallServiceERCTokenHistoricalTest.java +++ b/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallServiceERCTokenHistoricalTest.java @@ -28,14 +28,10 @@ import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; import com.google.common.collect.Range; -import com.google.protobuf.ByteString; import com.hedera.mirror.common.domain.balance.AccountBalance; import com.hedera.mirror.common.domain.balance.TokenBalance; import com.hedera.mirror.common.domain.entity.Entity; import com.hedera.mirror.common.domain.entity.EntityId; -import com.hedera.mirror.common.domain.entity.EntityType; -import com.hedera.mirror.common.domain.token.TokenFreezeStatusEnum; -import com.hedera.mirror.common.domain.token.TokenKycStatusEnum; import com.hedera.mirror.common.domain.token.TokenTypeEnum; import com.hedera.mirror.web3.exception.MirrorEvmTransactionException; import com.hedera.mirror.web3.viewmodel.BlockType; @@ -47,7 +43,7 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; -class ContractCallServiceERCTokenHistoricalTest extends AbstractContractCallServiceTest { +class ContractCallServiceERCTokenHistoricalTest extends AbstractContractCallServiceHistoricalTest { private Range historicalRange; @Nested @@ -61,7 +57,7 @@ void beforeEach() { @ValueSource(booleans = {true, false}) void getApprovedEmptySpender(final boolean isStatic) { // Given - final var ownerEntity = accountEntityPersistHistorical(); + final var ownerEntity = accountEntityPersistHistorical(historicalRange); final var tokenEntity = nftPersistHistorical(ownerEntity.toEntityId(), ownerEntity.toEntityId(), EntityId.EMPTY); final var contract = testWeb3jService.deploy(ERCTestContractHistorical::deploy); @@ -77,8 +73,8 @@ void getApprovedEmptySpender(final boolean isStatic) { @ValueSource(booleans = {true, false}) void getApproved(final boolean isStatic) { // Given - final var owner = accountEntityPersistHistorical(); - final var spender = accountEntityPersistHistorical(); + final var owner = accountEntityPersistHistorical(historicalRange); + final var spender = accountEntityPersistHistorical(historicalRange); final var nftToken = nftPersistHistorical(owner.toEntityId(), owner.toEntityId(), spender.toEntityId()); final var contract = testWeb3jService.deploy(ERCTestContractHistorical::deploy); // When @@ -93,10 +89,10 @@ void getApproved(final boolean isStatic) { @ValueSource(booleans = {true, false}) void isApproveForAll(final boolean isStatic) { // Given - final var owner = accountEntityPersistHistorical(); - final var spender = accountEntityPersistHistorical(); + final var owner = accountEntityPersistHistorical(historicalRange); + final var spender = accountEntityPersistHistorical(historicalRange); final var nftToken = nftPersistHistorical(owner.toEntityId(), owner.toEntityId(), spender.toEntityId()); - nftAllowancePersistHistorical(nftToken, owner, spender); + nftAllowancePersistHistorical(nftToken, owner, spender, historicalRange); final var contract = testWeb3jService.deploy(ERCTestContractHistorical::deploy); // When final var result = isStatic @@ -112,10 +108,11 @@ void isApproveForAll(final boolean isStatic) { @ValueSource(booleans = {true, false}) void isApproveForAllWithAlias(final boolean isStatic) { // Given - final var owner = accountEntityPersistHistoricalWithAlias(SENDER_ALIAS, SENDER_PUBLIC_KEY); - final var spender = accountEntityPersistHistoricalWithAlias(SPENDER_ALIAS, SPENDER_PUBLIC_KEY); + final var owner = accountEntityWithAliasPersistHistorical(SENDER_ALIAS, SENDER_PUBLIC_KEY, historicalRange); + final var spender = + accountEntityWithAliasPersistHistorical(SPENDER_ALIAS, SPENDER_PUBLIC_KEY, historicalRange); final var nftToken = nftPersistHistorical(owner.toEntityId(), owner.toEntityId(), spender.toEntityId()); - nftAllowancePersistHistorical(nftToken, owner, spender); + nftAllowancePersistHistorical(nftToken, owner, spender, historicalRange); final var contract = testWeb3jService.deploy(ERCTestContractHistorical::deploy); // When final var result = isStatic @@ -131,9 +128,9 @@ void isApproveForAllWithAlias(final boolean isStatic) { @ValueSource(booleans = {true, false}) void allowance(final boolean isStatic) { // Given - final var owner = accountEntityPersistHistorical(); - final var spender = accountEntityPersistHistorical(); - final var token = fungibleTokenPersistHistorical(); + final var owner = accountEntityPersistHistorical(historicalRange); + final var spender = accountEntityPersistHistorical(historicalRange); + final var token = fungibleTokenPersistHistorical(historicalRange); final var amountGranted = 10L; fungibleTokenAllowancePersistHistorical(token, owner, spender, amountGranted); final var contract = testWeb3jService.deploy(ERCTestContractHistorical::deploy); @@ -151,9 +148,10 @@ void allowance(final boolean isStatic) { @ValueSource(booleans = {true, false}) void allowanceWithAlias(final boolean isStatic) { // Given - final var owner = accountEntityPersistHistoricalWithAlias(SENDER_ALIAS, SENDER_PUBLIC_KEY); - final var spender = accountEntityPersistHistoricalWithAlias(SPENDER_ALIAS, SPENDER_PUBLIC_KEY); - final var token = fungibleTokenPersistHistorical(); + final var owner = accountEntityWithAliasPersistHistorical(SENDER_ALIAS, SENDER_PUBLIC_KEY, historicalRange); + final var spender = + accountEntityWithAliasPersistHistorical(SPENDER_ALIAS, SPENDER_PUBLIC_KEY, historicalRange); + final var token = fungibleTokenPersistHistorical(historicalRange); final var amountGranted = 10L; fungibleTokenAllowancePersistHistorical(token, owner, spender, amountGranted); final var contract = testWeb3jService.deploy(ERCTestContractHistorical::deploy); @@ -172,7 +170,7 @@ void allowanceWithAlias(final boolean isStatic) { void decimals(final boolean isStatic) { // Given final var decimals = 12; - final var tokenEntity = tokenEntityPersistHistorical(); + final var tokenEntity = tokenEntityPersistHistorical(historicalRange); invalidFungibleTokenPersist(tokenEntity, decimals); final var contract = testWeb3jService.deploy(ERCTestContractHistorical::deploy); // When @@ -188,8 +186,8 @@ void decimals(final boolean isStatic) { void totalSupply(final boolean isStatic) { // Given final var totalSupply = 12345L; - final var spender = accountEntityPersistHistorical(); - final var tokenEntity = tokenEntityPersistHistorical(); + final var spender = accountEntityPersistHistorical(historicalRange); + final var tokenEntity = tokenEntityPersistHistorical(historicalRange); fungibleTokenPersistHistoricalWithTotalSupply(tokenEntity, totalSupply); balancePersistHistorical(toAddress(tokenEntity.getId()), toAddress(spender.getId()), 12L); final var contract = testWeb3jService.deploy(ERCTestContractHistorical::deploy); @@ -206,7 +204,7 @@ void totalSupply(final boolean isStatic) { void symbol(final boolean isStatic) { // Given final var symbol = "HBAR"; - final var tokenEntity = tokenEntityPersistHistorical(); + final var tokenEntity = tokenEntityPersistHistorical(historicalRange); fungibleTokenPersistHistoricalWithSymbol(tokenEntity, symbol); final var contract = testWeb3jService.deploy(ERCTestContractHistorical::deploy); // When @@ -221,9 +219,9 @@ void symbol(final boolean isStatic) { @ValueSource(booleans = {true, false}) void balanceOf(final boolean isStatic) { // Given - final var owner = accountEntityPersistHistorical(); - final var token = fungibleTokenPersistHistorical(); - tokenAccountPersistHistorical(owner, token); + final var owner = accountEntityPersistHistorical(historicalRange); + final var token = fungibleTokenPersistHistorical(historicalRange); + tokenAccountFrozenRelationshipPersistHistorical(token, owner, historicalRange); final var balance = 10L; balancePersistHistorical(toAddress(token.getId()), toAddress(owner.getId()), balance); final var contract = testWeb3jService.deploy(ERCTestContractHistorical::deploy); @@ -239,9 +237,9 @@ void balanceOf(final boolean isStatic) { @ValueSource(booleans = {true, false}) void balanceOfWithAlias(final boolean isStatic) { // Given - final var owner = accountEntityPersistHistoricalWithAlias(SENDER_ALIAS, SENDER_PUBLIC_KEY); - final var token = fungibleTokenPersistHistorical(); - tokenAccountPersistHistorical(owner, token); + final var owner = accountEntityWithAliasPersistHistorical(SENDER_ALIAS, SENDER_PUBLIC_KEY, historicalRange); + final var token = fungibleTokenPersistHistorical(historicalRange); + tokenAccountFrozenRelationshipPersistHistorical(token, owner, historicalRange); final var balance = 10L; balancePersistHistorical(toAddress(token.getId()), toAddress(owner.getId()), balance); final var contract = testWeb3jService.deploy(ERCTestContractHistorical::deploy); @@ -258,7 +256,7 @@ void balanceOfWithAlias(final boolean isStatic) { void name(final boolean isStatic) { // Given final var name = "Hbars"; - final var tokenEntity = tokenEntityPersistHistorical(); + final var tokenEntity = tokenEntityPersistHistorical(historicalRange); fungibleTokenPersistHistoricalWithName(tokenEntity, name); final var contract = testWeb3jService.deploy(ERCTestContractHistorical::deploy); // When @@ -273,9 +271,9 @@ void name(final boolean isStatic) { @ValueSource(booleans = {true, false}) void ownerOf(final boolean isStatic) { // Given - final var owner = accountEntityPersistHistorical(); + final var owner = accountEntityPersistHistorical(historicalRange); final var nftToken = nftPersistHistorical(owner.toEntityId()); - tokenAccountPersistHistorical(owner, nftToken); + tokenAccountFrozenRelationshipPersistHistorical(nftToken, owner, historicalRange); final var contract = testWeb3jService.deploy(ERCTestContractHistorical::deploy); // When final var result = isStatic @@ -289,7 +287,7 @@ void ownerOf(final boolean isStatic) { @ValueSource(booleans = {true, false}) void emptyOwnerOf(final boolean isStatic) { // Given - final var owner = accountEntityPersistHistorical(); + final var owner = accountEntityPersistHistorical(historicalRange); final var nftToken = nftPersistHistorical(owner.toEntityId()); final var contract = testWeb3jService.deploy(ERCTestContractHistorical::deploy); // When @@ -304,9 +302,9 @@ void emptyOwnerOf(final boolean isStatic) { @ValueSource(booleans = {true, false}) void tokenURI(final boolean isStatic) { // Given - final var owner = accountEntityPersistHistorical(); + final var owner = accountEntityPersistHistorical(historicalRange); final var metadata = "NFT_METADATA_URI"; - final var tokenEntity = tokenEntityPersistHistorical(); + final var tokenEntity = tokenEntityPersistHistorical(historicalRange); nftPersistHistoricalWithMetadata(tokenEntity, owner, metadata); final var contract = testWeb3jService.deploy(ERCTestContractHistorical::deploy); // When @@ -329,7 +327,7 @@ void beforeEach() { @ValueSource(booleans = {true, false}) void getApprovedEmptySpender(final boolean isStatic) throws Exception { // Given - final var ownerEntity = accountEntityPersistHistorical(); + final var ownerEntity = accountEntityPersistHistorical(historicalRange); final var tokenEntity = nftPersistHistorical(ownerEntity.toEntityId(), ownerEntity.toEntityId(), EntityId.EMPTY); final var contract = testWeb3jService.deploy(ERCTestContractHistorical::deploy); @@ -347,8 +345,8 @@ void getApprovedEmptySpender(final boolean isStatic) throws Exception { @ValueSource(booleans = {true, false}) void getApproved(final boolean isStatic) throws Exception { // Given - final var owner = accountEntityPersistHistorical(); - final var spender = accountEntityPersistHistorical(); + final var owner = accountEntityPersistHistorical(historicalRange); + final var spender = accountEntityPersistHistorical(historicalRange); final var nftToken = nftPersistHistorical(owner.toEntityId(), owner.toEntityId(), spender.toEntityId()); final var contract = testWeb3jService.deploy(ERCTestContractHistorical::deploy); // When @@ -365,10 +363,10 @@ void getApproved(final boolean isStatic) throws Exception { @ValueSource(booleans = {true, false}) void isApproveForAll(final boolean isStatic) throws Exception { // Given - final var owner = accountEntityPersistHistorical(); - final var spender = accountEntityPersistHistorical(); + final var owner = accountEntityPersistHistorical(historicalRange); + final var spender = accountEntityPersistHistorical(historicalRange); final var nftToken = nftPersistHistorical(owner.toEntityId(), owner.toEntityId(), spender.toEntityId()); - nftAllowancePersistHistorical(nftToken, owner, spender); + nftAllowancePersistHistorical(nftToken, owner, spender, historicalRange); final var contract = testWeb3jService.deploy(ERCTestContractHistorical::deploy); // When final var result = isStatic @@ -390,10 +388,11 @@ void isApproveForAll(final boolean isStatic) throws Exception { @ValueSource(booleans = {true, false}) void isApproveForAllWithAlias(final boolean isStatic) throws Exception { // Given - final var owner = accountEntityPersistHistoricalWithAlias(SENDER_ALIAS, SENDER_PUBLIC_KEY); - final var spender = accountEntityPersistHistoricalWithAlias(SPENDER_ALIAS, SPENDER_PUBLIC_KEY); + final var owner = accountEntityWithAliasPersistHistorical(SENDER_ALIAS, SENDER_PUBLIC_KEY, historicalRange); + final var spender = + accountEntityWithAliasPersistHistorical(SPENDER_ALIAS, SPENDER_PUBLIC_KEY, historicalRange); final var nftToken = nftPersistHistorical(owner.toEntityId(), owner.toEntityId(), spender.toEntityId()); - nftAllowancePersistHistorical(nftToken, owner, spender); + nftAllowancePersistHistorical(nftToken, owner, spender, historicalRange); final var contract = testWeb3jService.deploy(ERCTestContractHistorical::deploy); // When final var result = isStatic @@ -415,9 +414,9 @@ void isApproveForAllWithAlias(final boolean isStatic) throws Exception { @ValueSource(booleans = {true, false}) void allowance(final boolean isStatic) throws Exception { // Given - final var owner = accountEntityPersistHistorical(); - final var spender = accountEntityPersistHistorical(); - final var token = fungibleTokenPersistHistorical(); + final var owner = accountEntityPersistHistorical(historicalRange); + final var spender = accountEntityPersistHistorical(historicalRange); + final var token = fungibleTokenPersistHistorical(historicalRange); final var amountGranted = 10L; fungibleTokenAllowancePersistHistorical(token, owner, spender, amountGranted); final var contract = testWeb3jService.deploy(ERCTestContractHistorical::deploy); @@ -441,9 +440,10 @@ void allowance(final boolean isStatic) throws Exception { @ValueSource(booleans = {true, false}) void allowanceWithAlias(final boolean isStatic) throws Exception { // Given - final var owner = accountEntityPersistHistoricalWithAlias(SENDER_ALIAS, SENDER_PUBLIC_KEY); - final var spender = accountEntityPersistHistoricalWithAlias(SPENDER_ALIAS, SPENDER_PUBLIC_KEY); - final var token = fungibleTokenPersistHistorical(); + final var owner = accountEntityWithAliasPersistHistorical(SENDER_ALIAS, SENDER_PUBLIC_KEY, historicalRange); + final var spender = + accountEntityWithAliasPersistHistorical(SPENDER_ALIAS, SPENDER_PUBLIC_KEY, historicalRange); + final var token = fungibleTokenPersistHistorical(historicalRange); final var amountGranted = 10L; fungibleTokenAllowancePersistHistorical(token, owner, spender, amountGranted); final var contract = testWeb3jService.deploy(ERCTestContractHistorical::deploy); @@ -468,7 +468,7 @@ void allowanceWithAlias(final boolean isStatic) throws Exception { void decimals(final boolean isStatic) throws Exception { // Given final var decimals = 12; - final var tokenEntity = tokenEntityPersistHistorical(); + final var tokenEntity = tokenEntityPersistHistorical(historicalRange); invalidFungibleTokenPersist(tokenEntity, decimals); final var contract = testWeb3jService.deploy(ERCTestContractHistorical::deploy); // When @@ -485,8 +485,8 @@ void decimals(final boolean isStatic) throws Exception { void totalSupply(final boolean isStatic) throws Exception { // Given final var totalSupply = 12345L; - final var spender = accountEntityPersistHistorical(); - final var tokenEntity = tokenEntityPersistHistorical(); + final var spender = accountEntityPersistHistorical(historicalRange); + final var tokenEntity = tokenEntityPersistHistorical(historicalRange); fungibleTokenPersistHistoricalWithTotalSupply(tokenEntity, totalSupply); balancePersistHistorical(toAddress(tokenEntity.getId()), toAddress(spender.getId()), 12L); final var contract = testWeb3jService.deploy(ERCTestContractHistorical::deploy); @@ -505,7 +505,7 @@ void totalSupply(final boolean isStatic) throws Exception { void symbol(final boolean isStatic) throws Exception { // Given final var symbol = "HBAR"; - final var tokenEntity = tokenEntityPersistHistorical(); + final var tokenEntity = tokenEntityPersistHistorical(historicalRange); fungibleTokenPersistHistoricalWithSymbol(tokenEntity, symbol); final var contract = testWeb3jService.deploy(ERCTestContractHistorical::deploy); // When @@ -521,9 +521,9 @@ void symbol(final boolean isStatic) throws Exception { @ValueSource(booleans = {true, false}) void balanceOf(final boolean isStatic) throws Exception { // Given - final var owner = accountEntityPersistHistorical(); - final var token = fungibleTokenPersistHistorical(); - tokenAccountPersistHistorical(owner, token); + final var owner = accountEntityPersistHistorical(historicalRange); + final var token = fungibleTokenPersistHistorical(historicalRange); + tokenAccountFrozenRelationshipPersistHistorical(token, owner, historicalRange); final var balance = 10L; balancePersistHistorical(toAddress(token.getId()), toAddress(owner.getId()), balance); final var contract = testWeb3jService.deploy(ERCTestContractHistorical::deploy); @@ -541,9 +541,9 @@ void balanceOf(final boolean isStatic) throws Exception { @ValueSource(booleans = {true, false}) void balanceOfWithAlias(final boolean isStatic) throws Exception { // Given - final var owner = accountEntityPersistHistoricalWithAlias(SENDER_ALIAS, SENDER_PUBLIC_KEY); - final var token = fungibleTokenPersistHistorical(); - tokenAccountPersistHistorical(owner, token); + final var owner = accountEntityWithAliasPersistHistorical(SENDER_ALIAS, SENDER_PUBLIC_KEY, historicalRange); + final var token = fungibleTokenPersistHistorical(historicalRange); + tokenAccountFrozenRelationshipPersistHistorical(token, owner, historicalRange); final var balance = 10L; balancePersistHistorical(toAddress(token.getId()), toAddress(owner.getId()), balance); final var contract = testWeb3jService.deploy(ERCTestContractHistorical::deploy); @@ -562,7 +562,7 @@ void balanceOfWithAlias(final boolean isStatic) throws Exception { void name(final boolean isStatic) throws Exception { // Given final var name = "Hbars"; - final var tokenEntity = tokenEntityPersistHistorical(); + final var tokenEntity = tokenEntityPersistHistorical(historicalRange); fungibleTokenPersistHistoricalWithName(tokenEntity, name); final var contract = testWeb3jService.deploy(ERCTestContractHistorical::deploy); // When @@ -578,9 +578,9 @@ void name(final boolean isStatic) throws Exception { @ValueSource(booleans = {true, false}) void ownerOf(final boolean isStatic) throws Exception { // Given - final var owner = accountEntityPersistHistorical(); + final var owner = accountEntityPersistHistorical(historicalRange); final var nftToken = nftPersistHistorical(owner.toEntityId()); - tokenAccountPersistHistorical(owner, nftToken); + tokenAccountFrozenRelationshipPersistHistorical(nftToken, owner, historicalRange); final var contract = testWeb3jService.deploy(ERCTestContractHistorical::deploy); // When final var result = isStatic @@ -596,7 +596,7 @@ void ownerOf(final boolean isStatic) throws Exception { @ValueSource(booleans = {true, false}) void emptyOwnerOf(final boolean isStatic) throws Exception { // Given - final var owner = accountEntityPersistHistorical(); + final var owner = accountEntityPersistHistorical(historicalRange); final var nftToken = nftPersistHistorical(owner.toEntityId()); final var contract = testWeb3jService.deploy(ERCTestContractHistorical::deploy); // When @@ -613,9 +613,9 @@ void emptyOwnerOf(final boolean isStatic) throws Exception { @ValueSource(booleans = {true, false}) void tokenURI(final boolean isStatic) throws Exception { // Given - final var owner = accountEntityPersistHistorical(); + final var owner = accountEntityPersistHistorical(historicalRange); final var metadata = "NFT_METADATA_URI"; - final var tokenEntity = tokenEntityPersistHistorical(); + final var tokenEntity = tokenEntityPersistHistorical(historicalRange); nftPersistHistoricalWithMetadata(tokenEntity, owner, metadata); final var contract = testWeb3jService.deploy(ERCTestContractHistorical::deploy); // When @@ -692,18 +692,6 @@ private void balancePersistHistorical(final Address tokenAddress, Address sender .persist(); } - private Entity fungibleTokenPersistHistorical() { - final var tokenEntity = tokenEntityPersistHistorical(); - domainBuilder - .tokenHistory() - .customize(t -> t.tokenId(tokenEntity.getId()) - .type(TokenTypeEnum.FUNGIBLE_COMMON) - .timestampRange(historicalRange) - .createdTimestamp(historicalRange.lowerEndpoint())) - .persist(); - return tokenEntity; - } - private Entity nftPersistHistorical(final EntityId treasury) { return nftPersistHistorical(treasury, treasury); } @@ -718,7 +706,7 @@ private Entity nftPersistHistorical(final EntityId treasury, final EntityId owne private Entity nftPersistHistorical( final EntityId treasury, final EntityId owner, final EntityId spender, final byte[] kycKey) { - final var tokenEntity = tokenEntityPersistHistorical(); + final var tokenEntity = tokenEntityPersistHistorical(historicalRange); domainBuilder .tokenHistory() .customize(t -> t.tokenId(tokenEntity.getId()) @@ -756,37 +744,6 @@ private void nftPersistHistoricalWithMetadata(final Entity tokenEntity, final En .persist(); } - private Entity tokenEntityPersistHistorical() { - return domainBuilder - .entity() - .customize(e -> e.type(EntityType.TOKEN).timestampRange(historicalRange)) - .persist(); - } - - private Entity accountEntityPersistHistorical() { - return domainBuilder - .entity() - .customize(e -> e.type(EntityType.ACCOUNT) - .deleted(false) - .balance(1_000_000_000_000L) - .timestampRange(historicalRange) - .createdTimestamp(historicalRange.lowerEndpoint())) - .persist(); - } - - private Entity accountEntityPersistHistoricalWithAlias(final Address alias, final ByteString publicKey) { - return domainBuilder - .entity() - .customize(e -> e.type(EntityType.ACCOUNT) - .deleted(false) - .evmAddress(alias.toArray()) - .alias(publicKey.toByteArray()) - .balance(1_000_000_000_000L) - .timestampRange(historicalRange) - .createdTimestamp(historicalRange.lowerEndpoint())) - .persist(); - } - private void invalidFungibleTokenPersist(final Entity tokenEntity, final int decimals) { domainBuilder .tokenHistory() @@ -843,27 +800,4 @@ private void fungibleTokenAllowancePersistHistorical( .timestampRange(historicalRange)) .persist(); } - - private void nftAllowancePersistHistorical(final Entity token, final Entity owner, final Entity spender) { - domainBuilder - .nftAllowanceHistory() - .customize(a -> a.tokenId(token.getId()) - .owner(owner.getNum()) - .spender(spender.getNum()) - .timestampRange(historicalRange) - .approvedForAll(true)) - .persist(); - } - - private void tokenAccountPersistHistorical(final Entity owner, final Entity token) { - domainBuilder - .tokenAccountHistory() - .customize(e -> e.freezeStatus(TokenFreezeStatusEnum.FROZEN) - .accountId(owner.getId()) - .tokenId(token.getId()) - .kycStatus(TokenKycStatusEnum.GRANTED) - .associated(true) - .timestampRange(historicalRange)) - .persist(); - } } diff --git a/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallServiceERCTokenReadOnlyFunctionsTest.java b/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallServiceERCTokenReadOnlyFunctionsTest.java index 6262599d05e..6b7f2245573 100644 --- a/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallServiceERCTokenReadOnlyFunctionsTest.java +++ b/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallServiceERCTokenReadOnlyFunctionsTest.java @@ -27,9 +27,7 @@ import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; import com.google.protobuf.ByteString; -import com.hedera.mirror.common.domain.entity.Entity; import com.hedera.mirror.common.domain.entity.EntityId; -import com.hedera.mirror.common.domain.entity.EntityType; import com.hedera.mirror.common.domain.token.Token; import com.hedera.mirror.common.domain.token.TokenTypeEnum; import com.hedera.mirror.web3.exception.MirrorEvmTransactionException; @@ -46,7 +44,7 @@ class ContractCallServiceERCTokenReadOnlyFunctionsTest extends AbstractContractC @Test void ethCallGetApprovedEmptySpenderStatic() throws Exception { final var treasuryEntityId = accountPersist(); - final var tokenEntity = persistTokenEntity(); + final var tokenEntity = tokenEntityPersist(); domainBuilder .token() .customize(t -> t.tokenId(tokenEntity.getId()) @@ -70,7 +68,7 @@ void ethCallGetApprovedEmptySpenderStatic() throws Exception { @Test void ethCallGetApprovedEmptySpenderNonStatic() throws Exception { final var treasuryEntityId = accountPersist(); - final var tokenEntity = persistTokenEntity(); + final var tokenEntity = tokenEntityPersist(); domainBuilder .token() .customize(t -> t.tokenId(tokenEntity.getId()) @@ -338,7 +336,7 @@ void ethCallGetApprovedNonStatic() throws Exception { @Test void ethCallGetDecimalsStatic() throws Exception { final var decimals = 12; - final var tokenEntity = persistTokenEntity(); + final var tokenEntity = tokenEntityPersist(); domainBuilder .token() .customize(ta -> ta.tokenId(tokenEntity.getId()).decimals(decimals)) @@ -354,7 +352,7 @@ void ethCallGetDecimalsStatic() throws Exception { @Test void ethCallGetDecimalsNonStatic() throws Exception { final var decimals = 12; - final var tokenEntity = persistTokenEntity(); + final var tokenEntity = tokenEntityPersist(); domainBuilder .token() .customize(ta -> ta.tokenId(tokenEntity.getId()).decimals(decimals)) @@ -371,7 +369,7 @@ void ethCallGetDecimalsNonStatic() throws Exception { @Test void ethCallGetTotalSupplyStatic() throws Exception { final var totalSupply = 12345L; - final var tokenEntity = persistTokenEntity(); + final var tokenEntity = tokenEntityPersist(); domainBuilder .token() .customize(t -> t.tokenId(tokenEntity.getId()) @@ -390,7 +388,7 @@ void ethCallGetTotalSupplyStatic() throws Exception { @Test void ethCallGetTotalSupplyNonStatic() throws Exception { final var totalSupply = 12345L; - final var tokenEntity = persistTokenEntity(); + final var tokenEntity = tokenEntityPersist(); domainBuilder .token() .customize(t -> t.tokenId(tokenEntity.getId()) @@ -409,7 +407,7 @@ void ethCallGetTotalSupplyNonStatic() throws Exception { @Test void ethCallSymbolStatic() throws Exception { final var symbol = "HBAR"; - final var tokenEntity = persistTokenEntity(); + final var tokenEntity = tokenEntityPersist(); domainBuilder .token() .customize(t -> t.tokenId(tokenEntity.getId()) @@ -427,7 +425,7 @@ void ethCallSymbolStatic() throws Exception { @Test void ethCallSymbolNonStatic() throws Exception { final var symbol = "HBAR"; - final var tokenEntity = persistTokenEntity(); + final var tokenEntity = tokenEntityPersist(); domainBuilder .token() .customize(t -> t.tokenId(tokenEntity.getId()) @@ -530,7 +528,7 @@ void ethCallBalanceOfWithAliasNonStatic() throws Exception { @Test void ethCallNameStatic() throws Exception { final var tokenName = "Hbars"; - final var tokenEntity = persistTokenEntity(); + final var tokenEntity = tokenEntityPersist(); domainBuilder .token() .customize(t -> t.tokenId(tokenEntity.getId()) @@ -548,7 +546,7 @@ void ethCallNameStatic() throws Exception { @Test void ethCallNameNonStatic() throws Exception { final var tokenName = "Hbars"; - final var tokenEntity = persistTokenEntity(); + final var tokenEntity = tokenEntityPersist(); domainBuilder .token() .customize(t -> t.tokenId(tokenEntity.getId()) @@ -619,7 +617,7 @@ void ethCallTokenURIStatic() throws Exception { final var ownerEntity = accountPersist(); final byte[] kycKey = domainBuilder.key(); final var metadata = "NFT_METADATA_URI"; - final var tokenEntity = persistTokenEntity(); + final var tokenEntity = tokenEntityPersist(); domainBuilder .token() @@ -649,7 +647,7 @@ void ethCallTokenURINonStatic() throws Exception { final var ownerEntity = accountPersist(); final byte[] kycKey = domainBuilder.key(); final var metadata = "NFT_METADATA_URI"; - final var tokenEntity = persistTokenEntity(); + final var tokenEntity = tokenEntityPersist(); domainBuilder .token() @@ -677,7 +675,7 @@ void ethCallTokenURINonStatic() throws Exception { @Test void ethCallGetApprovedEmptySpenderRedirect() { final var treasuryEntityId = accountPersist(); - final var tokenEntity = persistTokenEntity(); + final var tokenEntity = tokenEntityPersist(); domainBuilder .token() .customize(t -> t.tokenId(tokenEntity.getId()) @@ -797,7 +795,7 @@ void ethCallGetApprovedRedirect() { @Test void ethCallGetDecimalsRedirect() { final var decimals = 12; - final var tokenEntity = persistTokenEntity(); + final var tokenEntity = tokenEntityPersist(); domainBuilder .token() .customize(ta -> ta.tokenId(tokenEntity.getId()).decimals(decimals)) @@ -811,7 +809,7 @@ void ethCallGetDecimalsRedirect() { @Test void ethCallGetTotalSupplyRedirect() { final var totalSupply = 12345L; - final var tokenEntity = persistTokenEntity(); + final var tokenEntity = tokenEntityPersist(); domainBuilder .token() .customize(t -> t.tokenId(tokenEntity.getId()) @@ -828,7 +826,7 @@ void ethCallGetTotalSupplyRedirect() { @Test void ethCallSymbolRedirect() { final var symbol = "HBAR"; - final var tokenEntity = persistTokenEntity(); + final var tokenEntity = tokenEntityPersist(); domainBuilder .token() .customize(t -> t.tokenId(tokenEntity.getId()) @@ -880,7 +878,7 @@ void ethCallBalanceOfWithAliasRedirect() { @Test void ethCallNameRedirect() { final var tokenName = "Hbars"; - final var tokenEntity = persistTokenEntity(); + final var tokenEntity = tokenEntityPersist(); domainBuilder .token() .customize(t -> t.tokenId(tokenEntity.getId()) @@ -917,7 +915,7 @@ void ethCallTokenURIRedirect() { final var ownerEntity = accountPersist(); final byte[] kycKey = domainBuilder.key(); final var metadata = "NFT_METADATA_URI"; - final var tokenEntity = persistTokenEntity(); + final var tokenEntity = tokenEntityPersist(); domainBuilder .token() @@ -1069,7 +1067,7 @@ private Token fungibleTokenPersist() { } private Token nftPersist() { - final var tokenEntity = persistTokenEntity(); + final var tokenEntity = tokenEntityPersist(); final var token = domainBuilder .token() .customize(t -> t.tokenId(tokenEntity.getId()).type(TokenTypeEnum.NON_FUNGIBLE_UNIQUE)) @@ -1121,8 +1119,4 @@ private Token nftPersist( .persist(); return token; } - - private Entity persistTokenEntity() { - return domainBuilder.entity().customize(e -> e.type(EntityType.TOKEN)).persist(); - } } diff --git a/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallServiceHistoricalNegativeTest.java b/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallServiceHistoricalNegativeTest.java index 67ce0cdd222..75c73edcec4 100644 --- a/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallServiceHistoricalNegativeTest.java +++ b/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallServiceHistoricalNegativeTest.java @@ -17,7 +17,6 @@ package com.hedera.mirror.web3.service; import static com.hedera.mirror.web3.evm.utils.EvmTokenUtils.entityIdFromEvmAddress; -import static com.hedera.mirror.web3.utils.ContractCallTestUtil.EVM_V_30_BLOCK; import static com.hedera.mirror.web3.utils.ContractCallTestUtil.EVM_V_34_BLOCK; import static com.hedera.mirror.web3.utils.ContractCallTestUtil.EVM_V_38_BLOCK; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; @@ -43,14 +42,14 @@ class ContractCallServiceHistoricalNegativeTest extends AbstractContractCallServ @Test void contractNotPersistedYetThrowsException() { // Given - final var evm30RecordFile = persistRecordFile(EVM_V_30_BLOCK); + final var evm30RecordFile = recordFilePersist(EVM_V_34_BLOCK - 1); final var historicalRangeAfterEvm34 = setUpHistoricalContext(EVM_V_34_BLOCK); - final var tokenEntity = persistNftHistorical(historicalRangeAfterEvm34); + final var tokenEntity = nftPersistHistorical(historicalRangeAfterEvm34); // Deploy the contract against block X, make the contract call against block (X-1) -> throw an exception as the // contract does not exist yet. final var contract = testWeb3jService.deploy(PrecompileTestContractHistorical::deploy); - setupHistoricalStateInService(EVM_V_30_BLOCK, evm30RecordFile); + setupHistoricalStateInService(EVM_V_34_BLOCK - 1, evm30RecordFile); // When final var functionCall = contract.call_isTokenAddress(getAddressFromEntity(tokenEntity)); @@ -64,13 +63,13 @@ void contractNotPersistedYetThrowsException() { @ValueSource(booleans = {false, true}) void tokenNotPersistedYetThrowsException(final boolean isNft) { // Given - final var evm30RecordFile = persistRecordFile(EVM_V_30_BLOCK); + final var evm30RecordFile = recordFilePersist(EVM_V_34_BLOCK - 1); final var historicalRangeAfterEvm34 = setUpHistoricalContext(EVM_V_34_BLOCK); final var tokenEntity = isNft - ? persistNftHistorical(historicalRangeAfterEvm34) - : persistFungibleTokenHistorical(historicalRangeAfterEvm34); + ? nftPersistHistorical(historicalRangeAfterEvm34) + : fungibleTokenPersistHistorical(historicalRangeAfterEvm34); - setupHistoricalStateInService(EVM_V_30_BLOCK, evm30RecordFile); + setupHistoricalStateInService(EVM_V_34_BLOCK - 1, evm30RecordFile); final var contract = testWeb3jService.deploy(PrecompileTestContractHistorical::deploy); // Persist the token against block X, make the call against block (X-1) -> throw an exception as the token does @@ -86,15 +85,15 @@ void tokenNotPersistedYetThrowsException(final boolean isNft) { @Test void tokenAccountRelationshipNotPersistedYetReturnsFalse() throws Exception { // Given - final var evm30RecordFile = persistRecordFile(EVM_V_30_BLOCK); - final var evm30HistoricalRange = setupHistoricalStateInService(EVM_V_30_BLOCK, evm30RecordFile); + final var evm30RecordFile = recordFilePersist(EVM_V_34_BLOCK - 1); + final var evm30HistoricalRange = setupHistoricalStateInService(EVM_V_34_BLOCK - 1, evm30RecordFile); final var historicalRangeAfterEvm34 = setUpHistoricalContext(EVM_V_34_BLOCK); - final var tokenEntity = persistTokenEntityHistorical(evm30HistoricalRange); - persistFungibleTokenHistorical(tokenEntity, evm30HistoricalRange); - final var accountEntity = persistAccountEntityHistoricalWithAlias(evm30HistoricalRange); - persistTokenAccountFrozenRelationshipHistorical(tokenEntity, accountEntity, historicalRangeAfterEvm34); + final var tokenEntity = tokenEntityPersistHistorical(evm30HistoricalRange); + fungibleTokenPersistHistorical(tokenEntity, evm30HistoricalRange); + final var accountEntity = accountEntityWithAliasPersistHistorical(evm30HistoricalRange); + tokenAccountFrozenRelationshipPersistHistorical(tokenEntity, accountEntity, historicalRangeAfterEvm34); - setupHistoricalStateInService(EVM_V_30_BLOCK, evm30RecordFile); + setupHistoricalStateInService(EVM_V_34_BLOCK - 1, evm30RecordFile); final var contract = testWeb3jService.deploy(PrecompileTestContractHistorical::deploy); // Persist the token and the account in block (X-1), but the relationship in block X. The call against block @@ -112,20 +111,19 @@ void tokenAccountRelationshipNotPersistedYetReturnsFalse() throws Exception { @Test void getAllowanceForFungibleTokenNotPersistedYetReturnsZero() throws Exception { // Given - final var evm30RecordFile = persistRecordFile(EVM_V_30_BLOCK); - final var evm30HistoricalRange = setupHistoricalStateInService(EVM_V_30_BLOCK, evm30RecordFile); + final var evm30RecordFile = recordFilePersist(EVM_V_34_BLOCK - 1); + final var evm30HistoricalRange = setupHistoricalStateInService(EVM_V_34_BLOCK - 1, evm30RecordFile); final var historicalRangeAfterEvm34 = setUpHistoricalContext(EVM_V_34_BLOCK); - final var amountGranted = 50L; - final var owner = persistAccountEntityHistorical(evm30HistoricalRange); - final var spender = persistAccountEntityHistorical(evm30HistoricalRange); - final var tokenEntity = persistTokenEntityHistorical(evm30HistoricalRange); - persistFungibleTokenHistorical(tokenEntity, evm30HistoricalRange); + final var owner = accountEntityPersistHistorical(evm30HistoricalRange); + final var spender = accountEntityPersistHistorical(evm30HistoricalRange); + final var tokenEntity = tokenEntityPersistHistorical(evm30HistoricalRange); + fungibleTokenPersistHistorical(tokenEntity, evm30HistoricalRange); // Persist the token and the accounts in block (X-1), but the token allowance in block X. The call against block // (X-1) should fail as the allowance is not available yet. - persistTokenAllowanceHistorical(tokenEntity, owner, spender, amountGranted, historicalRangeAfterEvm34); + tokenAllowancePersistHistorical(tokenEntity, owner, spender, historicalRangeAfterEvm34); - setupHistoricalStateInService(EVM_V_30_BLOCK, evm30RecordFile); + setupHistoricalStateInService(EVM_V_34_BLOCK - 1, evm30RecordFile); final var contract = testWeb3jService.deploy(PrecompileTestContractHistorical::deploy); // When @@ -140,19 +138,19 @@ void getAllowanceForFungibleTokenNotPersistedYetReturnsZero() throws Exception { @Test void getAllowanceForNftNotPersistedYetReturnsZero() throws Exception { // Given - final var evm30RecordFile = persistRecordFile(EVM_V_30_BLOCK); - final var evm30HistoricalRange = setupHistoricalStateInService(EVM_V_30_BLOCK, evm30RecordFile); + final var evm30RecordFile = recordFilePersist(EVM_V_34_BLOCK - 1); + final var evm30HistoricalRange = setupHistoricalStateInService(EVM_V_34_BLOCK - 1, evm30RecordFile); final var historicalRangeAfterEvm34 = setUpHistoricalContext(EVM_V_34_BLOCK); - final var owner = persistAccountEntityHistorical(evm30HistoricalRange); - final var spender = persistAccountEntityHistorical(evm30HistoricalRange); - final var tokenEntity = persistNftHistorical(evm30HistoricalRange); + final var owner = accountEntityPersistHistorical(evm30HistoricalRange); + final var spender = accountEntityPersistHistorical(evm30HistoricalRange); + final var tokenEntity = nftPersistHistorical(evm30HistoricalRange); // Persist the token and the accounts in block (X-1), but the nft allowance in block X. The call against block // (X-1) // should fail as the allowance is not available yet. - persistNftAllowanceHistorical(tokenEntity, owner, spender, historicalRangeAfterEvm34); + nftAllowancePersistHistorical(tokenEntity, owner, spender, historicalRangeAfterEvm34); - setupHistoricalStateInService(EVM_V_30_BLOCK, evm30RecordFile); + setupHistoricalStateInService(EVM_V_34_BLOCK - 1, evm30RecordFile); final var contract = testWeb3jService.deploy(PrecompileTestContractHistorical::deploy); // When @@ -167,20 +165,20 @@ void getAllowanceForNftNotPersistedYetReturnsZero() throws Exception { @Test void getFungibleTokenInfoCustomFeesNotPersistedYetReturnsZero() throws Exception { // Given - final var evm30RecordFile = persistRecordFile(EVM_V_30_BLOCK); - final var evm30HistoricalRange = setupHistoricalStateInService(EVM_V_30_BLOCK, evm30RecordFile); + final var evm30RecordFile = recordFilePersist(EVM_V_34_BLOCK - 1); + final var evm30HistoricalRange = setupHistoricalStateInService(EVM_V_34_BLOCK - 1, evm30RecordFile); final var historicalRangeAfterEvm34 = setUpHistoricalContext(EVM_V_34_BLOCK); - final var tokenEntity = persistFungibleTokenHistorical(evm30HistoricalRange); - final var feeCollector = persistAccountEntityHistorical(evm30HistoricalRange); + final var tokenEntity = fungibleTokenPersistHistorical(evm30HistoricalRange); + final var feeCollector = accountEntityPersistHistorical(evm30HistoricalRange); // Persist the token and the account in block (X-1), but the custom fees in block X. The call against block // (X-1) // should fail as the custom fees are not available yet. - persistCustomFeesWithFeeCollectorHistorical( + customFeesWithFeeCollectorPersistHistorical( feeCollector, tokenEntity, TokenTypeEnum.FUNGIBLE_COMMON, historicalRangeAfterEvm34); - setupHistoricalStateInService(EVM_V_30_BLOCK, evm30RecordFile); + setupHistoricalStateInService(EVM_V_34_BLOCK - 1, evm30RecordFile); final var contract = testWeb3jService.deploy(PrecompileTestContractHistorical::deploy); // When @@ -197,20 +195,20 @@ void getFungibleTokenInfoCustomFeesNotPersistedYetReturnsZero() throws Exception @Test void getNftInfoCustomFeesNotPersistedYetReturnsZero() throws Exception { // Given - final var evm30RecordFile = persistRecordFile(EVM_V_30_BLOCK); - final var evm30HistoricalRange = setupHistoricalStateInService(EVM_V_30_BLOCK, evm30RecordFile); + final var evm30RecordFile = recordFilePersist(EVM_V_34_BLOCK - 1); + final var evm30HistoricalRange = setupHistoricalStateInService(EVM_V_34_BLOCK - 1, evm30RecordFile); final var historicalRangeAfterEvm34 = setUpHistoricalContext(EVM_V_34_BLOCK); - final var tokenEntity = persistNftHistorical(evm30HistoricalRange); - final var feeCollector = persistAccountEntityHistorical(evm30HistoricalRange); + final var tokenEntity = nftPersistHistorical(evm30HistoricalRange); + final var feeCollector = accountEntityPersistHistorical(evm30HistoricalRange); // Persist the token and the account in block (X-1), but the custom fees in block X. The call against block // (X-1) // should fail as the custom fees are not available yet. - persistCustomFeesWithFeeCollectorHistorical( + customFeesWithFeeCollectorPersistHistorical( feeCollector, tokenEntity, TokenTypeEnum.NON_FUNGIBLE_UNIQUE, historicalRangeAfterEvm34); - setupHistoricalStateInService(EVM_V_30_BLOCK, evm30RecordFile); + setupHistoricalStateInService(EVM_V_34_BLOCK - 1, evm30RecordFile); final var contract = testWeb3jService.deploy(PrecompileTestContractHistorical::deploy); // When @@ -227,13 +225,13 @@ void getNftInfoCustomFeesNotPersistedYetReturnsZero() throws Exception { @Test void tokenBalanceNotPersistedYetThrowsException() { // Given - final var evm38RecordFile = persistRecordFile(EVM_V_38_BLOCK); + final var evm38RecordFile = recordFilePersist(EVM_V_38_BLOCK); final var evm38HistoricalRange = setupHistoricalStateInService(EVM_V_38_BLOCK, evm38RecordFile); final var historicalRangeAfterEvm38 = setUpHistoricalContext(EVM_V_38_BLOCK + 1); - final var accountEntity = persistAccountEntityHistorical(evm38HistoricalRange); - final var receiverEntity = persistAccountEntityHistorical(evm38HistoricalRange); - final var tokenEntity = persistTokenEntityHistorical(evm38HistoricalRange); + final var accountEntity = accountEntityPersistHistorical(evm38HistoricalRange); + final var receiverEntity = accountEntityPersistHistorical(evm38HistoricalRange); + final var tokenEntity = tokenEntityPersistHistorical(evm38HistoricalRange); domainBuilder .tokenHistory() .customize(t -> t.tokenId(tokenEntity.getId()) @@ -242,12 +240,12 @@ void tokenBalanceNotPersistedYetThrowsException() { .treasuryAccountId(accountEntity.toEntityId()) .timestampRange(evm38HistoricalRange)) .persist(); - persistTokenBalanceHistorical(accountEntity.toEntityId(), tokenEntity.toEntityId(), 1L, evm38HistoricalRange); + tokenBalancePersistHistorical(accountEntity.toEntityId(), tokenEntity.toEntityId(), 1L, evm38HistoricalRange); // Persist the token, the account, balance1 in block (X-1) and balance2 in block X, where balance1 < balance2. // The call against block (X-1) // should fail with balance2, since the bigger balance is not available at this point. - persistTokenBalanceHistorical( + tokenBalancePersistHistorical( accountEntity.toEntityId(), tokenEntity.toEntityId(), 2L, historicalRangeAfterEvm38); setupHistoricalStateInService(EVM_V_38_BLOCK, evm38HistoricalRange); @@ -267,12 +265,12 @@ void tokenBalanceNotPersistedYetThrowsException() { @Test void transferWithNoPersistedCryptoAllowanceThrowsException() { // Given - final var evm38RecordFile = persistRecordFile(EVM_V_38_BLOCK); + final var evm38RecordFile = recordFilePersist(EVM_V_38_BLOCK); final var evm38HistoricalRange = setupHistoricalStateInService(EVM_V_38_BLOCK, evm38RecordFile); final var historicalRangeAfterEvm38 = setUpHistoricalContext(EVM_V_38_BLOCK + 1); - final var sender = persistAccountEntityHistorical(evm38HistoricalRange); - final var receiver = persistAccountEntityHistorical(evm38HistoricalRange); + final var sender = accountEntityPersistHistorical(evm38HistoricalRange); + final var receiver = accountEntityPersistHistorical(evm38HistoricalRange); setupHistoricalStateInService(EVM_V_38_BLOCK, evm38HistoricalRange); final var contract = testWeb3jService.deploy(ModificationPrecompileTestContract::deploy); @@ -281,7 +279,7 @@ void transferWithNoPersistedCryptoAllowanceThrowsException() { // The accounts are persisted against block (X-1) but the crypto allowance is persisted in // block X, so the call against block (X-1) fails as there is no allowance yet. - persistCryptoAllowanceHistorical(sender, contractEntityId, 5L, historicalRangeAfterEvm38); + cryptoAllowancePersistHistorical(sender, contractEntityId, 5L, historicalRangeAfterEvm38); testWeb3jService.setSender(getAddressFromEntity(sender)); final var transferList = new TransferList(List.of( @@ -299,18 +297,18 @@ void transferWithNoPersistedCryptoAllowanceThrowsException() { @Test void accountBalanceNotPersistedYetReturnsPreviousBalance() throws Exception { // Given - final var evm30RecordFile = persistRecordFile(EVM_V_30_BLOCK); - final var evm30HistoricalRange = setupHistoricalStateInService(EVM_V_30_BLOCK, evm30RecordFile); + final var evm30RecordFile = recordFilePersist(EVM_V_34_BLOCK - 1); + final var evm30HistoricalRange = setupHistoricalStateInService(EVM_V_34_BLOCK - 1, evm30RecordFile); final var historicalRangeAfterEvm34 = setUpHistoricalContext(EVM_V_34_BLOCK); - final var feeCollector = persistAccountWithBalanceHistorical(100L, evm30HistoricalRange); + final var feeCollector = accountWithBalancePersistHistorical(100L, evm30HistoricalRange); - setupHistoricalStateInService(EVM_V_30_BLOCK, evm30RecordFile); + setupHistoricalStateInService(EVM_V_34_BLOCK - 1, evm30RecordFile); final var contract = testWeb3jService.deploy(EvmCodesHistorical::deploy); // Persist the token, the account and the account balance in block 49. In block 50 enter another // account balance. The call against block 49 should return the first balance as the second // balance is not available at that point yet. - persistAccountBalanceHistorical(feeCollector.toEntityId(), 200L, historicalRangeAfterEvm34); + accountBalancePersistHistorical(feeCollector.toEntityId(), 200L, historicalRangeAfterEvm34); // When final var result = contract.call_getAccountBalance(getAddressFromEntity(feeCollector)) diff --git a/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallServicePrecompileHistoricalTest.java b/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallServicePrecompileHistoricalTest.java index 908747b59e6..55270abd907 100644 --- a/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallServicePrecompileHistoricalTest.java +++ b/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallServicePrecompileHistoricalTest.java @@ -75,7 +75,7 @@ class ContractCallServicePrecompileHistoricalTest extends AbstractContractCallSe void isTokenFrozen(long blockNumber) throws Exception { // Given final var historicalRange = setUpHistoricalContext(blockNumber); - final var accountAndToken = persistAccountTokenRelationshipHistorical(true, historicalRange); + final var accountAndToken = accountTokenAndFrozenRelationshipPersistHistorical(historicalRange); final var contract = testWeb3jService.deploy(PrecompileTestContractHistorical::deploy); @@ -92,7 +92,7 @@ void isTokenFrozen(long blockNumber) throws Exception { void isTokenFrozenWithAlias(long blockNumber) throws Exception { // Given final var historicalRange = setUpHistoricalContext(blockNumber); - final var accountAndToken = persistAccountTokenRelationshipHistorical(true, historicalRange); + final var accountAndToken = accountTokenAndFrozenRelationshipPersistHistorical(historicalRange); final var contract = testWeb3jService.deploy(PrecompileTestContractHistorical::deploy); // When @@ -108,10 +108,10 @@ void isTokenFrozenWithAlias(long blockNumber) throws Exception { void isKycGranted(long blockNumber) throws Exception { // Given final var historicalRange = setUpHistoricalContext(blockNumber); - final var account = persistAccountEntityHistorical(historicalRange); - final var tokenEntity = persistTokenEntityHistorical(historicalRange); - persistFungibleTokenHistorical(tokenEntity, historicalRange); - persistTokenRelationshipWithKycGrantedHistorical(tokenEntity, account, historicalRange); + final var account = accountEntityPersistHistorical(historicalRange); + final var tokenEntity = tokenEntityPersistHistorical(historicalRange); + fungibleTokenPersistHistorical(tokenEntity, historicalRange); + tokenAccountFrozenRelationshipPersistHistorical(tokenEntity, account, historicalRange); final var contract = testWeb3jService.deploy(PrecompileTestContractHistorical::deploy); @@ -128,10 +128,10 @@ void isKycGranted(long blockNumber) throws Exception { void isKycGrantedWithAlias(long blockNumber) throws Exception { // Given final var historicalRange = setUpHistoricalContext(blockNumber); - final var account = persistAccountEntityHistoricalWithAlias(historicalRange); - final var tokenEntity = persistTokenEntityHistorical(historicalRange); - persistFungibleTokenHistorical(tokenEntity, historicalRange); - persistTokenRelationshipWithKycGrantedHistorical(tokenEntity, account, historicalRange); + final var account = accountEntityWithAliasPersistHistorical(historicalRange); + final var tokenEntity = tokenEntityPersistHistorical(historicalRange); + fungibleTokenPersistHistorical(tokenEntity, historicalRange); + tokenAccountFrozenRelationshipPersistHistorical(tokenEntity, account, historicalRange); final var contract = testWeb3jService.deploy(PrecompileTestContractHistorical::deploy); @@ -148,9 +148,9 @@ void isKycGrantedWithAlias(long blockNumber) throws Exception { void isKycGrantedForNFT(long blockNumber) throws Exception { // Given final var historicalRange = setUpHistoricalContext(blockNumber); - final var account = persistAccountEntityHistorical(historicalRange); - final var tokenEntity = persistNftHistorical(historicalRange); - persistTokenRelationshipWithKycGrantedHistorical(tokenEntity, account, historicalRange); + final var account = accountEntityPersistHistorical(historicalRange); + final var tokenEntity = nftPersistHistorical(historicalRange); + tokenAccountFrozenRelationshipPersistHistorical(tokenEntity, account, historicalRange); final var contract = testWeb3jService.deploy(PrecompileTestContractHistorical::deploy); @@ -167,9 +167,9 @@ void isKycGrantedForNFT(long blockNumber) throws Exception { void isKycGrantedForNFTWithAlias(long blockNumber) throws Exception { // Given final var historicalRange = setUpHistoricalContext(blockNumber); - final var account = persistAccountEntityHistoricalWithAlias(historicalRange); - final var tokenEntity = persistNftHistorical(historicalRange); - persistTokenRelationshipWithKycGrantedHistorical(tokenEntity, account, historicalRange); + final var account = accountEntityWithAliasPersistHistorical(historicalRange); + final var tokenEntity = nftPersistHistorical(historicalRange); + tokenAccountFrozenRelationshipPersistHistorical(tokenEntity, account, historicalRange); final var contract = testWeb3jService.deploy(PrecompileTestContractHistorical::deploy); @@ -186,8 +186,8 @@ void isKycGrantedForNFTWithAlias(long blockNumber) throws Exception { void isTokenAddress(long blockNumber) throws Exception { // Given final var historicalRange = setUpHistoricalContext(blockNumber); - final var tokenEntity = persistTokenEntityHistorical(historicalRange); - persistFungibleTokenHistorical(tokenEntity, historicalRange); + final var tokenEntity = tokenEntityPersistHistorical(historicalRange); + fungibleTokenPersistHistorical(tokenEntity, historicalRange); final var contract = testWeb3jService.deploy(PrecompileTestContractHistorical::deploy); @@ -203,7 +203,7 @@ void isTokenAddress(long blockNumber) throws Exception { void isTokenAddressNFT(long blockNumber) throws Exception { // Given final var historicalRange = setUpHistoricalContext(blockNumber); - final var tokenEntity = persistNftHistorical(historicalRange); + final var tokenEntity = nftPersistHistorical(historicalRange); final var contract = testWeb3jService.deploy(PrecompileTestContractHistorical::deploy); @@ -219,7 +219,7 @@ void isTokenAddressNFT(long blockNumber) throws Exception { void getDefaultKycToken(long blockNumber) throws Exception { // Given final var historicalRange = setUpHistoricalContext(blockNumber); - final var tokenEntity = persistTokenEntityHistorical(historicalRange); + final var tokenEntity = tokenEntityPersistHistorical(historicalRange); domainBuilder .token() .customize(t -> t.tokenId(tokenEntity.getId()) @@ -242,7 +242,7 @@ void getDefaultKycToken(long blockNumber) throws Exception { void getDefaultKycNFT(long blockNumber) throws Exception { // Given final var historicalRange = setUpHistoricalContext(blockNumber); - final var tokenEntity = persistNftHistorical(historicalRange); + final var tokenEntity = nftPersistHistorical(historicalRange); final var contract = testWeb3jService.deploy(PrecompileTestContractHistorical::deploy); @@ -258,8 +258,8 @@ void getDefaultKycNFT(long blockNumber) throws Exception { void getTokenType(long blockNumber) throws Exception { // Given final var historicalRange = setUpHistoricalContext(blockNumber); - final var tokenEntity = persistTokenEntityHistorical(historicalRange); - persistFungibleTokenHistorical(tokenEntity, historicalRange); + final var tokenEntity = tokenEntityPersistHistorical(historicalRange); + fungibleTokenPersistHistorical(tokenEntity, historicalRange); final var contract = testWeb3jService.deploy(PrecompileTestContractHistorical::deploy); @@ -275,7 +275,7 @@ void getTokenType(long blockNumber) throws Exception { void getTokenTypeNFT(long blockNumber) throws Exception { // Given final var historicalRange = setUpHistoricalContext(blockNumber); - final var tokenEntity = persistNftHistorical(historicalRange); + final var tokenEntity = nftPersistHistorical(historicalRange); final var contract = testWeb3jService.deploy(PrecompileTestContractHistorical::deploy); @@ -291,7 +291,7 @@ void getTokenTypeNFT(long blockNumber) throws Exception { void getTokenDefaultFreeze(long blockNumber) throws Exception { // Given final var historicalRange = setUpHistoricalContext(blockNumber); - final var tokenEntity = persistTokenEntityHistorical(historicalRange); + final var tokenEntity = tokenEntityPersistHistorical(historicalRange); domainBuilder .token() .customize(t -> t.tokenId(tokenEntity.getId()) @@ -314,7 +314,7 @@ void getTokenDefaultFreeze(long blockNumber) throws Exception { void getNFTDefaultFreeze(long blockNumber) throws Exception { // Given final var historicalRange = setUpHistoricalContext(blockNumber); - final var tokenEntity = persistTokenEntityHistorical(historicalRange); + final var tokenEntity = tokenEntityPersistHistorical(historicalRange); domainBuilder .token() .customize(t -> t.tokenId(tokenEntity.getId()) @@ -341,9 +341,9 @@ void getNFTDefaultFreeze(long blockNumber) throws Exception { void getCustomFeesForTokenWithFixedFee(long blockNumber) throws Exception { // Given final var historicalRange = setUpHistoricalContext(blockNumber); - final var tokenEntity = persistTokenEntityHistorical(historicalRange); - persistFungibleTokenHistorical(tokenEntity, historicalRange); - final var collectorAccount = persistAccountEntityHistoricalWithAlias(historicalRange); + final var tokenEntity = tokenEntityPersistHistorical(historicalRange); + fungibleTokenPersistHistorical(tokenEntity, historicalRange); + final var collectorAccount = accountEntityWithAliasPersistHistorical(historicalRange); final var fixedFee = com.hedera.mirror.common.domain.token.FixedFee.builder() .amount(100L) .collectorAccountId(collectorAccount.toEntityId()) @@ -381,9 +381,9 @@ void getCustomFeesForTokenWithFixedFee(long blockNumber) throws Exception { void getCustomFeesForTokenWithFractionalFee(long blockNumber) throws Exception { // Given final var historicalRange = setUpHistoricalContext(blockNumber); - final var collectorAccount = persistAccountEntityHistoricalWithAlias(historicalRange); - final var tokenEntity = persistTokenEntityHistorical(historicalRange); - persistFungibleTokenHistorical(tokenEntity, historicalRange); + final var collectorAccount = accountEntityWithAliasPersistHistorical(historicalRange); + final var tokenEntity = tokenEntityPersistHistorical(historicalRange); + fungibleTokenPersistHistorical(tokenEntity, historicalRange); final var fractionalFee = FractionalFee.builder() .collectorAccountId(collectorAccount.toEntityId()) .denominator(10L) @@ -425,9 +425,9 @@ void getCustomFeesForTokenWithFractionalFee(long blockNumber) throws Exception { void getCustomFeesForTokenWithRoyaltyFee(long blockNumber) throws Exception { // Given final var historicalRange = setUpHistoricalContext(blockNumber); - final var collectorAccount = persistAccountEntityHistoricalWithAlias(historicalRange); - final var tokenEntity = persistTokenEntityHistorical(historicalRange); - persistFungibleTokenHistorical(tokenEntity, historicalRange); + final var collectorAccount = accountEntityWithAliasPersistHistorical(historicalRange); + final var tokenEntity = tokenEntityPersistHistorical(historicalRange); + fungibleTokenPersistHistorical(tokenEntity, historicalRange); final var royaltyFee = RoyaltyFee.builder() .collectorAccountId(collectorAccount.toEntityId()) .denominator(10L) @@ -473,7 +473,7 @@ void getExpiryForToken(long blockNumber) throws Exception { final var historicalRange = setUpHistoricalContext(blockNumber); final var expiryPeriod = 9999999999999L; final var autoRenewExpiry = 100000000L; - final var autoRenewAccount = persistAccountEntityHistorical(historicalRange); + final var autoRenewAccount = accountEntityPersistHistorical(historicalRange); final var tokenEntity = domainBuilder .entity() .customize(e -> e.type(EntityType.TOKEN) @@ -482,7 +482,7 @@ void getExpiryForToken(long blockNumber) throws Exception { .timestampRange(historicalRange) .autoRenewPeriod(autoRenewExpiry)) .persist(); - persistFungibleTokenHistorical(tokenEntity, historicalRange); + fungibleTokenPersistHistorical(tokenEntity, historicalRange); final var contract = testWeb3jService.deploy(PrecompileTestContractHistorical::deploy); // When @@ -504,8 +504,8 @@ void getExpiryForToken(long blockNumber) throws Exception { void getApproved(long blockNumber) throws Exception { // Given final var historicalRange = setUpHistoricalContext(blockNumber); - final var approvedAccount = persistAccountEntityHistoricalWithAlias(historicalRange); - final var tokenEntity = persistTokenEntityHistorical(historicalRange); + final var approvedAccount = accountEntityWithAliasPersistHistorical(historicalRange); + final var tokenEntity = tokenEntityPersistHistorical(historicalRange); domainBuilder .token() .customize(t -> t.tokenId(tokenEntity.getId()) @@ -537,10 +537,10 @@ void getAllowanceForToken(long blockNumber) throws Exception { // Given final var historicalRange = setUpHistoricalContext(blockNumber); final var amountGranted = 50L; - final var owner = persistAccountEntityHistorical(historicalRange); - final var spender = persistAccountEntityHistorical(historicalRange); - final var tokenEntity = persistTokenEntityHistorical(historicalRange); - persistFungibleTokenHistorical(tokenEntity, historicalRange); + final var owner = accountEntityPersistHistorical(historicalRange); + final var spender = accountEntityPersistHistorical(historicalRange); + final var tokenEntity = tokenEntityPersistHistorical(historicalRange); + fungibleTokenPersistHistorical(tokenEntity, historicalRange); domainBuilder .tokenAllowance() @@ -567,9 +567,9 @@ void getAllowanceForToken(long blockNumber) throws Exception { void isApprovedForAllNFT(long blockNumber) throws Exception { // Given final var historicalRange = setUpHistoricalContext(blockNumber); - final var owner = persistAccountEntityHistorical(historicalRange); - final var spender = persistAccountEntityHistorical(historicalRange); - final var tokenEntity = persistNftHistorical(historicalRange); + final var owner = accountEntityPersistHistorical(historicalRange); + final var spender = accountEntityPersistHistorical(historicalRange); + final var tokenEntity = nftPersistHistorical(historicalRange); domainBuilder .nftAllowance() @@ -603,7 +603,7 @@ void getFungibleTokenInfo(long blockNumber) throws Exception { .persist(); final var treasury = accountPersistWithBalanceHistorical(tokenSupply, tokenEntity.toEntityId(), historicalRange); - final var feeCollector = persistAccountEntityHistorical(historicalRange); + final var feeCollector = accountEntityPersistHistorical(historicalRange); final var token = domainBuilder .token() @@ -614,7 +614,7 @@ void getFungibleTokenInfo(long blockNumber) throws Exception { .totalSupply(tokenSupply)) .persist(); - final var customFees = persistCustomFeesWithFeeCollectorHistorical( + final var customFees = customFeesWithFeeCollectorPersistHistorical( feeCollector, tokenEntity, TokenTypeEnum.FUNGIBLE_COMMON, historicalRange); final var contract = testWeb3jService.deploy(PrecompileTestContractHistorical::deploy); @@ -649,9 +649,9 @@ void getNonFungibleTokenInfo(long blockNumber) throws Exception { // Given final var historicalRange = setUpHistoricalContext(blockNumber); - final var owner = persistAccountEntityHistorical(historicalRange); - final var treasury = persistAccountEntityHistorical(historicalRange); - final var feeCollector = persistAccountEntityHistorical(historicalRange); + final var owner = accountEntityPersistHistorical(historicalRange); + final var treasury = accountEntityPersistHistorical(historicalRange); + final var feeCollector = accountEntityPersistHistorical(historicalRange); final var tokenEntity = domainBuilder .entity() .customize(e -> e.type(EntityType.TOKEN) @@ -676,7 +676,7 @@ void getNonFungibleTokenInfo(long blockNumber) throws Exception { .createdTimestamp(historicalRange.lowerEndpoint())) .persist(); - final var customFees = persistCustomFeesWithFeeCollectorHistorical( + final var customFees = customFeesWithFeeCollectorPersistHistorical( feeCollector, tokenEntity, TokenTypeEnum.NON_FUNGIBLE_UNIQUE, historicalRange); final var contract = testWeb3jService.deploy(PrecompileTestContractHistorical::deploy); @@ -724,7 +724,7 @@ void getTokenInfoFungible(long blockNumber) throws Exception { .persist(); final var treasury = accountPersistWithBalanceHistorical(tokenSupply, tokenEntity.toEntityId(), historicalRange); - final var feeCollector = persistAccountEntityHistorical(historicalRange); + final var feeCollector = accountEntityPersistHistorical(historicalRange); final var token = domainBuilder .token() @@ -735,7 +735,7 @@ void getTokenInfoFungible(long blockNumber) throws Exception { .totalSupply(tokenSupply)) .persist(); - final var customFees = persistCustomFeesWithFeeCollectorHistorical( + final var customFees = customFeesWithFeeCollectorPersistHistorical( feeCollector, tokenEntity, TokenTypeEnum.FUNGIBLE_COMMON, historicalRange); final var contract = testWeb3jService.deploy(PrecompileTestContractHistorical::deploy); @@ -764,8 +764,8 @@ void getTokenInfoFungible(long blockNumber) throws Exception { void getTokenInfoNonFungible(long blockNumber) throws Exception { // Given final var historicalRange = setUpHistoricalContext(blockNumber); - final var treasury = persistAccountEntityHistorical(historicalRange); - final var feeCollector = persistAccountEntityHistorical(historicalRange); + final var treasury = accountEntityPersistHistorical(historicalRange); + final var feeCollector = accountEntityPersistHistorical(historicalRange); final var tokenEntity = domainBuilder .entity() .customize(e -> e.type(EntityType.TOKEN) @@ -789,7 +789,7 @@ void getTokenInfoNonFungible(long blockNumber) throws Exception { .createdTimestamp(historicalRange.lowerEndpoint())) .persist(); - final var customFees = persistCustomFeesWithFeeCollectorHistorical( + final var customFees = customFeesWithFeeCollectorPersistHistorical( feeCollector, tokenEntity, TokenTypeEnum.NON_FUNGIBLE_UNIQUE, historicalRange); final var contract = testWeb3jService.deploy(PrecompileTestContractHistorical::deploy); @@ -1160,16 +1160,4 @@ private PrecompileTestContractHistorical.TokenInfo createExpectedTokenInfo( royaltyFees, LEDGER_ID); } - - private void persistTokenRelationshipWithKycGrantedHistorical( - final Entity tokenEntity, final Entity account, final Range historicalRange) { - domainBuilder - .tokenAccount() - .customize(ta -> ta.tokenId(tokenEntity.getId()) - .accountId(account.getId()) - .kycStatus(TokenKycStatusEnum.GRANTED) - .associated(true) - .timestampRange(historicalRange)) - .persist(); - } } diff --git a/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallServicePrecompileModificationTest.java b/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallServicePrecompileModificationTest.java index e59423daa37..87f34a5de50 100644 --- a/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallServicePrecompileModificationTest.java +++ b/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallServicePrecompileModificationTest.java @@ -79,9 +79,9 @@ class ContractCallServicePrecompileModificationTest extends AbstractContractCall @Test void transferFrom() throws Exception { // Given - final var owner = persistAccountEntity(); - final var spender = persistAccountEntity(); - final var recipient = persistAccountEntity(); + final var owner = accountEntityPersist(); + final var spender = accountEntityPersist(); + final var recipient = accountEntityPersist(); final var tokenEntity = domainBuilder.entity().customize(e -> e.type(EntityType.TOKEN)).persist(); @@ -92,14 +92,14 @@ void transferFrom() throws Exception { .treasuryAccountId(owner.toEntityId())) .persist(); - persistAssociation(tokenEntity, spender); - persistAssociation(tokenEntity, recipient); + tokenAccountPersist(tokenEntity, spender); + tokenAccountPersist(tokenEntity, recipient); final var contract = testWeb3jService.deploy(ModificationPrecompileTestContract::deploy); final var contractAddress = Address.fromHexString(contract.getContractAddress()); final var contractEntityId = entityIdFromEvmAddress(contractAddress); - persistAssociation(tokenEntity, contractEntityId.getId()); + tokenAccountPersist(tokenEntity, contractEntityId.getId()); domainBuilder .tokenAllowance() @@ -125,16 +125,16 @@ void transferFrom() throws Exception { @CsvSource({"1", "0"}) void approve(final BigInteger allowance) throws Exception { // Given - final var spender = persistAccountEntity(); + final var spender = accountEntityPersist(); final var tokenEntity = persistFungibleToken(); - persistAssociation(tokenEntity, spender); + tokenAccountPersist(tokenEntity, spender); final var contract = testWeb3jService.deploy(ModificationPrecompileTestContract::deploy); final var contractAddress = Address.fromHexString(contract.getContractAddress()); final var contractEntityId = entityIdFromEvmAddress(contractAddress); - persistAssociation(tokenEntity, contractEntityId.getId()); + tokenAccountPersist(tokenEntity, contractEntityId.getId()); // When final var functionCall = contract.call_approveExternal( @@ -149,8 +149,8 @@ void approve(final BigInteger allowance) throws Exception { @ValueSource(booleans = {true, false}) void approveNFT(final Boolean approve) throws Exception { // Given - final var owner = persistAccountEntity(); - final var spender = persistAccountEntity(); + final var owner = accountEntityPersist(); + final var spender = accountEntityPersist(); final var tokenEntity = domainBuilder.entity().customize(e -> e.type(EntityType.TOKEN)).persist(); @@ -159,14 +159,14 @@ void approveNFT(final Boolean approve) throws Exception { .customize(t -> t.tokenId(tokenEntity.getId()).type(TokenTypeEnum.NON_FUNGIBLE_UNIQUE)) .persist(); - persistAssociation(tokenEntity, owner); - persistAssociation(tokenEntity, spender); + tokenAccountPersist(tokenEntity, owner); + tokenAccountPersist(tokenEntity, spender); final var contract = testWeb3jService.deploy(ModificationPrecompileTestContract::deploy); final var contractAddress = Address.fromHexString(contract.getContractAddress()); final var contractEntityId = entityIdFromEvmAddress(contractAddress); - persistAssociation(tokenEntity, contractEntityId.getId()); + tokenAccountPersist(tokenEntity, contractEntityId.getId()); domainBuilder .nft() @@ -187,7 +187,7 @@ void approveNFT(final Boolean approve) throws Exception { @Test void setApprovalForAll() throws Exception { // Given - final var spender = persistAccountEntity(); + final var spender = accountEntityPersist(); final var tokenEntity = domainBuilder.entity().customize(e -> e.type(EntityType.TOKEN)).persist(); @@ -196,13 +196,13 @@ void setApprovalForAll() throws Exception { .customize(t -> t.tokenId(tokenEntity.getId()).type(TokenTypeEnum.NON_FUNGIBLE_UNIQUE)) .persist(); - persistAssociation(tokenEntity, spender); + tokenAccountPersist(tokenEntity, spender); final var contract = testWeb3jService.deploy(ModificationPrecompileTestContract::deploy); final var contractAddress = Address.fromHexString(contract.getContractAddress()); final var contractEntityId = entityIdFromEvmAddress(contractAddress); - persistAssociation(tokenEntity, contractEntityId.getId()); + tokenAccountPersist(tokenEntity, contractEntityId.getId()); domainBuilder .nft() @@ -222,7 +222,7 @@ void setApprovalForAll() throws Exception { @ValueSource(booleans = {true, false}) void associateToken(final Boolean single) throws Exception { // Given - final var notAssociatedAccount = persistAccountEntity(); + final var notAssociatedAccount = accountEntityPersist(); final var tokenEntity = domainBuilder.entity().customize(e -> e.type(EntityType.TOKEN)).persist(); @@ -269,7 +269,7 @@ void associateTokenHRC() throws Exception { @ValueSource(booleans = {true, false}) void dissociateToken(final Boolean single) throws Exception { // Given - final var associatedAccount = persistAccountEntity(); + final var associatedAccount = accountEntityPersist(); final var tokenEntity = domainBuilder.entity().customize(e -> e.type(EntityType.TOKEN)).persist(); @@ -278,7 +278,7 @@ void dissociateToken(final Boolean single) throws Exception { .customize(t -> t.tokenId(tokenEntity.getId()).type(TokenTypeEnum.FUNGIBLE_COMMON)) .persist(); - persistAssociation(tokenEntity, associatedAccount); + tokenAccountPersist(tokenEntity, associatedAccount); final var contract = testWeb3jService.deploy(ModificationPrecompileTestContract::deploy); @@ -308,7 +308,7 @@ void dissociateTokenHRC() throws Exception { final var contractAddress = Address.fromHexString(contract.getContractAddress()); final var contractEntityId = entityIdFromEvmAddress(contractAddress); - persistAssociation(tokenEntity, contractEntityId.getId()); + tokenAccountPersist(tokenEntity, contractEntityId.getId()); // When final var functionCall = contract.call_dissociateWithRedirect(getAddressFromEntity(tokenEntity)); @@ -321,15 +321,15 @@ void dissociateTokenHRC() throws Exception { @Test void mintFungibleToken() throws Exception { // Given - final var treasury = persistAccountEntity(); - final var tokenEntity = persistTokenEntity(); + final var treasury = accountEntityPersist(); + final var tokenEntity = tokenEntityPersist(); final var token = domainBuilder .token() .customize(t -> t.tokenId(tokenEntity.getId()) .type(TokenTypeEnum.FUNGIBLE_COMMON) .treasuryAccountId(treasury.toEntityId())) .persist(); - persistAssociation(tokenEntity, treasury); + tokenAccountPersist(tokenEntity, treasury); final var totalSupply = token.getTotalSupply(); @@ -349,15 +349,15 @@ void mintFungibleToken() throws Exception { @Test void mintNFT() throws Exception { // Given - final var treasury = persistAccountEntity(); - final var tokenEntity = persistTokenEntity(); + final var treasury = accountEntityPersist(); + final var tokenEntity = tokenEntityPersist(); domainBuilder .token() .customize(t -> t.tokenId(tokenEntity.getId()) .type(TokenTypeEnum.NON_FUNGIBLE_UNIQUE) .treasuryAccountId(treasury.toEntityId())) .persist(); - persistAssociation(tokenEntity, treasury); + tokenAccountPersist(tokenEntity, treasury); final var contract = testWeb3jService.deploy(ModificationPrecompileTestContract::deploy); @@ -376,15 +376,15 @@ void mintNFT() throws Exception { @Test void burnFungibleToken() throws Exception { // Given - final var treasury = persistAccountEntity(); - final var tokenEntity = persistTokenEntity(); + final var treasury = accountEntityPersist(); + final var tokenEntity = tokenEntityPersist(); final var token = domainBuilder .token() .customize(t -> t.tokenId(tokenEntity.getId()) .type(TokenTypeEnum.FUNGIBLE_COMMON) .treasuryAccountId(treasury.toEntityId())) .persist(); - persistAssociation(tokenEntity, treasury); + tokenAccountPersist(tokenEntity, treasury); final var totalSupply = token.getTotalSupply(); @@ -405,15 +405,15 @@ void burnFungibleToken() throws Exception { @Test void burnNFT() throws Exception { // Given - final var treasury = persistAccountEntity(); - final var tokenEntity = persistTokenEntity(); + final var treasury = accountEntityPersist(); + final var tokenEntity = tokenEntityPersist(); final var token = domainBuilder .token() .customize(t -> t.tokenId(tokenEntity.getId()) .type(TokenTypeEnum.NON_FUNGIBLE_UNIQUE) .treasuryAccountId(treasury.toEntityId())) .persist(); - persistAssociation(tokenEntity, treasury); + tokenAccountPersist(tokenEntity, treasury); final var totalSupply = token.getTotalSupply(); domainBuilder @@ -438,15 +438,15 @@ void burnNFT() throws Exception { @Test void wipeFungibleToken() throws Exception { // Given - final var owner = persistAccountEntity(); + final var owner = accountEntityPersist(); - final var tokenEntity = persistTokenEntity(); + final var tokenEntity = tokenEntityPersist(); domainBuilder .token() .customize(t -> t.tokenId(tokenEntity.getId()).type(TokenTypeEnum.FUNGIBLE_COMMON)) .persist(); - persistAssociation(tokenEntity, owner); + tokenAccountPersist(tokenEntity, owner); final var contract = testWeb3jService.deploy(ModificationPrecompileTestContract::deploy); @@ -462,15 +462,15 @@ void wipeFungibleToken() throws Exception { @Test void wipeNFT() throws Exception { // Given - final var owner = persistAccountEntity(); + final var owner = accountEntityPersist(); - final var tokenEntity = persistTokenEntity(); + final var tokenEntity = tokenEntityPersist(); domainBuilder .token() .customize(t -> t.tokenId(tokenEntity.getId()).type(TokenTypeEnum.NON_FUNGIBLE_UNIQUE)) .persist(); - persistAssociation(tokenEntity, owner); + tokenAccountPersist(tokenEntity, owner); domainBuilder .nft() .customize(n -> n.tokenId(tokenEntity.getId()).serialNumber(1L).accountId(owner.toEntityId())) @@ -490,15 +490,15 @@ void wipeNFT() throws Exception { @Test void grantTokenKyc() throws Exception { // Given - final var accountWithoutGrant = persistAccountEntity(); + final var accountWithoutGrant = accountEntityPersist(); - final var tokenEntity = persistTokenEntity(); + final var tokenEntity = tokenEntityPersist(); domainBuilder .token() .customize(t -> t.tokenId(tokenEntity.getId()).type(TokenTypeEnum.FUNGIBLE_COMMON)) .persist(); - persistAssociation(tokenEntity, accountWithoutGrant); + tokenAccountPersist(tokenEntity, accountWithoutGrant); final var contract = testWeb3jService.deploy(ModificationPrecompileTestContract::deploy); @@ -514,15 +514,15 @@ void grantTokenKyc() throws Exception { @Test void revokeTokenKyc() throws Exception { // Given - final var accountWithGrant = persistAccountEntity(); + final var accountWithGrant = accountEntityPersist(); - final var tokenEntity = persistTokenEntity(); + final var tokenEntity = tokenEntityPersist(); domainBuilder .token() .customize(t -> t.tokenId(tokenEntity.getId()).type(TokenTypeEnum.FUNGIBLE_COMMON)) .persist(); - persistAssociation(tokenEntity, accountWithGrant); + tokenAccountPersist(tokenEntity, accountWithGrant); final var contract = testWeb3jService.deploy(ModificationPrecompileTestContract::deploy); @@ -538,7 +538,7 @@ void revokeTokenKyc() throws Exception { @Test void deleteToken() throws Exception { // Given - final var tokenEntity = persistTokenEntity(); + final var tokenEntity = tokenEntityPersist(); domainBuilder .token() .customize(t -> t.tokenId(tokenEntity.getId()).type(TokenTypeEnum.FUNGIBLE_COMMON)) @@ -557,9 +557,9 @@ void deleteToken() throws Exception { @Test void freezeToken() throws Exception { // Given - final var accountWithoutFreeze = persistAccountEntity(); + final var accountWithoutFreeze = accountEntityPersist(); final var tokenEntity = persistFungibleToken(); - persistAssociation(tokenEntity, accountWithoutFreeze); + tokenAccountPersist(tokenEntity, accountWithoutFreeze); final var contract = testWeb3jService.deploy(ModificationPrecompileTestContract::deploy); @@ -575,7 +575,7 @@ void freezeToken() throws Exception { @Test void unfreezeToken() throws Exception { // Given - final var accountWithFreeze = persistAccountEntity(); + final var accountWithFreeze = accountEntityPersist(); final var tokenEntity = persistFungibleToken(); @@ -603,7 +603,7 @@ void unfreezeToken() throws Exception { @Test void pauseToken() throws Exception { // Given - final var tokenEntity = persistTokenEntity(); + final var tokenEntity = tokenEntityPersist(); domainBuilder .token() .customize(t -> t.tokenId(tokenEntity.getId()).type(TokenTypeEnum.FUNGIBLE_COMMON)) @@ -622,9 +622,9 @@ void pauseToken() throws Exception { @Test void unpauseToken() throws Exception { // Given - final var sender = persistAccountEntity(); + final var sender = accountEntityPersist(); - final var tokenEntity = persistTokenEntity(); + final var tokenEntity = tokenEntityPersist(); domainBuilder .token() .customize(t -> t.tokenId(tokenEntity.getId()) @@ -633,7 +633,7 @@ void unpauseToken() throws Exception { .pauseStatus(TokenPauseStatusEnum.PAUSED)) .persist(); - persistAssociation(tokenEntity, sender); + tokenAccountPersist(tokenEntity, sender); final var contract = testWeb3jService.deploy(ModificationPrecompileTestContract::deploy); @@ -686,7 +686,7 @@ void createFungibleTokenWithCustomFees() throws Exception { var value = 10000L * 100_000_000L; final var tokenForDenomination = persistFungibleToken(); - final var feeCollector = persistAccountEntity(); + final var feeCollector = accountEntityPersist(); final var contract = testWeb3jService.deploy(ModificationPrecompileTestContract::deploy); @@ -766,7 +766,7 @@ void createNonFungibleTokenWithCustomFees() throws Exception { var value = 10000L * 100_000_000L; final var tokenForDenomination = persistFungibleToken(); - final var feeCollector = persistAccountEntity(); + final var feeCollector = accountEntityPersist(); final var contract = testWeb3jService.deploy(ModificationPrecompileTestContract::deploy); @@ -811,10 +811,10 @@ void createNonFungibleTokenWithCustomFees() throws Exception { @Test void create2ContractAndTransferFromIt() throws Exception { // Given - final var sponsor = persistAccountEntity(); - final var receiver = persistAccountEntity(); + final var sponsor = accountEntityPersist(); + final var receiver = accountEntityPersist(); final var token = persistFungibleToken(); - persistAssociation(token, sponsor); + tokenAccountPersist(token, sponsor); final var contract = testWeb3jService.deploy(ModificationPrecompileTestContract::deploy); @@ -847,7 +847,7 @@ void notExistingPrecompileCallFails() { void createFungibleTokenWithInheritKeysCall() throws Exception { // Given final var value = 10000 * 100_000_000L; - final var sender = persistAccountEntity(); + final var sender = accountEntityPersist(); final var contract = testWeb3jService.deploy(ModificationPrecompileTestContract::deploy); // When @@ -1049,13 +1049,13 @@ void transferToken(final String type) throws Exception { // Given final var contract = testWeb3jService.deploy(ModificationPrecompileTestContract::deploy); final var tokenEntity = persistFungibleToken(); - final var sender = persistAccountEntity(); - final var receiver = persistAccountEntity(); - final var payer = persistAccountEntity(); + final var sender = accountEntityPersist(); + final var receiver = accountEntityPersist(); + final var payer = accountEntityPersist(); - persistAssociation(tokenEntity, payer); - persistAssociation(tokenEntity, sender); - persistAssociation(tokenEntity, receiver); + tokenAccountPersist(tokenEntity, payer); + tokenAccountPersist(tokenEntity, sender); + tokenAccountPersist(tokenEntity, receiver); // When testWeb3jService.setSender(getAliasFromEntity(payer)); @@ -1085,8 +1085,8 @@ void transferToken(final String type) throws Exception { void transferNft(final String type) throws Exception { // Given final var contract = testWeb3jService.deploy(ModificationPrecompileTestContract::deploy); - final var sender = persistAccountEntity(); - final var tokenEntity = persistTokenEntity(); + final var sender = accountEntityPersist(); + final var tokenEntity = tokenEntityPersist(); domainBuilder .token() .customize(t -> t.tokenId(tokenEntity.getId()).type(TokenTypeEnum.NON_FUNGIBLE_UNIQUE)) @@ -1095,12 +1095,12 @@ void transferNft(final String type) throws Exception { .nft() .customize(n -> n.tokenId(tokenEntity.getId()).serialNumber(1L).accountId(sender.toEntityId())) .persist(); - final var receiver = persistAccountEntity(); - final var payer = persistAccountEntity(); + final var receiver = accountEntityPersist(); + final var payer = accountEntityPersist(); - persistAssociation(tokenEntity, payer); - persistAssociation(tokenEntity, sender); - persistAssociation(tokenEntity, receiver); + tokenAccountPersist(tokenEntity, payer); + tokenAccountPersist(tokenEntity, sender); + tokenAccountPersist(tokenEntity, receiver); // When testWeb3jService.setSender(getAliasFromEntity(payer)); @@ -1130,8 +1130,8 @@ void transferNft(final String type) throws Exception { void transferFromNft() throws Exception { // Given final var contract = testWeb3jService.deploy(ModificationPrecompileTestContract::deploy); - final var sender = persistAccountEntity(); - final var tokenEntity = persistTokenEntity(); + final var sender = accountEntityPersist(); + final var tokenEntity = tokenEntityPersist(); domainBuilder .token() .customize(t -> t.tokenId(tokenEntity.getId()).type(TokenTypeEnum.NON_FUNGIBLE_UNIQUE)) @@ -1140,12 +1140,12 @@ void transferFromNft() throws Exception { .nft() .customize(n -> n.tokenId(tokenEntity.getId()).serialNumber(1L).accountId(sender.toEntityId())) .persist(); - final var receiver = persistAccountEntity(); - final var payer = persistAccountEntity(); + final var receiver = accountEntityPersist(); + final var payer = accountEntityPersist(); - persistAssociation(tokenEntity, payer); - persistAssociation(tokenEntity, sender); - persistAssociation(tokenEntity, receiver); + tokenAccountPersist(tokenEntity, payer); + tokenAccountPersist(tokenEntity, sender); + tokenAccountPersist(tokenEntity, receiver); // When testWeb3jService.setSender(getAliasFromEntity(payer)); @@ -1169,9 +1169,9 @@ void transferFromNft() throws Exception { void cryptoTransferHbars() throws Exception { // Given final var contract = testWeb3jService.deploy(ModificationPrecompileTestContract::deploy); - final var sender = persistAccountEntity(); - final var receiver = persistAccountEntity(); - final var payer = persistAccountEntity(); + final var sender = accountEntityPersist(); + final var receiver = accountEntityPersist(); + final var payer = accountEntityPersist(); // When testWeb3jService.setSender(getAliasFromEntity(payer)); @@ -1192,14 +1192,14 @@ void cryptoTransferHbars() throws Exception { void cryptoTransferToken() throws Exception { // Given final var contract = testWeb3jService.deploy(ModificationPrecompileTestContract::deploy); - final var sender = persistAccountEntity(); + final var sender = accountEntityPersist(); final var tokenEntity = persistFungibleToken(); - final var receiver = persistAccountEntity(); - final var payer = persistAccountEntity(); + final var receiver = accountEntityPersist(); + final var payer = accountEntityPersist(); - persistAssociation(tokenEntity, payer); - persistAssociation(tokenEntity, sender); - persistAssociation(tokenEntity, receiver); + tokenAccountPersist(tokenEntity, payer); + tokenAccountPersist(tokenEntity, sender); + tokenAccountPersist(tokenEntity, receiver); // When testWeb3jService.setSender(getAliasFromEntity(payer)); @@ -1224,14 +1224,14 @@ void cryptoTransferToken() throws Exception { void cryptoTransferHbarsAndToken() throws Exception { // Given final var contract = testWeb3jService.deploy(ModificationPrecompileTestContract::deploy); - final var sender = persistAccountEntity(); + final var sender = accountEntityPersist(); final var tokenEntity = persistFungibleToken(); - final var receiver = persistAccountEntity(); - final var payer = persistAccountEntity(); + final var receiver = accountEntityPersist(); + final var payer = accountEntityPersist(); - persistAssociation(tokenEntity, payer); - persistAssociation(tokenEntity, sender); - persistAssociation(tokenEntity, receiver); + tokenAccountPersist(tokenEntity, payer); + tokenAccountPersist(tokenEntity, sender); + tokenAccountPersist(tokenEntity, receiver); // When testWeb3jService.setSender(getAliasFromEntity(payer)); @@ -1259,8 +1259,8 @@ void cryptoTransferHbarsAndToken() throws Exception { void cryptoTransferNft() throws Exception { // Given final var contract = testWeb3jService.deploy(ModificationPrecompileTestContract::deploy); - final var sender = persistAccountEntity(); - final var tokenEntity = persistTokenEntity(); + final var sender = accountEntityPersist(); + final var tokenEntity = tokenEntityPersist(); domainBuilder .token() .customize(t -> t.tokenId(tokenEntity.getId()).type(TokenTypeEnum.NON_FUNGIBLE_UNIQUE)) @@ -1269,12 +1269,12 @@ void cryptoTransferNft() throws Exception { .nft() .customize(n -> n.tokenId(tokenEntity.getId()).serialNumber(1L).accountId(sender.toEntityId())) .persist(); - final var receiver = persistAccountEntity(); - final var payer = persistAccountEntity(); + final var receiver = accountEntityPersist(); + final var payer = accountEntityPersist(); - persistAssociation(tokenEntity, payer); - persistAssociation(tokenEntity, sender); - persistAssociation(tokenEntity, receiver); + tokenAccountPersist(tokenEntity, payer); + tokenAccountPersist(tokenEntity, sender); + tokenAccountPersist(tokenEntity, receiver); // When testWeb3jService.setSender(getAliasFromEntity(payer)); @@ -1297,7 +1297,7 @@ void cryptoTransferNft() throws Exception { @Test void updateTokenInfo() throws Exception { // Given - final var treasuryAccount = persistAccountEntity(); + final var treasuryAccount = accountEntityPersist(); final var tokenWithAutoRenewPair = persistTokenWithAutoRenewAndTreasuryAccounts(TokenTypeEnum.FUNGIBLE_COMMON, treasuryAccount); @@ -1318,7 +1318,7 @@ void updateTokenInfo() throws Exception { @Test void updateTokenExpiry() throws Exception { // Given - final var treasuryAccount = persistAccountEntity(); + final var treasuryAccount = accountEntityPersist(); final var tokenWithAutoRenewPair = persistTokenWithAutoRenewAndTreasuryAccounts(TokenTypeEnum.FUNGIBLE_COMMON, treasuryAccount); @@ -1354,7 +1354,7 @@ void updateTokenExpiry() throws Exception { void updateTokenKey(final TokenTypeEnum tokenTypeEnum, final KeyValueType keyValueType) throws Exception { // Given final var allCasesKeyType = 0b1111111; - final var treasuryAccount = persistAccountEntity(); + final var treasuryAccount = accountEntityPersist(); final var tokenWithAutoRenewPair = persistTokenWithAutoRenewAndTreasuryAccounts(tokenTypeEnum, treasuryAccount); final var contract = testWeb3jService.deploy(ModificationPrecompileTestContract::deploy); @@ -1392,7 +1392,7 @@ private void verifyEthCallAndEstimateGas( private HederaToken populateHederaToken( final String contractAddress, final TokenTypeEnum tokenType, final EntityId treasuryAccountId) { - final var autoRenewAccount = persistAccountEntity(); + final var autoRenewAccount = accountEntityPersist(); final var tokenEntity = domainBuilder .entity() .customize(e -> e.type(EntityType.TOKEN).autoRenewAccountId(autoRenewAccount.getId())) @@ -1423,7 +1423,7 @@ private HederaToken populateHederaToken( private Pair persistTokenWithAutoRenewAndTreasuryAccounts( final TokenTypeEnum tokenType, final Entity treasuryAccount) { - final var autoRenewAccount = persistAccountEntity(); + final var autoRenewAccount = accountEntityPersist(); final var tokenToUpdateEntity = domainBuilder .entity() .customize(e -> e.type(EntityType.TOKEN).autoRenewAccountId(autoRenewAccount.getId())) @@ -1470,12 +1470,8 @@ private KeyValue getKeyValueForType(final KeyValueType keyValueType, String cont }; } - private Entity persistTokenEntity() { - return domainBuilder.entity().customize(e -> e.type(EntityType.TOKEN)).persist(); - } - private Entity persistFungibleToken() { - final var tokenEntity = persistTokenEntity(); + final var tokenEntity = tokenEntityPersist(); domainBuilder .token() .customize(t -> t.tokenId(tokenEntity.getId()).type(TokenTypeEnum.FUNGIBLE_COMMON)) diff --git a/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallServicePrecompileReadonlyTest.java b/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallServicePrecompileReadonlyTest.java index 8728e40d299..22fa320650b 100644 --- a/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallServicePrecompileReadonlyTest.java +++ b/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallServicePrecompileReadonlyTest.java @@ -107,8 +107,8 @@ void hrcIsAssociatedFails() { @Test void isTokenFrozen() throws Exception { // Given - final var account = persistAccountEntity(); - final var tokenEntity = persistTokenEntity(); + final var account = accountEntityPersist(); + final var tokenEntity = tokenEntityPersist(); domainBuilder .token() .customize( @@ -143,7 +143,7 @@ void isTokenFrozenWithAlias() throws Exception { .alias(SENDER_PUBLIC_KEY.toByteArray()) .evmAddress(SENDER_ALIAS.toArray())) .persist(); - final var tokenEntity = persistTokenEntity(); + final var tokenEntity = tokenEntityPersist(); domainBuilder .token() .customize( @@ -172,9 +172,9 @@ void isTokenFrozenWithAlias() throws Exception { @Test void isKycGranted() throws Exception { // Given - final var account = persistAccountEntity(); + final var account = accountEntityPersist(); final var tokenEntity = persistFungibleToken(); - persistAssociation(tokenEntity, account); + tokenAccountPersist(tokenEntity, account); final var contract = testWeb3jService.deploy(PrecompileTestContract::deploy); @@ -197,7 +197,7 @@ void isKycGrantedWithAlias() throws Exception { .evmAddress(SENDER_ALIAS.toArray())) .persist(); final var tokenEntity = persistFungibleToken(); - persistAssociation(tokenEntity, account); + tokenAccountPersist(tokenEntity, account); final var contract = testWeb3jService.deploy(PrecompileTestContract::deploy); @@ -214,9 +214,9 @@ void isKycGrantedWithAlias() throws Exception { @Test void isKycGrantedForNFT() throws Exception { // Given - final var account = persistAccountEntity(); + final var account = accountEntityPersist(); final var tokenEntity = persistNft(); - persistAssociation(tokenEntity, account); + tokenAccountPersist(tokenEntity, account); final var contract = testWeb3jService.deploy(PrecompileTestContract::deploy); @@ -240,7 +240,7 @@ void isKycGrantedForNFTWithAlias() throws Exception { .evmAddress(SENDER_ALIAS.toArray())) .persist(); final var tokenEntity = persistNft(); - persistAssociation(tokenEntity, account); + tokenAccountPersist(tokenEntity, account); final var contract = testWeb3jService.deploy(PrecompileTestContract::deploy); @@ -290,7 +290,7 @@ void isTokenAddressNFT() throws Exception { void getDefaultKycToken() throws Exception { // Given domainBuilder.recordFile().customize(f -> f.index(0L)).persist(); - final var tokenEntity = persistTokenEntity(); + final var tokenEntity = tokenEntityPersist(); domainBuilder .token() .customize(t -> t.tokenId(tokenEntity.getId()) @@ -312,7 +312,7 @@ void getDefaultKycToken() throws Exception { @Test void getDefaultKycNFT() throws Exception { // Given - final var tokenEntity = persistTokenEntity(); + final var tokenEntity = tokenEntityPersist(); domainBuilder .token() .customize(t -> t.tokenId(tokenEntity.getId()) @@ -370,7 +370,7 @@ void getTokenTypeNFT() throws Exception { @Test void getTokenDefaultFreeze() throws Exception { // Given - final var tokenEntity = persistTokenEntity(); + final var tokenEntity = tokenEntityPersist(); domainBuilder .token() .customize(t -> t.tokenId(tokenEntity.getId()) @@ -392,7 +392,7 @@ void getTokenDefaultFreeze() throws Exception { @Test void getNFTDefaultFreeze() throws Exception { // Given - final var tokenEntity = persistTokenEntity(); + final var tokenEntity = tokenEntityPersist(); domainBuilder .token() .customize(t -> t.tokenId(tokenEntity.getId()) @@ -492,7 +492,7 @@ void getTokenKey(final TokenTypeEnum tokenType, final KeyValueType keyValueType, @Test void getCustomFeesForTokenWithFixedFee() throws Exception { // Given - final var collectorAccount = persistAccountEntity(); + final var collectorAccount = accountEntityPersist(); final var tokenEntity = persistFungibleToken(); final var fixedFee = com.hedera.mirror.common.domain.token.FixedFee.builder() .amount(100L) @@ -530,7 +530,7 @@ void getCustomFeesForTokenWithFixedFee() throws Exception { @Test void getCustomFeesForTokenWithFractionalFee() throws Exception { // Given - final var collectorAccount = persistAccountEntity(); + final var collectorAccount = accountEntityPersist(); final var tokenEntity = persistFungibleToken(); final var fractionalFee = FractionalFee.builder() .collectorAccountId(collectorAccount.toEntityId()) @@ -572,7 +572,7 @@ void getCustomFeesForTokenWithFractionalFee() throws Exception { @Test void getCustomFeesForTokenWithRoyaltyFee() throws Exception { // Given - final var collectorAccount = persistAccountEntity(); + final var collectorAccount = accountEntityPersist(); final var tokenEntity = persistFungibleToken(); final var royaltyFee = RoyaltyFee.builder() .collectorAccountId(collectorAccount.toEntityId()) @@ -618,7 +618,7 @@ void getExpiryForToken() throws Exception { // Given final var expiryPeriod = 9999999999999L; final var autoRenewExpiry = 100000000L; - final var autoRenewAccount = persistAccountEntity(); + final var autoRenewAccount = accountEntityPersist(); final var tokenEntity = domainBuilder .entity() .customize(e -> e.type(EntityType.TOKEN) @@ -653,8 +653,8 @@ void getExpiryForToken() throws Exception { void getAllowanceForToken() throws Exception { // Given final var amountGranted = 50L; - final var owner = persistAccountEntity(); - final var spender = persistAccountEntity(); + final var owner = accountEntityPersist(); + final var spender = accountEntityPersist(); final var tokenEntity = persistFungibleToken(); domainBuilder @@ -681,8 +681,8 @@ void getAllowanceForToken() throws Exception { @Test void isApprovedForAllNFT() throws Exception { // Given - final var owner = persistAccountEntity(); - final var spender = persistAccountEntity(); + final var owner = accountEntityPersist(); + final var spender = accountEntityPersist(); final var tokenEntity = persistNft(); domainBuilder @@ -708,8 +708,8 @@ void isApprovedForAllNFT() throws Exception { @Test void getFungibleTokenInfo() throws Exception { // Given - final var treasury = persistAccountEntity(); - final var feeCollector = persistAccountEntity(); + final var treasury = accountEntityPersist(); + final var feeCollector = accountEntityPersist(); final var tokenEntity = domainBuilder.entity().customize(e -> e.type(EntityType.TOKEN)).persist(); final var token = domainBuilder @@ -774,9 +774,9 @@ void getFungibleTokenInfo() throws Exception { @Test void getNonFungibleTokenInfo() throws Exception { // Given - final var owner = persistAccountEntity(); - final var treasury = persistAccountEntity(); - final var feeCollector = persistAccountEntity(); + final var owner = accountEntityPersist(); + final var treasury = accountEntityPersist(); + final var feeCollector = accountEntityPersist(); final var tokenEntity = domainBuilder.entity().customize(e -> e.type(EntityType.TOKEN)).persist(); final var token = domainBuilder @@ -852,8 +852,8 @@ void getNonFungibleTokenInfo() throws Exception { @EnumSource(TokenTypeEnum.class) void getTokenInfo(final TokenTypeEnum tokenType) throws Exception { // Given - final var treasury = persistAccountEntity(); - final var feeCollector = persistAccountEntity(); + final var treasury = accountEntityPersist(); + final var feeCollector = accountEntityPersist(); final var tokenEntity = domainBuilder.entity().customize(e -> e.type(EntityType.TOKEN)).persist(); final var token = domainBuilder @@ -918,7 +918,7 @@ void getTokenInfo(final TokenTypeEnum tokenType) throws Exception { @Test void nftInfoForInvalidSerialNo() { // Given - final var nftEntity = persistTokenEntity(); + final var nftEntity = tokenEntityPersist(); domainBuilder .token() .customize(t -> t.tokenId(nftEntity.getId()).type(TokenTypeEnum.NON_FUNGIBLE_UNIQUE)) @@ -940,7 +940,7 @@ void nftInfoForInvalidSerialNo() { @Test void tokenInfoForNonTokenAccount() { // Given - final var account = persistAccountEntity(); + final var account = accountEntityPersist(); final var contract = testWeb3jService.deploy(PrecompileTestContract::deploy); @@ -1048,12 +1048,8 @@ private KeyValue getKeyValueForType(final KeyValueType keyValueType, String cont }; } - private Entity persistTokenEntity() { - return domainBuilder.entity().customize(e -> e.type(EntityType.TOKEN)).persist(); - } - private Entity persistFungibleToken() { - final var tokenEntity = persistTokenEntity(); + final var tokenEntity = tokenEntityPersist(); domainBuilder .token() .customize(t -> t.tokenId(tokenEntity.getId()).type(TokenTypeEnum.FUNGIBLE_COMMON)) @@ -1063,7 +1059,7 @@ private Entity persistFungibleToken() { } private Entity persistNft() { - final var tokenEntity = persistTokenEntity(); + final var tokenEntity = tokenEntityPersist(); domainBuilder .token() .customize(t -> t.tokenId(tokenEntity.getId()).type(TokenTypeEnum.NON_FUNGIBLE_UNIQUE)) diff --git a/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/utils/ContractCallTestUtil.java b/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/utils/ContractCallTestUtil.java index af92625e0f9..501d1d84a88 100644 --- a/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/utils/ContractCallTestUtil.java +++ b/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/utils/ContractCallTestUtil.java @@ -75,7 +75,6 @@ public class ContractCallTestUtil { }; public static final long EVM_V_34_BLOCK = 50L; - public static final long EVM_V_30_BLOCK = EVM_V_34_BLOCK - 1; public static final long EVM_V_38_BLOCK = 100L; /** From 3e0550d125429013701aa69377b8f9f64cbf9b29 Mon Sep 17 00:00:00 2001 From: Bilyana Gospodinova Date: Mon, 16 Sep 2024 10:15:59 +0300 Subject: [PATCH 3/3] Add check for error message Signed-off-by: Bilyana Gospodinova --- .../service/ContractCallServiceHistoricalNegativeTest.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallServiceHistoricalNegativeTest.java b/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallServiceHistoricalNegativeTest.java index 75c73edcec4..49cd9285fd7 100644 --- a/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallServiceHistoricalNegativeTest.java +++ b/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallServiceHistoricalNegativeTest.java @@ -19,6 +19,7 @@ import static com.hedera.mirror.web3.evm.utils.EvmTokenUtils.entityIdFromEvmAddress; import static com.hedera.mirror.web3.utils.ContractCallTestUtil.EVM_V_34_BLOCK; import static com.hedera.mirror.web3.utils.ContractCallTestUtil.EVM_V_38_BLOCK; +import static com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_TRANSACTION; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; @@ -55,7 +56,9 @@ void contractNotPersistedYetThrowsException() { final var functionCall = contract.call_isTokenAddress(getAddressFromEntity(tokenEntity)); // Then - assertThatThrownBy(functionCall::send).isInstanceOf(MirrorEvmTransactionException.class); + assertThatThrownBy(functionCall::send) + .isInstanceOf(MirrorEvmTransactionException.class) + .hasMessage(INVALID_TRANSACTION.name()); } // Tests TokenRepository and NftRepository