From 0a1b56ee9f89724b23955fea89e4b6cf0f275da3 Mon Sep 17 00:00:00 2001 From: mj52951 <116341045+mj52951@users.noreply.github.com> Date: Mon, 6 May 2024 13:12:18 +0200 Subject: [PATCH] chore: Remove resourceID from FROSTKeygen contract (#235) --- contracts/FROSTKeygen.sol | 15 +++++++++++---- test/frostKeygen/frostKeygen.js | 30 +++++++++++++++++------------- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/contracts/FROSTKeygen.sol b/contracts/FROSTKeygen.sol index 19abd71e..2776723b 100644 --- a/contracts/FROSTKeygen.sol +++ b/contracts/FROSTKeygen.sol @@ -7,13 +7,20 @@ import "@openzeppelin/contracts/access/Ownable.sol"; contract FROSTKeygen is Ownable { - event StartedFROSTKeygen(bytes32 resourceID); + bool private keygenStarted; + event StartedFROSTKeygen(); + + modifier onlyOnce(){ + require (!keygenStarted, "FROST keygen can be called only once"); + _; + keygenStarted = true; + } /** - @param resourceID ResourceID for which the keygen is initiated. + @notice Emits {StartedFROSTKeygen} event */ - function startFROSTKeygen(bytes32 resourceID) public onlyOwner { - emit StartedFROSTKeygen(resourceID); + function startFROSTKeygen() public onlyOwner onlyOnce { + emit StartedFROSTKeygen(); } } \ No newline at end of file diff --git a/test/frostKeygen/frostKeygen.js b/test/frostKeygen/frostKeygen.js index aacfa4db..bd6002da 100644 --- a/test/frostKeygen/frostKeygen.js +++ b/test/frostKeygen/frostKeygen.js @@ -3,33 +3,37 @@ const TruffleAssert = require("truffle-assertions"); const FROSTKeygen = artifacts.require("FROSTKeygen") -const Helpers = require("../helpers"); contract("FROSTKeygen", (accounts) => { let FROSTKeygenInstance; - let resourceID; beforeEach(async () => { FROSTKeygenInstance = await FROSTKeygen.new(accounts[0]); - resourceID = Helpers.createResourceID( - "0x", - 1 - ); }); - it("should emit StartedFROSTKeygen event when startKeygen is called by the owner", async () => { + it("should emit StartedFROSTKeygen event when startFROSTKeygen is called by the owner", async () => { - const tx = await FROSTKeygenInstance.startFROSTKeygen(resourceID, {from: accounts[0]}) + const tx = await FROSTKeygenInstance.startFROSTKeygen({from: accounts[0]}) - TruffleAssert.eventEmitted(tx, "StartedFROSTKeygen", (event) => { - return event.resourceID === resourceID - }, "StartedFROSTKeygen event should be emitted with correct resourceID"); + TruffleAssert.eventEmitted(tx, "StartedFROSTKeygen"); }); - it("should revert when it's not called by the owner", async () => { + it("should revert when startFROSTKeygen is not called by the owner", async () => { + await TruffleAssert.reverts( - FROSTKeygenInstance.startFROSTKeygen(resourceID, {from: accounts[1]}), + FROSTKeygenInstance.startFROSTKeygen({from: accounts[1]}), ) + }); + + it("should revert when startFROSTKeygen is called more than once", async() => { + + const tx = await FROSTKeygenInstance.startFROSTKeygen({from: accounts[0]}) + + TruffleAssert.eventEmitted(tx, "StartedFROSTKeygen"); + + await TruffleAssert.reverts( + FROSTKeygenInstance.startFROSTKeygen({from: accounts[0]})) + }) })