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

chore: Remove resourceID from FROSTKeygen contract #235

Merged
merged 2 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions contracts/FROSTKeygen.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

}
30 changes: 17 additions & 13 deletions test/frostKeygen/frostKeygen.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]}))
})
})
Loading