@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
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const config_1 = require("hardhat/config");
|
|
4
|
+
const ForgeFuzzingFramework_1 = require("../framework/ForgeFuzzingFramework");
|
|
5
|
+
const logger_1 = require("../utils/logger");
|
|
6
|
+
/**
|
|
7
|
+
* Task: diamonds-forge:test
|
|
8
|
+
*
|
|
9
|
+
* Runs Forge tests with Diamond deployment.
|
|
10
|
+
* - Ensures Diamond deployment exists
|
|
11
|
+
* - Generates Solidity helpers
|
|
12
|
+
* - Compiles Forge contracts
|
|
13
|
+
* - Runs forge test with specified options
|
|
14
|
+
*
|
|
15
|
+
* Use Hardhat's built-in --network flag to specify the network
|
|
16
|
+
*/
|
|
17
|
+
(0, config_1.task)("diamonds-forge:test", "Run Forge tests with Diamond deployment")
|
|
18
|
+
.addOptionalParam("diamondName", "Name of the Diamond to test", "ExampleDiamond", config_1.types.string)
|
|
19
|
+
.addOptionalParam("matchTest", "Run tests matching pattern (--match-test)", undefined, config_1.types.string)
|
|
20
|
+
.addOptionalParam("matchContract", "Run tests in contracts matching pattern (--match-contract)", undefined, config_1.types.string)
|
|
21
|
+
.addOptionalParam("verbosity", "Verbosity level (1-5, more v's = more verbose)", 2, config_1.types.int)
|
|
22
|
+
.addFlag("gasReport", "Show gas report")
|
|
23
|
+
.addFlag("skipDeployment", "Skip Diamond deployment step")
|
|
24
|
+
.addFlag("skipHelpers", "Skip helper generation step")
|
|
25
|
+
.addFlag("force", "Force redeployment of Diamond")
|
|
26
|
+
.setAction(async (taskArgs, hre) => {
|
|
27
|
+
logger_1.Logger.section("Running Forge Tests with Diamond");
|
|
28
|
+
const diamondName = taskArgs.diamondName;
|
|
29
|
+
// Use Hardhat's built-in network name from HRE
|
|
30
|
+
const networkName = hre.network.name;
|
|
31
|
+
const matchTest = taskArgs.matchTest;
|
|
32
|
+
const matchContract = taskArgs.matchContract;
|
|
33
|
+
const verbosity = taskArgs.verbosity;
|
|
34
|
+
const gasReport = taskArgs.gasReport;
|
|
35
|
+
const skipDeployment = taskArgs.skipDeployment;
|
|
36
|
+
const skipHelpers = taskArgs.skipHelpers;
|
|
37
|
+
const force = taskArgs.force;
|
|
38
|
+
logger_1.Logger.info(`Diamond: ${diamondName}`);
|
|
39
|
+
logger_1.Logger.info(`Network: ${networkName}`);
|
|
40
|
+
if (matchTest)
|
|
41
|
+
logger_1.Logger.info(`Match Test: ${matchTest}`);
|
|
42
|
+
if (matchContract)
|
|
43
|
+
logger_1.Logger.info(`Match Contract: ${matchContract}`);
|
|
44
|
+
if (gasReport)
|
|
45
|
+
logger_1.Logger.info("Gas Report: enabled");
|
|
46
|
+
if (skipDeployment)
|
|
47
|
+
logger_1.Logger.info("Skip Deployment: true");
|
|
48
|
+
if (skipHelpers)
|
|
49
|
+
logger_1.Logger.info("Skip Helpers: true");
|
|
50
|
+
// Create test options
|
|
51
|
+
const options = {
|
|
52
|
+
diamondName,
|
|
53
|
+
networkName,
|
|
54
|
+
force,
|
|
55
|
+
matchTest,
|
|
56
|
+
matchContract,
|
|
57
|
+
verbosity,
|
|
58
|
+
gasReport,
|
|
59
|
+
skipHelpers,
|
|
60
|
+
skipDeployment,
|
|
61
|
+
};
|
|
62
|
+
// Run tests using the framework
|
|
63
|
+
const framework = new ForgeFuzzingFramework_1.ForgeFuzzingFramework(hre);
|
|
64
|
+
try {
|
|
65
|
+
const success = await framework.runTests(options);
|
|
66
|
+
if (success) {
|
|
67
|
+
logger_1.Logger.section("Test Execution Complete");
|
|
68
|
+
logger_1.Logger.success("All tests passed!");
|
|
69
|
+
process.exitCode = 0;
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
logger_1.Logger.section("Test Execution Complete");
|
|
73
|
+
logger_1.Logger.error("Some tests failed");
|
|
74
|
+
process.exitCode = 1;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
logger_1.Logger.error(`Test execution failed: ${error.message}`);
|
|
79
|
+
process.exitCode = 1;
|
|
80
|
+
throw error;
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
//# sourceMappingURL=test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test.js","sourceRoot":"","sources":["../../src/tasks/test.ts"],"names":[],"mappings":"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","sourcesContent":["import { task, types } from \"hardhat/config\";\nimport { HardhatRuntimeEnvironment } from \"hardhat/types\";\nimport { ForgeFuzzingFramework, ForgeTestOptions } from \"../framework/ForgeFuzzingFramework\";\nimport { Logger } from \"../utils/logger\";\n\n/**\n * Task: diamonds-forge:test\n * \n * Runs Forge tests with Diamond deployment.\n * - Ensures Diamond deployment exists\n * - Generates Solidity helpers\n * - Compiles Forge contracts\n * - Runs forge test with specified options\n * \n * Use Hardhat's built-in --network flag to specify the network\n */\ntask(\"diamonds-forge:test\", \"Run Forge tests with Diamond deployment\")\n .addOptionalParam(\n \"diamondName\",\n \"Name of the Diamond to test\",\n \"ExampleDiamond\",\n types.string\n )\n .addOptionalParam(\n \"matchTest\",\n \"Run tests matching pattern (--match-test)\",\n undefined,\n types.string\n )\n .addOptionalParam(\n \"matchContract\",\n \"Run tests in contracts matching pattern (--match-contract)\",\n undefined,\n types.string\n )\n .addOptionalParam(\n \"verbosity\",\n \"Verbosity level (1-5, more v's = more verbose)\",\n 2,\n types.int\n )\n .addFlag(\"gasReport\", \"Show gas report\")\n .addFlag(\"skipDeployment\", \"Skip Diamond deployment step\")\n .addFlag(\"skipHelpers\", \"Skip helper generation step\")\n .addFlag(\"force\", \"Force redeployment of Diamond\")\n .setAction(async (taskArgs, hre: HardhatRuntimeEnvironment) => {\n Logger.section(\"Running Forge Tests with Diamond\");\n\n const diamondName = taskArgs.diamondName;\n // Use Hardhat's built-in network name from HRE\n const networkName = hre.network.name;\n const matchTest = taskArgs.matchTest;\n const matchContract = taskArgs.matchContract;\n const verbosity = taskArgs.verbosity;\n const gasReport = taskArgs.gasReport;\n const skipDeployment = taskArgs.skipDeployment;\n const skipHelpers = taskArgs.skipHelpers;\n const force = taskArgs.force;\n\n Logger.info(`Diamond: ${diamondName}`);\n Logger.info(`Network: ${networkName}`);\n \n if (matchTest) Logger.info(`Match Test: ${matchTest}`);\n if (matchContract) Logger.info(`Match Contract: ${matchContract}`);\n if (gasReport) Logger.info(\"Gas Report: enabled\");\n if (skipDeployment) Logger.info(\"Skip Deployment: true\");\n if (skipHelpers) Logger.info(\"Skip Helpers: true\");\n\n // Create test options\n const options: ForgeTestOptions = {\n diamondName,\n networkName,\n force,\n matchTest,\n matchContract,\n verbosity,\n gasReport,\n skipHelpers,\n skipDeployment,\n };\n\n // Run tests using the framework\n const framework = new ForgeFuzzingFramework(hre);\n \n try {\n const success = await framework.runTests(options);\n\n if (success) {\n Logger.section(\"Test Execution Complete\");\n Logger.success(\"All tests passed!\");\n process.exitCode = 0;\n } else {\n Logger.section(\"Test Execution Complete\");\n Logger.error(\"Some tests failed\");\n process.exitCode = 1;\n }\n\n } catch (error: any) {\n Logger.error(`Test execution failed: ${error.message}`);\n process.exitCode = 1;\n throw error;\n }\n });\n\n\n"]}
|
|
@@ -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,109 @@
|
|
|
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 "../../contracts/DiamondFuzzBase.sol";
|
|
7
|
+
import "../../helpers/DiamondDeployment.sol";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @title ExampleFuzzTest
|
|
11
|
+
* @notice Example fuzz test for Diamond contract
|
|
12
|
+
* @dev Uses DiamondFuzzBase for common fuzz testing utilities
|
|
13
|
+
*/
|
|
14
|
+
contract ExampleFuzzTest is DiamondFuzzBase {
|
|
15
|
+
function setUp() public override {
|
|
16
|
+
super.setUp();
|
|
17
|
+
|
|
18
|
+
// Load Diamond deployment
|
|
19
|
+
setDiamondAddress(DiamondDeployment.diamond());
|
|
20
|
+
|
|
21
|
+
// Register facets (customize for your Diamond)
|
|
22
|
+
// registerFacet("FacetName", DiamondDeployment.facetName());
|
|
23
|
+
|
|
24
|
+
console.log("Fuzz test setup complete");
|
|
25
|
+
console.log("Diamond:", diamond);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @notice Fuzz test with random address input
|
|
30
|
+
* @param randomAddress Fuzzed address parameter
|
|
31
|
+
*/
|
|
32
|
+
function testFuzz_AddressInput(address randomAddress) public {
|
|
33
|
+
// Filter invalid addresses
|
|
34
|
+
assumeValidAddress(randomAddress);
|
|
35
|
+
|
|
36
|
+
// TODO: Test your Diamond function with fuzzed address
|
|
37
|
+
// Example:
|
|
38
|
+
// MyDiamond(diamond).someFunction(randomAddress);
|
|
39
|
+
|
|
40
|
+
assertTrue(true, "Replace with actual fuzz test");
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @notice Fuzz test with random amount input
|
|
45
|
+
* @param amount Fuzzed amount parameter
|
|
46
|
+
*/
|
|
47
|
+
function testFuzz_AmountInput(uint256 amount) public {
|
|
48
|
+
// Bound the amount to valid range
|
|
49
|
+
assumeValidAmount(amount);
|
|
50
|
+
|
|
51
|
+
// TODO: Test your Diamond function with fuzzed amount
|
|
52
|
+
// Example:
|
|
53
|
+
// MyDiamond(diamond).transfer(user1, amount);
|
|
54
|
+
|
|
55
|
+
assertTrue(true, "Replace with actual fuzz test");
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* @notice Fuzz test with multiple parameters
|
|
60
|
+
* @param addr Fuzzed address
|
|
61
|
+
* @param value Fuzzed value
|
|
62
|
+
* @param data Fuzzed bytes data
|
|
63
|
+
*/
|
|
64
|
+
function testFuzz_MultipleParams(
|
|
65
|
+
address addr,
|
|
66
|
+
uint256 value,
|
|
67
|
+
bytes memory data
|
|
68
|
+
) public {
|
|
69
|
+
// Filter inputs
|
|
70
|
+
assumeValidAddress(addr);
|
|
71
|
+
assumeValidAmount(value);
|
|
72
|
+
vm.assume(data.length > 0);
|
|
73
|
+
vm.assume(data.length < 1024); // Reasonable size limit
|
|
74
|
+
|
|
75
|
+
// TODO: Test with multiple fuzzed parameters
|
|
76
|
+
|
|
77
|
+
assertTrue(true, "Replace with actual multi-param fuzz test");
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* @notice Fuzz test for failure conditions
|
|
82
|
+
* @param badValue Value that should cause revert
|
|
83
|
+
*/
|
|
84
|
+
function testFuzz_ExpectedRevert(uint256 badValue) public {
|
|
85
|
+
// Set up conditions for expected revert
|
|
86
|
+
vm.assume(badValue > type(uint128).max);
|
|
87
|
+
|
|
88
|
+
// TODO: Test that function reverts with invalid input
|
|
89
|
+
// expectRevertWithMessage("Invalid amount");
|
|
90
|
+
// MyDiamond(diamond).someFunction(badValue);
|
|
91
|
+
|
|
92
|
+
assertTrue(true, "Replace with actual revert fuzz test");
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* @notice Fuzz test with bounded values
|
|
97
|
+
* @param rawValue Raw fuzzed value
|
|
98
|
+
*/
|
|
99
|
+
function testFuzz_BoundedValue(uint256 rawValue) public {
|
|
100
|
+
// Bound value to specific range (e.g., 1 to 1000)
|
|
101
|
+
uint256 boundedValue = boundValue(rawValue, 1, 1000);
|
|
102
|
+
|
|
103
|
+
// TODO: Test with bounded value
|
|
104
|
+
assertGe(boundedValue, 1, "Value should be >= 1");
|
|
105
|
+
assertLe(boundedValue, 1000, "Value should be <= 1000");
|
|
106
|
+
|
|
107
|
+
assertTrue(true, "Replace with actual bounded fuzz test");
|
|
108
|
+
}
|
|
109
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
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 "../../helpers/DiamondDeployment.sol";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @title ExampleIntegrationTest
|
|
10
|
+
* @notice Example integration test for Diamond contract
|
|
11
|
+
* @dev Tests interactions between multiple facets and Diamond functionality
|
|
12
|
+
*/
|
|
13
|
+
contract ExampleIntegrationTest is Test {
|
|
14
|
+
address diamond;
|
|
15
|
+
address deployer;
|
|
16
|
+
|
|
17
|
+
// Test users
|
|
18
|
+
address user1;
|
|
19
|
+
address user2;
|
|
20
|
+
|
|
21
|
+
function setUp() public {
|
|
22
|
+
// Load Diamond deployment data
|
|
23
|
+
diamond = DiamondDeployment.diamond();
|
|
24
|
+
deployer = DiamondDeployment.deployer();
|
|
25
|
+
|
|
26
|
+
// Set up test users
|
|
27
|
+
user1 = makeAddr("user1");
|
|
28
|
+
user2 = makeAddr("user2");
|
|
29
|
+
|
|
30
|
+
// Fund test users
|
|
31
|
+
vm.deal(user1, 100 ether);
|
|
32
|
+
vm.deal(user2, 100 ether);
|
|
33
|
+
|
|
34
|
+
console.log("Diamond:", diamond);
|
|
35
|
+
console.log("User1:", user1);
|
|
36
|
+
console.log("User2:", user2);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @notice Test multi-facet interaction workflow
|
|
41
|
+
*/
|
|
42
|
+
function test_MultiFacetWorkflow() public {
|
|
43
|
+
// TODO: Implement your multi-facet workflow test
|
|
44
|
+
// Example:
|
|
45
|
+
// 1. User1 calls function on Facet A
|
|
46
|
+
// 2. Verify state change
|
|
47
|
+
// 3. User2 calls function on Facet B
|
|
48
|
+
// 4. Verify combined state
|
|
49
|
+
|
|
50
|
+
vm.startPrank(user1);
|
|
51
|
+
// Your test logic here
|
|
52
|
+
vm.stopPrank();
|
|
53
|
+
|
|
54
|
+
assertTrue(true, "Replace with actual integration test");
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* @notice Test cross-facet state management
|
|
59
|
+
*/
|
|
60
|
+
function test_CrossFacetState() public {
|
|
61
|
+
// TODO: Test that state is properly shared/isolated between facets
|
|
62
|
+
|
|
63
|
+
assertTrue(true, "Replace with actual state test");
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* @notice Test Diamond upgrade scenario (if applicable)
|
|
68
|
+
*/
|
|
69
|
+
function test_DiamondUpgrade() public {
|
|
70
|
+
// TODO: Test facet addition/replacement/removal
|
|
71
|
+
// This requires diamondCut functionality
|
|
72
|
+
|
|
73
|
+
vm.startPrank(deployer);
|
|
74
|
+
// Your upgrade logic here
|
|
75
|
+
vm.stopPrank();
|
|
76
|
+
|
|
77
|
+
assertTrue(true, "Replace with actual upgrade test");
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
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 "../../helpers/DiamondDeployment.sol";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @title ExampleUnitTest
|
|
10
|
+
* @notice Example unit test for Diamond contract
|
|
11
|
+
* @dev This is a template - customize for your specific Diamond implementation
|
|
12
|
+
*/
|
|
13
|
+
contract ExampleUnitTest is Test {
|
|
14
|
+
address diamond;
|
|
15
|
+
address deployer;
|
|
16
|
+
|
|
17
|
+
function setUp() public {
|
|
18
|
+
// Load Diamond deployment data
|
|
19
|
+
diamond = DiamondDeployment.diamond();
|
|
20
|
+
deployer = DiamondDeployment.deployer();
|
|
21
|
+
|
|
22
|
+
console.log("Diamond deployed at:", diamond);
|
|
23
|
+
console.log("Deployed by:", deployer);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @notice Test that Diamond was deployed successfully
|
|
28
|
+
*/
|
|
29
|
+
function test_DiamondDeployed() public view {
|
|
30
|
+
// Check that Diamond address is not zero
|
|
31
|
+
assertNotEq(diamond, address(0), "Diamond address should not be zero");
|
|
32
|
+
|
|
33
|
+
// Check that Diamond has code
|
|
34
|
+
uint256 codeSize;
|
|
35
|
+
assembly {
|
|
36
|
+
codeSize := extcodesize(diamond)
|
|
37
|
+
}
|
|
38
|
+
assertGt(codeSize, 0, "Diamond should have code deployed");
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @notice Test that deployer address is set correctly
|
|
43
|
+
*/
|
|
44
|
+
function test_DeployerSet() public view {
|
|
45
|
+
assertNotEq(deployer, address(0), "Deployer address should not be zero");
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @notice Example test - customize for your Diamond's functionality
|
|
50
|
+
*/
|
|
51
|
+
function test_ExampleFunctionality() public {
|
|
52
|
+
// TODO: Add your Diamond-specific tests here
|
|
53
|
+
// Example:
|
|
54
|
+
// MyDiamond(diamond).someFunction();
|
|
55
|
+
// assertEq(result, expectedValue);
|
|
56
|
+
|
|
57
|
+
assertTrue(true, "Replace this with actual test");
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration types for diamonds-hardhat-foundry plugin
|
|
3
|
+
* Will be fully implemented in Task 2.1
|
|
4
|
+
*/
|
|
5
|
+
export interface DiamondsFoundryConfig {
|
|
6
|
+
/**
|
|
7
|
+
* Output directory for generated helpers (relative to project root)
|
|
8
|
+
* @default "test/foundry/helpers"
|
|
9
|
+
*/
|
|
10
|
+
helpersDir?: string;
|
|
11
|
+
/**
|
|
12
|
+
* Whether to generate example tests on init
|
|
13
|
+
* @default true
|
|
14
|
+
*/
|
|
15
|
+
generateExamples?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Example test templates to generate
|
|
18
|
+
* @default ["unit", "integration", "fuzz"]
|
|
19
|
+
*/
|
|
20
|
+
exampleTests?: Array<"unit" | "integration" | "fuzz">;
|
|
21
|
+
/**
|
|
22
|
+
* Default network for deployments
|
|
23
|
+
* @default "hardhat"
|
|
24
|
+
*/
|
|
25
|
+
defaultNetwork?: string;
|
|
26
|
+
/**
|
|
27
|
+
* Whether to reuse existing deployment or deploy fresh
|
|
28
|
+
* @default true
|
|
29
|
+
*/
|
|
30
|
+
reuseDeployment?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Additional forge test arguments
|
|
33
|
+
* @default []
|
|
34
|
+
*/
|
|
35
|
+
forgeTestArgs?: string[];
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Default configuration values
|
|
39
|
+
*/
|
|
40
|
+
export declare const DEFAULT_CONFIG: Required<DiamondsFoundryConfig>;
|
|
41
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/types/config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,qBAAqB;IACpC;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAE3B;;;OAGG;IACH,YAAY,CAAC,EAAE,KAAK,CAAC,MAAM,GAAG,aAAa,GAAG,MAAM,CAAC,CAAC;IAEtD;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB;;;OAGG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAE1B;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;CAC1B;AAED;;GAEG;AACH,eAAO,MAAM,cAAc,EAAE,QAAQ,CAAC,qBAAqB,CAO1D,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Configuration types for diamonds-hardhat-foundry plugin
|
|
4
|
+
* Will be fully implemented in Task 2.1
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.DEFAULT_CONFIG = void 0;
|
|
8
|
+
/**
|
|
9
|
+
* Default configuration values
|
|
10
|
+
*/
|
|
11
|
+
exports.DEFAULT_CONFIG = {
|
|
12
|
+
helpersDir: "test/foundry/helpers",
|
|
13
|
+
generateExamples: true,
|
|
14
|
+
exampleTests: ["unit", "integration", "fuzz"],
|
|
15
|
+
defaultNetwork: "hardhat",
|
|
16
|
+
reuseDeployment: true,
|
|
17
|
+
forgeTestArgs: [],
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/types/config.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAwCH;;GAEG;AACU,QAAA,cAAc,GAAoC;IAC7D,UAAU,EAAE,sBAAsB;IAClC,gBAAgB,EAAE,IAAI;IACtB,YAAY,EAAE,CAAC,MAAM,EAAE,aAAa,EAAE,MAAM,CAAC;IAC7C,cAAc,EAAE,SAAS;IACzB,eAAe,EAAE,IAAI;IACrB,aAAa,EAAE,EAAE;CAClB,CAAC","sourcesContent":["/**\n * Configuration types for diamonds-hardhat-foundry plugin\n * Will be fully implemented in Task 2.1\n */\n\nexport interface DiamondsFoundryConfig {\n /**\n * Output directory for generated helpers (relative to project root)\n * @default \"test/foundry/helpers\"\n */\n helpersDir?: string;\n\n /**\n * Whether to generate example tests on init\n * @default true\n */\n generateExamples?: boolean;\n\n /**\n * Example test templates to generate\n * @default [\"unit\", \"integration\", \"fuzz\"]\n */\n exampleTests?: Array<\"unit\" | \"integration\" | \"fuzz\">;\n\n /**\n * Default network for deployments\n * @default \"hardhat\"\n */\n defaultNetwork?: string;\n\n /**\n * Whether to reuse existing deployment or deploy fresh\n * @default true\n */\n reuseDeployment?: boolean;\n\n /**\n * Additional forge test arguments\n * @default []\n */\n forgeTestArgs?: string[];\n}\n\n/**\n * Default configuration values\n */\nexport const DEFAULT_CONFIG: Required<DiamondsFoundryConfig> = {\n helpersDir: \"test/foundry/helpers\",\n generateExamples: true,\n exampleTests: [\"unit\", \"integration\", \"fuzz\"],\n defaultNetwork: \"hardhat\",\n reuseDeployment: true,\n forgeTestArgs: [],\n};\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type extensions for Hardhat Runtime Environment
|
|
3
|
+
*/
|
|
4
|
+
import "hardhat/types/config";
|
|
5
|
+
import "hardhat/types/runtime";
|
|
6
|
+
import { DiamondsFoundryConfig } from "../types/config";
|
|
7
|
+
declare module "hardhat/types/config" {
|
|
8
|
+
interface HardhatUserConfig {
|
|
9
|
+
diamondsFoundry?: Partial<DiamondsFoundryConfig>;
|
|
10
|
+
}
|
|
11
|
+
interface HardhatConfig {
|
|
12
|
+
diamondsFoundry: Required<DiamondsFoundryConfig>;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
declare module "hardhat/types/runtime" {
|
|
16
|
+
interface HardhatRuntimeEnvironment {
|
|
17
|
+
diamondsFoundry: Required<DiamondsFoundryConfig>;
|
|
18
|
+
ethers: any;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=hardhat.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hardhat.d.ts","sourceRoot":"","sources":["../../src/types/hardhat.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,sBAAsB,CAAC;AAC9B,OAAO,uBAAuB,CAAC;AAC/B,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAExD,OAAO,QAAQ,sBAAsB,CAAC;IACpC,UAAiB,iBAAiB;QAChC,eAAe,CAAC,EAAE,OAAO,CAAC,qBAAqB,CAAC,CAAC;KAClD;IAED,UAAiB,aAAa;QAC5B,eAAe,EAAE,QAAQ,CAAC,qBAAqB,CAAC,CAAC;KAClD;CACF;AAED,OAAO,QAAQ,uBAAuB,CAAC;IACrC,UAAiB,yBAAyB;QACxC,eAAe,EAAE,QAAQ,CAAC,qBAAqB,CAAC,CAAC;QACjD,MAAM,EAAE,GAAG,CAAC;KACb;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hardhat.js","sourceRoot":"","sources":["../../src/types/hardhat.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAEH,gCAA8B;AAC9B,iCAA+B","sourcesContent":["/**\n * Type extensions for Hardhat Runtime Environment\n */\n\nimport \"hardhat/types/config\";\nimport \"hardhat/types/runtime\";\nimport { DiamondsFoundryConfig } from \"../types/config\";\n\ndeclare module \"hardhat/types/config\" {\n export interface HardhatUserConfig {\n diamondsFoundry?: Partial<DiamondsFoundryConfig>;\n }\n\n export interface HardhatConfig {\n diamondsFoundry: Required<DiamondsFoundryConfig>;\n }\n}\n\ndeclare module \"hardhat/types/runtime\" {\n export interface HardhatRuntimeEnvironment {\n diamondsFoundry: Required<DiamondsFoundryConfig>;\n ethers: any; // Will be provided by @nomicfoundation/hardhat-ethers\n }\n}\n"]}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Execute a Foundry command synchronously
|
|
3
|
+
* @param command - The foundry command (e.g., "forge test")
|
|
4
|
+
* @param args - Command arguments
|
|
5
|
+
* @param options - Execution options
|
|
6
|
+
*/
|
|
7
|
+
export declare function execForgeSync(command: string, args?: string[], options?: {
|
|
8
|
+
cwd?: string;
|
|
9
|
+
stdio?: "inherit" | "pipe";
|
|
10
|
+
}): string;
|
|
11
|
+
/**
|
|
12
|
+
* Execute a Foundry command asynchronously
|
|
13
|
+
* @param command - The foundry command (e.g., "forge")
|
|
14
|
+
* @param args - Command arguments
|
|
15
|
+
* @param options - Execution options
|
|
16
|
+
*/
|
|
17
|
+
export declare function execForgeAsync(command: string, args?: string[], options?: {
|
|
18
|
+
cwd?: string;
|
|
19
|
+
verbose?: boolean;
|
|
20
|
+
}): Promise<{
|
|
21
|
+
stdout: string;
|
|
22
|
+
stderr: string;
|
|
23
|
+
exitCode: number;
|
|
24
|
+
}>;
|
|
25
|
+
/**
|
|
26
|
+
* Run forge test with specified options
|
|
27
|
+
* @param options - Test execution options
|
|
28
|
+
*/
|
|
29
|
+
export declare function runForgeTest(options: {
|
|
30
|
+
matchTest?: string;
|
|
31
|
+
matchContract?: string;
|
|
32
|
+
verbosity?: number;
|
|
33
|
+
gasReport?: boolean;
|
|
34
|
+
cwd?: string;
|
|
35
|
+
env?: Record<string, string>;
|
|
36
|
+
}): Promise<{
|
|
37
|
+
success: boolean;
|
|
38
|
+
output: string;
|
|
39
|
+
}>;
|
|
40
|
+
/**
|
|
41
|
+
* Compile Forge contracts
|
|
42
|
+
* @param options - Compilation options
|
|
43
|
+
*/
|
|
44
|
+
export declare function compileForge(options: {
|
|
45
|
+
cwd?: string;
|
|
46
|
+
verbose?: boolean;
|
|
47
|
+
}): Promise<{
|
|
48
|
+
success: boolean;
|
|
49
|
+
output: string;
|
|
50
|
+
}>;
|
|
51
|
+
/**
|
|
52
|
+
* Check if Foundry is installed
|
|
53
|
+
*/
|
|
54
|
+
export declare function isFoundryInstalled(): boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Get Foundry version
|
|
57
|
+
*/
|
|
58
|
+
export declare function getFoundryVersion(): string | null;
|
|
59
|
+
//# sourceMappingURL=foundry.d.ts.map
|
|
@@ -0,0 +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,CAsChD;AAED;;;GAGG;AACH,wBAAsB,YAAY,CAAC,OAAO,EAAE;IAC1C,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,GAAG,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CAsBhD;AAED;;GAEG;AACH,wBAAgB,kBAAkB,IAAI,OAAO,CAO5C;AAED;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,GAAG,IAAI,CASjD"}
|