Skip to content

Commit 8784ec1

Browse files
committed
Do not allow adding beta operators when chaosnet is not active
It does not hurt to add beta operators after deactivating chaosnet but for the consistency of events, we should require adding beta operators is possible only on the active chaosnet. This way, we are sure all beta operators actually participated in the chaosnet.
1 parent 1ad78df commit 8784ec1

2 files changed

Lines changed: 39 additions & 20 deletions

File tree

contracts/Chaosnet.sol

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,16 @@ contract Chaosnet {
3737
_;
3838
}
3939

40+
modifier onlyOnChaosnet() {
41+
require(isChaosnetActive, "Chaosnet is not active");
42+
_;
43+
}
44+
4045
/// @notice Adds beta operator to chaosnet. Can be called only by the
41-
/// chaosnet owner.
46+
/// chaosnet owner when the chaosnet is active.
4247
function addBetaOperators(address[] calldata operators)
4348
public
49+
onlyOnChaosnet
4450
onlyChaosnetOwner
4551
{
4652
for (uint256 i = 0; i < operators.length; i++) {
@@ -52,8 +58,7 @@ contract Chaosnet {
5258

5359
/// @notice Deactivates the chaosnet. Can be called only by the chaosnet
5460
/// owner. Once deactivated chaosnet can not be activated again.
55-
function deactivateChaosnet() public onlyChaosnetOwner {
56-
require(isChaosnetActive, "Chaosnet is not active");
61+
function deactivateChaosnet() public onlyOnChaosnet onlyChaosnetOwner {
5762
isChaosnetActive = false;
5863
emit ChaosnetDeactivated();
5964
}

test/sortitionPoolTest.js

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -547,24 +547,40 @@ describe("SortitionPool", () => {
547547
})
548548

549549
context("when called by the chaosnet owner", () => {
550-
let tx
550+
context("when chaosnet is not active", () => {
551+
beforeEach(async () => {
552+
await pool.connect(chaosnetOwner).deactivateChaosnet()
553+
})
551554

552-
beforeEach(async () => {
553-
tx = await pool
554-
.connect(chaosnetOwner)
555-
.addBetaOperators([alice.address, bob.address])
555+
it("should revert", async () => {
556+
await expect(
557+
pool
558+
.connect(chaosnetOwner)
559+
.addBetaOperators([alice.address, bob.address]),
560+
).to.be.revertedWith("Chaosnet is not active")
561+
})
556562
})
557563

558-
it("should set selected operators as beta operators", async () => {
559-
expect(await pool.isBetaOperator(alice.address)).to.be.true
560-
expect(await pool.isBetaOperator(bob.address)).to.be.true
561-
expect(await pool.isBetaOperator(carol.address)).to.be.false
562-
})
564+
context("when chaosnet is active", () => {
565+
let tx
566+
567+
beforeEach(async () => {
568+
tx = await pool
569+
.connect(chaosnetOwner)
570+
.addBetaOperators([alice.address, bob.address])
571+
})
563572

564-
it("should emit BetaOperatorsAdded event", async () => {
565-
await expect(tx)
566-
.to.emit(pool, "BetaOperatorsAdded")
567-
.withArgs([alice.address, bob.address])
573+
it("should set selected operators as beta operators", async () => {
574+
expect(await pool.isBetaOperator(alice.address)).to.be.true
575+
expect(await pool.isBetaOperator(bob.address)).to.be.true
576+
expect(await pool.isBetaOperator(carol.address)).to.be.false
577+
})
578+
579+
it("should emit BetaOperatorsAdded event", async () => {
580+
await expect(tx)
581+
.to.emit(pool, "BetaOperatorsAdded")
582+
.withArgs([alice.address, bob.address])
583+
})
568584
})
569585
})
570586
})
@@ -584,9 +600,7 @@ describe("SortitionPool", () => {
584600
context("when called with the new address set to zero", () => {
585601
it("should revert", async () => {
586602
await expect(
587-
pool
588-
.connect(chaosnetOwner)
589-
.transferChaosnetOwnerRole(ZERO_ADDRESS),
603+
pool.connect(chaosnetOwner).transferChaosnetOwnerRole(ZERO_ADDRESS),
590604
).to.be.revertedWith("New chaosnet owner must not be zero address")
591605
})
592606
})

0 commit comments

Comments
 (0)