Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: optimise- #123

Merged
merged 1 commit into from
Feb 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 11 additions & 19 deletions contracts/facets/OwnershipFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,67 +11,55 @@ contract OwnershipFacet is Modifiers {
external
onlyDiamondController
{
require(newController != s.diamondController, "same diamondController");
sameAsPreviousError(s.diamondController, newController);
s.diamondController = newController;
}

function setTrustedForwarder(address forwarder)
external
onlyDiamondController
{
require(forwarder != s.trustedForwarder, "same trustedForwarder");
sameAsPreviousError(s.trustedForwarder, forwarder);
s.trustedForwarder = forwarder;
}

function setFeesController(address newController)
external
onlyFeesController
{
require(newController != s.feesController, "same feesController");
sameAsPreviousError(s.feesController, newController);
s.feesController = newController;
}

function setDurationsController(address newController)
external
onlyDurationsController
{
require(
newController != s.durationsController,
"same durationsController"
);
sameAsPreviousError(s.durationsController, newController);
s.durationsController = newController;
}

function setMeTokenRegistryController(address newController)
external
onlyMeTokenRegistryController
{
require(
newController != s.meTokenRegistryController,
"same meTokenRegistryController"
);
sameAsPreviousError(s.meTokenRegistryController, newController);
s.meTokenRegistryController = newController;
}

function setRegisterController(address newController)
external
onlyRegisterController
{
require(
newController != s.registerController,
"same registerController"
);
sameAsPreviousError(s.registerController, newController);
s.registerController = newController;
}

function setDeactivateController(address newController)
external
onlyDeactivateController
{
require(
newController != s.deactivateController,
"same deactivateController"
);
sameAsPreviousError(s.deactivateController, newController);
s.deactivateController = newController;
}

Expand Down Expand Up @@ -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");
}
}
14 changes: 7 additions & 7 deletions test/contracts/facets/OwnershipFacet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down