Skip to content

Test/diamond cut facet#151

Merged
mudgen merged 14 commits into
Perfect-Abstractions:mainfrom
megabyte0x:test/DiamondCutFacet
Nov 3, 2025
Merged

Test/diamond cut facet#151
mudgen merged 14 commits into
Perfect-Abstractions:mainfrom
megabyte0x:test/DiamondCutFacet

Conversation

@megabyte0x

Copy link
Copy Markdown
Contributor

Tests for DiamondCutFacet, LibDiamond and DiamondLoupeFacet.

Issue: #119

@mudgen

mudgen commented Oct 30, 2025

Copy link
Copy Markdown
Contributor

@megabyte0x This pull request is very much appreciated.

One thing that is sorely need, (very very much) needed right now is tests that show gas usage for very large diamonds, for example 200 facets with 10 functions each, added to a diamond. This is especially needed for testing and seeing the gas used by the functions in DiamondLoupeFacet for the diamond gas challenge.

Is this something that can be added fairly easily to these tests?

@github-actions

github-actions Bot commented Oct 31, 2025

Copy link
Copy Markdown
Contributor

Coverage Report

Coverage

Metric Coverage Details
Lines 58% 819/1415 lines
Functions 66% 160/244 functions
Branches 40% 100/251 branches

Last updated: Mon, 03 Nov 2025 21:10:38 GMT for commit fa1cf3e

@github-actions

github-actions Bot commented Oct 31, 2025

Copy link
Copy Markdown
Contributor

Gas Report

No gas usage changes detected between main and test/DiamondCutFacet.

All functions maintain the same gas costs. ✅

Last updated: Mon, 03 Nov 2025 21:11:02 GMT for commit fa1cf3e

@megabyte0x

Copy link
Copy Markdown
Contributor Author

Is this something that can be added fairly easily to these tests?

hey @mudgen
I am not sure about the difficulty level, but I am almost done with DiamondCutFacet tests. Will keep this in consideration while testing for the LoupeFacet.

@megabyte0x

Copy link
Copy Markdown
Contributor Author

hey @mudgen

I am done with the DiamondCutFacet.sol tests with 100% coverage.
CleanShot 2025-10-31 at 17 49 30

This coverage was only achievable when I removed the following IncorrectFacetCutAction branch as its unreachable. I also mentioned the same in the discussion here.

@mudgen

mudgen commented Oct 31, 2025

Copy link
Copy Markdown
Contributor

@adamgall Do the tests look okay to you?

@mudgen mudgen requested a review from adamgall October 31, 2025 17:16
@lumoswiz

lumoswiz commented Nov 2, 2025

Copy link
Copy Markdown
Collaborator

@megabyte0x This pull request is very much appreciated.

One thing that is sorely need, (very very much) needed right now is tests that show gas usage for very large diamonds, for example 200 facets with 10 functions each, added to a diamond. This is especially needed for testing and seeing the gas used by the functions in DiamondLoupeFacet for the diamond gas challenge.

Is this something that can be added fairly easily to these tests?

See #165

Comment thread coverage.txt Outdated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove this file from the PR for now, please

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

Comment on lines +532 to +545
function test_DiamondCut_initalizeCallWithWrongCalldataReturningErrorMessage() public {
(DiamondCutFacet.FacetCut[] memory _cut,,) = _basicAction();

ERC20FacetHarnessWithFallback newFacet = new ERC20FacetHarnessWithFallback();
address _init = address(newFacet);

bytes memory _wrongCalldata = abi.encodeWithSelector(
bytes4(keccak256("initialize(string,string,uint256)")), TOKEN_NAME, TOKEN_DECIMALS, TOKEN_DECIMALS
);

vm.prank(owner);
vm.expectRevert(abi.encode("WRONG FUNCTION CALL"));
facet.diamondCut(_cut, _init, _wrongCalldata);
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm probably missing something, but can you explain what this test is testing for?

The revert comes from the ERC20FacetHarnessWithFallbackHarness (not an actual src contract), so it seems to me like this test doesn't actually hit a real contract.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is for the following condition branch when the _init address sends an error message on failed execution of the _calldata.

ERC20FacetHarnessWithFallbackHarness inherits the ERC20Facet which is being as the _init contract for testing, like in other test cases ERC20Harness is utilized.

@megabyte0x

Copy link
Copy Markdown
Contributor Author
CleanShot 2025-11-03 at 17 11 04@2x

@mudgen LibDiamond.sol is also 100% covered. Let me know if you think I should start with DiamondLoupe.sol test because its being updated right now for gas optimization.

@mudgen

mudgen commented Nov 3, 2025

Copy link
Copy Markdown
Contributor

@megabyte0x Great! Love to see this.

@adamgall is this ready for us to merge?

@megabyte0x You can work on DiamondLoupeFacet testing but some things for you to know are that some gas tests for it were merged in recently. Also, the DiamondLoupeFacet function implementations are changing, so there will probably be more aspects/conditions/code to test after the new implementations are merged in.

@mudgen

mudgen commented Nov 3, 2025

Copy link
Copy Markdown
Contributor

@megabyte0x Format check failed. Need to run forge fmt, preferably with forge version 1.4.3-stable

@megabyte0x

Copy link
Copy Markdown
Contributor Author

@megabyte0x Format check failed. Need to run forge fmt, preferably with forge version 1.4.3-stable

fixed this.

@mudgen If this PR is ready for merge as per you, then let's merge this. I'll work on the DiamondLoupeFacet when its ready. Till then I'll contribute to other issues.

@mudgen

mudgen commented Nov 3, 2025

Copy link
Copy Markdown
Contributor

@megabyte0x Great, thanks very much. Merged.

@mudgen mudgen marked this pull request as ready for review November 3, 2025 21:11
@mudgen mudgen merged commit 2f3b3b2 into Perfect-Abstractions:main Nov 3, 2025
4 checks passed
@megabyte0x megabyte0x deleted the test/DiamondCutFacet branch November 4, 2025 08:34
JackieXu pushed a commit to JackieXu/Compose that referenced this pull request Nov 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants