Skip to content

Commit

Permalink
Fix ContractCallServiceERCTokenReadOnlyFunctionsTest for modularized (#…
Browse files Browse the repository at this point in the history
…10068)

This PR fixes the 17 failing tests when run against modularized in ContractCallServiceERCTokenReadOnlyFunctionsTest.

Few negative test have different behaviours where we need to be checking the flag to assert the proper error. Described and discussed here -> hashgraph/hedera-services#17245

If we try to mimic modularized behaviour we might introduce some breaking changes since we are still using the mono code.
For now I'm asserting the differences based on which flag is up.

---------

Signed-off-by: Kristiyan Selveliev <[email protected]>
  • Loading branch information
kselveliev authored Jan 9, 2025
1 parent bfc9183 commit 876290c
Showing 1 changed file with 53 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import static com.hedera.mirror.web3.utils.ContractCallTestUtil.SENDER_PUBLIC_KEY;
import static com.hedera.mirror.web3.utils.ContractCallTestUtil.SPENDER_ALIAS;
import static com.hedera.mirror.web3.utils.ContractCallTestUtil.SPENDER_PUBLIC_KEY;
import static com.hederahashgraph.api.proto.java.ResponseCodeEnum.CONTRACT_REVERT_EXECUTED;
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;
Expand Down Expand Up @@ -593,23 +594,33 @@ void ethCallGetOwnerOfStaticEmptyOwner() throws Exception {
final var tokenEntity = nftPersist();
final var tokenAddress = toAddress(tokenEntity.getTokenId());
final var contract = testWeb3jService.deploy(ERCTestContract::deploy);
final var result = contract.call_getOwnerOf(tokenAddress.toHexString(), BigInteger.valueOf(1))
.send();
final var functionCall = contract.send_getOwnerOf(tokenAddress.toHexString(), BigInteger.valueOf(1));
assertThat(result).isEqualTo(Address.ZERO.toHexString());
verifyEthCallAndEstimateGas(functionCall, contract);
if (mirrorNodeEvmProperties.isModularizedServices()) {
verifyEstimateGasRevertExecution(
functionCall, CONTRACT_REVERT_EXECUTED.name(), MirrorEvmTransactionException.class);
} else {
final var result = contract.call_getOwnerOf(tokenAddress.toHexString(), BigInteger.valueOf(1))
.send();
assertThat(result).isEqualTo(Address.ZERO.toHexString());
verifyEthCallAndEstimateGas(functionCall, contract);
}
}

@Test
void ethCallGetOwnerOfStaticEmptyOwnerNonStatic() throws Exception {
final var tokenEntity = nftPersist();
final var tokenAddress = toAddress(tokenEntity.getTokenId());
final var contract = testWeb3jService.deploy(ERCTestContract::deploy);
final var result = contract.call_getOwnerOfNonStatic(tokenAddress.toHexString(), BigInteger.valueOf(1))
.send();
final var functionCall = contract.send_getOwnerOfNonStatic(tokenAddress.toHexString(), BigInteger.valueOf(1));
assertThat(result).isEqualTo(Address.ZERO.toHexString());
verifyEthCallAndEstimateGas(functionCall, contract);
if (mirrorNodeEvmProperties.isModularizedServices()) {
verifyEstimateGasRevertExecution(
functionCall, CONTRACT_REVERT_EXECUTED.name(), MirrorEvmTransactionException.class);
} else {
final var result = contract.call_getOwnerOfNonStatic(tokenAddress.toHexString(), BigInteger.valueOf(1))
.send();
assertThat(result).isEqualTo(Address.ZERO.toHexString());
verifyEthCallAndEstimateGas(functionCall, contract);
}
}

@Test
Expand Down Expand Up @@ -907,7 +918,12 @@ void ethCallGetOwnerOfEmptyOwnerRedirect() {
final var tokenAddress = toAddress(tokenEntity.getTokenId());
final var contract = testWeb3jService.deploy(RedirectTestContract::deploy);
final var functionCall = contract.send_getOwnerOfRedirect(tokenAddress.toHexString(), BigInteger.valueOf(1));
verifyEthCallAndEstimateGas(functionCall, contract);
if (mirrorNodeEvmProperties.isModularizedServices()) {
verifyEstimateGasRevertExecution(
functionCall, CONTRACT_REVERT_EXECUTED.name(), MirrorEvmTransactionException.class);
} else {
verifyEthCallAndEstimateGas(functionCall, contract);
}
}

@Test
Expand Down Expand Up @@ -982,9 +998,15 @@ void decimalsNegativeRedirect() {
// When
final var functionCall = contract.send_decimalsRedirect(tokenAddress.toHexString());
// Then
assertThatThrownBy(functionCall::send)
.isInstanceOf(MirrorEvmTransactionException.class)
.hasMessage(INVALID_TOKEN_ID.name());
if (mirrorNodeEvmProperties.isModularizedServices()) {
assertThatThrownBy(functionCall::send)
.isInstanceOf(MirrorEvmTransactionException.class)
.hasMessage(CONTRACT_REVERT_EXECUTED.name());
} else {
assertThatThrownBy(functionCall::send)
.isInstanceOf(MirrorEvmTransactionException.class)
.hasMessage(INVALID_TOKEN_ID.name());
}
}

@Test
Expand All @@ -996,9 +1018,15 @@ void ownerOfNegativeRedirect() {
// When
final var functionCall = contract.send_getOwnerOfRedirect(tokenAddress.toHexString(), BigInteger.ONE);
// Then
assertThatThrownBy(functionCall::send)
.isInstanceOf(MirrorEvmTransactionException.class)
.hasMessage(INVALID_TOKEN_ID.name());
if (mirrorNodeEvmProperties.isModularizedServices()) {
assertThatThrownBy(functionCall::send)
.isInstanceOf(MirrorEvmTransactionException.class)
.hasMessage(CONTRACT_REVERT_EXECUTED.name());
} else {
assertThatThrownBy(functionCall::send)
.isInstanceOf(MirrorEvmTransactionException.class)
.hasMessage(INVALID_TOKEN_ID.name());
}
}

@Test
Expand All @@ -1010,9 +1038,15 @@ void tokenURINegativeRedirect() {
// When
final var functionCall = contract.send_tokenURIRedirect(tokenAddress.toHexString(), BigInteger.ONE);
// Then
assertThatThrownBy(functionCall::send)
.isInstanceOf(MirrorEvmTransactionException.class)
.hasMessage(INVALID_TOKEN_ID.name());
if (mirrorNodeEvmProperties.isModularizedServices()) {
assertThatThrownBy(functionCall::send)
.isInstanceOf(MirrorEvmTransactionException.class)
.hasMessage(CONTRACT_REVERT_EXECUTED.name());
} else {
assertThatThrownBy(functionCall::send)
.isInstanceOf(MirrorEvmTransactionException.class)
.hasMessage(INVALID_TOKEN_ID.name());
}
}

private EntityId spenderEntityPersistWithAlias() {
Expand All @@ -1034,7 +1068,7 @@ private EntityId accountPersistWithAlias(final Address alias, final ByteString p
private EntityId accountPersist() {
return domainBuilder
.entity()
.customize(e -> e.evmAddress(null).balance(12L))
.customize(e -> e.evmAddress(null).alias(null).balance(12L))
.persist()
.toEntityId();
}
Expand Down

0 comments on commit 876290c

Please sign in to comment.