@diamondslab/diamonds-hardhat-foundry 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +113 -0
- package/package.json +3 -3
- package/src/tasks/deploy.ts +4 -7
- package/src/tasks/generate-helpers.ts +4 -7
- package/src/tasks/test.ts +4 -7
package/dist/index.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.HelperGenerator = exports.ForgeFuzzingFramework = exports.DeploymentManager = void 0;
|
|
21
|
+
const config_1 = require("hardhat/config");
|
|
22
|
+
require("./tasks/deploy");
|
|
23
|
+
require("./tasks/generate-helpers");
|
|
24
|
+
require("./tasks/init");
|
|
25
|
+
require("./tasks/test");
|
|
26
|
+
require("./types/hardhat");
|
|
27
|
+
const fs_1 = require("fs");
|
|
28
|
+
const task_names_1 = require("hardhat/builtin-tasks/task-names");
|
|
29
|
+
const path_1 = __importDefault(require("path"));
|
|
30
|
+
const picocolors_1 = __importDefault(require("picocolors"));
|
|
31
|
+
const foundry_1 = require("./foundry");
|
|
32
|
+
const validation_1 = require("./utils/validation");
|
|
33
|
+
// Export framework classes for programmatic use
|
|
34
|
+
var DeploymentManager_1 = require("./framework/DeploymentManager");
|
|
35
|
+
Object.defineProperty(exports, "DeploymentManager", { enumerable: true, get: function () { return DeploymentManager_1.DeploymentManager; } });
|
|
36
|
+
var ForgeFuzzingFramework_1 = require("./framework/ForgeFuzzingFramework");
|
|
37
|
+
Object.defineProperty(exports, "ForgeFuzzingFramework", { enumerable: true, get: function () { return ForgeFuzzingFramework_1.ForgeFuzzingFramework; } });
|
|
38
|
+
var HelperGenerator_1 = require("./framework/HelperGenerator");
|
|
39
|
+
Object.defineProperty(exports, "HelperGenerator", { enumerable: true, get: function () { return HelperGenerator_1.HelperGenerator; } });
|
|
40
|
+
// Export types
|
|
41
|
+
__exportStar(require("./types/config"), exports);
|
|
42
|
+
const TASK_INIT_FOUNDRY = "init-foundry";
|
|
43
|
+
let pluginActivated = false;
|
|
44
|
+
// Extend config with diamondsFoundry settings
|
|
45
|
+
(0, config_1.extendConfig)((config, userConfig) => {
|
|
46
|
+
// Validate and set diamondsFoundry config
|
|
47
|
+
config.diamondsFoundry = (0, validation_1.validateConfig)(userConfig.diamondsFoundry);
|
|
48
|
+
// Check foundry.toml presence. Don't warn when running foundry initialization task
|
|
49
|
+
if (!(0, fs_1.existsSync)(path_1.default.join(config.paths.root, "foundry.toml"))) {
|
|
50
|
+
if (!process.argv.includes(TASK_INIT_FOUNDRY)) {
|
|
51
|
+
console.log(picocolors_1.default.yellow(`Warning: You are using the diamonds-hardhat-foundry plugin but there isn't a foundry.toml file in your project. Run 'npx hardhat ${TASK_INIT_FOUNDRY}' to create one.`));
|
|
52
|
+
}
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
// Load foundry config
|
|
56
|
+
const foundryConfig = (0, foundry_1.getForgeConfig)();
|
|
57
|
+
// Ensure required keys exist
|
|
58
|
+
if (foundryConfig?.src === undefined ||
|
|
59
|
+
foundryConfig?.cache_path === undefined) {
|
|
60
|
+
throw new foundry_1.HardhatFoundryError("Couldn't find `src` or `cache_path` config keys after running `forge config --json`");
|
|
61
|
+
}
|
|
62
|
+
// Ensure foundry src path doesn't mismatch user-configured path
|
|
63
|
+
const userSourcesPath = userConfig.paths?.sources;
|
|
64
|
+
const foundrySourcesPath = foundryConfig.src;
|
|
65
|
+
if (userSourcesPath !== undefined &&
|
|
66
|
+
path_1.default.resolve(userSourcesPath) !== path_1.default.resolve(foundrySourcesPath)) {
|
|
67
|
+
throw new foundry_1.HardhatFoundryError(`User-configured sources path (${userSourcesPath}) doesn't match path configured in foundry (${foundrySourcesPath})`);
|
|
68
|
+
}
|
|
69
|
+
// Set sources path
|
|
70
|
+
config.paths.sources = path_1.default.resolve(config.paths.root, foundrySourcesPath);
|
|
71
|
+
// Change hardhat's cache path if it clashes with foundry's
|
|
72
|
+
const foundryCachePath = path_1.default.resolve(config.paths.root, foundryConfig.cache_path);
|
|
73
|
+
if (config.paths.cache === foundryCachePath) {
|
|
74
|
+
config.paths.cache = "cache_hardhat";
|
|
75
|
+
}
|
|
76
|
+
pluginActivated = true;
|
|
77
|
+
});
|
|
78
|
+
// Extend environment to add diamondsFoundry config to HRE
|
|
79
|
+
(0, config_1.extendEnvironment)((hre) => {
|
|
80
|
+
hre.diamondsFoundry = hre.config.diamondsFoundry;
|
|
81
|
+
});
|
|
82
|
+
// This task is in place to detect old hardhat-core versions
|
|
83
|
+
(0, config_1.internalTask)(task_names_1.TASK_COMPILE_TRANSFORM_IMPORT_NAME).setAction(async ({ importName, deprecationCheck, }, _hre) => {
|
|
84
|
+
// When the deprecationCheck param is passed, it means a new enough hardhat-core is being used
|
|
85
|
+
if (deprecationCheck) {
|
|
86
|
+
return importName;
|
|
87
|
+
}
|
|
88
|
+
throw new foundry_1.HardhatFoundryError("This version of diamonds-hardhat-foundry depends on hardhat version >= 2.17.2");
|
|
89
|
+
});
|
|
90
|
+
(0, config_1.internalTask)(task_names_1.TASK_COMPILE_GET_REMAPPINGS).setAction(async () => {
|
|
91
|
+
if (!pluginActivated) {
|
|
92
|
+
return {};
|
|
93
|
+
}
|
|
94
|
+
return (0, foundry_1.getRemappings)();
|
|
95
|
+
});
|
|
96
|
+
(0, config_1.task)(TASK_INIT_FOUNDRY, "Initialize foundry setup in current hardhat project", async (_, hre) => {
|
|
97
|
+
const foundryConfigPath = path_1.default.resolve(hre.config.paths.root, "foundry.toml");
|
|
98
|
+
if ((0, fs_1.existsSync)(foundryConfigPath)) {
|
|
99
|
+
console.warn(picocolors_1.default.yellow(`File foundry.toml already exists. Aborting.`));
|
|
100
|
+
process.exit(1);
|
|
101
|
+
}
|
|
102
|
+
console.log(`Creating foundry.toml file...`);
|
|
103
|
+
(0, fs_1.writeFileSync)(foundryConfigPath, [
|
|
104
|
+
`[profile.default]`,
|
|
105
|
+
`src = '${path_1.default.relative(hre.config.paths.root, hre.config.paths.sources)}'`,
|
|
106
|
+
`out = 'out'`,
|
|
107
|
+
`libs = ['node_modules', 'lib']`,
|
|
108
|
+
`test = '${path_1.default.relative(hre.config.paths.root, hre.config.paths.tests)}'`,
|
|
109
|
+
`cache_path = 'cache_forge'`,
|
|
110
|
+
].join("\n"));
|
|
111
|
+
await (0, foundry_1.installDependency)("foundry-rs/forge-std");
|
|
112
|
+
});
|
|
113
|
+
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@diamondslab/diamonds-hardhat-foundry",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Hardhat plugin that integrates Foundry testing with Diamond proxy contracts, providing deployment helpers and fuzzing support",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
"homepage": "https://github.com/diamondslab/diamonds-hardhat-foundry",
|
|
11
11
|
"author": "Am0rfu5",
|
|
12
12
|
"license": "MIT",
|
|
13
|
-
"main": "dist/
|
|
14
|
-
"types": "dist/
|
|
13
|
+
"main": "dist/index.js",
|
|
14
|
+
"types": "dist/index.d.ts",
|
|
15
15
|
"keywords": [
|
|
16
16
|
"ethereum",
|
|
17
17
|
"smart-contracts",
|
package/src/tasks/deploy.ts
CHANGED
|
@@ -12,14 +12,10 @@ import { validateFoundryInstallation } from "../utils/validation";
|
|
|
12
12
|
* - Deploys Diamond using LocalDiamondDeployer
|
|
13
13
|
* - Saves deployment record
|
|
14
14
|
* - Optionally reuses existing deployment
|
|
15
|
+
*
|
|
16
|
+
* Use Hardhat's built-in --network flag to specify the network
|
|
15
17
|
*/
|
|
16
18
|
task("diamonds-forge:deploy", "Deploy Diamond contract for Forge testing")
|
|
17
|
-
.addOptionalParam(
|
|
18
|
-
"network",
|
|
19
|
-
"Target network for deployment",
|
|
20
|
-
"hardhat",
|
|
21
|
-
types.string
|
|
22
|
-
)
|
|
23
19
|
.addOptionalParam(
|
|
24
20
|
"diamondName",
|
|
25
21
|
"Name of the Diamond to deploy",
|
|
@@ -31,7 +27,8 @@ task("diamonds-forge:deploy", "Deploy Diamond contract for Forge testing")
|
|
|
31
27
|
.setAction(async (taskArgs, hre: HardhatRuntimeEnvironment) => {
|
|
32
28
|
Logger.section("Deploying Diamond for Forge Testing");
|
|
33
29
|
|
|
34
|
-
|
|
30
|
+
// Use Hardhat's built-in network name from HRE
|
|
31
|
+
const networkName = hre.network.name;
|
|
35
32
|
const diamondName = taskArgs.diamondName;
|
|
36
33
|
const reuse = taskArgs.reuse;
|
|
37
34
|
const force = taskArgs.force;
|
|
@@ -11,6 +11,8 @@ import { Logger } from "../utils/logger";
|
|
|
11
11
|
* - Reads deployment record
|
|
12
12
|
* - Generates DiamondDeployment.sol library
|
|
13
13
|
* - Creates constants for addresses and facets
|
|
14
|
+
*
|
|
15
|
+
* Use Hardhat's built-in --network flag to specify the network
|
|
14
16
|
*/
|
|
15
17
|
task("diamonds-forge:generate-helpers", "Generate Solidity helpers from Diamond deployment")
|
|
16
18
|
.addOptionalParam(
|
|
@@ -19,12 +21,6 @@ task("diamonds-forge:generate-helpers", "Generate Solidity helpers from Diamond
|
|
|
19
21
|
"ExampleDiamond",
|
|
20
22
|
types.string
|
|
21
23
|
)
|
|
22
|
-
.addOptionalParam(
|
|
23
|
-
"network",
|
|
24
|
-
"Network where Diamond is deployed",
|
|
25
|
-
"hardhat",
|
|
26
|
-
types.string
|
|
27
|
-
)
|
|
28
24
|
.addOptionalParam(
|
|
29
25
|
"outputDir",
|
|
30
26
|
"Directory for generated helper files",
|
|
@@ -35,7 +31,8 @@ task("diamonds-forge:generate-helpers", "Generate Solidity helpers from Diamond
|
|
|
35
31
|
Logger.section("Generating Diamond Deployment Helpers");
|
|
36
32
|
|
|
37
33
|
const diamondName = taskArgs.diamondName;
|
|
38
|
-
|
|
34
|
+
// Use Hardhat's built-in network name from HRE
|
|
35
|
+
const networkName = hre.network.name;
|
|
39
36
|
const outputDir = taskArgs.outputDir || hre.diamondsFoundry.helpersDir;
|
|
40
37
|
|
|
41
38
|
Logger.info(`Diamond: ${diamondName}`);
|
package/src/tasks/test.ts
CHANGED
|
@@ -11,6 +11,8 @@ import { Logger } from "../utils/logger";
|
|
|
11
11
|
* - Generates Solidity helpers
|
|
12
12
|
* - Compiles Forge contracts
|
|
13
13
|
* - Runs forge test with specified options
|
|
14
|
+
*
|
|
15
|
+
* Use Hardhat's built-in --network flag to specify the network
|
|
14
16
|
*/
|
|
15
17
|
task("diamonds-forge:test", "Run Forge tests with Diamond deployment")
|
|
16
18
|
.addOptionalParam(
|
|
@@ -19,12 +21,6 @@ task("diamonds-forge:test", "Run Forge tests with Diamond deployment")
|
|
|
19
21
|
"ExampleDiamond",
|
|
20
22
|
types.string
|
|
21
23
|
)
|
|
22
|
-
.addOptionalParam(
|
|
23
|
-
"network",
|
|
24
|
-
"Network for deployment",
|
|
25
|
-
"hardhat",
|
|
26
|
-
types.string
|
|
27
|
-
)
|
|
28
24
|
.addOptionalParam(
|
|
29
25
|
"matchTest",
|
|
30
26
|
"Run tests matching pattern (--match-test)",
|
|
@@ -51,7 +47,8 @@ task("diamonds-forge:test", "Run Forge tests with Diamond deployment")
|
|
|
51
47
|
Logger.section("Running Forge Tests with Diamond");
|
|
52
48
|
|
|
53
49
|
const diamondName = taskArgs.diamondName;
|
|
54
|
-
|
|
50
|
+
// Use Hardhat's built-in network name from HRE
|
|
51
|
+
const networkName = hre.network.name;
|
|
55
52
|
const matchTest = taskArgs.matchTest;
|
|
56
53
|
const matchContract = taskArgs.matchContract;
|
|
57
54
|
const verbosity = taskArgs.verbosity;
|