Skip to content

Conversation

@adamgall
Copy link
Collaborator

@adamgall adamgall commented Oct 26, 2025

test: add comprehensive test coverage for AccessControl contracts (#131)

Implement complete test suites for LibAccessControl and AccessControlFacet
with test harnesses to expose internal library functions for thorough testing.

New files added:

  • test/access/AccessControl/LibAccessControl.t.sol (454 lines, 37 tests)
  • test/access/AccessControl/AccessControlFacet.t.sol (611 lines, 45 tests)
  • test/access/AccessControl/harnesses/LibAccessControlHarness.sol
  • test/access/AccessControl/harnesses/AccessControlFacetHarness.sol

Test coverage includes:

  • Core RBAC functionality (grant, revoke, renounce, hasRole)
  • Role admin hierarchies and custom role admins
  • Access control enforcement with requireRole
  • Storage slot verification and collision prevention
  • Event emission for all role operations
  • Edge cases (circular hierarchies, self-admin roles, zero addresses)
  • Comprehensive fuzz tests for all operations
  • Complex multi-level role hierarchy scenarios

Total: 82 new tests ensuring robust access control implementation
following patterns established by Owner and OwnerTwoSteps test suites.

Closes #131

@github-actions
Copy link

github-actions bot commented Oct 26, 2025

Coverage Report

Coverage

Metric Coverage Details
Lines 42% 423/1007 lines
Functions 58% 101/175 functions
Branches 26% 45/171 branches

Last updated: Mon, 27 Oct 2025 03:56:15 GMT for commit 61d0e0d

@adamgall adamgall force-pushed the access-control-tests branch 2 times, most recently from 3b71b42 to 31323f0 Compare October 26, 2025 21:54
uint256 gasUsed = gasBefore - gasleft();

console2.log("Gas used for hasRole:", gasUsed);
assertEq(gasUsed, 1377, "hasRole gas cost should be exactly 1377");
Copy link
Collaborator

@maxnorm maxnorm Oct 26, 2025

Choose a reason for hiding this comment

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

Using fix gas assumption, in test, break the coverage.

This gas value is based on the assumption of optimizer runs which the coverage action disable. The optimizer_runs value is set to 20_000, but this value can also be change. This will also break the tests.

Upper limit seems a good way to test gas usage within a appropriate range while i agree that it's not the most accurate way.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

best way IMO is to rip out these "gas tests" entirely, and utilize forge snapshot for tracking gas costs between commits / code.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@adamgall
Copy link
Collaborator Author

will fix these broken actions

@adamgall adamgall force-pushed the access-control-tests branch 2 times, most recently from 55ee4c5 to 90106c4 Compare October 27, 2025 03:53
…rfect-Abstractions#131)

Implement complete test suites for LibAccessControl and AccessControlFacet
with test harnesses to expose internal library functions for thorough testing.

New files added:
- test/access/AccessControl/LibAccessControl.t.sol (454 lines, 37 tests)
- test/access/AccessControl/AccessControlFacet.t.sol (611 lines, 45 tests)
- test/access/AccessControl/harnesses/LibAccessControlHarness.sol
- test/access/AccessControl/harnesses/AccessControlFacetHarness.sol

Test coverage includes:
- Core RBAC functionality (grant, revoke, renounce, hasRole)
- Role admin hierarchies and custom role admins
- Access control enforcement with requireRole
- Storage slot verification and collision prevention
- Event emission for all role operations
- Edge cases (circular hierarchies, self-admin roles, zero addresses)
- Comprehensive fuzz tests for all operations
- Complex multi-level role hierarchy scenarios

Total: 82 new tests ensuring robust access control implementation
following patterns established by Owner and OwnerTwoSteps test suites.

Closes Perfect-Abstractions#131
@adamgall adamgall force-pushed the access-control-tests branch from 90106c4 to 61d0e0d Compare October 27, 2025 03:55
@adamgall adamgall requested a review from maxnorm October 27, 2025 04:16
@adamgall adamgall merged commit 139b954 into Perfect-Abstractions:main Oct 27, 2025
3 checks passed
@adamgall adamgall deleted the access-control-tests branch October 27, 2025 05:04
JackieXu pushed a commit to JackieXu/Compose that referenced this pull request Nov 6, 2025
…rol-tests

test: add comprehensive test coverage for AccessControl contracts
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.

[Testing]: Add comprehensive test coverage for AccessControl contracts

2 participants