From 216e321b94a9c53b204cb605052c68ea80b633c1 Mon Sep 17 00:00:00 2001 From: Korrrba Date: Wed, 27 Dec 2023 13:56:06 +0100 Subject: [PATCH] test: add testCutFacetRemoveFacetFunctions test Verify that diamond cut can remove facet functions. Resolves: #838 --- .../contracts/test/diamond/DiamondTest.t.sol | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/packages/contracts/test/diamond/DiamondTest.t.sol b/packages/contracts/test/diamond/DiamondTest.t.sol index 54535faf6..93b20f74c 100644 --- a/packages/contracts/test/diamond/DiamondTest.t.sol +++ b/packages/contracts/test/diamond/DiamondTest.t.sol @@ -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")) {