@diamondslab/diamonds-hardhat-foundry 1.0.1 → 1.0.3
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 +6 -0
- package/dist/foundry.d.ts +11 -0
- package/dist/foundry.d.ts.map +1 -0
- package/dist/foundry.js +104 -0
- package/dist/foundry.js.map +1 -0
- package/dist/framework/DeploymentManager.d.ts +48 -0
- package/dist/framework/DeploymentManager.d.ts.map +1 -0
- package/dist/framework/DeploymentManager.js +145 -0
- package/dist/framework/DeploymentManager.js.map +1 -0
- package/dist/framework/ForgeFuzzingFramework.d.ts +57 -0
- package/dist/framework/ForgeFuzzingFramework.d.ts.map +1 -0
- package/dist/framework/ForgeFuzzingFramework.js +119 -0
- package/dist/framework/ForgeFuzzingFramework.js.map +1 -0
- package/dist/framework/HelperGenerator.d.ts +27 -0
- package/dist/framework/HelperGenerator.d.ts.map +1 -0
- package/dist/framework/HelperGenerator.js +195 -0
- package/dist/framework/HelperGenerator.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js.map +1 -0
- package/dist/tasks/deploy.d.ts +2 -0
- package/dist/tasks/deploy.d.ts.map +1 -0
- package/dist/tasks/deploy.js +82 -0
- package/dist/tasks/deploy.js.map +1 -0
- package/dist/tasks/generate-helpers.d.ts +2 -0
- package/dist/tasks/generate-helpers.d.ts.map +1 -0
- package/dist/tasks/generate-helpers.js +66 -0
- package/dist/tasks/generate-helpers.js.map +1 -0
- package/dist/tasks/init.d.ts +2 -0
- package/dist/tasks/init.d.ts.map +1 -0
- package/dist/tasks/init.js +78 -0
- package/dist/tasks/init.js.map +1 -0
- package/dist/tasks/test.d.ts +2 -0
- package/dist/tasks/test.d.ts.map +1 -0
- package/dist/tasks/test.js +83 -0
- package/dist/tasks/test.js.map +1 -0
- package/dist/templates/DiamondDeployment.sol.template +38 -0
- package/dist/templates/ExampleFuzzTest.t.sol.template +109 -0
- package/dist/templates/ExampleIntegrationTest.t.sol.template +79 -0
- package/dist/templates/ExampleUnitTest.t.sol.template +59 -0
- package/dist/types/config.d.ts +41 -0
- package/dist/types/config.d.ts.map +1 -0
- package/dist/types/config.js +19 -0
- package/dist/types/config.js.map +1 -0
- package/dist/types/hardhat.d.ts +21 -0
- package/dist/types/hardhat.d.ts.map +1 -0
- package/dist/types/hardhat.js +8 -0
- package/dist/types/hardhat.js.map +1 -0
- package/dist/utils/foundry.d.ts +59 -0
- package/dist/utils/foundry.d.ts.map +1 -0
- package/dist/utils/foundry.js +164 -0
- package/dist/utils/foundry.js.map +1 -0
- package/dist/utils/logger.d.ts +38 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +66 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/validation.d.ts +33 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +131 -0
- package/dist/utils/validation.js.map +1 -0
- package/package.json +4 -3
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [1.0.4] - 2025-12-16
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
- Templates from `src/templates/` are now properly copied to `dist/templates/` during build
|
|
12
|
+
- Added `copy-templates` script to ensure all `.template` files are included in the published package
|
|
13
|
+
|
|
8
14
|
## [1.0.0] - 2025-12-15
|
|
9
15
|
|
|
10
16
|
Initial public release of `@diamondslab/diamonds-hardhat-foundry`.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { NomicLabsHardhatPluginError } from "hardhat/internal/core/errors";
|
|
2
|
+
type Remappings = Record<string, string>;
|
|
3
|
+
export declare class HardhatFoundryError extends NomicLabsHardhatPluginError {
|
|
4
|
+
constructor(message: string, parent?: Error);
|
|
5
|
+
}
|
|
6
|
+
export declare function getForgeConfig(): any;
|
|
7
|
+
export declare function parseRemappings(remappingsTxt: string): Remappings;
|
|
8
|
+
export declare function getRemappings(): Promise<Remappings>;
|
|
9
|
+
export declare function installDependency(dependency: string): Promise<void>;
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=foundry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"foundry.d.ts","sourceRoot":"","sources":["../src/foundry.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,2BAA2B,EAAE,MAAM,8BAA8B,CAAC;AAM3E,KAAK,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAIzC,qBAAa,mBAAoB,SAAQ,2BAA2B;gBACtD,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,KAAK;CAG5C;AAcD,wBAAgB,cAAc,QAE7B;AAED,wBAAgB,eAAe,CAAC,aAAa,EAAE,MAAM,GAAG,UAAU,CA+BjE;AAED,wBAAsB,aAAa,wBAOlC;AAED,wBAAsB,iBAAiB,CAAC,UAAU,EAAE,MAAM,iBAgBzD"}
|
package/dist/foundry.js
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.installDependency = exports.getRemappings = exports.parseRemappings = exports.getForgeConfig = exports.HardhatFoundryError = void 0;
|
|
7
|
+
const child_process_1 = require("child_process");
|
|
8
|
+
const errors_1 = require("hardhat/internal/core/errors");
|
|
9
|
+
const picocolors_1 = __importDefault(require("picocolors"));
|
|
10
|
+
const util_1 = require("util");
|
|
11
|
+
const exec = (0, util_1.promisify)(child_process_1.exec);
|
|
12
|
+
let cachedRemappings;
|
|
13
|
+
class HardhatFoundryError extends errors_1.NomicLabsHardhatPluginError {
|
|
14
|
+
constructor(message, parent) {
|
|
15
|
+
super("diamonds-hardhat-foundry", message, parent);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.HardhatFoundryError = HardhatFoundryError;
|
|
19
|
+
class ForgeInstallError extends HardhatFoundryError {
|
|
20
|
+
constructor(dependency, parent) {
|
|
21
|
+
super(`Couldn't install '${dependency}', please install it manually.
|
|
22
|
+
|
|
23
|
+
${parent.message}
|
|
24
|
+
`, parent);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function getForgeConfig() {
|
|
28
|
+
return JSON.parse(runCmdSync("forge config --json"));
|
|
29
|
+
}
|
|
30
|
+
exports.getForgeConfig = getForgeConfig;
|
|
31
|
+
function parseRemappings(remappingsTxt) {
|
|
32
|
+
const remappings = {};
|
|
33
|
+
const remappingLines = remappingsTxt.split(/\r\n|\r|\n/);
|
|
34
|
+
for (const remappingLine of remappingLines) {
|
|
35
|
+
if (remappingLine.trim() === "") {
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
if (remappingLine.includes(":")) {
|
|
39
|
+
throw new HardhatFoundryError(`Invalid remapping '${remappingLine}', remapping contexts are not allowed`);
|
|
40
|
+
}
|
|
41
|
+
if (!remappingLine.includes("=")) {
|
|
42
|
+
throw new HardhatFoundryError(`Invalid remapping '${remappingLine}', remappings without a target are not allowed`);
|
|
43
|
+
}
|
|
44
|
+
const fromTo = remappingLine.split("=");
|
|
45
|
+
// if the remapping already exists, we ignore it because the first one wins
|
|
46
|
+
if (remappings[fromTo[0]] !== undefined) {
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
remappings[fromTo[0]] = fromTo[1];
|
|
50
|
+
}
|
|
51
|
+
return remappings;
|
|
52
|
+
}
|
|
53
|
+
exports.parseRemappings = parseRemappings;
|
|
54
|
+
async function getRemappings() {
|
|
55
|
+
// Get remappings only once
|
|
56
|
+
if (cachedRemappings === undefined) {
|
|
57
|
+
cachedRemappings = runCmd("forge remappings").then(parseRemappings);
|
|
58
|
+
}
|
|
59
|
+
return cachedRemappings;
|
|
60
|
+
}
|
|
61
|
+
exports.getRemappings = getRemappings;
|
|
62
|
+
async function installDependency(dependency) {
|
|
63
|
+
// Check if --no-commit flag is supported. Best way is checking the help text
|
|
64
|
+
const helpText = await runCmd("forge install --help");
|
|
65
|
+
const useNoCommitFlag = helpText.includes("--no-commit");
|
|
66
|
+
const cmd = `forge install ${useNoCommitFlag ? "--no-commit" : ""} ${dependency}`;
|
|
67
|
+
console.log(`Running '${picocolors_1.default.blue(cmd)}'`);
|
|
68
|
+
try {
|
|
69
|
+
await exec(cmd);
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
throw new ForgeInstallError(dependency, error);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
exports.installDependency = installDependency;
|
|
76
|
+
function runCmdSync(cmd) {
|
|
77
|
+
try {
|
|
78
|
+
return (0, child_process_1.execSync)(cmd, { stdio: "pipe" }).toString();
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
const pluginError = buildForgeExecutionError(error.status, error.stderr.toString());
|
|
82
|
+
throw pluginError;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
async function runCmd(cmd) {
|
|
86
|
+
try {
|
|
87
|
+
const { stdout } = await exec(cmd);
|
|
88
|
+
return stdout;
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
throw buildForgeExecutionError(error.code, error.message);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function buildForgeExecutionError(exitCode, message) {
|
|
95
|
+
switch (exitCode) {
|
|
96
|
+
case 127:
|
|
97
|
+
return new HardhatFoundryError("Couldn't run `forge`. Please check that your foundry installation is correct.");
|
|
98
|
+
case 134:
|
|
99
|
+
return new HardhatFoundryError("Running `forge` failed. Please check that your foundry.toml file is correct.");
|
|
100
|
+
default:
|
|
101
|
+
return new HardhatFoundryError(`Unexpected error while running \`forge\`: ${message}`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=foundry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"foundry.js","sourceRoot":"","sources":["../src/foundry.ts"],"names":[],"mappings":";;;;;;AAAA,iDAA+D;AAC/D,yDAA2E;AAC3E,4DAAoC;AACpC,+BAAiC;AAEjC,MAAM,IAAI,GAAG,IAAA,gBAAS,EAAC,oBAAY,CAAC,CAAC;AAIrC,IAAI,gBAAiD,CAAC;AAEtD,MAAa,mBAAoB,SAAQ,oCAA2B;IAClE,YAAY,OAAe,EAAE,MAAc;QACzC,KAAK,CAAC,0BAA0B,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;IACrD,CAAC;CACF;AAJD,kDAIC;AAED,MAAM,iBAAkB,SAAQ,mBAAmB;IACjD,YAAY,UAAkB,EAAE,MAAa;QAC3C,KAAK,CACH,qBAAqB,UAAU;;EAEnC,MAAM,CAAC,OAAO;CACf,EACK,MAAM,CACP,CAAC;IACJ,CAAC;CACF;AAED,SAAgB,cAAc;IAC5B,OAAO,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,qBAAqB,CAAC,CAAC,CAAC;AACvD,CAAC;AAFD,wCAEC;AAED,SAAgB,eAAe,CAAC,aAAqB;IACnD,MAAM,UAAU,GAAe,EAAE,CAAC;IAClC,MAAM,cAAc,GAAG,aAAa,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;IACzD,KAAK,MAAM,aAAa,IAAI,cAAc,EAAE;QAC1C,IAAI,aAAa,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;YAC/B,SAAS;SACV;QAED,IAAI,aAAa,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;YAC/B,MAAM,IAAI,mBAAmB,CAC3B,sBAAsB,aAAa,uCAAuC,CAC3E,CAAC;SACH;QAED,IAAI,CAAC,aAAa,CAAC,QAAQ,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AAI;QACF,OAAO,IAAA,wBAAQ,EAAC,GAAG,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC;KACpD;IAAC,OAAO,KAAU,EAAE;QACnB,MAAM,WAAW,GAAG,wBAAwB,CAC1C,KAAK,CAAC,MAAM,EACZ,KAAK,CAAC,MAAM,CAAC,QAAQ,EAAE,CACxB,CAAC;QAEF,MAAM,WAAW,CAAC;KACnB;AACH,CAAC;AAED,KAAK,UAAU,MAAM,CAAC,GAAW;IAC/B,IAAI;QACF,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,CAAC;QACnC,OAAO,MAAM,CAAC;KACf;IAAC,OAAO,KAAU,EAAE;QACnB,MAAM,wBAAwB,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;KAC3D;AACH,CAAC;AAED,SAAS,wBAAwB,CAC/B,QAA4B,EAC5B,OAAe;IAEf,QAAQ,QAAQ,EAAE;QAChB,KAAK,GAAG;YACN,OAAO,IAAI,mBAAmB,CAC5B,+EAA+E,CAChF,CAAC;QACJ,KAAK,GAAG;YACN,OAAO,IAAI,mBAAmB,CAC5B,8EAA8E,CAC/E,CAAC;QACJ;YACE,OAAO,IAAI,mBAAmB,CAC5B,6CAA6C,OAAO,EAAE,CACvD,CAAC;KACL;AACH,CAAC","sourcesContent":["import { exec as execCallback, execSync } from \"child_process\";\nimport { NomicLabsHardhatPluginError } from \"hardhat/internal/core/errors\";\nimport picocolors from \"picocolors\";\nimport { promisify } from \"util\";\n\nconst exec = promisify(execCallback);\n\ntype Remappings = Record<string, string>;\n\nlet cachedRemappings: Promise<Remappings> | undefined;\n\nexport class HardhatFoundryError extends NomicLabsHardhatPluginError {\n constructor(message: string, parent?: Error) {\n super(\"diamonds-hardhat-foundry\", message, parent);\n }\n}\n\nclass ForgeInstallError extends HardhatFoundryError {\n constructor(dependency: string, parent: Error) {\n super(\n `Couldn't install '${dependency}', please install it manually.\n\n${parent.message}\n`,\n parent\n );\n }\n}\n\nexport function getForgeConfig() {\n return JSON.parse(runCmdSync(\"forge config --json\"));\n}\n\nexport function parseRemappings(remappingsTxt: string): Remappings {\n const remappings: Remappings = {};\n const remappingLines = remappingsTxt.split(/\\r\\n|\\r|\\n/);\n for (const remappingLine of remappingLines) {\n if (remappingLine.trim() === \"\") {\n continue;\n }\n\n if (remappingLine.includes(\":\")) {\n throw new HardhatFoundryError(\n `Invalid remapping '${remappingLine}', remapping contexts are not allowed`\n );\n }\n\n if (!remappingLine.includes(\"=\")) {\n throw new HardhatFoundryError(\n `Invalid remapping '${remappingLine}', remappings without a target are not allowed`\n );\n }\n\n const fromTo = remappingLine.split(\"=\");\n\n // if the remapping already exists, we ignore it because the first one wins\n if (remappings[fromTo[0]] !== undefined) {\n continue;\n }\n\n remappings[fromTo[0]] = fromTo[1];\n }\n\n return remappings;\n}\n\nexport async function getRemappings() {\n // Get remappings only once\n if (cachedRemappings === undefined) {\n cachedRemappings = runCmd(\"forge remappings\").then(parseRemappings);\n }\n\n return cachedRemappings;\n}\n\nexport async function installDependency(dependency: string) {\n // Check if --no-commit flag is supported. Best way is checking the help text\n const helpText = await runCmd(\"forge install --help\");\n const useNoCommitFlag = helpText.includes(\"--no-commit\");\n\n const cmd = `forge install ${\n useNoCommitFlag ? \"--no-commit\" : \"\"\n } ${dependency}`;\n\n console.log(`Running '${picocolors.blue(cmd)}'`);\n\n try {\n await exec(cmd);\n } catch (error: any) {\n throw new ForgeInstallError(dependency, error);\n }\n}\n\nfunction runCmdSync(cmd: string): string {\n try {\n return execSync(cmd, { stdio: \"pipe\" }).toString();\n } catch (error: any) {\n const pluginError = buildForgeExecutionError(\n error.status,\n error.stderr.toString()\n );\n\n throw pluginError;\n }\n}\n\nasync function runCmd(cmd: string): Promise<string> {\n try {\n const { stdout } = await exec(cmd);\n return stdout;\n } catch (error: any) {\n throw buildForgeExecutionError(error.code, error.message);\n }\n}\n\nfunction buildForgeExecutionError(\n exitCode: number | undefined,\n message: string\n) {\n switch (exitCode) {\n case 127:\n return new HardhatFoundryError(\n \"Couldn't run `forge`. Please check that your foundry installation is correct.\"\n );\n case 134:\n return new HardhatFoundryError(\n \"Running `forge` failed. Please check that your foundry.toml file is correct.\"\n );\n default:\n return new HardhatFoundryError(\n `Unexpected error while running \\`forge\\`: ${message}`\n );\n }\n}\n"]}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Diamond } from "@diamondslab/diamonds";
|
|
2
|
+
import { HardhatRuntimeEnvironment } from "hardhat/types";
|
|
3
|
+
/**
|
|
4
|
+
* DeploymentManager - Manages Diamond deployment lifecycle for Forge testing
|
|
5
|
+
*
|
|
6
|
+
* Note: This class dynamically requires LocalDiamondDeployer from the workspace
|
|
7
|
+
* to avoid module resolution issues in the published package.
|
|
8
|
+
*/
|
|
9
|
+
export declare class DeploymentManager {
|
|
10
|
+
private hre;
|
|
11
|
+
constructor(hre: HardhatRuntimeEnvironment);
|
|
12
|
+
/**
|
|
13
|
+
* Get LocalDiamondDeployer class
|
|
14
|
+
* @private
|
|
15
|
+
*/
|
|
16
|
+
private getDeployerClass;
|
|
17
|
+
/**
|
|
18
|
+
* Deploy a Diamond using LocalDiamondDeployer
|
|
19
|
+
* @param diamondName - Name of the Diamond to deploy
|
|
20
|
+
* @param networkName - Target network (hardhat, localhost, anvil)
|
|
21
|
+
* @param force - Force redeployment even if exists
|
|
22
|
+
*/
|
|
23
|
+
deploy(diamondName?: string, networkName?: string, force?: boolean): Promise<Diamond>;
|
|
24
|
+
/**
|
|
25
|
+
* Get existing deployment record
|
|
26
|
+
* @param diamondName - Name of the Diamond
|
|
27
|
+
* @param networkName - Network name
|
|
28
|
+
* @param chainId - Chain ID
|
|
29
|
+
*/
|
|
30
|
+
getDeployment(diamondName?: string, networkName?: string, chainId?: number): Promise<Diamond | null>;
|
|
31
|
+
/**
|
|
32
|
+
* Ensure deployment exists, deploy if needed
|
|
33
|
+
* @param diamondName - Name of the Diamond
|
|
34
|
+
* @param networkName - Network name
|
|
35
|
+
* @param force - Force redeployment
|
|
36
|
+
*/
|
|
37
|
+
ensureDeployment(diamondName?: string, networkName?: string, force?: boolean): Promise<Diamond>;
|
|
38
|
+
/**
|
|
39
|
+
* Check if deployment record exists
|
|
40
|
+
* @private
|
|
41
|
+
*/
|
|
42
|
+
private hasDeploymentRecord;
|
|
43
|
+
/**
|
|
44
|
+
* Get deployment file path
|
|
45
|
+
*/
|
|
46
|
+
getDeploymentPath(diamondName: string, networkName: string, chainId: number): string;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=DeploymentManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DeploymentManager.d.ts","sourceRoot":"","sources":["../../src/framework/DeploymentManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAEhD,OAAO,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AAa1D;;;;;GAKG;AACH,qBAAa,iBAAiB;IAChB,OAAO,CAAC,GAAG;gBAAH,GAAG,EAAE,yBAAyB;IAElD;;;OAGG;YACW,gBAAgB;IAkB9B;;;;;OAKG;IACG,MAAM,CACV,WAAW,GAAE,MAAyB,EACtC,WAAW,GAAE,MAAkB,EAC/B,KAAK,GAAE,OAAe,GACrB,OAAO,CAAC,OAAO,CAAC;IAmDnB;;;;;OAKG;IACG,aAAa,CACjB,WAAW,GAAE,MAAyB,EACtC,WAAW,GAAE,MAAkB,EAC/B,OAAO,CAAC,EAAE,MAAM,GACf,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;IA2B1B;;;;;OAKG;IACG,gBAAgB,CACpB,WAAW,GAAE,MAAyB,EACtC,WAAW,GAAE,MAAkB,EAC/B,KAAK,GAAE,OAAe,GACrB,OAAO,CAAC,OAAO,CAAC;IAiBnB;;;OAGG;IACH,OAAO,CAAC,mBAAmB;IAiB3B;;OAEG;IACH,iBAAiB,CACf,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,GACd,MAAM;CAUV"}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DeploymentManager = void 0;
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const logger_1 = require("../utils/logger");
|
|
7
|
+
/**
|
|
8
|
+
* DeploymentManager - Manages Diamond deployment lifecycle for Forge testing
|
|
9
|
+
*
|
|
10
|
+
* Note: This class dynamically requires LocalDiamondDeployer from the workspace
|
|
11
|
+
* to avoid module resolution issues in the published package.
|
|
12
|
+
*/
|
|
13
|
+
class DeploymentManager {
|
|
14
|
+
hre;
|
|
15
|
+
constructor(hre) {
|
|
16
|
+
this.hre = hre;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Get LocalDiamondDeployer class
|
|
20
|
+
* @private
|
|
21
|
+
*/
|
|
22
|
+
async getDeployerClass() {
|
|
23
|
+
// LocalDiamondDeployer is in the workspace scripts, not exported from the module
|
|
24
|
+
// This will need to be available in user projects
|
|
25
|
+
const localDeployerPath = (0, path_1.join)(this.hre.config.paths.root, "scripts/setup/LocalDiamondDeployer");
|
|
26
|
+
try {
|
|
27
|
+
const deployer = await import(localDeployerPath);
|
|
28
|
+
return deployer.LocalDiamondDeployer;
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
throw new Error("LocalDiamondDeployer not found. Make sure your project has scripts/setup/LocalDiamondDeployer.ts");
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Deploy a Diamond using LocalDiamondDeployer
|
|
36
|
+
* @param diamondName - Name of the Diamond to deploy
|
|
37
|
+
* @param networkName - Target network (hardhat, localhost, anvil)
|
|
38
|
+
* @param force - Force redeployment even if exists
|
|
39
|
+
*/
|
|
40
|
+
async deploy(diamondName = "ExampleDiamond", networkName = "hardhat", force = false) {
|
|
41
|
+
logger_1.Logger.section(`Deploying ${diamondName} to ${networkName}`);
|
|
42
|
+
// Get provider and network info
|
|
43
|
+
const provider = this.hre.ethers.provider;
|
|
44
|
+
const network = await provider.getNetwork();
|
|
45
|
+
const chainId = Number(network.chainId);
|
|
46
|
+
// Check if deployment exists and handle force flag
|
|
47
|
+
if (!force && this.hasDeploymentRecord(diamondName, networkName, chainId)) {
|
|
48
|
+
logger_1.Logger.info("Deployment record exists, using existing deployment");
|
|
49
|
+
logger_1.Logger.info("Use --force to redeploy");
|
|
50
|
+
const LocalDiamondDeployer = await this.getDeployerClass();
|
|
51
|
+
const deployer = await LocalDiamondDeployer.getInstance({
|
|
52
|
+
diamondName,
|
|
53
|
+
networkName,
|
|
54
|
+
provider,
|
|
55
|
+
chainId,
|
|
56
|
+
writeDeployedDiamondData: true,
|
|
57
|
+
});
|
|
58
|
+
return await deployer.getDiamond();
|
|
59
|
+
}
|
|
60
|
+
logger_1.Logger.step("Initializing LocalDiamondDeployer...");
|
|
61
|
+
const LocalDiamondDeployer = await this.getDeployerClass();
|
|
62
|
+
const deployer = await LocalDiamondDeployer.getInstance({
|
|
63
|
+
diamondName,
|
|
64
|
+
networkName,
|
|
65
|
+
provider,
|
|
66
|
+
chainId,
|
|
67
|
+
writeDeployedDiamondData: true,
|
|
68
|
+
});
|
|
69
|
+
await deployer.setVerbose(false); // Reduce noise, use our logger instead
|
|
70
|
+
logger_1.Logger.step("Deploying Diamond contract...");
|
|
71
|
+
const diamond = await deployer.getDiamondDeployed();
|
|
72
|
+
const deployedData = diamond.getDeployedDiamondData();
|
|
73
|
+
logger_1.Logger.success(`Diamond deployed at: ${deployedData.DiamondAddress}`);
|
|
74
|
+
logger_1.Logger.info(`Deployer: ${deployedData.DeployerAddress}`);
|
|
75
|
+
logger_1.Logger.info(`Facets deployed: ${Object.keys(deployedData.DeployedFacets || {}).length}`);
|
|
76
|
+
return diamond;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Get existing deployment record
|
|
80
|
+
* @param diamondName - Name of the Diamond
|
|
81
|
+
* @param networkName - Network name
|
|
82
|
+
* @param chainId - Chain ID
|
|
83
|
+
*/
|
|
84
|
+
async getDeployment(diamondName = "ExampleDiamond", networkName = "hardhat", chainId) {
|
|
85
|
+
try {
|
|
86
|
+
const provider = this.hre.ethers.provider;
|
|
87
|
+
const network = await provider.getNetwork();
|
|
88
|
+
const actualChainId = chainId ?? Number(network.chainId);
|
|
89
|
+
if (!this.hasDeploymentRecord(diamondName, networkName, actualChainId)) {
|
|
90
|
+
logger_1.Logger.warn("No deployment record found");
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
const LocalDiamondDeployer = await this.getDeployerClass();
|
|
94
|
+
const deployer = await LocalDiamondDeployer.getInstance({
|
|
95
|
+
diamondName,
|
|
96
|
+
networkName,
|
|
97
|
+
provider,
|
|
98
|
+
chainId: actualChainId,
|
|
99
|
+
writeDeployedDiamondData: false,
|
|
100
|
+
});
|
|
101
|
+
return await deployer.getDiamond();
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
logger_1.Logger.error(`Failed to get deployment: ${error}`);
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Ensure deployment exists, deploy if needed
|
|
110
|
+
* @param diamondName - Name of the Diamond
|
|
111
|
+
* @param networkName - Network name
|
|
112
|
+
* @param force - Force redeployment
|
|
113
|
+
*/
|
|
114
|
+
async ensureDeployment(diamondName = "ExampleDiamond", networkName = "hardhat", force = false) {
|
|
115
|
+
const provider = this.hre.ethers.provider;
|
|
116
|
+
const network = await provider.getNetwork();
|
|
117
|
+
const chainId = Number(network.chainId);
|
|
118
|
+
// Check if deployment exists
|
|
119
|
+
const existing = await this.getDeployment(diamondName, networkName, chainId);
|
|
120
|
+
if (existing && !force) {
|
|
121
|
+
logger_1.Logger.info("Using existing deployment");
|
|
122
|
+
return existing;
|
|
123
|
+
}
|
|
124
|
+
// Deploy if not exists or force is true
|
|
125
|
+
return await this.deploy(diamondName, networkName, force);
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Check if deployment record exists
|
|
129
|
+
* @private
|
|
130
|
+
*/
|
|
131
|
+
hasDeploymentRecord(diamondName, networkName, chainId) {
|
|
132
|
+
const deploymentFileName = `${diamondName.toLowerCase()}-${networkName.toLowerCase()}-${chainId}.json`;
|
|
133
|
+
const deploymentPath = (0, path_1.join)(this.hre.config.paths.root, "diamonds", diamondName, "deployments", deploymentFileName);
|
|
134
|
+
return (0, fs_1.existsSync)(deploymentPath);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Get deployment file path
|
|
138
|
+
*/
|
|
139
|
+
getDeploymentPath(diamondName, networkName, chainId) {
|
|
140
|
+
const deploymentFileName = `${diamondName.toLowerCase()}-${networkName.toLowerCase()}-${chainId}.json`;
|
|
141
|
+
return (0, path_1.join)(this.hre.config.paths.root, "diamonds", diamondName, "deployments", deploymentFileName);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
exports.DeploymentManager = DeploymentManager;
|
|
145
|
+
//# sourceMappingURL=DeploymentManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DeploymentManager.js","sourceRoot":"","sources":["../../src/framework/DeploymentManager.ts"],"names":[],"mappings":";;;AACA,2BAAgC;AAEhC,+BAA4B;AAC5B,4CAAyC;AAWzC;;;;;GAKG;AACH,MAAa,iBAAiB;IACR;IAApB,YAAoB,GAA8B;QAA9B,QAAG,GAAH,GAAG,CAA2B;IAAG,CAAC;IAEtD;;;OAGG;IACK,KAAK,CAAC,gBAAgB;QAC5B,iFAAiF;QACjF,kDAAkD;QAClD,MAAM,iBAAiB,GAAG,IAAA,WAAI,EAC5B,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,EAC1B,oCA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,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,EAC1B,UAAU,EACV,WAAW,EACX,aAAa,EACb,kBAAkB,CACnB,CAAC;QAEF,OAAO,IAAA,eAAU,EAAC,cAAc,CAAC,CAAC;IACpC,CAAC;IAED;;OAEG;IACH,iBAAiB,CACf,WAAmB,EACnB,WAAmB,EACnB,OAAe;QAEf,MAAM,kBAAkB,GAAG,GAAG,WAAW,CAAC,WAAW,EAAE,IAAI,WAAW,CAAC,WAAW,EAAE,IAAI,OAAO,OAAO,CAAC;QACvG,OAAO,IAAA,WAAI,EACT,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,EAC1B,UAAU,EACV,WAAW,EACX,aAAa,EACb,kBAAkB,CACnB,CAAC;IACJ,CAAC;CACF;AA5LD,8CA4LC","sourcesContent":["import { Diamond } from \"@diamondslab/diamonds\";\nimport { existsSync } from \"fs\";\nimport { HardhatRuntimeEnvironment } from \"hardhat/types\";\nimport { join } from \"path\";\nimport { Logger } from \"../utils/logger\";\n\n// Type for LocalDiamondDeployer (avoiding import issues)\ntype LocalDiamondDeployerConfig = {\n diamondName: string;\n networkName: string;\n provider: any;\n chainId: number;\n writeDeployedDiamondData: boolean;\n};\n\n/**\n * DeploymentManager - Manages Diamond deployment lifecycle for Forge testing\n * \n * Note: This class dynamically requires LocalDiamondDeployer from the workspace\n * to avoid module resolution issues in the published package.\n */\nexport class DeploymentManager {\n constructor(private hre: HardhatRuntimeEnvironment) {}\n\n /**\n * Get LocalDiamondDeployer class\n * @private\n */\n private async getDeployerClass(): Promise<any> {\n // LocalDiamondDeployer is in the workspace scripts, not exported from the module\n // This will need to be available in user projects\n const localDeployerPath = join(\n this.hre.config.paths.root,\n \"scripts/setup/LocalDiamondDeployer\"\n );\n \n try {\n const deployer = await import(localDeployerPath);\n return deployer.LocalDiamondDeployer;\n } catch {\n throw new Error(\n \"LocalDiamondDeployer not found. Make sure your project has scripts/setup/LocalDiamondDeployer.ts\"\n );\n }\n }\n\n /**\n * Deploy a Diamond using LocalDiamondDeployer\n * @param diamondName - Name of the Diamond to deploy\n * @param networkName - Target network (hardhat, localhost, anvil)\n * @param force - Force redeployment even if exists\n */\n async deploy(\n diamondName: string = \"ExampleDiamond\",\n networkName: string = \"hardhat\",\n force: boolean = false\n ): Promise<Diamond> {\n Logger.section(`Deploying ${diamondName} to ${networkName}`);\n\n // Get provider and network info\n const provider = this.hre.ethers.provider;\n const network = await provider.getNetwork();\n const chainId = Number(network.chainId);\n\n // Check if deployment exists and handle force flag\n if (!force && this.hasDeploymentRecord(diamondName, networkName, chainId)) {\n Logger.info(\"Deployment record exists, using existing deployment\");\n Logger.info(\"Use --force to redeploy\");\n \n const LocalDiamondDeployer = await this.getDeployerClass();\n const deployer = await LocalDiamondDeployer.getInstance({\n diamondName,\n networkName,\n provider,\n chainId,\n writeDeployedDiamondData: true,\n } as LocalDiamondDeployerConfig);\n \n return await deployer.getDiamond();\n }\n\n Logger.step(\"Initializing LocalDiamondDeployer...\");\n \n const LocalDiamondDeployer = await this.getDeployerClass();\n \n const deployer = await LocalDiamondDeployer.getInstance({\n diamondName,\n networkName,\n provider,\n chainId,\n writeDeployedDiamondData: true,\n } as LocalDiamondDeployerConfig);\n\n await deployer.setVerbose(false); // Reduce noise, use our logger instead\n\n Logger.step(\"Deploying Diamond contract...\");\n const diamond = await deployer.getDiamondDeployed();\n \n const deployedData = diamond.getDeployedDiamondData();\n \n Logger.success(`Diamond deployed at: ${deployedData.DiamondAddress}`);\n Logger.info(`Deployer: ${deployedData.DeployerAddress}`);\n Logger.info(`Facets deployed: ${Object.keys(deployedData.DeployedFacets || {}).length}`);\n\n return diamond;\n }\n\n /**\n * Get existing deployment record\n * @param diamondName - Name of the Diamond\n * @param networkName - Network name\n * @param chainId - Chain ID\n */\n async getDeployment(\n diamondName: string = \"ExampleDiamond\",\n networkName: string = \"hardhat\",\n chainId?: number\n ): Promise<Diamond | null> {\n try {\n const provider = this.hre.ethers.provider;\n const network = await provider.getNetwork();\n const actualChainId = chainId ?? Number(network.chainId);\n\n if (!this.hasDeploymentRecord(diamondName, networkName, actualChainId)) {\n Logger.warn(\"No deployment record found\");\n return null;\n }\n\n const LocalDiamondDeployer = await this.getDeployerClass();\n const deployer = await LocalDiamondDeployer.getInstance({\n diamondName,\n networkName,\n provider,\n chainId: actualChainId,\n writeDeployedDiamondData: false,\n } as LocalDiamondDeployerConfig);\n\n return await deployer.getDiamond();\n } catch (error) {\n Logger.error(`Failed to get deployment: ${error}`);\n return null;\n }\n }\n\n /**\n * Ensure deployment exists, deploy if needed\n * @param diamondName - Name of the Diamond\n * @param networkName - Network name\n * @param force - Force redeployment\n */\n async ensureDeployment(\n diamondName: string = \"ExampleDiamond\",\n networkName: string = \"hardhat\",\n force: boolean = false\n ): Promise<Diamond> {\n const provider = this.hre.ethers.provider;\n const network = await provider.getNetwork();\n const chainId = Number(network.chainId);\n\n // Check if deployment exists\n const existing = await this.getDeployment(diamondName, networkName, chainId);\n \n if (existing && !force) {\n Logger.info(\"Using existing deployment\");\n return existing;\n }\n\n // Deploy if not exists or force is true\n return await this.deploy(diamondName, networkName, force);\n }\n\n /**\n * Check if deployment record exists\n * @private\n */\n private hasDeploymentRecord(\n diamondName: string,\n networkName: string,\n chainId: number\n ): boolean {\n const deploymentFileName = `${diamondName.toLowerCase()}-${networkName.toLowerCase()}-${chainId}.json`;\n const deploymentPath = join(\n this.hre.config.paths.root,\n \"diamonds\",\n diamondName,\n \"deployments\",\n deploymentFileName\n );\n\n return existsSync(deploymentPath);\n }\n\n /**\n * Get deployment file path\n */\n getDeploymentPath(\n diamondName: string,\n networkName: string,\n chainId: number\n ): string {\n const deploymentFileName = `${diamondName.toLowerCase()}-${networkName.toLowerCase()}-${chainId}.json`;\n return join(\n this.hre.config.paths.root,\n \"diamonds\",\n diamondName,\n \"deployments\",\n deploymentFileName\n );\n }\n}\n"]}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { HardhatRuntimeEnvironment } from "hardhat/types";
|
|
2
|
+
export interface ForgeTestOptions {
|
|
3
|
+
/** Name of the Diamond to deploy */
|
|
4
|
+
diamondName?: string;
|
|
5
|
+
/** Network to deploy on */
|
|
6
|
+
networkName?: string;
|
|
7
|
+
/** Force redeployment */
|
|
8
|
+
force?: boolean;
|
|
9
|
+
/** Match test pattern */
|
|
10
|
+
matchTest?: string;
|
|
11
|
+
/** Match contract pattern */
|
|
12
|
+
matchContract?: string;
|
|
13
|
+
/** Verbosity level (1-5) */
|
|
14
|
+
verbosity?: number;
|
|
15
|
+
/** Show gas report */
|
|
16
|
+
gasReport?: boolean;
|
|
17
|
+
/** Skip helper generation */
|
|
18
|
+
skipHelpers?: boolean;
|
|
19
|
+
/** Skip deployment (use existing) */
|
|
20
|
+
skipDeployment?: boolean;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* ForgeFuzzingFramework - Main orchestration class for Forge testing with Diamonds
|
|
24
|
+
*
|
|
25
|
+
* Coordinates:
|
|
26
|
+
* 1. Diamond deployment via DeploymentManager
|
|
27
|
+
* 2. Helper generation via HelperGenerator
|
|
28
|
+
* 3. Forge test execution
|
|
29
|
+
*/
|
|
30
|
+
export declare class ForgeFuzzingFramework {
|
|
31
|
+
private hre;
|
|
32
|
+
private deploymentManager;
|
|
33
|
+
private helperGenerator;
|
|
34
|
+
constructor(hre: HardhatRuntimeEnvironment);
|
|
35
|
+
/**
|
|
36
|
+
* Run complete Forge testing workflow
|
|
37
|
+
*
|
|
38
|
+
* Workflow:
|
|
39
|
+
* 1. Validate Foundry installation
|
|
40
|
+
* 2. Deploy or reuse Diamond
|
|
41
|
+
* 3. Generate Solidity helpers
|
|
42
|
+
* 4. Compile Forge contracts
|
|
43
|
+
* 5. Run Forge tests
|
|
44
|
+
*
|
|
45
|
+
* @param options - Test execution options
|
|
46
|
+
*/
|
|
47
|
+
runTests(options?: ForgeTestOptions): Promise<boolean>;
|
|
48
|
+
/**
|
|
49
|
+
* Deploy Diamond only (no testing)
|
|
50
|
+
*/
|
|
51
|
+
deployOnly(diamondName?: string, networkName?: string, force?: boolean): Promise<import("@diamondslab/diamonds").Diamond>;
|
|
52
|
+
/**
|
|
53
|
+
* Generate helpers only (no deployment or testing)
|
|
54
|
+
*/
|
|
55
|
+
generateHelpersOnly(diamondName?: string, networkName?: string): Promise<string>;
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=ForgeFuzzingFramework.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ForgeFuzzingFramework.d.ts","sourceRoot":"","sources":["../../src/framework/ForgeFuzzingFramework.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AAM1D,MAAM,WAAW,gBAAgB;IAC/B,oCAAoC;IACpC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,2BAA2B;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,yBAAyB;IACzB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,yBAAyB;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,6BAA6B;IAC7B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,4BAA4B;IAC5B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,sBAAsB;IACtB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,6BAA6B;IAC7B,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,qCAAqC;IACrC,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED;;;;;;;GAOG;AACH,qBAAa,qBAAqB;IAIpB,OAAO,CAAC,GAAG;IAHvB,OAAO,CAAC,iBAAiB,CAAoB;IAC7C,OAAO,CAAC,eAAe,CAAkB;gBAErB,GAAG,EAAE,yBAAyB;IAKlD;;;;;;;;;;;OAWG;IACG,QAAQ,CAAC,OAAO,GAAE,gBAAqB,GAAG,OAAO,CAAC,OAAO,CAAC;IA4FhE;;OAEG;IACG,UAAU,CACd,WAAW,GAAE,MAAyB,EACtC,WAAW,GAAE,MAAkB,EAC/B,KAAK,GAAE,OAAe;IASxB;;OAEG;IACG,mBAAmB,CACvB,WAAW,GAAE,MAAyB,EACtC,WAAW,GAAE,MAAkB;CAwBlC"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ForgeFuzzingFramework = void 0;
|
|
4
|
+
const foundry_1 = require("../utils/foundry");
|
|
5
|
+
const logger_1 = require("../utils/logger");
|
|
6
|
+
const DeploymentManager_1 = require("./DeploymentManager");
|
|
7
|
+
const HelperGenerator_1 = require("./HelperGenerator");
|
|
8
|
+
/**
|
|
9
|
+
* ForgeFuzzingFramework - Main orchestration class for Forge testing with Diamonds
|
|
10
|
+
*
|
|
11
|
+
* Coordinates:
|
|
12
|
+
* 1. Diamond deployment via DeploymentManager
|
|
13
|
+
* 2. Helper generation via HelperGenerator
|
|
14
|
+
* 3. Forge test execution
|
|
15
|
+
*/
|
|
16
|
+
class ForgeFuzzingFramework {
|
|
17
|
+
hre;
|
|
18
|
+
deploymentManager;
|
|
19
|
+
helperGenerator;
|
|
20
|
+
constructor(hre) {
|
|
21
|
+
this.hre = hre;
|
|
22
|
+
this.deploymentManager = new DeploymentManager_1.DeploymentManager(hre);
|
|
23
|
+
this.helperGenerator = new HelperGenerator_1.HelperGenerator(hre);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Run complete Forge testing workflow
|
|
27
|
+
*
|
|
28
|
+
* Workflow:
|
|
29
|
+
* 1. Validate Foundry installation
|
|
30
|
+
* 2. Deploy or reuse Diamond
|
|
31
|
+
* 3. Generate Solidity helpers
|
|
32
|
+
* 4. Compile Forge contracts
|
|
33
|
+
* 5. Run Forge tests
|
|
34
|
+
*
|
|
35
|
+
* @param options - Test execution options
|
|
36
|
+
*/
|
|
37
|
+
async runTests(options = {}) {
|
|
38
|
+
const { diamondName = "ExampleDiamond", networkName = "hardhat", force = false, matchTest, matchContract, verbosity = 2, gasReport = false, skipHelpers = false, skipDeployment = false, } = options;
|
|
39
|
+
logger_1.Logger.section("Forge Fuzzing Framework - Test Execution");
|
|
40
|
+
// Step 1: Validate Foundry
|
|
41
|
+
if (!(0, foundry_1.isFoundryInstalled)()) {
|
|
42
|
+
logger_1.Logger.error("Foundry is not installed. Please install it: https://book.getfoundry.sh/getting-started/installation");
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
try {
|
|
46
|
+
// Step 2: Ensure Diamond deployment
|
|
47
|
+
if (!skipDeployment) {
|
|
48
|
+
logger_1.Logger.section("Step 1/4: Ensuring Diamond Deployment");
|
|
49
|
+
await this.deploymentManager.ensureDeployment(diamondName, networkName, force);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
logger_1.Logger.info("Skipping deployment (using existing)");
|
|
53
|
+
}
|
|
54
|
+
// Step 3: Generate helpers
|
|
55
|
+
if (!skipHelpers) {
|
|
56
|
+
logger_1.Logger.section("Step 2/4: Generating Solidity Helpers");
|
|
57
|
+
const deployment = await this.deploymentManager.getDeployment(diamondName, networkName);
|
|
58
|
+
if (!deployment) {
|
|
59
|
+
logger_1.Logger.error("No deployment found. Cannot generate helpers.");
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
const provider = this.hre.ethers.provider;
|
|
63
|
+
const network = await provider.getNetwork();
|
|
64
|
+
const chainId = Number(network.chainId);
|
|
65
|
+
const deploymentData = deployment.getDeployedDiamondData();
|
|
66
|
+
await this.helperGenerator.generateDeploymentHelpers(diamondName, networkName, chainId, deploymentData);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
logger_1.Logger.info("Skipping helper generation");
|
|
70
|
+
}
|
|
71
|
+
// Step 4: Compile Forge contracts
|
|
72
|
+
logger_1.Logger.section("Step 3/4: Compiling Forge Contracts");
|
|
73
|
+
const compileResult = await (0, foundry_1.compileForge)({
|
|
74
|
+
cwd: this.hre.config.paths.root,
|
|
75
|
+
verbose: verbosity >= 3,
|
|
76
|
+
});
|
|
77
|
+
if (!compileResult.success) {
|
|
78
|
+
logger_1.Logger.error("Forge compilation failed");
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
// Step 5: Run tests
|
|
82
|
+
logger_1.Logger.section("Step 4/4: Running Forge Tests");
|
|
83
|
+
const testResult = await (0, foundry_1.runForgeTest)({
|
|
84
|
+
matchTest,
|
|
85
|
+
matchContract,
|
|
86
|
+
verbosity,
|
|
87
|
+
gasReport,
|
|
88
|
+
cwd: this.hre.config.paths.root,
|
|
89
|
+
});
|
|
90
|
+
return testResult.success;
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
logger_1.Logger.error(`Test execution failed: ${error.message}`);
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Deploy Diamond only (no testing)
|
|
99
|
+
*/
|
|
100
|
+
async deployOnly(diamondName = "ExampleDiamond", networkName = "hardhat", force = false) {
|
|
101
|
+
return await this.deploymentManager.ensureDeployment(diamondName, networkName, force);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Generate helpers only (no deployment or testing)
|
|
105
|
+
*/
|
|
106
|
+
async generateHelpersOnly(diamondName = "ExampleDiamond", networkName = "hardhat") {
|
|
107
|
+
const deployment = await this.deploymentManager.getDeployment(diamondName, networkName);
|
|
108
|
+
if (!deployment) {
|
|
109
|
+
throw new Error("No deployment found. Deploy first using deployOnly()");
|
|
110
|
+
}
|
|
111
|
+
const provider = this.hre.ethers.provider;
|
|
112
|
+
const network = await provider.getNetwork();
|
|
113
|
+
const chainId = Number(network.chainId);
|
|
114
|
+
const deploymentData = deployment.getDeployedDiamondData();
|
|
115
|
+
return await this.helperGenerator.generateDeploymentHelpers(diamondName, networkName, chainId, deploymentData);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
exports.ForgeFuzzingFramework = ForgeFuzzingFramework;
|
|
119
|
+
//# sourceMappingURL=ForgeFuzzingFramework.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ForgeFuzzingFramework.js","sourceRoot":"","sources":["../../src/framework/ForgeFuzzingFramework.ts"],"names":[],"mappings":";;;AACA,8CAAkF;AAClF,4CAAyC;AACzC,2DAAwD;AACxD,uDAAoD;AAuBpD;;;;;;;GAOG;AACH,MAAa,qBAAqB;IAIZ;IAHZ,iBAAiB,CAAoB;IACrC,eAAe,CAAkB;IAEzC,YAAoB,GAA8B;QAA9B,QAAG,GAAH,GAAG,CAA2B;QAChD,IAAI,CAAC,iBAAiB,GAAG,IAAI,qCAAiB,CAAC,GAAG,CAAC,CAAC;QACpD,IAAI,CAAC,eAAe,GAAG,IAAI,iCAAe,CAAC,GAAG,CAAC,CAAC;IAClD,CAAC;IAED;;;;;;;;;;;OAWG;IACH,KAAK,CAAC,QAAQ,CAAC,UAA4B,EAAE;QAC3C,MAAM,EACJ,WAAW,GAAG,gBAAgB,EAC9B,WAAW,GAAG,SAAS,EACvB,KAAK,GAAG,KAAK,EACb,SAAS,EACT,aAAa,EACb,SAAS,GAAG,CAAC,EACb,SAAS,GAAG,KAAK,EACjB,WAAW,GAAG,KAAK,EACnB,cAAc,GAAG,KAAK,GACvB,GAAG,OAAO,CAAC;QAEZ,eAAM,CAAC,OAAO,CAAC,0CAA0C,CAAC,CAAC;QAE3D,2BAA2B;QAC3B,IAAI,CAAC,IAAA,4BAAkB,GAAE,EAAE;YACzB,eAAM,CAAC,KAAK,CAAC,sGAAsG,CAAC,CAAC;YACrH,OAAO,KAAK,CAAC;SACd;QAED,IAAI;YACF,oCAAoC;YACpC,IAAI,CAAC,cAAc,EAAE;gBACnB,eAAM,CAAC,OAAO,CAAC,uCAAuC,CAAC,CAAC;gBACxD,MAAM,IAAI,CAAC,iBAAiB,CAAC,gBAAgB,CAC3C,WAAW,EACX,WAAW,EACX,KAAK,CAC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ACJ,CAAC;CACF;AA7JD,sDA6JC","sourcesContent":["import { HardhatRuntimeEnvironment } from \"hardhat/types\";\nimport { compileForge, isFoundryInstalled, runForgeTest } from \"../utils/foundry\";\nimport { Logger } from \"../utils/logger\";\nimport { DeploymentManager } from \"./DeploymentManager\";\nimport { HelperGenerator } from \"./HelperGenerator\";\n\nexport interface ForgeTestOptions {\n /** Name of the Diamond to deploy */\n diamondName?: string;\n /** Network to deploy on */\n networkName?: string;\n /** Force redeployment */\n force?: boolean;\n /** Match test pattern */\n matchTest?: string;\n /** Match contract pattern */\n matchContract?: string;\n /** Verbosity level (1-5) */\n verbosity?: number;\n /** Show gas report */\n gasReport?: boolean;\n /** Skip helper generation */\n skipHelpers?: boolean;\n /** Skip deployment (use existing) */\n skipDeployment?: boolean;\n}\n\n/**\n * ForgeFuzzingFramework - Main orchestration class for Forge testing with Diamonds\n * \n * Coordinates:\n * 1. Diamond deployment via DeploymentManager\n * 2. Helper generation via HelperGenerator\n * 3. Forge test execution\n */\nexport class ForgeFuzzingFramework {\n private deploymentManager: DeploymentManager;\n private helperGenerator: HelperGenerator;\n\n constructor(private hre: HardhatRuntimeEnvironment) {\n this.deploymentManager = new DeploymentManager(hre);\n this.helperGenerator = new HelperGenerator(hre);\n }\n\n /**\n * Run complete Forge testing workflow\n * \n * Workflow:\n * 1. Validate Foundry installation\n * 2. Deploy or reuse Diamond\n * 3. Generate Solidity helpers\n * 4. Compile Forge contracts\n * 5. Run Forge tests\n * \n * @param options - Test execution options\n */\n async runTests(options: ForgeTestOptions = {}): Promise<boolean> {\n const {\n diamondName = \"ExampleDiamond\",\n networkName = \"hardhat\",\n force = false,\n matchTest,\n matchContract,\n verbosity = 2,\n gasReport = false,\n skipHelpers = false,\n skipDeployment = false,\n } = options;\n\n Logger.section(\"Forge Fuzzing Framework - Test Execution\");\n\n // Step 1: Validate Foundry\n if (!isFoundryInstalled()) {\n Logger.error(\"Foundry is not installed. Please install it: https://book.getfoundry.sh/getting-started/installation\");\n return false;\n }\n\n try {\n // Step 2: Ensure Diamond deployment\n if (!skipDeployment) {\n Logger.section(\"Step 1/4: Ensuring Diamond Deployment\");\n await this.deploymentManager.ensureDeployment(\n diamondName,\n networkName,\n force\n );\n } else {\n Logger.info(\"Skipping deployment (using existing)\");\n }\n\n // Step 3: Generate helpers\n if (!skipHelpers) {\n Logger.section(\"Step 2/4: Generating Solidity Helpers\");\n const deployment = await this.deploymentManager.getDeployment(\n diamondName,\n networkName\n );\n\n if (!deployment) {\n Logger.error(\"No deployment found. Cannot generate helpers.\");\n return false;\n }\n\n const provider = this.hre.ethers.provider;\n const network = await provider.getNetwork();\n const chainId = Number(network.chainId);\n\n const deploymentData = deployment.getDeployedDiamondData();\n \n await this.helperGenerator.generateDeploymentHelpers(\n diamondName,\n networkName,\n chainId,\n deploymentData\n );\n } else {\n Logger.info(\"Skipping helper generation\");\n }\n\n // Step 4: Compile Forge contracts\n Logger.section(\"Step 3/4: Compiling Forge Contracts\");\n const compileResult = await compileForge({\n cwd: this.hre.config.paths.root,\n verbose: verbosity >= 3,\n });\n\n if (!compileResult.success) {\n Logger.error(\"Forge compilation failed\");\n return false;\n }\n\n // Step 5: Run tests\n Logger.section(\"Step 4/4: Running Forge Tests\");\n const testResult = await runForgeTest({\n matchTest,\n matchContract,\n verbosity,\n gasReport,\n cwd: this.hre.config.paths.root,\n });\n\n return testResult.success;\n } catch (error: any) {\n Logger.error(`Test execution failed: ${error.message}`);\n return false;\n }\n }\n\n /**\n * Deploy Diamond only (no testing)\n */\n async deployOnly(\n diamondName: string = \"ExampleDiamond\",\n networkName: string = \"hardhat\",\n force: boolean = false\n ) {\n return await this.deploymentManager.ensureDeployment(\n diamondName,\n networkName,\n force\n );\n }\n\n /**\n * Generate helpers only (no deployment or testing)\n */\n async generateHelpersOnly(\n diamondName: string = \"ExampleDiamond\",\n networkName: string = \"hardhat\"\n ) {\n const deployment = await this.deploymentManager.getDeployment(\n diamondName,\n networkName\n );\n\n if (!deployment) {\n throw new Error(\"No deployment found. Deploy first using deployOnly()\");\n }\n\n const provider = this.hre.ethers.provider;\n const network = await provider.getNetwork();\n const chainId = Number(network.chainId);\n\n const deploymentData = deployment.getDeployedDiamondData();\n\n return await this.helperGenerator.generateDeploymentHelpers(\n diamondName,\n networkName,\n chainId,\n deploymentData\n );\n }\n}\n\n"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { DeployedDiamondData } from "@diamondslab/diamonds";
|
|
2
|
+
import { HardhatRuntimeEnvironment } from "hardhat/types";
|
|
3
|
+
/**
|
|
4
|
+
* HelperGenerator - Generates Solidity helper files for testing
|
|
5
|
+
*/
|
|
6
|
+
export declare class HelperGenerator {
|
|
7
|
+
private hre;
|
|
8
|
+
constructor(hre: HardhatRuntimeEnvironment);
|
|
9
|
+
/**
|
|
10
|
+
* Scaffold project with initial test structure
|
|
11
|
+
*/
|
|
12
|
+
scaffoldProject(outputDir?: string): Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* Generate DiamondDeployment.sol from deployment record
|
|
15
|
+
*/
|
|
16
|
+
generateDeploymentHelpers(diamondName: string, networkName: string, chainId: number, deploymentData: DeployedDiamondData): Promise<string>;
|
|
17
|
+
/**
|
|
18
|
+
* Generate example test files
|
|
19
|
+
*/
|
|
20
|
+
generateExampleTests(): Promise<string[]>;
|
|
21
|
+
/**
|
|
22
|
+
* Generate Solidity library source from deployment data
|
|
23
|
+
* @private
|
|
24
|
+
*/
|
|
25
|
+
private generateLibrarySource;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=HelperGenerator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HelperGenerator.d.ts","sourceRoot":"","sources":["../../src/framework/HelperGenerator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,OAAO,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AAI1D;;GAEG;AACH,qBAAa,eAAe;IACd,OAAO,CAAC,GAAG;gBAAH,GAAG,EAAE,yBAAyB;IAElD;;OAEG;IACG,eAAe,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAgBxD;;OAEG;IACG,yBAAyB,CAC7B,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,EACf,cAAc,EAAE,mBAAmB,GAClC,OAAO,CAAC,MAAM,CAAC;IA6BlB;;OAEG;IACG,oBAAoB,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAuE/C;;;OAGG;IACH,OAAO,CAAC,qBAAqB;CAmG9B"}
|