@diamondslab/diamonds-hardhat-foundry 1.0.1 → 1.0.2
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/dist/foundry.d.ts +11 -0
- package/dist/foundry.d.ts.map +1 -0
- package/dist/foundry.js +104 -0
- package/dist/foundry.js.map +1 -0
- package/dist/framework/DeploymentManager.d.ts +48 -0
- package/dist/framework/DeploymentManager.d.ts.map +1 -0
- package/dist/framework/DeploymentManager.js +145 -0
- package/dist/framework/DeploymentManager.js.map +1 -0
- package/dist/framework/ForgeFuzzingFramework.d.ts +57 -0
- package/dist/framework/ForgeFuzzingFramework.d.ts.map +1 -0
- package/dist/framework/ForgeFuzzingFramework.js +119 -0
- package/dist/framework/ForgeFuzzingFramework.js.map +1 -0
- package/dist/framework/HelperGenerator.d.ts +27 -0
- package/dist/framework/HelperGenerator.d.ts.map +1 -0
- package/dist/framework/HelperGenerator.js +195 -0
- package/dist/framework/HelperGenerator.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js.map +1 -0
- package/dist/tasks/deploy.d.ts +2 -0
- package/dist/tasks/deploy.d.ts.map +1 -0
- package/dist/tasks/deploy.js +82 -0
- package/dist/tasks/deploy.js.map +1 -0
- package/dist/tasks/generate-helpers.d.ts +2 -0
- package/dist/tasks/generate-helpers.d.ts.map +1 -0
- package/dist/tasks/generate-helpers.js +66 -0
- package/dist/tasks/generate-helpers.js.map +1 -0
- package/dist/tasks/init.d.ts +2 -0
- package/dist/tasks/init.d.ts.map +1 -0
- package/dist/tasks/init.js +78 -0
- package/dist/tasks/init.js.map +1 -0
- package/dist/tasks/test.d.ts +2 -0
- package/dist/tasks/test.d.ts.map +1 -0
- package/dist/tasks/test.js +83 -0
- package/dist/tasks/test.js.map +1 -0
- package/dist/types/config.d.ts +41 -0
- package/dist/types/config.d.ts.map +1 -0
- package/dist/types/config.js +19 -0
- package/dist/types/config.js.map +1 -0
- package/dist/types/hardhat.d.ts +21 -0
- package/dist/types/hardhat.d.ts.map +1 -0
- package/dist/types/hardhat.js +8 -0
- package/dist/types/hardhat.js.map +1 -0
- package/dist/utils/foundry.d.ts +59 -0
- package/dist/utils/foundry.d.ts.map +1 -0
- package/dist/utils/foundry.js +164 -0
- package/dist/utils/foundry.js.map +1 -0
- package/dist/utils/logger.d.ts +38 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +66 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/validation.d.ts +33 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +131 -0
- package/dist/utils/validation.js.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HelperGenerator = void 0;
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const logger_1 = require("../utils/logger");
|
|
7
|
+
/**
|
|
8
|
+
* HelperGenerator - Generates Solidity helper files for testing
|
|
9
|
+
*/
|
|
10
|
+
class HelperGenerator {
|
|
11
|
+
hre;
|
|
12
|
+
constructor(hre) {
|
|
13
|
+
this.hre = hre;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Scaffold project with initial test structure
|
|
17
|
+
*/
|
|
18
|
+
async scaffoldProject(outputDir) {
|
|
19
|
+
const helpersDir = outputDir || this.hre.diamondsFoundry.helpersDir;
|
|
20
|
+
const basePath = (0, path_1.join)(this.hre.config.paths.root, helpersDir);
|
|
21
|
+
logger_1.Logger.section("Scaffolding Forge Test Structure");
|
|
22
|
+
// Create directories
|
|
23
|
+
logger_1.Logger.step("Creating directories...");
|
|
24
|
+
(0, fs_1.mkdirSync)(basePath, { recursive: true });
|
|
25
|
+
(0, fs_1.mkdirSync)((0, path_1.join)(basePath, "../unit"), { recursive: true });
|
|
26
|
+
(0, fs_1.mkdirSync)((0, path_1.join)(basePath, "../integration"), { recursive: true });
|
|
27
|
+
(0, fs_1.mkdirSync)((0, path_1.join)(basePath, "../fuzz"), { recursive: true });
|
|
28
|
+
logger_1.Logger.success(`Test structure created at ${basePath}`);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Generate DiamondDeployment.sol from deployment record
|
|
32
|
+
*/
|
|
33
|
+
async generateDeploymentHelpers(diamondName, networkName, chainId, deploymentData) {
|
|
34
|
+
logger_1.Logger.section("Generating Diamond Deployment Helper");
|
|
35
|
+
const helpersDir = this.hre.diamondsFoundry.helpersDir;
|
|
36
|
+
const outputPath = (0, path_1.join)(this.hre.config.paths.root, helpersDir, "DiamondDeployment.sol");
|
|
37
|
+
const content = this.generateLibrarySource(diamondName, networkName, chainId, deploymentData);
|
|
38
|
+
// Ensure directory exists
|
|
39
|
+
(0, fs_1.mkdirSync)((0, path_1.join)(this.hre.config.paths.root, helpersDir), {
|
|
40
|
+
recursive: true,
|
|
41
|
+
});
|
|
42
|
+
// Write file
|
|
43
|
+
(0, fs_1.writeFileSync)(outputPath, content, "utf8");
|
|
44
|
+
logger_1.Logger.success(`Generated: ${outputPath}`);
|
|
45
|
+
return outputPath;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Generate example test files
|
|
49
|
+
*/
|
|
50
|
+
async generateExampleTests() {
|
|
51
|
+
const generated = [];
|
|
52
|
+
const examples = this.hre.diamondsFoundry.exampleTests;
|
|
53
|
+
if (!this.hre.diamondsFoundry.generateExamples) {
|
|
54
|
+
logger_1.Logger.info("Example generation disabled in config");
|
|
55
|
+
return generated;
|
|
56
|
+
}
|
|
57
|
+
logger_1.Logger.section("Generating Example Tests");
|
|
58
|
+
const basePath = (0, path_1.join)(this.hre.config.paths.root, "test", "foundry");
|
|
59
|
+
const templatesPath = (0, path_1.join)(__dirname, "../templates");
|
|
60
|
+
for (const type of examples) {
|
|
61
|
+
let templateFile = "";
|
|
62
|
+
let outputPath = "";
|
|
63
|
+
switch (type) {
|
|
64
|
+
case "unit":
|
|
65
|
+
templateFile = (0, path_1.join)(templatesPath, "ExampleUnitTest.t.sol.template");
|
|
66
|
+
outputPath = (0, path_1.join)(basePath, "unit", "ExampleUnit.t.sol");
|
|
67
|
+
break;
|
|
68
|
+
case "integration":
|
|
69
|
+
templateFile = (0, path_1.join)(templatesPath, "ExampleIntegrationTest.t.sol.template");
|
|
70
|
+
outputPath = (0, path_1.join)(basePath, "integration", "ExampleIntegration.t.sol");
|
|
71
|
+
break;
|
|
72
|
+
case "fuzz":
|
|
73
|
+
templateFile = (0, path_1.join)(templatesPath, "ExampleFuzzTest.t.sol.template");
|
|
74
|
+
outputPath = (0, path_1.join)(basePath, "fuzz", "ExampleFuzz.t.sol");
|
|
75
|
+
break;
|
|
76
|
+
default:
|
|
77
|
+
logger_1.Logger.warn(`Unknown example type: ${type}`);
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
try {
|
|
81
|
+
// Check if template exists
|
|
82
|
+
if (!(0, fs_1.existsSync)(templateFile)) {
|
|
83
|
+
logger_1.Logger.warn(`Template not found: ${templateFile}`);
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
// Read template content
|
|
87
|
+
const templateContent = (0, fs_1.readFileSync)(templateFile, "utf8");
|
|
88
|
+
// Ensure output directory exists
|
|
89
|
+
(0, fs_1.mkdirSync)((0, path_1.join)(basePath, type), { recursive: true });
|
|
90
|
+
// Check if file already exists
|
|
91
|
+
if ((0, fs_1.existsSync)(outputPath)) {
|
|
92
|
+
logger_1.Logger.info(`Skipping ${type} example (already exists): ${outputPath}`);
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
// Write example test file
|
|
96
|
+
(0, fs_1.writeFileSync)(outputPath, templateContent, "utf8");
|
|
97
|
+
logger_1.Logger.success(`Generated ${type} example: ${outputPath}`);
|
|
98
|
+
generated.push(outputPath);
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
logger_1.Logger.error(`Failed to generate ${type} example: ${error.message}`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (generated.length === 0) {
|
|
105
|
+
logger_1.Logger.info("No new example tests generated (may already exist)");
|
|
106
|
+
}
|
|
107
|
+
return generated;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Generate Solidity library source from deployment data
|
|
111
|
+
* @private
|
|
112
|
+
*/
|
|
113
|
+
generateLibrarySource(diamondName, networkName, chainId, deploymentData) {
|
|
114
|
+
const timestamp = new Date().toISOString();
|
|
115
|
+
const networkInfo = `${networkName}-${chainId}`;
|
|
116
|
+
const deploymentFileName = `${diamondName.toLowerCase()}-${networkInfo}.json`;
|
|
117
|
+
const deploymentFilePath = `diamonds/${diamondName}/deployments/${deploymentFileName}`;
|
|
118
|
+
let source = "";
|
|
119
|
+
// SPDX and pragma
|
|
120
|
+
source += "// SPDX-License-Identifier: MIT\n";
|
|
121
|
+
source += "pragma solidity ^0.8.19;\n\n";
|
|
122
|
+
// Header comments
|
|
123
|
+
source += "/**\n";
|
|
124
|
+
source += ` * @title DiamondDeployment\n`;
|
|
125
|
+
source += ` * @notice Auto-generated deployment data for ${diamondName}\n`;
|
|
126
|
+
source += ` * @dev This library provides constants and helper functions for accessing\n`;
|
|
127
|
+
source += ` * deployment data in Forge tests. It is auto-generated from the deployment\n`;
|
|
128
|
+
source += ` * record and should not be edited manually.\n`;
|
|
129
|
+
source += ` *\n`;
|
|
130
|
+
source += ` * Generated from: ${deploymentFilePath}\n`;
|
|
131
|
+
source += ` * Generated at: ${timestamp}\n`;
|
|
132
|
+
source += ` *\n`;
|
|
133
|
+
source += ` * To regenerate this file:\n`;
|
|
134
|
+
source += ` * npx hardhat diamonds-forge:generate-helpers --diamond ${diamondName}\n`;
|
|
135
|
+
source += ` *\n`;
|
|
136
|
+
source += ` * ⚠️ DO NOT EDIT MANUALLY - Changes will be overwritten on next generation\n`;
|
|
137
|
+
source += " */\n";
|
|
138
|
+
source += "library DiamondDeployment {\n";
|
|
139
|
+
// Diamond address
|
|
140
|
+
source += ` /// @notice Address of the deployed ${diamondName} contract\n`;
|
|
141
|
+
source += ` /// @dev This is the main Diamond proxy address\n`;
|
|
142
|
+
source += ` address constant DIAMOND_ADDRESS = ${deploymentData.DiamondAddress};\n\n`;
|
|
143
|
+
// Facet addresses
|
|
144
|
+
source += " // ========================================\n";
|
|
145
|
+
source += " // Facet Addresses\n";
|
|
146
|
+
source += " // ========================================\n\n";
|
|
147
|
+
const facets = deploymentData.DeployedFacets ?? {};
|
|
148
|
+
for (const [facetName, facetData] of Object.entries(facets)) {
|
|
149
|
+
const constantName = facetName
|
|
150
|
+
.replace(/Facet$/, "")
|
|
151
|
+
.replace(/([A-Z])/g, "_$1")
|
|
152
|
+
.toUpperCase()
|
|
153
|
+
.replace(/^_/, "") + "_FACET";
|
|
154
|
+
source += ` /// @notice Address of ${facetName} implementation\n`;
|
|
155
|
+
source += ` address constant ${constantName} = ${facetData.address};\n`;
|
|
156
|
+
}
|
|
157
|
+
source += "\n";
|
|
158
|
+
// Helper functions
|
|
159
|
+
source += " // ========================================\n";
|
|
160
|
+
source += " // Helper Functions\n";
|
|
161
|
+
source += " // ========================================\n\n";
|
|
162
|
+
source += " /**\n";
|
|
163
|
+
source += " * @notice Get the Diamond contract address\n";
|
|
164
|
+
source += " * @return The address of the deployed Diamond proxy\n";
|
|
165
|
+
source += " */\n";
|
|
166
|
+
source += " function getDiamondAddress() internal pure returns (address) {\n";
|
|
167
|
+
source += " return DIAMOND_ADDRESS;\n";
|
|
168
|
+
source += " }\n\n";
|
|
169
|
+
source += " /**\n";
|
|
170
|
+
source += " * @notice Get facet implementation address by name\n";
|
|
171
|
+
source += " * @param facetName The name of the facet\n";
|
|
172
|
+
source += " * @return The address of the facet implementation\n";
|
|
173
|
+
source += " */\n";
|
|
174
|
+
source += " function getFacetAddress(string memory facetName) internal pure returns (address) {\n";
|
|
175
|
+
let firstFacet = true;
|
|
176
|
+
for (const [facetName, facetData] of Object.entries(facets)) {
|
|
177
|
+
const constantName = facetName
|
|
178
|
+
.replace(/Facet$/, "")
|
|
179
|
+
.replace(/([A-Z])/g, "_$1")
|
|
180
|
+
.toUpperCase()
|
|
181
|
+
.replace(/^_/, "") + "_FACET";
|
|
182
|
+
const condition = firstFacet ? "if" : "else if";
|
|
183
|
+
source += ` ${condition} (keccak256(bytes(facetName)) == keccak256(bytes("${facetName}"))) {\n`;
|
|
184
|
+
source += ` return ${constantName};\n`;
|
|
185
|
+
source += " }\n";
|
|
186
|
+
firstFacet = false;
|
|
187
|
+
}
|
|
188
|
+
source += " return address(0);\n";
|
|
189
|
+
source += " }\n";
|
|
190
|
+
source += "}\n";
|
|
191
|
+
return source;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
exports.HelperGenerator = HelperGenerator;
|
|
195
|
+
//# sourceMappingURL=HelperGenerator.js.map
|
|
@@ -0,0 +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,E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AAY,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;AA5OD,0CA4OC","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 */\n async generateDeploymentHelpers(\n diamondName: string,\n networkName: string,\n chainId: number,\n deploymentData: DeployedDiamondData\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 return outputPath;\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 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 // 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 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 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
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import "./tasks/deploy";
|
|
2
|
+
import "./tasks/generate-helpers";
|
|
3
|
+
import "./tasks/init";
|
|
4
|
+
import "./tasks/test";
|
|
5
|
+
import "./types/hardhat";
|
|
6
|
+
export { DeploymentManager } from "./framework/DeploymentManager";
|
|
7
|
+
export { ForgeFuzzingFramework } from "./framework/ForgeFuzzingFramework";
|
|
8
|
+
export { HelperGenerator } from "./framework/HelperGenerator";
|
|
9
|
+
export * from "./types/config";
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +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,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAG9D,cAAc,gBAAgB,CAAC"}
|
|
@@ -0,0 +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,gDAAgD;AAChD,mEAAkE;AAAzD,sHAAA,iBAAiB,OAAA;AAC1B,2EAA0E;AAAjE,8HAAA,qBAAqB,OAAA;AAC9B,+DAA8D;AAArD,kHAAA,eAAe,OAAA;AAExB,eAAe;AACf,iDAA+B;AAE/B,MAAM,iBAAiB,GAAG,cAAc,CAAC;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,CACV,oBAAU,CAAC,MAAM,CAAC,6CAA6C,CAAC,CACjE,CAAC;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 framework classes for programmatic use\nexport { DeploymentManager } from \"./framework/DeploymentManager\";\nexport { ForgeFuzzingFramework } from \"./framework/ForgeFuzzingFramework\";\nexport { HelperGenerator } from \"./framework/HelperGenerator\";\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 @@
|
|
|
1
|
+
{"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../../src/tasks/deploy.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const config_1 = require("hardhat/config");
|
|
4
|
+
const DeploymentManager_1 = require("../framework/DeploymentManager");
|
|
5
|
+
const logger_1 = require("../utils/logger");
|
|
6
|
+
const validation_1 = require("../utils/validation");
|
|
7
|
+
/**
|
|
8
|
+
* Task: diamonds-forge:deploy
|
|
9
|
+
*
|
|
10
|
+
* Deploys a Diamond contract for Forge testing.
|
|
11
|
+
* - Validates Foundry installation
|
|
12
|
+
* - Deploys Diamond using LocalDiamondDeployer
|
|
13
|
+
* - Saves deployment record
|
|
14
|
+
* - Optionally reuses existing deployment
|
|
15
|
+
*
|
|
16
|
+
* Use Hardhat's built-in --network flag to specify the network
|
|
17
|
+
*/
|
|
18
|
+
(0, config_1.task)("diamonds-forge:deploy", "Deploy Diamond contract for Forge testing")
|
|
19
|
+
.addOptionalParam("diamondName", "Name of the Diamond to deploy", "ExampleDiamond", config_1.types.string)
|
|
20
|
+
.addFlag("reuse", "Reuse existing deployment if available")
|
|
21
|
+
.addFlag("force", "Force redeployment even if deployment exists")
|
|
22
|
+
.setAction(async (taskArgs, hre) => {
|
|
23
|
+
logger_1.Logger.section("Deploying Diamond for Forge Testing");
|
|
24
|
+
// Use Hardhat's built-in network name from HRE
|
|
25
|
+
const networkName = hre.network.name;
|
|
26
|
+
const diamondName = taskArgs.diamondName;
|
|
27
|
+
const reuse = taskArgs.reuse;
|
|
28
|
+
const force = taskArgs.force;
|
|
29
|
+
// Validate flags
|
|
30
|
+
if (reuse && force) {
|
|
31
|
+
logger_1.Logger.error("Cannot use both --reuse and --force flags");
|
|
32
|
+
throw new Error("Conflicting flags: --reuse and --force");
|
|
33
|
+
}
|
|
34
|
+
logger_1.Logger.info(`Diamond: ${diamondName}`);
|
|
35
|
+
logger_1.Logger.info(`Network: ${networkName}`);
|
|
36
|
+
logger_1.Logger.info(`Mode: ${force ? "force deploy" : reuse ? "reuse if exists" : "deploy new"}`);
|
|
37
|
+
// Step 1: Validate Foundry (optional for deployment, but recommended)
|
|
38
|
+
logger_1.Logger.step("Checking Foundry installation...");
|
|
39
|
+
const foundryInstalled = (0, validation_1.validateFoundryInstallation)();
|
|
40
|
+
if (!foundryInstalled) {
|
|
41
|
+
logger_1.Logger.warn("Foundry is not installed");
|
|
42
|
+
logger_1.Logger.warn("You'll need it to run tests later");
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
logger_1.Logger.success("Foundry is installed");
|
|
46
|
+
}
|
|
47
|
+
// Step 2: Deploy or reuse Diamond
|
|
48
|
+
logger_1.Logger.step("Deploying Diamond contract...");
|
|
49
|
+
const deploymentManager = new DeploymentManager_1.DeploymentManager(hre);
|
|
50
|
+
try {
|
|
51
|
+
let diamond;
|
|
52
|
+
if (reuse) {
|
|
53
|
+
// Try to reuse, deploy if not exists
|
|
54
|
+
diamond = await deploymentManager.ensureDeployment(diamondName, networkName, false);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
// Deploy (force if flag is set)
|
|
58
|
+
diamond = await deploymentManager.deploy(diamondName, networkName, force);
|
|
59
|
+
}
|
|
60
|
+
// Step 3: Display deployment info
|
|
61
|
+
const deploymentData = diamond.getDeployedDiamondData();
|
|
62
|
+
logger_1.Logger.section("Deployment Summary");
|
|
63
|
+
logger_1.Logger.success(`Diamond Address: ${deploymentData.DiamondAddress}`);
|
|
64
|
+
logger_1.Logger.info(`Deployer Address: ${deploymentData.DeployerAddress}`);
|
|
65
|
+
const facetCount = Object.keys(deploymentData.DeployedFacets || {}).length;
|
|
66
|
+
logger_1.Logger.info(`Facets Deployed: ${facetCount}`);
|
|
67
|
+
if (facetCount > 0) {
|
|
68
|
+
logger_1.Logger.info("\nDeployed Facets:");
|
|
69
|
+
for (const [name, facet] of Object.entries(deploymentData.DeployedFacets || {})) {
|
|
70
|
+
logger_1.Logger.info(` - ${name}: ${facet.address}`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
logger_1.Logger.section("Next Steps");
|
|
74
|
+
logger_1.Logger.info("Generate helpers: npx hardhat diamonds-forge:generate-helpers");
|
|
75
|
+
logger_1.Logger.info("Run tests: npx hardhat diamonds-forge:test");
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
logger_1.Logger.error(`Deployment failed: ${error.message}`);
|
|
79
|
+
throw error;
|
|
80
|
+
}
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,IAAI,CAAC,oBAAoB,CAAC,CAAC;YAClC,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,cAAc,IAAI,EAAE,CAAC,EAAE;gBAC/E,eAAM,CAAC,IAAI,CAAC,OAAO,IAAI,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;aAC9C;SACF;QAED,eAAM,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;QAC7B,eAAM,CAAC,IAAI,CAAC,+DAA+D,CAAC,CAAC;QAC7E,eAAM,CAAC,IAAI,CAAC,4CAA4C,CAAC,CAAC;KAE3D;IAAC,OAAO,KAAU,EAAE;QACnB,eAAM,CAAC,KAAK,CAAC,sBAAsB,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QACpD,MAAM,KAAK,CAAC;KACb;AACH,CAAC,CAAC,CAAC","sourcesContent":["import { task, types } from \"hardhat/config\";\nimport { HardhatRuntimeEnvironment } from \"hardhat/types\";\nimport { DeploymentManager } from \"../framework/DeploymentManager\";\nimport { Logger } from \"../utils/logger\";\nimport { validateFoundryInstallation } from \"../utils/validation\";\n\n/**\n * Task: diamonds-forge:deploy\n * \n * Deploys a Diamond contract for Forge testing.\n * - Validates Foundry installation\n * - Deploys Diamond using LocalDiamondDeployer\n * - Saves deployment record\n * - Optionally reuses existing deployment\n * \n * Use Hardhat's built-in --network flag to specify the network\n */\ntask(\"diamonds-forge:deploy\", \"Deploy Diamond contract for Forge testing\")\n .addOptionalParam(\n \"diamondName\",\n \"Name of the Diamond to deploy\",\n \"ExampleDiamond\",\n types.string\n )\n .addFlag(\"reuse\", \"Reuse existing deployment if available\")\n .addFlag(\"force\", \"Force redeployment even if deployment exists\")\n .setAction(async (taskArgs, hre: HardhatRuntimeEnvironment) => {\n Logger.section(\"Deploying Diamond for Forge Testing\");\n\n // Use Hardhat's built-in network name from HRE\n const networkName = hre.network.name;\n const diamondName = taskArgs.diamondName;\n const reuse = taskArgs.reuse;\n const force = taskArgs.force;\n\n // Validate flags\n if (reuse && force) {\n Logger.error(\"Cannot use both --reuse and --force flags\");\n throw new Error(\"Conflicting flags: --reuse and --force\");\n }\n\n Logger.info(`Diamond: ${diamondName}`);\n Logger.info(`Network: ${networkName}`);\n Logger.info(`Mode: ${force ? \"force deploy\" : reuse ? \"reuse if exists\" : \"deploy new\"}`);\n\n // Step 1: Validate Foundry (optional for deployment, but recommended)\n Logger.step(\"Checking Foundry installation...\");\n const foundryInstalled = validateFoundryInstallation();\n \n if (!foundryInstalled) {\n Logger.warn(\"Foundry is not installed\");\n Logger.warn(\"You'll need it to run tests later\");\n } else {\n Logger.success(\"Foundry is installed\");\n }\n\n // Step 2: Deploy or reuse Diamond\n Logger.step(\"Deploying Diamond contract...\");\n const deploymentManager = new DeploymentManager(hre);\n\n try {\n let diamond;\n \n if (reuse) {\n // Try to reuse, deploy if not exists\n diamond = await deploymentManager.ensureDeployment(\n diamondName,\n networkName,\n false\n );\n } else {\n // Deploy (force if flag is set)\n diamond = await deploymentManager.deploy(\n diamondName,\n networkName,\n force\n );\n }\n\n // Step 3: Display deployment info\n const deploymentData = diamond.getDeployedDiamondData();\n \n Logger.section(\"Deployment Summary\");\n Logger.success(`Diamond Address: ${deploymentData.DiamondAddress}`);\n Logger.info(`Deployer Address: ${deploymentData.DeployerAddress}`);\n \n const facetCount = Object.keys(deploymentData.DeployedFacets || {}).length;\n Logger.info(`Facets Deployed: ${facetCount}`);\n \n if (facetCount > 0) {\n Logger.info(\"\\nDeployed Facets:\");\n for (const [name, facet] of Object.entries(deploymentData.DeployedFacets || {})) {\n Logger.info(` - ${name}: ${facet.address}`);\n }\n }\n\n Logger.section(\"Next Steps\");\n Logger.info(\"Generate helpers: npx hardhat diamonds-forge:generate-helpers\");\n Logger.info(\"Run tests: npx hardhat diamonds-forge:test\");\n\n } catch (error: any) {\n Logger.error(`Deployment failed: ${error.message}`);\n throw error;\n }\n });\n\n\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-helpers.d.ts","sourceRoot":"","sources":["../../src/tasks/generate-helpers.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const config_1 = require("hardhat/config");
|
|
4
|
+
const DeploymentManager_1 = require("../framework/DeploymentManager");
|
|
5
|
+
const HelperGenerator_1 = require("../framework/HelperGenerator");
|
|
6
|
+
const logger_1 = require("../utils/logger");
|
|
7
|
+
/**
|
|
8
|
+
* Task: diamonds-forge:generate-helpers
|
|
9
|
+
*
|
|
10
|
+
* Generates Solidity helper files from Diamond deployment data.
|
|
11
|
+
* - Reads deployment record
|
|
12
|
+
* - Generates DiamondDeployment.sol library
|
|
13
|
+
* - Creates constants for addresses and facets
|
|
14
|
+
*
|
|
15
|
+
* Use Hardhat's built-in --network flag to specify the network
|
|
16
|
+
*/
|
|
17
|
+
(0, config_1.task)("diamonds-forge:generate-helpers", "Generate Solidity helpers from Diamond deployment")
|
|
18
|
+
.addOptionalParam("diamondName", "Name of the deployed Diamond", "ExampleDiamond", config_1.types.string)
|
|
19
|
+
.addOptionalParam("outputDir", "Directory for generated helper files", undefined, config_1.types.string)
|
|
20
|
+
.setAction(async (taskArgs, hre) => {
|
|
21
|
+
logger_1.Logger.section("Generating Diamond Deployment Helpers");
|
|
22
|
+
const diamondName = taskArgs.diamondName;
|
|
23
|
+
// Use Hardhat's built-in network name from HRE
|
|
24
|
+
const networkName = hre.network.name;
|
|
25
|
+
const outputDir = taskArgs.outputDir || hre.diamondsFoundry.helpersDir;
|
|
26
|
+
logger_1.Logger.info(`Diamond: ${diamondName}`);
|
|
27
|
+
logger_1.Logger.info(`Network: ${networkName}`);
|
|
28
|
+
logger_1.Logger.info(`Output: ${outputDir}`);
|
|
29
|
+
// Step 1: Get deployment
|
|
30
|
+
logger_1.Logger.step("Loading deployment data...");
|
|
31
|
+
const deploymentManager = new DeploymentManager_1.DeploymentManager(hre);
|
|
32
|
+
try {
|
|
33
|
+
const diamond = await deploymentManager.getDeployment(diamondName, networkName);
|
|
34
|
+
if (!diamond) {
|
|
35
|
+
logger_1.Logger.error("No deployment found");
|
|
36
|
+
logger_1.Logger.info(`Deploy first: npx hardhat diamonds-forge:deploy --diamond-name ${diamondName} --network ${networkName}`);
|
|
37
|
+
throw new Error("Deployment not found");
|
|
38
|
+
}
|
|
39
|
+
logger_1.Logger.success("Deployment loaded");
|
|
40
|
+
// Step 2: Get network info for chainId
|
|
41
|
+
const provider = hre.ethers.provider;
|
|
42
|
+
const network = await provider.getNetwork();
|
|
43
|
+
const chainId = Number(network.chainId);
|
|
44
|
+
// Step 3: Generate helpers
|
|
45
|
+
logger_1.Logger.step("Generating Solidity helpers...");
|
|
46
|
+
const generator = new HelperGenerator_1.HelperGenerator(hre);
|
|
47
|
+
const deploymentData = diamond.getDeployedDiamondData();
|
|
48
|
+
const helperPath = await generator.generateDeploymentHelpers(diamondName, networkName, chainId, deploymentData);
|
|
49
|
+
// Step 4: Summary
|
|
50
|
+
logger_1.Logger.section("Helper Generation Complete");
|
|
51
|
+
logger_1.Logger.success(`Generated: ${helperPath}`);
|
|
52
|
+
const facetCount = Object.keys(deploymentData.DeployedFacets || {}).length;
|
|
53
|
+
logger_1.Logger.info(`Diamond Address: ${deploymentData.DiamondAddress}`);
|
|
54
|
+
logger_1.Logger.info(`Facets Included: ${facetCount}`);
|
|
55
|
+
logger_1.Logger.section("Next Steps");
|
|
56
|
+
logger_1.Logger.info("Import in your test files:");
|
|
57
|
+
logger_1.Logger.info(` import "../../helpers/DiamondDeployment.sol";`);
|
|
58
|
+
logger_1.Logger.info("\nRun tests:");
|
|
59
|
+
logger_1.Logger.info(` npx hardhat diamonds-forge:test`);
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
logger_1.Logger.error(`Helper generation failed: ${error.message}`);
|
|
63
|
+
throw error;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
//# sourceMappingURL=generate-helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-helpers.js","sourceRoot":"","sources":["../../src/tasks/generate-helpers.ts"],"names":[],"mappings":";;AAAA,2CAA6C;AAE7C,sEAAmE;AACnE,kEAA+D;AAC/D,4CAAyC;AAEzC;;;;;;;;;GASG;AACH,IAAA,aAAI,EAAC,iCAAiC,EAAE,mDAAmD,CAAC;KACzF,gBAAgB,CACf,aAAa,EACb,8BAA8B,EAC9B,gBAAgB,EAChB,cAAK,CAAC,MAAM,CACb;KACA,gBAAgB,CACf,WAAW,EACX,sCAAsC,EACtC,SAAS,EACT,cAAK,CAAC,MAAM,CACb;KACA,SAAS,CAAC,KAAK,EAAE,QAAQ,EAAE,GAA8B,EAAE,EAAE;IAC5D,eAAM,CAAC,OAAO,CAAC,uCAAuC,CAAC,CAAC;IAExD,MAAM,WAAW,GAAG,QAAQ,CAAC,WAAW,CAAC;IACzC,+CAA+C;IAC/C,MAAM,WAAW,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC;IACrC,MAAM,SAAS,GAAG,QAAQ,CAAC,SAAS,IAAI,GAAG,CAAC,eAAe,CAAC,UAAU,CAAC;IAEvE,eAAM,CAAC,IAAI,CAAC,YAAY,WAAW,EAAE,CAAC,CAAC;IACvC,eAAM,CAAC,IAAI,CAAC,YAAY,WAAW,EAAE,CAAC,CAAC;IACvC,eAAM,CAAC,IAAI,CAAC,WAAW,SAAS,EAAE,CAAC,CAAC;IAEpC,yBAAyB;IACzB,eAAM,CAAC,IAAI,CAAC,4BAA4B,CAAC,CAAC;IAC1C,MAAM,iBAAiB,GAAG,IAAI,qCAAiB,CAAC,GAAG,CAAC,CAAC;IAErD,IAAI;QACF,MAAM,OAAO,GAAG,MAAM,iBAAiB,CAAC,aAAa,CACnD,WAAW,EACX,WAAW,CACZ,CAAC;QAEF,IAAI,CAAC,OAAO,EAAE;YACZ,eA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CAAC,CAAC;QAC/D,eAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QAC5B,eAAM,CAAC,IAAI,CAAC,mCAAmC,CAAC,CAAC;KAElD;IAAC,OAAO,KAAU,EAAE;QACnB,eAAM,CAAC,KAAK,CAAC,6BAA6B,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QAC3D,MAAM,KAAK,CAAC;KACb;AACH,CAAC,CAAC,CAAC","sourcesContent":["import { task, types } from \"hardhat/config\";\nimport { HardhatRuntimeEnvironment } from \"hardhat/types\";\nimport { DeploymentManager } from \"../framework/DeploymentManager\";\nimport { HelperGenerator } from \"../framework/HelperGenerator\";\nimport { Logger } from \"../utils/logger\";\n\n/**\n * Task: diamonds-forge:generate-helpers\n * \n * Generates Solidity helper files from Diamond deployment data.\n * - Reads deployment record\n * - Generates DiamondDeployment.sol library\n * - Creates constants for addresses and facets\n * \n * Use Hardhat's built-in --network flag to specify the network\n */\ntask(\"diamonds-forge:generate-helpers\", \"Generate Solidity helpers from Diamond deployment\")\n .addOptionalParam(\n \"diamondName\",\n \"Name of the deployed Diamond\",\n \"ExampleDiamond\",\n types.string\n )\n .addOptionalParam(\n \"outputDir\",\n \"Directory for generated helper files\",\n undefined,\n types.string\n )\n .setAction(async (taskArgs, hre: HardhatRuntimeEnvironment) => {\n Logger.section(\"Generating Diamond Deployment Helpers\");\n\n const diamondName = taskArgs.diamondName;\n // Use Hardhat's built-in network name from HRE\n const networkName = hre.network.name;\n const outputDir = taskArgs.outputDir || hre.diamondsFoundry.helpersDir;\n\n Logger.info(`Diamond: ${diamondName}`);\n Logger.info(`Network: ${networkName}`);\n Logger.info(`Output: ${outputDir}`);\n\n // Step 1: Get deployment\n Logger.step(\"Loading deployment data...\");\n const deploymentManager = new DeploymentManager(hre);\n \n try {\n const diamond = await deploymentManager.getDeployment(\n diamondName,\n networkName\n );\n\n if (!diamond) {\n Logger.error(\"No deployment found\");\n Logger.info(`Deploy first: npx hardhat diamonds-forge:deploy --diamond-name ${diamondName} --network ${networkName}`);\n throw new Error(\"Deployment not found\");\n }\n\n Logger.success(\"Deployment loaded\");\n\n // Step 2: Get network info for chainId\n const provider = hre.ethers.provider;\n const network = await provider.getNetwork();\n const chainId = Number(network.chainId);\n\n // Step 3: Generate helpers\n Logger.step(\"Generating Solidity helpers...\");\n const generator = new HelperGenerator(hre);\n \n const deploymentData = diamond.getDeployedDiamondData();\n \n const helperPath = await generator.generateDeploymentHelpers(\n diamondName,\n networkName,\n chainId,\n deploymentData\n );\n\n // Step 4: Summary\n Logger.section(\"Helper Generation Complete\");\n Logger.success(`Generated: ${helperPath}`);\n \n const facetCount = Object.keys(deploymentData.DeployedFacets || {}).length;\n Logger.info(`Diamond Address: ${deploymentData.DiamondAddress}`);\n Logger.info(`Facets Included: ${facetCount}`);\n\n Logger.section(\"Next Steps\");\n Logger.info(\"Import in your test files:\");\n Logger.info(` import \"../../helpers/DiamondDeployment.sol\";`);\n Logger.info(\"\\nRun tests:\");\n Logger.info(` npx hardhat diamonds-forge:test`);\n\n } catch (error: any) {\n Logger.error(`Helper generation failed: ${error.message}`);\n throw error;\n }\n });\n\n\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/tasks/init.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const config_1 = require("hardhat/config");
|
|
4
|
+
const HelperGenerator_1 = require("../framework/HelperGenerator");
|
|
5
|
+
const logger_1 = require("../utils/logger");
|
|
6
|
+
const validation_1 = require("../utils/validation");
|
|
7
|
+
/**
|
|
8
|
+
* Task: diamonds-forge:init
|
|
9
|
+
*
|
|
10
|
+
* Initializes the project for Forge testing with Diamond contracts.
|
|
11
|
+
* - Validates configuration
|
|
12
|
+
* - Checks Foundry installation
|
|
13
|
+
* - Scaffolds test directory structure
|
|
14
|
+
* - Optionally generates example tests
|
|
15
|
+
*/
|
|
16
|
+
(0, config_1.task)("diamonds-forge:init", "Initialize Forge testing structure for Diamond contracts")
|
|
17
|
+
.addOptionalParam("helpersDir", "Directory for generated helper files", undefined, config_1.types.string)
|
|
18
|
+
.addFlag("examples", "Generate example test files")
|
|
19
|
+
.addFlag("force", "Overwrite existing files")
|
|
20
|
+
.setAction(async (taskArgs, hre) => {
|
|
21
|
+
logger_1.Logger.section("Initializing Diamonds-Forge Testing");
|
|
22
|
+
// Step 1: Validate configuration
|
|
23
|
+
logger_1.Logger.step("Validating configuration...");
|
|
24
|
+
const config = (0, validation_1.validateConfig)(hre.diamondsFoundry);
|
|
25
|
+
// Override with task args if provided
|
|
26
|
+
const helpersDir = taskArgs.helpersDir || config.helpersDir;
|
|
27
|
+
const generateExamples = taskArgs.examples || config.generateExamples;
|
|
28
|
+
logger_1.Logger.info(`Helpers directory: ${helpersDir}`);
|
|
29
|
+
logger_1.Logger.info(`Generate examples: ${generateExamples}`);
|
|
30
|
+
// Step 2: Check Foundry installation
|
|
31
|
+
logger_1.Logger.step("Checking Foundry installation...");
|
|
32
|
+
const foundryInstalled = (0, validation_1.validateFoundryInstallation)();
|
|
33
|
+
if (!foundryInstalled) {
|
|
34
|
+
logger_1.Logger.warn("Foundry is not installed or not in PATH");
|
|
35
|
+
logger_1.Logger.warn("Install from: https://book.getfoundry.sh/getting-started/installation");
|
|
36
|
+
logger_1.Logger.warn("Continuing anyway...");
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
logger_1.Logger.success("Foundry is installed");
|
|
40
|
+
}
|
|
41
|
+
// Step 3: Scaffold project structure
|
|
42
|
+
logger_1.Logger.step("Creating test directory structure...");
|
|
43
|
+
const generator = new HelperGenerator_1.HelperGenerator(hre);
|
|
44
|
+
try {
|
|
45
|
+
await generator.scaffoldProject(helpersDir);
|
|
46
|
+
logger_1.Logger.success("Directory structure created");
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
logger_1.Logger.error(`Failed to scaffold project: ${error.message}`);
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
52
|
+
// Step 4: Generate example tests if requested
|
|
53
|
+
if (generateExamples) {
|
|
54
|
+
logger_1.Logger.step("Generating example test files...");
|
|
55
|
+
try {
|
|
56
|
+
const examplePaths = await generator.generateExampleTests();
|
|
57
|
+
if (examplePaths.length > 0) {
|
|
58
|
+
logger_1.Logger.success(`Generated ${examplePaths.length} example test(s)`);
|
|
59
|
+
examplePaths.forEach((path) => logger_1.Logger.info(` - ${path}`));
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
logger_1.Logger.info("No example tests generated (implementation pending)");
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
logger_1.Logger.error(`Failed to generate examples: ${error.message}`);
|
|
67
|
+
throw error;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
// Step 5: Summary
|
|
71
|
+
logger_1.Logger.section("Initialization Complete");
|
|
72
|
+
logger_1.Logger.success("Your project is ready for Forge testing!");
|
|
73
|
+
logger_1.Logger.info("\nNext steps:");
|
|
74
|
+
logger_1.Logger.info(" 1. Deploy your Diamond: npx hardhat diamonds-forge:deploy");
|
|
75
|
+
logger_1.Logger.info(" 2. Generate helpers: npx hardhat diamonds-forge:generate-helpers");
|
|
76
|
+
logger_1.Logger.info(" 3. Run tests: npx hardhat diamonds-forge:test");
|
|
77
|
+
});
|
|
78
|
+
//# sourceMappingURL=init.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init.js","sourceRoot":"","sources":["../../src/tasks/init.ts"],"names":[],"mappings":";;AAAA,2CAA6C;AAE7C,kEAA+D;AAC/D,4CAAyC;AACzC,oDAAkF;AAElF;;;;;;;;GAQG;AACH,IAAA,aAAI,EAAC,qBAAqB,EAAE,0DAA0D,CAAC;KACpF,gBAAgB,CACf,YAAY,EACZ,sCAAsC,EACtC,SAAS,EACT,cA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,eAAM,CAAC,OAAO,CAAC,6BAA6B,CAAC,CAAC;KAC/C;IAAC,OAAO,KAAU,EAAE;QACnB,eAAM,CAAC,KAAK,CAAC,+BAA+B,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QAC7D,MAAM,KAAK,CAAC;KACb;IAED,8CAA8C;IAC9C,IAAI,gBAAgB,EAAE;QACpB,eAAM,CAAC,IAAI,CAAC,kCAAkC,CAAC,CAAC;QAChD,IAAI;YACF,MAAM,YAAY,GAAG,MAAM,SAAS,CAAC,oBAAoB,EAAE,CAAC;YAE5D,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE;gBAC3B,eAAM,CAAC,OAAO,CAAC,aAAa,YAAY,CAAC,MAAM,kBAAkB,CAAC,CAAC;gBACnE,YAAY,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,eAAM,CAAC,IAAI,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,CAAC;aAC5D;iBAAM;gBACL,eAAM,CAAC,IAAI,CAAC,qDAAqD,CAAC,CAAC;aACpE;SACF;QAAC,OAAO,KAAU,EAAE;YACnB,eAAM,CAAC,KAAK,CAAC,gCAAgC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;YAC9D,MAAM,KAAK,CAAC;SACb;KACF;IAED,kBAAkB;IAClB,eAAM,CAAC,OAAO,CAAC,yBAAyB,CAAC,CAAC;IAC1C,eAAM,CAAC,OAAO,CAAC,0CAA0C,CAAC,CAAC;IAC3D,eAAM,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;IAC7B,eAAM,CAAC,IAAI,CAAC,6DAA6D,CAAC,CAAC;IAC3E,eAAM,CAAC,IAAI,CAAC,oEAAoE,CAAC,CAAC;IAClF,eAAM,CAAC,IAAI,CAAC,iDAAiD,CAAC,CAAC;AACjE,CAAC,CAAC,CAAC","sourcesContent":["import { task, types } from \"hardhat/config\";\nimport { HardhatRuntimeEnvironment } from \"hardhat/types\";\nimport { HelperGenerator } from \"../framework/HelperGenerator\";\nimport { Logger } from \"../utils/logger\";\nimport { validateConfig, validateFoundryInstallation } from \"../utils/validation\";\n\n/**\n * Task: diamonds-forge:init\n * \n * Initializes the project for Forge testing with Diamond contracts.\n * - Validates configuration\n * - Checks Foundry installation\n * - Scaffolds test directory structure\n * - Optionally generates example tests\n */\ntask(\"diamonds-forge:init\", \"Initialize Forge testing structure for Diamond contracts\")\n .addOptionalParam(\n \"helpersDir\",\n \"Directory for generated helper files\",\n undefined,\n types.string\n )\n .addFlag(\"examples\", \"Generate example test files\")\n .addFlag(\"force\", \"Overwrite existing files\")\n .setAction(async (taskArgs, hre: HardhatRuntimeEnvironment) => {\n Logger.section(\"Initializing Diamonds-Forge Testing\");\n\n // Step 1: Validate configuration\n Logger.step(\"Validating configuration...\");\n const config = validateConfig(hre.diamondsFoundry);\n \n // Override with task args if provided\n const helpersDir = taskArgs.helpersDir || config.helpersDir;\n const generateExamples = taskArgs.examples || config.generateExamples;\n\n Logger.info(`Helpers directory: ${helpersDir}`);\n Logger.info(`Generate examples: ${generateExamples}`);\n\n // Step 2: Check Foundry installation\n Logger.step(\"Checking Foundry installation...\");\n const foundryInstalled = validateFoundryInstallation();\n \n if (!foundryInstalled) {\n Logger.warn(\"Foundry is not installed or not in PATH\");\n Logger.warn(\"Install from: https://book.getfoundry.sh/getting-started/installation\");\n Logger.warn(\"Continuing anyway...\");\n } else {\n Logger.success(\"Foundry is installed\");\n }\n\n // Step 3: Scaffold project structure\n Logger.step(\"Creating test directory structure...\");\n const generator = new HelperGenerator(hre);\n \n try {\n await generator.scaffoldProject(helpersDir);\n Logger.success(\"Directory structure created\");\n } catch (error: any) {\n Logger.error(`Failed to scaffold project: ${error.message}`);\n throw error;\n }\n\n // Step 4: Generate example tests if requested\n if (generateExamples) {\n Logger.step(\"Generating example test files...\");\n try {\n const examplePaths = await generator.generateExampleTests();\n \n if (examplePaths.length > 0) {\n Logger.success(`Generated ${examplePaths.length} example test(s)`);\n examplePaths.forEach((path) => Logger.info(` - ${path}`));\n } else {\n Logger.info(\"No example tests generated (implementation pending)\");\n }\n } catch (error: any) {\n Logger.error(`Failed to generate examples: ${error.message}`);\n throw error;\n }\n }\n\n // Step 5: Summary\n Logger.section(\"Initialization Complete\");\n Logger.success(\"Your project is ready for Forge testing!\");\n Logger.info(\"\\nNext steps:\");\n Logger.info(\" 1. Deploy your Diamond: npx hardhat diamonds-forge:deploy\");\n Logger.info(\" 2. Generate helpers: npx hardhat diamonds-forge:generate-helpers\");\n Logger.info(\" 3. Run tests: npx hardhat diamonds-forge:test\");\n });\n\n\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test.d.ts","sourceRoot":"","sources":["../../src/tasks/test.ts"],"names":[],"mappings":""}
|