@diamondslab/diamonds-hardhat-foundry 1.0.2 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/CHANGELOG.md +160 -0
  2. package/README.md +568 -4
  3. package/contracts/DiamondABILoader.sol +329 -0
  4. package/contracts/DiamondForgeHelpers.sol +309 -85
  5. package/contracts/DiamondFuzzBase.sol +305 -114
  6. package/dist/foundry.d.ts +28 -0
  7. package/dist/foundry.d.ts.map +1 -1
  8. package/dist/foundry.js +82 -1
  9. package/dist/foundry.js.map +1 -1
  10. package/dist/framework/DeploymentManager.d.ts +10 -11
  11. package/dist/framework/DeploymentManager.d.ts.map +1 -1
  12. package/dist/framework/DeploymentManager.js +56 -45
  13. package/dist/framework/DeploymentManager.js.map +1 -1
  14. package/dist/framework/ForgeFuzzingFramework.d.ts +4 -0
  15. package/dist/framework/ForgeFuzzingFramework.d.ts.map +1 -1
  16. package/dist/framework/ForgeFuzzingFramework.js +16 -2
  17. package/dist/framework/ForgeFuzzingFramework.js.map +1 -1
  18. package/dist/framework/HelperGenerator.d.ts.map +1 -1
  19. package/dist/framework/HelperGenerator.js +11 -0
  20. package/dist/framework/HelperGenerator.js.map +1 -1
  21. package/dist/index.d.ts +0 -3
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +0 -8
  24. package/dist/index.js.map +1 -1
  25. package/dist/tasks/deploy.js +3 -2
  26. package/dist/tasks/deploy.js.map +1 -1
  27. package/dist/tasks/generate-helpers.js +6 -4
  28. package/dist/tasks/generate-helpers.js.map +1 -1
  29. package/dist/tasks/init.js +3 -2
  30. package/dist/tasks/init.js.map +1 -1
  31. package/dist/tasks/test.js +13 -2
  32. package/dist/tasks/test.js.map +1 -1
  33. package/dist/templates/DiamondDeployment.sol.template +38 -0
  34. package/dist/templates/ExampleFuzzTest.t.sol.template +118 -0
  35. package/dist/templates/ExampleIntegrationTest.t.sol.template +87 -0
  36. package/dist/templates/ExampleUnitTest.t.sol.template +65 -0
  37. package/dist/types/hardhat.d.ts +1 -1
  38. package/dist/types/hardhat.d.ts.map +1 -1
  39. package/dist/types/hardhat.js +1 -0
  40. package/dist/types/hardhat.js.map +1 -1
  41. package/dist/utils/foundry.d.ts +1 -0
  42. package/dist/utils/foundry.d.ts.map +1 -1
  43. package/dist/utils/foundry.js +3 -0
  44. package/dist/utils/foundry.js.map +1 -1
  45. package/package.json +7 -4
  46. package/src/foundry.ts +104 -0
  47. package/src/framework/DeploymentManager.ts +74 -69
  48. package/src/framework/ForgeFuzzingFramework.ts +23 -1
  49. package/src/framework/HelperGenerator.ts +13 -0
  50. package/src/index.ts +0 -5
  51. package/src/tasks/deploy.ts +3 -1
  52. package/src/tasks/generate-helpers.ts +6 -2
  53. package/src/tasks/init.ts +3 -1
  54. package/src/tasks/test.ts +12 -1
  55. package/src/templates/ExampleFuzzTest.t.sol.template +26 -17
  56. package/src/templates/ExampleIntegrationTest.t.sol.template +9 -1
  57. package/src/templates/ExampleUnitTest.t.sol.template +7 -1
  58. package/src/types/hardhat.ts +1 -1
  59. package/src/utils/foundry.ts +5 -0
@@ -1 +1 @@
1
- {"version":3,"file":"DeploymentManager.d.ts","sourceRoot":"","sources":["../../src/framework/DeploymentManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAEhD,OAAO,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AAa1D;;;;;GAKG;AACH,qBAAa,iBAAiB;IAChB,OAAO,CAAC,GAAG;gBAAH,GAAG,EAAE,yBAAyB;IAElD;;;OAGG;YACW,gBAAgB;IAkB9B;;;;;OAKG;IACG,MAAM,CACV,WAAW,GAAE,MAAyB,EACtC,WAAW,GAAE,MAAkB,EAC/B,KAAK,GAAE,OAAe,GACrB,OAAO,CAAC,OAAO,CAAC;IAmDnB;;;;;OAKG;IACG,aAAa,CACjB,WAAW,GAAE,MAAyB,EACtC,WAAW,GA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O,CAAC,mBAAmB;IAiB3B;;OAEG;IACH,iBAAiB,CACf,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,GACd,MAAM;CAUV"}
@@ -1,43 +1,32 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DeploymentManager = void 0;
4
+ const lib_1 = require("@diamondslab/hardhat-diamonds/dist/lib");
5
+ require("@nomicfoundation/hardhat-ethers");
4
6
  const fs_1 = require("fs");
5
7
  const path_1 = require("path");
6
8
  const logger_1 = require("../utils/logger");
7
9
  /**
8
10
  * DeploymentManager - Manages Diamond deployment lifecycle for Forge testing
9
11
  *
10
- * Note: This class dynamically requires LocalDiamondDeployer from the workspace
11
- * to avoid module resolution issues in the published package.
12
+ * Uses LocalDiamondDeployer from @diamondslab/hardhat-diamonds peer dependency
13
+ * for portable, dependency-managed Diamond deployments.
12
14
  */
13
15
  class DeploymentManager {
14
16
  hre;
17
+ // In-memory cache for ephemeral deployments (when writeDeployedDiamondData: false)
18
+ deploymentCache = new Map();
15
19
  constructor(hre) {
16
20
  this.hre = hre;
17
21
  }
18
- /**
19
- * Get LocalDiamondDeployer class
20
- * @private
21
- */
22
- async getDeployerClass() {
23
- // LocalDiamondDeployer is in the workspace scripts, not exported from the module
24
- // This will need to be available in user projects
25
- const localDeployerPath = (0, path_1.join)(this.hre.config.paths.root, "scripts/setup/LocalDiamondDeployer");
26
- try {
27
- const deployer = await import(localDeployerPath);
28
- return deployer.LocalDiamondDeployer;
29
- }
30
- catch {
31
- throw new Error("LocalDiamondDeployer not found. Make sure your project has scripts/setup/LocalDiamondDeployer.ts");
32
- }
33
- }
34
22
  /**
35
23
  * Deploy a Diamond using LocalDiamondDeployer
36
24
  * @param diamondName - Name of the Diamond to deploy
37
25
  * @param networkName - Target network (hardhat, localhost, anvil)
38
26
  * @param force - Force redeployment even if exists
27
+ * @param writeDeployedDiamondData - Whether to write deployment record to file
39
28
  */
40
- async deploy(diamondName = "ExampleDiamond", networkName = "hardhat", force = false) {
29
+ async deploy(diamondName = "ExampleDiamond", networkName = "hardhat", force = false, writeDeployedDiamondData = false) {
41
30
  logger_1.Logger.section(`Deploying ${diamondName} to ${networkName}`);
42
31
  // Get provider and network info
43
32
  const provider = this.hre.ethers.provider;
@@ -47,33 +36,49 @@ class DeploymentManager {
47
36
  if (!force && this.hasDeploymentRecord(diamondName, networkName, chainId)) {
48
37
  logger_1.Logger.info("Deployment record exists, using existing deployment");
49
38
  logger_1.Logger.info("Use --force to redeploy");
50
- const LocalDiamondDeployer = await this.getDeployerClass();
51
- const deployer = await LocalDiamondDeployer.getInstance({
39
+ try {
40
+ const deployer = await lib_1.LocalDiamondDeployer.getInstance(this.hre, {
41
+ diamondName,
42
+ networkName,
43
+ provider,
44
+ chainId,
45
+ writeDeployedDiamondData,
46
+ });
47
+ return await deployer.getDiamond();
48
+ }
49
+ catch (error) {
50
+ throw new Error(`Failed to load deployment. Ensure @diamondslab/hardhat-diamonds is installed.\n` +
51
+ `Error: ${error instanceof Error ? error.message : String(error)}`);
52
+ }
53
+ }
54
+ logger_1.Logger.step("Initializing LocalDiamondDeployer...");
55
+ try {
56
+ const deployer = await lib_1.LocalDiamondDeployer.getInstance(this.hre, {
52
57
  diamondName,
53
58
  networkName,
54
59
  provider,
55
60
  chainId,
56
- writeDeployedDiamondData: true,
61
+ writeDeployedDiamondData,
57
62
  });
58
- return await deployer.getDiamond();
63
+ await deployer.setVerbose(false); // Reduce noise, use our logger instead
64
+ logger_1.Logger.step("Deploying Diamond contract...");
65
+ const diamond = await deployer.getDiamondDeployed();
66
+ const deployedData = diamond.getDeployedDiamondData();
67
+ logger_1.Logger.success(`Diamond deployed at: ${deployedData.DiamondAddress}`);
68
+ logger_1.Logger.info(`Deployer: ${deployedData.DeployerAddress}`);
69
+ logger_1.Logger.info(`Facets deployed: ${Object.keys(deployedData.DeployedFacets || {}).length}`);
70
+ // Cache deployment if not writing to file
71
+ if (!writeDeployedDiamondData) {
72
+ const cacheKey = `${diamondName}-${networkName}-${chainId}`;
73
+ this.deploymentCache.set(cacheKey, diamond);
74
+ logger_1.Logger.info("Deployment cached in memory (not persisted to file)");
75
+ }
76
+ return diamond;
77
+ }
78
+ catch (error) {
79
+ throw new Error(`Failed to deploy diamond. Ensure @diamondslab/hardhat-diamonds is installed.\n` +
80
+ `Error: ${error instanceof Error ? error.message : String(error)}`);
59
81
  }
60
- logger_1.Logger.step("Initializing LocalDiamondDeployer...");
61
- const LocalDiamondDeployer = await this.getDeployerClass();
62
- const deployer = await LocalDiamondDeployer.getInstance({
63
- diamondName,
64
- networkName,
65
- provider,
66
- chainId,
67
- writeDeployedDiamondData: true,
68
- });
69
- await deployer.setVerbose(false); // Reduce noise, use our logger instead
70
- logger_1.Logger.step("Deploying Diamond contract...");
71
- const diamond = await deployer.getDiamondDeployed();
72
- const deployedData = diamond.getDeployedDiamondData();
73
- logger_1.Logger.success(`Diamond deployed at: ${deployedData.DiamondAddress}`);
74
- logger_1.Logger.info(`Deployer: ${deployedData.DeployerAddress}`);
75
- logger_1.Logger.info(`Facets deployed: ${Object.keys(deployedData.DeployedFacets || {}).length}`);
76
- return diamond;
77
82
  }
78
83
  /**
79
84
  * Get existing deployment record
@@ -86,12 +91,17 @@ class DeploymentManager {
86
91
  const provider = this.hre.ethers.provider;
87
92
  const network = await provider.getNetwork();
88
93
  const actualChainId = chainId ?? Number(network.chainId);
94
+ // Check in-memory cache first (for ephemeral deployments)
95
+ const cacheKey = `${diamondName}-${networkName}-${actualChainId}`;
96
+ if (this.deploymentCache.has(cacheKey)) {
97
+ logger_1.Logger.info("Using cached deployment (ephemeral)");
98
+ return this.deploymentCache.get(cacheKey);
99
+ }
89
100
  if (!this.hasDeploymentRecord(diamondName, networkName, actualChainId)) {
90
101
  logger_1.Logger.warn("No deployment record found");
91
102
  return null;
92
103
  }
93
- const LocalDiamondDeployer = await this.getDeployerClass();
94
- const deployer = await LocalDiamondDeployer.getInstance({
104
+ const deployer = await lib_1.LocalDiamondDeployer.getInstance(this.hre, {
95
105
  diamondName,
96
106
  networkName,
97
107
  provider,
@@ -101,7 +111,7 @@ class DeploymentManager {
101
111
  return await deployer.getDiamond();
102
112
  }
103
113
  catch (error) {
104
- logger_1.Logger.error(`Failed to get deployment: ${error}`);
114
+ logger_1.Logger.error(`Failed to get deployment. Ensure @diamondslab/hardhat-diamonds is installed: ${error}`);
105
115
  return null;
106
116
  }
107
117
  }
@@ -110,8 +120,9 @@ class DeploymentManager {
110
120
  * @param diamondName - Name of the Diamond
111
121
  * @param networkName - Network name
112
122
  * @param force - Force redeployment
123
+ * @param writeDeployedDiamondData - Whether to write deployment record to file
113
124
  */
114
- async ensureDeployment(diamondName = "ExampleDiamond", networkName = "hardhat", force = false) {
125
+ async ensureDeployment(diamondName = "ExampleDiamond", networkName = "hardhat", force = false, writeDeployedDiamondData = false) {
115
126
  const provider = this.hre.ethers.provider;
116
127
  const network = await provider.getNetwork();
117
128
  const chainId = Number(network.chainId);
@@ -122,7 +133,7 @@ class DeploymentManager {
122
133
  return existing;
123
134
  }
124
135
  // Deploy if not exists or force is true
125
- return await this.deploy(diamondName, networkName, force);
136
+ return await this.deploy(diamondName, networkName, force, writeDeployedDiamondData);
126
137
  }
127
138
  /**
128
139
  * Check if deployment record exists
@@ -1 +1 @@
1
- {"version":3,"file":"DeploymentManager.js","sourceRoot":"","sources":["../../src/framework/DeploymentManager.ts"],"names":[],"mappings":";;;AACA,2BAAgC;AAEhC,+BAA4B;AAC5B,4CAAyC;AAWzC;;;;;GAKG;AACH,MAAa,iBAAiB;IACR;IAApB,YAAoB,GAA8B;QAA9B,QAAG,GAAH,GAAG,CAA2B;IAAG,CAAC;IAEtD;;;OAGG;IACK,KAAK,CAAC,gBAAgB;QAC5B,iFAAiF;QACjF,kDAAkD;QAClD,MAAM,iBAAiB,GAAG,IAAA,WAAI,EAC5B,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,EA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AI,EACzB,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,EAC1B,UAAU,EACV,WAAW,EACX,aAAa,EACb,kBAAkB,CACnB,CAAC;QAEF,OAAO,IAAA,eAAU,EAAC,cAAc,CAAC,CAAC;IACpC,CAAC;IAED;;OAEG;IACH,iBAAiB,CACf,WAAmB,EACnB,WAAmB,EACnB,OAAe;QAEf,MAAM,kBAAkB,GAAG,GAAG,WAAW,CAAC,WAAW,EAAE,IAAI,WAAW,CAAC,WAAW,EAAE,IAAI,OAAO,OAAO,CAAC;QACvG,OAAO,IAAA,WAAI,EACT,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,EAC1B,UAAU,EACV,WAAW,EACX,aAAa,EACb,kBAAkB,CACnB,CAAC;IACJ,CAAC;CACF;AA5LD,8CA4LC","sourcesContent":["import { Diamond } from \"@diamondslab/diamonds\";\nimport { existsSync } from \"fs\";\nimport { HardhatRuntimeEnvironment } from \"hardhat/types\";\nimport { join } from \"path\";\nimport { Logger } from \"../utils/logger\";\n\n// Type for LocalDiamondDeployer (avoiding import issues)\ntype LocalDiamondDeployerConfig = {\n diamondName: string;\n networkName: string;\n provider: any;\n chainId: number;\n writeDeployedDiamondData: boolean;\n};\n\n/**\n * DeploymentManager - Manages Diamond deployment lifecycle for Forge testing\n * \n * Note: This class dynamically requires LocalDiamondDeployer from the workspace\n * to avoid module resolution issues in the published package.\n */\nexport class DeploymentManager {\n constructor(private hre: HardhatRuntimeEnvironment) {}\n\n /**\n * Get LocalDiamondDeployer class\n * @private\n */\n private async getDeployerClass(): Promise<any> {\n // LocalDiamondDeployer is in the workspace scripts, not exported from the module\n // This will need to be available in user projects\n const localDeployerPath = join(\n this.hre.config.paths.root,\n \"scripts/setup/LocalDiamondDeployer\"\n );\n \n try {\n const deployer = await import(localDeployerPath);\n return deployer.LocalDiamondDeployer;\n } catch {\n throw new Error(\n \"LocalDiamondDeployer not found. Make sure your project has scripts/setup/LocalDiamondDeployer.ts\"\n );\n }\n }\n\n /**\n * Deploy a Diamond using LocalDiamondDeployer\n * @param diamondName - Name of the Diamond to deploy\n * @param networkName - Target network (hardhat, localhost, anvil)\n * @param force - Force redeployment even if exists\n */\n async deploy(\n diamondName: string = \"ExampleDiamond\",\n networkName: string = \"hardhat\",\n force: boolean = false\n ): Promise<Diamond> {\n Logger.section(`Deploying ${diamondName} to ${networkName}`);\n\n // Get provider and network info\n const provider = this.hre.ethers.provider;\n const network = await provider.getNetwork();\n const chainId = Number(network.chainId);\n\n // Check if deployment exists and handle force flag\n if (!force && this.hasDeploymentRecord(diamondName, networkName, chainId)) {\n Logger.info(\"Deployment record exists, using existing deployment\");\n Logger.info(\"Use --force to redeploy\");\n \n const LocalDiamondDeployer = await this.getDeployerClass();\n const deployer = await LocalDiamondDeployer.getInstance({\n diamondName,\n networkName,\n provider,\n chainId,\n writeDeployedDiamondData: true,\n } as LocalDiamondDeployerConfig);\n \n return await deployer.getDiamond();\n }\n\n Logger.step(\"Initializing LocalDiamondDeployer...\");\n \n const LocalDiamondDeployer = await this.getDeployerClass();\n \n const deployer = await LocalDiamondDeployer.getInstance({\n diamondName,\n networkName,\n provider,\n chainId,\n writeDeployedDiamondData: true,\n } as LocalDiamondDeployerConfig);\n\n await deployer.setVerbose(false); // Reduce noise, use our logger instead\n\n Logger.step(\"Deploying Diamond contract...\");\n const diamond = await deployer.getDiamondDeployed();\n \n const deployedData = diamond.getDeployedDiamondData();\n \n Logger.success(`Diamond deployed at: ${deployedData.DiamondAddress}`);\n Logger.info(`Deployer: ${deployedData.DeployerAddress}`);\n Logger.info(`Facets deployed: ${Object.keys(deployedData.DeployedFacets || {}).length}`);\n\n return diamond;\n }\n\n /**\n * Get existing deployment record\n * @param diamondName - Name of the Diamond\n * @param networkName - Network name\n * @param chainId - Chain ID\n */\n async getDeployment(\n diamondName: string = \"ExampleDiamond\",\n networkName: string = \"hardhat\",\n chainId?: number\n ): Promise<Diamond | null> {\n try {\n const provider = this.hre.ethers.provider;\n const network = await provider.getNetwork();\n const actualChainId = chainId ?? Number(network.chainId);\n\n if (!this.hasDeploymentRecord(diamondName, networkName, actualChainId)) {\n Logger.warn(\"No deployment record found\");\n return null;\n }\n\n const LocalDiamondDeployer = await this.getDeployerClass();\n const deployer = await LocalDiamondDeployer.getInstance({\n diamondName,\n networkName,\n provider,\n chainId: actualChainId,\n writeDeployedDiamondData: false,\n } as LocalDiamondDeployerConfig);\n\n return await deployer.getDiamond();\n } catch (error) {\n Logger.error(`Failed to get deployment: ${error}`);\n return null;\n }\n }\n\n /**\n * Ensure deployment exists, deploy if needed\n * @param diamondName - Name of the Diamond\n * @param networkName - Network name\n * @param force - Force redeployment\n */\n async ensureDeployment(\n diamondName: string = \"ExampleDiamond\",\n networkName: string = \"hardhat\",\n force: boolean = false\n ): Promise<Diamond> {\n const provider = this.hre.ethers.provider;\n const network = await provider.getNetwork();\n const chainId = Number(network.chainId);\n\n // Check if deployment exists\n const existing = await this.getDeployment(diamondName, networkName, chainId);\n \n if (existing && !force) {\n Logger.info(\"Using existing deployment\");\n return existing;\n }\n\n // Deploy if not exists or force is true\n return await this.deploy(diamondName, networkName, force);\n }\n\n /**\n * Check if deployment record exists\n * @private\n */\n private hasDeploymentRecord(\n diamondName: string,\n networkName: string,\n chainId: number\n ): boolean {\n const deploymentFileName = `${diamondName.toLowerCase()}-${networkName.toLowerCase()}-${chainId}.json`;\n const deploymentPath = join(\n this.hre.config.paths.root,\n \"diamonds\",\n diamondName,\n \"deployments\",\n deploymentFileName\n );\n\n return existsSync(deploymentPath);\n }\n\n /**\n * Get deployment file path\n */\n getDeploymentPath(\n diamondName: string,\n networkName: string,\n chainId: number\n ): string {\n const deploymentFileName = `${diamondName.toLowerCase()}-${networkName.toLowerCase()}-${chainId}.json`;\n return join(\n this.hre.config.paths.root,\n \"diamonds\",\n diamondName,\n \"deployments\",\n deploymentFileName\n );\n }\n}\n"]}
1
+ {"version":3,"file":"DeploymentManager.js","sourceR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CAAC,WAAW,EAAE,IAAI,WAAW,CAAC,WAAW,EAAE,IAAI,OAAO,OAAO,CAAC;QACvG,OAAO,IAAA,WAAI,EACT,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,EAC1B,UAAU,EACV,WAAW,EACX,aAAa,EACb,kBAAkB,CACnB,CAAC;IACJ,CAAC;CACF;AArMD,8CAqMC","sourcesContent":["import { Diamond } from \"@diamondslab/diamonds/core\";\nimport {\n LocalDiamondDeployer,\n LocalDiamondDeployerConfig,\n} from \"@diamondslab/hardhat-diamonds/dist/lib\";\nimport \"@nomicfoundation/hardhat-ethers\";\nimport { existsSync } from \"fs\";\nimport type { HardhatRuntimeEnvironment } from \"hardhat/types\";\nimport { join } from \"path\";\nimport { Logger } from \"../utils/logger\";\n\n/**\n * DeploymentManager - Manages Diamond deployment lifecycle for Forge testing\n * \n * Uses LocalDiamondDeployer from @diamondslab/hardhat-diamonds peer dependency\n * for portable, dependency-managed Diamond deployments.\n */\nexport class DeploymentManager {\n // In-memory cache for ephemeral deployments (when writeDeployedDiamondData: false)\n private deploymentCache: Map<string, Diamond> = new Map();\n\n constructor(private hre: HardhatRuntimeEnvironment) {}\n\n /**\n * Deploy a Diamond using LocalDiamondDeployer\n * @param diamondName - Name of the Diamond to deploy\n * @param networkName - Target network (hardhat, localhost, anvil)\n * @param force - Force redeployment even if exists\n * @param writeDeployedDiamondData - Whether to write deployment record to file\n */\n async deploy(\n diamondName: string = \"ExampleDiamond\",\n networkName: string = \"hardhat\",\n force: boolean = false,\n writeDeployedDiamondData: boolean = false\n ): Promise<Diamond> {\n Logger.section(`Deploying ${diamondName} to ${networkName}`);\n\n // Get provider and network info\n const provider = this.hre.ethers.provider;\n const network = await provider.getNetwork();\n const chainId = Number(network.chainId);\n\n // Check if deployment exists and handle force flag\n if (!force && this.hasDeploymentRecord(diamondName, networkName, chainId)) {\n Logger.info(\"Deployment record exists, using existing deployment\");\n Logger.info(\"Use --force to redeploy\");\n \n try {\n const deployer = await LocalDiamondDeployer.getInstance(this.hre, {\n diamondName,\n networkName,\n provider,\n chainId,\n writeDeployedDiamondData,\n } as LocalDiamondDeployerConfig);\n \n return await deployer.getDiamond();\n } catch (error) {\n throw new Error(\n `Failed to load deployment. Ensure @diamondslab/hardhat-diamonds is installed.\\n` +\n `Error: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n }\n\n Logger.step(\"Initializing LocalDiamondDeployer...\");\n \n try {\n const deployer = await LocalDiamondDeployer.getInstance(this.hre as any, {\n diamondName,\n networkName,\n provider,\n chainId,\n writeDeployedDiamondData,\n } as LocalDiamondDeployerConfig);\n\n await deployer.setVerbose(false); // Reduce noise, use our logger instead\n\n Logger.step(\"Deploying Diamond contract...\");\n const diamond = await deployer.getDiamondDeployed();\n \n const deployedData = diamond.getDeployedDiamondData();\n \n Logger.success(`Diamond deployed at: ${deployedData.DiamondAddress}`);\n Logger.info(`Deployer: ${deployedData.DeployerAddress}`);\n Logger.info(`Facets deployed: ${Object.keys(deployedData.DeployedFacets || {}).length}`);\n\n // Cache deployment if not writing to file\n if (!writeDeployedDiamondData) {\n const cacheKey = `${diamondName}-${networkName}-${chainId}`;\n this.deploymentCache.set(cacheKey, diamond);\n Logger.info(\"Deployment cached in memory (not persisted to file)\");\n }\n\n return diamond;\n } catch (error) {\n throw new Error(\n `Failed to deploy diamond. Ensure @diamondslab/hardhat-diamonds is installed.\\n` +\n `Error: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n }\n\n /**\n * Get existing deployment record\n * @param diamondName - Name of the Diamond\n * @param networkName - Network name\n * @param chainId - Chain ID\n */\n async getDeployment(\n diamondName: string = \"ExampleDiamond\",\n networkName: string = \"hardhat\",\n chainId?: number\n ): Promise<Diamond | null> {\n try {\n const provider = this.hre.ethers.provider;\n const network = await provider.getNetwork();\n const actualChainId = chainId ?? Number(network.chainId);\n\n // Check in-memory cache first (for ephemeral deployments)\n const cacheKey = `${diamondName}-${networkName}-${actualChainId}`;\n if (this.deploymentCache.has(cacheKey)) {\n Logger.info(\"Using cached deployment (ephemeral)\");\n return this.deploymentCache.get(cacheKey)!;\n }\n\n if (!this.hasDeploymentRecord(diamondName, networkName, actualChainId)) {\n Logger.warn(\"No deployment record found\");\n return null;\n }\n\n const deployer = await LocalDiamondDeployer.getInstance(this.hre as any, {\n diamondName,\n networkName,\n provider,\n chainId: actualChainId,\n writeDeployedDiamondData: false,\n } as LocalDiamondDeployerConfig);\n\n return await deployer.getDiamond();\n } catch (error) {\n Logger.error(`Failed to get deployment. Ensure @diamondslab/hardhat-diamonds is installed: ${error}`);\n return null;\n }\n }\n\n /**\n * Ensure deployment exists, deploy if needed\n * @param diamondName - Name of the Diamond\n * @param networkName - Network name\n * @param force - Force redeployment\n * @param writeDeployedDiamondData - Whether to write deployment record to file\n */\n async ensureDeployment(\n diamondName: string = \"ExampleDiamond\",\n networkName: string = \"hardhat\",\n force: boolean = false,\n writeDeployedDiamondData: boolean = false\n ): Promise<Diamond> {\n const provider = this.hre.ethers.provider;\n const network = await provider.getNetwork();\n const chainId = Number(network.chainId);\n\n // Check if deployment exists\n const existing = await this.getDeployment(diamondName, networkName, chainId);\n \n if (existing && !force) {\n Logger.info(\"Using existing deployment\");\n return existing;\n }\n\n // Deploy if not exists or force is true\n return await this.deploy(diamondName, networkName, force, writeDeployedDiamondData);\n }\n\n /**\n * Check if deployment record exists\n * @private\n */\n private hasDeploymentRecord(\n diamondName: string,\n networkName: string,\n chainId: number\n ): boolean {\n const deploymentFileName = `${diamondName.toLowerCase()}-${networkName.toLowerCase()}-${chainId}.json`;\n const deploymentPath = join(\n this.hre.config.paths.root,\n \"diamonds\",\n diamondName,\n \"deployments\",\n deploymentFileName\n );\n\n return existsSync(deploymentPath);\n }\n\n /**\n * Get deployment file path\n */\n getDeploymentPath(\n diamondName: string,\n networkName: string,\n chainId: number\n ): string {\n const deploymentFileName = `${diamondName.toLowerCase()}-${networkName.toLowerCase()}-${chainId}.json`;\n return join(\n this.hre.config.paths.root,\n \"diamonds\",\n diamondName,\n \"deployments\",\n deploymentFileName\n );\n }\n}\n"]}
@@ -18,6 +18,10 @@ export interface ForgeTestOptions {
18
18
  skipHelpers?: boolean;
19
19
  /** Skip deployment (use existing) */
20
20
  skipDeployment?: boolean;
21
+ /** Write deployment data to file (default: false for ephemeral) */
22
+ writeDeployedDiamondData?: boolean;
23
+ /** Use EVM snapshots for test isolation */
24
+ useSnapshot?: boolean;
21
25
  }
22
26
  /**
23
27
  * ForgeFuzzingFramework - Main orchestration class for Forge testing with Diamonds
@@ -1 +1 @@
1
- {"version":3,"file":"ForgeFuzzingFramework.d.ts","sourceRoot":"","sources":["../../src/framework/ForgeFuzzingFramework.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AAM1D,MAAM,WAAW,gBAAgB;IAC/B,oCAAoC;IACpC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,2BAA2B;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,yBAAyB;IACzB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,yBAAyB;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,6BAA6B;IAC7B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,4BAA4B;IAC5B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,sBAAsB;IACtB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,6BAA6B;IAC7B,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,qCAAqC;IACrC,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED;;;;;;;GAOG;AACH,qBAAa,qBAAqB;IAIpB,OAAO,CAAC,GAAG;IAHvB,OAAO,CAAC,iBAAiB,CAAoB;IAC7C,OAAO,CAAC,eAAe,CAAkB;gBAErB,GAAG,EAAE,yBAAyB;IAKlD;;;;;;;;;;;OAWG;IACG,QAAQ,CAAC,OAAO,GAAE,gBAAqB,GAAG,OAAO,CAAC,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AAW,GAAE,MAAyB,EACtC,WAAW,GAAE,MAAkB,EAC/B,KAAK,GAAE,OAAe;IASxB;;OAEG;IACG,mBAAmB,CACvB,WAAW,GAAE,MAAyB,EACtC,WAAW,GAAE,MAAkB;CAwBlC"}
@@ -35,7 +35,7 @@ class ForgeFuzzingFramework {
35
35
  * @param options - Test execution options
36
36
  */
37
37
  async runTests(options = {}) {
38
- const { diamondName = "ExampleDiamond", networkName = "hardhat", force = false, matchTest, matchContract, verbosity = 2, gasReport = false, skipHelpers = false, skipDeployment = false, } = options;
38
+ const { diamondName = "ExampleDiamond", networkName = "hardhat", writeDeployedDiamondData = false, useSnapshot = false, force = false, matchTest, matchContract, verbosity = 2, gasReport = false, skipHelpers = false, skipDeployment = false, } = options;
39
39
  logger_1.Logger.section("Forge Fuzzing Framework - Test Execution");
40
40
  // Step 1: Validate Foundry
41
41
  if (!(0, foundry_1.isFoundryInstalled)()) {
@@ -46,7 +46,7 @@ class ForgeFuzzingFramework {
46
46
  // Step 2: Ensure Diamond deployment
47
47
  if (!skipDeployment) {
48
48
  logger_1.Logger.section("Step 1/4: Ensuring Diamond Deployment");
49
- await this.deploymentManager.ensureDeployment(diamondName, networkName, force);
49
+ await this.deploymentManager.ensureDeployment(diamondName, networkName, force, writeDeployedDiamondData);
50
50
  }
51
51
  else {
52
52
  logger_1.Logger.info("Skipping deployment (using existing)");
@@ -80,11 +80,25 @@ class ForgeFuzzingFramework {
80
80
  }
81
81
  // Step 5: Run tests
82
82
  logger_1.Logger.section("Step 4/4: Running Forge Tests");
83
+ // Only fork when using persistent networks (localhost, sepolia, mainnet, etc.)
84
+ // The ephemeral "hardhat" network cannot be forked from
85
+ let forkUrl;
86
+ if (networkName !== "hardhat") {
87
+ const provider = this.hre.ethers.provider;
88
+ forkUrl = provider._hardhatProvider?._wrapped?.url || "http://127.0.0.1:8545";
89
+ logger_1.Logger.info(`Forking from ${networkName}: ${forkUrl}`);
90
+ }
91
+ else {
92
+ logger_1.Logger.warn(`⚠️ Using ephemeral "${networkName}" network - tests requiring deployed Diamond will fail`);
93
+ logger_1.Logger.warn(`💡 For deployed Diamond testing, use: npx hardhat diamonds-forge:test --network localhost`);
94
+ logger_1.Logger.warn(`💡 Make sure to start Hardhat node first: npx hardhat node`);
95
+ }
83
96
  const testResult = await (0, foundry_1.runForgeTest)({
84
97
  matchTest,
85
98
  matchContract,
86
99
  verbosity,
87
100
  gasReport,
101
+ forkUrl,
88
102
  cwd: this.hre.config.paths.root,
89
103
  });
90
104
  return testResult.success;
@@ -1 +1 @@
1
- {"version":3,"file":"ForgeFuzzingFramework.js","sourceRoot":"","sources":["../../src/framework/ForgeFuzzingFramework.ts"],"names":[],"mappings":";;;AACA,8CAAkF;AAClF,4CAAyC;AACzC,2DAAwD;AACxD,uDAAoD;AAuBpD;;;;;;;GAOG;AACH,MAAa,qBAAqB;IAIZ;IAHZ,iBAAiB,CAAoB;IACrC,eAAe,CAAkB;IAEzC,YAAoB,GAA8B;QAA9B,QAAG,GAAH,GAAG,CAA2B;QAChD,IAAI,CAAC,iBAAiB,GAAG,IAAI,qCAAiB,CAAC,GAAG,CAAC,CAAC;QACpD,IAAI,CAAC,eAAe,GAAG,IAAI,iCAAe,CAAC,GAAG,CAAC,CAAC;IAClD,CAAC;IAED;;;;;;;;;;;OAWG;IACH,KAAK,CAAC,QAAQ,CAAC,UAA4B,EAAE;QAC3C,MAAM,EACJ,WAAW,GAAG,gBAAgB,EAC9B,WAAW,GAAG,SAAS,EACvB,KAAK,GAAG,KAAK,EACb,SAAS,EACT,aAAa,EACb,SAAS,GAAG,CAAC,EACb,SAAS,GAAG,KAAK,EACjB,WAAW,GAAG,KAAK,EACnB,cAAc,GAAG,KAAK,GACvB,GAAG,OAAO,CAAC;QAEZ,eAAM,CAAC,OAAO,CAAC,0CAA0C,CAAC,CAAC;QAE3D,2BAA2B;QAC3B,IAAI,CAAC,IAAA,4BAAkB,GAAE,EAAE;YACzB,eAAM,CAAC,KAAK,CAAC,sGAAsG,CA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C5C,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAExC,MAAM,cAAc,GAAG,UAAU,CAAC,sBAAsB,EAAE,CAAC;QAE3D,OAAO,MAAM,IAAI,CAAC,eAAe,CAAC,yBAAyB,CACzD,WAAW,EACX,WAAW,EACX,OAAO,EACP,cAAc,CACf,CAAC;IACJ,CAAC;CACF;AA7JD,sDA6JC","sourcesContent":["import { HardhatRuntimeEnvironment } from \"hardhat/types\";\nimport { compileForge, isFoundryInstalled, runForgeTest } from \"../utils/foundry\";\nimport { Logger } from \"../utils/logger\";\nimport { DeploymentManager } from \"./DeploymentManager\";\nimport { HelperGenerator } from \"./HelperGenerator\";\n\nexport interface ForgeTestOptions {\n /** Name of the Diamond to deploy */\n diamondName?: string;\n /** Network to deploy on */\n networkName?: string;\n /** Force redeployment */\n force?: boolean;\n /** Match test pattern */\n matchTest?: string;\n /** Match contract pattern */\n matchContract?: string;\n /** Verbosity level (1-5) */\n verbosity?: number;\n /** Show gas report */\n gasReport?: boolean;\n /** Skip helper generation */\n skipHelpers?: boolean;\n /** Skip deployment (use existing) */\n skipDeployment?: boolean;\n}\n\n/**\n * ForgeFuzzingFramework - Main orchestration class for Forge testing with Diamonds\n * \n * Coordinates:\n * 1. Diamond deployment via DeploymentManager\n * 2. Helper generation via HelperGenerator\n * 3. Forge test execution\n */\nexport class ForgeFuzzingFramework {\n private deploymentManager: DeploymentManager;\n private helperGenerator: HelperGenerator;\n\n constructor(private hre: HardhatRuntimeEnvironment) {\n this.deploymentManager = new DeploymentManager(hre);\n this.helperGenerator = new HelperGenerator(hre);\n }\n\n /**\n * Run complete Forge testing workflow\n * \n * Workflow:\n * 1. Validate Foundry installation\n * 2. Deploy or reuse Diamond\n * 3. Generate Solidity helpers\n * 4. Compile Forge contracts\n * 5. Run Forge tests\n * \n * @param options - Test execution options\n */\n async runTests(options: ForgeTestOptions = {}): Promise<boolean> {\n const {\n diamondName = \"ExampleDiamond\",\n networkName = \"hardhat\",\n force = false,\n matchTest,\n matchContract,\n verbosity = 2,\n gasReport = false,\n skipHelpers = false,\n skipDeployment = false,\n } = options;\n\n Logger.section(\"Forge Fuzzing Framework - Test Execution\");\n\n // Step 1: Validate Foundry\n if (!isFoundryInstalled()) {\n Logger.error(\"Foundry is not installed. Please install it: https://book.getfoundry.sh/getting-started/installation\");\n return false;\n }\n\n try {\n // Step 2: Ensure Diamond deployment\n if (!skipDeployment) {\n Logger.section(\"Step 1/4: Ensuring Diamond Deployment\");\n await this.deploymentManager.ensureDeployment(\n diamondName,\n networkName,\n force\n );\n } else {\n Logger.info(\"Skipping deployment (using existing)\");\n }\n\n // Step 3: Generate helpers\n if (!skipHelpers) {\n Logger.section(\"Step 2/4: Generating Solidity Helpers\");\n const deployment = await this.deploymentManager.getDeployment(\n diamondName,\n networkName\n );\n\n if (!deployment) {\n Logger.error(\"No deployment found. Cannot generate helpers.\");\n return false;\n }\n\n const provider = this.hre.ethers.provider;\n const network = await provider.getNetwork();\n const chainId = Number(network.chainId);\n\n const deploymentData = deployment.getDeployedDiamondData();\n \n await this.helperGenerator.generateDeploymentHelpers(\n diamondName,\n networkName,\n chainId,\n deploymentData\n );\n } else {\n Logger.info(\"Skipping helper generation\");\n }\n\n // Step 4: Compile Forge contracts\n Logger.section(\"Step 3/4: Compiling Forge Contracts\");\n const compileResult = await compileForge({\n cwd: this.hre.config.paths.root,\n verbose: verbosity >= 3,\n });\n\n if (!compileResult.success) {\n Logger.error(\"Forge compilation failed\");\n return false;\n }\n\n // Step 5: Run tests\n Logger.section(\"Step 4/4: Running Forge Tests\");\n const testResult = await runForgeTest({\n matchTest,\n matchContract,\n verbosity,\n gasReport,\n cwd: this.hre.config.paths.root,\n });\n\n return testResult.success;\n } catch (error: any) {\n Logger.error(`Test execution failed: ${error.message}`);\n return false;\n }\n }\n\n /**\n * Deploy Diamond only (no testing)\n */\n async deployOnly(\n diamondName: string = \"ExampleDiamond\",\n networkName: string = \"hardhat\",\n force: boolean = false\n ) {\n return await this.deploymentManager.ensureDeployment(\n diamondName,\n networkName,\n force\n );\n }\n\n /**\n * Generate helpers only (no deployment or testing)\n */\n async generateHelpersOnly(\n diamondName: string = \"ExampleDiamond\",\n networkName: string = \"hardhat\"\n ) {\n const deployment = await this.deploymentManager.getDeployment(\n diamondName,\n networkName\n );\n\n if (!deployment) {\n throw new Error(\"No deployment found. Deploy first using deployOnly()\");\n }\n\n const provider = this.hre.ethers.provider;\n const network = await provider.getNetwork();\n const chainId = Number(network.chainId);\n\n const deploymentData = deployment.getDeployedDiamondData();\n\n return await this.helperGenerator.generateDeploymentHelpers(\n diamondName,\n networkName,\n chainId,\n deploymentData\n );\n }\n}\n\n"]}
1
+ {"version":3,"file":"ForgeFuzzingFramework.js","sourceRoot":"","sources":["../../src/framework/ForgeFuzzingFramework.ts"],"names":[],"mappings":";;;AACA,8CAAkF;AAClF,4CAAyC;AACzC,2DAAwD;AACxD,uDAAoD;AA2BpD;;;;;;;GAOG;AACH,MAAa,qBAAqB;IAIZ;IAHZ,iBAAiB,CAAoB;IACrC,eAAe,CAAkB;IAEzC,YAAoB,GAA8B;QAA9B,QAAG,GAAH,GAAG,CAA2B;QAChD,IAAI,CAAC,iBAAiB,GAAG,IAAI,qCAAiB,CAAC,GAAG,CAAC,CAAC;QACpD,IAAI,CAAC,eAAe,GAAG,IAAI,iCAAe,CAAC,GAAG,CAAC,CAAC;IAClD,CAAC;IAED;;;;;;;;;;;OAWG;IACH,KAAK,CAAC,QAAQ,CAAC,UAA4B,EAAE;QAC3C,MAAM,EACJ,WAAW,GAAG,gBAAgB,EAC9B,WAAW,GAAG,SAAS,EACvB,wBAAwB,GAAG,KAAK,EAChC,WAAW,GAAG,KAAK,EACnB,KAAK,GAAG,KAAK,EACb,SAAS,EACT,aAAa,EACb,SAAS,GAAG,CAAC,EACb,SAAS,GAAG,KAAK,EACjB,WAAW,GAAG,KAAK,EACnB,cAAc,GAAG,KAAK,GACvB,GAAG,OAAO,CAAC;Q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K,CAAC,0BAA0B,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;YACxD,OAAO,KAAK,CAAC;SACd;IACH,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,UAAU,CACd,cAAsB,gBAAgB,EACtC,cAAsB,SAAS,EAC/B,QAAiB,KAAK;QAEtB,OAAO,MAAM,IAAI,CAAC,iBAAiB,CAAC,gBAAgB,CAClD,WAAW,EACX,WAAW,EACX,KAAK,CACN,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,mBAAmB,CACvB,cAAsB,gBAAgB,EACtC,cAAsB,SAAS;QAE/B,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,iBAAiB,CAAC,aAAa,CAC3D,WAAW,EACX,WAAW,CACZ,CAAC;QAEF,IAAI,CAAC,UAAU,EAAE;YACf,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;SACzE;QAED,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC;QAC1C,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,UAAU,EAAE,CAAC;QAC5C,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAExC,MAAM,cAAc,GAAG,UAAU,CAAC,sBAAsB,EAAE,CAAC;QAE3D,OAAO,MAAM,IAAI,CAAC,eAAe,CAAC,yBAAyB,CACzD,WAAW,EACX,WAAW,EACX,OAAO,EACP,cAAc,CACf,CAAC;IACJ,CAAC;CACF;AA/KD,sDA+KC","sourcesContent":["import { HardhatRuntimeEnvironment } from \"hardhat/types\";\nimport { compileForge, isFoundryInstalled, runForgeTest } from \"../utils/foundry\";\nimport { Logger } from \"../utils/logger\";\nimport { DeploymentManager } from \"./DeploymentManager\";\nimport { HelperGenerator } from \"./HelperGenerator\";\n\nexport interface ForgeTestOptions {\n /** Name of the Diamond to deploy */\n diamondName?: string;\n /** Network to deploy on */\n networkName?: string;\n /** Force redeployment */\n force?: boolean;\n /** Match test pattern */\n matchTest?: string;\n /** Match contract pattern */\n matchContract?: string;\n /** Verbosity level (1-5) */\n verbosity?: number;\n /** Show gas report */\n gasReport?: boolean;\n /** Skip helper generation */\n skipHelpers?: boolean;\n /** Skip deployment (use existing) */\n skipDeployment?: boolean;\n /** Write deployment data to file (default: false for ephemeral) */\n writeDeployedDiamondData?: boolean;\n /** Use EVM snapshots for test isolation */\n useSnapshot?: boolean;\n}\n\n/**\n * ForgeFuzzingFramework - Main orchestration class for Forge testing with Diamonds\n * \n * Coordinates:\n * 1. Diamond deployment via DeploymentManager\n * 2. Helper generation via HelperGenerator\n * 3. Forge test execution\n */\nexport class ForgeFuzzingFramework {\n private deploymentManager: DeploymentManager;\n private helperGenerator: HelperGenerator;\n\n constructor(private hre: HardhatRuntimeEnvironment) {\n this.deploymentManager = new DeploymentManager(hre);\n this.helperGenerator = new HelperGenerator(hre);\n }\n\n /**\n * Run complete Forge testing workflow\n * \n * Workflow:\n * 1. Validate Foundry installation\n * 2. Deploy or reuse Diamond\n * 3. Generate Solidity helpers\n * 4. Compile Forge contracts\n * 5. Run Forge tests\n * \n * @param options - Test execution options\n */\n async runTests(options: ForgeTestOptions = {}): Promise<boolean> {\n const {\n diamondName = \"ExampleDiamond\",\n networkName = \"hardhat\",\n writeDeployedDiamondData = false,\n useSnapshot = false,\n force = false,\n matchTest,\n matchContract,\n verbosity = 2,\n gasReport = false,\n skipHelpers = false,\n skipDeployment = false,\n } = options;\n\n Logger.section(\"Forge Fuzzing Framework - Test Execution\");\n\n // Step 1: Validate Foundry\n if (!isFoundryInstalled()) {\n Logger.error(\"Foundry is not installed. Please install it: https://book.getfoundry.sh/getting-started/installation\");\n return false;\n }\n\n try {\n // Step 2: Ensure Diamond deployment\n if (!skipDeployment) {\n Logger.section(\"Step 1/4: Ensuring Diamond Deployment\");\n await this.deploymentManager.ensureDeployment(\n diamondName,\n networkName,\n force,\n writeDeployedDiamondData\n );\n } else {\n Logger.info(\"Skipping deployment (using existing)\");\n }\n\n // Step 3: Generate helpers\n if (!skipHelpers) {\n Logger.section(\"Step 2/4: Generating Solidity Helpers\");\n const deployment = await this.deploymentManager.getDeployment(\n diamondName,\n networkName\n );\n\n if (!deployment) {\n Logger.error(\"No deployment found. Cannot generate helpers.\");\n return false;\n }\n\n const provider = this.hre.ethers.provider;\n const network = await provider.getNetwork();\n const chainId = Number(network.chainId);\n\n const deploymentData = deployment.getDeployedDiamondData();\n \n await this.helperGenerator.generateDeploymentHelpers(\n diamondName,\n networkName,\n chainId,\n deploymentData\n );\n } else {\n Logger.info(\"Skipping helper generation\");\n }\n\n // Step 4: Compile Forge contracts\n Logger.section(\"Step 3/4: Compiling Forge Contracts\");\n const compileResult = await compileForge({\n cwd: this.hre.config.paths.root,\n verbose: verbosity >= 3,\n });\n\n if (!compileResult.success) {\n Logger.error(\"Forge compilation failed\");\n return false;\n }\n\n // Step 5: Run tests\n Logger.section(\"Step 4/4: Running Forge Tests\");\n \n // Only fork when using persistent networks (localhost, sepolia, mainnet, etc.)\n // The ephemeral \"hardhat\" network cannot be forked from\n let forkUrl: string | undefined;\n if (networkName !== \"hardhat\") {\n const provider = this.hre.ethers.provider;\n forkUrl = (provider as any)._hardhatProvider?._wrapped?.url || \"http://127.0.0.1:8545\";\n Logger.info(`Forking from ${networkName}: ${forkUrl}`);\n } else {\n Logger.warn(`⚠️ Using ephemeral \"${networkName}\" network - tests requiring deployed Diamond will fail`);\n Logger.warn(`💡 For deployed Diamond testing, use: npx hardhat diamonds-forge:test --network localhost`);\n Logger.warn(`💡 Make sure to start Hardhat node first: npx hardhat node`);\n }\n \n const testResult = await runForgeTest({\n matchTest,\n matchContract,\n verbosity,\n gasReport,\n forkUrl, // Only set for persistent networks\n cwd: this.hre.config.paths.root,\n });\n\n return testResult.success;\n } catch (error: any) {\n Logger.error(`Test execution failed: ${error.message}`);\n return false;\n }\n }\n\n /**\n * Deploy Diamond only (no testing)\n */\n async deployOnly(\n diamondName: string = \"ExampleDiamond\",\n networkName: string = \"hardhat\",\n force: boolean = false\n ) {\n return await this.deploymentManager.ensureDeployment(\n diamondName,\n networkName,\n force\n );\n }\n\n /**\n * Generate helpers only (no deployment or testing)\n */\n async generateHelpersOnly(\n diamondName: string = \"ExampleDiamond\",\n networkName: string = \"hardhat\"\n ) {\n const deployment = await this.deploymentManager.getDeployment(\n diamondName,\n networkName\n );\n\n if (!deployment) {\n throw new Error(\"No deployment found. Deploy first using deployOnly()\");\n }\n\n const provider = this.hre.ethers.provider;\n const network = await provider.getNetwork();\n const chainId = Number(network.chainId);\n\n const deploymentData = deployment.getDeployedDiamondData();\n\n return await this.helperGenerator.generateDeploymentHelpers(\n diamondName,\n networkName,\n chainId,\n deploymentData\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;;OAEG;IACG,yBAAyB,CAC7B,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,EACf,cAAc,EAAE,mBAAmB,GAClC,OAAO,CAAC,MAAM,CAAC;IA6BlB;;OAEG;IACG,oBAAoB,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAuE/C;;;OAGG;IACH,OAAO,CAAC,qBAAqB;CAmG9B"}
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;;OAEG;IACG,yBAAyB,CAC7B,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,EACf,cAAc,EAAE,mBAAmB,GAClC,OAAO,CAAC,MAAM,CAAC;IA6BlB;;OAEG;IACG,oBAAoB,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAuE/C;;;OAGG;IACH,OAAO,CAAC,qBAAqB;CAgH9B"}
@@ -140,6 +140,10 @@ class HelperGenerator {
140
140
  source += ` /// @notice Address of the deployed ${diamondName} contract\n`;
141
141
  source += ` /// @dev This is the main Diamond proxy address\n`;
142
142
  source += ` address constant DIAMOND_ADDRESS = ${deploymentData.DiamondAddress};\n\n`;
143
+ // Deployer address
144
+ source += ` /// @notice Address of the deployer account\n`;
145
+ source += ` /// @dev Account that deployed the Diamond\n`;
146
+ source += ` address constant DEPLOYER_ADDRESS = ${deploymentData.DeployerAddress};\n\n`;
143
147
  // Facet addresses
144
148
  source += " // ========================================\n";
145
149
  source += " // Facet Addresses\n";
@@ -167,6 +171,13 @@ class HelperGenerator {
167
171
  source += " return DIAMOND_ADDRESS;\n";
168
172
  source += " }\n\n";
169
173
  source += " /**\n";
174
+ source += " * @notice Get the deployer address\n";
175
+ source += " * @return The address of the deployer account\n";
176
+ source += " */\n";
177
+ source += " function getDeployerAddress() internal pure returns (address) {\n";
178
+ source += " return DEPLOYER_ADDRESS;\n";
179
+ source += " }\n\n";
180
+ source += " /**\n";
170
181
  source += " * @notice Get facet implementation address by name\n";
171
182
  source += " * @param facetName The name of the facet\n";
172
183
  source += " * @return The address of the facet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A5OD,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"]}
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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AM,IAAI,WAAW,CAAC;QAEtB,MAAM,IAAI,WAAW,CAAC;QACtB,MAAM,IAAI,2DAA2D,CAAC;QACtE,MAAM,IAAI,iDAAiD,CAAC;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;AAzPD,0CAyPC","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 // 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 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
@@ -3,8 +3,5 @@ import "./tasks/generate-helpers";
3
3
  import "./tasks/init";
4
4
  import "./tasks/test";
5
5
  import "./types/hardhat";
6
- export { DeploymentManager } from "./framework/DeploymentManager";
7
- export { ForgeFuzzingFramework } from "./framework/ForgeFuzzingFramework";
8
- export { HelperGenerator } from "./framework/HelperGenerator";
9
6
  export * from "./types/config";
10
7
  //# sourceMappingURL=index.d.ts.map
@@ -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,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"}
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"}
package/dist/index.js CHANGED
@@ -17,7 +17,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
17
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.HelperGenerator = exports.ForgeFuzzingFramework = exports.DeploymentManager = void 0;
21
20
  const config_1 = require("hardhat/config");
22
21
  require("./tasks/deploy");
23
22
  require("./tasks/generate-helpers");
@@ -30,13 +29,6 @@ const path_1 = __importDefault(require("path"));
30
29
  const picocolors_1 = __importDefault(require("picocolors"));
31
30
  const foundry_1 = require("./foundry");
32
31
  const validation_1 = require("./utils/validation");
33
- // Export framework classes for programmatic use
34
- var DeploymentManager_1 = require("./framework/DeploymentManager");
35
- Object.defineProperty(exports, "DeploymentManager", { enumerable: true, get: function () { return DeploymentManager_1.DeploymentManager; } });
36
- var ForgeFuzzingFramework_1 = require("./framework/ForgeFuzzingFramework");
37
- Object.defineProperty(exports, "ForgeFuzzingFramework", { enumerable: true, get: function () { return ForgeFuzzingFramework_1.ForgeFuzzingFramework; } });
38
- var HelperGenerator_1 = require("./framework/HelperGenerator");
39
- Object.defineProperty(exports, "HelperGenerator", { enumerable: true, get: function () { return HelperGenerator_1.HelperGenerator; } });
40
32
  // Export types
41
33
  __exportStar(require("./types/config"), exports);
42
34
  const TASK_INIT_FOUNDRY = "init-foundry";
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;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C,eAAe,EAAE;QACpB,OAAO,EAAE,CAAC;KACX;IAED,OAAO,IAAA,uBAAa,GAAE,CAAC;AACzB,CAAC,CACF,CAAC;AAEF,IAAA,aAAI,EACF,iBAAiB,EACjB,qDAAqD,EACrD,KAAK,EAAE,CAAC,EAAE,GAA8B,EAAE,EAAE;IAC1C,MAAM,iBAAiB,GAAG,cAAI,CAAC,OAAO,CACpC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,EACrB,cAAc,CACf,CAAC;IAEF,IAAI,IAAA,eAAU,EAAC,iBAAiB,CAAC,EAAE;QACjC,OAAO,CAAC,IAAI,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"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A,uBAAa,GAAE,CAAC;AACzB,CAAC,CACF,CAAC;AAEF,IAAA,aAAI,EACF,iBAAiB,EACjB,qDAAqD,EACrD,KAAK,EAAE,CAAC,EAAE,GAA8B,EAAE,EAAE;IAC1C,MAAM,iBAAiB,GAAG,cAAI,CAAC,OAAO,CACpC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,EACrB,cAAc,CACf,CAAC;IAEF,IAAI,IAAA,eAAU,EAAC,iBAAiB,CAAC,EAAE;QACjC,OAAO,CAAC,IAAI,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 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,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const config_1 = require("hardhat/config");
4
- const DeploymentManager_1 = require("../framework/DeploymentManager");
5
4
  const logger_1 = require("../utils/logger");
6
5
  const validation_1 = require("../utils/validation");
7
6
  /**
@@ -46,7 +45,9 @@ const validation_1 = require("../utils/validation");
46
45
  }
47
46
  // Step 2: Deploy or reuse Diamond
48
47
  logger_1.Logger.step("Deploying Diamond contract...");
49
- const deploymentManager = new DeploymentManager_1.DeploymentManager(hre);
48
+ // Lazy-load DeploymentManager to avoid circular dependency
49
+ const { DeploymentManager } = await import("../framework/DeploymentManager.js");
50
+ const deploymentManager = new DeploymentManager(hre);
50
51
  try {
51
52
  let diamond;
52
53
  if (reuse) {
@@ -1 +1 @@
1
- {"version":3,"file":"deploy.js","sourceRoot":"","sources":["../../src/tasks/deploy.ts"],"names":[],"mappings":";;AAAA,2CAA6C;AAE7C,sEAAmE;AACnE,4CAAyC;AACzC,oDAAkE;AAElE;;;;;;;;;;GAUG;AACH,IAAA,aAAI,EAAC,uBAAuB,EAAE,2CAA2C,CAAC;KACvE,gBAAgB,CACf,aAAa,EACb,+BAA+B,EAC/B,gBAAgB,EAChB,cAAK,CAAC,MAAM,CACb;KACA,OAAO,CAAC,OAAO,EAAE,wCAAwC,CAAC;KAC1D,OAAO,CAAC,OAAO,EAAE,8CAA8C,CAAC;KAChE,SAAS,CAAC,KAAK,EAAE,QAAQ,EAAE,GAA8B,EAAE,EAAE;IAC5D,eAAM,CAAC,OAAO,CAAC,qCAAqC,CAAC,CAAC;IAEtD,+CAA+C;IAC/C,MAAM,WAAW,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC;IACrC,MAAM,WAAW,GAAG,QAAQ,CAAC,WAAW,CAAC;IACzC,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC;IAC7B,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC;IAE7B,iBAAiB;IACjB,IAAI,KAAK,IAAI,KAAK,EAAE;QAClB,eAAM,CAAC,KAAK,CAAC,2CAA2C,CAAC,CAAC;QAC1D,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;KAC3D;IAED,eAAM,CAAC,IAAI,CAAC,YAAY,WAAW,EA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CAAC;QAEnE,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,cAAc,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC;QAC3E,eAAM,CAAC,IAAI,CAAC,oBAAoB,UAAU,EAAE,CAAC,CAAC;QAE9C,IAAI,UAAU,GAAG,CAAC,EAAE;YAClB,eAAM,CAAC,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"]}
1
+ {"version":3,"file":"deploy.js","sourceRoot":"","sources":["../../src/tasks/deploy.ts"],"names":[],"mappings":";;AAAA,2CAA6C;AAE7C,4CAAyC;AACzC,oDAAkE;AAElE;;;;;;;;;;GAUG;AACH,IAAA,aAAI,EAAC,uBAAuB,EAAE,2CAA2C,CAAC;KACvE,gBAAgB,CACf,aAAa,EACb,+BAA+B,EAC/B,gBAAgB,EAChB,cAAK,CAAC,MAAM,CACb;KACA,OAAO,CAAC,OAAO,EAAE,wCAAwC,CAAC;KAC1D,OAAO,CAAC,OAAO,EAAE,8CAA8C,CAAC;KAChE,SAAS,CAAC,KAAK,EAAE,QAAQ,EAAE,GAA8B,EAAE,EAAE;IAC5D,eAAM,CAAC,OAAO,CAAC,qCAAqC,CAAC,CAAC;IAEtD,+CAA+C;IAC/C,MAAM,WAAW,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC;IACrC,MAAM,WAAW,GAAG,QAAQ,CAAC,WAAW,CAAC;IACzC,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC;IAC7B,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC;IAE7B,iBAAiB;IACjB,IAAI,KAAK,IAAI,KAAK,EAAE;QAClB,eAAM,CAAC,KAAK,CAAC,2CAA2C,CAAC,CAAC;QAC1D,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;KAC3D;IAED,eAAM,CAAC,IAAI,CAAC,YAAY,WAAW,EAAE,CAAC,CAAC;IACvC,eAAM,CAAC,IAAI,CAAC,YAAY,WAAW,EAAE,CAAC,CAAC;IACvC,eAAM,CAAC,IAAI,CAAC,SAA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M,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,cAAc,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC;QAC3E,eAAM,CAAC,IAAI,CAAC,oBAAoB,UAAU,EAAE,CAAC,CAAC;QAE9C,IAAI,UAAU,GAAG,CAAC,EAAE;YAClB,eAAM,CAAC,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 { 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 \n // Lazy-load DeploymentManager to avoid circular dependency\n const { DeploymentManager } = await import(\"../framework/DeploymentManager.js\");\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"]}