Skip to content

Commit

Permalink
fix: make frost keygen retryable (#251)
Browse files Browse the repository at this point in the history
  • Loading branch information
mpetrun5 authored Jun 20, 2024
1 parent b2d975e commit 88fd294
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
25 changes: 16 additions & 9 deletions contracts/FROSTKeygen.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,27 @@ import "@openzeppelin/contracts/access/Ownable.sol";

contract FROSTKeygen is Ownable {

bool private keygenStarted;
event StartedFROSTKeygen();
bool private keygenEnded = false;

event StartedFROSTKeygen();
event EndedFROSTKeygen();

modifier onlyOnce(){
require (!keygenStarted, "FROST keygen can be called only once");
_;
keygenStarted = true;
}

/**
@notice Emits {StartedFROSTKeygen} event
*/
function startFROSTKeygen() public onlyOwner onlyOnce {
function startFROSTKeygen() public onlyOwner {
require (!keygenEnded, "FROST keygen ended");

emit StartedFROSTKeygen();
}

/**
@notice Blocks further calls for starting keygen.
*/
function endFROSTKeygen() public onlyOwner {
keygenEnded = true;

emit EndedFROSTKeygen();
}

}
19 changes: 11 additions & 8 deletions test/frostKeygen/frostKeygen.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,31 @@ contract("FROSTKeygen", (accounts) => {
});

it("should emit StartedFROSTKeygen event when startFROSTKeygen is called by the owner", async () => {

const tx = await FROSTKeygenInstance.startFROSTKeygen({from: accounts[0]})

TruffleAssert.eventEmitted(tx, "StartedFROSTKeygen");

});

it("should revert when startFROSTKeygen is not called by the owner", async () => {

await TruffleAssert.reverts(
FROSTKeygenInstance.startFROSTKeygen({from: accounts[1]}),
)

});

it("should revert when startFROSTKeygen is called more than once", async() => {

const tx = await FROSTKeygenInstance.startFROSTKeygen({from: accounts[0]})
it("should revert when keygen ended", async() => {
const tx = await FROSTKeygenInstance.endFROSTKeygen({from: accounts[0]})
TruffleAssert.eventEmitted(tx, "EndedFROSTKeygen");

TruffleAssert.eventEmitted(tx, "StartedFROSTKeygen");
await TruffleAssert.reverts(
FROSTKeygenInstance.startFROSTKeygen({from: accounts[1]}),
)
});

it("should revert when end keygen not called by owner", async() => {
await TruffleAssert.reverts(
FROSTKeygenInstance.startFROSTKeygen({from: accounts[0]}))
})
FROSTKeygenInstance.endFROSTKeygen({from: accounts[1]}),
)
});
})

0 comments on commit 88fd294

Please sign in to comment.