Skip to content

Commit

Permalink
Fix contract call ERC modification approve tests (#10210)
Browse files Browse the repository at this point in the history
Fix the approve* tests in ERC test suite. Also, a slight refactoring was made - extract common hollow account creation logic in a separate method.

---------

Signed-off-by: Bilyana Gospodinova <[email protected]>
  • Loading branch information
bilyana-gospodinova authored Jan 23, 2025
1 parent 22a0e91 commit c619b9d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.protobuf.ByteString;
import com.hedera.mirror.common.domain.entity.Entity;
import com.hedera.mirror.common.domain.entity.EntityId;
import com.hedera.mirror.common.domain.token.Token;
import com.hedera.mirror.common.domain.token.TokenKycStatusEnum;
Expand Down Expand Up @@ -100,7 +101,7 @@ void approveNFT() {
final var tokenAddress = toAddress(token.getTokenId());
tokenAssociateAccountPersist(contractEntityId, entityIdFromEvmAddress(tokenAddress));
// When
final var functionCall = contract.send_approve(
final var functionCall = contract.send_approveNFT(
tokenAddress.toHexString(), toAddress(spender).toHexString(), BigInteger.ONE);
// Then
verifyEthCallAndEstimateGas(functionCall, contract);
Expand All @@ -118,7 +119,7 @@ void deleteAllowanceNFT() {
tokenAssociateAccountPersist(contractEntityId, entityIdFromEvmAddress(tokenAddress));
// When
final var functionCall =
contract.send_approve(tokenAddress.toHexString(), Address.ZERO.toHexString(), BigInteger.ONE);
contract.send_approveNFT(tokenAddress.toHexString(), Address.ZERO.toHexString(), BigInteger.ONE);
// Then
verifyEthCallAndEstimateGas(functionCall, contract);
}
Expand Down Expand Up @@ -192,7 +193,7 @@ void approveNFTWithAlias() {
final var tokenAddress = toAddress(token.getTokenId());
tokenAssociateAccountPersist(contractEntityId, entityIdFromEvmAddress(tokenAddress));
// When
final var functionCall = contract.send_approve(
final var functionCall = contract.send_approveNFT(
tokenAddress.toHexString(), SPENDER_ALIAS.toHexString(), BigInteger.valueOf(serialNo));
// Then
verifyEthCallAndEstimateGas(functionCall, contract);
Expand Down Expand Up @@ -253,29 +254,23 @@ void transferFrom() {
@Test
void transferFromToHollowAccount() {
// Given
final var treasury = accountEntityPersist().toEntityId();
final var owner = accountEntityPersist().toEntityId();
final var token = domainBuilder.entity().customize(e -> e.type(TOKEN)).persist();

domainBuilder
.token()
.customize(t -> t.tokenId(token.getId())
.type(TokenTypeEnum.FUNGIBLE_COMMON)
.treasuryAccountId(treasury)
.kycKey(new byte[0]))
.persist();

tokenAssociateAccountPersist(owner, token.toEntityId());

final var hollowAccount = domainBuilder
.entity()
.customize(e -> e.key(null).maxAutomaticTokenAssociations(10).receiverSigRequired(false))
.persist();

final var hollowAccount = hollowAccountPersist();
final var contract = testWeb3jService.deploy(ERCTestContract::deploy);
final var contractAddress = Address.fromHexString(contract.getContractAddress());
final var contractEntityId = entityIdFromEvmAddress(contractAddress);
tokenAssociateAccountPersist(contractEntityId, token.toEntityId());
tokenAssociateAccountPersist(hollowAccount.toEntityId(), token.toEntityId());
tokenAssociateAccountPersist(owner, token.toEntityId());

final var amount = 10L;
fungibleTokenAllowancePersist(contractEntityId, owner, token.toEntityId(), amount);
Expand Down Expand Up @@ -561,11 +556,7 @@ void transferFromToHollowAccountRedirect() {

tokenAssociateAccountPersist(owner, entityIdFromEvmAddress(toAddress(tokenEntity.getId())));

final var hollowAccount = domainBuilder
.entity()
.customize(e -> e.key(null).maxAutomaticTokenAssociations(10).receiverSigRequired(false))
.persist();

final var hollowAccount = hollowAccountPersist();
final var contract = testWeb3jService.deploy(RedirectTestContract::deploy);
final var contractAddress = Address.fromHexString(contract.getContractAddress());
final var contractEntityId = entityIdFromEvmAddress(contractAddress);
Expand Down Expand Up @@ -720,6 +711,13 @@ private EntityId accountPersistWithAlias(final Address alias, final ByteString p
.toEntityId();
}

private Entity hollowAccountPersist() {
return domainBuilder
.entity()
.customize(e -> e.key(null).maxAutomaticTokenAssociations(10).receiverSigRequired(false))
.persist();
}

private Token fungibleTokenPersist(final EntityId treasuryEntityId) {
final var tokenEntity =
domainBuilder.entity().customize(e -> e.type(TOKEN)).persist();
Expand Down
4 changes: 4 additions & 0 deletions hedera-mirror-web3/src/test/solidity/ERCTestContract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ contract ERCTestContract {
IERC20(token).approve(spender, amount);
}

function approveNFT(address token, address spender, uint256 tokenId) public {
IERC721(token).approve(spender, tokenId);
}

function transferFromNFT(address token, address from, address to, uint256 tokenId) public {
IERC721(token).transferFrom(from, to, tokenId);
}
Expand Down

0 comments on commit c619b9d

Please sign in to comment.