test: mutation-harden log unit coverage#447
Conversation
Strengthen and extend the unit tests for src/core/process/log.ts so they kill previously-surviving mutants in the income/clear-amount accounting helpers. The existing tests asserted only weak properties (a "_18" suffix for getActualPrice, and typeof/positivity for getTotalIncome), which let arithmetic and argument mutations pass undetected. - getActualPrice: pin the exact computed price and add a non-18 decimals case so the scaleTo18 decimals argument and the ONE18 scaling are checked. - getTotalIncome: pin exact per-branch and summed values, and add a case with distinct prices and incomes so each income is verified to pair with its own token price (not swapped) and the ONE18 divisor is verified. - getActualClearAmount: cover the AfterClearV2 normalize-failure branch returning undefined. Tests-only; no source changes. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughTest coverage for three log-processing helpers is updated: a new edge case is added for ChangesLog helper test tightening
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 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 |
Summary
Mutation-hardens the unit tests for
src/core/process/log.ts(transaction-receipt income / clear-amount accounting helpers), the weakest qualifying module found in a scoped adversarial-mutation pass over the core solve/processing logic (src/core/**).The existing tests asserted only weak properties — a
"_18"suffix forgetActualPrice, andtypeof === "bigint"/> 0nforgetTotalIncome— so arithmetic and argument mutations on the actual money math passed undetected. This PR pins the exact computed values and adds the missing branch.Tests-only. No source changes (
git diff src/is empty apart from the test file).Mutation matrix (
log.ts)getActualPrice·* ONE18scaling* ONE18→/ ONE18getActualPrice·scaleTo18(value, tokenDecimals)0getTotalIncome· input price/income pairingoutputTokenPricegetTotalIncome· input/ ONE18divisor/ ONE18→* ONE18getActualClearAmount· AfterClearV2 normalize-failAlready-covered behaviors confirmed by mutation (existing tests killed the mutant):
getIncometoken-address filter, value compare, andto === signerfilter;getActualClearAmountbranch selector, Transferfrom === obfilter,AfterClearevent selection, and AfterClearV2 decimals arg;getActualPriceto === arb/from !== orderbookfilters;getTotalIncomeboth-undefined guard and the sign of the final sum.What was added / strengthened
getActualPrice— strengthened the existing "formatted price" test to pin the exact price; added a non-18 (6) decimals test so thescaleTo18decimals argument and theONE18scaling are both exercised.getTotalIncome— pinned exact per-branch and summed values (4n/9n/13n); added a distinct-price/distinct-income case (19nvs swapped25n) so each income is verified to pair with its own token price and theONE18divisor is verified.getActualClearAmount— added a test for the AfterClearV2 normalize-failure branch returningundefined(unparsablealiceOutput).Exact expected values are deterministic from the test file's existing
formatUnits/parseUnitsmocks combined with the realscaleTo18, so the assertions discriminate correct vs. mutated output.Gaps checklist
getActualPriceprice arithmetic pinned (scaling + divisor + decimals)getTotalIncomeexact value, price↔income pairing, and divisor pinnedgetActualClearAmountAfterClearV2 normalize-failure branch coveredlog.tsafter this passif (outputResult.isErr())guard is an equivalent mutant (anErrresult's.valueis alsoundefined), so it is not separately killable; the negated-guard variant is killed by the existing valid-float test.Verification
log.test.ts: 15 → 18 tests, all green on baseline.src/coreunit suite: 224 tests green (was 221).tsc -p tsconfig.check.json: clean.eslint: clean.src/loggertest requires the project's--disableConsoleInterceptinvocation, which is a pre-existing harness quirk, in an out-of-scope module, and passes under its own npm script).e2e/ hardhat fork tests are a pre-existing environmental red (RPC/secrets) and are out of scope.🤖 Generated with Claude Code
Summary by CodeRabbit