Pay host when contract is finished
This commit is contained in:
parent
d2a3cc4a89
commit
38fee6d83a
|
@ -60,6 +60,7 @@ contract Storage is Contracts, Proofs, Stakes {
|
||||||
function finishContract(bytes32 id) public {
|
function finishContract(bytes32 id) public {
|
||||||
require(block.number > proofEnd(id), "Contract has not ended yet");
|
require(block.number > proofEnd(id), "Contract has not ended yet");
|
||||||
require(!finished[id], "Contract already finished");
|
require(!finished[id], "Contract already finished");
|
||||||
|
require(_token().transfer(host(id), price(id)), "Payment failed");
|
||||||
_unlockStake(host(id));
|
_unlockStake(host(id));
|
||||||
finished[id] = true;
|
finished[id] = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,15 +88,27 @@ describe("Storage", function () {
|
||||||
await storage.connect(host).startContract(id)
|
await storage.connect(host).startContract(id)
|
||||||
})
|
})
|
||||||
|
|
||||||
it("unlocks the host stake", async function () {
|
async function mineUntilEnd() {
|
||||||
const end = await storage.proofEnd(id)
|
const end = await storage.proofEnd(id)
|
||||||
while (await minedBlockNumber() < end) {
|
while (await minedBlockNumber() < end) {
|
||||||
await mineBlock()
|
await mineBlock()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
it("unlocks the host stake", async function () {
|
||||||
|
await mineUntilEnd()
|
||||||
await storage.finishContract(id)
|
await storage.finishContract(id)
|
||||||
await expect(storage.connect(host).withdrawStake()).not.to.be.reverted
|
await expect(storage.connect(host).withdrawStake()).not.to.be.reverted
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("pays the host", async function () {
|
||||||
|
await mineUntilEnd()
|
||||||
|
const startBalance = await token.balanceOf(host.address)
|
||||||
|
await storage.finishContract(id)
|
||||||
|
const endBalance = await token.balanceOf(host.address)
|
||||||
|
expect(endBalance - startBalance).to.equal(bid.price)
|
||||||
|
})
|
||||||
|
|
||||||
it("is only allowed when end time has passed", async function () {
|
it("is only allowed when end time has passed", async function () {
|
||||||
await expect(
|
await expect(
|
||||||
storage.finishContract(id)
|
storage.finishContract(id)
|
||||||
|
@ -104,10 +116,7 @@ describe("Storage", function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
it("can only be done once", async function () {
|
it("can only be done once", async function () {
|
||||||
const end = await storage.proofEnd(id)
|
await mineUntilEnd()
|
||||||
while (await minedBlockNumber() < end) {
|
|
||||||
await mineBlock()
|
|
||||||
}
|
|
||||||
await storage.finishContract(id)
|
await storage.finishContract(id)
|
||||||
await expect(
|
await expect(
|
||||||
storage.finishContract(id)
|
storage.finishContract(id)
|
||||||
|
@ -162,4 +171,6 @@ describe("Storage", function () {
|
||||||
// TODO: contract start and timeout
|
// TODO: contract start and timeout
|
||||||
// TODO: failure to start contract burns host and client
|
// TODO: failure to start contract burns host and client
|
||||||
// TODO: implement checking of actual proofs of storage, instead of dummy bool
|
// TODO: implement checking of actual proofs of storage, instead of dummy bool
|
||||||
// TODO: payout
|
// TODO: slash stake when too many missed proofs
|
||||||
|
// TODO: allow other host to take over contract when too many missed proofs
|
||||||
|
// TODO: small partial payouts when proofs are being submitted
|
||||||
|
|
Loading…
Reference in New Issue