Skip to content

Commit

Permalink
test: add testCutFacetRemoveFacetFunctions test
Browse files Browse the repository at this point in the history
Verify that diamond cut can remove facet functions.

Resolves: #838
  • Loading branch information
gitcoindev committed Dec 27, 2023
1 parent d48309a commit 216e321
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions packages/contracts/test/diamond/DiamondTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,39 @@ contract TestDiamond is DiamondTestSetup {
assertEq(IMockFacet(address(diamondCutFacet)).functionB(), 1);
}

function testCutFacetRemoveFacetFunctions() public {
FacetCut[] memory facetCut = new FacetCut[](1);
bytes4[] memory selectors = new bytes4[](2);
selectors[0] = MockFacetWithStorageWriteFunctions.functionA.selector;
selectors[1] = MockFacetWithStorageWriteFunctions.functionB.selector;

facetCut[0] = FacetCut({
facetAddress: address(writeFacet),
action: FacetCutAction.Add,
functionSelectors: selectors
});

vm.prank(owner);
diamondCutFacet.diamondCut(facetCut, address(0x0), "");

assertEq(IMockFacet(address(diamondCutFacet)).functionA(), 0);
assertEq(IMockFacet(address(diamondCutFacet)).functionB(), 1);

facetCut[0] = FacetCut({
facetAddress: address(0),
action: FacetCutAction.Remove,
functionSelectors: selectors
});

vm.prank(owner);
diamondCutFacet.diamondCut(facetCut, address(0x0), "");

vm.expectRevert("Diamond: Function does not exist");
IMockFacet(address(diamondCutFacet)).functionA();
vm.expectRevert("Diamond: Function does not exist");
IMockFacet(address(diamondCutFacet)).functionB();
}

function testSelectors_ShouldBeAssociatedWithCorrectFacet() public {
for (uint256 i; i < facetAddressList.length; i++) {
if (compareStrings(facetNames[i], "DiamondCutFacet")) {
Expand Down

0 comments on commit 216e321

Please sign in to comment.