-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add FROSTKeygen contract and tests (#227)
Co-authored-by: mj52951 <[email protected]> Co-authored-by: nmlinaric <[email protected]>
- Loading branch information
1 parent
d06d6bc
commit 824151a
Showing
3 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// The Licensed Work is (c) 2022 Sygma | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
pragma solidity 0.8.11; | ||
|
||
import "@openzeppelin/contracts/access/Ownable.sol"; | ||
|
||
contract FROSTKeygen is Ownable { | ||
|
||
event StartedFROSTKeygen(bytes32 resourceID); | ||
|
||
/** | ||
@param resourceID ResourceID for which the keygen is initiated. | ||
*/ | ||
function startFROSTKeygen(bytes32 resourceID) public onlyOwner { | ||
emit StartedFROSTKeygen(resourceID); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const parseArgs = require("minimist"); | ||
|
||
const FROSTKeygenContract = artifacts.require("FROSTKeygen"); | ||
|
||
module.exports = async function (deployer) { | ||
|
||
const deployFrostKeygen = parseArgs(process.argv.slice(2))["deploy-frost-keygen"]; | ||
|
||
if (deployFrostKeygen){ | ||
await deployer.deploy(FROSTKeygenContract); | ||
const frostKeygenInstance = await FROSTKeygenContract.deployed(); | ||
|
||
console.table({ | ||
"FROSTKeygen Address": frostKeygenInstance.address, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// The Licensed Work is (c) 2022 Sygma | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
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 () => { | ||
|
||
const tx = await FROSTKeygenInstance.startFROSTKeygen(resourceID, {from: accounts[0]}) | ||
|
||
TruffleAssert.eventEmitted(tx, "StartedFROSTKeygen", (event) => { | ||
return event.resourceID === resourceID | ||
}, "StartedFROSTKeygen event should be emitted with correct resourceID"); | ||
|
||
}); | ||
|
||
it("should revert when it's not called by the owner", async () => { | ||
await TruffleAssert.reverts( | ||
FROSTKeygenInstance.startFROSTKeygen(resourceID, {from: accounts[1]}), | ||
) | ||
}); | ||
}) |