From a64acefaa33c16ef8ab9addd4184de8d24e82981 Mon Sep 17 00:00:00 2001 From: filev94 Date: Tue, 11 Feb 2025 14:49:40 +0200 Subject: [PATCH 01/13] spotlessApply + removing unnecessary methods Signed-off-by: filev94 --- .../hedera/services/utils/EntityIdUtils.java | 10 + .../AbstractContractCallServiceTest.java | 53 ++--- .../service/ContractCallDynamicCallsTest.java | 101 +++++---- ...CallServicePrecompileModificationTest.java | 196 +++++++++--------- ...ractCallServicePrecompileReadonlyTest.java | 86 ++++---- 5 files changed, 210 insertions(+), 236 deletions(-) diff --git a/hedera-mirror-web3/src/main/java/com/hedera/services/utils/EntityIdUtils.java b/hedera-mirror-web3/src/main/java/com/hedera/services/utils/EntityIdUtils.java index 524e5dbbf2c..b15cb47399f 100644 --- a/hedera-mirror-web3/src/main/java/com/hedera/services/utils/EntityIdUtils.java +++ b/hedera-mirror-web3/src/main/java/com/hedera/services/utils/EntityIdUtils.java @@ -26,6 +26,7 @@ import com.hedera.hapi.node.base.AccountID.AccountOneOfType; import com.hedera.mirror.common.domain.entity.Entity; import com.hedera.mirror.common.domain.entity.EntityId; +import com.hedera.mirror.web3.evm.utils.EvmTokenUtils; import com.hedera.pbj.runtime.OneOf; import com.hedera.services.store.models.Id; import com.hedera.services.store.models.NftId; @@ -324,4 +325,13 @@ public static String readableId(final Object o) { public static boolean isAliasSizeGreaterThanEvmAddress(final ByteString alias) { return alias.size() > EVM_ADDRESS_SIZE; } + + public static String getAddressFromId(long tokenId) { + return EvmTokenUtils.toAddress(tokenId).toHexString(); + } + + public static EntityId entityIdFromTokenId(long tokenId) { + var address = EvmTokenUtils.toAddress(tokenId); + return EvmTokenUtils.entityIdFromEvmAddress(address); + } } 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 b2608c1949a..781b9715587 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 @@ -75,6 +75,7 @@ public abstract class AbstractContractCallServiceTest extends Web3IntegrationTes protected static final String TREASURY_ADDRESS = EvmTokenUtils.toAddress(2).toHexString(); protected static final long DEFAULT_ACCOUNT_BALANCE = 100_000_000_000_000_000L; + protected static final int DEFAULT_TOKEN_BALANCE = 100; @Resource protected TestWeb3jService testWeb3jService; @@ -257,18 +258,6 @@ protected Token fungibleTokenPersistWithTreasuryAccount(final EntityId treasuryE return fungibleTokenCustomizable(t -> t.treasuryAccountId(treasuryEntityId)); } - /** - * - * @param treasuryEntity - the treasuryEntity which has to be set in the token - * @param kycKey - the kycKey that has to be set in the token - * @return Token object that is persisted in db - */ - protected Token fungibleTokenPersistWithTreasuryAccountAndKYCKey( - final EntityId treasuryEntity, final byte[] kycKey) { - return fungibleTokenCustomizable( - t -> t.treasuryAccountId(treasuryEntity).kycKey(kycKey)); - } - /** * Method used to customize different fields of a token and persist it in db * @param customizer - the consumer used to customize the token @@ -392,16 +381,6 @@ protected Entity accountPersistWithAlias(final Address alias, final ByteString p e -> e.evmAddress(alias.toArray()).alias(publicKey.toByteArray())); } - /** - * - * @param balance - the balance with which the account is created - * @return Entity object that is persisted in the db - */ - protected Entity accountEntityPersistWithBalance(final long balance) { - return accountEntityPersistCustomizable( - e -> e.type(EntityType.ACCOUNT).evmAddress(null).alias(null).balance(balance)); - } - /** * * @param customizer - the consumer with which to customize the entity @@ -416,17 +395,6 @@ protected Entity accountEntityPersistCustomizable(Consumer ta.tokenId(token.getId()).accountId(account.toEntityId().getId())); - } - - protected void tokenAccountPersist(final Entity token, final Entity account, Long balance) { - tokenAccount(ta -> ta.tokenId(token.getId()) - .accountId(account.toEntityId().getId()) - .balance(balance)); - } - protected TokenAccount tokenAccount(Consumer> consumer) { return domainBuilder .tokenAccount() @@ -437,6 +405,19 @@ protected TokenAccount tokenAccount(Consumer { + ta.tokenId(tokenId).accountId(accountId); + if (balance != null) { + ta.balance(balance); + } + }); + } + + protected void tokenAccountPersist(final long tokenId, final long accountId) { + tokenAccountPersist(tokenId, accountId, null); + } + /** * Creates a non-fungible token instance with a specific serial number(a record in the nft table is persisted). The * instance is tied to a specific token in the token db table. @@ -487,11 +468,11 @@ protected void persistAccountBalance(Entity account, long balance) { * No record for the token balance at a particular timestamp may result in INSUFFICIENT_TOKEN_BALANCE exception * for a historical query with the same timestamp. */ - protected void persistTokenBalance(Entity account, Entity token, long timestamp) { + protected void persistTokenBalance(EntityId account, EntityId token, long timestamp) { domainBuilder .tokenBalance() - .customize(ab -> ab.id(new TokenBalance.Id(timestamp, account.toEntityId(), token.toEntityId())) - .balance(100)) + .customize(ab -> + ab.id(new TokenBalance.Id(timestamp, account, token)).balance(DEFAULT_TOKEN_BALANCE)) .persist(); } diff --git a/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallDynamicCallsTest.java b/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallDynamicCallsTest.java index ebfc8baf134..f7da5ea210e 100644 --- a/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallDynamicCallsTest.java +++ b/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallDynamicCallsTest.java @@ -29,7 +29,6 @@ import com.hedera.mirror.common.domain.entity.Entity; import com.hedera.mirror.common.domain.entity.EntityId; import com.hedera.mirror.common.domain.token.Token; -import com.hedera.mirror.common.domain.token.TokenKycStatusEnum; import com.hedera.mirror.common.domain.token.TokenTypeEnum; import com.hedera.mirror.web3.common.ContractCallContext; import com.hedera.mirror.web3.evm.store.Store.OnMissing; @@ -95,7 +94,7 @@ void burnTokenGetTotalSupplyAndBalanceOfTreasury(final TokenTypeEnum tokenType) final var treasuryAccount = accountEntityPersist(); final var tokenEntity = tokenEntityPersist(); - tokenAccountPersist(tokenEntity, treasuryAccount, 1L); + tokenAccountPersist(tokenEntity.getId(), treasuryAccount.getId()); if (tokenType.equals(TokenTypeEnum.FUNGIBLE_COMMON)) { fungibleTokenPersist(tokenEntity, treasuryAccount); @@ -251,11 +250,12 @@ void associateTokenTransfer(final TokenTypeEnum tokenType, final long amount, fi final var senderAddress = toAddress(senderEntityId.getId()); final var tokenEntity = tokenType == TokenTypeEnum.FUNGIBLE_COMMON - ? fungibleTokenPersistWithTreasuryAccountAndKYCKey(treasuryEntityId, null) + ? fungibleTokenCustomizable( + t -> t.treasuryAccountId(treasuryEntityId).kycKey(null)) : nftPersist(treasuryEntityId, treasuryEntityId, treasuryEntityId, null); final var tokenAddress = toAddress(tokenEntity.getTokenId()); - tokenAccountPersist(entityIdFromEvmAddress(tokenAddress), treasuryEntityId); + tokenAccountPersist(tokenEntity.getTokenId(), treasuryEntityId.getId()); final var contract = testWeb3jService.deploy(DynamicEthCalls::deploy); @@ -339,14 +339,15 @@ void approveTokenGetAllowance(final TokenTypeEnum tokenType, final long amount, ? fungibleTokenPersistWithTreasuryAccount(treasuryEntityId) : nftPersist(treasuryEntityId, ownerEntityId, spenderEntityId); final var tokenAddress = toAddress(tokenEntity.getTokenId()); + final var tokenId = tokenEntity.getTokenId(); final var tokenEntityId = entityIdFromEvmAddress(toAddress(tokenEntity.getTokenId())); final var contract = testWeb3jService.deploy(DynamicEthCalls::deploy); final var contractAddress = Address.fromHexString(contract.getContractAddress()); final var contractEntityId = entityIdFromEvmAddress(contractAddress); - tokenAccountPersist(tokenEntityId, contractEntityId); - tokenAccountPersist(tokenEntityId, ownerEntityId); + tokenAccountPersist(tokenId, contractEntityId.getId()); + tokenAccountPersist(tokenId, ownerEntityId.getId()); if (tokenType == TokenTypeEnum.NON_FUNGIBLE_UNIQUE) { nftAllowancePersist(tokenEntityId, contractEntityId, ownerEntityId); @@ -389,10 +390,11 @@ void approveTokenTransferFromGetAllowanceGetBalance( : nftPersist(treasuryEntityId, contractEntityId, spenderEntityId); final var tokenAddress = toAddress(tokenEntity.getTokenId()); final var tokenEntityId = entityIdFromEvmAddress(tokenAddress); + final var tokenId = tokenEntity.getTokenId(); - tokenAccountPersist(tokenEntityId, contractEntityId); - tokenAccountPersist(tokenEntityId, spenderEntityId); - tokenAccountPersist(tokenEntityId, ownerEntityId); + tokenAccountPersist(tokenId, contractEntityId.getId()); + tokenAccountPersist(tokenId, spenderEntityId.getId()); + tokenAccountPersist(tokenId, ownerEntityId.getId()); if (tokenType == TokenTypeEnum.NON_FUNGIBLE_UNIQUE) { nftAllowancePersist(tokenEntityId, contractEntityId, ownerEntityId); @@ -430,11 +432,11 @@ void approveTokenTransferGetAllowanceGetBalance( final var tokenEntity = tokenType == TokenTypeEnum.FUNGIBLE_COMMON ? fungibleTokenPersistWithTreasuryAccount(treasuryEntityId) : nftPersist(treasuryEntityId, senderEntityId); - final var tokenAddress = toAddress(tokenEntity.getTokenId()); - final var tokenEntityId = entityIdFromEvmAddress(tokenAddress); + final var tokenId = tokenEntity.getTokenId(); + final var tokenAddress = toAddress(tokenId); - tokenAccountPersist(tokenEntityId, senderEntityId); - tokenAccountPersist(tokenEntityId, contractEntityId); + tokenAccountPersist(tokenId, senderEntityId.getId()); + tokenAccountPersist(tokenId, contractEntityId.getId()); // When final var functionCall = contract.send_approveTokenTransferGetAllowanceGetBalance( @@ -468,11 +470,11 @@ void approveTokenCryptoTransferGetAllowanceGetBalance( final var tokenEntity = tokenType == TokenTypeEnum.FUNGIBLE_COMMON ? fungibleTokenPersistWithTreasuryAccount(treasuryEntityId) : nftPersist(treasuryEntityId, spenderEntityId); - final var tokenAddress = toAddress(tokenEntity.getTokenId()); - final var tokenEntityId = entityIdFromEvmAddress(tokenAddress); + final var tokenId = tokenEntity.getTokenId(); + final var tokenAddress = toAddress(tokenId); - tokenAccountPersist(tokenEntityId, spenderEntityId); - tokenAccountPersist(tokenEntityId, contractEntityId); + tokenAccountPersist(tokenId, spenderEntityId.getId()); + tokenAccountPersist(tokenId, contractEntityId.getId()); TokenTransferList tokenTransferList; if (tokenType == TokenTypeEnum.FUNGIBLE_COMMON) { @@ -514,10 +516,10 @@ void approveForAllTokenTransferFromGetAllowance() { final var tokenEntity = nftPersist(treasuryEntityId, spenderEntityId); final var tokenAddress = toAddress(tokenEntity.getTokenId()); - final var tokenEntityId = entityIdFromEvmAddress(tokenAddress); + final var tokenId = tokenEntity.getTokenId(); - tokenAccountPersist(tokenEntityId, spenderEntityId); - tokenAccountPersist(tokenEntityId, contractEntityId); + tokenAccountPersist(tokenId, spenderEntityId.getId()); + tokenAccountPersist(tokenId, contractEntityId.getId()); // When final var functionCall = contract.send_approveForAllTokenTransferGetAllowance( @@ -540,10 +542,10 @@ void approveForAllCryptoTransferGetAllowance() { final var tokenEntity = nftPersist(treasuryEntityId, spenderEntityId); final var tokenAddress = toAddress(tokenEntity.getTokenId()); - final var tokenEntityId = entityIdFromEvmAddress(tokenAddress); + final var tokenId = tokenEntity.getTokenId(); - tokenAccountPersist(tokenEntityId, spenderEntityId); - tokenAccountPersist(tokenEntityId, contractEntityId); + tokenAccountPersist(tokenId, spenderEntityId.getId()); + tokenAccountPersist(tokenId, contractEntityId.getId()); var tokenTransferList = new TokenTransferList( tokenAddress.toHexString(), @@ -580,11 +582,11 @@ void cryptoTransferFromGetAllowanceGetBalance( final var tokenEntity = tokenType == TokenTypeEnum.FUNGIBLE_COMMON ? fungibleTokenPersistWithTreasuryAccount(treasuryEntityId) : nftPersist(treasuryEntityId, spenderEntityId); - final var tokenAddress = toAddress(tokenEntity.getTokenId()); - final var tokenEntityId = entityIdFromEvmAddress(tokenAddress); + final var tokenId = tokenEntity.getTokenId(); + final var tokenAddress = toAddress(tokenId); - tokenAccountPersist(tokenEntityId, spenderEntityId); - tokenAccountPersist(tokenEntityId, contractEntityId); + tokenAccountPersist(tokenId, spenderEntityId.getId()); + tokenAccountPersist(tokenId, contractEntityId.getId()); TokenTransferList tokenTransferList; if (tokenType == TokenTypeEnum.FUNGIBLE_COMMON) { @@ -622,14 +624,15 @@ void transferFromNFTGetAllowance() { final var spenderEntityId = accountEntityPersist().toEntityId(); final var tokenEntity = nftPersist(treasuryEntityId, spenderEntityId); - final var tokenAddress = toAddress(tokenEntity.getTokenId()); + final var tokenId = tokenEntity.getTokenId(); + final var tokenAddress = toAddress(tokenId); final var contract = testWeb3jService.deploy(DynamicEthCalls::deploy); final var contractAddress = Address.fromHexString(contract.getContractAddress()); final var contractEntityId = entityIdFromEvmAddress(contractAddress); - tokenAccountPersist(entityIdFromEvmAddress(tokenAddress), spenderEntityId); - tokenAccountPersist(entityIdFromEvmAddress(tokenAddress), contractEntityId); + tokenAccountPersist(tokenId, spenderEntityId.getId()); + tokenAccountPersist(tokenId, contractEntityId.getId()); // When final var functionCall = contract.send_transferFromNFTGetAllowance(tokenAddress.toHexString(), BigInteger.ONE); @@ -659,11 +662,11 @@ void transferFromGetAllowanceGetBalance(final TokenTypeEnum tokenType, final lon ? fungibleTokenPersistWithTreasuryAccount(treasuryEntityId) : nftPersist(treasuryEntityId, treasuryEntityId); final var tokenAddress = toAddress(tokenEntity.getTokenId()); - final var tokenEntityId = entityIdFromEvmAddress(tokenAddress); + final var tokenId = tokenEntity.getTokenId(); - tokenAccountPersist(tokenEntityId, treasuryEntityId); - tokenAccountPersist(tokenEntityId, spenderEntityId); - tokenAccountPersist(tokenEntityId, contractEntityId); + tokenAccountPersist(tokenId, treasuryEntityId.getId()); + tokenAccountPersist(tokenId, spenderEntityId.getId()); + tokenAccountPersist(tokenId, contractEntityId.getId()); // When final var functionCall = contract.send_transferFromGetAllowanceGetBalance( @@ -692,10 +695,10 @@ void grantKycRevokeKyc(final TokenTypeEnum tokenType) { final var tokenEntity = tokenType == TokenTypeEnum.FUNGIBLE_COMMON ? fungibleTokenPersistWithTreasuryAccount(treasuryEntityId) : nftPersist(treasuryEntityId, treasuryEntityId); - final var tokenAddress = toAddress(tokenEntity.getTokenId()); - final var tokenEntityId = entityIdFromEvmAddress(tokenAddress); + final var tokenId = tokenEntity.getTokenId(); + final var tokenAddress = toAddress(tokenId); - tokenAccountPersist(tokenEntityId, spenderEntityId); + tokenAccountPersist(tokenId, spenderEntityId.getId()); // When final var functionCall = @@ -805,16 +808,6 @@ private EntityId spenderEntityPersistWithAlias() { return accountPersistWithAlias(SPENDER_ALIAS, SPENDER_PUBLIC_KEY).toEntityId(); } - private void tokenAccountPersist(final EntityId tokenEntityId, final EntityId accountId) { - domainBuilder - .tokenAccount() - .customize(e -> e.accountId(accountId.getId()) - .tokenId(tokenEntityId.getId()) - .associated(true) - .kycStatus(TokenKycStatusEnum.GRANTED)) - .persist(); - } - private void nftAllowancePersist( final EntityId tokenEntityId, final EntityId spenderEntityId, final EntityId ownerEntityId) { domainBuilder @@ -829,12 +822,14 @@ private void nftAllowancePersist( private Entity setUpToken(TokenTypeEnum tokenType, Entity treasuryAccount, Entity owner, Entity spender) { final var tokenEntity = tokenEntityPersist(); - - tokenAccountPersist(tokenEntity, treasuryAccount, 1L); - tokenAccountPersist(tokenEntity, spender, 1L); - - if (!Objects.equals(owner.getId(), spender.getId())) { - tokenAccountPersist(tokenEntity, owner, 1L); + final var tokenId = tokenEntity.getId(); + final var spenderId = spender.getId(); + final var ownerId = owner.getId(); + tokenAccountPersist(tokenId, treasuryAccount.getId(), 1L); + tokenAccountPersist(tokenId, spenderId, 1L); + + if (!Objects.equals(ownerId, spenderId)) { + tokenAccountPersist(tokenId, ownerId, 1L); } if (tokenType.equals(TokenTypeEnum.FUNGIBLE_COMMON)) { 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 c35d5d09634..bac5f0121d2 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 @@ -24,6 +24,9 @@ import static com.hedera.mirror.web3.utils.ContractCallTestUtil.ZERO_VALUE; import static com.hedera.mirror.web3.utils.ContractCallTestUtil.isWithinExpectedGasRange; import static com.hedera.mirror.web3.utils.ContractCallTestUtil.longValueOf; +import static com.hedera.services.utils.EntityIdUtils.asHexedEvmAddress; +import static com.hedera.services.utils.EntityIdUtils.entityIdFromTokenId; +import static com.hedera.services.utils.EntityIdUtils.getAddressFromId; import static com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_TOKEN_ID; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; @@ -55,7 +58,6 @@ import com.hedera.mirror.web3.web3j.generated.ModificationPrecompileTestContract.TransferList; import com.hedera.services.store.contracts.precompile.codec.KeyValueWrapper.KeyValueType; import com.hedera.services.store.models.Id; -import com.hedera.services.utils.EntityIdUtils; import com.hederahashgraph.api.proto.java.Key.KeyCase; import java.math.BigInteger; import java.nio.charset.StandardCharsets; @@ -81,17 +83,17 @@ void transferFrom() throws Exception { final var recipient = accountEntityWithEvmAddressPersist(); final var tokenEntity = tokenEntityPersist(); - + final var tokenId = tokenEntity.getId(); fungibleTokenPersist(tokenEntity, owner); - tokenAccountPersist(tokenEntity, spender); - tokenAccountPersist(tokenEntity, recipient); + tokenAccountPersist(tokenId, spender.getId()); + tokenAccountPersist(tokenId, recipient.getId()); final var contract = testWeb3jService.deploy(ModificationPrecompileTestContract::deploy); final var contractAddress = Address.fromHexString(contract.getContractAddress()); final var contractEntityId = entityIdFromEvmAddress(contractAddress); - tokenAccount(ta -> ta.tokenId(tokenEntity.getId()).accountId(contractEntityId.getId())); + tokenAccount(ta -> ta.tokenId(tokenId).accountId(contractEntityId.getId())); tokenAllowancePersist(10L, tokenEntity, spender, contractEntityId); @@ -112,19 +114,19 @@ void transferFrom() throws Exception { void approve(final BigInteger allowance) throws Exception { // Given final var spender = accountEntityPersist(); - final var tokenEntity = persistFungibleToken(); + final var tokenEntity = fungibleTokenPersist(); - tokenAccountPersist(tokenEntity, spender); + tokenAccountPersist(tokenEntity.getTokenId(), spender.getId()); final var contract = testWeb3jService.deploy(ModificationPrecompileTestContract::deploy); final var contractAddress = Address.fromHexString(contract.getContractAddress()); final var contractEntityId = entityIdFromEvmAddress(contractAddress); - tokenAccount(ta -> ta.tokenId(tokenEntity.getId()).accountId(contractEntityId.getId())); + tokenAccount(ta -> ta.tokenId(tokenEntity.getTokenId()).accountId(contractEntityId.getId())); // When final var functionCall = contract.call_approveExternal( - getAddressFromEntity(tokenEntity), getAddressFromEntity(spender), allowance); + getAddressFromId(tokenEntity.getTokenId()), getAddressFromEntity(spender), allowance); // Then verifyEthCallAndEstimateGas(functionCall, contract, ZERO_VALUE); @@ -139,17 +141,18 @@ void approveNFT(final Boolean approve) throws Exception { final var spender = accountEntityPersist(); final var tokenEntity = tokenEntityPersist(); + final var tokenId = tokenEntity.getId(); Token token = nonFungibleTokenPersist(tokenEntity); - tokenAccountPersist(tokenEntity, owner); - tokenAccountPersist(tokenEntity, spender); + tokenAccountPersist(tokenId, owner.getId()); + tokenAccountPersist(tokenId, spender.getId()); final var contract = testWeb3jService.deploy(ModificationPrecompileTestContract::deploy); final var contractAddress = Address.fromHexString(contract.getContractAddress()); final var contractEntityId = entityIdFromEvmAddress(contractAddress); - tokenAccount(ta -> ta.tokenId(tokenEntity.getId()).accountId(contractEntityId.getId())); + tokenAccount(ta -> ta.tokenId(tokenId).accountId(contractEntityId.getId())); nonFungibleTokenInstancePersist(token, 1L, contractEntityId, spender.toEntityId()); @@ -176,7 +179,7 @@ void setApprovalForAll() throws Exception { .customize(t -> t.tokenId(tokenEntity.getId()).type(TokenTypeEnum.NON_FUNGIBLE_UNIQUE)) .persist(); - tokenAccountPersist(tokenEntity, spender); + tokenAccountPersist(tokenEntity.getId(), spender.getId()); final var contract = testWeb3jService.deploy(ModificationPrecompileTestContract::deploy); @@ -315,7 +318,7 @@ void mintFungibleToken() throws Exception { .type(TokenTypeEnum.FUNGIBLE_COMMON) .treasuryAccountId(treasury.toEntityId())) .persist(); - tokenAccountPersist(tokenEntity, treasury); + tokenAccountPersist(tokenEntity.getId(), treasury.getId()); final var totalSupply = token.getTotalSupply(); @@ -340,7 +343,7 @@ void mintNFT() throws Exception { nonFungibleTokenPersist(tokenEntity, treasury); - tokenAccountPersist(tokenEntity, treasury); + tokenAccountPersist(tokenEntity.getId(), treasury.getId()); final var contract = testWeb3jService.deploy(ModificationPrecompileTestContract::deploy); @@ -362,16 +365,15 @@ void mintNFT() throws Exception { @Test void burnFungibleToken() throws Exception { // Given - final var tokenEntity = tokenEntityPersist(); final var treasuryAccount = accountEntityPersist(); - final var token = fungibleTokenPersist(tokenEntity, treasuryAccount); - tokenAccountPersist(tokenEntity, treasuryAccount); + final var token = fungibleTokenPersistWithTreasuryAccount(treasuryAccount.toEntityId()); + tokenAccountPersist(token.getTokenId(), treasuryAccount.getId()); final var sender = accountEntityPersist(); accountBalanceRecordsPersist(sender); long balanceTimestamp = treasuryAccount.getBalanceTimestamp(); - persistTokenBalance(treasuryAccount, tokenEntity, balanceTimestamp); + persistTokenBalance(treasuryAccount.toEntityId(), entityIdFromTokenId(token.getTokenId()), balanceTimestamp); testWeb3jService.setSender(getAddressFromEntity(sender)); @@ -381,7 +383,7 @@ void burnFungibleToken() throws Exception { // When final var functionCall = contract.call_burnTokenExternal( - getAddressFromEntity(tokenEntity), BigInteger.valueOf(4), new ArrayList<>()); + getAddressFromId(token.getTokenId()), BigInteger.valueOf(4), new ArrayList<>()); final var result = functionCall.send(); @@ -403,11 +405,11 @@ void burnNFT() throws Exception { .treasuryAccountId(treasury.toEntityId())) .persist(); - tokenAccountPersist(tokenEntity, treasury); + tokenAccountPersist(tokenEntity.getId(), treasury.getId()); final var totalSupply = token.getTotalSupply(); long balanceTimestamp = treasury.getBalanceTimestamp(); - persistTokenBalance(treasury, tokenEntity, balanceTimestamp); + persistTokenBalance(treasury.toEntityId(), tokenEntity.toEntityId(), balanceTimestamp); Nft nft = domainBuilder .nft() @@ -450,10 +452,10 @@ void wipeFungibleToken() throws Exception { final var tokenEntity = tokenEntityPersist(); fungibleTokenPersist(tokenEntity, treasuryEntity); - tokenAccountPersist(tokenEntity, owner); + tokenAccountPersist(tokenEntity.getId(), owner.getId()); Long createdTimestamp = owner.getCreatedTimestamp(); - persistTokenBalance(owner, tokenEntity, createdTimestamp); + persistTokenBalance(owner.toEntityId(), tokenEntity.toEntityId(), createdTimestamp); persistAccountBalance(treasuryEntity, treasuryEntity.getBalance(), createdTimestamp); final var contract = testWeb3jService.deploy(ModificationPrecompileTestContract::deploy); @@ -480,7 +482,7 @@ void wipeNFT() throws Exception { .treasuryAccountId(tokenTreasury.toEntityId())) .persist(); - tokenAccountPersist(tokenEntity, owner); + tokenAccountPersist(tokenEntity.getId(), owner.getId()); domainBuilder .nft() .customize(n -> n.tokenId(tokenEntity.getId()).serialNumber(1L).accountId(owner.toEntityId())) @@ -508,7 +510,7 @@ void grantTokenKyc() throws Exception { .customize(t -> t.tokenId(tokenEntity.getId()).type(TokenTypeEnum.FUNGIBLE_COMMON)) .persist(); - tokenAccountPersist(tokenEntity, accountWithoutGrant); + tokenAccountPersist(tokenEntity.getId(), accountWithoutGrant.getId()); final var contract = testWeb3jService.deploy(ModificationPrecompileTestContract::deploy); @@ -532,7 +534,7 @@ void revokeTokenKyc() throws Exception { .customize(t -> t.tokenId(tokenEntity.getId()).type(TokenTypeEnum.FUNGIBLE_COMMON)) .persist(); - tokenAccountPersist(tokenEntity, accountWithGrant); + tokenAccountPersist(tokenEntity.getId(), accountWithGrant.getId()); final var contract = testWeb3jService.deploy(ModificationPrecompileTestContract::deploy); @@ -567,14 +569,14 @@ void deleteToken() throws Exception { void freezeToken() throws Exception { // Given final var accountWithoutFreeze = accountEntityWithEvmAddressPersist(); - final var tokenEntity = persistFungibleToken(); - tokenAccountPersist(tokenEntity, accountWithoutFreeze); + final var tokenEntity = fungibleTokenPersist(); + tokenAccountPersist(tokenEntity.getTokenId(), accountWithoutFreeze.getId()); final var contract = testWeb3jService.deploy(ModificationPrecompileTestContract::deploy); // When final var functionCall = contract.call_freezeTokenExternal( - getAddressFromEntity(tokenEntity), getAliasFromEntity(accountWithoutFreeze)); + getAddressFromId(tokenEntity.getTokenId()), getAliasFromEntity(accountWithoutFreeze)); // Then verifyEthCallAndEstimateGas(functionCall, contract, ZERO_VALUE); @@ -586,11 +588,11 @@ void unfreezeToken() throws Exception { // Given final var accountWithFreeze = accountEntityWithEvmAddressPersist(); - final var tokenEntity = persistFungibleToken(); + final var tokenEntity = fungibleTokenPersist(); domainBuilder .tokenAccount() - .customize(ta -> ta.tokenId(tokenEntity.getId()) + .customize(ta -> ta.tokenId(tokenEntity.getTokenId()) .accountId(accountWithFreeze.getId()) .kycStatus(TokenKycStatusEnum.GRANTED) .freezeStatus(TokenFreezeStatusEnum.FROZEN) @@ -602,7 +604,7 @@ void unfreezeToken() throws Exception { // When final var functionCall = contract.call_unfreezeTokenExternal( - getAddressFromEntity(tokenEntity), getAliasFromEntity(accountWithFreeze)); + getAddressFromId(tokenEntity.getTokenId()), getAliasFromEntity(accountWithFreeze)); // Then verifyEthCallAndEstimateGas(functionCall, contract, ZERO_VALUE); @@ -641,7 +643,7 @@ void unpauseToken() throws Exception { .pauseStatus(TokenPauseStatusEnum.PAUSED)) .persist(); - tokenAccountPersist(tokenEntity, sender); + tokenAccountPersist(tokenEntity.getId(), sender.getId()); final var contract = testWeb3jService.deploy(ModificationPrecompileTestContract::deploy); @@ -705,10 +707,11 @@ void createFungibleTokenWithCustomFees() throws Exception { final var treasuryAccount = accountEntityPersist(); - final var tokenForDenomination = persistFungibleToken(); + final var tokenForDenomination = fungibleTokenPersist(); final var feeCollector = accountEntityWithEvmAddressPersist(); + final var tokenId = tokenForDenomination.getTokenId(); - tokenAccountPersist(tokenForDenomination, feeCollector); + tokenAccountPersist(tokenId, feeCollector.getId()); final var contract = testWeb3jService.deploy(ModificationPrecompileTestContract::deploy); @@ -719,11 +722,7 @@ void createFungibleTokenWithCustomFees() throws Exception { contract.getContractAddress(), TokenTypeEnum.FUNGIBLE_COMMON, treasuryAccount.toEntityId()); final var fixedFee = new FixedFee( - BigInteger.valueOf(100L), - getAddressFromEntityId(tokenForDenomination.toEntityId()), - false, - false, - getAliasFromEntity(feeCollector)); + BigInteger.valueOf(100L), getAddressFromId(tokenId), false, false, getAliasFromEntity(feeCollector)); final var fractionalFee = new FractionalFee( BigInteger.valueOf(1L), BigInteger.valueOf(100L), @@ -795,10 +794,11 @@ void createNonFungibleTokenWithCustomFees() throws Exception { accountBalanceRecordsPersist(sender); - final var tokenForDenomination = persistFungibleToken(); + final var tokenForDenomination = fungibleTokenPersist(); final var feeCollector = accountEntityWithEvmAddressPersist(); + final var tokenId = tokenForDenomination.getTokenId(); - tokenAccountPersist(tokenForDenomination, feeCollector); + tokenAccountPersist(tokenId, feeCollector.getId()); final var contract = testWeb3jService.deploy(ModificationPrecompileTestContract::deploy); @@ -811,18 +811,13 @@ void createNonFungibleTokenWithCustomFees() throws Exception { .persist(); final var token = populateHederaToken( contract.getContractAddress(), TokenTypeEnum.NON_FUNGIBLE_UNIQUE, treasuryAccount.toEntityId()); - final var fixedFee = new FixedFee( - BigInteger.valueOf(100L), - getAddressFromEntityId(tokenForDenomination.toEntityId()), - false, - false, - getAliasFromEntity(feeCollector)); + BigInteger.valueOf(100L), getAddressFromId(tokenId), false, false, getAliasFromEntity(feeCollector)); final var royaltyFee = new RoyaltyFee( BigInteger.valueOf(1L), BigInteger.valueOf(100L), BigInteger.valueOf(10L), - getAddressFromEntity(tokenForDenomination), + getAddressFromId(tokenId), false, getAliasFromEntity(feeCollector)); @@ -848,17 +843,18 @@ void createNonFungibleTokenWithCustomFees() throws Exception { void create2ContractAndTransferFromIt() throws Exception { // Given final var receiver = accountEntityWithEvmAddressPersist(); - final var token = persistFungibleToken(); + final var token = fungibleTokenPersist(); final var sponsor = accountEntityWithEvmAddressPersist(); - persistTokenBalance(sponsor, token, sponsor.getCreatedTimestamp()); + persistTokenBalance( + sponsor.toEntityId(), entityIdFromTokenId(token.getTokenId()), sponsor.getCreatedTimestamp()); accountBalanceRecordsPersist(sponsor); - tokenAccountPersist(token, sponsor); + tokenAccountPersist(token.getTokenId(), sponsor.getId()); final var contract = testWeb3jService.deploy(ModificationPrecompileTestContract::deploy); // When final var functionCall = contract.call_createContractViaCreate2AndTransferFromIt( - getAddressFromEntity(token), + getAddressFromId(token.getTokenId()), getAliasFromEntity(sponsor), getAliasFromEntity(receiver), BigInteger.valueOf(10L)); @@ -871,14 +867,14 @@ void create2ContractAndTransferFromIt() throws Exception { @Test void notExistingPrecompileCall() throws Exception { // Given - final var token = persistFungibleToken(); + final var token = fungibleTokenPersist(); final var contract = testWeb3jService.deploy(ModificationPrecompileTestContract::deploy); // Then if (mirrorNodeEvmProperties.isModularizedServices()) { - final var modularizedCall = contract.call_callNotExistingPrecompile(getAddressFromEntity(token)); + final var modularizedCall = contract.call_callNotExistingPrecompile(getAddressFromId(token.getTokenId())); assertThat(Bytes.wrap(modularizedCall.send())).isEqualTo(Bytes.EMPTY); } else { - final var functionCall = contract.send_callNotExistingPrecompile(getAddressFromEntity(token)); + final var functionCall = contract.send_callNotExistingPrecompile(getAddressFromId(token.getTokenId())); assertThatThrownBy(functionCall::send) .isInstanceOf(MirrorEvmTransactionException.class) .hasMessage(INVALID_TOKEN_ID.name()); @@ -1097,17 +1093,17 @@ void transferToken(final String type) throws Exception { final var receiver = accountEntityWithEvmAddressPersist(); // Create token-account associations so sender and receiver can operate with the token - tokenAccountPersist(tokenEntity, sender); - tokenAccountPersist(tokenEntity, receiver); + tokenAccountPersist(tokenEntity.getId(), sender.getId()); + tokenAccountPersist(tokenEntity.getId(), receiver.getId()); accountBalanceRecordsPersist(sender.toEntityId(), sender.getCreatedTimestamp(), sender.getBalance()); accountBalanceRecordsPersist(receiver.toEntityId(), receiver.getCreatedTimestamp(), receiver.getBalance()); long senderBalanceTimestamp = sender.getBalanceTimestamp(); - persistTokenBalance(sender, tokenEntity, senderBalanceTimestamp); + persistTokenBalance(sender.toEntityId(), tokenEntity.toEntityId(), senderBalanceTimestamp); long receiverBalanceTimestamp = receiver.getBalanceTimestamp(); - persistTokenBalance(receiver, tokenEntity, receiverBalanceTimestamp); + persistTokenBalance(receiver.toEntityId(), tokenEntity.toEntityId(), receiverBalanceTimestamp); final var contract = testWeb3jService.deploy(ModificationPrecompileTestContract::deploy); // When @@ -1145,6 +1141,7 @@ void transferNft(final String type) throws Exception { final var tokenEntity = tokenEntityPersist(); final var treasuryAccount = accountEntityPersist(); + final var tokenId = tokenEntity.getId(); accountBalanceRecordsPersist(sender); @@ -1152,14 +1149,14 @@ void transferNft(final String type) throws Exception { domainBuilder .nft() - .customize(n -> n.tokenId(tokenEntity.getId()).serialNumber(1L).accountId(sender.toEntityId())) + .customize(n -> n.tokenId(tokenId).serialNumber(1L).accountId(sender.toEntityId())) .persist(); final var receiver = accountEntityWithEvmAddressPersist(); nftAllowancePersist(token, sender, getEntity(contractId), sender); - tokenAccountPersist(tokenEntity, sender); - tokenAccountPersist(tokenEntity, receiver); + tokenAccountPersist(tokenId, sender.getId()); + tokenAccountPersist(tokenId, receiver.getId()); // When testWeb3jService.setSender(getAliasFromEntity(sender)); @@ -1209,8 +1206,8 @@ void transferFromNft() throws Exception { nftAllowancePersist(token, sender, getEntity(contractId), sender); - tokenAccountPersist(tokenEntity, sender); - tokenAccountPersist(tokenEntity, receiver); + tokenAccountPersist(tokenEntity.getId(), sender.getId()); + tokenAccountPersist(tokenEntity.getId(), receiver.getId()); // When testWeb3jService.setSender(getAliasFromEntity(sender)); @@ -1264,27 +1261,29 @@ void cryptoTransferToken() throws Exception { // Given final var contract = testWeb3jService.deploy(ModificationPrecompileTestContract::deploy); final var sender = accountEntityWithEvmAddressPersist(); - final var tokenEntity = persistFungibleToken(); + final var token = fungibleTokenPersist(); final var receiver = accountEntityWithEvmAddressPersist(); final var payer = accountEntityWithEvmAddressPersist(); + final var tokenId = token.getTokenId(); long timestampForBalances = payer.getCreatedTimestamp(); + final var entity = entityIdFromTokenId(tokenId); persistAccountBalance(payer, payer.getBalance()); - persistTokenBalance(payer, tokenEntity, timestampForBalances); + persistTokenBalance(payer.toEntityId(), entity, timestampForBalances); persistAccountBalance(sender, sender.getBalance(), timestampForBalances); - persistTokenBalance(sender, tokenEntity, timestampForBalances); + persistTokenBalance(sender.toEntityId(), entity, timestampForBalances); - persistTokenBalance(receiver, tokenEntity, timestampForBalances); + persistTokenBalance(receiver.toEntityId(), entity, timestampForBalances); persistAccountBalance(treasuryEntity, treasuryEntity.getBalance(), timestampForBalances); - tokenAccountPersist(tokenEntity, sender); - tokenAccountPersist(tokenEntity, receiver); - tokenAccountPersist(tokenEntity, payer); + tokenAccountPersist(tokenId, sender.getId()); + tokenAccountPersist(tokenId, receiver.getId()); + tokenAccountPersist(tokenId, payer.getId()); // When testWeb3jService.setSender(getAliasFromEntity(payer)); final var tokenTransferList = new TokenTransferList( - getAddressFromEntity(tokenEntity), + getAddressFromId(tokenId), List.of( new AccountAmount(getAliasFromEntity(sender), BigInteger.valueOf(5L), false), new AccountAmount(getAliasFromEntity(receiver), BigInteger.valueOf(-5L), false)), @@ -1305,24 +1304,26 @@ void cryptoTransferHbarsAndToken() throws Exception { // Given final var contract = testWeb3jService.deploy(ModificationPrecompileTestContract::deploy); final var sender = accountEntityWithEvmAddressPersist(); - final var tokenEntity = persistFungibleToken(); + final var tokenEntity = fungibleTokenPersist(); final var receiver = accountEntityWithEvmAddressPersist(); final var payer = accountEntityWithEvmAddressPersist(); - long timestampForBalances = payer.getCreatedTimestamp(); + final var tokenId = tokenEntity.getTokenId(); + final var entity = entityIdFromTokenId(tokenId); + persistAccountBalance(payer, payer.getBalance()); - persistTokenBalance(payer, tokenEntity, timestampForBalances); + persistTokenBalance(payer.toEntityId(), entity, timestampForBalances); persistAccountBalance(sender, sender.getBalance(), timestampForBalances); - persistTokenBalance(sender, tokenEntity, timestampForBalances); + persistTokenBalance(sender.toEntityId(), entity, timestampForBalances); - persistTokenBalance(receiver, tokenEntity, timestampForBalances); + persistTokenBalance(receiver.toEntityId(), entity, timestampForBalances); persistAccountBalance(treasuryEntity, treasuryEntity.getBalance(), timestampForBalances); - tokenAccountPersist(tokenEntity, sender); - tokenAccountPersist(tokenEntity, receiver); - tokenAccountPersist(tokenEntity, payer); + tokenAccountPersist(tokenId, sender.getId()); + tokenAccountPersist(tokenId, receiver.getId()); + tokenAccountPersist(tokenId, payer.getId()); // When testWeb3jService.setSender(getAliasFromEntity(payer)); @@ -1331,7 +1332,7 @@ void cryptoTransferHbarsAndToken() throws Exception { new AccountAmount(getAliasFromEntity(receiver), BigInteger.valueOf(5L), false))); final var tokenTransferList = new TokenTransferList( - getAddressFromEntity(tokenEntity), + getAddressFromId(tokenId), List.of( new AccountAmount(getAliasFromEntity(sender), BigInteger.valueOf(5L), false), new AccountAmount(getAliasFromEntity(receiver), BigInteger.valueOf(-5L), false)), @@ -1355,21 +1356,22 @@ void cryptoTransferNft() throws Exception { final var receiver = accountEntityWithEvmAddressPersist(); final var payer = accountEntityWithEvmAddressPersist(); final var tokenEntity = tokenEntityPersist(); + final var tokenId = tokenEntity.getId(); accountBalanceRecordsPersist(payer); domainBuilder .token() - .customize(t -> t.tokenId(tokenEntity.getId()) + .customize(t -> t.tokenId(tokenId) .type(TokenTypeEnum.NON_FUNGIBLE_UNIQUE) .treasuryAccountId(tokenTreasury.toEntityId())) .persist(); domainBuilder .nft() - .customize(n -> n.tokenId(tokenEntity.getId()).serialNumber(1L).accountId(sender.toEntityId())) + .customize(n -> n.tokenId(tokenId).serialNumber(1L).accountId(sender.toEntityId())) .persist(); - tokenAccountPersist(tokenEntity, payer); - tokenAccountPersist(tokenEntity, sender); - tokenAccountPersist(tokenEntity, receiver); + tokenAccountPersist(tokenId, payer.getId()); + tokenAccountPersist(tokenId, sender.getId()); + tokenAccountPersist(tokenId, receiver.getId()); // When testWeb3jService.setSender(getAliasFromEntity(payer)); @@ -1540,16 +1542,6 @@ private KeyValue getKeyValueForType(final KeyValueType keyValueType, String cont }; } - private Entity persistFungibleToken() { - final var tokenEntity = tokenEntityPersist(); - domainBuilder - .token() - .customize(t -> t.tokenId(tokenEntity.getId()).type(TokenTypeEnum.FUNGIBLE_COMMON)) - .persist(); - - return tokenEntity; - } - private HederaToken convertTokenEntityToHederaToken(final Token token) { final var tokenEntity = domainBuilder.entity().customize(e -> e.id(token.getTokenId())).get(); @@ -1561,7 +1553,7 @@ private HederaToken convertTokenEntityToHederaToken(final Token token) { token.getName(), token.getSymbol(), treasuryAccountId != null - ? EntityIdUtils.asHexedEvmAddress(new Id( + ? asHexedEvmAddress(new Id( treasuryAccountId.getShard(), treasuryAccountId.getRealm(), treasuryAccountId.getNum())) : Address.ZERO.toHexString(), new String(token.getMetadata(), StandardCharsets.UTF_8), @@ -1571,7 +1563,7 @@ private HederaToken convertTokenEntityToHederaToken(final Token token) { keys, new Expiry( BigInteger.valueOf(tokenEntity.getEffectiveExpiration()), - EntityIdUtils.asHexedEvmAddress(new Id(0, 0, entityRenewAccountId)), + asHexedEvmAddress(new Id(0, 0, entityRenewAccountId)), BigInteger.valueOf(tokenEntity.getEffectiveExpiration()))); } @@ -1583,7 +1575,7 @@ private HederaToken convertTokenEntityToHederaToken(final Token token, final Ent return new HederaToken( token.getName(), token.getSymbol(), - EntityIdUtils.asHexedEvmAddress( + asHexedEvmAddress( new Id(treasuryAccountId.getShard(), treasuryAccountId.getRealm(), treasuryAccountId.getNum())), new String(token.getMetadata(), StandardCharsets.UTF_8), token.getSupplyType().equals(TokenSupplyTypeEnum.FINITE), @@ -1592,7 +1584,7 @@ private HederaToken convertTokenEntityToHederaToken(final Token token, final Ent keys, new Expiry( BigInteger.valueOf(entity.getEffectiveExpiration()), - EntityIdUtils.asHexedEvmAddress(new Id(0, 0, entityRenewAccountId)), + asHexedEvmAddress(new Id(0, 0, entityRenewAccountId)), BigInteger.valueOf(entity.getEffectiveExpiration()))); } } 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 18abfa72d50..ae0efae8672 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 @@ -31,6 +31,9 @@ import static com.hedera.mirror.web3.web3j.generated.PrecompileTestContract.Expiry; import static com.hedera.mirror.web3.web3j.generated.PrecompileTestContract.HederaToken; import static com.hedera.mirror.web3.web3j.generated.PrecompileTestContract.TokenKey; +import static com.hedera.services.utils.EntityIdUtils.asTypedEvmAddress; +import static com.hedera.services.utils.EntityIdUtils.entityIdFromTokenId; +import static com.hedera.services.utils.EntityIdUtils.getAddressFromId; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; @@ -96,11 +99,12 @@ void unsupportedPrecompileFails() { @Test void hrcIsAssociatedFails() throws Exception { // Given - final var token = persistFungibleToken(); + final var token = fungibleTokenPersist(); + final var contract = testWeb3jService.deploy(PrecompileTestContract::deploy); // When - final var functionCall = contract.call_hrcIsAssociated(getAddressFromEntity(token)); + final var functionCall = contract.call_hrcIsAssociated(getAddressFromId(token.getTokenId())); // Then if (mirrorNodeEvmProperties.isModularizedServices()) { @@ -181,14 +185,14 @@ void isTokenFrozenWithAlias() throws Exception { void isKycGranted() throws Exception { // Given final var account = accountEntityPersist(); - final var tokenEntity = persistFungibleToken(); - tokenAccountPersist(tokenEntity, account); + final var token = fungibleTokenPersist(); + tokenAccountPersist(token.getTokenId(), account.getId()); final var contract = testWeb3jService.deploy(PrecompileTestContract::deploy); // When final var functionCall = - contract.call_isKycGranted(getAddressFromEntity(tokenEntity), getAddressFromEntity(account)); + contract.call_isKycGranted(getAddressFromId(token.getTokenId()), getAddressFromEntity(account)); // Then assertThat(functionCall.send()).isTrue(); @@ -204,14 +208,14 @@ void isKycGrantedWithAlias() throws Exception { .alias(SENDER_PUBLIC_KEY.toByteArray()) .evmAddress(SENDER_ALIAS.toArray())) .persist(); - final var tokenEntity = persistFungibleToken(); - tokenAccountPersist(tokenEntity, account); + final var tokenEntity = fungibleTokenPersist(); + tokenAccountPersist(tokenEntity.getTokenId(), account.getId()); final var contract = testWeb3jService.deploy(PrecompileTestContract::deploy); // When final var functionCall = - contract.call_isKycGranted(getAddressFromEntity(tokenEntity), getAliasFromEntity(account)); + contract.call_isKycGranted(getAddressFromId(tokenEntity.getTokenId()), getAliasFromEntity(account)); // Then assertThat(functionCall.send()).isTrue(); @@ -224,7 +228,7 @@ void isKycGrantedForNFT() throws Exception { // Given final var account = accountEntityPersist(); final var tokenEntity = persistNft(); - tokenAccountPersist(tokenEntity, account); + tokenAccountPersist(tokenEntity.getId(), account.getId()); final var contract = testWeb3jService.deploy(PrecompileTestContract::deploy); @@ -248,7 +252,7 @@ void isKycGrantedForNFTWithAlias() throws Exception { .evmAddress(SENDER_ALIAS.toArray())) .persist(); final var tokenEntity = persistNft(); - tokenAccountPersist(tokenEntity, account); + tokenAccountPersist(tokenEntity.getId(), account.getId()); final var contract = testWeb3jService.deploy(PrecompileTestContract::deploy); @@ -265,12 +269,12 @@ void isKycGrantedForNFTWithAlias() throws Exception { @Test void isTokenAddress() throws Exception { // Given - final var tokenEntity = persistFungibleToken(); + final var tokenEntity = fungibleTokenPersist(); final var contract = testWeb3jService.deploy(PrecompileTestContract::deploy); // When - final var functionCall = contract.call_isTokenAddress(getAddressFromEntity(tokenEntity)); + final var functionCall = contract.call_isTokenAddress(getAddressFromId(tokenEntity.getTokenId())); // Then assertThat(functionCall.send()).isTrue(); @@ -346,12 +350,12 @@ void getDefaultKycNFT() throws Exception { @Test void getTokenType() throws Exception { // Given - final var tokenEntity = persistFungibleToken(); + final var tokenEntity = fungibleTokenPersist(); final var contract = testWeb3jService.deploy(PrecompileTestContract::deploy); // When - final var functionCall = contract.call_getType(getAddressFromEntity(tokenEntity)); + final var functionCall = contract.call_getType(getAddressFromId(tokenEntity.getTokenId())); // Then assertThat(functionCall.send()).isEqualTo(BigInteger.ZERO); @@ -501,15 +505,17 @@ void getTokenKey(final TokenTypeEnum tokenType, final KeyValueType keyValueType, void getCustomFeesForTokenWithFixedFee() throws Exception { // Given final var collectorAccount = accountEntityWithEvmAddressPersist(); - final var tokenEntity = persistFungibleToken(); + final var tokenEntity = fungibleTokenPersist(); + final var tokenId = tokenEntity.getTokenId(); + final var entityId = entityIdFromTokenId(tokenId); final var fixedFee = com.hedera.mirror.common.domain.token.FixedFee.builder() .amount(100L) .collectorAccountId(collectorAccount.toEntityId()) - .denominatingTokenId(tokenEntity.toEntityId()) + .denominatingTokenId(entityId) .build(); domainBuilder .customFee() - .customize(f -> f.entityId(tokenEntity.getId()) + .customize(f -> f.entityId(tokenId) .fixedFees(List.of(fixedFee)) .fractionalFees(List.of()) .royaltyFees(List.of())) @@ -518,11 +524,11 @@ void getCustomFeesForTokenWithFixedFee() throws Exception { final var contract = testWeb3jService.deploy(PrecompileTestContract::deploy); // When - final var functionCall = contract.call_getCustomFeesForToken(getAddressFromEntity(tokenEntity)); + final var functionCall = contract.call_getCustomFeesForToken(getAddressFromId(tokenId)); final var expectedFee = new FixedFee( BigInteger.valueOf(100L), - getAddressFromEntity(tokenEntity), + getAddressFromId(tokenId), false, false, Address.fromHexString( @@ -539,7 +545,7 @@ void getCustomFeesForTokenWithFixedFee() throws Exception { void getCustomFeesForTokenWithFractionalFee() throws Exception { // Given final var collectorAccount = accountEntityWithEvmAddressPersist(); - final var tokenEntity = persistFungibleToken(); + final var tokenEntity = fungibleTokenPersist(); final var fractionalFee = FractionalFee.builder() .collectorAccountId(collectorAccount.toEntityId()) .denominator(10L) @@ -550,7 +556,7 @@ void getCustomFeesForTokenWithFractionalFee() throws Exception { .build(); domainBuilder .customFee() - .customize(f -> f.entityId(tokenEntity.getId()) + .customize(f -> f.entityId(tokenEntity.getTokenId()) .fractionalFees(List.of(fractionalFee)) .fixedFees(List.of()) .royaltyFees(List.of())) @@ -559,7 +565,7 @@ void getCustomFeesForTokenWithFractionalFee() throws Exception { final var contract = testWeb3jService.deploy(PrecompileTestContract::deploy); // When - final var functionCall = contract.call_getCustomFeesForToken(getAddressFromEntity(tokenEntity)); + final var functionCall = contract.call_getCustomFeesForToken(getAddressFromId(tokenEntity.getTokenId())); final var expectedFee = new PrecompileTestContract.FractionalFee( BigInteger.valueOf(100L), @@ -581,19 +587,22 @@ void getCustomFeesForTokenWithFractionalFee() throws Exception { void getCustomFeesForTokenWithRoyaltyFee() throws Exception { // Given final var collectorAccount = accountEntityWithEvmAddressPersist(); - final var tokenEntity = persistFungibleToken(); + final var tokenEntity = fungibleTokenPersist(); + final var tokenId = tokenEntity.getTokenId(); + final var entityId = entityIdFromTokenId(tokenId); + final var royaltyFee = RoyaltyFee.builder() .collectorAccountId(collectorAccount.toEntityId()) .denominator(10L) .fallbackFee(FallbackFee.builder() .amount(100L) - .denominatingTokenId(tokenEntity.toEntityId()) + .denominatingTokenId(entityId) .build()) .numerator(20L) .build(); domainBuilder .customFee() - .customize(f -> f.entityId(tokenEntity.getId()) + .customize(f -> f.entityId(tokenId) .royaltyFees(List.of(royaltyFee)) .fixedFees(List.of()) .fractionalFees(List.of())) @@ -602,14 +611,13 @@ void getCustomFeesForTokenWithRoyaltyFee() throws Exception { final var contract = testWeb3jService.deploy(PrecompileTestContract::deploy); // When - final var functionCall = contract.call_getCustomFeesForToken(getAddressFromEntity(tokenEntity)); + final var functionCall = contract.call_getCustomFeesForToken(getAddressFromId(tokenId)); final var expectedFee = new PrecompileTestContract.RoyaltyFee( BigInteger.valueOf(20L), BigInteger.valueOf(10L), BigInteger.valueOf(100L), - EntityIdUtils.asHexedEvmAddress( - new Id(tokenEntity.getShard(), tokenEntity.getRealm(), tokenEntity.getNum())), + EntityIdUtils.asHexedEvmAddress(new Id(entityId.getShard(), entityId.getRealm(), entityId.getNum())), false, Address.fromHexString( Bytes.wrap(collectorAccount.getEvmAddress()).toHexString()) @@ -663,11 +671,11 @@ void getAllowanceForToken() throws Exception { final var amountGranted = 50L; final var owner = accountEntityWithEvmAddressPersist(); final var spender = accountEntityWithEvmAddressPersist(); - final var tokenEntity = persistFungibleToken(); + final var tokenEntity = fungibleTokenPersist(); domainBuilder .tokenAllowance() - .customize(a -> a.tokenId(tokenEntity.getId()) + .customize(a -> a.tokenId(tokenEntity.getTokenId()) .owner(owner.getNum()) .spender(spender.getNum()) .amount(amountGranted) @@ -678,7 +686,7 @@ void getAllowanceForToken() throws Exception { // When final var functionCall = contract.call_htsAllowance( - getAddressFromEntity(tokenEntity), getAliasFromEntity(owner), getAliasFromEntity(spender)); + getAddressFromId(tokenEntity.getTokenId()), getAliasFromEntity(owner), getAliasFromEntity(spender)); // Then assertThat(functionCall.send()).isEqualTo(BigInteger.valueOf(amountGranted)); @@ -1059,16 +1067,6 @@ private KeyValue getKeyValueForType(final KeyValueType keyValueType, String cont }; } - private Entity persistFungibleToken() { - final var tokenEntity = tokenEntityPersist(); - domainBuilder - .token() - .customize(t -> t.tokenId(tokenEntity.getId()).type(TokenTypeEnum.FUNGIBLE_COMMON)) - .persist(); - - return tokenEntity; - } - private Entity persistNft() { final var tokenEntity = tokenEntityPersist(); domainBuilder @@ -1160,14 +1158,12 @@ private KeyValue getKeyValue(byte[] serializedKey) { return new KeyValue( false, key.getContractID().hasContractNum() - ? EntityIdUtils.asTypedEvmAddress(key.getContractID()) - .toHexString() + ? asTypedEvmAddress(key.getContractID()).toHexString() : Address.ZERO.toHexString(), key.getEd25519().toByteArray(), key.getECDSASecp256K1().toByteArray(), key.getDelegatableContractId().hasContractNum() - ? EntityIdUtils.asTypedEvmAddress(key.getDelegatableContractId()) - .toHexString() + ? asTypedEvmAddress(key.getDelegatableContractId()).toHexString() : Address.ZERO.toHexString()); } catch (InvalidProtocolBufferException e) { throw new IllegalArgumentException("Unable to parse key", e); From dffd41133403b582194063637e570484dc818cf3 Mon Sep 17 00:00:00 2001 From: filev94 Date: Tue, 11 Feb 2025 16:40:48 +0200 Subject: [PATCH 02/13] renaming method to adhere to correct pattern in utility class Signed-off-by: filev94 --- .../hedera/services/utils/EntityIdUtils.java | 2 +- ...CallServicePrecompileModificationTest.java | 26 +++++++++---------- ...ractCallServicePrecompileReadonlyTest.java | 22 ++++++++-------- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/hedera-mirror-web3/src/main/java/com/hedera/services/utils/EntityIdUtils.java b/hedera-mirror-web3/src/main/java/com/hedera/services/utils/EntityIdUtils.java index b15cb47399f..119b480e554 100644 --- a/hedera-mirror-web3/src/main/java/com/hedera/services/utils/EntityIdUtils.java +++ b/hedera-mirror-web3/src/main/java/com/hedera/services/utils/EntityIdUtils.java @@ -326,7 +326,7 @@ public static boolean isAliasSizeGreaterThanEvmAddress(final ByteString alias) { return alias.size() > EVM_ADDRESS_SIZE; } - public static String getAddressFromId(long tokenId) { + public static String addressFromId(long tokenId) { return EvmTokenUtils.toAddress(tokenId).toHexString(); } 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 bac5f0121d2..3543ab212cb 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 @@ -26,7 +26,7 @@ import static com.hedera.mirror.web3.utils.ContractCallTestUtil.longValueOf; import static com.hedera.services.utils.EntityIdUtils.asHexedEvmAddress; import static com.hedera.services.utils.EntityIdUtils.entityIdFromTokenId; -import static com.hedera.services.utils.EntityIdUtils.getAddressFromId; +import static com.hedera.services.utils.EntityIdUtils.addressFromId; import static com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_TOKEN_ID; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; @@ -126,7 +126,7 @@ void approve(final BigInteger allowance) throws Exception { // When final var functionCall = contract.call_approveExternal( - getAddressFromId(tokenEntity.getTokenId()), getAddressFromEntity(spender), allowance); + addressFromId(tokenEntity.getTokenId()), getAddressFromEntity(spender), allowance); // Then verifyEthCallAndEstimateGas(functionCall, contract, ZERO_VALUE); @@ -383,7 +383,7 @@ void burnFungibleToken() throws Exception { // When final var functionCall = contract.call_burnTokenExternal( - getAddressFromId(token.getTokenId()), BigInteger.valueOf(4), new ArrayList<>()); + addressFromId(token.getTokenId()), BigInteger.valueOf(4), new ArrayList<>()); final var result = functionCall.send(); @@ -576,7 +576,7 @@ void freezeToken() throws Exception { // When final var functionCall = contract.call_freezeTokenExternal( - getAddressFromId(tokenEntity.getTokenId()), getAliasFromEntity(accountWithoutFreeze)); + addressFromId(tokenEntity.getTokenId()), getAliasFromEntity(accountWithoutFreeze)); // Then verifyEthCallAndEstimateGas(functionCall, contract, ZERO_VALUE); @@ -604,7 +604,7 @@ void unfreezeToken() throws Exception { // When final var functionCall = contract.call_unfreezeTokenExternal( - getAddressFromId(tokenEntity.getTokenId()), getAliasFromEntity(accountWithFreeze)); + addressFromId(tokenEntity.getTokenId()), getAliasFromEntity(accountWithFreeze)); // Then verifyEthCallAndEstimateGas(functionCall, contract, ZERO_VALUE); @@ -722,7 +722,7 @@ void createFungibleTokenWithCustomFees() throws Exception { contract.getContractAddress(), TokenTypeEnum.FUNGIBLE_COMMON, treasuryAccount.toEntityId()); final var fixedFee = new FixedFee( - BigInteger.valueOf(100L), getAddressFromId(tokenId), false, false, getAliasFromEntity(feeCollector)); + BigInteger.valueOf(100L), addressFromId(tokenId), false, false, getAliasFromEntity(feeCollector)); final var fractionalFee = new FractionalFee( BigInteger.valueOf(1L), BigInteger.valueOf(100L), @@ -812,12 +812,12 @@ void createNonFungibleTokenWithCustomFees() throws Exception { final var token = populateHederaToken( contract.getContractAddress(), TokenTypeEnum.NON_FUNGIBLE_UNIQUE, treasuryAccount.toEntityId()); final var fixedFee = new FixedFee( - BigInteger.valueOf(100L), getAddressFromId(tokenId), false, false, getAliasFromEntity(feeCollector)); + BigInteger.valueOf(100L), addressFromId(tokenId), false, false, getAliasFromEntity(feeCollector)); final var royaltyFee = new RoyaltyFee( BigInteger.valueOf(1L), BigInteger.valueOf(100L), BigInteger.valueOf(10L), - getAddressFromId(tokenId), + addressFromId(tokenId), false, getAliasFromEntity(feeCollector)); @@ -854,7 +854,7 @@ void create2ContractAndTransferFromIt() throws Exception { // When final var functionCall = contract.call_createContractViaCreate2AndTransferFromIt( - getAddressFromId(token.getTokenId()), + addressFromId(token.getTokenId()), getAliasFromEntity(sponsor), getAliasFromEntity(receiver), BigInteger.valueOf(10L)); @@ -871,10 +871,10 @@ void notExistingPrecompileCall() throws Exception { final var contract = testWeb3jService.deploy(ModificationPrecompileTestContract::deploy); // Then if (mirrorNodeEvmProperties.isModularizedServices()) { - final var modularizedCall = contract.call_callNotExistingPrecompile(getAddressFromId(token.getTokenId())); + final var modularizedCall = contract.call_callNotExistingPrecompile(addressFromId(token.getTokenId())); assertThat(Bytes.wrap(modularizedCall.send())).isEqualTo(Bytes.EMPTY); } else { - final var functionCall = contract.send_callNotExistingPrecompile(getAddressFromId(token.getTokenId())); + final var functionCall = contract.send_callNotExistingPrecompile(addressFromId(token.getTokenId())); assertThatThrownBy(functionCall::send) .isInstanceOf(MirrorEvmTransactionException.class) .hasMessage(INVALID_TOKEN_ID.name()); @@ -1283,7 +1283,7 @@ void cryptoTransferToken() throws Exception { // When testWeb3jService.setSender(getAliasFromEntity(payer)); final var tokenTransferList = new TokenTransferList( - getAddressFromId(tokenId), + addressFromId(tokenId), List.of( new AccountAmount(getAliasFromEntity(sender), BigInteger.valueOf(5L), false), new AccountAmount(getAliasFromEntity(receiver), BigInteger.valueOf(-5L), false)), @@ -1332,7 +1332,7 @@ void cryptoTransferHbarsAndToken() throws Exception { new AccountAmount(getAliasFromEntity(receiver), BigInteger.valueOf(5L), false))); final var tokenTransferList = new TokenTransferList( - getAddressFromId(tokenId), + addressFromId(tokenId), List.of( new AccountAmount(getAliasFromEntity(sender), BigInteger.valueOf(5L), false), new AccountAmount(getAliasFromEntity(receiver), BigInteger.valueOf(-5L), false)), 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 ae0efae8672..5dbae5236dc 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 @@ -33,7 +33,7 @@ import static com.hedera.mirror.web3.web3j.generated.PrecompileTestContract.TokenKey; import static com.hedera.services.utils.EntityIdUtils.asTypedEvmAddress; import static com.hedera.services.utils.EntityIdUtils.entityIdFromTokenId; -import static com.hedera.services.utils.EntityIdUtils.getAddressFromId; +import static com.hedera.services.utils.EntityIdUtils.addressFromId; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; @@ -104,7 +104,7 @@ void hrcIsAssociatedFails() throws Exception { final var contract = testWeb3jService.deploy(PrecompileTestContract::deploy); // When - final var functionCall = contract.call_hrcIsAssociated(getAddressFromId(token.getTokenId())); + final var functionCall = contract.call_hrcIsAssociated(addressFromId(token.getTokenId())); // Then if (mirrorNodeEvmProperties.isModularizedServices()) { @@ -192,7 +192,7 @@ void isKycGranted() throws Exception { // When final var functionCall = - contract.call_isKycGranted(getAddressFromId(token.getTokenId()), getAddressFromEntity(account)); + contract.call_isKycGranted(addressFromId(token.getTokenId()), getAddressFromEntity(account)); // Then assertThat(functionCall.send()).isTrue(); @@ -215,7 +215,7 @@ void isKycGrantedWithAlias() throws Exception { // When final var functionCall = - contract.call_isKycGranted(getAddressFromId(tokenEntity.getTokenId()), getAliasFromEntity(account)); + contract.call_isKycGranted(addressFromId(tokenEntity.getTokenId()), getAliasFromEntity(account)); // Then assertThat(functionCall.send()).isTrue(); @@ -274,7 +274,7 @@ void isTokenAddress() throws Exception { final var contract = testWeb3jService.deploy(PrecompileTestContract::deploy); // When - final var functionCall = contract.call_isTokenAddress(getAddressFromId(tokenEntity.getTokenId())); + final var functionCall = contract.call_isTokenAddress(addressFromId(tokenEntity.getTokenId())); // Then assertThat(functionCall.send()).isTrue(); @@ -355,7 +355,7 @@ void getTokenType() throws Exception { final var contract = testWeb3jService.deploy(PrecompileTestContract::deploy); // When - final var functionCall = contract.call_getType(getAddressFromId(tokenEntity.getTokenId())); + final var functionCall = contract.call_getType(addressFromId(tokenEntity.getTokenId())); // Then assertThat(functionCall.send()).isEqualTo(BigInteger.ZERO); @@ -524,11 +524,11 @@ void getCustomFeesForTokenWithFixedFee() throws Exception { final var contract = testWeb3jService.deploy(PrecompileTestContract::deploy); // When - final var functionCall = contract.call_getCustomFeesForToken(getAddressFromId(tokenId)); + final var functionCall = contract.call_getCustomFeesForToken(addressFromId(tokenId)); final var expectedFee = new FixedFee( BigInteger.valueOf(100L), - getAddressFromId(tokenId), + addressFromId(tokenId), false, false, Address.fromHexString( @@ -565,7 +565,7 @@ void getCustomFeesForTokenWithFractionalFee() throws Exception { final var contract = testWeb3jService.deploy(PrecompileTestContract::deploy); // When - final var functionCall = contract.call_getCustomFeesForToken(getAddressFromId(tokenEntity.getTokenId())); + final var functionCall = contract.call_getCustomFeesForToken(addressFromId(tokenEntity.getTokenId())); final var expectedFee = new PrecompileTestContract.FractionalFee( BigInteger.valueOf(100L), @@ -611,7 +611,7 @@ void getCustomFeesForTokenWithRoyaltyFee() throws Exception { final var contract = testWeb3jService.deploy(PrecompileTestContract::deploy); // When - final var functionCall = contract.call_getCustomFeesForToken(getAddressFromId(tokenId)); + final var functionCall = contract.call_getCustomFeesForToken(addressFromId(tokenId)); final var expectedFee = new PrecompileTestContract.RoyaltyFee( BigInteger.valueOf(20L), @@ -686,7 +686,7 @@ void getAllowanceForToken() throws Exception { // When final var functionCall = contract.call_htsAllowance( - getAddressFromId(tokenEntity.getTokenId()), getAliasFromEntity(owner), getAliasFromEntity(spender)); + addressFromId(tokenEntity.getTokenId()), getAliasFromEntity(owner), getAliasFromEntity(spender)); // Then assertThat(functionCall.send()).isEqualTo(BigInteger.valueOf(amountGranted)); From 8ebb1f3143b0219e196b62e026a69b87d0e9e71b Mon Sep 17 00:00:00 2001 From: filev94 Date: Tue, 11 Feb 2025 16:46:07 +0200 Subject: [PATCH 03/13] spotlessApply Signed-off-by: filev94 --- .../service/ContractCallServicePrecompileModificationTest.java | 2 +- .../web3/service/ContractCallServicePrecompileReadonlyTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 3543ab212cb..2276dd15e7b 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 @@ -24,9 +24,9 @@ import static com.hedera.mirror.web3.utils.ContractCallTestUtil.ZERO_VALUE; import static com.hedera.mirror.web3.utils.ContractCallTestUtil.isWithinExpectedGasRange; import static com.hedera.mirror.web3.utils.ContractCallTestUtil.longValueOf; +import static com.hedera.services.utils.EntityIdUtils.addressFromId; import static com.hedera.services.utils.EntityIdUtils.asHexedEvmAddress; import static com.hedera.services.utils.EntityIdUtils.entityIdFromTokenId; -import static com.hedera.services.utils.EntityIdUtils.addressFromId; import static com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_TOKEN_ID; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; 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 5dbae5236dc..0629a61c6f9 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 @@ -31,9 +31,9 @@ import static com.hedera.mirror.web3.web3j.generated.PrecompileTestContract.Expiry; import static com.hedera.mirror.web3.web3j.generated.PrecompileTestContract.HederaToken; import static com.hedera.mirror.web3.web3j.generated.PrecompileTestContract.TokenKey; +import static com.hedera.services.utils.EntityIdUtils.addressFromId; import static com.hedera.services.utils.EntityIdUtils.asTypedEvmAddress; import static com.hedera.services.utils.EntityIdUtils.entityIdFromTokenId; -import static com.hedera.services.utils.EntityIdUtils.addressFromId; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; From ce15ebcba5c641d036867af4fe956a01e0dbc0f3 Mon Sep 17 00:00:00 2001 From: filev94 Date: Wed, 12 Feb 2025 10:30:03 +0200 Subject: [PATCH 04/13] small refactoring + spotlessApply Signed-off-by: filev94 --- .../hedera/services/utils/EntityIdUtils.java | 8 +++--- ...CallServicePrecompileModificationTest.java | 25 +++++++++---------- ...ractCallServicePrecompileReadonlyTest.java | 22 ++++++++-------- 3 files changed, 27 insertions(+), 28 deletions(-) diff --git a/hedera-mirror-web3/src/main/java/com/hedera/services/utils/EntityIdUtils.java b/hedera-mirror-web3/src/main/java/com/hedera/services/utils/EntityIdUtils.java index 119b480e554..3283b25f600 100644 --- a/hedera-mirror-web3/src/main/java/com/hedera/services/utils/EntityIdUtils.java +++ b/hedera-mirror-web3/src/main/java/com/hedera/services/utils/EntityIdUtils.java @@ -268,6 +268,10 @@ public static String asHexedEvmAddress(final Id id) { return CommonUtils.hex(asEvmAddress(id.num())); } + public static String asHexedEvmAddress(long tokenId) { + return CommonUtils.hex(asEvmAddress(tokenId)); + } + public static boolean isAlias(final AccountID idOrAlias) { return idOrAlias.getAccountNum() == 0 && !idOrAlias.getAlias().isEmpty(); } @@ -326,10 +330,6 @@ public static boolean isAliasSizeGreaterThanEvmAddress(final ByteString alias) { return alias.size() > EVM_ADDRESS_SIZE; } - public static String addressFromId(long tokenId) { - return EvmTokenUtils.toAddress(tokenId).toHexString(); - } - public static EntityId entityIdFromTokenId(long tokenId) { var address = EvmTokenUtils.toAddress(tokenId); return EvmTokenUtils.entityIdFromEvmAddress(address); 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 2276dd15e7b..7150b73ee17 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 @@ -24,7 +24,6 @@ import static com.hedera.mirror.web3.utils.ContractCallTestUtil.ZERO_VALUE; import static com.hedera.mirror.web3.utils.ContractCallTestUtil.isWithinExpectedGasRange; import static com.hedera.mirror.web3.utils.ContractCallTestUtil.longValueOf; -import static com.hedera.services.utils.EntityIdUtils.addressFromId; import static com.hedera.services.utils.EntityIdUtils.asHexedEvmAddress; import static com.hedera.services.utils.EntityIdUtils.entityIdFromTokenId; import static com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_TOKEN_ID; @@ -126,7 +125,7 @@ void approve(final BigInteger allowance) throws Exception { // When final var functionCall = contract.call_approveExternal( - addressFromId(tokenEntity.getTokenId()), getAddressFromEntity(spender), allowance); + asHexedEvmAddress(tokenEntity.getTokenId()), getAddressFromEntity(spender), allowance); // Then verifyEthCallAndEstimateGas(functionCall, contract, ZERO_VALUE); @@ -383,7 +382,7 @@ void burnFungibleToken() throws Exception { // When final var functionCall = contract.call_burnTokenExternal( - addressFromId(token.getTokenId()), BigInteger.valueOf(4), new ArrayList<>()); + asHexedEvmAddress(token.getTokenId()), BigInteger.valueOf(4), new ArrayList<>()); final var result = functionCall.send(); @@ -576,7 +575,7 @@ void freezeToken() throws Exception { // When final var functionCall = contract.call_freezeTokenExternal( - addressFromId(tokenEntity.getTokenId()), getAliasFromEntity(accountWithoutFreeze)); + asHexedEvmAddress(tokenEntity.getTokenId()), getAliasFromEntity(accountWithoutFreeze)); // Then verifyEthCallAndEstimateGas(functionCall, contract, ZERO_VALUE); @@ -604,7 +603,7 @@ void unfreezeToken() throws Exception { // When final var functionCall = contract.call_unfreezeTokenExternal( - addressFromId(tokenEntity.getTokenId()), getAliasFromEntity(accountWithFreeze)); + asHexedEvmAddress(tokenEntity.getTokenId()), getAliasFromEntity(accountWithFreeze)); // Then verifyEthCallAndEstimateGas(functionCall, contract, ZERO_VALUE); @@ -722,7 +721,7 @@ void createFungibleTokenWithCustomFees() throws Exception { contract.getContractAddress(), TokenTypeEnum.FUNGIBLE_COMMON, treasuryAccount.toEntityId()); final var fixedFee = new FixedFee( - BigInteger.valueOf(100L), addressFromId(tokenId), false, false, getAliasFromEntity(feeCollector)); + BigInteger.valueOf(100L), asHexedEvmAddress(tokenId), false, false, getAliasFromEntity(feeCollector)); final var fractionalFee = new FractionalFee( BigInteger.valueOf(1L), BigInteger.valueOf(100L), @@ -812,12 +811,12 @@ void createNonFungibleTokenWithCustomFees() throws Exception { final var token = populateHederaToken( contract.getContractAddress(), TokenTypeEnum.NON_FUNGIBLE_UNIQUE, treasuryAccount.toEntityId()); final var fixedFee = new FixedFee( - BigInteger.valueOf(100L), addressFromId(tokenId), false, false, getAliasFromEntity(feeCollector)); + BigInteger.valueOf(100L), asHexedEvmAddress(tokenId), false, false, getAliasFromEntity(feeCollector)); final var royaltyFee = new RoyaltyFee( BigInteger.valueOf(1L), BigInteger.valueOf(100L), BigInteger.valueOf(10L), - addressFromId(tokenId), + asHexedEvmAddress(tokenId), false, getAliasFromEntity(feeCollector)); @@ -854,7 +853,7 @@ void create2ContractAndTransferFromIt() throws Exception { // When final var functionCall = contract.call_createContractViaCreate2AndTransferFromIt( - addressFromId(token.getTokenId()), + asHexedEvmAddress(token.getTokenId()), getAliasFromEntity(sponsor), getAliasFromEntity(receiver), BigInteger.valueOf(10L)); @@ -871,10 +870,10 @@ void notExistingPrecompileCall() throws Exception { final var contract = testWeb3jService.deploy(ModificationPrecompileTestContract::deploy); // Then if (mirrorNodeEvmProperties.isModularizedServices()) { - final var modularizedCall = contract.call_callNotExistingPrecompile(addressFromId(token.getTokenId())); + final var modularizedCall = contract.call_callNotExistingPrecompile(asHexedEvmAddress(token.getTokenId())); assertThat(Bytes.wrap(modularizedCall.send())).isEqualTo(Bytes.EMPTY); } else { - final var functionCall = contract.send_callNotExistingPrecompile(addressFromId(token.getTokenId())); + final var functionCall = contract.send_callNotExistingPrecompile(asHexedEvmAddress(token.getTokenId())); assertThatThrownBy(functionCall::send) .isInstanceOf(MirrorEvmTransactionException.class) .hasMessage(INVALID_TOKEN_ID.name()); @@ -1283,7 +1282,7 @@ void cryptoTransferToken() throws Exception { // When testWeb3jService.setSender(getAliasFromEntity(payer)); final var tokenTransferList = new TokenTransferList( - addressFromId(tokenId), + asHexedEvmAddress(tokenId), List.of( new AccountAmount(getAliasFromEntity(sender), BigInteger.valueOf(5L), false), new AccountAmount(getAliasFromEntity(receiver), BigInteger.valueOf(-5L), false)), @@ -1332,7 +1331,7 @@ void cryptoTransferHbarsAndToken() throws Exception { new AccountAmount(getAliasFromEntity(receiver), BigInteger.valueOf(5L), false))); final var tokenTransferList = new TokenTransferList( - addressFromId(tokenId), + asHexedEvmAddress(tokenId), List.of( new AccountAmount(getAliasFromEntity(sender), BigInteger.valueOf(5L), false), new AccountAmount(getAliasFromEntity(receiver), BigInteger.valueOf(-5L), false)), 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 0629a61c6f9..a7fca935446 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 @@ -31,7 +31,7 @@ import static com.hedera.mirror.web3.web3j.generated.PrecompileTestContract.Expiry; import static com.hedera.mirror.web3.web3j.generated.PrecompileTestContract.HederaToken; import static com.hedera.mirror.web3.web3j.generated.PrecompileTestContract.TokenKey; -import static com.hedera.services.utils.EntityIdUtils.addressFromId; +import static com.hedera.services.utils.EntityIdUtils.asHexedEvmAddress; import static com.hedera.services.utils.EntityIdUtils.asTypedEvmAddress; import static com.hedera.services.utils.EntityIdUtils.entityIdFromTokenId; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; @@ -104,7 +104,7 @@ void hrcIsAssociatedFails() throws Exception { final var contract = testWeb3jService.deploy(PrecompileTestContract::deploy); // When - final var functionCall = contract.call_hrcIsAssociated(addressFromId(token.getTokenId())); + final var functionCall = contract.call_hrcIsAssociated(asHexedEvmAddress(token.getTokenId())); // Then if (mirrorNodeEvmProperties.isModularizedServices()) { @@ -192,7 +192,7 @@ void isKycGranted() throws Exception { // When final var functionCall = - contract.call_isKycGranted(addressFromId(token.getTokenId()), getAddressFromEntity(account)); + contract.call_isKycGranted(asHexedEvmAddress(token.getTokenId()), getAddressFromEntity(account)); // Then assertThat(functionCall.send()).isTrue(); @@ -215,7 +215,7 @@ void isKycGrantedWithAlias() throws Exception { // When final var functionCall = - contract.call_isKycGranted(addressFromId(tokenEntity.getTokenId()), getAliasFromEntity(account)); + contract.call_isKycGranted(asHexedEvmAddress(tokenEntity.getTokenId()), getAliasFromEntity(account)); // Then assertThat(functionCall.send()).isTrue(); @@ -274,7 +274,7 @@ void isTokenAddress() throws Exception { final var contract = testWeb3jService.deploy(PrecompileTestContract::deploy); // When - final var functionCall = contract.call_isTokenAddress(addressFromId(tokenEntity.getTokenId())); + final var functionCall = contract.call_isTokenAddress(asHexedEvmAddress(tokenEntity.getTokenId())); // Then assertThat(functionCall.send()).isTrue(); @@ -355,7 +355,7 @@ void getTokenType() throws Exception { final var contract = testWeb3jService.deploy(PrecompileTestContract::deploy); // When - final var functionCall = contract.call_getType(addressFromId(tokenEntity.getTokenId())); + final var functionCall = contract.call_getType(asHexedEvmAddress(tokenEntity.getTokenId())); // Then assertThat(functionCall.send()).isEqualTo(BigInteger.ZERO); @@ -524,11 +524,11 @@ void getCustomFeesForTokenWithFixedFee() throws Exception { final var contract = testWeb3jService.deploy(PrecompileTestContract::deploy); // When - final var functionCall = contract.call_getCustomFeesForToken(addressFromId(tokenId)); + final var functionCall = contract.call_getCustomFeesForToken(asHexedEvmAddress(tokenId)); final var expectedFee = new FixedFee( BigInteger.valueOf(100L), - addressFromId(tokenId), + asHexedEvmAddress(tokenId), false, false, Address.fromHexString( @@ -565,7 +565,7 @@ void getCustomFeesForTokenWithFractionalFee() throws Exception { final var contract = testWeb3jService.deploy(PrecompileTestContract::deploy); // When - final var functionCall = contract.call_getCustomFeesForToken(addressFromId(tokenEntity.getTokenId())); + final var functionCall = contract.call_getCustomFeesForToken(asHexedEvmAddress(tokenEntity.getTokenId())); final var expectedFee = new PrecompileTestContract.FractionalFee( BigInteger.valueOf(100L), @@ -611,7 +611,7 @@ void getCustomFeesForTokenWithRoyaltyFee() throws Exception { final var contract = testWeb3jService.deploy(PrecompileTestContract::deploy); // When - final var functionCall = contract.call_getCustomFeesForToken(addressFromId(tokenId)); + final var functionCall = contract.call_getCustomFeesForToken(asHexedEvmAddress(tokenId)); final var expectedFee = new PrecompileTestContract.RoyaltyFee( BigInteger.valueOf(20L), @@ -686,7 +686,7 @@ void getAllowanceForToken() throws Exception { // When final var functionCall = contract.call_htsAllowance( - addressFromId(tokenEntity.getTokenId()), getAliasFromEntity(owner), getAliasFromEntity(spender)); + asHexedEvmAddress(tokenEntity.getTokenId()), getAliasFromEntity(owner), getAliasFromEntity(spender)); // Then assertThat(functionCall.send()).isEqualTo(BigInteger.valueOf(amountGranted)); From 8027b9d7f1d058ac69ebd0246478f054fea4b894 Mon Sep 17 00:00:00 2001 From: filev94 Date: Wed, 12 Feb 2025 11:07:22 +0200 Subject: [PATCH 05/13] addressing pr comment about token account Signed-off-by: filev94 --- .../web3/service/AbstractContractCallServiceTest.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) 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 781b9715587..4cf1795f038 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 @@ -407,15 +407,12 @@ protected TokenAccount tokenAccount(Consumer { - ta.tokenId(tokenId).accountId(accountId); - if (balance != null) { - ta.balance(balance); - } + ta.tokenId(tokenId).accountId(accountId).balance(balance); }); } protected void tokenAccountPersist(final long tokenId, final long accountId) { - tokenAccountPersist(tokenId, accountId, null); + tokenAccount(ta -> ta.tokenId(tokenId).accountId(accountId)); } /** From 9625b8714b7ed4fee73a4157a3b84367b9cd6b3b Mon Sep 17 00:00:00 2001 From: filev94 Date: Wed, 12 Feb 2025 11:32:36 +0200 Subject: [PATCH 06/13] removing tokenAccount with balance method Signed-off-by: filev94 --- .../web3/service/AbstractContractCallServiceTest.java | 6 ------ .../mirror/web3/service/ContractCallDynamicCallsTest.java | 6 +++--- 2 files changed, 3 insertions(+), 9 deletions(-) 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 4cf1795f038..2b557bee92f 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 @@ -405,12 +405,6 @@ protected TokenAccount tokenAccount(Consumer { - ta.tokenId(tokenId).accountId(accountId).balance(balance); - }); - } - protected void tokenAccountPersist(final long tokenId, final long accountId) { tokenAccount(ta -> ta.tokenId(tokenId).accountId(accountId)); } diff --git a/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallDynamicCallsTest.java b/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallDynamicCallsTest.java index f7da5ea210e..6daa23ab174 100644 --- a/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallDynamicCallsTest.java +++ b/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallDynamicCallsTest.java @@ -825,11 +825,11 @@ private Entity setUpToken(TokenTypeEnum tokenType, Entity treasuryAccount, Entit final var tokenId = tokenEntity.getId(); final var spenderId = spender.getId(); final var ownerId = owner.getId(); - tokenAccountPersist(tokenId, treasuryAccount.getId(), 1L); - tokenAccountPersist(tokenId, spenderId, 1L); + tokenAccountPersist(tokenId, treasuryAccount.getId()); + tokenAccountPersist(tokenId, spenderId); if (!Objects.equals(ownerId, spenderId)) { - tokenAccountPersist(tokenId, ownerId, 1L); + tokenAccountPersist(tokenId, ownerId); } if (tokenType.equals(TokenTypeEnum.FUNGIBLE_COMMON)) { From 978ea074a2bfef26082fa59bff0985c0e47c2ad1 Mon Sep 17 00:00:00 2001 From: filev94 Date: Wed, 12 Feb 2025 14:02:37 +0200 Subject: [PATCH 07/13] addressing pr comments Signed-off-by: filev94 --- .../hedera/services/utils/EntityIdUtils.java | 5 -- .../AbstractContractCallServiceTest.java | 14 ++--- ...CallServicePrecompileModificationTest.java | 52 +++++++++---------- ...ractCallServicePrecompileReadonlyTest.java | 6 +-- .../web3/service/ContractCallServiceTest.java | 8 +-- .../services/utils/EntityIdUtilsTest.java | 12 ++++- 6 files changed, 46 insertions(+), 51 deletions(-) diff --git a/hedera-mirror-web3/src/main/java/com/hedera/services/utils/EntityIdUtils.java b/hedera-mirror-web3/src/main/java/com/hedera/services/utils/EntityIdUtils.java index 3283b25f600..988504114c5 100644 --- a/hedera-mirror-web3/src/main/java/com/hedera/services/utils/EntityIdUtils.java +++ b/hedera-mirror-web3/src/main/java/com/hedera/services/utils/EntityIdUtils.java @@ -329,9 +329,4 @@ public static String readableId(final Object o) { public static boolean isAliasSizeGreaterThanEvmAddress(final ByteString alias) { return alias.size() > EVM_ADDRESS_SIZE; } - - public static EntityId entityIdFromTokenId(long tokenId) { - var address = EvmTokenUtils.toAddress(tokenId); - return EvmTokenUtils.entityIdFromEvmAddress(address); - } } 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 2b557bee92f..ac8c05d60e6 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 @@ -434,24 +434,16 @@ protected Nft nonFungibleTokenInstancePersist( * When an account balance is updated during a consensus event, an account_balance record with the consensus_timestamp, * account_id and balance is created.The balance_timestamp for the account entry is updated as well in the entity table. * @param account The account that the account_balance record is going to be created for - * @param balance The account balance that is going to be stored for the particular timestamp * @param timestamp The timestamp indicating the account balance update */ - protected void persistAccountBalance(Entity account, long balance, long timestamp) { + protected void accountBalancePersist(Entity account, long timestamp) { domainBuilder .accountBalance() .customize(ab -> ab.id(new AccountBalance.Id(timestamp, account.toEntityId())) - .balance(balance)) + .balance(account.getBalance())) .persist(); } - protected void persistAccountBalance(Entity account, long balance) { - domainBuilder - .accountBalance() - .customize(ab -> ab.id(new AccountBalance.Id(account.getCreatedTimestamp(), account.toEntityId())) - .balance(balance)) - .persist(); - } /** * Persists a record in the token_balance db table (consensus_timestamp, account_id, balance, token_id). @@ -459,7 +451,7 @@ protected void persistAccountBalance(Entity account, long balance) { * No record for the token balance at a particular timestamp may result in INSUFFICIENT_TOKEN_BALANCE exception * for a historical query with the same timestamp. */ - protected void persistTokenBalance(EntityId account, EntityId token, long timestamp) { + protected void tokenBalancePersist(EntityId account, EntityId token, long timestamp) { domainBuilder .tokenBalance() .customize(ab -> 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 7150b73ee17..ef0ea748db3 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 @@ -25,7 +25,6 @@ import static com.hedera.mirror.web3.utils.ContractCallTestUtil.isWithinExpectedGasRange; import static com.hedera.mirror.web3.utils.ContractCallTestUtil.longValueOf; import static com.hedera.services.utils.EntityIdUtils.asHexedEvmAddress; -import static com.hedera.services.utils.EntityIdUtils.entityIdFromTokenId; import static com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_TOKEN_ID; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; @@ -371,8 +370,9 @@ void burnFungibleToken() throws Exception { final var sender = accountEntityPersist(); accountBalanceRecordsPersist(sender); + long balanceTimestamp = treasuryAccount.getBalanceTimestamp(); - persistTokenBalance(treasuryAccount.toEntityId(), entityIdFromTokenId(token.getTokenId()), balanceTimestamp); + tokenBalancePersist(treasuryAccount.toEntityId(), EntityId.of(token.getTokenId()), balanceTimestamp); testWeb3jService.setSender(getAddressFromEntity(sender)); @@ -408,7 +408,7 @@ void burnNFT() throws Exception { final var totalSupply = token.getTotalSupply(); long balanceTimestamp = treasury.getBalanceTimestamp(); - persistTokenBalance(treasury.toEntityId(), tokenEntity.toEntityId(), balanceTimestamp); + tokenBalancePersist(treasury.toEntityId(), tokenEntity.toEntityId(), balanceTimestamp); Nft nft = domainBuilder .nft() @@ -454,8 +454,8 @@ void wipeFungibleToken() throws Exception { tokenAccountPersist(tokenEntity.getId(), owner.getId()); Long createdTimestamp = owner.getCreatedTimestamp(); - persistTokenBalance(owner.toEntityId(), tokenEntity.toEntityId(), createdTimestamp); - persistAccountBalance(treasuryEntity, treasuryEntity.getBalance(), createdTimestamp); + tokenBalancePersist(owner.toEntityId(), tokenEntity.toEntityId(), createdTimestamp); + accountBalancePersist(treasuryEntity, createdTimestamp); final var contract = testWeb3jService.deploy(ModificationPrecompileTestContract::deploy); @@ -844,8 +844,8 @@ void create2ContractAndTransferFromIt() throws Exception { final var receiver = accountEntityWithEvmAddressPersist(); final var token = fungibleTokenPersist(); final var sponsor = accountEntityWithEvmAddressPersist(); - persistTokenBalance( - sponsor.toEntityId(), entityIdFromTokenId(token.getTokenId()), sponsor.getCreatedTimestamp()); + tokenBalancePersist( + sponsor.toEntityId(), EntityId.of(token.getTokenId()), sponsor.getCreatedTimestamp()); accountBalanceRecordsPersist(sponsor); tokenAccountPersist(token.getTokenId(), sponsor.getId()); @@ -1099,10 +1099,10 @@ void transferToken(final String type) throws Exception { accountBalanceRecordsPersist(receiver.toEntityId(), receiver.getCreatedTimestamp(), receiver.getBalance()); long senderBalanceTimestamp = sender.getBalanceTimestamp(); - persistTokenBalance(sender.toEntityId(), tokenEntity.toEntityId(), senderBalanceTimestamp); + tokenBalancePersist(sender.toEntityId(), tokenEntity.toEntityId(), senderBalanceTimestamp); long receiverBalanceTimestamp = receiver.getBalanceTimestamp(); - persistTokenBalance(receiver.toEntityId(), tokenEntity.toEntityId(), receiverBalanceTimestamp); + tokenBalancePersist(receiver.toEntityId(), tokenEntity.toEntityId(), receiverBalanceTimestamp); final var contract = testWeb3jService.deploy(ModificationPrecompileTestContract::deploy); // When @@ -1236,9 +1236,9 @@ void cryptoTransferHbars() throws Exception { final var payer = accountEntityWithEvmAddressPersist(); long timestampForBalances = payer.getCreatedTimestamp(); - persistAccountBalance(payer, payer.getBalance()); - persistAccountBalance(sender, sender.getBalance(), timestampForBalances); - persistAccountBalance(treasuryEntity, treasuryEntity.getBalance(), timestampForBalances); + accountBalancePersist(payer, timestampForBalances); + accountBalancePersist(sender, timestampForBalances); + accountBalancePersist(treasuryEntity, timestampForBalances); // When testWeb3jService.setSender(getAliasFromEntity(payer)); @@ -1266,15 +1266,15 @@ void cryptoTransferToken() throws Exception { final var tokenId = token.getTokenId(); long timestampForBalances = payer.getCreatedTimestamp(); - final var entity = entityIdFromTokenId(tokenId); - persistAccountBalance(payer, payer.getBalance()); - persistTokenBalance(payer.toEntityId(), entity, timestampForBalances); + final var entity = EntityId.of(tokenId); + accountBalancePersist(payer, payer.getCreatedTimestamp()); + tokenBalancePersist(payer.toEntityId(), entity, timestampForBalances); - persistAccountBalance(sender, sender.getBalance(), timestampForBalances); - persistTokenBalance(sender.toEntityId(), entity, timestampForBalances); + accountBalancePersist(sender, timestampForBalances); + tokenBalancePersist(sender.toEntityId(), entity, timestampForBalances); - persistTokenBalance(receiver.toEntityId(), entity, timestampForBalances); - persistAccountBalance(treasuryEntity, treasuryEntity.getBalance(), timestampForBalances); + tokenBalancePersist(receiver.toEntityId(), entity, timestampForBalances); + accountBalancePersist(treasuryEntity, timestampForBalances); tokenAccountPersist(tokenId, sender.getId()); tokenAccountPersist(tokenId, receiver.getId()); @@ -1308,17 +1308,17 @@ void cryptoTransferHbarsAndToken() throws Exception { final var payer = accountEntityWithEvmAddressPersist(); long timestampForBalances = payer.getCreatedTimestamp(); final var tokenId = tokenEntity.getTokenId(); - final var entity = entityIdFromTokenId(tokenId); + final var entity = EntityId.of(tokenId); - persistAccountBalance(payer, payer.getBalance()); - persistTokenBalance(payer.toEntityId(), entity, timestampForBalances); + accountBalancePersist(payer, timestampForBalances); + tokenBalancePersist(payer.toEntityId(), entity, timestampForBalances); - persistAccountBalance(sender, sender.getBalance(), timestampForBalances); - persistTokenBalance(sender.toEntityId(), entity, timestampForBalances); + accountBalancePersist(sender, timestampForBalances); + tokenBalancePersist(sender.toEntityId(), entity, timestampForBalances); - persistTokenBalance(receiver.toEntityId(), entity, timestampForBalances); + tokenBalancePersist(receiver.toEntityId(), entity, timestampForBalances); - persistAccountBalance(treasuryEntity, treasuryEntity.getBalance(), timestampForBalances); + accountBalancePersist(treasuryEntity, timestampForBalances); tokenAccountPersist(tokenId, sender.getId()); tokenAccountPersist(tokenId, receiver.getId()); 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 a7fca935446..84042aa6e25 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 @@ -33,12 +33,12 @@ import static com.hedera.mirror.web3.web3j.generated.PrecompileTestContract.TokenKey; import static com.hedera.services.utils.EntityIdUtils.asHexedEvmAddress; import static com.hedera.services.utils.EntityIdUtils.asTypedEvmAddress; -import static com.hedera.services.utils.EntityIdUtils.entityIdFromTokenId; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; import com.google.protobuf.InvalidProtocolBufferException; 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; @@ -507,7 +507,7 @@ void getCustomFeesForTokenWithFixedFee() throws Exception { final var collectorAccount = accountEntityWithEvmAddressPersist(); final var tokenEntity = fungibleTokenPersist(); final var tokenId = tokenEntity.getTokenId(); - final var entityId = entityIdFromTokenId(tokenId); + final var entityId = EntityId.of(tokenId); final var fixedFee = com.hedera.mirror.common.domain.token.FixedFee.builder() .amount(100L) .collectorAccountId(collectorAccount.toEntityId()) @@ -589,7 +589,7 @@ void getCustomFeesForTokenWithRoyaltyFee() throws Exception { final var collectorAccount = accountEntityWithEvmAddressPersist(); final var tokenEntity = fungibleTokenPersist(); final var tokenId = tokenEntity.getTokenId(); - final var entityId = entityIdFromTokenId(tokenId); + final var entityId = EntityId.of(tokenId); final var royaltyFee = RoyaltyFee.builder() .collectorAccountId(collectorAccount.toEntityId()) diff --git a/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallServiceTest.java b/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallServiceTest.java index 5e210c1f537..78dcf5e5ed4 100644 --- a/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallServiceTest.java +++ b/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallServiceTest.java @@ -180,7 +180,7 @@ void pureCall() throws Exception { // Given final var gasUsedBeforeExecution = getGasUsedBeforeExecution(ETH_CALL); final var payer = accountEntityWithEvmAddressPersist(); - persistAccountBalance(payer, payer.getBalance()); + accountBalancePersist(payer, payer.getCreatedTimestamp()); testWeb3jService.setSender(toAddress(payer.toEntityId()).toHexString()); final var contract = testWeb3jService.deploy(EthCall::deploy); meterRegistry.clear(); // Clear it as the contract deploy increases the gas limit metric @@ -377,7 +377,7 @@ void viewCall() throws Exception { void estimateGasForViewCall() { // Given final var payer = accountEntityWithEvmAddressPersist(); - persistAccountBalance(payer, payer.getBalance()); + accountBalancePersist(payer, payer.getCreatedTimestamp()); testWeb3jService.setSender(toAddress(payer.toEntityId()).toHexString()); final var contract = testWeb3jService.deploy(EthCall::deploy); @@ -605,7 +605,7 @@ void transferNegative() { final var receiverEntity = accountPersist(); final var receiverAddress = getAliasAddressFromEntity(receiverEntity); final var payer = accountEntityWithEvmAddressPersist(); - persistAccountBalance(payer, payer.getBalance()); + accountBalancePersist(payer, payer.getCreatedTimestamp()); final var serviceParameters = getContractExecutionParametersWithValue( Bytes.EMPTY, toAddress(payer.toEntityId()), receiverAddress, -5L); // Then @@ -653,7 +653,7 @@ void transferThruContract() throws Exception { final var receiverAddress = getAliasAddressFromEntity(receiverEntity); final var contract = testWeb3jService.deploy(EthCall::deploy); final var payer = accountEntityWithEvmAddressPersist(); - persistAccountBalance(payer, payer.getBalance()); + accountBalancePersist(payer, payer.getCreatedTimestamp()); meterRegistry.clear(); testWeb3jService.setSender(toAddress(payer.toEntityId()).toHexString()); // When diff --git a/hedera-mirror-web3/src/test/java/com/hedera/services/utils/EntityIdUtilsTest.java b/hedera-mirror-web3/src/test/java/com/hedera/services/utils/EntityIdUtilsTest.java index ff44f2c868e..8de557f6f80 100644 --- a/hedera-mirror-web3/src/test/java/com/hedera/services/utils/EntityIdUtilsTest.java +++ b/hedera-mirror-web3/src/test/java/com/hedera/services/utils/EntityIdUtilsTest.java @@ -62,6 +62,8 @@ class EntityIdUtilsTest { public static final ByteString EVM_ADDRESS = ByteString.fromHex("ebb9a1be370150759408cd7af48e9eda2b8ead57"); public static final ByteString WRONG_EVM_ADDRESS = ByteString.fromHex("ebb9a1be3701cd7af48e9eda2b8ead57"); + private static final String expectedHexedAddress = "0000000000000000000000000000000000000003"; + @Test void asSolidityAddressBytesWorksProperly() { final var id = AccountID.newBuilder() @@ -218,7 +220,7 @@ void isOfEcdsaPublicAddressSizeWorks() { void asSolidityAddressHexWorksProperly() { final var id = new Id(1, 2, 3); - assertEquals("0000000000000000000000000000000000000003", EntityIdUtils.asHexedEvmAddress(id)); + assertEquals(expectedHexedAddress, EntityIdUtils.asHexedEvmAddress(id)); } @Test @@ -229,7 +231,13 @@ void asSolidityAddressHexWorksProperlyForAccount() { .setAccountNum(3) .build(); - assertEquals("0000000000000000000000000000000000000003", EntityIdUtils.asHexedEvmAddress(accountId)); + assertEquals(expectedHexedAddress, EntityIdUtils.asHexedEvmAddress(accountId)); + } + + @Test + void asSolidityAddressHexWorksProperlyForLong() { + var test = EntityIdUtils.asHexedEvmAddress(1); + assertEquals(expectedHexedAddress, EntityIdUtils.asHexedEvmAddress(3)); } @Test From ff4ceb3592c620e05f081269bd8334f14bf63453 Mon Sep 17 00:00:00 2001 From: filev94 Date: Wed, 12 Feb 2025 14:14:09 +0200 Subject: [PATCH 08/13] spotlessApply Signed-off-by: filev94 --- .../main/java/com/hedera/services/utils/EntityIdUtils.java | 1 - .../mirror/web3/service/AbstractContractCallServiceTest.java | 1 - .../ContractCallServicePrecompileModificationTest.java | 4 +--- 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/hedera-mirror-web3/src/main/java/com/hedera/services/utils/EntityIdUtils.java b/hedera-mirror-web3/src/main/java/com/hedera/services/utils/EntityIdUtils.java index 988504114c5..abf88b7ea93 100644 --- a/hedera-mirror-web3/src/main/java/com/hedera/services/utils/EntityIdUtils.java +++ b/hedera-mirror-web3/src/main/java/com/hedera/services/utils/EntityIdUtils.java @@ -26,7 +26,6 @@ import com.hedera.hapi.node.base.AccountID.AccountOneOfType; import com.hedera.mirror.common.domain.entity.Entity; import com.hedera.mirror.common.domain.entity.EntityId; -import com.hedera.mirror.web3.evm.utils.EvmTokenUtils; import com.hedera.pbj.runtime.OneOf; import com.hedera.services.store.models.Id; import com.hedera.services.store.models.NftId; 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 ac8c05d60e6..693d6be95b2 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 @@ -444,7 +444,6 @@ protected void accountBalancePersist(Entity account, long timestamp) { .persist(); } - /** * Persists a record in the token_balance db table (consensus_timestamp, account_id, balance, token_id). * Each record represents the fungible token balance that an account holds at a given consensus timestamp. 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 ef0ea748db3..97f384f2e50 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 @@ -370,7 +370,6 @@ void burnFungibleToken() throws Exception { final var sender = accountEntityPersist(); accountBalanceRecordsPersist(sender); - long balanceTimestamp = treasuryAccount.getBalanceTimestamp(); tokenBalancePersist(treasuryAccount.toEntityId(), EntityId.of(token.getTokenId()), balanceTimestamp); @@ -844,8 +843,7 @@ void create2ContractAndTransferFromIt() throws Exception { final var receiver = accountEntityWithEvmAddressPersist(); final var token = fungibleTokenPersist(); final var sponsor = accountEntityWithEvmAddressPersist(); - tokenBalancePersist( - sponsor.toEntityId(), EntityId.of(token.getTokenId()), sponsor.getCreatedTimestamp()); + tokenBalancePersist(sponsor.toEntityId(), EntityId.of(token.getTokenId()), sponsor.getCreatedTimestamp()); accountBalanceRecordsPersist(sponsor); tokenAccountPersist(token.getTokenId(), sponsor.getId()); From de28d9bc89ff70a69d97f6f818354b3ccd191ff1 Mon Sep 17 00:00:00 2001 From: filev94 Date: Wed, 12 Feb 2025 14:25:19 +0200 Subject: [PATCH 09/13] small refactoring Signed-off-by: filev94 --- ...ractCallServicePrecompileModificationTest.java | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) 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 97f384f2e50..5a7907a0595 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 @@ -370,8 +370,8 @@ void burnFungibleToken() throws Exception { final var sender = accountEntityPersist(); accountBalanceRecordsPersist(sender); - long balanceTimestamp = treasuryAccount.getBalanceTimestamp(); - tokenBalancePersist(treasuryAccount.toEntityId(), EntityId.of(token.getTokenId()), balanceTimestamp); + tokenBalancePersist( + treasuryAccount.toEntityId(), EntityId.of(token.getTokenId()), treasuryAccount.getBalanceTimestamp()); testWeb3jService.setSender(getAddressFromEntity(sender)); @@ -406,8 +406,7 @@ void burnNFT() throws Exception { tokenAccountPersist(tokenEntity.getId(), treasury.getId()); final var totalSupply = token.getTotalSupply(); - long balanceTimestamp = treasury.getBalanceTimestamp(); - tokenBalancePersist(treasury.toEntityId(), tokenEntity.toEntityId(), balanceTimestamp); + tokenBalancePersist(treasury.toEntityId(), tokenEntity.toEntityId(), treasury.getBalanceTimestamp()); Nft nft = domainBuilder .nft() @@ -1096,11 +1095,9 @@ void transferToken(final String type) throws Exception { accountBalanceRecordsPersist(sender.toEntityId(), sender.getCreatedTimestamp(), sender.getBalance()); accountBalanceRecordsPersist(receiver.toEntityId(), receiver.getCreatedTimestamp(), receiver.getBalance()); - long senderBalanceTimestamp = sender.getBalanceTimestamp(); - tokenBalancePersist(sender.toEntityId(), tokenEntity.toEntityId(), senderBalanceTimestamp); + tokenBalancePersist(sender.toEntityId(), tokenEntity.toEntityId(), sender.getBalanceTimestamp()); - long receiverBalanceTimestamp = receiver.getBalanceTimestamp(); - tokenBalancePersist(receiver.toEntityId(), tokenEntity.toEntityId(), receiverBalanceTimestamp); + tokenBalancePersist(receiver.toEntityId(), tokenEntity.toEntityId(), receiver.getBalanceTimestamp()); final var contract = testWeb3jService.deploy(ModificationPrecompileTestContract::deploy); // When @@ -1265,7 +1262,7 @@ void cryptoTransferToken() throws Exception { long timestampForBalances = payer.getCreatedTimestamp(); final var entity = EntityId.of(tokenId); - accountBalancePersist(payer, payer.getCreatedTimestamp()); + accountBalancePersist(payer, timestampForBalances); tokenBalancePersist(payer.toEntityId(), entity, timestampForBalances); accountBalancePersist(sender, timestampForBalances); From c9958e709f5af855617cfc465ced37ec598f0b60 Mon Sep 17 00:00:00 2001 From: filev94 Date: Wed, 12 Feb 2025 14:45:23 +0200 Subject: [PATCH 10/13] small refactoring Signed-off-by: filev94 --- .../com/hedera/services/utils/EntityIdUtilsTest.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/hedera-mirror-web3/src/test/java/com/hedera/services/utils/EntityIdUtilsTest.java b/hedera-mirror-web3/src/test/java/com/hedera/services/utils/EntityIdUtilsTest.java index 8de557f6f80..459575948cf 100644 --- a/hedera-mirror-web3/src/test/java/com/hedera/services/utils/EntityIdUtilsTest.java +++ b/hedera-mirror-web3/src/test/java/com/hedera/services/utils/EntityIdUtilsTest.java @@ -62,7 +62,7 @@ class EntityIdUtilsTest { public static final ByteString EVM_ADDRESS = ByteString.fromHex("ebb9a1be370150759408cd7af48e9eda2b8ead57"); public static final ByteString WRONG_EVM_ADDRESS = ByteString.fromHex("ebb9a1be3701cd7af48e9eda2b8ead57"); - private static final String expectedHexedAddress = "0000000000000000000000000000000000000003"; + private static final String EXPECTED_HEXED_ADDRESS = "0000000000000000000000000000000000000003"; @Test void asSolidityAddressBytesWorksProperly() { @@ -220,7 +220,7 @@ void isOfEcdsaPublicAddressSizeWorks() { void asSolidityAddressHexWorksProperly() { final var id = new Id(1, 2, 3); - assertEquals(expectedHexedAddress, EntityIdUtils.asHexedEvmAddress(id)); + assertEquals(EXPECTED_HEXED_ADDRESS, EntityIdUtils.asHexedEvmAddress(id)); } @Test @@ -231,13 +231,12 @@ void asSolidityAddressHexWorksProperlyForAccount() { .setAccountNum(3) .build(); - assertEquals(expectedHexedAddress, EntityIdUtils.asHexedEvmAddress(accountId)); + assertEquals(EXPECTED_HEXED_ADDRESS, EntityIdUtils.asHexedEvmAddress(accountId)); } @Test - void asSolidityAddressHexWorksProperlyForLong() { - var test = EntityIdUtils.asHexedEvmAddress(1); - assertEquals(expectedHexedAddress, EntityIdUtils.asHexedEvmAddress(3)); + void asSolidityAddressHexWorksProperlyForTokenId() { + assertEquals(EXPECTED_HEXED_ADDRESS, EntityIdUtils.asHexedEvmAddress(3)); } @Test From b354304a4939f9fff830b584434cf4fe0636446e Mon Sep 17 00:00:00 2001 From: filev94 Date: Wed, 12 Feb 2025 17:18:24 +0200 Subject: [PATCH 11/13] changing tokenEntity to token and adding tokenId variable Signed-off-by: filev94 --- .../service/ContractCallDynamicCallsTest.java | 44 ++++---- .../service/ContractCallNestedCallsTest.java | 4 +- ...viceERCTokenModificationFunctionsTest.java | 66 +++++++----- ...lServiceERCTokenReadOnlyFunctionsTest.java | 100 ++++++++++-------- ...CallServicePrecompileModificationTest.java | 27 ++--- ...ractCallServicePrecompileReadonlyTest.java | 36 ++++--- .../web3/service/OpcodeServiceTest.java | 4 +- 7 files changed, 154 insertions(+), 127 deletions(-) diff --git a/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallDynamicCallsTest.java b/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallDynamicCallsTest.java index 6daa23ab174..24dafacc4d0 100644 --- a/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallDynamicCallsTest.java +++ b/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallDynamicCallsTest.java @@ -99,7 +99,7 @@ void burnTokenGetTotalSupplyAndBalanceOfTreasury(final TokenTypeEnum tokenType) if (tokenType.equals(TokenTypeEnum.FUNGIBLE_COMMON)) { fungibleTokenPersist(tokenEntity, treasuryAccount); } else { - Token token = nonFungibleTokenPersist(tokenEntity, treasuryAccount); + var token = nonFungibleTokenPersist(tokenEntity, treasuryAccount); nonFungibleTokenInstancePersist( token, 1L, @@ -290,10 +290,10 @@ void associateTokenDissociateFailTransferEthCall( final var senderEntityId = accountEntityPersist().toEntityId(); final var senderAddress = toAddress(senderEntityId.getId()); - final var tokenEntity = tokenType == TokenTypeEnum.FUNGIBLE_COMMON + final var token = tokenType == TokenTypeEnum.FUNGIBLE_COMMON ? fungibleTokenPersistWithTreasuryAccount(treasuryEntityId) : nftPersist(treasuryEntityId, ownerEntityId); - final var tokenAddress = toAddress(tokenEntity.getTokenId()); + final var tokenAddress = toAddress(token.getTokenId()); final var contract = testWeb3jService.deploy(DynamicEthCalls::deploy); @@ -335,12 +335,12 @@ void approveTokenGetAllowance(final TokenTypeEnum tokenType, final long amount, final var ownerAddress = toAddress(ownerEntityId); final var spenderEntityId = accountEntityPersist().toEntityId(); - final var tokenEntity = tokenType == TokenTypeEnum.FUNGIBLE_COMMON + final var token = tokenType == TokenTypeEnum.FUNGIBLE_COMMON ? fungibleTokenPersistWithTreasuryAccount(treasuryEntityId) : nftPersist(treasuryEntityId, ownerEntityId, spenderEntityId); - final var tokenAddress = toAddress(tokenEntity.getTokenId()); - final var tokenId = tokenEntity.getTokenId(); - final var tokenEntityId = entityIdFromEvmAddress(toAddress(tokenEntity.getTokenId())); + final var tokenAddress = toAddress(token.getTokenId()); + final var tokenId = token.getTokenId(); + final var tokenEntityId = entityIdFromEvmAddress(toAddress(token.getTokenId())); final var contract = testWeb3jService.deploy(DynamicEthCalls::deploy); final var contractAddress = Address.fromHexString(contract.getContractAddress()); @@ -385,12 +385,12 @@ void approveTokenTransferFromGetAllowanceGetBalance( final var contractAddress = Address.fromHexString(contract.getContractAddress()); final var contractEntityId = entityIdFromEvmAddress(contractAddress); - final var tokenEntity = tokenType == TokenTypeEnum.FUNGIBLE_COMMON + final var token = tokenType == TokenTypeEnum.FUNGIBLE_COMMON ? fungibleTokenPersistWithTreasuryAccount(treasuryEntityId) : nftPersist(treasuryEntityId, contractEntityId, spenderEntityId); - final var tokenAddress = toAddress(tokenEntity.getTokenId()); + final var tokenAddress = toAddress(token.getTokenId()); final var tokenEntityId = entityIdFromEvmAddress(tokenAddress); - final var tokenId = tokenEntity.getTokenId(); + final var tokenId = token.getTokenId(); tokenAccountPersist(tokenId, contractEntityId.getId()); tokenAccountPersist(tokenId, spenderEntityId.getId()); @@ -429,10 +429,10 @@ void approveTokenTransferGetAllowanceGetBalance( final var contractAddress = Address.fromHexString(contract.getContractAddress()); final var contractEntityId = entityIdFromEvmAddress(contractAddress); - final var tokenEntity = tokenType == TokenTypeEnum.FUNGIBLE_COMMON + final var token = tokenType == TokenTypeEnum.FUNGIBLE_COMMON ? fungibleTokenPersistWithTreasuryAccount(treasuryEntityId) : nftPersist(treasuryEntityId, senderEntityId); - final var tokenId = tokenEntity.getTokenId(); + final var tokenId = token.getTokenId(); final var tokenAddress = toAddress(tokenId); tokenAccountPersist(tokenId, senderEntityId.getId()); @@ -467,10 +467,10 @@ void approveTokenCryptoTransferGetAllowanceGetBalance( final var contractAddress = Address.fromHexString(contract.getContractAddress()); final var contractEntityId = entityIdFromEvmAddress(contractAddress); - final var tokenEntity = tokenType == TokenTypeEnum.FUNGIBLE_COMMON + final var token = tokenType == TokenTypeEnum.FUNGIBLE_COMMON ? fungibleTokenPersistWithTreasuryAccount(treasuryEntityId) : nftPersist(treasuryEntityId, spenderEntityId); - final var tokenId = tokenEntity.getTokenId(); + final var tokenId = token.getTokenId(); final var tokenAddress = toAddress(tokenId); tokenAccountPersist(tokenId, spenderEntityId.getId()); @@ -579,10 +579,10 @@ void cryptoTransferFromGetAllowanceGetBalance( final var contractAddress = Address.fromHexString(contract.getContractAddress()); final var contractEntityId = entityIdFromEvmAddress(contractAddress); - final var tokenEntity = tokenType == TokenTypeEnum.FUNGIBLE_COMMON + final var token = tokenType == TokenTypeEnum.FUNGIBLE_COMMON ? fungibleTokenPersistWithTreasuryAccount(treasuryEntityId) : nftPersist(treasuryEntityId, spenderEntityId); - final var tokenId = tokenEntity.getTokenId(); + final var tokenId = token.getTokenId(); final var tokenAddress = toAddress(tokenId); tokenAccountPersist(tokenId, spenderEntityId.getId()); @@ -658,11 +658,11 @@ void transferFromGetAllowanceGetBalance(final TokenTypeEnum tokenType, final lon final var contractAddress = Address.fromHexString(contract.getContractAddress()); final var contractEntityId = entityIdFromEvmAddress(contractAddress); - final var tokenEntity = tokenType == TokenTypeEnum.FUNGIBLE_COMMON + final var token = tokenType == TokenTypeEnum.FUNGIBLE_COMMON ? fungibleTokenPersistWithTreasuryAccount(treasuryEntityId) : nftPersist(treasuryEntityId, treasuryEntityId); - final var tokenAddress = toAddress(tokenEntity.getTokenId()); - final var tokenId = tokenEntity.getTokenId(); + final var tokenId = token.getTokenId(); + final var tokenAddress = toAddress(tokenId); tokenAccountPersist(tokenId, treasuryEntityId.getId()); tokenAccountPersist(tokenId, spenderEntityId.getId()); @@ -692,10 +692,10 @@ void grantKycRevokeKyc(final TokenTypeEnum tokenType) { final var contract = testWeb3jService.deploy(DynamicEthCalls::deploy); - final var tokenEntity = tokenType == TokenTypeEnum.FUNGIBLE_COMMON + final var token = tokenType == TokenTypeEnum.FUNGIBLE_COMMON ? fungibleTokenPersistWithTreasuryAccount(treasuryEntityId) : nftPersist(treasuryEntityId, treasuryEntityId); - final var tokenId = tokenEntity.getTokenId(); + final var tokenId = token.getTokenId(); final var tokenAddress = toAddress(tokenId); tokenAccountPersist(tokenId, spenderEntityId.getId()); @@ -835,7 +835,7 @@ private Entity setUpToken(TokenTypeEnum tokenType, Entity treasuryAccount, Entit if (tokenType.equals(TokenTypeEnum.FUNGIBLE_COMMON)) { fungibleTokenPersist(tokenEntity, treasuryAccount); } else { - Token token = nonFungibleTokenPersist(tokenEntity, treasuryAccount); + var token = nonFungibleTokenPersist(tokenEntity, treasuryAccount); nonFungibleTokenInstancePersist(token, 1L, owner.toEntityId(), spender.toEntityId()); } diff --git a/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallNestedCallsTest.java b/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallNestedCallsTest.java index 257b346bfa9..95f044eb492 100644 --- a/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallNestedCallsTest.java +++ b/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallNestedCallsTest.java @@ -84,9 +84,9 @@ class ContractCallNestedCallsTest extends AbstractContractCallServiceOpcodeTrace void updateTokenKeysAndGetUpdatedTokenKeyForFungibleToken(final KeyValueType keyValueType, final KeyType keyType) throws Exception { // Given - final var tokenEntityId = fungibleTokenPersistWithTreasuryAccount( + final var token = fungibleTokenPersistWithTreasuryAccount( domainBuilder.entity().persist().toEntityId()); - final var tokenAddress = toAddress(tokenEntityId.getTokenId()); + final var tokenAddress = toAddress(token.getTokenId()); final var contract = testWeb3jService.deploy(NestedCalls::deploy); final var contractAddress = contract.getContractAddress(); diff --git a/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallServiceERCTokenModificationFunctionsTest.java b/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallServiceERCTokenModificationFunctionsTest.java index 34691f6fec1..286b0c0b02d 100644 --- a/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallServiceERCTokenModificationFunctionsTest.java +++ b/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallServiceERCTokenModificationFunctionsTest.java @@ -72,9 +72,10 @@ void approveFungibleToken() { // Given final var spender = accountEntityPersist(); final var token = fungibleTokenPersist(); + final var tokenId = token.getTokenId(); final var amountGranted = 13L; - final var tokenEntity = entityIdFromEvmAddress(toAddress(token.getTokenId())); - final var tokenAddress = toAddress(token.getTokenId()); + final var tokenEntity = entityIdFromEvmAddress(toAddress(tokenId)); + final var tokenAddress = toAddress(tokenId); final var contract = testWeb3jService.deploy(ERCTestContract::deploy); final var contractAddress = Address.fromHexString(contract.getContractAddress()); final var contractEntityId = entityIdFromEvmAddress(contractAddress); @@ -163,10 +164,11 @@ void approveFungibleTokenWithAlias() { accountPersistWithAlias(SPENDER_ALIAS, SPENDER_PUBLIC_KEY).toEntityId(); final var treasury = accountEntityPersist().toEntityId(); final var token = fungibleTokenPersistWithTreasuryAccount(treasury); + final var tokenId = token.getTokenId(); final var amountGranted = 13L; - final var tokenEntity = entityIdFromEvmAddress(toAddress(token.getTokenId())); - final var tokenAddress = toAddress(token.getTokenId()); - tokenAssociateAccountPersist(spender, entityIdFromEvmAddress(toAddress(token.getTokenId()))); + final var tokenEntity = entityIdFromEvmAddress(toAddress(tokenId)); + final var tokenAddress = toAddress(tokenId); + tokenAssociateAccountPersist(spender, entityIdFromEvmAddress(toAddress(tokenId))); final var contract = testWeb3jService.deploy(ERCTestContract::deploy); final var contractAddress = Address.fromHexString(contract.getContractAddress()); @@ -205,9 +207,10 @@ void transfer() { final var recipient = accountEntityPersist().toEntityId(); final var treasury = accountEntityPersist().toEntityId(); final var token = fungibleTokenPersistWithTreasuryAccount(treasury); - final var tokenEntity = entityIdFromEvmAddress(toAddress(token.getTokenId())); + final var tokenId = token.getTokenId(); + final var tokenEntity = entityIdFromEvmAddress(toAddress(tokenId)); final var tokenAddress = toAddress(tokenEntity.getId()); - tokenAssociateAccountPersist(recipient, entityIdFromEvmAddress(toAddress(tokenEntity.getId()))); + tokenAssociateAccountPersist(recipient, entityIdFromEvmAddress(toAddress(tokenId))); final var contract = testWeb3jService.deploy(ERCTestContract::deploy); final var contractAddress = Address.fromHexString(contract.getContractAddress()); @@ -230,7 +233,8 @@ void transferFrom() { final var recipient = accountEntityPersist().toEntityId(); final var token = fungibleTokenPersistWithTreasuryAccount(treasury); - final var tokenEntity = entityIdFromEvmAddress(toAddress(token.getTokenId())); + final var tokenId = token.getTokenId(); + final var tokenEntity = entityIdFromEvmAddress(toAddress(tokenId)); tokenAssociateAccountPersist(owner, tokenEntity); tokenAssociateAccountPersist(recipient, tokenEntity); @@ -240,10 +244,10 @@ void transferFrom() { tokenAssociateAccountPersist(contractEntityId, tokenEntity); final var amount = 10L; fungibleTokenAllowancePersist( - contractEntityId, owner, entityIdFromEvmAddress(toAddress(tokenEntity.getId())), amount); + contractEntityId, owner, entityIdFromEvmAddress(toAddress(tokenId)), amount); // When final var functionCall = contract.send_transferFrom( - toAddress(tokenEntity.getId()).toHexString(), + toAddress(tokenId).toHexString(), toAddress(owner).toHexString(), toAddress(recipient).toHexString(), BigInteger.valueOf(amount)); @@ -320,17 +324,18 @@ void transferWithAlias() { final var treasury = accountPersistWithAlias(SENDER_ALIAS, SENDER_PUBLIC_KEY).toEntityId(); final var token = fungibleTokenPersistWithTreasuryAccount(treasury); - tokenAssociateAccountPersist(recipient.toEntityId(), entityIdFromEvmAddress(toAddress(token.getTokenId()))); + final var tokenId = token.getTokenId(); + tokenAssociateAccountPersist(recipient.toEntityId(), entityIdFromEvmAddress(toAddress(tokenId))); final var contract = testWeb3jService.deploy(ERCTestContract::deploy); final var contractAddress = Address.fromHexString(contract.getContractAddress()); final var contractEntityId = entityIdFromEvmAddress(contractAddress); - tokenAssociateAccountPersist(contractEntityId, entityIdFromEvmAddress(toAddress(token.getTokenId()))); + tokenAssociateAccountPersist(contractEntityId, entityIdFromEvmAddress(toAddress(tokenId))); final var amount = 10L; // When final var functionCall = contract.send_transfer( - toAddress(token.getTokenId()).toHexString(), SPENDER_ALIAS.toHexString(), BigInteger.valueOf(amount)); + toAddress(tokenId).toHexString(), SPENDER_ALIAS.toHexString(), BigInteger.valueOf(amount)); // Then verifyEthCallAndEstimateGas(functionCall, contract); } @@ -398,10 +403,11 @@ void approveFungibleTokenRedirect() { // Given final var spender = accountEntityPersist().toEntityId(); final var token = fungibleTokenPersist(); + final var tokenId = token.getTokenId(); final var amountGranted = 13L; - final var tokenEntity = entityIdFromEvmAddress(toAddress(token.getTokenId())); - final var tokenAddress = toAddress(token.getTokenId()); - tokenAssociateAccountPersist(spender, entityIdFromEvmAddress(toAddress(token.getTokenId()))); + final var tokenEntity = entityIdFromEvmAddress(toAddress(tokenId)); + final var tokenAddress = toAddress(tokenId); + tokenAssociateAccountPersist(spender, entityIdFromEvmAddress(toAddress(tokenId))); final var contract = testWeb3jService.deploy(RedirectTestContract::deploy); final var contractAddress = Address.fromHexString(contract.getContractAddress()); @@ -455,10 +461,11 @@ void approveFungibleTokenWithAliasRedirect() { final var spender = accountPersistWithAlias(SPENDER_ALIAS, SPENDER_PUBLIC_KEY).toEntityId(); final var token = fungibleTokenPersist(); + final var tokenId = token.getTokenId(); final var amountGranted = 13L; - final var tokenEntity = entityIdFromEvmAddress(toAddress(token.getTokenId())); - final var tokenAddress = toAddress(token.getTokenId()); - tokenAssociateAccountPersist(spender, entityIdFromEvmAddress(toAddress(token.getTokenId()))); + final var tokenEntity = entityIdFromEvmAddress(toAddress(tokenId)); + final var tokenAddress = toAddress(tokenId); + tokenAssociateAccountPersist(spender, entityIdFromEvmAddress(toAddress(tokenId))); final var contract = testWeb3jService.deploy(RedirectTestContract::deploy); final var contractAddress = Address.fromHexString(contract.getContractAddress()); @@ -524,19 +531,20 @@ void transferFromRedirect() { final var recipient = accountEntityPersist().toEntityId(); final var token = fungibleTokenPersistWithTreasuryAccount(treasury); - final var tokenEntity = entityIdFromEvmAddress(toAddress(token.getTokenId())); + final var tokenId = token.getTokenId(); + final var tokenEntity = entityIdFromEvmAddress(toAddress(tokenId)); tokenAssociateAccountPersist(owner, tokenEntity); tokenAssociateAccountPersist(recipient, tokenEntity); final var contract = testWeb3jService.deploy(RedirectTestContract::deploy); final var contractAddress = Address.fromHexString(contract.getContractAddress()); final var contractEntityId = entityIdFromEvmAddress(contractAddress); - tokenAssociateAccountPersist(contractEntityId, entityIdFromEvmAddress(toAddress(tokenEntity.getId()))); + tokenAssociateAccountPersist(contractEntityId, entityIdFromEvmAddress(toAddress(tokenId))); final var amount = 10L; fungibleTokenAllowancePersist(contractEntityId, owner, tokenEntity, amount); // When final var functionCall = contract.send_transferFromRedirect( - toAddress(tokenEntity.getId()).toHexString(), + toAddress(tokenId).toHexString(), toAddress(owner).toHexString(), toAddress(recipient).toHexString(), BigInteger.valueOf(amount)); @@ -618,17 +626,18 @@ void transferWithAliasRedirect() { final var treasury = accountPersistWithAlias(SENDER_ALIAS, SENDER_PUBLIC_KEY).toEntityId(); final var token = fungibleTokenPersistWithTreasuryAccount(treasury); - tokenAssociateAccountPersist(recipient, entityIdFromEvmAddress(toAddress(token.getTokenId()))); + final var tokenId = token.getTokenId(); + tokenAssociateAccountPersist(recipient, entityIdFromEvmAddress(toAddress(tokenId))); final var contract = testWeb3jService.deploy(RedirectTestContract::deploy); final var contractAddress = Address.fromHexString(contract.getContractAddress()); final var contractEntityId = entityIdFromEvmAddress(contractAddress); - tokenAssociateAccountPersist(contractEntityId, entityIdFromEvmAddress(toAddress(token.getTokenId()))); + tokenAssociateAccountPersist(contractEntityId, entityIdFromEvmAddress(toAddress(tokenId))); final var amount = 10L; // When final var functionCall = contract.send_transferRedirect( - toAddress(token.getTokenId()).toHexString(), SPENDER_ALIAS.toHexString(), BigInteger.valueOf(amount)); + toAddress(tokenId).toHexString(), SPENDER_ALIAS.toHexString(), BigInteger.valueOf(amount)); // Then verifyEthCallAndEstimateGas(functionCall, contract); } @@ -642,7 +651,8 @@ void transferFromWithAliasRedirect() { final var recipient = accountPersistWithAlias(SPENDER_ALIAS, SPENDER_PUBLIC_KEY).toEntityId(); final var token = fungibleTokenPersistWithTreasuryAccount(treasury); - final var tokenEntity = entityIdFromEvmAddress(toAddress(token.getTokenId())); + final var tokenId = token.getTokenId(); + final var tokenEntity = entityIdFromEvmAddress(toAddress(tokenId)); tokenAssociateAccountPersist(owner, tokenEntity); tokenAssociateAccountPersist(recipient, tokenEntity); @@ -652,10 +662,10 @@ void transferFromWithAliasRedirect() { tokenAssociateAccountPersist(contractEntityId, tokenEntity); final var amount = 10L; fungibleTokenAllowancePersist( - contractEntityId, owner, entityIdFromEvmAddress(toAddress(tokenEntity.getId())), amount); + contractEntityId, owner, entityIdFromEvmAddress(toAddress(tokenId)), amount); // When final var functionCall = contract.send_transferFromRedirect( - toAddress(tokenEntity.getId()).toHexString(), + toAddress(tokenId).toHexString(), SENDER_ALIAS.toHexString(), SPENDER_ALIAS.toHexString(), BigInteger.valueOf(amount)); 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 e9170c5a89a..83d40bc7772 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 @@ -208,14 +208,15 @@ void ethCallIsApprovedForAllWithAliasNonStatic() throws Exception { void ethCallAllowanceStatic() throws Exception { final var owner = accountPersist(); final var spender = accountPersist(); - final var tokenEntity = fungibleTokenPersist(); + final var token = fungibleTokenPersist(); + final var tokenId = token.getTokenId(); var entity = domainBuilder .tokenAllowance() - .customize(a -> a.tokenId(tokenEntity.getTokenId()) + .customize(a -> a.tokenId(tokenId) .owner(owner.getNum()) .spender(spender.getNum())) .persist(); - final var tokenAddress = toAddress(tokenEntity.getTokenId()); + final var tokenAddress = toAddress(tokenId); final var contract = testWeb3jService.deploy(ERCTestContract::deploy); final var result = contract.call_allowance( tokenAddress.toHexString(), @@ -234,14 +235,15 @@ void ethCallAllowanceStatic() throws Exception { void ethCallAllowanceNonStatic() throws Exception { final var owner = accountPersist(); final var spender = accountPersist(); - final var tokenEntity = fungibleTokenPersist(); + final var token = fungibleTokenPersist(); + final var tokenId = token.getTokenId(); var entity = domainBuilder .tokenAllowance() - .customize(a -> a.tokenId(tokenEntity.getTokenId()) + .customize(a -> a.tokenId(tokenId) .owner(owner.getNum()) .spender(spender.getNum())) .persist(); - final var tokenAddress = toAddress(tokenEntity.getTokenId()); + final var tokenAddress = toAddress(tokenId); final var contract = testWeb3jService.deploy(ERCTestContract::deploy); final var result = contract.call_allowanceNonStatic( tokenAddress.toHexString(), @@ -260,14 +262,15 @@ void ethCallAllowanceNonStatic() throws Exception { void ethCallAllowanceWithAliasStatic() throws Exception { final var spender = spenderEntityPersistWithAlias(); final var owner = senderEntityPersistWithAlias(); - final var tokenEntity = fungibleTokenPersist(); + final var token = fungibleTokenPersist(); + final var tokenId = token.getTokenId(); var entity = domainBuilder .tokenAllowance() - .customize(a -> a.tokenId(tokenEntity.getTokenId()) + .customize(a -> a.tokenId(tokenId) .owner(owner.getNum()) .spender(spender.getNum())) .persist(); - final var tokenAddress = toAddress(tokenEntity.getTokenId()); + final var tokenAddress = toAddress(tokenId); final var contract = testWeb3jService.deploy(ERCTestContract::deploy); final var result = contract.call_allowance( tokenAddress.toHexString(), SENDER_ALIAS.toHexString(), SPENDER_ALIAS.toHexString()) @@ -282,14 +285,15 @@ void ethCallAllowanceWithAliasStatic() throws Exception { void ethCallAllowanceWithAliasNonStatic() throws Exception { final var spender = spenderEntityPersistWithAlias(); final var owner = senderEntityPersistWithAlias(); - final var tokenEntity = fungibleTokenPersist(); + final var token = fungibleTokenPersist(); + final var tokenId = token.getTokenId(); var entity = domainBuilder .tokenAllowance() - .customize(a -> a.tokenId(tokenEntity.getTokenId()) + .customize(a -> a.tokenId(tokenId) .owner(owner.getNum()) .spender(spender.getNum())) .persist(); - final var tokenAddress = toAddress(tokenEntity.getTokenId()); + final var tokenAddress = toAddress(tokenId); final var contract = testWeb3jService.deploy(ERCTestContract::deploy); final var result = contract.call_allowanceNonStatic( tokenAddress.toHexString(), SENDER_ALIAS.toHexString(), SPENDER_ALIAS.toHexString()) @@ -438,12 +442,13 @@ void ethCallSymbolNonStatic() throws Exception { @Test void ethCallBalanceOfStatic() throws Exception { final var owner = accountPersist(); - final var tokenEntity = fungibleTokenPersistWithTreasuryAccount(owner); + final var token = fungibleTokenPersistWithTreasuryAccount(owner); + final var tokenId = token.getTokenId(); var entity = domainBuilder .tokenAccount() - .customize(e -> e.accountId(owner.getId()).tokenId(tokenEntity.getTokenId())) + .customize(e -> e.accountId(owner.getId()).tokenId(tokenId)) .persist(); - final var tokenAddress = toAddress(tokenEntity.getTokenId()); + final var tokenAddress = toAddress(tokenId); final var contract = testWeb3jService.deploy(ERCTestContract::deploy); final var result = contract.call_balanceOf( tokenAddress.toHexString(), toAddress(owner).toHexString()) @@ -457,12 +462,13 @@ void ethCallBalanceOfStatic() throws Exception { @Test void ethCallBalanceOfNonStatic() throws Exception { final var owner = accountPersist(); - final var tokenEntity = fungibleTokenPersistWithTreasuryAccount(owner); + final var token = fungibleTokenPersistWithTreasuryAccount(owner); + final var tokenId = token.getTokenId(); var entity = domainBuilder .tokenAccount() - .customize(e -> e.accountId(owner.getId()).tokenId(tokenEntity.getTokenId())) + .customize(e -> e.accountId(owner.getId()).tokenId(tokenId)) .persist(); - final var tokenAddress = toAddress(tokenEntity.getTokenId()); + final var tokenAddress = toAddress(tokenId); final var contract = testWeb3jService.deploy(ERCTestContract::deploy); final var result = contract.call_balanceOfNonStatic( tokenAddress.toHexString(), toAddress(owner).toHexString()) @@ -476,12 +482,13 @@ void ethCallBalanceOfNonStatic() throws Exception { @Test void ethCallBalanceOfWithAliasStatic() throws Exception { final var owner = senderEntityPersistWithAlias(); - final var tokenEntity = fungibleTokenPersistWithTreasuryAccount(owner); + final var token = fungibleTokenPersistWithTreasuryAccount(owner); + final var tokenId = token.getTokenId(); var entity = domainBuilder .tokenAccount() - .customize(e -> e.accountId(owner.getId()).tokenId(tokenEntity.getTokenId())) + .customize(e -> e.accountId(owner.getId()).tokenId(tokenId)) .persist(); - final var tokenAddress = toAddress(tokenEntity.getTokenId()); + final var tokenAddress = toAddress(tokenId); final var contract = testWeb3jService.deploy(ERCTestContract::deploy); final var result = contract.call_balanceOf(tokenAddress.toHexString(), SENDER_ALIAS.toHexString()) .send(); @@ -493,12 +500,13 @@ void ethCallBalanceOfWithAliasStatic() throws Exception { @Test void ethCallBalanceOfWithAliasNonStatic() throws Exception { final var owner = senderEntityPersistWithAlias(); - final var tokenEntity = fungibleTokenPersistWithTreasuryAccount(owner); + final var token = fungibleTokenPersistWithTreasuryAccount(owner); + final var tokenId = token.getTokenId(); var entity = domainBuilder .tokenAccount() - .customize(e -> e.accountId(owner.getId()).tokenId(tokenEntity.getTokenId())) + .customize(e -> e.accountId(owner.getId()).tokenId(tokenId)) .persist(); - final var tokenAddress = toAddress(tokenEntity.getTokenId()); + final var tokenAddress = toAddress(tokenId); final var contract = testWeb3jService.deploy(ERCTestContract::deploy); final var result = contract.call_balanceOfNonStatic(tokenAddress.toHexString(), SENDER_ALIAS.toHexString()) .send(); @@ -734,14 +742,15 @@ void ethCallIsApprovedForAllWithAliasRedirect() { void ethCallAllowanceRedirect() { final var owner = accountPersist(); final var spender = accountPersist(); - final var tokenEntity = fungibleTokenPersist(); + final var token = fungibleTokenPersist(); + final var tokenId = token.getTokenId(); domainBuilder .tokenAllowance() - .customize(a -> a.tokenId(tokenEntity.getTokenId()) + .customize(a -> a.tokenId(tokenId) .owner(owner.getNum()) .spender(spender.getNum())) .persist(); - final var tokenAddress = toAddress(tokenEntity.getTokenId()); + final var tokenAddress = toAddress(tokenId); final var contract = testWeb3jService.deploy(RedirectTestContract::deploy); final var functionCall = contract.send_allowanceRedirect( tokenAddress.toHexString(), @@ -754,14 +763,15 @@ void ethCallAllowanceRedirect() { void ethCallAllowanceWithAliasRedirect() { final var spender = spenderEntityPersistWithAlias(); final var owner = senderEntityPersistWithAlias(); - final var tokenEntity = fungibleTokenPersist(); + final var token = fungibleTokenPersist(); + final var tokenId = token.getTokenId(); domainBuilder .tokenAllowance() - .customize(a -> a.tokenId(tokenEntity.getTokenId()) + .customize(a -> a.tokenId(tokenId) .owner(owner.getNum()) .spender(spender.getNum())) .persist(); - final var tokenAddress = toAddress(tokenEntity.getTokenId()); + final var tokenAddress = toAddress(tokenId); final var contract = testWeb3jService.deploy(RedirectTestContract::deploy); final var functionCall = contract.send_allowanceRedirect( tokenAddress.toHexString(), SENDER_ALIAS.toHexString(), SPENDER_ALIAS.toHexString()); @@ -829,12 +839,13 @@ void ethCallSymbolRedirect() { @Test void ethCallBalanceOfRedirect() { final var owner = accountPersist(); - final var tokenEntity = fungibleTokenPersistWithTreasuryAccount(owner); + final var token = fungibleTokenPersistWithTreasuryAccount(owner); + final var tokenId = token.getTokenId(); domainBuilder .tokenAccount() - .customize(e -> e.accountId(owner.getId()).tokenId(tokenEntity.getTokenId())) + .customize(e -> e.accountId(owner.getId()).tokenId(tokenId)) .persist(); - final var tokenAddress = toAddress(tokenEntity.getTokenId()); + final var tokenAddress = toAddress(tokenId); final var contract = testWeb3jService.deploy(RedirectTestContract::deploy); final var functionCall = contract.send_balanceOfRedirect( tokenAddress.toHexString(), toAddress(owner).toHexString()); @@ -844,13 +855,14 @@ void ethCallBalanceOfRedirect() { @Test void ethCallBalanceOfWithAliasRedirect() { final var owner = senderEntityPersistWithAlias(); - final var tokenEntity = fungibleTokenPersistWithTreasuryAccount(owner); + final var token = fungibleTokenPersistWithTreasuryAccount(owner); + final var tokenId = token.getTokenId(); domainBuilder .tokenAccount() - .customize(e -> e.accountId(owner.getId()).tokenId(tokenEntity.getTokenId())) + .customize(e -> e.accountId(owner.getId()).tokenId(tokenId)) .persist(); - final var tokenAddress = toAddress(tokenEntity.getTokenId()); + final var tokenAddress = toAddress(tokenId); final var contract = testWeb3jService.deploy(RedirectTestContract::deploy); final var functionCall = contract.send_balanceOfRedirect(tokenAddress.toHexString(), SENDER_ALIAS.toHexString()); @@ -973,8 +985,8 @@ void decimalsNegativeModularizedServices() throws InvocationTargetException, Ill @Test void ownerOfNegative() { // Given - final var tokenEntity = fungibleTokenPersist(); - final var tokenAddress = toAddress(tokenEntity.getTokenId()); + final var token = fungibleTokenPersist(); + final var tokenAddress = toAddress(token.getTokenId()); final var contract = testWeb3jService.deploy(ERCTestContract::deploy); // When final var functionCall = contract.send_getOwnerOf(tokenAddress.toHexString(), BigInteger.ONE); @@ -985,8 +997,8 @@ void ownerOfNegative() { @Test void tokenURINegative() { // Given - final var tokenEntity = fungibleTokenPersist(); - final var tokenAddress = toAddress(tokenEntity.getTokenId()); + final var token = fungibleTokenPersist(); + final var tokenAddress = toAddress(token.getTokenId()); final var contract = testWeb3jService.deploy(ERCTestContract::deploy); // When final var functionCall = contract.send_tokenURI(tokenAddress.toHexString(), BigInteger.ONE); @@ -1017,8 +1029,8 @@ void decimalsNegativeRedirect() { @Test void ownerOfNegativeRedirect() { // Given - final var tokenEntity = fungibleTokenPersist(); - final var tokenAddress = toAddress(tokenEntity.getTokenId()); + final var token = fungibleTokenPersist(); + final var tokenAddress = toAddress(token.getTokenId()); final var contract = testWeb3jService.deploy(RedirectTestContract::deploy); // When final var functionCall = contract.send_getOwnerOfRedirect(tokenAddress.toHexString(), BigInteger.ONE); @@ -1037,8 +1049,8 @@ void ownerOfNegativeRedirect() { @Test void tokenURINegativeRedirect() { // Given - final var tokenEntity = fungibleTokenPersist(); - final var tokenAddress = toAddress(tokenEntity.getTokenId()); + final var token = fungibleTokenPersist(); + final var tokenAddress = toAddress(token.getTokenId()); final var contract = testWeb3jService.deploy(RedirectTestContract::deploy); // When final var functionCall = contract.send_tokenURIRedirect(tokenAddress.toHexString(), BigInteger.ONE); 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 5a7907a0595..b94de4d7bf0 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 @@ -112,19 +112,20 @@ void transferFrom() throws Exception { void approve(final BigInteger allowance) throws Exception { // Given final var spender = accountEntityPersist(); - final var tokenEntity = fungibleTokenPersist(); + final var token = fungibleTokenPersist(); + final var tokenId = token.getTokenId(); - tokenAccountPersist(tokenEntity.getTokenId(), spender.getId()); + tokenAccountPersist(token.getTokenId(), spender.getId()); final var contract = testWeb3jService.deploy(ModificationPrecompileTestContract::deploy); final var contractAddress = Address.fromHexString(contract.getContractAddress()); final var contractEntityId = entityIdFromEvmAddress(contractAddress); - tokenAccount(ta -> ta.tokenId(tokenEntity.getTokenId()).accountId(contractEntityId.getId())); + tokenAccount(ta -> ta.tokenId(tokenId).accountId(contractEntityId.getId())); // When final var functionCall = contract.call_approveExternal( - asHexedEvmAddress(tokenEntity.getTokenId()), getAddressFromEntity(spender), allowance); + asHexedEvmAddress(tokenId), getAddressFromEntity(spender), allowance); // Then verifyEthCallAndEstimateGas(functionCall, contract, ZERO_VALUE); @@ -141,7 +142,7 @@ void approveNFT(final Boolean approve) throws Exception { final var tokenEntity = tokenEntityPersist(); final var tokenId = tokenEntity.getId(); - Token token = nonFungibleTokenPersist(tokenEntity); + var token = nonFungibleTokenPersist(tokenEntity); tokenAccountPersist(tokenId, owner.getId()); tokenAccountPersist(tokenId, spender.getId()); @@ -566,14 +567,15 @@ void deleteToken() throws Exception { void freezeToken() throws Exception { // Given final var accountWithoutFreeze = accountEntityWithEvmAddressPersist(); - final var tokenEntity = fungibleTokenPersist(); - tokenAccountPersist(tokenEntity.getTokenId(), accountWithoutFreeze.getId()); + final var token = fungibleTokenPersist(); + final var tokenId = token.getTokenId(); + tokenAccountPersist(tokenId, accountWithoutFreeze.getId()); final var contract = testWeb3jService.deploy(ModificationPrecompileTestContract::deploy); // When final var functionCall = contract.call_freezeTokenExternal( - asHexedEvmAddress(tokenEntity.getTokenId()), getAliasFromEntity(accountWithoutFreeze)); + asHexedEvmAddress(tokenId), getAliasFromEntity(accountWithoutFreeze)); // Then verifyEthCallAndEstimateGas(functionCall, contract, ZERO_VALUE); @@ -585,11 +587,12 @@ void unfreezeToken() throws Exception { // Given final var accountWithFreeze = accountEntityWithEvmAddressPersist(); - final var tokenEntity = fungibleTokenPersist(); + final var token = fungibleTokenPersist(); + final var tokenId = token.getTokenId(); domainBuilder .tokenAccount() - .customize(ta -> ta.tokenId(tokenEntity.getTokenId()) + .customize(ta -> ta.tokenId(tokenId) .accountId(accountWithFreeze.getId()) .kycStatus(TokenKycStatusEnum.GRANTED) .freezeStatus(TokenFreezeStatusEnum.FROZEN) @@ -601,7 +604,7 @@ void unfreezeToken() throws Exception { // When final var functionCall = contract.call_unfreezeTokenExternal( - asHexedEvmAddress(tokenEntity.getTokenId()), getAliasFromEntity(accountWithFreeze)); + asHexedEvmAddress(tokenId), getAliasFromEntity(accountWithFreeze)); // Then verifyEthCallAndEstimateGas(functionCall, contract, ZERO_VALUE); @@ -1139,7 +1142,7 @@ void transferNft(final String type) throws Exception { accountBalanceRecordsPersist(sender); - Token token = nonFungibleTokenPersist(tokenEntity, treasuryAccount); + var token = nonFungibleTokenPersist(tokenEntity, treasuryAccount); domainBuilder .nft() 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 84042aa6e25..e1281e26093 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 @@ -208,14 +208,14 @@ void isKycGrantedWithAlias() throws Exception { .alias(SENDER_PUBLIC_KEY.toByteArray()) .evmAddress(SENDER_ALIAS.toArray())) .persist(); - final var tokenEntity = fungibleTokenPersist(); - tokenAccountPersist(tokenEntity.getTokenId(), account.getId()); + final var token = fungibleTokenPersist(); + tokenAccountPersist(token.getTokenId(), account.getId()); final var contract = testWeb3jService.deploy(PrecompileTestContract::deploy); // When final var functionCall = - contract.call_isKycGranted(asHexedEvmAddress(tokenEntity.getTokenId()), getAliasFromEntity(account)); + contract.call_isKycGranted(asHexedEvmAddress(token.getTokenId()), getAliasFromEntity(account)); // Then assertThat(functionCall.send()).isTrue(); @@ -269,12 +269,12 @@ void isKycGrantedForNFTWithAlias() throws Exception { @Test void isTokenAddress() throws Exception { // Given - final var tokenEntity = fungibleTokenPersist(); + final var token = fungibleTokenPersist(); final var contract = testWeb3jService.deploy(PrecompileTestContract::deploy); // When - final var functionCall = contract.call_isTokenAddress(asHexedEvmAddress(tokenEntity.getTokenId())); + final var functionCall = contract.call_isTokenAddress(asHexedEvmAddress(token.getTokenId())); // Then assertThat(functionCall.send()).isTrue(); @@ -350,12 +350,12 @@ void getDefaultKycNFT() throws Exception { @Test void getTokenType() throws Exception { // Given - final var tokenEntity = fungibleTokenPersist(); + final var token = fungibleTokenPersist(); final var contract = testWeb3jService.deploy(PrecompileTestContract::deploy); // When - final var functionCall = contract.call_getType(asHexedEvmAddress(tokenEntity.getTokenId())); + final var functionCall = contract.call_getType(asHexedEvmAddress(token.getTokenId())); // Then assertThat(functionCall.send()).isEqualTo(BigInteger.ZERO); @@ -505,8 +505,8 @@ void getTokenKey(final TokenTypeEnum tokenType, final KeyValueType keyValueType, void getCustomFeesForTokenWithFixedFee() throws Exception { // Given final var collectorAccount = accountEntityWithEvmAddressPersist(); - final var tokenEntity = fungibleTokenPersist(); - final var tokenId = tokenEntity.getTokenId(); + final var token = fungibleTokenPersist(); + final var tokenId = token.getTokenId(); final var entityId = EntityId.of(tokenId); final var fixedFee = com.hedera.mirror.common.domain.token.FixedFee.builder() .amount(100L) @@ -545,7 +545,8 @@ void getCustomFeesForTokenWithFixedFee() throws Exception { void getCustomFeesForTokenWithFractionalFee() throws Exception { // Given final var collectorAccount = accountEntityWithEvmAddressPersist(); - final var tokenEntity = fungibleTokenPersist(); + final var token = fungibleTokenPersist(); + final var tokenId = token.getTokenId(); final var fractionalFee = FractionalFee.builder() .collectorAccountId(collectorAccount.toEntityId()) .denominator(10L) @@ -556,7 +557,7 @@ void getCustomFeesForTokenWithFractionalFee() throws Exception { .build(); domainBuilder .customFee() - .customize(f -> f.entityId(tokenEntity.getTokenId()) + .customize(f -> f.entityId(tokenId) .fractionalFees(List.of(fractionalFee)) .fixedFees(List.of()) .royaltyFees(List.of())) @@ -565,7 +566,7 @@ void getCustomFeesForTokenWithFractionalFee() throws Exception { final var contract = testWeb3jService.deploy(PrecompileTestContract::deploy); // When - final var functionCall = contract.call_getCustomFeesForToken(asHexedEvmAddress(tokenEntity.getTokenId())); + final var functionCall = contract.call_getCustomFeesForToken(asHexedEvmAddress(tokenId)); final var expectedFee = new PrecompileTestContract.FractionalFee( BigInteger.valueOf(100L), @@ -587,8 +588,8 @@ void getCustomFeesForTokenWithFractionalFee() throws Exception { void getCustomFeesForTokenWithRoyaltyFee() throws Exception { // Given final var collectorAccount = accountEntityWithEvmAddressPersist(); - final var tokenEntity = fungibleTokenPersist(); - final var tokenId = tokenEntity.getTokenId(); + final var token = fungibleTokenPersist(); + final var tokenId = token.getTokenId(); final var entityId = EntityId.of(tokenId); final var royaltyFee = RoyaltyFee.builder() @@ -671,11 +672,12 @@ void getAllowanceForToken() throws Exception { final var amountGranted = 50L; final var owner = accountEntityWithEvmAddressPersist(); final var spender = accountEntityWithEvmAddressPersist(); - final var tokenEntity = fungibleTokenPersist(); + final var token = fungibleTokenPersist(); + final var tokenId = token.getTokenId(); domainBuilder .tokenAllowance() - .customize(a -> a.tokenId(tokenEntity.getTokenId()) + .customize(a -> a.tokenId(tokenId) .owner(owner.getNum()) .spender(spender.getNum()) .amount(amountGranted) @@ -686,7 +688,7 @@ void getAllowanceForToken() throws Exception { // When final var functionCall = contract.call_htsAllowance( - asHexedEvmAddress(tokenEntity.getTokenId()), getAliasFromEntity(owner), getAliasFromEntity(spender)); + asHexedEvmAddress(tokenId), getAliasFromEntity(owner), getAliasFromEntity(spender)); // Then assertThat(functionCall.send()).isEqualTo(BigInteger.valueOf(amountGranted)); diff --git a/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/OpcodeServiceTest.java b/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/OpcodeServiceTest.java index 68fb86352a9..c9e18a4238f 100644 --- a/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/OpcodeServiceTest.java +++ b/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/OpcodeServiceTest.java @@ -113,9 +113,9 @@ class OpcodeServiceTest extends AbstractContractCallServiceOpcodeTracerTest { """) void updateTokenKeysAndGetUpdatedTokenKeyForFungibleToken(final KeyValueType keyValueType, final KeyType keyType) { // Given - final var tokenEntity = fungibleTokenPersistWithTreasuryAccount( + final var token = fungibleTokenPersistWithTreasuryAccount( domainBuilder.entity().persist().toEntityId()); - final var tokenAddress = toAddress(tokenEntity.getTokenId()); + final var tokenAddress = toAddress(token.getTokenId()); final var contract = testWeb3jService.deploy(NestedCalls::deploy); final var contractAddress = contract.getContractAddress(); From 4440cbe48aece50f514ca5327326ddc44dafe5f6 Mon Sep 17 00:00:00 2001 From: filev94 Date: Wed, 12 Feb 2025 17:21:35 +0200 Subject: [PATCH 12/13] spotlessApply Signed-off-by: filev94 --- ...viceERCTokenModificationFunctionsTest.java | 6 ++--- ...lServiceERCTokenReadOnlyFunctionsTest.java | 24 +++++-------------- ...CallServicePrecompileModificationTest.java | 12 +++++----- 3 files changed, 14 insertions(+), 28 deletions(-) diff --git a/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallServiceERCTokenModificationFunctionsTest.java b/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallServiceERCTokenModificationFunctionsTest.java index 286b0c0b02d..46f82d438cd 100644 --- a/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallServiceERCTokenModificationFunctionsTest.java +++ b/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallServiceERCTokenModificationFunctionsTest.java @@ -243,8 +243,7 @@ void transferFrom() { final var contractEntityId = entityIdFromEvmAddress(contractAddress); tokenAssociateAccountPersist(contractEntityId, tokenEntity); final var amount = 10L; - fungibleTokenAllowancePersist( - contractEntityId, owner, entityIdFromEvmAddress(toAddress(tokenId)), amount); + fungibleTokenAllowancePersist(contractEntityId, owner, entityIdFromEvmAddress(toAddress(tokenId)), amount); // When final var functionCall = contract.send_transferFrom( toAddress(tokenId).toHexString(), @@ -661,8 +660,7 @@ void transferFromWithAliasRedirect() { final var contractEntityId = entityIdFromEvmAddress(contractAddress); tokenAssociateAccountPersist(contractEntityId, tokenEntity); final var amount = 10L; - fungibleTokenAllowancePersist( - contractEntityId, owner, entityIdFromEvmAddress(toAddress(tokenId)), amount); + fungibleTokenAllowancePersist(contractEntityId, owner, entityIdFromEvmAddress(toAddress(tokenId)), amount); // When final var functionCall = contract.send_transferFromRedirect( toAddress(tokenId).toHexString(), 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 83d40bc7772..7560534da9b 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 @@ -212,9 +212,7 @@ void ethCallAllowanceStatic() throws Exception { final var tokenId = token.getTokenId(); var entity = domainBuilder .tokenAllowance() - .customize(a -> a.tokenId(tokenId) - .owner(owner.getNum()) - .spender(spender.getNum())) + .customize(a -> a.tokenId(tokenId).owner(owner.getNum()).spender(spender.getNum())) .persist(); final var tokenAddress = toAddress(tokenId); final var contract = testWeb3jService.deploy(ERCTestContract::deploy); @@ -239,9 +237,7 @@ void ethCallAllowanceNonStatic() throws Exception { final var tokenId = token.getTokenId(); var entity = domainBuilder .tokenAllowance() - .customize(a -> a.tokenId(tokenId) - .owner(owner.getNum()) - .spender(spender.getNum())) + .customize(a -> a.tokenId(tokenId).owner(owner.getNum()).spender(spender.getNum())) .persist(); final var tokenAddress = toAddress(tokenId); final var contract = testWeb3jService.deploy(ERCTestContract::deploy); @@ -266,9 +262,7 @@ void ethCallAllowanceWithAliasStatic() throws Exception { final var tokenId = token.getTokenId(); var entity = domainBuilder .tokenAllowance() - .customize(a -> a.tokenId(tokenId) - .owner(owner.getNum()) - .spender(spender.getNum())) + .customize(a -> a.tokenId(tokenId).owner(owner.getNum()).spender(spender.getNum())) .persist(); final var tokenAddress = toAddress(tokenId); final var contract = testWeb3jService.deploy(ERCTestContract::deploy); @@ -289,9 +283,7 @@ void ethCallAllowanceWithAliasNonStatic() throws Exception { final var tokenId = token.getTokenId(); var entity = domainBuilder .tokenAllowance() - .customize(a -> a.tokenId(tokenId) - .owner(owner.getNum()) - .spender(spender.getNum())) + .customize(a -> a.tokenId(tokenId).owner(owner.getNum()).spender(spender.getNum())) .persist(); final var tokenAddress = toAddress(tokenId); final var contract = testWeb3jService.deploy(ERCTestContract::deploy); @@ -746,9 +738,7 @@ void ethCallAllowanceRedirect() { final var tokenId = token.getTokenId(); domainBuilder .tokenAllowance() - .customize(a -> a.tokenId(tokenId) - .owner(owner.getNum()) - .spender(spender.getNum())) + .customize(a -> a.tokenId(tokenId).owner(owner.getNum()).spender(spender.getNum())) .persist(); final var tokenAddress = toAddress(tokenId); final var contract = testWeb3jService.deploy(RedirectTestContract::deploy); @@ -767,9 +757,7 @@ void ethCallAllowanceWithAliasRedirect() { final var tokenId = token.getTokenId(); domainBuilder .tokenAllowance() - .customize(a -> a.tokenId(tokenId) - .owner(owner.getNum()) - .spender(spender.getNum())) + .customize(a -> a.tokenId(tokenId).owner(owner.getNum()).spender(spender.getNum())) .persist(); final var tokenAddress = toAddress(tokenId); final var contract = testWeb3jService.deploy(RedirectTestContract::deploy); 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 b94de4d7bf0..93e435f665a 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 @@ -124,8 +124,8 @@ void approve(final BigInteger allowance) throws Exception { tokenAccount(ta -> ta.tokenId(tokenId).accountId(contractEntityId.getId())); // When - final var functionCall = contract.call_approveExternal( - asHexedEvmAddress(tokenId), getAddressFromEntity(spender), allowance); + final var functionCall = + contract.call_approveExternal(asHexedEvmAddress(tokenId), getAddressFromEntity(spender), allowance); // Then verifyEthCallAndEstimateGas(functionCall, contract, ZERO_VALUE); @@ -574,8 +574,8 @@ void freezeToken() throws Exception { final var contract = testWeb3jService.deploy(ModificationPrecompileTestContract::deploy); // When - final var functionCall = contract.call_freezeTokenExternal( - asHexedEvmAddress(tokenId), getAliasFromEntity(accountWithoutFreeze)); + final var functionCall = + contract.call_freezeTokenExternal(asHexedEvmAddress(tokenId), getAliasFromEntity(accountWithoutFreeze)); // Then verifyEthCallAndEstimateGas(functionCall, contract, ZERO_VALUE); @@ -603,8 +603,8 @@ void unfreezeToken() throws Exception { final var contract = testWeb3jService.deploy(ModificationPrecompileTestContract::deploy); // When - final var functionCall = contract.call_unfreezeTokenExternal( - asHexedEvmAddress(tokenId), getAliasFromEntity(accountWithFreeze)); + final var functionCall = + contract.call_unfreezeTokenExternal(asHexedEvmAddress(tokenId), getAliasFromEntity(accountWithFreeze)); // Then verifyEthCallAndEstimateGas(functionCall, contract, ZERO_VALUE); From a1ec0bd7302416831f316951fd49076a1bd4c6cb Mon Sep 17 00:00:00 2001 From: filev94 Date: Thu, 13 Feb 2025 11:14:29 +0200 Subject: [PATCH 13/13] spotlessApply + refactoring Signed-off-by: filev94 --- .../service/ContractCallDynamicCallsTest.java | 12 ++++++------ ...ctCallServicePrecompileModificationTest.java | 17 +++++++++-------- ...ntractCallServicePrecompileReadonlyTest.java | 12 ++++++------ 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallDynamicCallsTest.java b/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallDynamicCallsTest.java index 24dafacc4d0..5ad341980c3 100644 --- a/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallDynamicCallsTest.java +++ b/hedera-mirror-web3/src/test/java/com/hedera/mirror/web3/service/ContractCallDynamicCallsTest.java @@ -338,9 +338,9 @@ void approveTokenGetAllowance(final TokenTypeEnum tokenType, final long amount, final var token = tokenType == TokenTypeEnum.FUNGIBLE_COMMON ? fungibleTokenPersistWithTreasuryAccount(treasuryEntityId) : nftPersist(treasuryEntityId, ownerEntityId, spenderEntityId); - final var tokenAddress = toAddress(token.getTokenId()); final var tokenId = token.getTokenId(); - final var tokenEntityId = entityIdFromEvmAddress(toAddress(token.getTokenId())); + final var tokenAddress = toAddress(tokenId); + final var tokenEntityId = entityIdFromEvmAddress(toAddress(tokenId)); final var contract = testWeb3jService.deploy(DynamicEthCalls::deploy); final var contractAddress = Address.fromHexString(contract.getContractAddress()); @@ -388,9 +388,9 @@ void approveTokenTransferFromGetAllowanceGetBalance( final var token = tokenType == TokenTypeEnum.FUNGIBLE_COMMON ? fungibleTokenPersistWithTreasuryAccount(treasuryEntityId) : nftPersist(treasuryEntityId, contractEntityId, spenderEntityId); - final var tokenAddress = toAddress(token.getTokenId()); - final var tokenEntityId = entityIdFromEvmAddress(tokenAddress); final var tokenId = token.getTokenId(); + final var tokenAddress = toAddress(tokenId); + final var tokenEntityId = entityIdFromEvmAddress(tokenAddress); tokenAccountPersist(tokenId, contractEntityId.getId()); tokenAccountPersist(tokenId, spenderEntityId.getId()); @@ -515,8 +515,8 @@ void approveForAllTokenTransferFromGetAllowance() { final var contractEntityId = entityIdFromEvmAddress(contractAddress); final var tokenEntity = nftPersist(treasuryEntityId, spenderEntityId); - final var tokenAddress = toAddress(tokenEntity.getTokenId()); final var tokenId = tokenEntity.getTokenId(); + final var tokenAddress = toAddress(tokenId); tokenAccountPersist(tokenId, spenderEntityId.getId()); tokenAccountPersist(tokenId, contractEntityId.getId()); @@ -541,8 +541,8 @@ void approveForAllCryptoTransferGetAllowance() { final var contractEntityId = entityIdFromEvmAddress(contractAddress); final var tokenEntity = nftPersist(treasuryEntityId, spenderEntityId); - final var tokenAddress = toAddress(tokenEntity.getTokenId()); final var tokenId = tokenEntity.getTokenId(); + final var tokenAddress = toAddress(tokenId); tokenAccountPersist(tokenId, spenderEntityId.getId()); tokenAccountPersist(tokenId, contractEntityId.getId()); 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 93e435f665a..d41c2f53270 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 @@ -366,13 +366,13 @@ void burnFungibleToken() throws Exception { // Given final var treasuryAccount = accountEntityPersist(); final var token = fungibleTokenPersistWithTreasuryAccount(treasuryAccount.toEntityId()); - tokenAccountPersist(token.getTokenId(), treasuryAccount.getId()); + final var tokenId = token.getTokenId(); + tokenAccountPersist(tokenId, treasuryAccount.getId()); final var sender = accountEntityPersist(); accountBalanceRecordsPersist(sender); - tokenBalancePersist( - treasuryAccount.toEntityId(), EntityId.of(token.getTokenId()), treasuryAccount.getBalanceTimestamp()); + tokenBalancePersist(treasuryAccount.toEntityId(), EntityId.of(tokenId), treasuryAccount.getBalanceTimestamp()); testWeb3jService.setSender(getAddressFromEntity(sender)); @@ -381,8 +381,8 @@ void burnFungibleToken() throws Exception { final var contract = testWeb3jService.deploy(ModificationPrecompileTestContract::deploy); // When - final var functionCall = contract.call_burnTokenExternal( - asHexedEvmAddress(token.getTokenId()), BigInteger.valueOf(4), new ArrayList<>()); + final var functionCall = + contract.call_burnTokenExternal(asHexedEvmAddress(tokenId), BigInteger.valueOf(4), new ArrayList<>()); final var result = functionCall.send(); @@ -844,16 +844,17 @@ void create2ContractAndTransferFromIt() throws Exception { // Given final var receiver = accountEntityWithEvmAddressPersist(); final var token = fungibleTokenPersist(); + final var tokenId = token.getTokenId(); final var sponsor = accountEntityWithEvmAddressPersist(); - tokenBalancePersist(sponsor.toEntityId(), EntityId.of(token.getTokenId()), sponsor.getCreatedTimestamp()); + tokenBalancePersist(sponsor.toEntityId(), EntityId.of(tokenId), sponsor.getCreatedTimestamp()); accountBalanceRecordsPersist(sponsor); - tokenAccountPersist(token.getTokenId(), sponsor.getId()); + tokenAccountPersist(tokenId, sponsor.getId()); final var contract = testWeb3jService.deploy(ModificationPrecompileTestContract::deploy); // When final var functionCall = contract.call_createContractViaCreate2AndTransferFromIt( - asHexedEvmAddress(token.getTokenId()), + asHexedEvmAddress(tokenId), getAliasFromEntity(sponsor), getAliasFromEntity(receiver), BigInteger.valueOf(10L)); 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 e1281e26093..7ce7d6b009f 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 @@ -186,13 +186,13 @@ void isKycGranted() throws Exception { // Given final var account = accountEntityPersist(); final var token = fungibleTokenPersist(); - tokenAccountPersist(token.getTokenId(), account.getId()); + final var tokenId = token.getTokenId(); + tokenAccountPersist(tokenId, account.getId()); final var contract = testWeb3jService.deploy(PrecompileTestContract::deploy); // When - final var functionCall = - contract.call_isKycGranted(asHexedEvmAddress(token.getTokenId()), getAddressFromEntity(account)); + final var functionCall = contract.call_isKycGranted(asHexedEvmAddress(tokenId), getAddressFromEntity(account)); // Then assertThat(functionCall.send()).isTrue(); @@ -209,13 +209,13 @@ void isKycGrantedWithAlias() throws Exception { .evmAddress(SENDER_ALIAS.toArray())) .persist(); final var token = fungibleTokenPersist(); - tokenAccountPersist(token.getTokenId(), account.getId()); + final var tokenId = token.getTokenId(); + tokenAccountPersist(tokenId, account.getId()); final var contract = testWeb3jService.deploy(PrecompileTestContract::deploy); // When - final var functionCall = - contract.call_isKycGranted(asHexedEvmAddress(token.getTokenId()), getAliasFromEntity(account)); + final var functionCall = contract.call_isKycGranted(asHexedEvmAddress(tokenId), getAliasFromEntity(account)); // Then assertThat(functionCall.send()).isTrue();