Add proof period and timeout to contract

This commit is contained in:
Mark Spanbroek 2021-10-14 09:10:57 +02:00
parent 31807dfe58
commit 550fcf4afe
2 changed files with 23 additions and 2 deletions

View File

@ -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

View File

@ -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