@diamondslab/diamonds-hardhat-foundry 2.2.2 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +76 -1
- package/dist/framework/ForgeCoverageFramework.d.ts +61 -0
- package/dist/framework/ForgeCoverageFramework.d.ts.map +1 -0
- package/dist/framework/ForgeCoverageFramework.js +238 -0
- package/dist/framework/ForgeCoverageFramework.js.map +1 -0
- package/dist/framework/HelperGenerator.d.ts.map +1 -1
- package/dist/framework/HelperGenerator.js +7 -3
- package/dist/framework/HelperGenerator.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/tasks/coverage.d.ts +2 -0
- package/dist/tasks/coverage.d.ts.map +1 -0
- package/dist/tasks/coverage.js +173 -0
- package/dist/tasks/coverage.js.map +1 -0
- package/dist/types/config.d.ts +80 -0
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/config.js.map +1 -1
- package/package.json +3 -3
- package/src/framework/ForgeCoverageFramework.ts +287 -0
- package/src/framework/HelperGenerator.ts +9 -5
- package/src/index.ts +7 -6
- package/src/tasks/coverage.ts +307 -0
- package/src/types/config.ts +94 -0
- package/CHANGELOG.md +0 -321
package/CHANGELOG.md
DELETED
|
@@ -1,321 +0,0 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
All notable changes to this project will be documented in this file.
|
|
4
|
-
|
|
5
|
-
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
-
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
-
|
|
8
|
-
## [Unreleased]
|
|
9
|
-
|
|
10
|
-
## [2.1.0] - 2024-12-19
|
|
11
|
-
|
|
12
|
-
### Summary
|
|
13
|
-
|
|
14
|
-
This release achieves **100% test pass rate** (141/141 tests passing) with comprehensive fixes across all test categories. The module is now production-ready with robust test coverage spanning unit, integration, fuzz, and invariant testing.
|
|
15
|
-
|
|
16
|
-
### Fixed
|
|
17
|
-
|
|
18
|
-
- **Access Control Tests** (19 tests fixed):
|
|
19
|
-
- Fixed `AccessControlFuzz.t.sol` - Tests now properly grant DEFAULT_ADMIN_ROLE in setUp()
|
|
20
|
-
- Fixed `DiamondAccessControl.t.sol` - Tests initialize Diamond and grant necessary roles
|
|
21
|
-
- All role granting, revocation, and enumeration tests now pass
|
|
22
|
-
- Gas profiling tests for grantRole and revokeRole fixed
|
|
23
|
-
- SuperAdmin protection test properly validates role hierarchy
|
|
24
|
-
|
|
25
|
-
- **Invariant Tests** (24 tests fixed):
|
|
26
|
-
- Fixed `DiamondInvariants.t.sol` (13 tests) - Proper role setup and Diamond initialization
|
|
27
|
-
- Fixed `DiamondProxyInvariant.t.sol` (11 tests) - Correct facet validation and ABI matching
|
|
28
|
-
- All state invariants now properly validated
|
|
29
|
-
- Selector collision detection working correctly
|
|
30
|
-
- Facet address validation handles undeployed selectors gracefully
|
|
31
|
-
|
|
32
|
-
- **Ownership Tests** (7 tests fixed):
|
|
33
|
-
- Fixed `DiamondOwnership.t.sol` - Transfer to address(0) now correctly handled (renounce ownership)
|
|
34
|
-
- Original owner properly saved and restored in fuzz tests
|
|
35
|
-
- Double transfer and unauthorized transfer tests pass
|
|
36
|
-
- Transfer to self and contract addresses validated
|
|
37
|
-
|
|
38
|
-
- **Routing Tests** (11 tests fixed):
|
|
39
|
-
- Fixed `DiamondRouting.t.sol` - Tests skip undeployed selectors (facetAddress returns address(0))
|
|
40
|
-
- All selector routing verification tests pass
|
|
41
|
-
- Facet enumeration and function selector lookups working correctly
|
|
42
|
-
- Gas profiling for facetAddress queries fixed
|
|
43
|
-
- Standard Diamond functions (owner, facets, facetAddress) properly validated
|
|
44
|
-
|
|
45
|
-
- **Integration Tests** (11 tests fixed):
|
|
46
|
-
- Fixed `BasicDiamondIntegrationDeployed.t.sol` - Selector validation skips undeployed selectors
|
|
47
|
-
- Facet address lookup tests validate only deployed functions
|
|
48
|
-
- On-chain selector matching with validation counters
|
|
49
|
-
- All integration workflows execute successfully
|
|
50
|
-
|
|
51
|
-
- **Unit Tests** (3 tests fixed):
|
|
52
|
-
- Fixed `ExampleUnit.t.sol` - Deployer address now properly set from DiamondDeployment helper
|
|
53
|
-
- All basic unit tests validate Diamond deployment
|
|
54
|
-
|
|
55
|
-
- **POC Tests** (2 tests fixed):
|
|
56
|
-
- Fixed `JSONParseTest.t.sol` - Empty array parsing accepts both error and success outcomes
|
|
57
|
-
- Accounts for variable Forge JSON parsing behavior across versions
|
|
58
|
-
|
|
59
|
-
### Improved
|
|
60
|
-
|
|
61
|
-
- **Test Setup Patterns**:
|
|
62
|
-
- DiamondFuzzBase now provides comprehensive role granting helpers
|
|
63
|
-
- Tests consistently use `vm.prank(owner)` for privileged operations
|
|
64
|
-
- Invariant tests properly use `targetContract()` for fuzzing
|
|
65
|
-
- All tests follow best practices for isolation and cleanup
|
|
66
|
-
|
|
67
|
-
- **Selector Filtering Pattern**:
|
|
68
|
-
- Tests gracefully skip selectors not deployed on Diamond
|
|
69
|
-
- Pattern: `if (facet == address(0)) continue;` prevents false negatives
|
|
70
|
-
- Validation counters ensure at least one selector tested
|
|
71
|
-
- Comprehensive logging for debugging
|
|
72
|
-
|
|
73
|
-
- **Test Performance**:
|
|
74
|
-
- Complete test suite executes in ~8-9 seconds
|
|
75
|
-
- All 141 tests pass consistently
|
|
76
|
-
- No flaky tests or intermittent failures
|
|
77
|
-
- Production-ready reliability
|
|
78
|
-
|
|
79
|
-
### Documentation
|
|
80
|
-
|
|
81
|
-
- **README.md**:
|
|
82
|
-
- Added test status badges (141 tests passing, 100% coverage)
|
|
83
|
-
- Added comprehensive "Test Suite" section with statistics
|
|
84
|
-
- Documented test categories and execution commands
|
|
85
|
-
- Added test pattern best practices
|
|
86
|
-
|
|
87
|
-
- **Test Execution**:
|
|
88
|
-
- Verified clean workspace workflow (clean → deploy → test)
|
|
89
|
-
- Confirmed reproducible deployments and helper generation
|
|
90
|
-
- All tests pass from clean state
|
|
91
|
-
|
|
92
|
-
### Test Statistics
|
|
93
|
-
|
|
94
|
-
- **Total Tests**: 144 (141 passing, 3 skipped, 0 failed)
|
|
95
|
-
- **Test Categories**:
|
|
96
|
-
- Unit Tests: 3/3 passing
|
|
97
|
-
- Integration Tests: 14/14 passing
|
|
98
|
-
- Fuzz Tests: 93/93 passing
|
|
99
|
-
- Invariant Tests: 24/24 passing
|
|
100
|
-
- **Execution Time**: 8-9 seconds
|
|
101
|
-
- **Success Rate**: 100% (141/141)
|
|
102
|
-
|
|
103
|
-
## [Unreleased] (Previous Features)
|
|
104
|
-
|
|
105
|
-
### Added
|
|
106
|
-
|
|
107
|
-
- **Dynamic Helper Generation**: DiamondDeployment.sol now generated dynamically from deployment records
|
|
108
|
-
- No more hardcoded addresses in test helpers
|
|
109
|
-
- Automatic regeneration on each deployment
|
|
110
|
-
- Network-specific helpers for multi-network testing
|
|
111
|
-
- Helper library pattern for clean imports
|
|
112
|
-
- **Deployment Management Improvements**:
|
|
113
|
-
- Ephemeral deployment mode (default) - deploy in-memory without persisting records
|
|
114
|
-
- Persistent deployment mode - save deployment records for reuse
|
|
115
|
-
- `--save-deployment` flag to persist deployment records
|
|
116
|
-
- `--use-deployment` flag to load existing deployments
|
|
117
|
-
- `--force-deploy` flag to force redeployment
|
|
118
|
-
- Smart deployment detection and reuse
|
|
119
|
-
- **Enhanced Test Task Flags**:
|
|
120
|
-
- `--match-test <pattern>` - Filter tests by name pattern
|
|
121
|
-
- `--match-contract <contract>` - Filter tests by contract name
|
|
122
|
-
- `--match-path <path>` - Filter tests by file path
|
|
123
|
-
- `--verbosity <1-5>` - Control Forge output verbosity
|
|
124
|
-
- `--gas-report` - Display gas usage reports
|
|
125
|
-
- `--coverage` - Generate coverage reports
|
|
126
|
-
- `--skip-helpers` - Skip helper generation step
|
|
127
|
-
- `--helpers-dir <path>` - Custom helpers output directory
|
|
128
|
-
- **Snapshot/Restore Support**:
|
|
129
|
-
- `DiamondForgeHelpers.snapshotState()` - Take blockchain state snapshot
|
|
130
|
-
- `DiamondForgeHelpers.revertToSnapshot()` - Restore to saved snapshot
|
|
131
|
-
- Uses Foundry's `vm.snapshotState()` and `vm.revertToState()` (no deprecation warnings)
|
|
132
|
-
- Comprehensive snapshot examples in `SnapshotExample.t.sol`
|
|
133
|
-
- Full documentation in TESTING.md
|
|
134
|
-
- **Integration Tests**:
|
|
135
|
-
- 40+ integration tests covering all framework functionality
|
|
136
|
-
- DeploymentIntegrationTest - validates deployment management
|
|
137
|
-
- HelperGenerationTest - validates dynamic helper generation
|
|
138
|
-
- EndToEndTest - validates complete workflows
|
|
139
|
-
- DiamondABILoaderTest - validates ABI parsing
|
|
140
|
-
- ExampleIntegrationTest - demonstrates multi-facet interactions
|
|
141
|
-
- BasicDiamondIntegration - self-deploying test pattern
|
|
142
|
-
- BasicDiamondIntegrationDeployed - deployed Diamond pattern with fork-awareness
|
|
143
|
-
- SnapshotExample - snapshot/restore examples
|
|
144
|
-
- All tests pass with proper fork-awareness and graceful skipping
|
|
145
|
-
|
|
146
|
-
### Changed
|
|
147
|
-
|
|
148
|
-
- Helper generation now creates library-based helpers instead of standalone contracts
|
|
149
|
-
- Test workflows now support both ephemeral and persistent deployment modes
|
|
150
|
-
- `diamonds-forge:test` task now supports comprehensive filtering and control
|
|
151
|
-
- Fork-aware test pattern established for deployed Diamond tests
|
|
152
|
-
- Enhanced error messages with actionable troubleshooting steps
|
|
153
|
-
- Improved CI/CD compatibility with ephemeral deployments
|
|
154
|
-
|
|
155
|
-
### Documentation
|
|
156
|
-
|
|
157
|
-
- **README.md**:
|
|
158
|
-
- Added "Dynamic Helper Generation" section with examples
|
|
159
|
-
- Added "Deployment Management" section covering ephemeral vs persistent modes
|
|
160
|
-
- Added "Task Flags Reference" with all available options
|
|
161
|
-
- Added "Snapshot and Restore" section with usage examples
|
|
162
|
-
- Expanded "Troubleshooting" section with 10+ common issues and solutions
|
|
163
|
-
- Added fork-awareness patterns and best practices
|
|
164
|
-
- **TESTING.md**:
|
|
165
|
-
- Added comprehensive "Snapshot and Restore" section
|
|
166
|
-
- Added snapshot API reference
|
|
167
|
-
- Added snapshot use cases and examples
|
|
168
|
-
- Added snapshot limitations and best practices
|
|
169
|
-
- Enhanced fork-aware testing documentation
|
|
170
|
-
- All documentation updated with working examples from integration tests
|
|
171
|
-
|
|
172
|
-
### Fixed
|
|
173
|
-
|
|
174
|
-
- Helper generation now works reliably with ephemeral deployments
|
|
175
|
-
- Tests properly skip when Diamond not deployed (fork-awareness)
|
|
176
|
-
- Snapshot functions use non-deprecated Foundry APIs
|
|
177
|
-
- All integration tests pass with proper isolation
|
|
178
|
-
|
|
179
|
-
## [2.0.0] - 2024-12-16
|
|
180
|
-
|
|
181
|
-
### Breaking Changes
|
|
182
|
-
|
|
183
|
-
- **LocalDiamondDeployer Migration**: `LocalDiamondDeployer` is now imported from `@diamondslab/hardhat-diamonds` peer dependency instead of being bundled
|
|
184
|
-
- Requires `@diamondslab/hardhat-diamonds` as a peer dependency
|
|
185
|
-
- Eliminates code duplication and ensures single source of truth
|
|
186
|
-
- No API changes for users of Hardhat tasks (CLI workflow)
|
|
187
|
-
- Minimal impact on programmatic API users (just ensure peer dependency is installed)
|
|
188
|
-
- See [MIGRATION.md](./MIGRATION.md) for detailed upgrade instructions
|
|
189
|
-
|
|
190
|
-
### Added
|
|
191
|
-
|
|
192
|
-
- **Importable Helper Contracts**: Three Solidity helper contracts now available as package resources:
|
|
193
|
-
- `DiamondFuzzBase.sol`: Abstract base contract for Diamond fuzz testing with virtual functions
|
|
194
|
-
- Automatic Diamond address and ABI loading
|
|
195
|
-
- Built-in helpers: `_callDiamond()`, `_callDiamondWithValue()`, `_expectDiamondRevert()`
|
|
196
|
-
- Facet routing verification: `_verifyFacetRouting()`
|
|
197
|
-
- Gas measurement: `_measureDiamondGas()`
|
|
198
|
-
- Access control helpers: `_getDiamondOwner()`, `_hasRole()`, `_grantRole()`, `_revokeRole()`
|
|
199
|
-
- All functions are virtual for extensibility
|
|
200
|
-
- `DiamondForgeHelpers.sol`: Utility library for Diamond testing
|
|
201
|
-
- Validation: `assertValidDiamond()`, `assertValidFacet()`, `isValidTestAddress()`, `isValidTestAmount()`
|
|
202
|
-
- DiamondLoupe wrappers: `getFacetAddress()`, `getAllFacets()`, `getFacetAddresses()`, `getFacetSelectors()`
|
|
203
|
-
- Fuzzing helpers: `boundAddress()`, `boundAmount()`, `selectorsEqual()`
|
|
204
|
-
- Owner management: `getDiamondOwner()`, `assertDiamondOwner()`
|
|
205
|
-
- `DiamondABILoader.sol`: Library for loading and parsing Diamond ABI files
|
|
206
|
-
- Functions: `loadDiamondABI()`, `extractSelectors()`, `extractSignatures()`, `getFunctionInfo()`, `verifySelectorsMatch()`
|
|
207
|
-
- All helper contracts use pragma `^0.8.0` for broad Solidity version compatibility
|
|
208
|
-
- Comprehensive NatSpec documentation for all helper contract functions with usage examples
|
|
209
|
-
- Updated test templates to demonstrate helper contract imports from package path
|
|
210
|
-
|
|
211
|
-
### Changed
|
|
212
|
-
|
|
213
|
-
- `DeploymentManager` now imports `LocalDiamondDeployer` statically from `@diamondslab/hardhat-diamonds`
|
|
214
|
-
- Removed dynamic `getDeployerClass()` method in favor of direct static imports
|
|
215
|
-
- Enhanced error handling with helpful messages for missing peer dependency
|
|
216
|
-
- Updated all test templates to use `@diamondslab/diamonds-hardhat-foundry/contracts/...` imports
|
|
217
|
-
- ExampleUnitTest template now uses `DiamondForgeHelpers`
|
|
218
|
-
- ExampleIntegrationTest template now uses `DiamondForgeHelpers` and `DiamondABILoader`
|
|
219
|
-
- ExampleFuzzTest template now extends `DiamondFuzzBase`
|
|
220
|
-
|
|
221
|
-
### Fixed
|
|
222
|
-
|
|
223
|
-
- Improved TypeScript type extension loading for HardhatRuntimeEnvironment
|
|
224
|
-
- Better type safety with explicit type imports for Hardhat and Ethers types
|
|
225
|
-
- Resolved module resolution issues with proper side-effect imports
|
|
226
|
-
|
|
227
|
-
### Documentation
|
|
228
|
-
|
|
229
|
-
- Added comprehensive "Importing Helper Contracts" section to README with code examples
|
|
230
|
-
- Created [MIGRATION.md](./MIGRATION.md) with detailed v1.x to v2.0.0 upgrade guide
|
|
231
|
-
- Updated installation instructions to highlight required peer dependencies
|
|
232
|
-
- Added examples for all three helper contracts with real-world usage patterns
|
|
233
|
-
- Documented all helper contract functions with parameter descriptions
|
|
234
|
-
|
|
235
|
-
### Testing
|
|
236
|
-
|
|
237
|
-
- Verified all existing fuzz and invariant tests compile successfully
|
|
238
|
-
- Integration tests updated to use new deployment patterns
|
|
239
|
-
- All test templates generate with correct package imports
|
|
240
|
-
|
|
241
|
-
### Migration Guide
|
|
242
|
-
|
|
243
|
-
See [MIGRATION.md](./MIGRATION.md) for complete upgrade instructions, including:
|
|
244
|
-
- Breaking changes explanation
|
|
245
|
-
- Step-by-step migration guide
|
|
246
|
-
- Common scenarios and code examples
|
|
247
|
-
- Troubleshooting section
|
|
248
|
-
|
|
249
|
-
## [1.0.5] - 2025-12-16
|
|
250
|
-
|
|
251
|
-
### Fixed
|
|
252
|
-
- Fixed DeploymentManager to use `require()` instead of `import()` for better TypeScript module loading in Hardhat environment
|
|
253
|
-
- Corrected template import paths from `../../helpers/` to `../helpers/` for proper file resolution
|
|
254
|
-
- Simplified ExampleFuzz template to use standard Foundry Test helpers instead of non-existent custom functions
|
|
255
|
-
- All changes validated through full workspace integration testing
|
|
256
|
-
|
|
257
|
-
## [1.0.4] - 2025-12-16
|
|
258
|
-
|
|
259
|
-
### Fixed
|
|
260
|
-
- Templates from `src/templates/` are now properly copied to `dist/templates/` during build
|
|
261
|
-
- Added `copy-templates` script to ensure all `.template` files are included in the published package
|
|
262
|
-
|
|
263
|
-
## [1.0.0] - 2025-12-15
|
|
264
|
-
|
|
265
|
-
Initial public release of `@diamondslab/diamonds-hardhat-foundry`.
|
|
266
|
-
|
|
267
|
-
### Added
|
|
268
|
-
- Initial release of `@diamondslab/diamonds-hardhat-foundry`
|
|
269
|
-
- Core framework classes for Diamond deployment and testing:
|
|
270
|
-
- `DeploymentManager` - Manages Diamond contract deployments
|
|
271
|
-
- `HelperGenerator` - Generates Solidity test helpers and scaffolding
|
|
272
|
-
- `ForgeFuzzingFramework` - Orchestrates complete test workflows
|
|
273
|
-
- Four Hardhat tasks for Diamond + Foundry workflow:
|
|
274
|
-
- `diamonds-forge:init` - Initialize test directory structure
|
|
275
|
-
- `diamonds-forge:deploy` - Deploy Diamond contracts
|
|
276
|
-
- `diamonds-forge:generate-helpers` - Generate DiamondDeployment.sol helpers
|
|
277
|
-
- `diamonds-forge:test` - Run Foundry tests with deployment orchestration
|
|
278
|
-
- Base Solidity contracts for testing:
|
|
279
|
-
- `DiamondForgeHelpers.sol` - Utility functions for Diamond testing
|
|
280
|
-
- `DiamondFuzzBase.sol` - Abstract base contract for fuzz tests
|
|
281
|
-
- Template system for generating:
|
|
282
|
-
- `DiamondDeployment.sol` - Generated deployment data helper
|
|
283
|
-
- Example unit tests (`ExampleUnitTest.t.sol`)
|
|
284
|
-
- Example integration tests (`ExampleIntegrationTest.t.sol`)
|
|
285
|
-
- Example fuzz tests (`ExampleFuzzTest.t.sol`)
|
|
286
|
-
- Configuration system via `hardhat.config.ts`:
|
|
287
|
-
- `diamondsFoundry.helpersDir` - Configure helper output directory
|
|
288
|
-
- `diamondsFoundry.generateExamples` - Toggle example generation
|
|
289
|
-
- `diamondsFoundry.exampleTests` - Select example test types
|
|
290
|
-
- `diamondsFoundry.defaultNetwork` - Set default deployment network
|
|
291
|
-
- `diamondsFoundry.reuseDeployment` - Enable deployment reuse
|
|
292
|
-
- `diamondsFoundry.forgeTestArgs` - Default Forge test arguments
|
|
293
|
-
- Comprehensive validation:
|
|
294
|
-
- Foundry installation check
|
|
295
|
-
- Peer dependency validation
|
|
296
|
-
- Configuration validation with helpful error messages
|
|
297
|
-
- Colored logging with `picocolors` for better UX
|
|
298
|
-
- Integration with `@diamondslab/diamonds` ecosystem:
|
|
299
|
-
- Uses `LocalDiamondDeployer` from workspace
|
|
300
|
-
- Reads deployment records from Diamond deployments
|
|
301
|
-
- Compatible with `@diamondslab/hardhat-diamonds` configuration
|
|
302
|
-
- Comprehensive documentation:
|
|
303
|
-
- Full README with Quick Start guide
|
|
304
|
-
- API documentation for all classes and methods
|
|
305
|
-
- Configuration reference with all options
|
|
306
|
-
- Usage examples and workflows
|
|
307
|
-
- Troubleshooting guide
|
|
308
|
-
- Integration guide for existing projects
|
|
309
|
-
|
|
310
|
-
### Testing
|
|
311
|
-
- 61 unit tests covering:
|
|
312
|
-
- Framework class functionality
|
|
313
|
-
- Configuration validation
|
|
314
|
-
- Helper generation
|
|
315
|
-
- Deployment management
|
|
316
|
-
- Error handling
|
|
317
|
-
- Integration tests:
|
|
318
|
-
- Solidity integration tests for workflow verification
|
|
319
|
-
- TypeScript integration tests for API validation
|
|
320
|
-
|
|
321
|
-
[1.0.0]: https://github.com/diamondslab/diamonds-hardhat-foundry/releases/tag/v1.0.0
|