Skip to content

test: exercise adjustExponent logic paths in div#236

Merged
thedavidmeister merged 2 commits into
mainfrom
2026-06-13-issue-133
Jun 13, 2026
Merged

test: exercise adjustExponent logic paths in div#236
thedavidmeister merged 2 commits into
mainfrom
2026-06-13-issue-133

Conversation

@thedavidmeister

Copy link
Copy Markdown
Contributor

Fixes #133

The div implementation in LibDecimalFloatImplementation selects an adjustExponent for scaling the numerator via a binary search over the order of magnitude of the (maximized) divisor coefficient. The smaller-than-1e75 leaves of that search were not exercised by the existing tests, because they are only reachable when the divisor cannot be maximized — its exponent is pinned at type(int256).min, leaving the coefficient at its given magnitude.

This PR adds deterministic unit tests (test-only, no production source change) covering:

  • testDivAdjustExponentLeaves — every interior leaf of the binary search, placing one divisor strictly inside each sub-range (< 1e5, [1e5,1e10), ... [1e73,1e75) including the "noop" leaf that keeps the starting 1e76 scale).
  • testDivAdjustExponentBoundaries — the strict < boundary comparisons at each power-of-ten boundary (1e5 .. 1e68).
  • testDivAdjustExponentFullDivisor — the dedicated full-divisor branch (scale = 1e75, adjustExponent = 75).
  • testDivAdjustExponentLargeDivisor — the >= 1e76 path that skips the scaling block entirely (adjustExponent = 76).
  • testDivAdjustExponentSpillsToExponentB — the adjustment spilling from exponentA onto exponentB.
  • testDivAdjustExponentSpillOverflowReturnsZero — the spill-overflow return-zero case.
  • testDivUnderflowReturnsZero — the underflow return-zero case.

Each case asserts the round-trip identity (a / b) * b == a (compared as a value via eq), which pins both the quotient mantissa and the adjustExponent constant for that branch: a wrong constant scales the quotient by a power of ten and breaks the equality. The leaves test also asserts the exact quotient mantissa (3e75).

Verification

  • forge build clean.
  • New div suite: 23 passed, 0 failed (7 new tests).
  • Full Solidity suite: 458 passed, 5 failed. The 5 failures are the pre-existing testProdDeployment{Arbitrum,Base,BaseSepolia,Flare,Polygon} fork tests that require *_RPC_URL env vars; verified identical on clean origin/main.
  • Mutation check: changing one adjustExponent constant (56) makes testDivAdjustExponentLeaves fail, confirming the round-trip oracle has real discriminating power; reverted before commit.

🤖 Generated with Claude Code

The `div` implementation selects an `adjustExponent` for scaling the
numerator via a binary search over the order of magnitude of the
(maximized) divisor coefficient. The smaller-than-1e75 leaves of that
search were not exercised by the existing tests, because they are only
reachable when the divisor cannot be maximized (its exponent is pinned at
type(int256).min, leaving the coefficient at its given magnitude).

Adds deterministic unit tests covering:
- every interior leaf of the binary search (one divisor strictly inside
  each sub-range, 1e5 .. 1e75) plus the "noop" leaf,
- the strict `<` boundary comparisons at each power-of-ten boundary,
- the dedicated full-divisor (scale 1e75) and >=1e76 (scale 1e76) paths,
- the exponent-adjustment application paths: applied to exponentA,
  spilled over onto exponentB, the spill-overflow return-zero case, and
  the underflow return-zero case.

Each case asserts the round-trip identity `(a / b) * b == a` (compared as
a value via `eq`), which pins both the quotient mantissa and the
`adjustExponent` constant for that branch: a wrong constant scales the
quotient by a power of ten and breaks the equality. Confirmed
discriminating by mutating an `adjustExponent` constant and observing the
new test fail.

Test-only change; no production source is modified.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@thedavidmeister thedavidmeister self-assigned this Jun 13, 2026
@coderabbitai

coderabbitai Bot commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@thedavidmeister, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 27 minutes and 7 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more credits in the billing tab to continue.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: c502b2b8-e10b-4347-b671-162e8dd71a1b

📥 Commits

Reviewing files that changed from the base of the PR and between 90aa415 and a64dd7d.

📒 Files selected for processing (1)
  • test/src/lib/implementation/LibDecimalFloatImplementation.div.t.sol
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 2026-06-13-issue-133

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@thedavidmeister

Copy link
Copy Markdown
Contributor Author

Reviewed a64dd7d: exercise the adjustExponent logic paths in div; mutation-validated discriminating test (not enshrining). All checks green. LGTM.

@thedavidmeister thedavidmeister merged commit cdf1a63 into main Jun 13, 2026
9 checks passed
@github-actions

Copy link
Copy Markdown

@coderabbitai assess this PR size classification for the totality of the PR with the following criterias and report it in your comment:

S/M/L PR Classification Guidelines:

This guide helps classify merged pull requests by effort and complexity rather than just line count. The goal is to assess the difficulty and scope of changes after they have been completed.

Small (S)

Characteristics:

  • Simple bug fixes, typos, or minor refactoring
  • Single-purpose changes affecting 1-2 files
  • Documentation updates
  • Configuration tweaks
  • Changes that require minimal context to review

Review Effort: Would have taken 5-10 minutes

Examples:

  • Fix typo in variable name
  • Update README with new instructions
  • Adjust configuration values
  • Simple one-line bug fixes
  • Import statement cleanup

Medium (M)

Characteristics:

  • Feature additions or enhancements
  • Refactoring that touches multiple files but maintains existing behavior
  • Breaking changes with backward compatibility
  • Changes requiring some domain knowledge to review

Review Effort: Would have taken 15-30 minutes

Examples:

  • Add new feature or component
  • Refactor common utility functions
  • Update dependencies with minor breaking changes
  • Add new component with tests
  • Performance optimizations
  • More complex bug fixes

Large (L)

Characteristics:

  • Major feature implementations
  • Breaking changes or API redesigns
  • Complex refactoring across multiple modules
  • New architectural patterns or significant design changes
  • Changes requiring deep context and multiple review rounds

Review Effort: Would have taken 45+ minutes

Examples:

  • Complete new feature with frontend/backend changes
  • Protocol upgrades or breaking changes
  • Major architectural refactoring
  • Framework or technology upgrades

Additional Factors to Consider

When deciding between sizes, also consider:

  • Test coverage impact: More comprehensive test changes lean toward larger classification
  • Risk level: Changes to critical systems bump up a size category
  • Team familiarity: Novel patterns or technologies increase complexity

Notes:

  • the assessment must be for the totality of the PR, that means comparing the base branch to the last commit of the PR
  • the assessment output must be exactly one of: S, M or L (single-line comment) in format of: SIZE={S/M/L}
  • do not include any additional text, only the size classification
  • your assessment comment must not include tips or additional sections
  • do NOT tag me or anyone else on your comment

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.

exercise adjustExponent logic paths in div

1 participant