From 5843ec5a26514d7350189392ca9ab3ee6ed5df5f Mon Sep 17 00:00:00 2001 From: Parv Date: Thu, 24 Feb 2022 22:31:03 +0530 Subject: [PATCH] feat: optimise- - 16% reduction in deployment costs - 0.186921347% increase in call costs --- contracts/facets/OwnershipFacet.sol | 30 +++++++++---------------- test/contracts/facets/OwnershipFacet.ts | 14 ++++++------ 2 files changed, 18 insertions(+), 26 deletions(-) diff --git a/contracts/facets/OwnershipFacet.sol b/contracts/facets/OwnershipFacet.sol index aef019f5..cdf21a20 100644 --- a/contracts/facets/OwnershipFacet.sol +++ b/contracts/facets/OwnershipFacet.sol @@ -11,7 +11,7 @@ contract OwnershipFacet is Modifiers { external onlyDiamondController { - require(newController != s.diamondController, "same diamondController"); + sameAsPreviousError(s.diamondController, newController); s.diamondController = newController; } @@ -19,7 +19,7 @@ contract OwnershipFacet is Modifiers { external onlyDiamondController { - require(forwarder != s.trustedForwarder, "same trustedForwarder"); + sameAsPreviousError(s.trustedForwarder, forwarder); s.trustedForwarder = forwarder; } @@ -27,7 +27,7 @@ contract OwnershipFacet is Modifiers { external onlyFeesController { - require(newController != s.feesController, "same feesController"); + sameAsPreviousError(s.feesController, newController); s.feesController = newController; } @@ -35,10 +35,7 @@ contract OwnershipFacet is Modifiers { external onlyDurationsController { - require( - newController != s.durationsController, - "same durationsController" - ); + sameAsPreviousError(s.durationsController, newController); s.durationsController = newController; } @@ -46,10 +43,7 @@ contract OwnershipFacet is Modifiers { external onlyMeTokenRegistryController { - require( - newController != s.meTokenRegistryController, - "same meTokenRegistryController" - ); + sameAsPreviousError(s.meTokenRegistryController, newController); s.meTokenRegistryController = newController; } @@ -57,10 +51,7 @@ contract OwnershipFacet is Modifiers { external onlyRegisterController { - require( - newController != s.registerController, - "same registerController" - ); + sameAsPreviousError(s.registerController, newController); s.registerController = newController; } @@ -68,10 +59,7 @@ contract OwnershipFacet is Modifiers { external onlyDeactivateController { - require( - newController != s.deactivateController, - "same deactivateController" - ); + sameAsPreviousError(s.deactivateController, newController); s.deactivateController = newController; } @@ -102,4 +90,8 @@ contract OwnershipFacet is Modifiers { function deactivateController() external view returns (address) { return s.deactivateController; } + + function sameAsPreviousError(address _old, address _new) internal pure { + require(_old != _new, "same"); + } } diff --git a/test/contracts/facets/OwnershipFacet.ts b/test/contracts/facets/OwnershipFacet.ts index e27bc7cc..fed85bee 100644 --- a/test/contracts/facets/OwnershipFacet.ts +++ b/test/contracts/facets/OwnershipFacet.ts @@ -72,7 +72,7 @@ const setup = async () => { ownershipFacet .connect(oldDiamondController) .setDiamondController(oldDiamondController.address) - ).to.be.revertedWith("same diamondController"); + ).to.be.revertedWith("same"); }); it("should change diamond controller", async () => { await ownershipFacet @@ -109,7 +109,7 @@ const setup = async () => { it("should revert when new forwarder is same as old", async () => { await expect( ownershipFacet.setTrustedForwarder(ethers.constants.AddressZero) - ).to.be.revertedWith("same trustedForwarder"); + ).to.be.revertedWith("same"); }); it("should be able to set new trusted forwarder", async () => { await ownershipFacet.setTrustedForwarder(forwarder.address); @@ -146,7 +146,7 @@ const setup = async () => { it("should revert when new fee controller is same as old", async () => { await expect( ownershipFacet.setFeesController(oldFeeController.address) - ).to.be.revertedWith("same feesController"); + ).to.be.revertedWith("same"); }); it("should be able to set new fee controller", async () => { await ownershipFacet.setFeesController(newFeeController.address); @@ -185,7 +185,7 @@ const setup = async () => { it("should revert when new duration controller is same as old", async () => { await expect( ownershipFacet.setDurationsController(oldDurationController.address) - ).to.be.revertedWith("same durationsController"); + ).to.be.revertedWith("same"); }); it("should be able to set new duration controller", async () => { await ownershipFacet.setDurationsController( @@ -226,7 +226,7 @@ const setup = async () => { it("should revert when new meToken registry controller is same as old", async () => { await expect( ownershipFacet.setMeTokenRegistryController(oldMTRController.address) - ).to.be.revertedWith("same meTokenRegistryController"); + ).to.be.revertedWith("same"); }); it("should be able to set new meToken registry controller", async () => { await ownershipFacet.setMeTokenRegistryController( @@ -267,7 +267,7 @@ const setup = async () => { it("should revert when new register controller is same as old", async () => { await expect( ownershipFacet.setRegisterController(oldRegisterController.address) - ).to.be.revertedWith("same registerController"); + ).to.be.revertedWith("same"); }); it("should be able to set new register controller", async () => { await ownershipFacet.setRegisterController( @@ -308,7 +308,7 @@ const setup = async () => { it("should revert when new deactivate controller is same as old", async () => { await expect( ownershipFacet.setDeactivateController(oldRegisterController.address) - ).to.be.revertedWith("same deactivateController"); + ).to.be.revertedWith("same"); }); it("should be able to set new deactivate controller", async () => { await ownershipFacet.setDeactivateController(