@diamondslab/diamonds-hardhat-foundry 1.0.3 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/CHANGELOG.md +249 -0
  2. package/README.md +650 -4
  3. package/contracts/DiamondABILoader.sol +329 -0
  4. package/contracts/DiamondForgeHelpers.sol +309 -85
  5. package/contracts/DiamondFuzzBase.sol +322 -114
  6. package/dist/foundry.d.ts +28 -0
  7. package/dist/foundry.d.ts.map +1 -1
  8. package/dist/foundry.js +82 -1
  9. package/dist/foundry.js.map +1 -1
  10. package/dist/framework/DeploymentManager.d.ts +10 -11
  11. package/dist/framework/DeploymentManager.d.ts.map +1 -1
  12. package/dist/framework/DeploymentManager.js +56 -45
  13. package/dist/framework/DeploymentManager.js.map +1 -1
  14. package/dist/framework/ForgeFuzzingFramework.d.ts +4 -0
  15. package/dist/framework/ForgeFuzzingFramework.d.ts.map +1 -1
  16. package/dist/framework/ForgeFuzzingFramework.js +16 -2
  17. package/dist/framework/ForgeFuzzingFramework.js.map +1 -1
  18. package/dist/framework/HelperGenerator.d.ts.map +1 -1
  19. package/dist/framework/HelperGenerator.js +11 -0
  20. package/dist/framework/HelperGenerator.js.map +1 -1
  21. package/dist/index.d.ts +0 -3
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +0 -8
  24. package/dist/index.js.map +1 -1
  25. package/dist/tasks/deploy.js +11 -4
  26. package/dist/tasks/deploy.js.map +1 -1
  27. package/dist/tasks/generate-helpers.js +6 -4
  28. package/dist/tasks/generate-helpers.js.map +1 -1
  29. package/dist/tasks/init.js +3 -2
  30. package/dist/tasks/init.js.map +1 -1
  31. package/dist/tasks/test.js +13 -2
  32. package/dist/tasks/test.js.map +1 -1
  33. package/dist/types/hardhat.d.ts +1 -1
  34. package/dist/types/hardhat.d.ts.map +1 -1
  35. package/dist/types/hardhat.js +1 -0
  36. package/dist/types/hardhat.js.map +1 -1
  37. package/dist/utils/foundry.d.ts +1 -0
  38. package/dist/utils/foundry.d.ts.map +1 -1
  39. package/dist/utils/foundry.js +3 -0
  40. package/dist/utils/foundry.js.map +1 -1
  41. package/package.json +5 -3
  42. package/src/foundry.ts +104 -0
  43. package/src/framework/DeploymentManager.ts +74 -69
  44. package/src/framework/ForgeFuzzingFramework.ts +23 -1
  45. package/src/framework/HelperGenerator.ts +13 -0
  46. package/src/index.ts +0 -5
  47. package/src/tasks/deploy.ts +14 -3
  48. package/src/tasks/generate-helpers.ts +6 -2
  49. package/src/tasks/init.ts +3 -1
  50. package/src/tasks/test.ts +12 -1
  51. package/src/templates/ExampleFuzzTest.t.sol.template +26 -17
  52. package/src/templates/ExampleIntegrationTest.t.sol.template +9 -1
  53. package/src/templates/ExampleUnitTest.t.sol.template +7 -1
  54. package/src/types/hardhat.ts +1 -1
  55. package/src/utils/foundry.ts +5 -0
  56. package/dist/templates/DiamondDeployment.sol.template +0 -38
  57. package/dist/templates/ExampleFuzzTest.t.sol.template +0 -109
  58. package/dist/templates/ExampleIntegrationTest.t.sol.template +0 -79
  59. package/dist/templates/ExampleUnitTest.t.sol.template +0 -59
@@ -1,38 +0,0 @@
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
- }
@@ -1,109 +0,0 @@
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
- }
@@ -1,79 +0,0 @@
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
- }
@@ -1,59 +0,0 @@
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
- }