Skip to content

Commit

Permalink
test: add diamond cut facet replace test
Browse files Browse the repository at this point in the history
Resolves: ubiquity#838
  • Loading branch information
gitcoindev committed Dec 27, 2023
1 parent a143a1f commit d48309a
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions packages/contracts/test/diamond/DiamondTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,37 @@ contract TestDiamond is DiamondTestSetup {
assertEq(IMockFacet(address(diamondCutFacet)).functionB(), 22);
}

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

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

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

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

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

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

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

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

0 comments on commit d48309a

Please sign in to comment.