[TEST] Spike: initialize cap example#827
Draft
MiguelLZPF wants to merge 2 commits intodevelopmentfrom
Draft
Conversation
…ion-gated logic
Implement a comprehensive facet reinitialization framework for the Diamond pattern
that enables safe upgrades and reinitializations with version-based gating.
Core Infrastructure Changes:
- Added FacetVersionsStorageWrapper.sol: Centralized versioned storage for all
facets using single bytes32 storage slot with mapping(bytes32 => uint64)
- Added _FACET_VERSIONS_STORAGE_POSITION to storagePositions.sol
- Added facetKeys.sol with _CAP_FACET_KEY constant (keccak256('ats.facet.cap'))
Cap Facet Implementation:
- Updated ICap.sol: Added CapInitParams struct with maxSupply and partitionCap
- Updated CapStorageWrapper1.sol: Refactored _initialize_Cap with version logic
- Fresh deploy (v0 → v1): Runs V1 block, stores data, sets version to 1
- Migration (initialized=true, v=0): Treats as V1, updates version only
- Already at V1: Reverts AlreadyAtLatestVersion to prevent re-initialization
- Extensible for future versions: Infrastructure ready for v2, v3+ blocks
- Updated Cap.sol: Added conditional access control
- Fresh deploy: Anyone can call (Factory deployment before roles assigned)
- Upgrade: Requires DEFAULT_ADMIN_ROLE for security
- Version check in wrapper handles idempotency
- Updated Factory.sol: Uses new CapInitParams struct for initialize_Cap call
- Updated Internals.sol: Updated _initialize_Cap abstract signature
Test Coverage:
- Created facetVersions.test.ts (5 tests): Version tracking, migration, errors
- Created capReinitialization.test.ts (10 tests): Deploy, upgrades, admin checks
- Updated cap.test.ts: Adjusted for new CapInitParams struct
- All 1606 tests passing
Benefits:
- Safe facet upgrades with version tracking
- Backward compatibility through migration handling
- Future-proof initialization infrastructure for additional versions
- Proper separation of concerns between storage and access control
Signed-off-by: Miguel_LZPF <miguel.carpena@io.builders>
Add deinitialize_Cap function to enable rollback from version N to N-1, undoing storage changes made during version upgrades. Infrastructure changes: - Add InvalidRollbackTarget and CannotRollbackBelowMinVersion errors - Add FacetVersionRolledBack event to FacetVersionsStorageWrapper Cap facet implementation: - Add _CAP_MIN_VERSION constant (floor at V1, cannot rollback below) - Add _deinitialize_Cap internal function with reverse cumulative pattern - Add deinitialize_Cap external function with DEFAULT_ADMIN_ROLE access - Register new selector in CapFacetBase getStaticFunctionSelectors Signed-off-by: Miguel_LZPF <miguel.carpena@io.builders>
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
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.
Description
Type of change
Testing
Node version:
Checklist