test: mutation-harden gas/index unit coverage#444
Open
thedavidmeister wants to merge 8 commits into
Open
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>
Contributor
|
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)
WalkthroughAdds 93 lines of new tests to ChangesGasManager test coverage
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 |
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Summary by CodeRabbit