@diamondslab/diamonds-hardhat-foundry 1.0.2 → 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/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/package.json +3 -2
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,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
|
+
}
|
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.3",
|
|
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",
|
|
@@ -35,7 +35,8 @@
|
|
|
35
35
|
"prettier": "prettier \"**/*.{js,md,json}\"",
|
|
36
36
|
"pretest": "cd ../.. && yarn build",
|
|
37
37
|
"test": "mocha --recursive \"test/**/*.ts\" --exit",
|
|
38
|
-
"build": "tsc --build .",
|
|
38
|
+
"build": "tsc --build . && yarn copy-templates",
|
|
39
|
+
"copy-templates": "mkdir -p dist/templates && cp src/templates/*.template dist/templates/",
|
|
39
40
|
"prepublishOnly": "yarn build",
|
|
40
41
|
"clean": "rimraf dist"
|
|
41
42
|
},
|