From 6de82709cace7da39c8c7dbc31ab7aa953bb5d26 Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Thu, 4 Nov 2021 09:53:01 +0100 Subject: [PATCH] Only host can call start on a contract --- contracts/Storage.sol | 7 ++++++- test/Storage.test.js | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-) 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") + }) }) })