From e5ed3bd59d51d88623e7b7ac18233fab87b55f80 Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Wed, 20 Jul 2022 10:05:36 +0200 Subject: [PATCH] [storage] Remove finishContract() Is superceded by Marketplace.payoutSlot(). --- contracts/Storage.sol | 13 ----------- test/Storage.test.js | 50 ++++++++----------------------------------- 2 files changed, 9 insertions(+), 54 deletions(-) diff --git a/contracts/Storage.sol b/contracts/Storage.sol index b7c9d61..ebde0f9 100644 --- a/contracts/Storage.sol +++ b/contracts/Storage.sol @@ -10,8 +10,6 @@ contract Storage is Collateral, Marketplace { uint256 public slashMisses; uint256 public slashPercentage; - mapping(bytes32 => bool) private contractFinished; - constructor( IERC20 token, uint256 _proofPeriod, @@ -42,17 +40,6 @@ contract Storage is Collateral, Marketplace { return _host(id); } - function finishContract(bytes32 id) public { - require(_host(id) != address(0), "Contract not started"); - require(!contractFinished[id], "Contract already finished"); - require(block.timestamp > proofEnd(id), "Contract has not ended yet"); - contractFinished[id] = true; - require( - token.transfer(_host(id), _request(id).ask.reward), - "Payment failed" - ); - } - function missingProofs(bytes32 contractId) public view returns (uint256) { return _missed(contractId); } diff --git a/test/Storage.test.js b/test/Storage.test.js index 6f309aa..062c82a 100644 --- a/test/Storage.test.js +++ b/test/Storage.test.js @@ -4,7 +4,7 @@ const { hexlify, randomBytes } = ethers.utils const { AddressZero } = ethers.constants const { exampleRequest } = require("./examples") const { advanceTime, advanceTimeTo, currentTime } = require("./evm") -const { requestId } = require("./ids") +const { requestId, slotId } = require("./ids") const { periodic } = require("./time") describe("Storage", function () { @@ -15,6 +15,7 @@ describe("Storage", function () { let client, host let request let collateralAmount, slashMisses, slashPercentage + let slot let id function switchAccount(account) { @@ -39,6 +40,10 @@ describe("Storage", function () { request = exampleRequest() request.client = client.address id = requestId(request) + slot = { + request: requestId(request), + index: request.content.erasure.totalNodes / 2, + } switchAccount(client) await token.approve(storage.address, request.ask.reward) @@ -62,54 +67,17 @@ describe("Storage", function () { expect(await storage.getHost(requestId(request))).to.equal(host.address) }) - describe("finishing the contract", function () { + describe("ending the contract", function () { async function waitUntilEnd() { - const end = (await storage.proofEnd(id)).toNumber() + const end = (await storage.proofEnd(slotId(slot))).toNumber() await advanceTimeTo(end) } it("unlocks the host collateral", async function () { - await storage.fulfillRequest(requestId(request), proof) + await storage.fillSlot(slot.request, slot.index, proof) await waitUntilEnd() - await storage.finishContract(id) await expect(storage.withdraw()).not.to.be.reverted }) - - it("pays the host", async function () { - await storage.fulfillRequest(requestId(request), proof) - await waitUntilEnd() - const startBalance = await token.balanceOf(host.address) - await storage.finishContract(id) - const endBalance = await token.balanceOf(host.address) - expect(endBalance - startBalance).to.equal(request.ask.reward) - }) - - it("is only allowed when the contract has started", async function () { - await expect(storage.finishContract(id)).to.be.revertedWith( - "Contract not started" - ) - }) - - it("is only allowed when end time has passed", async function () { - await storage.fulfillRequest(requestId(request), proof) - await expect(storage.finishContract(id)).to.be.revertedWith( - "Contract has not ended yet" - ) - }) - - it("can only be done once", async function () { - await storage.fulfillRequest(requestId(request), proof) - await waitUntilEnd() - await storage.finishContract(id) - await expect(storage.finishContract(id)).to.be.reverted - }) - - it("can not be restarted", async function () { - await storage.fulfillRequest(requestId(request), proof) - await waitUntilEnd() - await storage.finishContract(id) - await expect(storage.fulfillRequest(id, proof)).to.be.reverted - }) }) describe("slashing when missing proofs", function () {