Skip to content

Commit

Permalink
Fix tests in ContractCallServiceTest suite (#10194)
Browse files Browse the repository at this point in the history
This PR fixes 3 tests in ContractCallServiceTest. Fixes PAYER_ACCOUNT_NOT_FOUND error and some assertion messages

---------

Signed-off-by: Nikolay Nikolov <[email protected]>
  • Loading branch information
nickeynikolovv authored Jan 21, 2025
1 parent 17133f5 commit 190b421
Showing 1 changed file with 29 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
import static com.hedera.mirror.web3.utils.ContractCallTestUtil.longValueOf;
import static com.hedera.mirror.web3.validation.HexValidator.HEX_PREFIX;
import static com.hederahashgraph.api.proto.java.ResponseCodeEnum.CONTRACT_EXECUTION_EXCEPTION;
import static com.hederahashgraph.api.proto.java.ResponseCodeEnum.CONTRACT_NEGATIVE_VALUE;
import static com.hederahashgraph.api.proto.java.ResponseCodeEnum.CONTRACT_REVERT_EXECUTED;
import static com.hederahashgraph.api.proto.java.ResponseCodeEnum.INSUFFICIENT_PAYER_BALANCE;
import static com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_TRANSACTION;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
Expand Down Expand Up @@ -547,12 +549,20 @@ void transferNegative() {
// Given
final var receiverEntity = accountPersist();
final var receiverAddress = getAliasAddressFromEntity(receiverEntity);
final var serviceParameters = getContractExecutionParametersWithValue(Bytes.EMPTY, receiverAddress, -5L);

final var payer = accountEntityWithEvmAddressPersist();
persistAccountBalance(payer, payer.getBalance());
final var serviceParameters = getContractExecutionParametersWithValue(
Bytes.EMPTY, toAddress(payer.toEntityId()), receiverAddress, -5L);
// Then
assertThatThrownBy(() -> contractExecutionService.processCall(serviceParameters))
.isInstanceOf(MirrorEvmTransactionException.class)
.hasMessage("Argument must be positive");
if (mirrorNodeEvmProperties.isModularizedServices()) {
assertThatThrownBy(() -> contractExecutionService.processCall(serviceParameters))
.isInstanceOf(MirrorEvmTransactionException.class)
.hasMessage(CONTRACT_NEGATIVE_VALUE.name());
} else {
assertThatThrownBy(() -> contractExecutionService.processCall(serviceParameters))
.isInstanceOf(MirrorEvmTransactionException.class)
.hasMessage("Argument must be positive");
}
assertGasLimit(serviceParameters);
}

Expand All @@ -566,13 +576,18 @@ void transferExceedsBalance() {
final var value = senderEntity.getBalance() + 5L;
final var serviceParameters =
getContractExecutionParametersWithValue(Bytes.EMPTY, senderAddress, receiverAddress, value);

// Then
assertThatThrownBy(() -> contractExecutionService.processCall(serviceParameters))
.isInstanceOf(MirrorEvmTransactionException.class)
.hasMessage(
"Cannot remove %s wei from account, balance is only %s",
toHexWith64LeadingZeros(value), toHexWith64LeadingZeros(senderEntity.getBalance()));
if (mirrorNodeEvmProperties.isModularizedServices()) {
assertThatThrownBy(() -> contractExecutionService.processCall(serviceParameters))
.isInstanceOf(MirrorEvmTransactionException.class)
.hasMessage(INSUFFICIENT_PAYER_BALANCE.name());
} else {
assertThatThrownBy(() -> contractExecutionService.processCall(serviceParameters))
.isInstanceOf(MirrorEvmTransactionException.class)
.hasMessage(
"Cannot remove %s wei from account, balance is only %s",
toHexWith64LeadingZeros(value), toHexWith64LeadingZeros(senderEntity.getBalance()));
}
assertGasLimit(serviceParameters);
}

Expand All @@ -582,12 +597,13 @@ void transferThruContract() throws Exception {
final var receiverEntity = accountPersist();
final var receiverAddress = getAliasAddressFromEntity(receiverEntity);
final var contract = testWeb3jService.deploy(EthCall::deploy);
final var payer = accountEntityWithEvmAddressPersist();
persistAccountBalance(payer, payer.getBalance());
meterRegistry.clear();

testWeb3jService.setSender(toAddress(payer.toEntityId()).toHexString());
// When
contract.send_transferHbarsToAddress(receiverAddress.toHexString(), BigInteger.TEN)
.send();

// Then
assertThat(testWeb3jService.getTransactionResult()).isEqualTo(HEX_PREFIX);
assertGasLimit(ETH_CALL, TRANSACTION_GAS_LIMIT);
Expand Down

0 comments on commit 190b421

Please sign in to comment.