Skip to content

test(contracts): expand test suite to ~95% scenario coverage 🧪#32

Merged
Klazomenai merged 3 commits intomainfrom
test/25-expand-test-coverage
Mar 23, 2026
Merged

test(contracts): expand test suite to ~95% scenario coverage 🧪#32
Klazomenai merged 3 commits intomainfrom
test/25-expand-test-coverage

Conversation

@Klazomenai
Copy link
Copy Markdown
Owner

@Klazomenai Klazomenai commented Mar 23, 2026

Summary

  • 21 new tests (27 → 48 total)
  • 6 fuzz tests (1,000 runs each) for access control enforcement
  • 2 invariant tests (256 runs, depth 64) with handler contract
  • foundry.toml configured with fuzz/invariant settings and gas reports

New Test Categories

Category Tests Priority
Self-referential ops 3 Must-have
State transition cycles 3 Must-have
Removed admin cannot act 2 Should-have
Multi-admin complex scenarios 3 Should-have
adminCount view test 1 Should-have
Full lifecycle integration 1 Should-have
Fuzz: access control enforcement 6 Must-have
Invariant: admin count + operations exercised 2 Must-have

Coverage

Metric Before After
Test count 27 48
Scenario coverage ~55% ~95%
Fuzz tests 0 6 (1000 runs)
Invariant tests 0 2 (256 runs x 64 depth)

Refs #25

Test plan

  • forge test -vv — 48 tests pass (2 test suites)
  • Invariant tests: 2 x 256 runs x ~16,384 calls each — expected reverts only
  • CI passes

Add 22 new tests covering:
- Self-referential operations (admin grants/revokes self)
- State transition cycles (grant/revoke/re-grant, add/remove/re-add)
- Admin/access independence (removeAdmin does not revoke access)
- Removed admin cannot act (grantAccess, addAdmin revert)
- Multi-admin complex scenarios (3 admins, cross-admin ops)
- Full lifecycle integration test
- 6 fuzz tests (1000 runs each) for access control enforcement
- 3 invariant tests (256 runs, depth 64) with handler contract

Configure foundry.toml with fuzz/invariant settings and gas reports.

Refs #25
@Klazomenai Klazomenai self-assigned this Mar 23, 2026
@Klazomenai Klazomenai marked this pull request as ready for review March 23, 2026 23:06
Copilot AI review requested due to automatic review settings March 23, 2026 23:06
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Expands the Foundry test suite for KeyRAAccessControl to increase scenario coverage by adding additional unit tests plus new fuzz and invariant-based tests, and configures Foundry to run them at higher intensity.

Changes:

  • Add multiple scenario/unit tests covering self-ops, state transition cycles, removed-admin behavior, multi-admin scenarios, and a full lifecycle flow.
  • Introduce a new invariant test suite with a handler contract to drive random sequences of admin/access operations.
  • Update foundry.toml to enable gas reports and set fuzz/invariant run parameters.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
contracts/test/AccessList.t.sol Adds ~22 new scenario + fuzz tests for admin/access behavior and lifecycle flows.
contracts/test/AccessList.invariant.t.sol Adds invariant harness + invariants for KeyRAAccessControl.
contracts/foundry.toml Configures fuzz/invariant run counts and gas reporting.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- Remove redundant invariant_adminCountMatchesMinimum (same as NeverZero)
- Remove incorrect invariant_atLeastOneKnownAdminExists (third admin
  can replace both known admins)
- Replace blanket catch {} with _expectKnownError that only swallows
  expected revert selectors and propagates unexpected ones
- Remove dead address(0) guards (already excluded by _boundAddr)
- Add invariant_operationsExercised to detect misconfigured handler
- Track successful operation counts for observability

Refs #25
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Use assembly to revert with original ABI-encoded data instead of
casting to string, so Foundry can decode the actual error selector.

Refs #25
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Klazomenai Klazomenai merged commit 153778a into main Mar 23, 2026
5 checks passed
@Klazomenai Klazomenai deleted the test/25-expand-test-coverage branch March 23, 2026 23:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants