@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 CHANGED
@@ -14,7 +14,8 @@ Hardhat plugin that seamlessly integrates Foundry testing with [ERC-2535 Diamond
14
14
  - ๐Ÿš€ **Automated Diamond Deployment** - Deploy Diamond contracts with a single command
15
15
  - ๐Ÿ“ **Helper Generation** - Automatically generate Solidity helpers with deployment data
16
16
  - ๐Ÿงช **Test Scaffolding** - Create unit, integration, and fuzz test templates
17
- - ๐Ÿ”ง **Hardhat Tasks** - CLI tasks for init, deploy, generate, and test workflows
17
+ - ๏ฟฝ **Coverage Testing** - Run forge coverage with full Diamond integration and multiple report formats
18
+ - ๐Ÿ”ง **Hardhat Tasks** - CLI tasks for init, deploy, generate, test, and coverage workflows
18
19
  - ๐ŸŽฏ **Programmatic API** - Use framework classes directly in scripts
19
20
  - ๐Ÿ“š **Base Contracts** - Reusable Solidity utilities and test base classes
20
21
  - โšก **Foundry Integration** - Leverage Forge's speed and fuzzing capabilities
@@ -342,6 +343,80 @@ npx hardhat diamonds-forge:test --match-test "testOwnership" --verbosity 4
342
343
  npx hardhat diamonds-forge:test --skip-deployment --match-contract "MyTest"
343
344
  ```
344
345
 
346
+ ### `diamonds-forge:coverage`
347
+
348
+ Run forge coverage for your Diamond contracts with full integration support.
349
+
350
+ **Important:** Coverage requires a deployed Diamond on a persistent network (like localhost). See workflow below.
351
+
352
+ **Options:**
353
+
354
+ - `--diamond-name <name>` - Diamond to analyze (default: from config)
355
+ - `--network <name>` - Network for deployment (default: from config)
356
+ - `--report <format>` - Report format: summary, lcov, debug, bytecode (default: summary)
357
+ - `--report-file <path>` - Output file for coverage report
358
+ - `--lcov-version <version>` - LCOV version for LCOV reports (default: v1)
359
+ - `--match-test <pattern>` - Run tests matching pattern
360
+ - `--match-contract <pattern>` - Run tests in matching contracts
361
+ - `--match-path <glob>` - Run tests in files matching glob
362
+ - `--no-match-test <pattern>` - Skip tests matching pattern
363
+ - `--no-match-contract <pattern>` - Skip tests in matching contracts
364
+ - `--no-match-path <glob>` - Skip tests in files matching glob
365
+ - `--no-match-coverage <pattern>` - Exclude contracts from coverage
366
+ - `--verbosity <level>` - Verbosity level: 0-5 (default: 0)
367
+ - `--color <mode>` - Color output: auto, always, never (default: auto)
368
+ - And many more options for filtering, optimization, and EVM configuration
369
+
370
+ **Workflow (Required):**
371
+
372
+ ```bash
373
+ # Step 1: Start Hardhat node (persistent network)
374
+ npx hardhat node
375
+
376
+ # Step 2: Deploy Diamond to localhost network (in another terminal)
377
+ npx hardhat diamonds-forge:deploy --diamond-name MyDiamond --network localhost
378
+
379
+ # Step 3: Run coverage against deployed Diamond
380
+ npx hardhat diamonds-forge:coverage --diamond-name MyDiamond --network localhost
381
+ ```
382
+
383
+ **Examples:**
384
+
385
+ ```bash
386
+ # Basic coverage with default summary
387
+ npx hardhat diamonds-forge:coverage --diamond-name MyDiamond --network localhost
388
+
389
+ # Generate LCOV report for CI/CD
390
+ npx hardhat diamonds-forge:coverage \
391
+ --diamond-name MyDiamond \
392
+ --network localhost \
393
+ --report lcov \
394
+ --report-file coverage/lcov.info
395
+
396
+ # Coverage for specific test patterns
397
+ npx hardhat diamonds-forge:coverage \
398
+ --diamond-name MyDiamond \
399
+ --network localhost \
400
+ --match-contract "Unit" \
401
+ --verbosity 2
402
+
403
+ # Multiple report formats
404
+ npx hardhat diamonds-forge:coverage \
405
+ --diamond-name MyDiamond \
406
+ --network localhost \
407
+ --report summary \
408
+ --report lcov \
409
+ --report debug
410
+ ```
411
+
412
+ **Important Notes:**
413
+ - Always specify `--network localhost` (coverage needs deployed contracts)
414
+ - Cannot use `--network hardhat` (ephemeral in-memory network)
415
+ - Diamond must be deployed before running coverage
416
+ - Same workflow as `diamonds-forge:test` - both require persistent network
417
+
418
+ **See the [Coverage Guide](../../docs/FOUNDRY_FORGE_DIAMONDS_COVERAGE.md) for complete documentation, CI/CD integration examples, and best practices.**
419
+
345
420
  ## Dynamic Helper Generation
346
421
 
347
422
  Version 2.0.0+ introduces **dynamic helper generation** that creates deployment-specific Solidity helpers without hardcoded addresses.
@@ -0,0 +1,61 @@
1
+ import { HardhatRuntimeEnvironment } from "hardhat/types";
2
+ import { CoverageOptions } from "../types/config";
3
+ /**
4
+ * ForgeCoverageFramework - Orchestrates forge coverage execution for Diamond contracts
5
+ *
6
+ * Responsibilities:
7
+ * 1. Build forge coverage command with all options
8
+ * 2. Execute forge coverage with proper fork URL
9
+ * 3. Stream output to terminal
10
+ * 4. Handle errors appropriately
11
+ */
12
+ export declare class ForgeCoverageFramework {
13
+ private hre;
14
+ constructor(hre: HardhatRuntimeEnvironment);
15
+ /**
16
+ * Run forge coverage with provided options
17
+ *
18
+ * @param options - Coverage execution options
19
+ * @returns Promise<boolean> - true if coverage succeeds, false otherwise
20
+ */
21
+ runCoverage(options?: CoverageOptions): Promise<boolean>;
22
+ /**
23
+ * Build complete forge coverage command arguments
24
+ *
25
+ * @param options - Coverage options
26
+ * @returns Array of command arguments
27
+ */
28
+ private buildCoverageCommand;
29
+ /**
30
+ * Build report-related options
31
+ */
32
+ private buildReportOptions;
33
+ /**
34
+ * Build test filtering options
35
+ */
36
+ private buildFilterOptions;
37
+ /**
38
+ * Build display options
39
+ */
40
+ private buildDisplayOptions;
41
+ /**
42
+ * Build test execution options
43
+ */
44
+ private buildTestOptions;
45
+ /**
46
+ * Build EVM options
47
+ */
48
+ private buildEvmOptions;
49
+ /**
50
+ * Build build options
51
+ */
52
+ private buildBuildOptions;
53
+ /**
54
+ * Execute forge coverage command and stream output
55
+ *
56
+ * @param args - Command arguments
57
+ * @returns Promise<boolean> - true if command succeeds
58
+ */
59
+ private executeForge;
60
+ }
61
+ //# sourceMappingURL=ForgeCoverageFramework.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ForgeCoverageFramework.d.ts","sourceRoot":"","sources":["../../src/framework/ForgeCoverageFramework.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAGlD;;;;;;;;GAQG;AACH,qBAAa,sBAAsB;IACrB,OAAO,CAAC,GAAG;gBAAH,GAAG,EAAE,yBAAyB;IAElD;;;;;OAKG;IACG,WAAW,CAAC,OAAO,GAAE,eAAoB,GAAG,OAAO,CAAC,OAAO,CAAC;IA0BlE;;;;;OAKG;IACH,OAAO,CAAC,oBAAoB;IAmB5B;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAiC1B;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAkC1B;;OAEG;IACH,OAAO,CAAC,mBAAmB;IA2B3B;;OAEG;IACH,OAAO,CAAC,gBAAgB;IA0BxB;;OAEG;IACH,OAAO,CAAC,eAAe;IAsBvB;;OAEG;IACH,OAAO,CAAC,iBAAiB;IA0BzB;;;;;OAKG;IACH,OAAO,CAAC,YAAY;CAoBrB"}
@@ -0,0 +1,238 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ForgeCoverageFramework = void 0;
4
+ const child_process_1 = require("child_process");
5
+ const logger_1 = require("../utils/logger");
6
+ /**
7
+ * ForgeCoverageFramework - Orchestrates forge coverage execution for Diamond contracts
8
+ *
9
+ * Responsibilities:
10
+ * 1. Build forge coverage command with all options
11
+ * 2. Execute forge coverage with proper fork URL
12
+ * 3. Stream output to terminal
13
+ * 4. Handle errors appropriately
14
+ */
15
+ class ForgeCoverageFramework {
16
+ hre;
17
+ constructor(hre) {
18
+ this.hre = hre;
19
+ }
20
+ /**
21
+ * Run forge coverage with provided options
22
+ *
23
+ * @param options - Coverage execution options
24
+ * @returns Promise<boolean> - true if coverage succeeds, false otherwise
25
+ */
26
+ async runCoverage(options = {}) {
27
+ logger_1.Logger.section("Forge Coverage - Execution");
28
+ try {
29
+ // Build command arguments
30
+ const args = this.buildCoverageCommand(options);
31
+ logger_1.Logger.info(`Executing: forge coverage ${args.join(" ")}`);
32
+ logger_1.Logger.info("โณ Running coverage analysis (this may take a while)...\n");
33
+ // Execute forge coverage
34
+ const success = await this.executeForge(args);
35
+ if (success) {
36
+ logger_1.Logger.success("โœ… Coverage analysis completed successfully");
37
+ }
38
+ else {
39
+ logger_1.Logger.error("โŒ Coverage analysis failed");
40
+ }
41
+ return success;
42
+ }
43
+ catch (error) {
44
+ logger_1.Logger.error(`Coverage execution error: ${error.message}`);
45
+ return false;
46
+ }
47
+ }
48
+ /**
49
+ * Build complete forge coverage command arguments
50
+ *
51
+ * @param options - Coverage options
52
+ * @returns Array of command arguments
53
+ */
54
+ buildCoverageCommand(options) {
55
+ const args = [];
56
+ // Add fork URL if provided
57
+ if (options.forkUrl) {
58
+ args.push("--fork-url", options.forkUrl);
59
+ }
60
+ // Add all option groups
61
+ args.push(...this.buildReportOptions(options));
62
+ args.push(...this.buildFilterOptions(options));
63
+ args.push(...this.buildDisplayOptions(options));
64
+ args.push(...this.buildTestOptions(options));
65
+ args.push(...this.buildEvmOptions(options));
66
+ args.push(...this.buildBuildOptions(options));
67
+ return args.filter((arg) => arg !== "");
68
+ }
69
+ /**
70
+ * Build report-related options
71
+ */
72
+ buildReportOptions(options) {
73
+ const args = [];
74
+ // Multiple --report flags
75
+ if (options.report && options.report.length > 0) {
76
+ options.report.forEach((reportType) => {
77
+ args.push("--report", reportType);
78
+ });
79
+ }
80
+ if (options.reportFile) {
81
+ args.push("--report-file", options.reportFile);
82
+ }
83
+ if (options.lcovVersion) {
84
+ args.push("--lcov-version", options.lcovVersion);
85
+ }
86
+ if (options.includeLibs) {
87
+ args.push("--include-libs");
88
+ }
89
+ if (options.excludeTests) {
90
+ args.push("--exclude-tests");
91
+ }
92
+ if (options.irMinimum) {
93
+ args.push("--ir-minimum");
94
+ }
95
+ return args;
96
+ }
97
+ /**
98
+ * Build test filtering options
99
+ */
100
+ buildFilterOptions(options) {
101
+ const args = [];
102
+ if (options.matchTest) {
103
+ args.push("--match-test", options.matchTest);
104
+ }
105
+ if (options.noMatchTest) {
106
+ args.push("--no-match-test", options.noMatchTest);
107
+ }
108
+ if (options.matchContract) {
109
+ args.push("--match-contract", options.matchContract);
110
+ }
111
+ if (options.noMatchContract) {
112
+ args.push("--no-match-contract", options.noMatchContract);
113
+ }
114
+ if (options.matchPath) {
115
+ args.push("--match-path", options.matchPath);
116
+ }
117
+ if (options.noMatchPath) {
118
+ args.push("--no-match-path", options.noMatchPath);
119
+ }
120
+ if (options.noMatchCoverage) {
121
+ args.push("--no-match-coverage", options.noMatchCoverage);
122
+ }
123
+ return args;
124
+ }
125
+ /**
126
+ * Build display options
127
+ */
128
+ buildDisplayOptions(options) {
129
+ const args = [];
130
+ // Verbosity (-v, -vv, -vvv, etc.)
131
+ if (options.verbosity && options.verbosity > 0) {
132
+ args.push("-" + "v".repeat(options.verbosity));
133
+ }
134
+ if (options.quiet) {
135
+ args.push("--quiet");
136
+ }
137
+ if (options.json) {
138
+ args.push("--json");
139
+ }
140
+ if (options.md) {
141
+ args.push("--md");
142
+ }
143
+ if (options.color) {
144
+ args.push("--color", options.color);
145
+ }
146
+ return args;
147
+ }
148
+ /**
149
+ * Build test execution options
150
+ */
151
+ buildTestOptions(options) {
152
+ const args = [];
153
+ if (options.threads !== undefined) {
154
+ args.push("--threads", options.threads.toString());
155
+ }
156
+ if (options.fuzzRuns !== undefined) {
157
+ args.push("--fuzz-runs", options.fuzzRuns.toString());
158
+ }
159
+ if (options.fuzzSeed) {
160
+ args.push("--fuzz-seed", options.fuzzSeed);
161
+ }
162
+ if (options.failFast) {
163
+ args.push("--fail-fast");
164
+ }
165
+ if (options.allowFailure) {
166
+ args.push("--allow-failure");
167
+ }
168
+ return args;
169
+ }
170
+ /**
171
+ * Build EVM options
172
+ */
173
+ buildEvmOptions(options) {
174
+ const args = [];
175
+ if (options.forkBlockNumber !== undefined) {
176
+ args.push("--fork-block-number", options.forkBlockNumber.toString());
177
+ }
178
+ if (options.initialBalance) {
179
+ args.push("--initial-balance", options.initialBalance);
180
+ }
181
+ if (options.sender) {
182
+ args.push("--sender", options.sender);
183
+ }
184
+ if (options.ffi) {
185
+ args.push("--ffi");
186
+ }
187
+ return args;
188
+ }
189
+ /**
190
+ * Build build options
191
+ */
192
+ buildBuildOptions(options) {
193
+ const args = [];
194
+ if (options.force) {
195
+ args.push("--force");
196
+ }
197
+ if (options.noCache) {
198
+ args.push("--no-cache");
199
+ }
200
+ if (options.optimize) {
201
+ args.push("--optimize");
202
+ }
203
+ if (options.optimizerRuns !== undefined) {
204
+ args.push("--optimizer-runs", options.optimizerRuns.toString());
205
+ }
206
+ if (options.viaIr) {
207
+ args.push("--via-ir");
208
+ }
209
+ return args;
210
+ }
211
+ /**
212
+ * Execute forge coverage command and stream output
213
+ *
214
+ * @param args - Command arguments
215
+ * @returns Promise<boolean> - true if command succeeds
216
+ */
217
+ executeForge(args) {
218
+ return new Promise((resolve, reject) => {
219
+ const forgeProcess = (0, child_process_1.spawn)("forge", ["coverage", ...args], {
220
+ cwd: this.hre.config.paths.root,
221
+ stdio: "inherit", // Stream output directly to terminal
222
+ });
223
+ forgeProcess.on("close", (code) => {
224
+ if (code === 0) {
225
+ resolve(true);
226
+ }
227
+ else {
228
+ resolve(false);
229
+ }
230
+ });
231
+ forgeProcess.on("error", (error) => {
232
+ reject(new Error(`Failed to execute forge coverage: ${error.message}`));
233
+ });
234
+ });
235
+ }
236
+ }
237
+ exports.ForgeCoverageFramework = ForgeCoverageFramework;
238
+ //# sourceMappingURL=ForgeCoverageFramework.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ForgeCoverageFramework.js","sourceRoot":"","sources":["../../src/framework/ForgeCoverageFramework.ts"],"names":[],"mappings":";;;AAAA,iDAAsC;AAGtC,4CAAyC;AAEzC;;;;;;;;GAQG;AACH,MAAa,sBAAsB;IACb;IAApB,YAAoB,GAA8B;QAA9B,QAAG,GAAH,GAAG,CAA2B;IAAG,CAAC;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AE,GAAG,IAAI,CAAC,EAAE;gBACzD,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI;gBAC/B,KAAK,EAAE,SAAS,EAAE,qCAAqC;aACxD,CAAC,CAAC;YAEH,YAAY,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE;gBAChC,IAAI,IAAI,KAAK,CAAC,EAAE;oBACd,OAAO,CAAC,IAAI,CAAC,CAAC;iBACf;qBAAM;oBACL,OAAO,CAAC,KAAK,CAAC,CAAC;iBAChB;YACH,CAAC,CAAC,CAAC;YAEH,YAAY,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;gBACjC,MAAM,CAAC,IAAI,KAAK,CAAC,qCAAqC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;YAC1E,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAhRD,wDAgRC","sourcesContent":["import { spawn } from \"child_process\";\nimport { HardhatRuntimeEnvironment } from \"hardhat/types\";\nimport { CoverageOptions } from \"../types/config\";\nimport { Logger } from \"../utils/logger\";\n\n/**\n * ForgeCoverageFramework - Orchestrates forge coverage execution for Diamond contracts\n *\n * Responsibilities:\n * 1. Build forge coverage command with all options\n * 2. Execute forge coverage with proper fork URL\n * 3. Stream output to terminal\n * 4. Handle errors appropriately\n */\nexport class ForgeCoverageFramework {\n constructor(private hre: HardhatRuntimeEnvironment) {}\n\n /**\n * Run forge coverage with provided options\n *\n * @param options - Coverage execution options\n * @returns Promise<boolean> - true if coverage succeeds, false otherwise\n */\n async runCoverage(options: CoverageOptions = {}): Promise<boolean> {\n Logger.section(\"Forge Coverage - Execution\");\n\n try {\n // Build command arguments\n const args = this.buildCoverageCommand(options);\n\n Logger.info(`Executing: forge coverage ${args.join(\" \")}`);\n Logger.info(\"โณ Running coverage analysis (this may take a while)...\\n\");\n\n // Execute forge coverage\n const success = await this.executeForge(args);\n\n if (success) {\n Logger.success(\"โœ… Coverage analysis completed successfully\");\n } else {\n Logger.error(\"โŒ Coverage analysis failed\");\n }\n\n return success;\n } catch (error: any) {\n Logger.error(`Coverage execution error: ${error.message}`);\n return false;\n }\n }\n\n /**\n * Build complete forge coverage command arguments\n *\n * @param options - Coverage options\n * @returns Array of command arguments\n */\n private buildCoverageCommand(options: CoverageOptions): string[] {\n const args: string[] = [];\n\n // Add fork URL if provided\n if (options.forkUrl) {\n args.push(\"--fork-url\", options.forkUrl);\n }\n\n // Add all option groups\n args.push(...this.buildReportOptions(options));\n args.push(...this.buildFilterOptions(options));\n args.push(...this.buildDisplayOptions(options));\n args.push(...this.buildTestOptions(options));\n args.push(...this.buildEvmOptions(options));\n args.push(...this.buildBuildOptions(options));\n\n return args.filter((arg) => arg !== \"\");\n }\n\n /**\n * Build report-related options\n */\n private buildReportOptions(options: CoverageOptions): string[] {\n const args: string[] = [];\n\n // Multiple --report flags\n if (options.report && options.report.length > 0) {\n options.report.forEach((reportType) => {\n args.push(\"--report\", reportType);\n });\n }\n\n if (options.reportFile) {\n args.push(\"--report-file\", options.reportFile);\n }\n\n if (options.lcovVersion) {\n args.push(\"--lcov-version\", options.lcovVersion);\n }\n\n if (options.includeLibs) {\n args.push(\"--include-libs\");\n }\n\n if (options.excludeTests) {\n args.push(\"--exclude-tests\");\n }\n\n if (options.irMinimum) {\n args.push(\"--ir-minimum\");\n }\n\n return args;\n }\n\n /**\n * Build test filtering options\n */\n private buildFilterOptions(options: CoverageOptions): string[] {\n const args: string[] = [];\n\n if (options.matchTest) {\n args.push(\"--match-test\", options.matchTest);\n }\n\n if (options.noMatchTest) {\n args.push(\"--no-match-test\", options.noMatchTest);\n }\n\n if (options.matchContract) {\n args.push(\"--match-contract\", options.matchContract);\n }\n\n if (options.noMatchContract) {\n args.push(\"--no-match-contract\", options.noMatchContract);\n }\n\n if (options.matchPath) {\n args.push(\"--match-path\", options.matchPath);\n }\n\n if (options.noMatchPath) {\n args.push(\"--no-match-path\", options.noMatchPath);\n }\n\n if (options.noMatchCoverage) {\n args.push(\"--no-match-coverage\", options.noMatchCoverage);\n }\n\n return args;\n }\n\n /**\n * Build display options\n */\n private buildDisplayOptions(options: CoverageOptions): string[] {\n const args: string[] = [];\n\n // Verbosity (-v, -vv, -vvv, etc.)\n if (options.verbosity && options.verbosity > 0) {\n args.push(\"-\" + \"v\".repeat(options.verbosity));\n }\n\n if (options.quiet) {\n args.push(\"--quiet\");\n }\n\n if (options.json) {\n args.push(\"--json\");\n }\n\n if (options.md) {\n args.push(\"--md\");\n }\n\n if (options.color) {\n args.push(\"--color\", options.color);\n }\n\n return args;\n }\n\n /**\n * Build test execution options\n */\n private buildTestOptions(options: CoverageOptions): string[] {\n const args: string[] = [];\n\n if (options.threads !== undefined) {\n args.push(\"--threads\", options.threads.toString());\n }\n\n if (options.fuzzRuns !== undefined) {\n args.push(\"--fuzz-runs\", options.fuzzRuns.toString());\n }\n\n if (options.fuzzSeed) {\n args.push(\"--fuzz-seed\", options.fuzzSeed);\n }\n\n if (options.failFast) {\n args.push(\"--fail-fast\");\n }\n\n if (options.allowFailure) {\n args.push(\"--allow-failure\");\n }\n\n return args;\n }\n\n /**\n * Build EVM options\n */\n private buildEvmOptions(options: CoverageOptions): string[] {\n const args: string[] = [];\n\n if (options.forkBlockNumber !== undefined) {\n args.push(\"--fork-block-number\", options.forkBlockNumber.toString());\n }\n\n if (options.initialBalance) {\n args.push(\"--initial-balance\", options.initialBalance);\n }\n\n if (options.sender) {\n args.push(\"--sender\", options.sender);\n }\n\n if (options.ffi) {\n args.push(\"--ffi\");\n }\n\n return args;\n }\n\n /**\n * Build build options\n */\n private buildBuildOptions(options: CoverageOptions): string[] {\n const args: string[] = [];\n\n if (options.force) {\n args.push(\"--force\");\n }\n\n if (options.noCache) {\n args.push(\"--no-cache\");\n }\n\n if (options.optimize) {\n args.push(\"--optimize\");\n }\n\n if (options.optimizerRuns !== undefined) {\n args.push(\"--optimizer-runs\", options.optimizerRuns.toString());\n }\n\n if (options.viaIr) {\n args.push(\"--via-ir\");\n }\n\n return args;\n }\n\n /**\n * Execute forge coverage command and stream output\n *\n * @param args - Command arguments\n * @returns Promise<boolean> - true if command succeeds\n */\n private executeForge(args: string[]): Promise<boolean> {\n return new Promise((resolve, reject) => {\n const forgeProcess = spawn(\"forge\", [\"coverage\", ...args], {\n cwd: this.hre.config.paths.root,\n stdio: \"inherit\", // Stream output directly to terminal\n });\n\n forgeProcess.on(\"close\", (code) => {\n if (code === 0) {\n resolve(true);\n } else {\n resolve(false);\n }\n });\n\n forgeProcess.on(\"error\", (error) => {\n reject(new Error(`Failed to execute forge coverage: ${error.message}`));\n });\n });\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"HelperGenerator.d.ts","sourceRoot":"","sources":["../../src/framework/HelperGenerator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,OAAO,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AAI1D;;GAEG;AACH,qBAAa,eAAe;IACd,OAAO,CAAC,GAAG;gBAAH,GAAG,EAAE,yBAAyB;IAElD;;OAEG;IACG,eAAe,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAgBxD;;;OAGG;IACG,yBAAyB,CAC7B,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,EACf,cAAc,EAAE,mBAAmB,EACnC,OAAO,CAAC,EAAE,GAAG,GACZ,OAAO,CAAC,MAAM,CAAC;IAmClB;;;OAGG;IACH,OAAO,CAAC,4BAA4B;IAuBpC;;OAEG;IACG,oBAAoB,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAuE/C;;;OAGG;IACH,OAAO,CAAC,qBAAqB;CA0I9B"}
1
+ {"version":3,"file":"HelperGenerator.d.ts","sourceRoot":"","sources":["../../src/framework/HelperGenerator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAW,MAAM,uBAAuB,CAAC;AAErE,OAAO,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AAI1D;;GAEG;AACH,qBAAa,eAAe;IACd,OAAO,CAAC,GAAG;gBAAH,GAAG,EAAE,yBAAyB;IAElD;;OAEG;IACG,eAAe,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAgBxD;;;OAGG;IACG,yBAAyB,CAC7B,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,EACf,cAAc,EAAE,mBAAmB,EACnC,OAAO,CAAC,EAAE,GAAG,GACZ,OAAO,CAAC,MAAM,CAAC;IAmClB;;;OAGG;IACH,OAAO,CAAC,4BAA4B;IA2BpC;;OAEG;IACG,oBAAoB,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAuE/C;;;OAGG;IACH,OAAO,CAAC,qBAAqB;CA0I9B"}
@@ -56,8 +56,12 @@ class HelperGenerator {
56
56
  */
57
57
  setForgeEnvironmentVariables(diamond, deploymentData) {
58
58
  try {
59
- // Get Diamond ABI path
60
- const abiPath = diamond.getDiamondAbiFilePath?.() || `./diamond-abi/${deploymentData.DiamondAddress}.json`;
59
+ // Get Diamond ABI path - remove leading "./" for Foundry compatibility
60
+ let abiPath = diamond.getDiamondAbiFilePath?.() || `diamond-abi/${diamond.getDiamondConfig().diamondName}.json` || `diamond-abi/Diamond.json`;
61
+ // Normalize path - remove leading "./" if present
62
+ if (abiPath.startsWith('./')) {
63
+ abiPath = abiPath.substring(2);
64
+ }
61
65
  // Get Diamond address
62
66
  const diamondAddress = deploymentData.DiamondAddress;
63
67
  // Set environment variables
@@ -170,7 +174,7 @@ class HelperGenerator {
170
174
  // Diamond ABI path
171
175
  source += ` /// @notice Path to the Diamond ABI file\n`;
172
176
  source += ` /// @dev Used by DiamondFuzzBase to load ABI for testing\n`;
173
- source += ` string constant DIAMOND_ABI_PATH = "./diamond-abi/${diamondName}.json";\n\n`;
177
+ source += ` string constant DIAMOND_ABI_PATH = "diamond-abi/${diamondName}.json";\n\n`;
174
178
  // Diamond address
175
179
  source += ` /// @notice Address of the deployed ${diamondName} contract\n`;
176
180
  source += ` /// @dev This is the main Diamond proxy address\n`;
@@ -1 +1 @@
1
- {"version":3,"file":"HelperGenerator.js","sourceRoot":"","sources":["../../src/framework/HelperGenerator.ts"],"names":[],"mappings":";;;AACA,2BAAwE;AAExE,+BAA4B;AAC5B,4CAAyC;AAEzC;;GAEG;AACH,MAAa,eAAe;IACN;IAApB,YAAoB,GAA8B;QAA9B,QAAG,GAAH,GAAG,CAA2B;IAAG,CAAC;IAEtD;;OAEG;IACH,KAAK,CAAC,eAAe,CAAC,SAAkB;QACtC,MAAM,UAAU,GAAG,SAAS,IAAI,IAAI,CAAC,GAAG,CAAC,eAAe,CAAC,UAAU,CAAC;QACpE,MAAM,QAAQ,GAAG,IAAA,WAAI,EAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;QAE9D,eAAM,CAAC,OAAO,CAAC,kCAAkC,CAAC,CAAC;QAEnD,qBAAqB;QACrB,eAAM,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC;QACvC,IAAA,cAAS,EAAC,QAAQ,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QACzC,IAAA,cAAS,EAAC,IAAA,WAAI,EAAC,QAAQ,EAAE,SAAS,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAC1D,IAAA,cAAS,EAAC,IAAA,WAAI,EAAC,QAAQ,EAAE,gBAAgB,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QACjE,IAAA,cAAS,EAAC,IAAA,WAAI,EAAC,QAAQ,EAAE,SAAS,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE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C;QAC5D,MAAM,IAAI,0DAA0D,CAAC;QACrE,MAAM,IAAI,WAAW,CAAC;QACtB,MAAM,IAAI,2FAA2F,CAAC;QAEtG,IAAI,UAAU,GAAG,IAAI,CAAC;QACtB,KAAK,MAAM,CAAC,SAAS,EAAE,SAAS,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;YAC3D,MAAM,YAAY,GAAG,SAAS;iBAC3B,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC;iBACrB,OAAO,CAAC,UAAU,EAAE,KAAK,CAAC;iBAC1B,WAAW,EAAE;iBACb,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,QAAQ,CAAC;YAEhC,MAAM,SAAS,GAAG,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;YAChD,MAAM,IAAI,WAAW,SAAS,qDAAqD,SAAS,UAAU,CAAC;YACvG,MAAM,IAAI,sBAAsB,YAAY,KAAK,CAAC;YAClD,MAAM,IAAI,aAAa,CAAC;YACxB,UAAU,GAAG,KAAK,CAAC;SACpB;QACD,MAAM,IAAI,8BAA8B,CAAC;QACzC,MAAM,IAAI,SAAS,CAAC;QAEpB,MAAM,IAAI,KAAK,CAAC;QAEhB,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AAtTD,0CAsTC","sourcesContent":["import { DeployedDiamondData } from \"@diamondslab/diamonds\";\nimport { existsSync, mkdirSync, readFileSync, writeFileSync } from \"fs\";\nimport { HardhatRuntimeEnvironment } from \"hardhat/types\";\nimport { join } from \"path\";\nimport { Logger } from \"../utils/logger\";\n\n/**\n * HelperGenerator - Generates Solidity helper files for testing\n */\nexport class HelperGenerator {\n constructor(private hre: HardhatRuntimeEnvironment) {}\n\n /**\n * Scaffold project with initial test structure\n */\n async scaffoldProject(outputDir?: string): Promise<void> {\n const helpersDir = outputDir || this.hre.diamondsFoundry.helpersDir;\n const basePath = join(this.hre.config.paths.root, helpersDir);\n\n Logger.section(\"Scaffolding Forge Test Structure\");\n \n // Create directories\n Logger.step(\"Creating directories...\");\n mkdirSync(basePath, { recursive: true });\n mkdirSync(join(basePath, \"../unit\"), { recursive: true });\n mkdirSync(join(basePath, \"../integration\"), { recursive: true });\n mkdirSync(join(basePath, \"../fuzz\"), { recursive: true });\n\n Logger.success(`Test structure created at ${basePath}`);\n }\n\n /**\n * Generate DiamondDeployment.sol from deployment record\n * Also sets DIAMOND_ADDRESS and DIAMOND_ABI_PATH environment variables for Forge tests\n */\n async generateDeploymentHelpers(\n diamondName: string,\n networkName: string,\n chainId: number,\n deploymentData: DeployedDiamondData,\n diamond?: any // Diamond instance from @diamondslab/hardhat-diamonds\n ): Promise<string> {\n Logger.section(\"Generating Diamond Deployment Helper\");\n\n const helpersDir = this.hre.diamondsFoundry.helpersDir;\n const outputPath = join(\n this.hre.config.paths.root,\n helpersDir,\n \"DiamondDeployment.sol\"\n );\n\n const content = this.generateLibrarySource(\n diamondName,\n networkName,\n chainId,\n deploymentData\n );\n\n // Ensure directory exists\n mkdirSync(join(this.hre.config.paths.root, helpersDir), {\n recursive: true,\n });\n\n // Write file\n writeFileSync(outputPath, content, \"utf8\");\n\n Logger.success(`Generated: ${outputPath}`);\n\n // Set environment variables for Forge tests (if Diamond instance provided)\n if (diamond) {\n this.setForgeEnvironmentVariables(diamond, deploymentData);\n }\n\n return outputPath;\n }\n\n /**\n * Set environment variables for Forge tests\n * @private\n */\n private setForgeEnvironmentVariables(\n diamond: any,\n deploymentData: DeployedDiamondData\n ): void {\n try {\n // Get Diamond ABI path\n const abiPath = diamond.getDiamondAbiFilePath?.() || `./diamond-abi/${deploymentData.DiamondAddress}.json`;\n \n // Get Diamond address\n const diamondAddress = deploymentData.DiamondAddress;\n\n // Set environment variables\n process.env.DIAMOND_ABI_PATH = abiPath;\n process.env.DIAMOND_ADDRESS = diamondAddress;\n\n Logger.info(`Set DIAMOND_ABI_PATH: ${abiPath}`);\n Logger.info(`Set DIAMOND_ADDRESS: ${diamondAddress}`);\n } catch (error: any) {\n Logger.warn(`Failed to set environment variables: ${error.message}`);\n Logger.warn(\"Tests can still use DiamondDeployment.sol overrides\");\n }\n }\n\n /**\n * Generate example test files\n */\n async generateExampleTests(): Promise<string[]> {\n const generated: string[] = [];\n const examples = this.hre.diamondsFoundry.exampleTests;\n\n if (!this.hre.diamondsFoundry.generateExamples) {\n Logger.info(\"Example generation disabled in config\");\n return generated;\n }\n\n Logger.section(\"Generating Example Tests\");\n\n const basePath = join(this.hre.config.paths.root, \"test\", \"foundry\");\n const templatesPath = join(__dirname, \"../templates\");\n\n for (const type of examples) {\n let templateFile = \"\";\n let outputPath = \"\";\n\n switch (type) {\n case \"unit\":\n templateFile = join(templatesPath, \"ExampleUnitTest.t.sol.template\");\n outputPath = join(basePath, \"unit\", \"ExampleUnit.t.sol\");\n break;\n case \"integration\":\n templateFile = join(templatesPath, \"ExampleIntegrationTest.t.sol.template\");\n outputPath = join(basePath, \"integration\", \"ExampleIntegration.t.sol\");\n break;\n case \"fuzz\":\n templateFile = join(templatesPath, \"ExampleFuzzTest.t.sol.template\");\n outputPath = join(basePath, \"fuzz\", \"ExampleFuzz.t.sol\");\n break;\n default:\n Logger.warn(`Unknown example type: ${type}`);\n continue;\n }\n\n try {\n // Check if template exists\n if (!existsSync(templateFile)) {\n Logger.warn(`Template not found: ${templateFile}`);\n continue;\n }\n\n // Read template content\n const templateContent = readFileSync(templateFile, \"utf8\");\n\n // Ensure output directory exists\n mkdirSync(join(basePath, type), { recursive: true });\n\n // Check if file already exists\n if (existsSync(outputPath)) {\n Logger.info(`Skipping ${type} example (already exists): ${outputPath}`);\n continue;\n }\n\n // Write example test file\n writeFileSync(outputPath, templateContent, \"utf8\");\n Logger.success(`Generated ${type} example: ${outputPath}`);\n generated.push(outputPath);\n } catch (error: any) {\n Logger.error(`Failed to generate ${type} example: ${error.message}`);\n }\n }\n\n if (generated.length === 0) {\n Logger.info(\"No new example tests generated (may already exist)\");\n }\n\n return generated;\n }\n\n /**\n * Generate Solidity library source from deployment data\n * @private\n */\n private generateLibrarySource(\n diamondName: string,\n networkName: string,\n chainId: number,\n deploymentData: DeployedDiamondData\n ): string {\n const timestamp = new Date().toISOString();\n const networkInfo = `${networkName}-${chainId}`;\n const deploymentFileName = `${diamondName.toLowerCase()}-${networkInfo}.json`;\n const deploymentFilePath = `diamonds/${diamondName}/deployments/${deploymentFileName}`;\n\n let source = \"\";\n\n // SPDX and pragma\n source += \"// SPDX-License-Identifier: MIT\\n\";\n source += \"pragma solidity ^0.8.19;\\n\\n\";\n\n // Header comments\n source += \"/**\\n\";\n source += ` * @title DiamondDeployment\\n`;\n source += ` * @notice Auto-generated deployment data for ${diamondName}\\n`;\n source += ` * @dev This library provides constants and helper functions for accessing\\n`;\n source += ` * deployment data in Forge tests. It is auto-generated from the deployment\\n`;\n source += ` * record and should not be edited manually.\\n`;\n source += ` *\\n`;\n source += ` * Generated from: ${deploymentFilePath}\\n`;\n source += ` * Generated at: ${timestamp}\\n`;\n source += ` *\\n`;\n source += ` * To regenerate this file:\\n`;\n source += ` * npx hardhat diamonds-forge:generate-helpers --diamond ${diamondName}\\n`;\n source += ` *\\n`;\n source += ` * โš ๏ธ DO NOT EDIT MANUALLY - Changes will be overwritten on next generation\\n`;\n source += \" */\\n\";\n source += \"library DiamondDeployment {\\n\";\n\n // Diamond name\n source += ` /// @notice Name of the Diamond contract\\n`;\n source += ` /// @dev Used for identifying the Diamond in tests\\n`;\n source += ` string constant DIAMOND_NAME = \"${diamondName}\";\\n\\n`;\n\n // Diamond ABI path\n source += ` /// @notice Path to the Diamond ABI file\\n`;\n source += ` /// @dev Used by DiamondFuzzBase to load ABI for testing\\n`;\n source += ` string constant DIAMOND_ABI_PATH = \"./diamond-abi/${diamondName}.json\";\\n\\n`;\n\n // Diamond address\n source += ` /// @notice Address of the deployed ${diamondName} contract\\n`;\n source += ` /// @dev This is the main Diamond proxy address\\n`;\n source += ` address constant DIAMOND_ADDRESS = ${deploymentData.DiamondAddress};\\n\\n`;\n\n // Deployer address\n source += ` /// @notice Address of the deployer account\\n`;\n source += ` /// @dev Account that deployed the Diamond\\n`;\n source += ` address constant DEPLOYER_ADDRESS = ${deploymentData.DeployerAddress};\\n\\n`;\n\n // Facet addresses\n source += \" // ========================================\\n\";\n source += \" // Facet Addresses\\n\";\n source += \" // ========================================\\n\\n\";\n\n const facets = deploymentData.DeployedFacets ?? {};\n for (const [facetName, facetData] of Object.entries(facets)) {\n const constantName = facetName\n .replace(/Facet$/, \"\")\n .replace(/([A-Z])/g, \"_$1\")\n .toUpperCase()\n .replace(/^_/, \"\") + \"_FACET\";\n\n source += ` /// @notice Address of ${facetName} implementation\\n`;\n source += ` address constant ${constantName} = ${facetData.address};\\n`;\n }\n source += \"\\n\";\n\n // Helper functions\n source += \" // ========================================\\n\";\n source += \" // Helper Functions\\n\";\n source += \" // ========================================\\n\\n\";\n\n source += \" /**\\n\";\n source += \" * @notice Get the Diamond name\\n\";\n source += \" * @return The name of the Diamond contract\\n\";\n source += \" */\\n\";\n source += \" function getDiamondName() internal pure returns (string memory) {\\n\";\n source += \" return DIAMOND_NAME;\\n\";\n source += \" }\\n\\n\";\n\n source += \" /**\\n\";\n source += \" * @notice Get the path to the Diamond ABI file\\n\";\n source += \" * @return The path to the Diamond ABI JSON file\\n\";\n source += \" */\\n\";\n source += \" function getDiamondABIPath() internal pure returns (string memory) {\\n\";\n source += \" return DIAMOND_ABI_PATH;\\n\";\n source += \" }\\n\\n\";\n\n source += \" /**\\n\";\n source += \" * @notice Get the Diamond contract address\\n\";\n source += \" * @return The address of the deployed Diamond proxy\\n\";\n source += \" */\\n\";\n source += \" function getDiamondAddress() internal pure returns (address) {\\n\";\n source += \" return DIAMOND_ADDRESS;\\n\";\n source += \" }\\n\\n\";\n\n source += \" /**\\n\";\n source += \" * @notice Get the deployer address\\n\";\n source += \" * @return The address of the deployer account\\n\";\n source += \" */\\n\";\n source += \" function getDeployerAddress() internal pure returns (address) {\\n\";\n source += \" return DEPLOYER_ADDRESS;\\n\";\n source += \" }\\n\\n\";\n\n source += \" /**\\n\";\n source += \" * @notice Get facet implementation address by name\\n\";\n source += \" * @param facetName The name of the facet\\n\";\n source += \" * @return The address of the facet implementation\\n\";\n source += \" */\\n\";\n source += \" function getFacetAddress(string memory facetName) internal pure returns (address) {\\n\";\n\n let firstFacet = true;\n for (const [facetName, facetData] of Object.entries(facets)) {\n const constantName = facetName\n .replace(/Facet$/, \"\")\n .replace(/([A-Z])/g, \"_$1\")\n .toUpperCase()\n .replace(/^_/, \"\") + \"_FACET\";\n\n const condition = firstFacet ? \"if\" : \"else if\";\n source += ` ${condition} (keccak256(bytes(facetName)) == keccak256(bytes(\"${facetName}\"))) {\\n`;\n source += ` return ${constantName};\\n`;\n source += \" }\\n\";\n firstFacet = false;\n }\n source += \" return address(0);\\n\";\n source += \" }\\n\";\n\n source += \"}\\n\";\n\n return source;\n }\n}\n"]}
1
+ {"version":3,"file":"HelperGenerator.js","sourceRoot":"","sources":["../../src/framework/HelperGenerator.ts"],"names":[],"mappings":";;;AACA,2BAAwE;AAExE,+BAA4B;AAC5B,4CAAyC;AAEzC;;GAEG;AACH,MAAa,eAAe;IACN;IAApB,YAAoB,GAA8B;QAA9B,QAAG,GAAH,GAAG,CAA2B;IAAG,CAAC;IAEtD;;OAEG;IACH,KAAK,CAAC,eAAe,CAAC,SAAkB;QACtC,MAAM,UAAU,GAAG,SAAS,IAAI,IAAI,CAAC,GAAG,CAAC,eAAe,CAAC,UAAU,CAAC;QACpE,MAAM,QAAQ,GAAG,IAAA,WAAI,EAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;QAE9D,eAAM,CAAC,OAAO,CAAC,kCAAkC,CAAC,CAAC;QAEnD,qBAAqB;QACrB,eAAM,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC;QACvC,IAAA,cAAS,EAAC,QAAQ,EAAE,EAAE,SAAS,EAAE,IAA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BAA8B,CAAC;QACzC,MAAM,IAAI,SAAS,CAAC;QAEpB,MAAM,IAAI,KAAK,CAAC;QAEhB,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AA1TD,0CA0TC","sourcesContent":["import { DeployedDiamondData, Diamond } from \"@diamondslab/diamonds\";\nimport { existsSync, mkdirSync, readFileSync, writeFileSync } from \"fs\";\nimport { HardhatRuntimeEnvironment } from \"hardhat/types\";\nimport { join } from \"path\";\nimport { Logger } from \"../utils/logger\";\n\n/**\n * HelperGenerator - Generates Solidity helper files for testing\n */\nexport class HelperGenerator {\n constructor(private hre: HardhatRuntimeEnvironment) {}\n\n /**\n * Scaffold project with initial test structure\n */\n async scaffoldProject(outputDir?: string): Promise<void> {\n const helpersDir = outputDir || this.hre.diamondsFoundry.helpersDir;\n const basePath = join(this.hre.config.paths.root, helpersDir);\n\n Logger.section(\"Scaffolding Forge Test Structure\");\n \n // Create directories\n Logger.step(\"Creating directories...\");\n mkdirSync(basePath, { recursive: true });\n mkdirSync(join(basePath, \"../unit\"), { recursive: true });\n mkdirSync(join(basePath, \"../integration\"), { recursive: true });\n mkdirSync(join(basePath, \"../fuzz\"), { recursive: true });\n\n Logger.success(`Test structure created at ${basePath}`);\n }\n\n /**\n * Generate DiamondDeployment.sol from deployment record\n * Also sets DIAMOND_ADDRESS and DIAMOND_ABI_PATH environment variables for Forge tests\n */\n async generateDeploymentHelpers(\n diamondName: string,\n networkName: string,\n chainId: number,\n deploymentData: DeployedDiamondData,\n diamond?: any // Diamond instance from @diamondslab/hardhat-diamonds\n ): Promise<string> {\n Logger.section(\"Generating Diamond Deployment Helper\");\n\n const helpersDir = this.hre.diamondsFoundry.helpersDir;\n const outputPath = join(\n this.hre.config.paths.root,\n helpersDir,\n \"DiamondDeployment.sol\"\n );\n\n const content = this.generateLibrarySource(\n diamondName,\n networkName,\n chainId,\n deploymentData\n );\n\n // Ensure directory exists\n mkdirSync(join(this.hre.config.paths.root, helpersDir), {\n recursive: true,\n });\n\n // Write file\n writeFileSync(outputPath, content, \"utf8\");\n\n Logger.success(`Generated: ${outputPath}`);\n\n // Set environment variables for Forge tests (if Diamond instance provided)\n if (diamond) {\n this.setForgeEnvironmentVariables(diamond, deploymentData);\n }\n\n return outputPath;\n }\n\n /**\n * Set environment variables for Forge tests\n * @private\n */\n private setForgeEnvironmentVariables(\n diamond: Diamond,\n deploymentData: DeployedDiamondData\n ): void {\n try {\n // Get Diamond ABI path - remove leading \"./\" for Foundry compatibility\n let abiPath = diamond.getDiamondAbiFilePath?.() || `diamond-abi/${diamond.getDiamondConfig().diamondName}.json` || `diamond-abi/Diamond.json`;\n // Normalize path - remove leading \"./\" if present\n if (abiPath.startsWith('./')) {\n abiPath = abiPath.substring(2);\n }\n \n // Get Diamond address\n const diamondAddress = deploymentData.DiamondAddress;\n\n // Set environment variables\n process.env.DIAMOND_ABI_PATH = abiPath;\n process.env.DIAMOND_ADDRESS = diamondAddress;\n\n Logger.info(`Set DIAMOND_ABI_PATH: ${abiPath}`);\n Logger.info(`Set DIAMOND_ADDRESS: ${diamondAddress}`);\n } catch (error: any) {\n Logger.warn(`Failed to set environment variables: ${error.message}`);\n Logger.warn(\"Tests can still use DiamondDeployment.sol overrides\");\n }\n }\n\n /**\n * Generate example test files\n */\n async generateExampleTests(): Promise<string[]> {\n const generated: string[] = [];\n const examples = this.hre.diamondsFoundry.exampleTests;\n\n if (!this.hre.diamondsFoundry.generateExamples) {\n Logger.info(\"Example generation disabled in config\");\n return generated;\n }\n\n Logger.section(\"Generating Example Tests\");\n\n const basePath = join(this.hre.config.paths.root, \"test\", \"foundry\");\n const templatesPath = join(__dirname, \"../templates\");\n\n for (const type of examples) {\n let templateFile = \"\";\n let outputPath = \"\";\n\n switch (type) {\n case \"unit\":\n templateFile = join(templatesPath, \"ExampleUnitTest.t.sol.template\");\n outputPath = join(basePath, \"unit\", \"ExampleUnit.t.sol\");\n break;\n case \"integration\":\n templateFile = join(templatesPath, \"ExampleIntegrationTest.t.sol.template\");\n outputPath = join(basePath, \"integration\", \"ExampleIntegration.t.sol\");\n break;\n case \"fuzz\":\n templateFile = join(templatesPath, \"ExampleFuzzTest.t.sol.template\");\n outputPath = join(basePath, \"fuzz\", \"ExampleFuzz.t.sol\");\n break;\n default:\n Logger.warn(`Unknown example type: ${type}`);\n continue;\n }\n\n try {\n // Check if template exists\n if (!existsSync(templateFile)) {\n Logger.warn(`Template not found: ${templateFile}`);\n continue;\n }\n\n // Read template content\n const templateContent = readFileSync(templateFile, \"utf8\");\n\n // Ensure output directory exists\n mkdirSync(join(basePath, type), { recursive: true });\n\n // Check if file already exists\n if (existsSync(outputPath)) {\n Logger.info(`Skipping ${type} example (already exists): ${outputPath}`);\n continue;\n }\n\n // Write example test file\n writeFileSync(outputPath, templateContent, \"utf8\");\n Logger.success(`Generated ${type} example: ${outputPath}`);\n generated.push(outputPath);\n } catch (error: any) {\n Logger.error(`Failed to generate ${type} example: ${error.message}`);\n }\n }\n\n if (generated.length === 0) {\n Logger.info(\"No new example tests generated (may already exist)\");\n }\n\n return generated;\n }\n\n /**\n * Generate Solidity library source from deployment data\n * @private\n */\n private generateLibrarySource(\n diamondName: string,\n networkName: string,\n chainId: number,\n deploymentData: DeployedDiamondData\n ): string {\n const timestamp = new Date().toISOString();\n const networkInfo = `${networkName}-${chainId}`;\n const deploymentFileName = `${diamondName.toLowerCase()}-${networkInfo}.json`;\n const deploymentFilePath = `diamonds/${diamondName}/deployments/${deploymentFileName}`;\n\n let source = \"\";\n\n // SPDX and pragma\n source += \"// SPDX-License-Identifier: MIT\\n\";\n source += \"pragma solidity ^0.8.19;\\n\\n\";\n\n // Header comments\n source += \"/**\\n\";\n source += ` * @title DiamondDeployment\\n`;\n source += ` * @notice Auto-generated deployment data for ${diamondName}\\n`;\n source += ` * @dev This library provides constants and helper functions for accessing\\n`;\n source += ` * deployment data in Forge tests. It is auto-generated from the deployment\\n`;\n source += ` * record and should not be edited manually.\\n`;\n source += ` *\\n`;\n source += ` * Generated from: ${deploymentFilePath}\\n`;\n source += ` * Generated at: ${timestamp}\\n`;\n source += ` *\\n`;\n source += ` * To regenerate this file:\\n`;\n source += ` * npx hardhat diamonds-forge:generate-helpers --diamond ${diamondName}\\n`;\n source += ` *\\n`;\n source += ` * โš ๏ธ DO NOT EDIT MANUALLY - Changes will be overwritten on next generation\\n`;\n source += \" */\\n\";\n source += \"library DiamondDeployment {\\n\";\n\n // Diamond name\n source += ` /// @notice Name of the Diamond contract\\n`;\n source += ` /// @dev Used for identifying the Diamond in tests\\n`;\n source += ` string constant DIAMOND_NAME = \"${diamondName}\";\\n\\n`;\n\n // Diamond ABI path\n source += ` /// @notice Path to the Diamond ABI file\\n`;\n source += ` /// @dev Used by DiamondFuzzBase to load ABI for testing\\n`;\n source += ` string constant DIAMOND_ABI_PATH = \"diamond-abi/${diamondName}.json\";\\n\\n`;\n\n // Diamond address\n source += ` /// @notice Address of the deployed ${diamondName} contract\\n`;\n source += ` /// @dev This is the main Diamond proxy address\\n`;\n source += ` address constant DIAMOND_ADDRESS = ${deploymentData.DiamondAddress};\\n\\n`;\n\n // Deployer address\n source += ` /// @notice Address of the deployer account\\n`;\n source += ` /// @dev Account that deployed the Diamond\\n`;\n source += ` address constant DEPLOYER_ADDRESS = ${deploymentData.DeployerAddress};\\n\\n`;\n\n // Facet addresses\n source += \" // ========================================\\n\";\n source += \" // Facet Addresses\\n\";\n source += \" // ========================================\\n\\n\";\n\n const facets = deploymentData.DeployedFacets ?? {};\n for (const [facetName, facetData] of Object.entries(facets)) {\n const constantName = facetName\n .replace(/Facet$/, \"\")\n .replace(/([A-Z])/g, \"_$1\")\n .toUpperCase()\n .replace(/^_/, \"\") + \"_FACET\";\n\n source += ` /// @notice Address of ${facetName} implementation\\n`;\n source += ` address constant ${constantName} = ${facetData.address};\\n`;\n }\n source += \"\\n\";\n\n // Helper functions\n source += \" // ========================================\\n\";\n source += \" // Helper Functions\\n\";\n source += \" // ========================================\\n\\n\";\n\n source += \" /**\\n\";\n source += \" * @notice Get the Diamond name\\n\";\n source += \" * @return The name of the Diamond contract\\n\";\n source += \" */\\n\";\n source += \" function getDiamondName() internal pure returns (string memory) {\\n\";\n source += \" return DIAMOND_NAME;\\n\";\n source += \" }\\n\\n\";\n\n source += \" /**\\n\";\n source += \" * @notice Get the path to the Diamond ABI file\\n\";\n source += \" * @return The path to the Diamond ABI JSON file\\n\";\n source += \" */\\n\";\n source += \" function getDiamondABIPath() internal pure returns (string memory) {\\n\";\n source += \" return DIAMOND_ABI_PATH;\\n\";\n source += \" }\\n\\n\";\n\n source += \" /**\\n\";\n source += \" * @notice Get the Diamond contract address\\n\";\n source += \" * @return The address of the deployed Diamond proxy\\n\";\n source += \" */\\n\";\n source += \" function getDiamondAddress() internal pure returns (address) {\\n\";\n source += \" return DIAMOND_ADDRESS;\\n\";\n source += \" }\\n\\n\";\n\n source += \" /**\\n\";\n source += \" * @notice Get the deployer address\\n\";\n source += \" * @return The address of the deployer account\\n\";\n source += \" */\\n\";\n source += \" function getDeployerAddress() internal pure returns (address) {\\n\";\n source += \" return DEPLOYER_ADDRESS;\\n\";\n source += \" }\\n\\n\";\n\n source += \" /**\\n\";\n source += \" * @notice Get facet implementation address by name\\n\";\n source += \" * @param facetName The name of the facet\\n\";\n source += \" * @return The address of the facet implementation\\n\";\n source += \" */\\n\";\n source += \" function getFacetAddress(string memory facetName) internal pure returns (address) {\\n\";\n\n let firstFacet = true;\n for (const [facetName, facetData] of Object.entries(facets)) {\n const constantName = facetName\n .replace(/Facet$/, \"\")\n .replace(/([A-Z])/g, \"_$1\")\n .toUpperCase()\n .replace(/^_/, \"\") + \"_FACET\";\n\n const condition = firstFacet ? \"if\" : \"else if\";\n source += ` ${condition} (keccak256(bytes(facetName)) == keccak256(bytes(\"${facetName}\"))) {\\n`;\n source += ` return ${constantName};\\n`;\n source += \" }\\n\";\n firstFacet = false;\n }\n source += \" return address(0);\\n\";\n source += \" }\\n\";\n\n source += \"}\\n\";\n\n return source;\n }\n}\n"]}
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import "./tasks/coverage";
1
2
  import "./tasks/deploy";
2
3
  import "./tasks/generate-helpers";
3
4
  import "./tasks/init";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,gBAAgB,CAAC;AACxB,OAAO,0BAA0B,CAAC;AAClC,OAAO,cAAc,CAAC;AACtB,OAAO,cAAc,CAAC;AACtB,OAAO,iBAAiB,CAAC;AAmBzB,cAAc,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,kBAAkB,CAAC;AAC1B,OAAO,gBAAgB,CAAC;AACxB,OAAO,0BAA0B,CAAC;AAClC,OAAO,cAAc,CAAC;AACtB,OAAO,cAAc,CAAC;AACtB,OAAO,iBAAiB,CAAC;AAmBzB,cAAc,gBAAgB,CAAC"}
package/dist/index.js CHANGED
@@ -18,6 +18,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
20
  const config_1 = require("hardhat/config");
21
+ require("./tasks/coverage");
21
22
  require("./tasks/deploy");
22
23
  require("./tasks/generate-helpers");
23
24
  require("./tasks/init");
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,2CAAqF;AACrF,0BAAwB;AACxB,oCAAkC;AAClC,wBAAsB;AACtB,wBAAsB;AACtB,2BAAyB;AAEzB,2BAA+C;AAC/C,iEAG0C;AAE1C,gDAAwB;AACxB,4DAAoC;AACpC,uCAKmB;AACnB,mDAAoD;AAEpD,eAAe;AACf,iDAA+B;AAE/B,MAAM,iBAAiB,GAAG,cAAc,CAAC;AAEzC,IAAI,eAAe,GAAG,KAAK,CAAC;AAE5B,8CAA8C;AAC9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QACF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACjB;IAED,OAAO,CAAC,GAAG,CAAC,+BAA+B,CAAC,CAAC;IAE7C,IAAA,kBAAa,EACX,iBAAiB,EACjB;QACE,mBAAmB;QACnB,UAAU,cAAI,CAAC,QAAQ,CACrB,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,EACrB,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CACzB,GAAG;QACJ,aAAa;QACb,gCAAgC;QAChC,WAAW,cAAI,CAAC,QAAQ,CACtB,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,EACrB,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CACvB,GAAG;QACJ,6BAA6B;KAC9B,CAAC,IAAI,CAAC,IAAI,CAAC,CACb,CAAC;IAEF,MAAM,IAAA,2BAAiB,EAAC,sBAAsB,CAAC,CAAC;AAClD,CAAC,CACF,CAAC","sourcesContent":["import { extendConfig, extendEnvironment, internalTask, task } from \"hardhat/config\";\nimport \"./tasks/deploy\";\nimport \"./tasks/generate-helpers\";\nimport \"./tasks/init\";\nimport \"./tasks/test\";\nimport \"./types/hardhat\";\n\nimport { existsSync, writeFileSync } from \"fs\";\nimport {\n TASK_COMPILE_GET_REMAPPINGS,\n TASK_COMPILE_TRANSFORM_IMPORT_NAME,\n} from \"hardhat/builtin-tasks/task-names\";\nimport { HardhatRuntimeEnvironment } from \"hardhat/types\";\nimport path from \"path\";\nimport picocolors from \"picocolors\";\nimport {\n getForgeConfig,\n getRemappings,\n HardhatFoundryError,\n installDependency,\n} from \"./foundry\";\nimport { validateConfig } from \"./utils/validation\";\n\n// Export types\nexport * from \"./types/config\";\n\nconst TASK_INIT_FOUNDRY = \"init-foundry\";\n\nlet pluginActivated = false;\n\n// Extend config with diamondsFoundry settings\nextendConfig((config, userConfig) => {\n // Validate and set diamondsFoundry config\n config.diamondsFoundry = validateConfig(userConfig.diamondsFoundry);\n\n // Check foundry.toml presence. Don't warn when running foundry initialization task\n if (!existsSync(path.join(config.paths.root, \"foundry.toml\"))) {\n if (!process.argv.includes(TASK_INIT_FOUNDRY)) {\n console.log(\n picocolors.yellow(\n `Warning: You are using the diamonds-hardhat-foundry plugin but there isn't a foundry.toml file in your project. Run 'npx hardhat ${TASK_INIT_FOUNDRY}' to create one.`\n )\n );\n }\n return;\n }\n\n // Load foundry config\n const foundryConfig = getForgeConfig();\n\n // Ensure required keys exist\n if (\n foundryConfig?.src === undefined ||\n foundryConfig?.cache_path === undefined\n ) {\n throw new HardhatFoundryError(\n \"Couldn't find `src` or `cache_path` config keys after running `forge config --json`\"\n );\n }\n\n // Ensure foundry src path doesn't mismatch user-configured path\n const userSourcesPath = userConfig.paths?.sources;\n const foundrySourcesPath = foundryConfig.src;\n\n if (\n userSourcesPath !== undefined &&\n path.resolve(userSourcesPath) !== path.resolve(foundrySourcesPath)\n ) {\n throw new HardhatFoundryError(\n `User-configured sources path (${userSourcesPath}) doesn't match path configured in foundry (${foundrySourcesPath})`\n );\n }\n\n // Set sources path\n config.paths.sources = path.resolve(config.paths.root, foundrySourcesPath);\n\n // Change hardhat's cache path if it clashes with foundry's\n const foundryCachePath = path.resolve(\n config.paths.root,\n foundryConfig.cache_path\n );\n if (config.paths.cache === foundryCachePath) {\n config.paths.cache = \"cache_hardhat\";\n }\n\n pluginActivated = true;\n});\n\n// Extend environment to add diamondsFoundry config to HRE\nextendEnvironment((hre: HardhatRuntimeEnvironment) => {\n hre.diamondsFoundry = hre.config.diamondsFoundry;\n});\n\n// This task is in place to detect old hardhat-core versions\ninternalTask(TASK_COMPILE_TRANSFORM_IMPORT_NAME).setAction(\n async (\n {\n importName,\n deprecationCheck,\n }: { importName: string; deprecationCheck: boolean },\n _hre\n ): Promise<string> => {\n // When the deprecationCheck param is passed, it means a new enough hardhat-core is being used\n if (deprecationCheck) {\n return importName;\n }\n throw new HardhatFoundryError(\n \"This version of diamonds-hardhat-foundry depends on hardhat version >= 2.17.2\"\n );\n }\n);\n\ninternalTask(TASK_COMPILE_GET_REMAPPINGS).setAction(\n async (): Promise<Record<string, string>> => {\n if (!pluginActivated) {\n return {};\n }\n\n return getRemappings();\n }\n);\n\ntask(\n TASK_INIT_FOUNDRY,\n \"Initialize foundry setup in current hardhat project\",\n async (_, hre: HardhatRuntimeEnvironment) => {\n const foundryConfigPath = path.resolve(\n hre.config.paths.root,\n \"foundry.toml\"\n );\n\n if (existsSync(foundryConfigPath)) {\n console.warn(\n picocolors.yellow(`File foundry.toml already exists. Aborting.`)\n );\n process.exit(1);\n }\n\n console.log(`Creating foundry.toml file...`);\n\n writeFileSync(\n foundryConfigPath,\n [\n `[profile.default]`,\n `src = '${path.relative(\n hre.config.paths.root,\n hre.config.paths.sources\n )}'`,\n `out = 'out'`,\n `libs = ['node_modules', 'lib']`,\n `test = '${path.relative(\n hre.config.paths.root,\n hre.config.paths.tests\n )}'`,\n `cache_path = 'cache_forge'`,\n ].join(\"\\n\")\n );\n\n await installDependency(\"foundry-rs/forge-std\");\n }\n);\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,2CAAqF;AACrF,4BAA0B;AAC1B,0BAAwB;AACxB,oCAAkC;AAClC,wBAAsB;AACtB,wBAAsB;AACtB,2BAAyB;AAEzB,2BAA+C;AAC/C,iEAG0C;AAE1C,gDAAwB;AACxB,4DAAoC;AACpC,uCAKmB;AACnB,mDAAoD;AAEpD,eAAe;AACf,iDAA+B;AAE/B,MAAM,iBAAiB,GAAG,cAAc,CAAC;AAEzC,IAAI,eAAe,GAAG,KAAK,CAAC;AAE5B,8CAA8C;AAC9C,IAAA,qBAAY,EAAC,CAAC,MAAM,EAAE,UAAU,EAAE,EAAE;IAClC,0CAA0C;IAC1C,MAAM,CAAC,eAAe,GAAG,IAAA,2BAAc,EAAC,UAAU,CAAC,eAAe,CAAC,CAAC;IAEpE,mFAAmF;IACnF,IAAI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QAAQ,CACrB,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,EACrB,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CACzB,GAAG;QACJ,aAAa;QACb,gCAAgC;QAChC,WAAW,cAAI,CAAC,QAAQ,CACtB,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,EACrB,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CACvB,GAAG;QACJ,6BAA6B;KAC9B,CAAC,IAAI,CAAC,IAAI,CAAC,CACb,CAAC;IAEF,MAAM,IAAA,2BAAiB,EAAC,sBAAsB,CAAC,CAAC;AAClD,CAAC,CACF,CAAC","sourcesContent":["import { extendConfig, extendEnvironment, internalTask, task } from \"hardhat/config\";\nimport \"./tasks/coverage\";\nimport \"./tasks/deploy\";\nimport \"./tasks/generate-helpers\";\nimport \"./tasks/init\";\nimport \"./tasks/test\";\nimport \"./types/hardhat\";\n\nimport { existsSync, writeFileSync } from \"fs\";\nimport {\n TASK_COMPILE_GET_REMAPPINGS,\n TASK_COMPILE_TRANSFORM_IMPORT_NAME,\n} from \"hardhat/builtin-tasks/task-names\";\nimport { HardhatRuntimeEnvironment } from \"hardhat/types\";\nimport path from \"path\";\nimport picocolors from \"picocolors\";\nimport {\n getForgeConfig,\n getRemappings,\n HardhatFoundryError,\n installDependency,\n} from \"./foundry\";\nimport { validateConfig } from \"./utils/validation\";\n\n// Export types\nexport * from \"./types/config\";\n\nconst TASK_INIT_FOUNDRY = \"init-foundry\";\n\nlet pluginActivated = false;\n\n// Extend config with diamondsFoundry settings\nextendConfig((config, userConfig) => {\n // Validate and set diamondsFoundry config\n config.diamondsFoundry = validateConfig(userConfig.diamondsFoundry);\n\n // Check foundry.toml presence. Don't warn when running foundry initialization task\n if (!existsSync(path.join(config.paths.root, \"foundry.toml\"))) {\n if (!process.argv.includes(TASK_INIT_FOUNDRY)) {\n console.log(\n picocolors.yellow(\n `Warning: You are using the diamonds-hardhat-foundry plugin but there isn't a foundry.toml file in your project. Run 'npx hardhat ${TASK_INIT_FOUNDRY}' to create one.`\n )\n );\n }\n return;\n }\n\n // Load foundry config\n const foundryConfig = getForgeConfig();\n\n // Ensure required keys exist\n if (\n foundryConfig?.src === undefined ||\n foundryConfig?.cache_path === undefined\n ) {\n throw new HardhatFoundryError(\n \"Couldn't find `src` or `cache_path` config keys after running `forge config --json`\"\n );\n }\n\n // Ensure foundry src path doesn't mismatch user-configured path\n const userSourcesPath = userConfig.paths?.sources;\n const foundrySourcesPath = foundryConfig.src;\n\n if (\n userSourcesPath !== undefined &&\n path.resolve(userSourcesPath) !== path.resolve(foundrySourcesPath)\n ) {\n throw new HardhatFoundryError(\n `User-configured sources path (${userSourcesPath}) doesn't match path configured in foundry (${foundrySourcesPath})`\n );\n }\n\n // Set sources path\n config.paths.sources = path.resolve(config.paths.root, foundrySourcesPath);\n\n // Change hardhat's cache path if it clashes with foundry's\n const foundryCachePath = path.resolve(\n config.paths.root,\n foundryConfig.cache_path\n );\n if (config.paths.cache === foundryCachePath) {\n config.paths.cache = \"cache_hardhat\";\n }\n\n pluginActivated = true;\n});\n\n// Extend environment to add diamondsFoundry config to HRE\nextendEnvironment((hre: HardhatRuntimeEnvironment) => {\n hre.diamondsFoundry = hre.config.diamondsFoundry;\n});\n\n// This task is in place to detect old hardhat-core versions\ninternalTask(TASK_COMPILE_TRANSFORM_IMPORT_NAME).setAction(\n async (\n {\n importName,\n deprecationCheck,\n }: { importName: string; deprecationCheck: boolean },\n _hre\n ): Promise<string> => {\n // When the deprecationCheck param is passed, it means a new enough hardhat-core is being used\n if (deprecationCheck) {\n return importName;\n }\n throw new HardhatFoundryError(\n \"This version of diamonds-hardhat-foundry depends on hardhat version >= 2.17.2\"\n );\n }\n);\n\ninternalTask(TASK_COMPILE_GET_REMAPPINGS).setAction(\n async (): Promise<Record<string, string>> => {\n if (!pluginActivated) {\n return {};\n }\n\n return getRemappings();\n }\n);\n\ntask(\n TASK_INIT_FOUNDRY,\n \"Initialize foundry setup in current hardhat project\",\n async (_, hre: HardhatRuntimeEnvironment) => {\n const foundryConfigPath = path.resolve(\n hre.config.paths.root,\n \"foundry.toml\"\n );\n\n if (existsSync(foundryConfigPath)) {\n console.warn(\n picocolors.yellow(`File foundry.toml already exists. Aborting.`)\n );\n process.exit(1);\n }\n\n console.log(`Creating foundry.toml file...`);\n\n writeFileSync(\n foundryConfigPath,\n [\n `[profile.default]`,\n `src = '${path.relative(\n hre.config.paths.root,\n hre.config.paths.sources\n )}'`,\n `out = 'out'`,\n `libs = ['node_modules', 'lib']`,\n `test = '${path.relative(\n hre.config.paths.root,\n hre.config.paths.tests\n )}'`,\n `cache_path = 'cache_forge'`,\n ].join(\"\\n\")\n );\n\n await installDependency(\"foundry-rs/forge-std\");\n }\n);\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=coverage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"coverage.d.ts","sourceRoot":"","sources":["../../src/tasks/coverage.ts"],"names":[],"mappings":""}