Unlock host stake at end of contract
This commit is contained in:
parent
d0a22afc3d
commit
aa673ff71c
|
@ -54,6 +54,11 @@ contract Storage is Contracts, Proofs, Stakes {
|
|||
_expectProofs(id, proofPeriod(id), proofTimeout(id), duration(id));
|
||||
}
|
||||
|
||||
function finishContract(bytes32 id) public {
|
||||
require(block.number > proofEnd(id), "Contract has not ended yet");
|
||||
_unlockStake(host(id));
|
||||
}
|
||||
|
||||
function duration(bytes32 contractId) public view returns (uint) {
|
||||
return _duration(contractId);
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ const { expect } = require("chai")
|
|||
const { ethers } = require("hardhat")
|
||||
const { hashRequest, hashBid, sign } = require("./marketplace")
|
||||
const { exampleRequest, exampleBid } = require("./examples")
|
||||
const { mineBlock, minedBlockNumber } = require ("./mining")
|
||||
|
||||
describe("Storage", function () {
|
||||
|
||||
|
@ -74,6 +75,28 @@ describe("Storage", function () {
|
|||
).to.be.revertedWith("Only host can call this function")
|
||||
})
|
||||
})
|
||||
|
||||
describe("finishing the contract", function () {
|
||||
|
||||
beforeEach(async function () {
|
||||
await storage.connect(host).startContract(id)
|
||||
})
|
||||
|
||||
it("unlocks the host stake", async function () {
|
||||
const end = await storage.proofEnd(id)
|
||||
while (await minedBlockNumber() < end) {
|
||||
await mineBlock()
|
||||
}
|
||||
await storage.finishContract(id)
|
||||
await expect(storage.connect(host).withdrawStake()).not.to.be.reverted
|
||||
})
|
||||
|
||||
it("is only allowed when end time has passed", async function () {
|
||||
await expect(
|
||||
storage.finishContract(id)
|
||||
).to.be.revertedWith("Contract has not ended yet")
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it("doesn't create contract with insufficient stake", async function () {
|
||||
|
@ -97,11 +120,8 @@ describe("Storage", function () {
|
|||
})
|
||||
})
|
||||
|
||||
// TODO: unlock stake at end of contract
|
||||
// TODO: payment when new contract
|
||||
// TODO: contract start and timeout
|
||||
// TODO: failure to start contract burns host and client
|
||||
// TODO: implement checking of actual proofs of storage, instead of dummy bool
|
||||
// TODO: only allow proofs after start of contract
|
||||
// TODO: proofs no longer required after contract duration
|
||||
// TODO: payout
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
const { ethers } = require("hardhat")
|
||||
|
||||
const exampleRequest = () => ({
|
||||
duration: 200000, // 200,000 blocks ≈ 1 month
|
||||
duration: 150, // 150 blocks ≈ half an hour
|
||||
size: 1 * 1024 * 1024 * 1024, // 1 Gigabyte
|
||||
contentHash: ethers.utils.sha256("0xdeadbeef"),
|
||||
proofPeriod: 8, // 8 blocks ≈ 2 minutes
|
||||
|
|
Loading…
Reference in New Issue