@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.
- package/CHANGELOG.md +160 -0
- package/README.md +568 -4
- package/contracts/DiamondABILoader.sol +329 -0
- package/contracts/DiamondForgeHelpers.sol +309 -85
- package/contracts/DiamondFuzzBase.sol +305 -114
- package/dist/foundry.d.ts +28 -0
- package/dist/foundry.d.ts.map +1 -1
- package/dist/foundry.js +82 -1
- package/dist/foundry.js.map +1 -1
- package/dist/framework/DeploymentManager.d.ts +10 -11
- package/dist/framework/DeploymentManager.d.ts.map +1 -1
- package/dist/framework/DeploymentManager.js +56 -45
- package/dist/framework/DeploymentManager.js.map +1 -1
- package/dist/framework/ForgeFuzzingFramework.d.ts +4 -0
- package/dist/framework/ForgeFuzzingFramework.d.ts.map +1 -1
- package/dist/framework/ForgeFuzzingFramework.js +16 -2
- package/dist/framework/ForgeFuzzingFramework.js.map +1 -1
- package/dist/framework/HelperGenerator.d.ts.map +1 -1
- package/dist/framework/HelperGenerator.js +11 -0
- package/dist/framework/HelperGenerator.js.map +1 -1
- package/dist/index.d.ts +0 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -8
- package/dist/index.js.map +1 -1
- package/dist/tasks/deploy.js +3 -2
- package/dist/tasks/deploy.js.map +1 -1
- package/dist/tasks/generate-helpers.js +6 -4
- package/dist/tasks/generate-helpers.js.map +1 -1
- package/dist/tasks/init.js +3 -2
- package/dist/tasks/init.js.map +1 -1
- package/dist/tasks/test.js +13 -2
- package/dist/tasks/test.js.map +1 -1
- package/dist/templates/DiamondDeployment.sol.template +38 -0
- package/dist/templates/ExampleFuzzTest.t.sol.template +118 -0
- package/dist/templates/ExampleIntegrationTest.t.sol.template +87 -0
- package/dist/templates/ExampleUnitTest.t.sol.template +65 -0
- package/dist/types/hardhat.d.ts +1 -1
- package/dist/types/hardhat.d.ts.map +1 -1
- package/dist/types/hardhat.js +1 -0
- package/dist/types/hardhat.js.map +1 -1
- package/dist/utils/foundry.d.ts +1 -0
- package/dist/utils/foundry.d.ts.map +1 -1
- package/dist/utils/foundry.js +3 -0
- package/dist/utils/foundry.js.map +1 -1
- package/package.json +7 -4
- package/src/foundry.ts +104 -0
- package/src/framework/DeploymentManager.ts +74 -69
- package/src/framework/ForgeFuzzingFramework.ts +23 -1
- package/src/framework/HelperGenerator.ts +13 -0
- package/src/index.ts +0 -5
- package/src/tasks/deploy.ts +3 -1
- package/src/tasks/generate-helpers.ts +6 -2
- package/src/tasks/init.ts +3 -1
- package/src/tasks/test.ts +12 -1
- package/src/templates/ExampleFuzzTest.t.sol.template +26 -17
- package/src/templates/ExampleIntegrationTest.t.sol.template +9 -1
- package/src/templates/ExampleUnitTest.t.sol.template +7 -1
- package/src/types/hardhat.ts +1 -1
- 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
|
|
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
|
|
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,
|
|
1
|
+
{"version":3,"file":"generate-helpers.js","sourceRoot":"","sources":["../../src/tasks/generate-helpers.ts"],"names":[],"mappings":";;AAAA,2CAA6C;AAE7C,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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,CAAC,CAAC;QAC9C,MAAM,SAAS,GAAG,IAAI,eAAe,CAAC,GAAG,CAAC,CAAC;QAE3C,MAAM,cAAc,GAAG,OAAO,CAAC,sBAAsB,EAAE,CAAC;QAExD,MAAM,UAAU,GAAG,MAAM,SAAS,CAAC,yBAAyB,CAC1D,WAAW,EACX,WAAW,EACX,OAAO,EACP,cAAc,CACf,CAAC;QAEF,kBAAkB;QAClB,eAAM,CAAC,OAAO,CAAC,4BAA4B,CAAC,CAAC;QAC7C,eAAM,CAAC,OAAO,CAAC,cAAc,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 { 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"]}
|
package/dist/tasks/init.js
CHANGED
|
@@ -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
|
-
|
|
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");
|
package/dist/tasks/init.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.js","sourceRoot":"","sources":["../../src/tasks/init.ts"],"names":[],"mappings":";;AAAA,2CAA6C;AAE7C,
|
|
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,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F,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"]}
|
package/dist/tasks/test.js
CHANGED
|
@@ -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
|
|
74
|
+
const framework = new ForgeFuzzingFramework(hre);
|
|
64
75
|
try {
|
|
65
76
|
const success = await framework.runTests(options);
|
|
66
77
|
if (success) {
|
package/dist/tasks/test.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test.js","sourceRoot":"","sources":["../../src/tasks/test.ts"],"names":[],"mappings":";;AAAA,2CAA6C;AAE7C,
|
|
1
|
+
{"version":3,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,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QAElD,IAAI,OAAO,EAAE;YACX,eAAM,CAAC,OAAO,CAAC,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 { 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"]}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.0;
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @title DiamondDeployment
|
|
6
|
+
* @notice Deployment data for {{DIAMOND_NAME}} on {{NETWORK_NAME}} (Chain ID: {{CHAIN_ID}})
|
|
7
|
+
* @dev Auto-generated by diamonds-hardhat-foundry
|
|
8
|
+
*
|
|
9
|
+
* Generated: {{TIMESTAMP}}
|
|
10
|
+
*/
|
|
11
|
+
library DiamondDeployment {
|
|
12
|
+
// Diamond Contract Address
|
|
13
|
+
address constant DIAMOND_ADDRESS = {{DIAMOND_ADDRESS}};
|
|
14
|
+
|
|
15
|
+
// Deployer Address
|
|
16
|
+
address constant DEPLOYER_ADDRESS = {{DEPLOYER_ADDRESS}};
|
|
17
|
+
|
|
18
|
+
// Facet Addresses
|
|
19
|
+
{{FACET_ADDRESSES}}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @notice Get the Diamond contract address
|
|
23
|
+
* @return The address of the Diamond contract
|
|
24
|
+
*/
|
|
25
|
+
function diamond() internal pure returns (address) {
|
|
26
|
+
return DIAMOND_ADDRESS;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @notice Get the deployer address
|
|
31
|
+
* @return The address that deployed the Diamond
|
|
32
|
+
*/
|
|
33
|
+
function deployer() internal pure returns (address) {
|
|
34
|
+
return DEPLOYER_ADDRESS;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
{{FACET_GETTERS}}
|
|
38
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.0;
|
|
3
|
+
|
|
4
|
+
import "forge-std/Test.sol";
|
|
5
|
+
import "forge-std/console.sol";
|
|
6
|
+
import "@diamondslab/diamonds-hardhat-foundry/contracts/DiamondFuzzBase.sol";
|
|
7
|
+
import "@diamondslab/diamonds-hardhat-foundry/contracts/DiamondForgeHelpers.sol";
|
|
8
|
+
import "../helpers/DiamondDeployment.sol";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @title ExampleFuzzTest
|
|
12
|
+
* @notice Example fuzz test for Diamond contract
|
|
13
|
+
* @dev Uses DiamondFuzzBase for common fuzz testing utilities
|
|
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
|
+
|
|
23
|
+
function setUp() public override {
|
|
24
|
+
super.setUp();
|
|
25
|
+
|
|
26
|
+
console.log("Fuzz test setup complete");
|
|
27
|
+
console.log("Diamond:", diamond);
|
|
28
|
+
console.log("Functions loaded:", diamondSelectors.length);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @notice Fuzz test with random address input
|
|
33
|
+
* @param randomAddress Fuzzed address parameter
|
|
34
|
+
*/
|
|
35
|
+
function testFuzz_AddressInput(address randomAddress) public {
|
|
36
|
+
// Filter invalid addresses
|
|
37
|
+
vm.assume(DiamondForgeHelpers.isValidTestAddress(randomAddress));
|
|
38
|
+
|
|
39
|
+
// TODO: Test your Diamond function with fuzzed address
|
|
40
|
+
// Example:
|
|
41
|
+
// bytes4 selector = bytes4(keccak256("someFunction(address)"));
|
|
42
|
+
// bytes memory data = abi.encode(randomAddress);
|
|
43
|
+
// (bool success,) = _callDiamond(selector, data);
|
|
44
|
+
// assertTrue(success);
|
|
45
|
+
|
|
46
|
+
assertTrue(true, "Replace with actual fuzz test");
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @notice Fuzz test with random amount input
|
|
51
|
+
* @param amount Fuzzed amount parameter
|
|
52
|
+
*/
|
|
53
|
+
function testFuzz_AmountInput(uint256 amount) public {
|
|
54
|
+
// Bound the amount to valid range
|
|
55
|
+
vm.assume(DiamondForgeHelpers.isValidTestAmount(amount));
|
|
56
|
+
|
|
57
|
+
// TODO: Test your Diamond function with fuzzed amount
|
|
58
|
+
// Example:
|
|
59
|
+
// bytes4 selector = bytes4(keccak256("transfer(address,uint256)"));
|
|
60
|
+
// bytes memory data = abi.encode(user1, amount);
|
|
61
|
+
// (bool success,) = _callDiamond(selector, data);
|
|
62
|
+
|
|
63
|
+
assertTrue(true, "Replace with actual fuzz test");
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* @notice Fuzz test with multiple parameters
|
|
68
|
+
* @param addr Fuzzed address
|
|
69
|
+
* @param value Fuzzed value
|
|
70
|
+
* @param data Fuzzed bytes data
|
|
71
|
+
*/
|
|
72
|
+
function testFuzz_MultipleParams(
|
|
73
|
+
address addr,
|
|
74
|
+
uint256 value,
|
|
75
|
+
bytes memory data
|
|
76
|
+
) public {
|
|
77
|
+
// Filter inputs
|
|
78
|
+
vm.assume(DiamondForgeHelpers.isValidTestAddress(addr));
|
|
79
|
+
vm.assume(DiamondForgeHelpers.isValidTestAmount(value));
|
|
80
|
+
vm.assume(data.length > 0);
|
|
81
|
+
vm.assume(data.length < 1024); // Reasonable size limit
|
|
82
|
+
|
|
83
|
+
// TODO: Test with multiple fuzzed parameters
|
|
84
|
+
|
|
85
|
+
assertTrue(true, "Replace with actual multi-param fuzz test");
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* @notice Fuzz test for failure conditions
|
|
90
|
+
* @param badValue Value that should cause revert
|
|
91
|
+
*/
|
|
92
|
+
function testFuzz_ExpectedRevert(uint256 badValue) public {
|
|
93
|
+
// Set up conditions for expected revert
|
|
94
|
+
vm.assume(badValue > type(uint128).max);
|
|
95
|
+
|
|
96
|
+
// TODO: Test that function reverts with invalid input
|
|
97
|
+
// bytes4 selector = bytes4(keccak256("someFunction(uint256)"));
|
|
98
|
+
// bytes memory data = abi.encode(badValue);
|
|
99
|
+
// _expectDiamondRevert(selector, data, bytes(""));
|
|
100
|
+
|
|
101
|
+
assertTrue(true, "Replace with actual revert fuzz test");
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* @notice Fuzz test with bounded values
|
|
106
|
+
* @param rawValue Raw fuzzed value
|
|
107
|
+
*/
|
|
108
|
+
function testFuzz_BoundedValue(uint256 rawValue) public {
|
|
109
|
+
// Bound value to specific range (e.g., 1 to 1000)
|
|
110
|
+
uint256 boundedValue = bound(rawValue, 1, 1000);
|
|
111
|
+
|
|
112
|
+
// TODO: Test with bounded value
|
|
113
|
+
assertGe(boundedValue, 1, "Value should be >= 1");
|
|
114
|
+
assertLe(boundedValue, 1000, "Value should be <= 1000");
|
|
115
|
+
|
|
116
|
+
assertTrue(true, "Replace with actual bounded fuzz test");
|
|
117
|
+
}
|
|
118
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.0;
|
|
3
|
+
|
|
4
|
+
import "forge-std/Test.sol";
|
|
5
|
+
import "forge-std/console.sol";
|
|
6
|
+
import "@diamondslab/diamonds-hardhat-foundry/contracts/DiamondForgeHelpers.sol";
|
|
7
|
+
import "@diamondslab/diamonds-hardhat-foundry/contracts/DiamondABILoader.sol";
|
|
8
|
+
import "../helpers/DiamondDeployment.sol";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @title ExampleIntegrationTest
|
|
12
|
+
* @notice Example integration test for Diamond contract
|
|
13
|
+
* @dev Tests interactions between multiple facets and Diamond functionality
|
|
14
|
+
*/
|
|
15
|
+
contract ExampleIntegrationTest is Test {
|
|
16
|
+
using DiamondForgeHelpers for address;
|
|
17
|
+
using DiamondABILoader for string;
|
|
18
|
+
|
|
19
|
+
address diamond;
|
|
20
|
+
address deployer;
|
|
21
|
+
|
|
22
|
+
// Test users
|
|
23
|
+
address user1;
|
|
24
|
+
address user2;
|
|
25
|
+
|
|
26
|
+
function setUp() public {
|
|
27
|
+
// Load Diamond deployment data
|
|
28
|
+
diamond = DiamondDeployment.diamond();
|
|
29
|
+
deployer = DiamondDeployment.deployer();
|
|
30
|
+
|
|
31
|
+
// Validate Diamond
|
|
32
|
+
DiamondForgeHelpers.assertValidDiamond(diamond);
|
|
33
|
+
|
|
34
|
+
// Set up test users
|
|
35
|
+
user1 = makeAddr("user1");
|
|
36
|
+
user2 = makeAddr("user2");
|
|
37
|
+
|
|
38
|
+
// Fund test users
|
|
39
|
+
vm.deal(user1, 100 ether);
|
|
40
|
+
vm.deal(user2, 100 ether);
|
|
41
|
+
|
|
42
|
+
console.log("Diamond:", diamond);
|
|
43
|
+
console.log("User1:", user1);
|
|
44
|
+
console.log("User2:", user2);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @notice Test multi-facet interaction workflow
|
|
49
|
+
*/
|
|
50
|
+
function test_MultiFacetWorkflow() public {
|
|
51
|
+
// TODO: Implement your multi-facet workflow test
|
|
52
|
+
// Example:
|
|
53
|
+
// 1. User1 calls function on Facet A
|
|
54
|
+
// 2. Verify state change
|
|
55
|
+
// 3. User2 calls function on Facet B
|
|
56
|
+
// 4. Verify combined state
|
|
57
|
+
|
|
58
|
+
vm.startPrank(user1);
|
|
59
|
+
// Your test logic here
|
|
60
|
+
vm.stopPrank();
|
|
61
|
+
|
|
62
|
+
assertTrue(true, "Replace with actual integration test");
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* @notice Test cross-facet state management
|
|
67
|
+
*/
|
|
68
|
+
function test_CrossFacetState() public {
|
|
69
|
+
// TODO: Test that state is properly shared/isolated between facets
|
|
70
|
+
|
|
71
|
+
assertTrue(true, "Replace with actual state test");
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* @notice Test Diamond upgrade scenario (if applicable)
|
|
76
|
+
*/
|
|
77
|
+
function test_DiamondUpgrade() public {
|
|
78
|
+
// TODO: Test facet addition/replacement/removal
|
|
79
|
+
// This requires diamondCut functionality
|
|
80
|
+
|
|
81
|
+
vm.startPrank(deployer);
|
|
82
|
+
// Your upgrade logic here
|
|
83
|
+
vm.stopPrank();
|
|
84
|
+
|
|
85
|
+
assertTrue(true, "Replace with actual upgrade test");
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.0;
|
|
3
|
+
|
|
4
|
+
import "forge-std/Test.sol";
|
|
5
|
+
import "forge-std/console.sol";
|
|
6
|
+
import "@diamondslab/diamonds-hardhat-foundry/contracts/DiamondForgeHelpers.sol";
|
|
7
|
+
import "../helpers/DiamondDeployment.sol";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @title ExampleUnitTest
|
|
11
|
+
* @notice Example unit test for Diamond contract
|
|
12
|
+
* @dev This is a template - customize for your specific Diamond implementation
|
|
13
|
+
*/
|
|
14
|
+
contract ExampleUnitTest is Test {
|
|
15
|
+
using DiamondForgeHelpers for address;
|
|
16
|
+
|
|
17
|
+
address diamond;
|
|
18
|
+
address deployer;
|
|
19
|
+
|
|
20
|
+
function setUp() public {
|
|
21
|
+
// Load Diamond deployment data
|
|
22
|
+
diamond = DiamondDeployment.diamond();
|
|
23
|
+
deployer = DiamondDeployment.deployer();
|
|
24
|
+
|
|
25
|
+
console.log("Diamond deployed at:", diamond);
|
|
26
|
+
console.log("Deployed by:", deployer);
|
|
27
|
+
|
|
28
|
+
// Validate Diamond deployment
|
|
29
|
+
DiamondForgeHelpers.assertValidDiamond(diamond);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @notice Test that Diamond was deployed successfully
|
|
34
|
+
*/
|
|
35
|
+
function test_DiamondDeployed() public view {
|
|
36
|
+
// Check that Diamond address is not zero
|
|
37
|
+
assertNotEq(diamond, address(0), "Diamond address should not be zero");
|
|
38
|
+
|
|
39
|
+
// Check that Diamond has code
|
|
40
|
+
uint256 codeSize;
|
|
41
|
+
assembly {
|
|
42
|
+
codeSize := extcodesize(diamond)
|
|
43
|
+
}
|
|
44
|
+
assertGt(codeSize, 0, "Diamond should have code deployed");
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @notice Test that deployer address is set correctly
|
|
49
|
+
*/
|
|
50
|
+
function test_DeployerSet() public view {
|
|
51
|
+
assertNotEq(deployer, address(0), "Deployer address should not be zero");
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @notice Example test - customize for your Diamond's functionality
|
|
56
|
+
*/
|
|
57
|
+
function test_ExampleFunctionality() public {
|
|
58
|
+
// TODO: Add your Diamond-specific tests here
|
|
59
|
+
// Example:
|
|
60
|
+
// MyDiamond(diamond).someFunction();
|
|
61
|
+
// assertEq(result, expectedValue);
|
|
62
|
+
|
|
63
|
+
assertTrue(true, "Replace this with actual test");
|
|
64
|
+
}
|
|
65
|
+
}
|
package/dist/types/hardhat.d.ts
CHANGED
|
@@ -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;
|
|
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"}
|
package/dist/types/hardhat.js
CHANGED
|
@@ -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
|
|
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"]}
|
package/dist/utils/foundry.d.ts
CHANGED
|
@@ -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;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,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,
|
|
1
|
+
{"version":3,"file":"foundry.d.ts","sourceRoot":"","sources":["../../src/utils/foundry.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,w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;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,GAAG,IAAI,CASjD"}
|
package/dist/utils/foundry.js
CHANGED
|
@@ -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,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;IACnD,eAAM,CAAC,IAAI,CAAC,YAAY,WAAW,EAAE,CAAC,CAAC;IAEvC,IAAI;QACF,MAAM,MAAM,GAAG,IAAA,wBAAQ,EAAC,WAAW,EAAE;YACnC,GAAG,EAAE,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE;YACjC,KAAK,EAAE,OAAO,CAAC,KAAK,IAAI,MAAM;YAC9B,QAAQ,EAAE,OAAO;SAClB,CAAC,CAAC;QAEH,OAAO,MAAM,CAAC;KACf;IAAC,OAAO,KAAU,EAAE;QACnB,eAAM,CAAC,KAAK,CAAC,yBAAyB,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QACvD,IAAI,KAAK,CAAC,MAAM;YAAE,eAAM,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAC5C,IAAI,KAAK,CAAC,MAAM;YAAE,eAAM,CAAC,KAAK,CAAC,KAAK,CAAC,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E,CAAC,CAAC;QACrD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC;KAClD;AACH,CAAC;AAzBD,oCAyBC;AAED;;GAEG;AACH,SAAgB,kBAAkB;IAChC,IAAI;QACF,IAAA,wBAAQ,EAAC,iBAAiB,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;QAC/C,OAAO,IAAI,CAAC;KACb;IAAC,MAAM;QACN,OAAO,KAAK,CAAC;KACd;AACH,CAAC;AAPD,gDAOC;AAED;;GAEG;AACH,SAAgB,iBAAiB;IAC/B,IAAI;QACF,MAAM,MAAM,GAAG,IAAA,wBAAQ,EAAC,iBAAiB,EAAE,EAAE,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"]}
|