@diamondslab/diamonds-hardhat-foundry 1.0.3 → 2.1.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.
Files changed (58) hide show
  1. package/CHANGELOG.md +154 -0
  2. package/README.md +568 -4
  3. package/contracts/DiamondABILoader.sol +329 -0
  4. package/contracts/DiamondForgeHelpers.sol +309 -85
  5. package/contracts/DiamondFuzzBase.sol +305 -114
  6. package/dist/foundry.d.ts +28 -0
  7. package/dist/foundry.d.ts.map +1 -1
  8. package/dist/foundry.js +82 -1
  9. package/dist/foundry.js.map +1 -1
  10. package/dist/framework/DeploymentManager.d.ts +10 -11
  11. package/dist/framework/DeploymentManager.d.ts.map +1 -1
  12. package/dist/framework/DeploymentManager.js +56 -45
  13. package/dist/framework/DeploymentManager.js.map +1 -1
  14. package/dist/framework/ForgeFuzzingFramework.d.ts +4 -0
  15. package/dist/framework/ForgeFuzzingFramework.d.ts.map +1 -1
  16. package/dist/framework/ForgeFuzzingFramework.js +16 -2
  17. package/dist/framework/ForgeFuzzingFramework.js.map +1 -1
  18. package/dist/framework/HelperGenerator.d.ts.map +1 -1
  19. package/dist/framework/HelperGenerator.js +11 -0
  20. package/dist/framework/HelperGenerator.js.map +1 -1
  21. package/dist/index.d.ts +0 -3
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +0 -8
  24. package/dist/index.js.map +1 -1
  25. package/dist/tasks/deploy.js +3 -2
  26. package/dist/tasks/deploy.js.map +1 -1
  27. package/dist/tasks/generate-helpers.js +6 -4
  28. package/dist/tasks/generate-helpers.js.map +1 -1
  29. package/dist/tasks/init.js +3 -2
  30. package/dist/tasks/init.js.map +1 -1
  31. package/dist/tasks/test.js +13 -2
  32. package/dist/tasks/test.js.map +1 -1
  33. package/dist/templates/ExampleFuzzTest.t.sol.template +26 -17
  34. package/dist/templates/ExampleIntegrationTest.t.sol.template +9 -1
  35. package/dist/templates/ExampleUnitTest.t.sol.template +7 -1
  36. package/dist/types/hardhat.d.ts +1 -1
  37. package/dist/types/hardhat.d.ts.map +1 -1
  38. package/dist/types/hardhat.js +1 -0
  39. package/dist/types/hardhat.js.map +1 -1
  40. package/dist/utils/foundry.d.ts +1 -0
  41. package/dist/utils/foundry.d.ts.map +1 -1
  42. package/dist/utils/foundry.js +3 -0
  43. package/dist/utils/foundry.js.map +1 -1
  44. package/package.json +5 -3
  45. package/src/foundry.ts +104 -0
  46. package/src/framework/DeploymentManager.ts +74 -69
  47. package/src/framework/ForgeFuzzingFramework.ts +23 -1
  48. package/src/framework/HelperGenerator.ts +13 -0
  49. package/src/index.ts +0 -5
  50. package/src/tasks/deploy.ts +3 -1
  51. package/src/tasks/generate-helpers.ts +6 -2
  52. package/src/tasks/init.ts +3 -1
  53. package/src/tasks/test.ts +12 -1
  54. package/src/templates/ExampleFuzzTest.t.sol.template +26 -17
  55. package/src/templates/ExampleIntegrationTest.t.sol.template +9 -1
  56. package/src/templates/ExampleUnitTest.t.sol.template +7 -1
  57. package/src/types/hardhat.ts +1 -1
  58. package/src/utils/foundry.ts +5 -0
package/CHANGELOG.md CHANGED
@@ -5,6 +5,160 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [Unreleased]
9
+
10
+ ### Added
11
+
12
+ - **Dynamic Helper Generation**: DiamondDeployment.sol now generated dynamically from deployment records
13
+ - No more hardcoded addresses in test helpers
14
+ - Automatic regeneration on each deployment
15
+ - Network-specific helpers for multi-network testing
16
+ - Helper library pattern for clean imports
17
+ - **Deployment Management Improvements**:
18
+ - Ephemeral deployment mode (default) - deploy in-memory without persisting records
19
+ - Persistent deployment mode - save deployment records for reuse
20
+ - `--save-deployment` flag to persist deployment records
21
+ - `--use-deployment` flag to load existing deployments
22
+ - `--force-deploy` flag to force redeployment
23
+ - Smart deployment detection and reuse
24
+ - **Enhanced Test Task Flags**:
25
+ - `--match-test <pattern>` - Filter tests by name pattern
26
+ - `--match-contract <contract>` - Filter tests by contract name
27
+ - `--match-path <path>` - Filter tests by file path
28
+ - `--verbosity <1-5>` - Control Forge output verbosity
29
+ - `--gas-report` - Display gas usage reports
30
+ - `--coverage` - Generate coverage reports
31
+ - `--skip-helpers` - Skip helper generation step
32
+ - `--helpers-dir <path>` - Custom helpers output directory
33
+ - **Snapshot/Restore Support**:
34
+ - `DiamondForgeHelpers.snapshotState()` - Take blockchain state snapshot
35
+ - `DiamondForgeHelpers.revertToSnapshot()` - Restore to saved snapshot
36
+ - Uses Foundry's `vm.snapshotState()` and `vm.revertToState()` (no deprecation warnings)
37
+ - Comprehensive snapshot examples in `SnapshotExample.t.sol`
38
+ - Full documentation in TESTING.md
39
+ - **Integration Tests**:
40
+ - 40+ integration tests covering all framework functionality
41
+ - DeploymentIntegrationTest - validates deployment management
42
+ - HelperGenerationTest - validates dynamic helper generation
43
+ - EndToEndTest - validates complete workflows
44
+ - DiamondABILoaderTest - validates ABI parsing
45
+ - ExampleIntegrationTest - demonstrates multi-facet interactions
46
+ - BasicDiamondIntegration - self-deploying test pattern
47
+ - BasicDiamondIntegrationDeployed - deployed Diamond pattern with fork-awareness
48
+ - SnapshotExample - snapshot/restore examples
49
+ - All tests pass with proper fork-awareness and graceful skipping
50
+
51
+ ### Changed
52
+
53
+ - Helper generation now creates library-based helpers instead of standalone contracts
54
+ - Test workflows now support both ephemeral and persistent deployment modes
55
+ - `diamonds-forge:test` task now supports comprehensive filtering and control
56
+ - Fork-aware test pattern established for deployed Diamond tests
57
+ - Enhanced error messages with actionable troubleshooting steps
58
+ - Improved CI/CD compatibility with ephemeral deployments
59
+
60
+ ### Documentation
61
+
62
+ - **README.md**:
63
+ - Added "Dynamic Helper Generation" section with examples
64
+ - Added "Deployment Management" section covering ephemeral vs persistent modes
65
+ - Added "Task Flags Reference" with all available options
66
+ - Added "Snapshot and Restore" section with usage examples
67
+ - Expanded "Troubleshooting" section with 10+ common issues and solutions
68
+ - Added fork-awareness patterns and best practices
69
+ - **TESTING.md**:
70
+ - Added comprehensive "Snapshot and Restore" section
71
+ - Added snapshot API reference
72
+ - Added snapshot use cases and examples
73
+ - Added snapshot limitations and best practices
74
+ - Enhanced fork-aware testing documentation
75
+ - All documentation updated with working examples from integration tests
76
+
77
+ ### Fixed
78
+
79
+ - Helper generation now works reliably with ephemeral deployments
80
+ - Tests properly skip when Diamond not deployed (fork-awareness)
81
+ - Snapshot functions use non-deprecated Foundry APIs
82
+ - All integration tests pass with proper isolation
83
+
84
+ ## [2.0.0] - 2024-12-16
85
+
86
+ ### Breaking Changes
87
+
88
+ - **LocalDiamondDeployer Migration**: `LocalDiamondDeployer` is now imported from `@diamondslab/hardhat-diamonds` peer dependency instead of being bundled
89
+ - Requires `@diamondslab/hardhat-diamonds` as a peer dependency
90
+ - Eliminates code duplication and ensures single source of truth
91
+ - No API changes for users of Hardhat tasks (CLI workflow)
92
+ - Minimal impact on programmatic API users (just ensure peer dependency is installed)
93
+ - See [MIGRATION.md](./MIGRATION.md) for detailed upgrade instructions
94
+
95
+ ### Added
96
+
97
+ - **Importable Helper Contracts**: Three Solidity helper contracts now available as package resources:
98
+ - `DiamondFuzzBase.sol`: Abstract base contract for Diamond fuzz testing with virtual functions
99
+ - Automatic Diamond address and ABI loading
100
+ - Built-in helpers: `_callDiamond()`, `_callDiamondWithValue()`, `_expectDiamondRevert()`
101
+ - Facet routing verification: `_verifyFacetRouting()`
102
+ - Gas measurement: `_measureDiamondGas()`
103
+ - Access control helpers: `_getDiamondOwner()`, `_hasRole()`, `_grantRole()`, `_revokeRole()`
104
+ - All functions are virtual for extensibility
105
+ - `DiamondForgeHelpers.sol`: Utility library for Diamond testing
106
+ - Validation: `assertValidDiamond()`, `assertValidFacet()`, `isValidTestAddress()`, `isValidTestAmount()`
107
+ - DiamondLoupe wrappers: `getFacetAddress()`, `getAllFacets()`, `getFacetAddresses()`, `getFacetSelectors()`
108
+ - Fuzzing helpers: `boundAddress()`, `boundAmount()`, `selectorsEqual()`
109
+ - Owner management: `getDiamondOwner()`, `assertDiamondOwner()`
110
+ - `DiamondABILoader.sol`: Library for loading and parsing Diamond ABI files
111
+ - Functions: `loadDiamondABI()`, `extractSelectors()`, `extractSignatures()`, `getFunctionInfo()`, `verifySelectorsMatch()`
112
+ - All helper contracts use pragma `^0.8.0` for broad Solidity version compatibility
113
+ - Comprehensive NatSpec documentation for all helper contract functions with usage examples
114
+ - Updated test templates to demonstrate helper contract imports from package path
115
+
116
+ ### Changed
117
+
118
+ - `DeploymentManager` now imports `LocalDiamondDeployer` statically from `@diamondslab/hardhat-diamonds`
119
+ - Removed dynamic `getDeployerClass()` method in favor of direct static imports
120
+ - Enhanced error handling with helpful messages for missing peer dependency
121
+ - Updated all test templates to use `@diamondslab/diamonds-hardhat-foundry/contracts/...` imports
122
+ - ExampleUnitTest template now uses `DiamondForgeHelpers`
123
+ - ExampleIntegrationTest template now uses `DiamondForgeHelpers` and `DiamondABILoader`
124
+ - ExampleFuzzTest template now extends `DiamondFuzzBase`
125
+
126
+ ### Fixed
127
+
128
+ - Improved TypeScript type extension loading for HardhatRuntimeEnvironment
129
+ - Better type safety with explicit type imports for Hardhat and Ethers types
130
+ - Resolved module resolution issues with proper side-effect imports
131
+
132
+ ### Documentation
133
+
134
+ - Added comprehensive "Importing Helper Contracts" section to README with code examples
135
+ - Created [MIGRATION.md](./MIGRATION.md) with detailed v1.x to v2.0.0 upgrade guide
136
+ - Updated installation instructions to highlight required peer dependencies
137
+ - Added examples for all three helper contracts with real-world usage patterns
138
+ - Documented all helper contract functions with parameter descriptions
139
+
140
+ ### Testing
141
+
142
+ - Verified all existing fuzz and invariant tests compile successfully
143
+ - Integration tests updated to use new deployment patterns
144
+ - All test templates generate with correct package imports
145
+
146
+ ### Migration Guide
147
+
148
+ See [MIGRATION.md](./MIGRATION.md) for complete upgrade instructions, including:
149
+ - Breaking changes explanation
150
+ - Step-by-step migration guide
151
+ - Common scenarios and code examples
152
+ - Troubleshooting section
153
+
154
+ ## [1.0.5] - 2025-12-16
155
+
156
+ ### Fixed
157
+ - Fixed DeploymentManager to use `require()` instead of `import()` for better TypeScript module loading in Hardhat environment
158
+ - Corrected template import paths from `../../helpers/` to `../helpers/` for proper file resolution
159
+ - Simplified ExampleFuzz template to use standard Foundry Test helpers instead of non-existent custom functions
160
+ - All changes validated through full workspace integration testing
161
+
8
162
  ## [1.0.4] - 2025-12-16
9
163
 
10
164
  ### Fixed