chore(test): add vitest v8 coverage with 95% perFile gate#527
Conversation
Adds @vitest/coverage-v8, a test:coverage script, and the coverage block in vitest.config.ts mirroring the feat/forwarder reference. Covers TS witnesses and simulators; compactc-generated artifact JS is instrumented but dropped after source-map remap (.compact source-map granularity is unreliable for branch attribution).
…to 100% - Adds the three literal tests from the PR #420 review snippets: - `_grantRole should independently check initialization` - `_revokeRole should independently check initialization` - `when revoking a role from an unauthorized accountId that was never granted` - Derives UNAUTHORIZED_ACCOUNT_ID from the existing UNAUTHORIZED_SK. - Adds tests for the SAC simulator's privateState helpers (getCurrentSecretKey, getCommitmentPathWithFindForLeaf, getCommitmentPathWithWitnessImpl), lifting ShieldedAccessControlSimulator.ts to 100% lines/branches/funcs/stmts. Closes #443.
Covers the three previously-untested code paths: the `ledgerExtractor`
callback (asserted to return the expected empty `{}` ledger), and both
branches of `getCurrentSecretKey` (happy path after `injectSecretKey`,
and the defensive `Missing secret key` throw when the secret key field
is undefined on the private state).
Covers the previously-untested simulator wiring (`defaultPrivateState`
fallback when constructed without options, `ledgerExtractor` returning
the expected empty `{}` ledger) and both branches of `getCurrentSecretKey`.
Adds a simulator-wiring test that exercises `getPublicState` and asserts the deterministic `Pausable__isPaused` value before and after pausing, covering the previously-untested `ledgerExtractor` callback.
Adds simulator-wiring and privateState-helper tests that exercise the
previously-untested `ledgerExtractor` callback (asserting the expected
empty `{}` ledger) and both branches of `getCurrentSecretKey`.
Adds simulator-wiring and privateState-helper tests covering the previously-untested `ledgerExtractor` callback (asserting the deterministic `MultiToken__balances` map starts empty) and both branches of `getCurrentSecretKey`.
Drops `excludeAfterRemap: true` and the `.compact` exclude so v8's source-map remap routes artifact-JS coverage back to the original `.compact` source. The report now measures real circuit-level test thoroughness per module rather than only the TS wrapper layer. Note: compactc source maps remain function-entry-granularity, so branch attribution on `.compact` lines can still be approximate. Upstream: LFDT-Minokawa/compact#465
Adds wiring + privateState-helper tests covering the `ledgerExtractor`
callback (asserting an empty `{}` public ledger) and both branches of
`getCurrentSecretKey`.
Adds a wiring test that exercises `getPublicState`, asserting the
expected empty `{}` public ledger and covering the previously-untested
`ledgerExtractor` callback.
Scope the 95% perFile gate to `**/*.ts` (simulator wrappers + witnesses) via a per-pattern threshold. `.compact` coverage stays surfaced in the HTML / text report for visibility but is not gated. Background: compactc emits function-entry-granularity source maps and v8 ends up attributing uncovered functions to `pragma language_version` lines, uncovered statements to doc comments, uncovered branches to ledger declaration lines with no `if` statement, and even surfaces "uncovered" line numbers past EOF. No test additions can move those metrics, so any threshold on `.compact` is fragile noise. Tracking upstream: LFDT-Minokawa/compact#465
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (10)
WalkthroughThis PR extends test coverage across the contract test suite to verify simulator initialization, public state exposure, and private state handling. Vitest is configured with v8 coverage reporting at 95% thresholds, while test suites systematically add simulator wiring and privateState helper tests across all contract modules. ChangesTest Coverage & Simulator Verification
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add Comment |
|
Actionable comments posted: 0 |
Types of changes
What types of changes does your code introduce to OpenZeppelin Midnight Contracts?
Put an `` in the boxes that apply
Fixes https://github.com/OpenZeppelin/compact-contracts/issues/443\
In general this PR increases the testing coverage as possible.
\
PR Checklist
Further comments
If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc...
Summary by CodeRabbit
Tests
Chores
test:coveragenpm script for coverage reporting.