From 550fcf4afeef2b69ede96d90f76842e6a6caa3c9 Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Thu, 14 Oct 2021 09:10:57 +0200 Subject: [PATCH] Add proof period and timeout to contract --- contracts/StorageContract.sol | 6 ++++++ test/StorageContract.test.js | 19 +++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/contracts/StorageContract.sol b/contracts/StorageContract.sol index 8a75f7e..787a6f9 100644 --- a/contracts/StorageContract.sol +++ b/contracts/StorageContract.sol @@ -8,10 +8,14 @@ contract StorageContract { uint public immutable size; // storage size in bytes uint public immutable price; // price in coins address public immutable host; // host that provides storage + uint public immutable proofPeriod; // average time between proofs (in blocks) + uint public immutable proofTimeout; // proof has to be submitted before this constructor(uint _duration, uint _size, uint _price, + uint _proofPeriod, + uint _proofTimeout, address _host, bytes memory requestSignature, bytes memory bidSignature) @@ -24,6 +28,8 @@ contract StorageContract { size = _size; price = _price; host = _host; + proofPeriod = _proofPeriod; + proofTimeout = _proofTimeout; } // creates hash for a storage request that can be used to check its signature diff --git a/test/StorageContract.test.js b/test/StorageContract.test.js index e8da24f..748d9a2 100644 --- a/test/StorageContract.test.js +++ b/test/StorageContract.test.js @@ -4,8 +4,10 @@ const { hashRequest, hashBid, sign } = require("./marketplace") describe("Storage Contract", function () { - const duration = 31 * 24 * 60 * 60 - const size = 1 * 1024 * 1024 * 1024 + const duration = 31 * 24 * 60 * 60 // 31 days + const size = 1 * 1024 * 1024 * 1024 // 1 Gigabyte + const proofPeriod = 64 // 64 blocks ≈ 15 minutes + const proofTimeout = 42 // 42 blocks ≈ 10 minutes const price = 42 var StorageContract @@ -27,6 +29,8 @@ describe("Storage Contract", function () { duration, size, price, + proofPeriod, + proofTimeout, await host.getAddress(), await sign(client, requestHash), await sign(host, bidHash) @@ -49,6 +53,13 @@ describe("Storage Contract", function () { expect(await contract.host()).to.equal(await host.getAddress()) }) + it("has an average time between proofs (in blocks)", async function (){ + expect(await contract.proofPeriod()).to.equal(proofPeriod) + }) + + it("has a proof timeout (in blocks)", async function (){ + expect(await contract.proofTimeout()).to.equal(proofTimeout) + }) }) it("cannot be created when client signature is invalid", async function () { @@ -57,6 +68,8 @@ describe("Storage Contract", function () { duration, size, price, + proofPeriod, + proofTimeout, await host.getAddress(), invalidSignature, await sign(host, bidHash) @@ -69,6 +82,8 @@ describe("Storage Contract", function () { duration, size, price, + proofPeriod, + proofTimeout, await host.getAddress(), await sign(client, requestHash), invalidSignature