Skip to content

[Testing]: Add comprehensive tests for DiamondCutFacet #119

@panditdhamdhere

Description

@panditdhamdhere

Add comprehensive tests for DiamondCutFacet

Summary

The DiamondCutFacet lacks comprehensive test coverage. This facet is critical for diamond contract functionality as it handles adding, removing, and replacing facets in diamond contracts according to the ERC-2535 standard.

Motivation

The DiamondCutFacet is a core component of the diamond pattern implementation and needs thorough testing to ensure:

  • Facet addition works correctly
  • Facet removal works correctly
  • Facet replacement works correctly
  • Initialization functions work properly
  • Error conditions are handled correctly
  • Storage management is correct

Without proper test coverage, bugs in this facet could break the entire diamond functionality.

Create comprehensive tests following the established testing patterns in the project:

  1. Create test harness - DiamondCutFacetHarness.sol to expose internal functions for testing
  2. Create test file - DiamondCutFacet.t.sol with comprehensive test coverage
  3. Follow existing patterns - Use the same structure as ERC20 tests
  4. Test all functions - Cover all public and internal functionality
  5. Test error conditions - Verify all error cases work correctly
  6. Test edge cases - Cover boundary conditions and edge cases

Test Coverage Needed

Core Functionality Tests

  • diamondCut() with ADD action
  • diamondCut() with REMOVE action
  • diamondCut() with REPLACE action
  • Multiple operations in single call
  • Initialization function execution

Error Condition Tests

  • Invalid facet addresses
  • Duplicate function selectors
  • Non-existent function removal
  • Invalid initialization data
  • Unauthorized access attempts

Edge Case Tests

  • Empty selector arrays
  • Maximum selector limits
  • Storage slot management
  • Function selector collision detection

Integration Tests

  • Test with actual ERC20Facet
  • Test with actual ERC721Facet
  • Test diamond functionality after cuts

Additional Context

  • Follow the testing patterns established in test/ERC20/
  • Use the same naming conventions (test_FunctionName_Scenario)
  • Include fuzz tests for functions with array parameters
  • Test gas usage for optimisation
  • Ensure all tests pass with forge test

Checklist

  • Follows project standards (no banned Solidity features)
  • Uses diamond storage patterns correctly
  • Includes comprehensive test coverage
  • Follows established testing patterns
  • Includes error condition testing
  • Includes fuzz testing where appropriate
  • Updates test/README.md
  • All tests pass with forge test

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions