diff --git a/contracts/Storage.sol b/contracts/Storage.sol index 04ba9a6..9e692c3 100644 --- a/contracts/Storage.sol +++ b/contracts/Storage.sol @@ -45,7 +45,12 @@ contract Storage is Contracts, Proofs, Stakes { ); } - function startContract(bytes32 id) public { + modifier onlyHost(bytes32 id) { + require(msg.sender == host(id), "Only host can call this function"); + _; + } + + function startContract(bytes32 id) public onlyHost(id) { _expectProofs(id, proofPeriod(id), proofTimeout(id), duration(id)); } diff --git a/test/Storage.test.js b/test/Storage.test.js index e7850d0..6627e64 100644 --- a/test/Storage.test.js +++ b/test/Storage.test.js @@ -67,6 +67,12 @@ describe("Storage", function () { await storage.connect(host).startContract(id) expect(await storage.proofEnd(id)).to.be.gt(0) }) + + it("can only be done by the host", async function () { + await expect( + storage.connect(client).startContract(id) + ).to.be.revertedWith("Only host can call this function") + }) }) })