Skip to content

Commit

Permalink
Do not allow adding beta operators when chaosnet is not active
Browse files Browse the repository at this point in the history
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.
Rate limit · GitHub

Access has been restricted

You have triggered a rate limit.

Please wait a few minutes before you try again;
in some cases this may take up to an hour.

pdyraga committed Sep 20, 2022
1 parent 1ad78df commit 8784ec1
Showing 2 changed files with 39 additions and 20 deletions.
11 changes: 8 additions & 3 deletions contracts/Chaosnet.sol
Original file line number Diff line number Diff line change
@@ -37,10 +37,16 @@ contract Chaosnet {
_;
}

modifier onlyOnChaosnet() {
require(isChaosnetActive, "Chaosnet is not active");
_;
}

/// @notice Adds beta operator to chaosnet. Can be called only by the
/// chaosnet owner.
/// chaosnet owner when the chaosnet is active.
function addBetaOperators(address[] calldata operators)
public
onlyOnChaosnet
onlyChaosnetOwner
{
for (uint256 i = 0; i < operators.length; i++) {
@@ -52,8 +58,7 @@ contract Chaosnet {

/// @notice Deactivates the chaosnet. Can be called only by the chaosnet
/// owner. Once deactivated chaosnet can not be activated again.
function deactivateChaosnet() public onlyChaosnetOwner {
require(isChaosnetActive, "Chaosnet is not active");
function deactivateChaosnet() public onlyOnChaosnet onlyChaosnetOwner {
isChaosnetActive = false;
emit ChaosnetDeactivated();
}
48 changes: 31 additions & 17 deletions test/sortitionPoolTest.js
Original file line number Diff line number Diff line change
@@ -547,24 +547,40 @@ describe("SortitionPool", () => {
})

context("when called by the chaosnet owner", () => {
let tx
context("when chaosnet is not active", () => {
beforeEach(async () => {
await pool.connect(chaosnetOwner).deactivateChaosnet()
})

beforeEach(async () => {
tx = await pool
.connect(chaosnetOwner)
.addBetaOperators([alice.address, bob.address])
it("should revert", async () => {
await expect(
pool
.connect(chaosnetOwner)
.addBetaOperators([alice.address, bob.address]),
).to.be.revertedWith("Chaosnet is not active")
})
})

it("should set selected operators as beta operators", async () => {
expect(await pool.isBetaOperator(alice.address)).to.be.true
expect(await pool.isBetaOperator(bob.address)).to.be.true
expect(await pool.isBetaOperator(carol.address)).to.be.false
})
context("when chaosnet is active", () => {
let tx

beforeEach(async () => {
tx = await pool
.connect(chaosnetOwner)
.addBetaOperators([alice.address, bob.address])
})

it("should emit BetaOperatorsAdded event", async () => {
await expect(tx)
.to.emit(pool, "BetaOperatorsAdded")
.withArgs([alice.address, bob.address])
it("should set selected operators as beta operators", async () => {
expect(await pool.isBetaOperator(alice.address)).to.be.true
expect(await pool.isBetaOperator(bob.address)).to.be.true
expect(await pool.isBetaOperator(carol.address)).to.be.false
})

it("should emit BetaOperatorsAdded event", async () => {
await expect(tx)
.to.emit(pool, "BetaOperatorsAdded")
.withArgs([alice.address, bob.address])
})
})
})
})
@@ -584,9 +600,7 @@ describe("SortitionPool", () => {
context("when called with the new address set to zero", () => {
it("should revert", async () => {
await expect(
pool
.connect(chaosnetOwner)
.transferChaosnetOwnerRole(ZERO_ADDRESS),
pool.connect(chaosnetOwner).transferChaosnetOwnerRole(ZERO_ADDRESS),
).to.be.revertedWith("New chaosnet owner must not be zero address")
})
})

0 comments on commit 8784ec1

Please sign in to comment.