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

Add pauser role and user it in service config #124

Merged
merged 15 commits into from
Dec 8, 2022
19 changes: 18 additions & 1 deletion contracts/ServiceConfiguration.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ contract ServiceConfiguration is AccessControl, IServiceConfiguration {
*/
bytes32 public constant OPERATOR_ROLE = keccak256("OPERATOR_ROLE");

/**
* @dev The Pauser Role
*/
bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");

/**
* @dev Whether the protocol is paused.
*/
Expand Down Expand Up @@ -74,6 +79,7 @@ contract ServiceConfiguration is AccessControl, IServiceConfiguration {
* owners.
*/
constructor() {
_setupRole(DEFAULT_ADMIN_ROLE, msg.sender);
// Grant the contract deployer the Operator role
_setupRole(OPERATOR_ROLE, msg.sender);
Copy link
Contributor

@ams9198 ams9198 Dec 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think it's worth deferring this, and letting the Admin grant the OPERATOR role in a separate transaction?

}
Expand All @@ -89,6 +95,17 @@ contract ServiceConfiguration is AccessControl, IServiceConfiguration {
_;
}

/**
* @dev Require the caller be the pauser
*/
modifier onlyPauser() {
require(
hasRole(PAUSER_ROLE, msg.sender),
"ServiceConfiguration: caller is not a pauser"
);
_;
}

/**
* @dev Set a liquidity asset as valid or not.
*/
Expand All @@ -104,7 +121,7 @@ contract ServiceConfiguration is AccessControl, IServiceConfiguration {
/**
* @dev Pause/unpause the protocol.
*/
function setPaused(bool paused_) public onlyOperator {
function setPaused(bool paused_) public onlyPauser {
paused = paused_;
emit ProtocolPaused(paused);
}
Expand Down
19 changes: 12 additions & 7 deletions test/ServiceConfiguration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ import { deployServiceConfiguration } from "./support/serviceconfiguration";

describe("ServiceConfiguration", () => {
async function deployFixture() {
const [operator, otherAccount] = await ethers.getSigners();
const [operator, pauser, otherAccount] = await ethers.getSigners();

const { serviceConfiguration } = await deployServiceConfiguration();
const { serviceConfiguration } = await deployServiceConfiguration(
operator,
pauser
);

return {
operator,
pauser,
otherAccount,
serviceConfiguration
};
Expand All @@ -29,18 +33,19 @@ describe("ServiceConfiguration", () => {
});

describe("setPaused", () => {
it("can only be called by the operator", async () => {
const { serviceConfiguration, operator, otherAccount } =
await loadFixture(deployFixture);
it("can only be called by the pauser", async () => {
const { serviceConfiguration, pauser, otherAccount } = await loadFixture(
deployFixture
);

expect(await serviceConfiguration.paused()).to.equal(false);
const tx = serviceConfiguration.connect(operator).setPaused(true);
const tx = serviceConfiguration.connect(pauser).setPaused(true);
await expect(tx).not.to.be.reverted;
expect(await serviceConfiguration.paused()).to.equal(true);

const tx2 = serviceConfiguration.connect(otherAccount).setPaused(true);
await expect(tx2).to.be.revertedWith(
"ServiceConfiguration: caller is not an operator"
"ServiceConfiguration: caller is not a pauser"
);
});
});
Expand Down
10 changes: 9 additions & 1 deletion test/support/serviceconfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,22 @@ import { deployToSAcceptanceRegistry } from "./tosacceptanceregistry";
/**
* Deploy ServiceConfiguration
*/
export async function deployServiceConfiguration(operator?: any) {
export async function deployServiceConfiguration(operator?: any, pauser?: any) {
const ServiceConfiguration = await ethers.getContractFactory(
"ServiceConfiguration",
operator
);
const serviceConfiguration = await ServiceConfiguration.deploy();
await serviceConfiguration.deployed();

if (pauser) {
const tx = await serviceConfiguration.grantRole(
await serviceConfiguration.PAUSER_ROLE(),
pauser.address
);
await tx.wait();
}

return {
serviceConfiguration
};
Expand Down