test: mutation-harden math unit coverage#448
Conversation
Adds discriminating unit tests for the two previously-untested exports in src/math/index.ts: toNumber and isBigNumberish. Before this change both functions had zero test coverage (math/index.ts branch coverage was the weakest qualifying module at 73.33%) so every mutant in them survived. toNumber: pins the 18-decimal scaling (1e18 -> 1, 1.5e18 -> 1.5, 123e18 -> 123, 0 -> 0); kills decimal-shift mutations of the formatUnits argument. isBigNumberish: one discriminating case per OR-branch so removing or inverting any single branch is caught -- integer vs non-integer number (value % 1 === 0), all-digit/signed string vs decimal/non-numeric string (the /^-?[0-9]+$/ regex incl. the -? prefix and dot rejection), hex-string via isHex, bigint, byte-array via isBytes, and the value != null nullish guard. Tests only; no src/ behavior change. Full vitest unit suite green (847 tests). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Warning Review limit reached
More reviews will be available in 31 minutes and 45 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the 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 configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
State what each assertion verifies as present-tense fact, without referencing the mutations they kill. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Module hardened
src/math/index.ts— selected as the weakest qualifying module fromvitest run --coverageover the in-scope modules (excludingorder/,router/,gas/, the core solve loop,index, andconfig). It had the lowest branch coverage (73.33%), driven entirely by two exported functions that had zero test coverage:toNumberandisBigNumberish. Every mutant planted in them survived the existing suite.This PR is tests-only — no source line changed (
git difftouches onlysrc/math/index.test.ts).Mutation matrix
Each mutation was applied to the exact source line, the math suite re-run, then the line restored.
Pre-existing coverage — already killed by existing tests (audited, left as-is)
scaleTo18down-branchvalue / 10^(d-18)→*scaleTo18up-branchvalue * 10^(18-d)→/scaleTo18operandrepeat(d-18)→repeat(18-d)scaleFrom18up-branch*→/scaleFrom18down-branch/→*calculatePrice18zero guardamountIn === 0n→!== 0ncalculatePrice18numeratorout18 * ONE18→out18 / ONE18calculatePrice18denominator/ amountIn18→* amountIn18calculatePrice18out decimalsdecimalsOut→decimalsIncalculatePrice18in decimalsdecimalsIn→decimalsOutNew coverage — mutants that SURVIVED before, now KILLED by added tests
toNumberscalingformatUnits(v, 18)→17toNumberscalingformatUnits(v, 18)→19isBigNumberishint checkvalue % 1 === 0→!== 0isBigNumberishnumber branchisBigNumberishstring branchisBigNumberishregex sign/^-?[0-9]+$/→ drop-?isBigNumberishregex dot/^-?[0-9]+$/→ allow.isBigNumberishisHex branchisHex(value)isBigNumberishbigint branchtypeof === "bigint"isBigNumberishisBytes branchisBytes(value)isBigNumberishnull guardvalue != null→== nullGaps checklist
toNumber— fully covered (4 discriminating values pinning the 18-decimal scale).isBigNumberish— every OR-branch independently pinned by a discriminating case.scaleTo18/scaleFrom18/calculatePrice18— pre-existing tests audited, all mutants killed.scaleTo18/scaleFrom18boundary> 18→>= 18: equivalent mutant (at exactly 18 decimals both branches computevalue * 1 == value / 1 == value); no test can distinguish — left uncovered intentionally.Verification
tsc -p tsconfig.check.jsonclean.eslintclean on the changed test file.e2e fork testjobs are a pre-existing environmental red (RPC/secrets), out of scope and not touched.🤖 Generated with Claude Code