Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix more tests in ContractCallServiceTests #10382

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

nickeynikolovv
Copy link
Contributor

Description:
This PR fixes some tests in ContractCallServicesTests

  • made changes to capture the result from handleFailedResult but still throw an exception
  • Lowered the initial balance of 0.0.2 to avoid FAILED_INVALID because it was set to maximum and wasn't able to receive reward
  • Fix INSUFFICIENT_TX_FEE

Tests left to be fixed - 4
Related issue(s):

Related to #10087

Checklist

  • Documented (Code comments, README, etc.)
  • Tested (unit, integration, etc.)

@nickeynikolovv nickeynikolovv added enhancement Type: New feature web3 Area: Web3 API modularizedEVM labels Feb 14, 2025
@nickeynikolovv nickeynikolovv requested a review from a team February 14, 2025 11:36
@nickeynikolovv nickeynikolovv self-assigned this Feb 14, 2025
@nickeynikolovv nickeynikolovv changed the title Fix insufficient tx fee issue in contract call services test Fix more tests in ContractCallServiceTests Feb 14, 2025
@nickeynikolovv nickeynikolovv changed the title Fix more tests in ContractCallServiceTests Fix more tests in ContractCallServiceTests Feb 14, 2025
Copy link

codecov bot commented Feb 14, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.29%. Comparing base (5393ea9) to head (38a491a).

Additional details and impacted files
@@             Coverage Diff              @@
##               main   #10382      +/-   ##
============================================
+ Coverage     92.19%   92.29%   +0.09%     
+ Complexity     8111     8009     -102     
============================================
  Files           989      971      -18     
  Lines         33758    33509     -249     
  Branches       4268     4247      -21     
============================================
- Hits          31124    30926     -198     
+ Misses         1617     1571      -46     
+ Partials       1017     1012       -5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -133,6 +134,20 @@ protected void setup() {
treasuryEntity.getCreatedTimestamp(), treasuryEntity.toEntityId()))
.balance(treasuryEntity.getBalance()))
.persist();
domainBuilder
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and the next account is needed only only in a couple of tests in ContractCallServiceTest. We don't need to initialize them in every test. We can add them only in the needed tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

}
if (exceptionToThrow != null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to do this separately. A finally block is guaranteed to execute no matter if an exception is thrown.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@steven-sheehy steven-sheehy added this to the 0.124.0 milestone Feb 14, 2025
Signed-off-by: Nikolay Nikolov <[email protected]>
…ll-services-test

# Conflicts:
#	hedera-mirror-web3/src/main/java/com/hedera/mirror/web3/service/TransactionExecutionService.java
@@ -82,7 +82,8 @@ public HederaEvmTransactionProcessingResult execute(
TransactionBody transactionBody;
HederaEvmTransactionProcessingResult result = null;
if (isContractCreate) {
transactionBody = buildContractCreateTransactionBody(params, estimatedGas, maxLifetime);
transactionBody = buildContractCreateTransactionBody(
params, estimatedGas, maxLifetime, mirrorNodeEvmProperties.getContractCreateTxFee());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 4th parameter is always the same value, so it can be used in buildContractCreateTransactionBody() directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@@ -142,15 +142,21 @@ void cleanup() {

protected long gasUsedAfterExecution(final ContractExecutionParameters serviceParameters) {
try {
return contractExecutionService.callContract(serviceParameters).getGasUsed();
if (mirrorNodeEvmProperties.isModularizedServices()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The if and the else are the same statement. Can be simplified.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@@ -140,6 +140,9 @@ public class MirrorNodeEvmProperties implements EvmProperties {
@Min(21_000L)
private long maxGasLimit = 15_000_000L;

@Getter
private long contractCreateTxFee = 100_000_000L;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this really need to be a property? I am not sure if this needs to be configurable. I think a constant in the TransactionExecutionService should be enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need it, removed

@@ -152,7 +156,9 @@ private void restoreGasToBucket(HederaEvmTransactionProcessingResult result, lon
// of the gasLimit value back in the bucket.
final var gasLimitToRestoreBaseline =
(long) (Math.floorDiv(gasLimit, gasUnit) * throttleProperties.getGasLimitRefundPercent() / 100f);
if (!result.isSuccessful() && gasLimit == result.getGasUsed()) {
if (result == null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The if and the else-if can be combined since their body is the same.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@@ -145,7 +146,7 @@ private HederaEvmTransactionProcessingResult handleFailedResult(
var detail = maybeDecodeSolidityErrorStringToReadableMessage(errorMessage);
updateErrorGasUsedMetric(gasUsedCounter, result.gasUsed(), 1);
if (ContractCallContext.get().getOpcodeTracerOptions() == null) {
throw new MirrorEvmTransactionException(status.protoName(), detail, errorMessage.toHexString());
throw new MirrorEvmTransactionException(status.protoName(), detail, errorMessage.toHexString(), HederaEvmTransactionProcessingResult.failed(result.gasUsed(), 0L, 0L, Optional.empty(), Optional.empty()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have the Optional.of(errorMessage) - might as well pass it in the constructed result. Can become useful at some point.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

@@ -116,7 +116,7 @@ protected void setup() {
.entity()
.customize(e -> e.id(2L)
.num(2L)
.balance(5000000000000000000L)
.balance(1000000000000000000L)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can add a comment here - to say that if a balance is set near the max value, some unexpected errors occur as the balance overflows the max value if we use the same account for the node operator. This might save us some headaches in the future to avoid the same issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

Signed-off-by: Nikolay Nikolov <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Type: New feature modularizedEVM web3 Area: Web3 API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants