test: mutation-harden gas/index unit coverage#444
Conversation
Add discriminating tests to src/gas/index.test.ts that kill mutants surviving the existing GasManager suite: - Constructor default branches: assert class-field defaults (gasIncreasePointsPerStep=3, gasIncreaseStepTime=3_600_000, txTimeThreshold=30_000) and the maxGasPriceMultiplier = base + 50 fallback when optional config fields are omitted, plus a companion test pinning the provided-value assignment branches. - onTransactionMine boundary: a mine time exactly equal to the threshold must take the increase branch (>=, not >). - Deadline arithmetic: the deadline is Date.now() + gasIncreaseStepTime (not minus), bracketed against before/after timestamps. - Future-deadline guard: an under-threshold mine with a future deadline must not reset the multiplier. - watchGasPrice idempotency: a second call while already watching must early-return and keep the same interval handle (no leaked interval). Tests-only; src/ unchanged. 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 38 minutes and 30 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 |
Restate the added gas/index test comments as present-tense facts about what the code does, dropping mutant/process/coverage framing. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Summary
Mutation-hardens the
GasManagerunit suite (src/gas/index.ts). Ascoped adversarial-mutation pass over the gas-estimation peripheral logic
found 10 surviving mutants in the existing
src/gas/index.test.tssuite —all in the constructor default-value logic, the
onTransactionMinethreshold/deadline arithmetic, and the
watchGasPriceidempotency guard.This PR adds 6 discriminating tests (tests-only; no
src/change) thateach pass on the clean baseline and fail under the corresponding mutation.
Every previously-surviving mutant is now killed.
Mutation matrix
maxGasPriceMultiplier = baseGasPriceMultiplier + 50+ 50→- 50if (config.txTimeThreshold !== undefined)falseif (config.gasIncreasePointsPerStep !== undefined)falseif (config.gasIncreaseStepTime !== undefined)falsegasIncreasePointsPerStep: number = 33→7txTimeThreshold: number = 30_00030_000→1gasIncreaseStepTime: number = 60 * 60 * 10001if (txMineRecord.length >= this.txTimeThreshold)>=→>this.deadline = Date.now() + this.gasIncreaseStepTime+→-if (this.isWatchingGasPrice) return;falseAlready-covered (audited, no new test)
Math.min(max, multiplier + step)clamp →Math.max— KILLED by existing"should not increase the multiplier over the max value".
>=→<=on the deadline-reset comparison — KILLED by existing"under threshold and reset" (past deadline).
isOk()branches ininit/watchGasPrice— covered by existinginit/interval tests.
Equivalent (intentionally not tested)
if (this.deadline && Date.now() >= this.deadline)— dropping thethis.deadline &&short-circuit is equivalent in practice:deadlineisonly ever
undefinedor a positive timestamp, andDate.now() >= undefinedis already
false, so no reachable state distinguishes the mutant.>=vs>on the deadline comparison would only be discriminated byDate.now() === deadlineexactly, which is non-deterministic.New tests added (
src/gas/index.test.ts, +94 lines)should not start a second watcher when already watching(M9)should apply class defaults when optional config fields are omitted(M1/M2/M3/M4/M13/M14/M15)should use provided optional config values over the defaults(assignment branches)should increase the multiplier when mine time equals the threshold exactly(M5)should set the deadline to now plus the step time when increasing(M6)should not reset the multiplier when the deadline is still in the future(future-deadline guard)Gaps checklist
maxGasPriceMultiplier = base + 50fallbackonTransactionMine>=threshold boundary+ stepTimearithmeticwatchGasPricedouble-start idempotencyinit/watchGasPriceisErrbranches — already covered by existing tests (audited)Verification
tsc -p ./tsconfig.check.jsoncleaneslint ./src/gas/index.test.tscleangit diff src/is empty — tests-only changee2e fork testjobs are a pre-existing environmental red (RPC/secrets) and are untouched by this PR.🤖 Generated with Claude Code