Skip to content

test: cover ContractCallLocal fee calculation for out-of-range gas values - #26947

Open
ruslanvelkov-beep wants to merge 1 commit into
hiero-ledger:mainfrom
ruslanvelkov-beep:test/contract-call-local-fee-gas-bounds
Open

test: cover ContractCallLocal fee calculation for out-of-range gas values#26947
ruslanvelkov-beep wants to merge 1 commit into
hiero-ledger:mainfrom
ruslanvelkov-beep:test/contract-call-local-fee-gas-bounds

Conversation

@ruslanvelkov-beep

Copy link
Copy Markdown
Contributor

Description

Adds unit-test coverage for ContractCallLocalFeeCalculator fee calculation at the
boundary gas values, pinning down that the query-fee arithmetic is sign- and
overflow-safe for a client-supplied gas.

accumulateNodePayment forwards the query's gas into the shared extra-fee accumulation
(FeeResult.addServiceExtraFeeTinycents), which clamps the billable count with
Math.max(0, used - included) and accumulates it with the saturating clampedMultiply /
clampedAdd helpers. The existing tests only exercised gas = 0 and a small positive
value, leaving the sign/overflow edges uncovered.

Tests added (no production code changed)

ContractServiceFeeCalculatorsTest:

  • testContractCallLocalWithNegativeGasChargesBaseFeeOnly — a negative gas clamps the
    extra count to zero, so only the base fee is charged (no negative extra fee).
  • testContractCallLocalWithMaxGasSaturatesInsteadOfWrapping — a Long.MAX_VALUE gas
    saturates via clampedMultiply/clampedAdd (fee overcharges) rather than wrapping into a
    negative or undercharged value.

Both assert exact totals against the test fee schedule, so a future change that reintroduced
raw (wrapping) arithmetic or dropped the negative-clamp would fail these tests.

Related issue(s)

N/A

…lues

Signed-off-by: Ruslan Velkov <ruslan.velkov@limechain.tech>
@ruslanvelkov-beep ruslanvelkov-beep self-assigned this Aug 24, 2026
@lfdt-bot

Copy link
Copy Markdown

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@codecov

codecov Bot commented Aug 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Impacted file tree graph

@@            Coverage Diff            @@
##               main   #26947   +/-   ##
=========================================
  Coverage     70.50%   70.50%           
  Complexity    11690    11690           
=========================================
  Files          2586     2586           
  Lines        108469   108469           
  Branches      12142    12141    -1     
=========================================
+ Hits          76474    76475    +1     
+ Misses        28015    28013    -2     
- Partials       3980     3981    +1     

see 1 file with indirect coverage changes

Impacted file tree graph

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@testlens-app

testlens-app Bot commented Aug 24, 2026

Copy link
Copy Markdown

✅ All tests passed ✅

🏷️ Commit: 6815c65
▶️ Tests: 1909 executed
⚪️ Checks: 39/39 completed


Learn more about TestLens at testlens.app/docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants