@diamondslab/diamonds-hardhat-foundry 1.0.3 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/CHANGELOG.md +154 -0
  2. package/README.md +568 -4
  3. package/contracts/DiamondABILoader.sol +329 -0
  4. package/contracts/DiamondForgeHelpers.sol +309 -85
  5. package/contracts/DiamondFuzzBase.sol +305 -114
  6. package/dist/foundry.d.ts +28 -0
  7. package/dist/foundry.d.ts.map +1 -1
  8. package/dist/foundry.js +82 -1
  9. package/dist/foundry.js.map +1 -1
  10. package/dist/framework/DeploymentManager.d.ts +10 -11
  11. package/dist/framework/DeploymentManager.d.ts.map +1 -1
  12. package/dist/framework/DeploymentManager.js +56 -45
  13. package/dist/framework/DeploymentManager.js.map +1 -1
  14. package/dist/framework/ForgeFuzzingFramework.d.ts +4 -0
  15. package/dist/framework/ForgeFuzzingFramework.d.ts.map +1 -1
  16. package/dist/framework/ForgeFuzzingFramework.js +16 -2
  17. package/dist/framework/ForgeFuzzingFramework.js.map +1 -1
  18. package/dist/framework/HelperGenerator.d.ts.map +1 -1
  19. package/dist/framework/HelperGenerator.js +11 -0
  20. package/dist/framework/HelperGenerator.js.map +1 -1
  21. package/dist/index.d.ts +0 -3
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +0 -8
  24. package/dist/index.js.map +1 -1
  25. package/dist/tasks/deploy.js +3 -2
  26. package/dist/tasks/deploy.js.map +1 -1
  27. package/dist/tasks/generate-helpers.js +6 -4
  28. package/dist/tasks/generate-helpers.js.map +1 -1
  29. package/dist/tasks/init.js +3 -2
  30. package/dist/tasks/init.js.map +1 -1
  31. package/dist/tasks/test.js +13 -2
  32. package/dist/tasks/test.js.map +1 -1
  33. package/dist/templates/ExampleFuzzTest.t.sol.template +26 -17
  34. package/dist/templates/ExampleIntegrationTest.t.sol.template +9 -1
  35. package/dist/templates/ExampleUnitTest.t.sol.template +7 -1
  36. package/dist/types/hardhat.d.ts +1 -1
  37. package/dist/types/hardhat.d.ts.map +1 -1
  38. package/dist/types/hardhat.js +1 -0
  39. package/dist/types/hardhat.js.map +1 -1
  40. package/dist/utils/foundry.d.ts +1 -0
  41. package/dist/utils/foundry.d.ts.map +1 -1
  42. package/dist/utils/foundry.js +3 -0
  43. package/dist/utils/foundry.js.map +1 -1
  44. package/package.json +5 -3
  45. package/src/foundry.ts +104 -0
  46. package/src/framework/DeploymentManager.ts +74 -69
  47. package/src/framework/ForgeFuzzingFramework.ts +23 -1
  48. package/src/framework/HelperGenerator.ts +13 -0
  49. package/src/index.ts +0 -5
  50. package/src/tasks/deploy.ts +3 -1
  51. package/src/tasks/generate-helpers.ts +6 -2
  52. package/src/tasks/init.ts +3 -1
  53. package/src/tasks/test.ts +12 -1
  54. package/src/templates/ExampleFuzzTest.t.sol.template +26 -17
  55. package/src/templates/ExampleIntegrationTest.t.sol.template +9 -1
  56. package/src/templates/ExampleUnitTest.t.sol.template +7 -1
  57. package/src/types/hardhat.ts +1 -1
  58. package/src/utils/foundry.ts +5 -0
@@ -1,8 +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
- const HelperGenerator_1 = require("../framework/HelperGenerator");
6
4
  const logger_1 = require("../utils/logger");
7
5
  /**
8
6
  * Task: diamonds-forge:generate-helpers
@@ -26,9 +24,11 @@ const logger_1 = require("../utils/logger");
26
24
  logger_1.Logger.info(`Diamond: ${diamondName}`);
27
25
  logger_1.Logger.info(`Network: ${networkName}`);
28
26
  logger_1.Logger.info(`Output: ${outputDir}`);
27
+ // Lazy-load framework to avoid circular dependency during config loading
28
+ const { DeploymentManager } = await import("../framework/DeploymentManager.js");
29
29
  // Step 1: Get deployment
30
30
  logger_1.Logger.step("Loading deployment data...");
31
- const deploymentManager = new DeploymentManager_1.DeploymentManager(hre);
31
+ const deploymentManager = new DeploymentManager(hre);
32
32
  try {
33
33
  const diamond = await deploymentManager.getDeployment(diamondName, networkName);
34
34
  if (!diamond) {
@@ -41,9 +41,11 @@ const logger_1 = require("../utils/logger");
41
41
  const provider = hre.ethers.provider;
42
42
  const network = await provider.getNetwork();
43
43
  const chainId = Number(network.chainId);
44
+ // Lazy-load HelperGenerator
45
+ const { HelperGenerator } = await import("../framework/HelperGenerator.js");
44
46
  // Step 3: Generate helpers
45
47
  logger_1.Logger.step("Generating Solidity helpers...");
46
- const generator = new HelperGenerator_1.HelperGenerator(hre);
48
+ const generator = new HelperGenerator(hre);
47
49
  const deploymentData = diamond.getDeployedDiamondData();
48
50
  const helperPath = await generator.generateDeploymentHelpers(diamondName, networkName, chainId, deploymentData);
49
51
  // Step 4: Summary
@@ -1 +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,W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Ac,UAAU,EAAE,CAAC,CAAC;QAE3C,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,cAAc,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC;QAC3E,eAAM,CAAC,IAAI,CAAC,oBAAoB,cAAc,CAAC,cAAc,EAAE,CAAC,CAAC;QACjE,eAAM,CAAC,IAAI,CAAC,oBAAoB,UAAU,EAAE,CAAC,CAAC;QAE9C,eAAM,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;QAC7B,eAAM,CAAC,IAAI,CAAC,4BAA4B,CAAC,CAAC;QAC1C,eAAM,CAAC,IAAI,CAAC,iDAAiD,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"]}
1
+ {"version":3,"file":"generate-helpers.js","sourceRoot":"","sources":["../../src/tasks/generate-helpers.ts"],"names":[],"mappings":";;AAAA,2CAA6C;AAE7C,4CAAyC;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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 { 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 // Lazy-load framework to avoid circular dependency during config loading\n const { DeploymentManager } = await import(\"../framework/DeploymentManager.js\");\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 // Lazy-load HelperGenerator\n const { HelperGenerator } = await import(\"../framework/HelperGenerator.js\");\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"]}
@@ -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 HelperGenerator_1 = require("../framework/HelperGenerator");
5
4
  const logger_1 = require("../utils/logger");
6
5
  const validation_1 = require("../utils/validation");
7
6
  /**
@@ -40,7 +39,9 @@ const validation_1 = require("../utils/validation");
40
39
  }
41
40
  // Step 3: Scaffold project structure
42
41
  logger_1.Logger.step("Creating test directory structure...");
43
- const generator = new HelperGenerator_1.HelperGenerator(hre);
42
+ // Lazy-load framework classes to avoid circular dependency
43
+ const { HelperGenerator } = await import("../framework/HelperGenerator.js");
44
+ const generator = new HelperGenerator(hre);
44
45
  try {
45
46
  await generator.scaffoldProject(helpersDir);
46
47
  logger_1.Logger.success("Directory structure created");
@@ -1 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C;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"]}
1
+ {"version":3,"file":"init.js","sourceRoot":"","sources":["../../src/tasks/init.ts"],"names":[],"mappings":";;AAAA,2CAA6C;AAE7C,4CAAyC;AACzC,oDAAkF;AAElF;;;;;;;;GAQG;AACH,IAAA,aAAI,EAAC,qBAAqB,EAAE,0DAA0D,CAAC;KACpF,gBAAgB,CACf,YAAY,EACZ,sCAAsC,EACtC,SAAS,EACT,cAAK,CAAC,MAAM,CACb;KACA,OAAO,CAAC,UAAU,EAAE,6BAA6B,CAAC;KAClD,OAAO,CAAC,OAAO,EAAE,0BAA0B,CAAC;KAC5C,SAAS,CAAC,KAAK,EAAE,QAAQ,EAAE,GAA8B,EAAE,EAAE;IAC5D,eAAM,CAAC,OAAO,CAAC,qCAAqC,CAAC,CAAC;IAEtD,iCAAiC;IACjC,eAAM,CAAC,IAAI,CAAC,6BAA6B,CAAC,CAAC;IAC3C,MAAM,MAAM,GAAG,IAAA,2BAAc,EAAC,GAAG,CAAC,eAAe,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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 { 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 \n // Lazy-load framework classes to avoid circular dependency\n const { HelperGenerator } = await import(\"../framework/HelperGenerator.js\");\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"]}
@@ -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 ForgeFuzzingFramework_1 = require("../framework/ForgeFuzzingFramework");
5
4
  const logger_1 = require("../utils/logger");
6
5
  /**
7
6
  * Task: diamonds-forge:test
@@ -23,6 +22,8 @@ const logger_1 = require("../utils/logger");
23
22
  .addFlag("skipDeployment", "Skip Diamond deployment step")
24
23
  .addFlag("skipHelpers", "Skip helper generation step")
25
24
  .addFlag("force", "Force redeployment of Diamond")
25
+ .addFlag("saveDeployment", "Write deployment data to file for reuse")
26
+ .addFlag("useSnapshot", "Use EVM snapshots for test isolation")
26
27
  .setAction(async (taskArgs, hre) => {
27
28
  logger_1.Logger.section("Running Forge Tests with Diamond");
28
29
  const diamondName = taskArgs.diamondName;
@@ -35,6 +36,8 @@ const logger_1 = require("../utils/logger");
35
36
  const skipDeployment = taskArgs.skipDeployment;
36
37
  const skipHelpers = taskArgs.skipHelpers;
37
38
  const force = taskArgs.force;
39
+ const saveDeployment = taskArgs.saveDeployment;
40
+ const useSnapshot = taskArgs.useSnapshot;
38
41
  logger_1.Logger.info(`Diamond: ${diamondName}`);
39
42
  logger_1.Logger.info(`Network: ${networkName}`);
40
43
  if (matchTest)
@@ -47,6 +50,12 @@ const logger_1 = require("../utils/logger");
47
50
  logger_1.Logger.info("Skip Deployment: true");
48
51
  if (skipHelpers)
49
52
  logger_1.Logger.info("Skip Helpers: true");
53
+ if (saveDeployment)
54
+ logger_1.Logger.info("Save Deployment: true");
55
+ if (useSnapshot)
56
+ logger_1.Logger.info("Use Snapshot: true");
57
+ // Lazy-load framework to avoid circular dependency during config loading
58
+ const { ForgeFuzzingFramework } = await import("../framework/ForgeFuzzingFramework.js");
50
59
  // Create test options
51
60
  const options = {
52
61
  diamondName,
@@ -58,9 +67,11 @@ const logger_1 = require("../utils/logger");
58
67
  gasReport,
59
68
  skipHelpers,
60
69
  skipDeployment,
70
+ writeDeployedDiamondData: saveDeployment,
71
+ useSnapshot,
61
72
  };
62
73
  // Run tests using the framework
63
- const framework = new ForgeFuzzingFramework_1.ForgeFuzzingFramework(hre);
74
+ const framework = new ForgeFuzzingFramework(hre);
64
75
  try {
65
76
  const success = await framework.runTests(options);
66
77
  if (success) {
@@ -1 +1 @@
1
- {"version":3,"file":"test.js","sourceRoot":"","sources":["../../src/tasks/test.ts"],"names":[],"mappings":";;AAAA,2CAA6C;AAE7C,8EAA6F;AAC7F,4CAAyC;AAEzC;;;;;;;;;;GAUG;AACH,IAAA,aAAI,EAAC,qBAAqB,EAAE,yCAAyC,CAAC;KACnE,gBAAgB,CACf,aAAa,EACb,6BAA6B,EAC7B,gBAAgB,EAChB,cAAK,CAAC,MAAM,CACb;KACA,gBAAgB,CACf,WAAW,EACX,2CAA2C,EAC3C,SAAS,EACT,cAAK,CAAC,MAAM,CACb;KACA,gBAAgB,CACf,eAAe,EACf,4DAA4D,EAC5D,SAAS,EACT,cAAK,CAAC,MAAM,CACb;KACA,gBAAgB,CACf,WAAW,EACX,gDAAgD,EAChD,CAAC,EACD,cAAK,CAAC,GAAG,CACV;KACA,OAAO,CAAC,WAAW,EAAE,iBAAiB,CAAC;KACvC,OAAO,CAAC,gBAAgB,EAAE,8BAA8B,CAAC;KACzD,OAAO,CAAC,aAAa,EAAE,6BAA6B,CAAC;KACrD,OAAO,CAAC,OAAO,EAAE,+BAA+B,CAAC;KACjD,SAAS,CAAC,KAAK,EAAE,QAAQ,EAAE,GAA8B,EAAE,EAAE;IAC5D,eAAM,CAAC,OAAO,CAAC,kCAAkC,CAAC,CAAC;IAEnD,MAAM,WAAW,GAAG,QAAQ,CAAC,WAAW,CAAC;IACzC,+CAA+C;IAC/C,MAAM,WAAW,GAAG,GAA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,yBAAyB,CAAC,CAAC;YAC1C,eAAM,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC;YACpC,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;SACtB;aAAM;YACL,eAAM,CAAC,OAAO,CAAC,yBAAyB,CAAC,CAAC;YAC1C,eAAM,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC;YAClC,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;SACtB;KAEF;IAAC,OAAO,KAAU,EAAE;QACnB,eAAM,CAAC,KAAK,CAAC,0BAA0B,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QACxD,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;QACrB,MAAM,KAAK,CAAC;KACb;AACH,CAAC,CAAC,CAAC","sourcesContent":["import { task, types } from \"hardhat/config\";\nimport { HardhatRuntimeEnvironment } from \"hardhat/types\";\nimport { ForgeFuzzingFramework, ForgeTestOptions } from \"../framework/ForgeFuzzingFramework\";\nimport { Logger } from \"../utils/logger\";\n\n/**\n * Task: diamonds-forge:test\n * \n * Runs Forge tests with Diamond deployment.\n * - Ensures Diamond deployment exists\n * - Generates Solidity helpers\n * - Compiles Forge contracts\n * - Runs forge test with specified options\n * \n * Use Hardhat's built-in --network flag to specify the network\n */\ntask(\"diamonds-forge:test\", \"Run Forge tests with Diamond deployment\")\n .addOptionalParam(\n \"diamondName\",\n \"Name of the Diamond to test\",\n \"ExampleDiamond\",\n types.string\n )\n .addOptionalParam(\n \"matchTest\",\n \"Run tests matching pattern (--match-test)\",\n undefined,\n types.string\n )\n .addOptionalParam(\n \"matchContract\",\n \"Run tests in contracts matching pattern (--match-contract)\",\n undefined,\n types.string\n )\n .addOptionalParam(\n \"verbosity\",\n \"Verbosity level (1-5, more v's = more verbose)\",\n 2,\n types.int\n )\n .addFlag(\"gasReport\", \"Show gas report\")\n .addFlag(\"skipDeployment\", \"Skip Diamond deployment step\")\n .addFlag(\"skipHelpers\", \"Skip helper generation step\")\n .addFlag(\"force\", \"Force redeployment of Diamond\")\n .setAction(async (taskArgs, hre: HardhatRuntimeEnvironment) => {\n Logger.section(\"Running Forge Tests with Diamond\");\n\n const diamondName = taskArgs.diamondName;\n // Use Hardhat's built-in network name from HRE\n const networkName = hre.network.name;\n const matchTest = taskArgs.matchTest;\n const matchContract = taskArgs.matchContract;\n const verbosity = taskArgs.verbosity;\n const gasReport = taskArgs.gasReport;\n const skipDeployment = taskArgs.skipDeployment;\n const skipHelpers = taskArgs.skipHelpers;\n const force = taskArgs.force;\n\n Logger.info(`Diamond: ${diamondName}`);\n Logger.info(`Network: ${networkName}`);\n \n if (matchTest) Logger.info(`Match Test: ${matchTest}`);\n if (matchContract) Logger.info(`Match Contract: ${matchContract}`);\n if (gasReport) Logger.info(\"Gas Report: enabled\");\n if (skipDeployment) Logger.info(\"Skip Deployment: true\");\n if (skipHelpers) Logger.info(\"Skip Helpers: true\");\n\n // Create test options\n const options: ForgeTestOptions = {\n diamondName,\n networkName,\n force,\n matchTest,\n matchContract,\n verbosity,\n gasReport,\n skipHelpers,\n skipDeployment,\n };\n\n // Run tests using the framework\n const framework = new ForgeFuzzingFramework(hre);\n \n try {\n const success = await framework.runTests(options);\n\n if (success) {\n Logger.section(\"Test Execution Complete\");\n Logger.success(\"All tests passed!\");\n process.exitCode = 0;\n } else {\n Logger.section(\"Test Execution Complete\");\n Logger.error(\"Some tests failed\");\n process.exitCode = 1;\n }\n\n } catch (error: any) {\n Logger.error(`Test execution failed: ${error.message}`);\n process.exitCode = 1;\n throw error;\n }\n });\n\n\n"]}
1
+ {"version":3,"file":"test.js","sourceRoot":"","sources":["../../src/tasks/test.ts"],"names":[],"mappings":";;AAAA,2CAA6C;AAE7C,4CAAyC;AAEzC;;;;;;;;;;GAUG;AACH,IAAA,aAAI,EAAC,qBAAqB,EAAE,yCAAyC,CAAC;KACnE,gBAAgB,CACf,aAAa,EACb,6BAA6B,EAC7B,gBAAgB,EAChB,cAAK,CAAC,MAAM,CACb;KACA,gBAA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BAAyB,CAAC,CAAC;YAC1C,eAAM,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC;YAClC,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;SACtB;KAEF;IAAC,OAAO,KAAU,EAAE;QACnB,eAAM,CAAC,KAAK,CAAC,0BAA0B,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QACxD,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;QACrB,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\";\n\n/**\n * Task: diamonds-forge:test\n * \n * Runs Forge tests with Diamond deployment.\n * - Ensures Diamond deployment exists\n * - Generates Solidity helpers\n * - Compiles Forge contracts\n * - Runs forge test with specified options\n * \n * Use Hardhat's built-in --network flag to specify the network\n */\ntask(\"diamonds-forge:test\", \"Run Forge tests with Diamond deployment\")\n .addOptionalParam(\n \"diamondName\",\n \"Name of the Diamond to test\",\n \"ExampleDiamond\",\n types.string\n )\n .addOptionalParam(\n \"matchTest\",\n \"Run tests matching pattern (--match-test)\",\n undefined,\n types.string\n )\n .addOptionalParam(\n \"matchContract\",\n \"Run tests in contracts matching pattern (--match-contract)\",\n undefined,\n types.string\n )\n .addOptionalParam(\n \"verbosity\",\n \"Verbosity level (1-5, more v's = more verbose)\",\n 2,\n types.int\n )\n .addFlag(\"gasReport\", \"Show gas report\")\n .addFlag(\"skipDeployment\", \"Skip Diamond deployment step\")\n .addFlag(\"skipHelpers\", \"Skip helper generation step\")\n .addFlag(\"force\", \"Force redeployment of Diamond\")\n .addFlag(\"saveDeployment\", \"Write deployment data to file for reuse\")\n .addFlag(\"useSnapshot\", \"Use EVM snapshots for test isolation\")\n .setAction(async (taskArgs, hre: HardhatRuntimeEnvironment) => {\n Logger.section(\"Running Forge Tests with Diamond\");\n\n const diamondName = taskArgs.diamondName;\n // Use Hardhat's built-in network name from HRE\n const networkName = hre.network.name;\n const matchTest = taskArgs.matchTest;\n const matchContract = taskArgs.matchContract;\n const verbosity = taskArgs.verbosity;\n const gasReport = taskArgs.gasReport;\n const skipDeployment = taskArgs.skipDeployment;\n const skipHelpers = taskArgs.skipHelpers;\n const force = taskArgs.force;\n const saveDeployment = taskArgs.saveDeployment;\n const useSnapshot = taskArgs.useSnapshot;\n\n Logger.info(`Diamond: ${diamondName}`);\n Logger.info(`Network: ${networkName}`);\n \n if (matchTest) Logger.info(`Match Test: ${matchTest}`);\n if (matchContract) Logger.info(`Match Contract: ${matchContract}`);\n if (gasReport) Logger.info(\"Gas Report: enabled\");\n if (skipDeployment) Logger.info(\"Skip Deployment: true\");\n if (skipHelpers) Logger.info(\"Skip Helpers: true\");\n if (saveDeployment) Logger.info(\"Save Deployment: true\");\n if (useSnapshot) Logger.info(\"Use Snapshot: true\");\n\n // Lazy-load framework to avoid circular dependency during config loading\n const { ForgeFuzzingFramework } = await import(\"../framework/ForgeFuzzingFramework.js\");\n type ForgeTestOptions = Parameters<InstanceType<typeof ForgeFuzzingFramework>[\"runTests\"]>[0];\n\n // Create test options\n const options: ForgeTestOptions = {\n diamondName,\n networkName,\n force,\n matchTest,\n matchContract,\n verbosity,\n gasReport,\n skipHelpers,\n skipDeployment,\n writeDeployedDiamondData: saveDeployment,\n useSnapshot,\n };\n\n // Run tests using the framework\n const framework = new ForgeFuzzingFramework(hre);\n \n try {\n const success = await framework.runTests(options);\n\n if (success) {\n Logger.section(\"Test Execution Complete\");\n Logger.success(\"All tests passed!\");\n process.exitCode = 0;\n } else {\n Logger.section(\"Test Execution Complete\");\n Logger.error(\"Some tests failed\");\n process.exitCode = 1;\n }\n\n } catch (error: any) {\n Logger.error(`Test execution failed: ${error.message}`);\n process.exitCode = 1;\n throw error;\n }\n });\n\n\n"]}
@@ -3,8 +3,9 @@ pragma solidity ^0.8.0;
3
3
 
4
4
  import "forge-std/Test.sol";
5
5
  import "forge-std/console.sol";
6
- import "../../contracts/DiamondFuzzBase.sol";
7
- import "../../helpers/DiamondDeployment.sol";
6
+ import "@diamondslab/diamonds-hardhat-foundry/contracts/DiamondFuzzBase.sol";
7
+ import "@diamondslab/diamonds-hardhat-foundry/contracts/DiamondForgeHelpers.sol";
8
+ import "../helpers/DiamondDeployment.sol";
8
9
 
9
10
  /**
10
11
  * @title ExampleFuzzTest
@@ -12,17 +13,19 @@ import "../../helpers/DiamondDeployment.sol";
12
13
  * @dev Uses DiamondFuzzBase for common fuzz testing utilities
13
14
  */
14
15
  contract ExampleFuzzTest is DiamondFuzzBase {
16
+ using DiamondForgeHelpers for address;
17
+
18
+ /// @notice Override to load Diamond from deployment
19
+ function _loadDiamondAddress() internal view override returns (address) {
20
+ return DiamondDeployment.diamond();
21
+ }
22
+
15
23
  function setUp() public override {
16
24
  super.setUp();
17
25
 
18
- // Load Diamond deployment
19
- setDiamondAddress(DiamondDeployment.diamond());
20
-
21
- // Register facets (customize for your Diamond)
22
- // registerFacet("FacetName", DiamondDeployment.facetName());
23
-
24
26
  console.log("Fuzz test setup complete");
25
27
  console.log("Diamond:", diamond);
28
+ console.log("Functions loaded:", diamondSelectors.length);
26
29
  }
27
30
 
28
31
  /**
@@ -31,11 +34,14 @@ contract ExampleFuzzTest is DiamondFuzzBase {
31
34
  */
32
35
  function testFuzz_AddressInput(address randomAddress) public {
33
36
  // Filter invalid addresses
34
- assumeValidAddress(randomAddress);
37
+ vm.assume(DiamondForgeHelpers.isValidTestAddress(randomAddress));
35
38
 
36
39
  // TODO: Test your Diamond function with fuzzed address
37
40
  // Example:
38
- // MyDiamond(diamond).someFunction(randomAddress);
41
+ // bytes4 selector = bytes4(keccak256("someFunction(address)"));
42
+ // bytes memory data = abi.encode(randomAddress);
43
+ // (bool success,) = _callDiamond(selector, data);
44
+ // assertTrue(success);
39
45
 
40
46
  assertTrue(true, "Replace with actual fuzz test");
41
47
  }
@@ -46,11 +52,13 @@ contract ExampleFuzzTest is DiamondFuzzBase {
46
52
  */
47
53
  function testFuzz_AmountInput(uint256 amount) public {
48
54
  // Bound the amount to valid range
49
- assumeValidAmount(amount);
55
+ vm.assume(DiamondForgeHelpers.isValidTestAmount(amount));
50
56
 
51
57
  // TODO: Test your Diamond function with fuzzed amount
52
58
  // Example:
53
- // MyDiamond(diamond).transfer(user1, amount);
59
+ // bytes4 selector = bytes4(keccak256("transfer(address,uint256)"));
60
+ // bytes memory data = abi.encode(user1, amount);
61
+ // (bool success,) = _callDiamond(selector, data);
54
62
 
55
63
  assertTrue(true, "Replace with actual fuzz test");
56
64
  }
@@ -67,8 +75,8 @@ contract ExampleFuzzTest is DiamondFuzzBase {
67
75
  bytes memory data
68
76
  ) public {
69
77
  // Filter inputs
70
- assumeValidAddress(addr);
71
- assumeValidAmount(value);
78
+ vm.assume(DiamondForgeHelpers.isValidTestAddress(addr));
79
+ vm.assume(DiamondForgeHelpers.isValidTestAmount(value));
72
80
  vm.assume(data.length > 0);
73
81
  vm.assume(data.length < 1024); // Reasonable size limit
74
82
 
@@ -86,8 +94,9 @@ contract ExampleFuzzTest is DiamondFuzzBase {
86
94
  vm.assume(badValue > type(uint128).max);
87
95
 
88
96
  // TODO: Test that function reverts with invalid input
89
- // expectRevertWithMessage("Invalid amount");
90
- // MyDiamond(diamond).someFunction(badValue);
97
+ // bytes4 selector = bytes4(keccak256("someFunction(uint256)"));
98
+ // bytes memory data = abi.encode(badValue);
99
+ // _expectDiamondRevert(selector, data, bytes(""));
91
100
 
92
101
  assertTrue(true, "Replace with actual revert fuzz test");
93
102
  }
@@ -98,7 +107,7 @@ contract ExampleFuzzTest is DiamondFuzzBase {
98
107
  */
99
108
  function testFuzz_BoundedValue(uint256 rawValue) public {
100
109
  // Bound value to specific range (e.g., 1 to 1000)
101
- uint256 boundedValue = boundValue(rawValue, 1, 1000);
110
+ uint256 boundedValue = bound(rawValue, 1, 1000);
102
111
 
103
112
  // TODO: Test with bounded value
104
113
  assertGe(boundedValue, 1, "Value should be >= 1");
@@ -3,7 +3,9 @@ pragma solidity ^0.8.0;
3
3
 
4
4
  import "forge-std/Test.sol";
5
5
  import "forge-std/console.sol";
6
- import "../../helpers/DiamondDeployment.sol";
6
+ import "@diamondslab/diamonds-hardhat-foundry/contracts/DiamondForgeHelpers.sol";
7
+ import "@diamondslab/diamonds-hardhat-foundry/contracts/DiamondABILoader.sol";
8
+ import "../helpers/DiamondDeployment.sol";
7
9
 
8
10
  /**
9
11
  * @title ExampleIntegrationTest
@@ -11,6 +13,9 @@ import "../../helpers/DiamondDeployment.sol";
11
13
  * @dev Tests interactions between multiple facets and Diamond functionality
12
14
  */
13
15
  contract ExampleIntegrationTest is Test {
16
+ using DiamondForgeHelpers for address;
17
+ using DiamondABILoader for string;
18
+
14
19
  address diamond;
15
20
  address deployer;
16
21
 
@@ -23,6 +28,9 @@ contract ExampleIntegrationTest is Test {
23
28
  diamond = DiamondDeployment.diamond();
24
29
  deployer = DiamondDeployment.deployer();
25
30
 
31
+ // Validate Diamond
32
+ DiamondForgeHelpers.assertValidDiamond(diamond);
33
+
26
34
  // Set up test users
27
35
  user1 = makeAddr("user1");
28
36
  user2 = makeAddr("user2");
@@ -3,7 +3,8 @@ pragma solidity ^0.8.0;
3
3
 
4
4
  import "forge-std/Test.sol";
5
5
  import "forge-std/console.sol";
6
- import "../../helpers/DiamondDeployment.sol";
6
+ import "@diamondslab/diamonds-hardhat-foundry/contracts/DiamondForgeHelpers.sol";
7
+ import "../helpers/DiamondDeployment.sol";
7
8
 
8
9
  /**
9
10
  * @title ExampleUnitTest
@@ -11,6 +12,8 @@ import "../../helpers/DiamondDeployment.sol";
11
12
  * @dev This is a template - customize for your specific Diamond implementation
12
13
  */
13
14
  contract ExampleUnitTest is Test {
15
+ using DiamondForgeHelpers for address;
16
+
14
17
  address diamond;
15
18
  address deployer;
16
19
 
@@ -21,6 +24,9 @@ contract ExampleUnitTest is Test {
21
24
 
22
25
  console.log("Diamond deployed at:", diamond);
23
26
  console.log("Deployed by:", deployer);
27
+
28
+ // Validate Diamond deployment
29
+ DiamondForgeHelpers.assertValidDiamond(diamond);
24
30
  }
25
31
 
26
32
  /**
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * Type extensions for Hardhat Runtime Environment
3
3
  */
4
+ import "@nomicfoundation/hardhat-ethers";
4
5
  import "hardhat/types/config";
5
6
  import "hardhat/types/runtime";
6
7
  import { DiamondsFoundryConfig } from "../types/config";
@@ -15,7 +16,6 @@ declare module "hardhat/types/config" {
15
16
  declare module "hardhat/types/runtime" {
16
17
  interface HardhatRuntimeEnvironment {
17
18
  diamondsFoundry: Required<DiamondsFoundryConfig>;
18
- ethers: any;
19
19
  }
20
20
  }
21
21
  //# sourceMappingURL=hardhat.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"hardhat.d.ts","sourceRoot":"","sources":["../../src/types/hardhat.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,sBAAsB,CAAC;AAC9B,OAAO,uBAAuB,CAAC;AAC/B,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAExD,OAAO,QAAQ,sBAAsB,CAAC;IACpC,UAAiB,iBAAiB;QAChC,eAAe,CAAC,EAAE,OAAO,CAAC,qBAAqB,CAAC,CAAC;KAClD;IAED,UAAiB,aAAa;QAC5B,eAAe,EAAE,QAAQ,CAAC,qBAAqB,CAAC,CAAC;KAClD;CACF;AAED,OAAO,QAAQ,uBAAuB,CAAC;IACrC,UAAiB,yBAAyB;QACxC,eAAe,EAAE,QAAQ,CAAC,qBAAqB,CAAC,CAAC;QACjD,MAAM,EAAE,GAAG,CAAC;KACb;CACF"}
1
+ {"version":3,"file":"hardhat.d.ts","sourceRoot":"","sources":["../../src/types/hardhat.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,iCAAiC,CAAC;AACzC,OAAO,sBAAsB,CAAC;AAC9B,OAAO,uBAAuB,CAAC;AAC/B,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAExD,OAAO,QAAQ,sBAAsB,CAAC;IACpC,UAAiB,iBAAiB;QAChC,eAAe,CAAC,EAAE,OAAO,CAAC,qBAAqB,CAAC,CAAC;KAClD;IAED,UAAiB,aAAa;QAC5B,eAAe,EAAE,QAAQ,CAAC,qBAAqB,CAAC,CAAC;KAClD;CACF;AAED,OAAO,QAAQ,uBAAuB,CAAC;IACrC,UAAiB,yBAAyB;QACxC,eAAe,EAAE,QAAQ,CAAC,qBAAqB,CAAC,CAAC;KAClD;CACF"}
@@ -3,6 +3,7 @@
3
3
  * Type extensions for Hardhat Runtime Environment
4
4
  */
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ require("@nomicfoundation/hardhat-ethers");
6
7
  require("hardhat/types/config");
7
8
  require("hardhat/types/runtime");
8
9
  //# sourceMappingURL=hardhat.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"hardhat.js","sourceRoot":"","sources":["../../src/types/hardhat.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAEH,gCAA8B;AAC9B,iCAA+B","sourcesContent":["/**\n * Type extensions for Hardhat Runtime Environment\n */\n\nimport \"hardhat/types/config\";\nimport \"hardhat/types/runtime\";\nimport { DiamondsFoundryConfig } from \"../types/config\";\n\ndeclare module \"hardhat/types/config\" {\n export interface HardhatUserConfig {\n diamondsFoundry?: Partial<DiamondsFoundryConfig>;\n }\n\n export interface HardhatConfig {\n diamondsFoundry: Required<DiamondsFoundryConfig>;\n }\n}\n\ndeclare module \"hardhat/types/runtime\" {\n export interface HardhatRuntimeEnvironment {\n diamondsFoundry: Required<DiamondsFoundryConfig>;\n ethers: any; // Will be provided by @nomicfoundation/hardhat-ethers\n }\n}\n"]}
1
+ {"version":3,"file":"hardhat.js","sourceRoot":"","sources":["../../src/types/hardhat.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAEH,2CAAyC;AACzC,gCAA8B;AAC9B,iCAA+B","sourcesContent":["/**\n * Type extensions for Hardhat Runtime Environment\n */\n\nimport \"@nomicfoundation/hardhat-ethers\";\nimport \"hardhat/types/config\";\nimport \"hardhat/types/runtime\";\nimport { DiamondsFoundryConfig } from \"../types/config\";\n\ndeclare module \"hardhat/types/config\" {\n export interface HardhatUserConfig {\n diamondsFoundry?: Partial<DiamondsFoundryConfig>;\n }\n\n export interface HardhatConfig {\n diamondsFoundry: Required<DiamondsFoundryConfig>;\n }\n}\n\ndeclare module \"hardhat/types/runtime\" {\n export interface HardhatRuntimeEnvironment {\n diamondsFoundry: Required<DiamondsFoundryConfig>;\n }\n}\n"]}
@@ -31,6 +31,7 @@ export declare function runForgeTest(options: {
31
31
  matchContract?: string;
32
32
  verbosity?: number;
33
33
  gasReport?: boolean;
34
+ forkUrl?: string;
34
35
  cwd?: string;
35
36
  env?: Record<string, string>;
36
37
  }): Promise<{
@@ -1 +1 @@
1
- {"version":3,"file":"foundry.d.ts","sourceRoot":"","sources":["../../src/utils/foundry.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,wBAAgB,aAAa,CAC3B,OAAO,EAAE,MAAM,EACf,IAAI,GAAE,MAAM,EAAO,EACnB,OAAO,GAAE;IAAE,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,SAAS,GAAG,MAAM,CAAA;CAAO,GACzD,MAAM,CAkBR;AAED;;;;;GAKG;AACH,wBAAsB,cAAc,CAClC,OAAO,EAAE,MAAM,EACf,IAAI,GAAE,MAAM,EAAO,EACnB,OAAO,GAAE;IAAE,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAAO,GAChD,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC,CAqC/D;AAED;;;GAGG;AACH,wBAAsB,YAAY,CAAC,OAAO,EAAE;IAC1C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;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AED;;;GAGG;AACH,wBAAsB,YAAY,CAAC,OAAO,EAAE;IAC1C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC9B,GAAG,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CA0ChD;AAED;;;GAGG;AACH,wBAAsB,YAAY,CAAC,OAAO,EAAE;IAC1C,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,GAAG,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CAsBhD;AAED;;GAEG;AACH,wBAAgB,kBAAkB,IAAI,OAAO,CAO5C;AAED;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,GAAG,IAAI,CASjD"}
@@ -87,6 +87,9 @@ async function runForgeTest(options) {
87
87
  if (options.gasReport) {
88
88
  args.push("--gas-report");
89
89
  }
90
+ if (options.forkUrl) {
91
+ args.push("--fork-url", options.forkUrl);
92
+ }
90
93
  try {
91
94
  const result = await execForgeAsync("forge", args, {
92
95
  cwd: options.cwd,
@@ -1 +1 @@
1
- {"version":3,"file":"foundry.js","sourceRoot":"","sources":["../../src/utils/foundry.ts"],"names":[],"mappings":";;;AAAA,iDAAgD;AAChD,qCAAkC;AAElC;;;;;GAKG;AACH,SAAgB,aAAa,CAC3B,OAAe,EACf,OAAiB,EAAE,EACnB,UAAwD,EAAE;IAE1D,MAAM,WAAW,GAAG,GAAG,OAAO,IAAI,IAAI,CAA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child_process\";\nimport { Logger } from \"./logger\";\n\n/**\n * Execute a Foundry command synchronously\n * @param command - The foundry command (e.g., \"forge test\")\n * @param args - Command arguments\n * @param options - Execution options\n */\nexport function execForgeSync(\n command: string,\n args: string[] = [],\n options: { cwd?: string; stdio?: \"inherit\" | \"pipe\" } = {}\n): string {\n const fullCommand = `${command} ${args.join(\" \")}`;\n Logger.step(`Running: ${fullCommand}`);\n\n try {\n const output = execSync(fullCommand, {\n cwd: options.cwd || process.cwd(),\n stdio: options.stdio || \"pipe\",\n encoding: \"utf-8\",\n });\n\n return output;\n } catch (error: any) {\n Logger.error(`Forge command failed: ${error.message}`);\n if (error.stdout) Logger.info(error.stdout);\n if (error.stderr) Logger.error(error.stderr);\n throw error;\n }\n}\n\n/**\n * Execute a Foundry command asynchronously\n * @param command - The foundry command (e.g., \"forge\")\n * @param args - Command arguments\n * @param options - Execution options\n */\nexport async function execForgeAsync(\n command: string,\n args: string[] = [],\n options: { cwd?: string; verbose?: boolean } = {}\n): Promise<{ stdout: string; stderr: string; exitCode: number }> {\n Logger.step(`Running: ${command} ${args.join(\" \")}`);\n\n return new Promise((resolve, reject) => {\n const child = spawn(command, args, {\n cwd: options.cwd || process.cwd(),\n shell: true,\n });\n\n let stdout = \"\";\n let stderr = \"\";\n\n child.stdout?.on(\"data\", (data) => {\n const text = data.toString();\n stdout += text;\n if (options.verbose) {\n process.stdout.write(text);\n }\n });\n\n child.stderr?.on(\"data\", (data) => {\n const text = data.toString();\n stderr += text;\n if (options.verbose) {\n process.stderr.write(text);\n }\n });\n\n child.on(\"close\", (code) => {\n resolve({ stdout, stderr, exitCode: code || 0 });\n });\n\n child.on(\"error\", (error) => {\n Logger.error(`Failed to spawn ${command}: ${error.message}`);\n reject(error);\n });\n });\n}\n\n/**\n * Run forge test with specified options\n * @param options - Test execution options\n */\nexport async function runForgeTest(options: {\n matchTest?: string;\n matchContract?: string;\n verbosity?: number;\n gasReport?: boolean;\n cwd?: string;\n env?: Record<string, string>;\n}): Promise<{ success: boolean; output: string }> {\n const args: string[] = [\"test\"];\n\n if (options.matchTest) {\n args.push(\"--match-test\", options.matchTest);\n }\n\n if (options.matchContract) {\n args.push(\"--match-contract\", options.matchContract);\n }\n\n if (options.verbosity) {\n args.push(\"-\" + \"v\".repeat(options.verbosity));\n }\n\n if (options.gasReport) {\n args.push(\"--gas-report\");\n }\n\n try {\n const result = await execForgeAsync(\"forge\", args, {\n cwd: options.cwd,\n verbose: true,\n });\n\n const success = result.exitCode === 0;\n \n if (success) {\n Logger.success(\"Forge tests passed!\");\n } else {\n Logger.error(\"Forge tests failed\");\n }\n\n return { success, output: result.stdout + result.stderr };\n } catch (error: any) {\n Logger.error(`Test execution failed: ${error.message}`);\n return { success: false, output: error.message };\n }\n}\n\n/**\n * Compile Forge contracts\n * @param options - Compilation options\n */\nexport async function compileForge(options: {\n cwd?: string;\n verbose?: boolean;\n}): Promise<{ success: boolean; output: string }> {\n Logger.step(\"Compiling Forge contracts...\");\n\n try {\n const result = await execForgeAsync(\"forge\", [\"build\"], {\n cwd: options.cwd,\n verbose: options.verbose,\n });\n\n const success = result.exitCode === 0;\n \n if (success) {\n Logger.success(\"Forge compilation successful!\");\n } else {\n Logger.error(\"Forge compilation failed\");\n }\n\n return { success, output: result.stdout + result.stderr };\n } catch (error: any) {\n Logger.error(`Compilation failed: ${error.message}`);\n return { success: false, output: error.message };\n }\n}\n\n/**\n * Check if Foundry is installed\n */\nexport function isFoundryInstalled(): boolean {\n try {\n execSync(\"forge --version\", { stdio: \"pipe\" });\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Get Foundry version\n */\nexport function getFoundryVersion(): string | null {\n try {\n const output = execSync(\"forge --version\", { encoding: \"utf-8\", stdio: \"pipe\" });\n // Extract version from output like \"forge 0.2.0 (abc123 2024-01-01T00:00:00.000000000Z)\"\n const match = output.match(/forge\\s+([\\d.]+)/);\n return match ? match[1] : null;\n } catch {\n return null;\n }\n}\n"]}
1
+ {"version":3,"file":"foundry.js","s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,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;QACjF,yFAAyF;QACzF,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;QAC/C,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;KAChC;IAAC,MAAM;QACN,OAAO,IAAI,CAAC;KACb;AACH,CAAC;AATD,8CASC","sourcesContent":["import { execSync, spawn } from \"child_process\";\nimport { Logger } from \"./logger\";\n\n/**\n * Execute a Foundry command synchronously\n * @param command - The foundry command (e.g., \"forge test\")\n * @param args - Command arguments\n * @param options - Execution options\n */\nexport function execForgeSync(\n command: string,\n args: string[] = [],\n options: { cwd?: string; stdio?: \"inherit\" | \"pipe\" } = {}\n): string {\n const fullCommand = `${command} ${args.join(\" \")}`;\n Logger.step(`Running: ${fullCommand}`);\n\n try {\n const output = execSync(fullCommand, {\n cwd: options.cwd || process.cwd(),\n stdio: options.stdio || \"pipe\",\n encoding: \"utf-8\",\n });\n\n return output;\n } catch (error: any) {\n Logger.error(`Forge command failed: ${error.message}`);\n if (error.stdout) Logger.info(error.stdout);\n if (error.stderr) Logger.error(error.stderr);\n throw error;\n }\n}\n\n/**\n * Execute a Foundry command asynchronously\n * @param command - The foundry command (e.g., \"forge\")\n * @param args - Command arguments\n * @param options - Execution options\n */\nexport async function execForgeAsync(\n command: string,\n args: string[] = [],\n options: { cwd?: string; verbose?: boolean } = {}\n): Promise<{ stdout: string; stderr: string; exitCode: number }> {\n Logger.step(`Running: ${command} ${args.join(\" \")}`);\n\n return new Promise((resolve, reject) => {\n const child = spawn(command, args, {\n cwd: options.cwd || process.cwd(),\n shell: true,\n });\n\n let stdout = \"\";\n let stderr = \"\";\n\n child.stdout?.on(\"data\", (data) => {\n const text = data.toString();\n stdout += text;\n if (options.verbose) {\n process.stdout.write(text);\n }\n });\n\n child.stderr?.on(\"data\", (data) => {\n const text = data.toString();\n stderr += text;\n if (options.verbose) {\n process.stderr.write(text);\n }\n });\n\n child.on(\"close\", (code) => {\n resolve({ stdout, stderr, exitCode: code || 0 });\n });\n\n child.on(\"error\", (error) => {\n Logger.error(`Failed to spawn ${command}: ${error.message}`);\n reject(error);\n });\n });\n}\n\n/**\n * Run forge test with specified options\n * @param options - Test execution options\n */\nexport async function runForgeTest(options: {\n matchTest?: string;\n matchContract?: string;\n verbosity?: number;\n gasReport?: boolean;\n forkUrl?: string;\n cwd?: string;\n env?: Record<string, string>;\n}): Promise<{ success: boolean; output: string }> {\n const args: string[] = [\"test\"];\n\n if (options.matchTest) {\n args.push(\"--match-test\", options.matchTest);\n }\n\n if (options.matchContract) {\n args.push(\"--match-contract\", options.matchContract);\n }\n\n if (options.verbosity) {\n args.push(\"-\" + \"v\".repeat(options.verbosity));\n }\n\n if (options.gasReport) {\n args.push(\"--gas-report\");\n }\n\n if (options.forkUrl) {\n args.push(\"--fork-url\", options.forkUrl);\n }\n\n try {\n const result = await execForgeAsync(\"forge\", args, {\n cwd: options.cwd,\n verbose: true,\n });\n\n const success = result.exitCode === 0;\n \n if (success) {\n Logger.success(\"Forge tests passed!\");\n } else {\n Logger.error(\"Forge tests failed\");\n }\n\n return { success, output: result.stdout + result.stderr };\n } catch (error: any) {\n Logger.error(`Test execution failed: ${error.message}`);\n return { success: false, output: error.message };\n }\n}\n\n/**\n * Compile Forge contracts\n * @param options - Compilation options\n */\nexport async function compileForge(options: {\n cwd?: string;\n verbose?: boolean;\n}): Promise<{ success: boolean; output: string }> {\n Logger.step(\"Compiling Forge contracts...\");\n\n try {\n const result = await execForgeAsync(\"forge\", [\"build\"], {\n cwd: options.cwd,\n verbose: options.verbose,\n });\n\n const success = result.exitCode === 0;\n \n if (success) {\n Logger.success(\"Forge compilation successful!\");\n } else {\n Logger.error(\"Forge compilation failed\");\n }\n\n return { success, output: result.stdout + result.stderr };\n } catch (error: any) {\n Logger.error(`Compilation failed: ${error.message}`);\n return { success: false, output: error.message };\n }\n}\n\n/**\n * Check if Foundry is installed\n */\nexport function isFoundryInstalled(): boolean {\n try {\n execSync(\"forge --version\", { stdio: \"pipe\" });\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Get Foundry version\n */\nexport function getFoundryVersion(): string | null {\n try {\n const output = execSync(\"forge --version\", { encoding: \"utf-8\", stdio: \"pipe\" });\n // Extract version from output like \"forge 0.2.0 (abc123 2024-01-01T00:00:00.000000000Z)\"\n const match = output.match(/forge\\s+([\\d.]+)/);\n return match ? match[1] : null;\n } catch {\n return null;\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diamondslab/diamonds-hardhat-foundry",
3
- "version": "1.0.3",
3
+ "version": "2.1.0",
4
4
  "description": "Hardhat plugin that integrates Foundry testing with Diamond proxy contracts, providing deployment helpers and fuzzing support",
5
5
  "repository": {
6
6
  "type": "git",
@@ -68,8 +68,10 @@
68
68
  "typescript": "~5.0.0"
69
69
  },
70
70
  "peerDependencies": {
71
- "@diamondslab/diamonds": "^1.2.1",
72
- "@diamondslab/hardhat-diamonds": "^1.1.9",
71
+ "@diamondslab/diamonds": "^1.3.0",
72
+ "@diamondslab/hardhat-diamonds": "^1.1.12",
73
+ "@nomicfoundation/hardhat-ethers": "^3.0.8",
74
+ "ethers": "^6.0.0",
73
75
  "hardhat": "^2.26.0"
74
76
  },
75
77
  "dependencies": {
package/src/foundry.ts CHANGED
@@ -132,3 +132,107 @@ function buildForgeExecutionError(
132
132
  );
133
133
  }
134
134
  }
135
+
136
+ /**
137
+ * Check if Foundry is installed
138
+ */
139
+ export function isFoundryInstalled(): boolean {
140
+ try {
141
+ execSync("forge --version", { stdio: "pipe" });
142
+ return true;
143
+ } catch {
144
+ return false;
145
+ }
146
+ }
147
+
148
+ /**
149
+ * Compile Forge contracts
150
+ */
151
+ export async function compileForge(options: {
152
+ cwd?: string;
153
+ verbose?: boolean;
154
+ }): Promise<{ success: boolean; output?: string }> {
155
+ const { cwd = process.cwd(), verbose = false } = options;
156
+
157
+ try {
158
+ const args = ["build"];
159
+ if (!verbose) {
160
+ args.push("--quiet");
161
+ }
162
+
163
+ const { stdout, stderr } = await exec(`forge ${args.join(" ")}`, { cwd });
164
+ return { success: true, output: stdout || stderr };
165
+ } catch (error: any) {
166
+ console.error("Forge build failed:", error.message);
167
+ return { success: false, output: error.message };
168
+ }
169
+ }
170
+
171
+ /**
172
+ * Run Forge tests with optional forking
173
+ */
174
+ export async function runForgeTest(options: {
175
+ matchTest?: string;
176
+ matchContract?: string;
177
+ verbosity?: number;
178
+ gasReport?: boolean;
179
+ forkUrl?: string;
180
+ cwd?: string;
181
+ }): Promise<{ success: boolean; output?: string }> {
182
+ const {
183
+ matchTest,
184
+ matchContract,
185
+ verbosity = 2,
186
+ gasReport = false,
187
+ forkUrl,
188
+ cwd = process.cwd(),
189
+ } = options;
190
+
191
+ try {
192
+ const args = ["test"];
193
+
194
+ // Add verbosity
195
+ if (verbosity > 0 && verbosity <= 5) {
196
+ args.push(`-${"v".repeat(verbosity)}`);
197
+ }
198
+
199
+ // Add test filters
200
+ if (matchTest) {
201
+ args.push("--match-test", matchTest);
202
+ }
203
+
204
+ if (matchContract) {
205
+ args.push("--match-contract", matchContract);
206
+ }
207
+
208
+ // Add gas reporting
209
+ if (gasReport) {
210
+ args.push("--gas-report");
211
+ }
212
+
213
+ // CRITICAL: Add fork URL to connect to deployed Diamond
214
+ // This allows Forge tests to access the Hardhat-deployed Diamond contract
215
+ if (forkUrl) {
216
+ args.push("--fork-url", forkUrl);
217
+ }
218
+
219
+ const cmd = `forge ${args.join(" ")}`;
220
+ console.log(`\nRunning: ${picocolors.blue(cmd)}\n`);
221
+
222
+ const { stdout, stderr } = await exec(cmd, { cwd, maxBuffer: 10 * 1024 * 1024 });
223
+ console.log(stdout);
224
+ if (stderr) console.error(stderr);
225
+
226
+ return { success: true, output: stdout };
227
+ } catch (error: any) {
228
+ // Forge returns non-zero exit code when tests fail
229
+ // We still want to show the output
230
+ if (error.stdout) console.log(error.stdout);
231
+ if (error.stderr) console.error(error.stderr);
232
+
233
+ return {
234
+ success: false,
235
+ output: error.stdout || error.stderr || error.message,
236
+ };
237
+ }
238
+ }