diff --git a/contracts/Marketplace.sol b/contracts/Marketplace.sol index a50fa7a..558769e 100644 --- a/contracts/Marketplace.sol +++ b/contracts/Marketplace.sol @@ -264,6 +264,10 @@ contract Marketplace is Collateral, Proofs { return slots[slotId].host; } + function getHost(SlotId slotId) public view returns (address) { + return _host(slotId); + } + function _request(RequestId requestId) internal view @@ -274,6 +278,14 @@ contract Marketplace is Collateral, Proofs { return request; } + function getRequest(RequestId requestId) + public + view + returns (Request memory) + { + return _request(requestId); + } + function _slot(SlotId slotId) internal view returns (Slot storage) { Slot storage slot = slots[slotId]; require(slot.host != address(0), "Slot empty"); diff --git a/contracts/Storage.sol b/contracts/Storage.sol index 6f76e82..b1aed99 100644 --- a/contracts/Storage.sol +++ b/contracts/Storage.sol @@ -35,22 +35,10 @@ contract Storage is Marketplace { minCollateralThreshold = _minCollateralThreshold; } - function getRequest(RequestId requestId) - public - view - returns (Request memory) - { - return _request(requestId); - } - function getSlot(SlotId slotId) public view returns (Slot memory) { return _slot(slotId); } - function getHost(SlotId slotId) public view returns (address) { - return _host(slotId); - } - function missingProofs(SlotId slotId) public view returns (uint256) { return _missed(_toProofId(slotId)); } diff --git a/test/Marketplace.test.js b/test/Marketplace.test.js index 1302013..b44234d 100644 --- a/test/Marketplace.test.js +++ b/test/Marketplace.test.js @@ -1,5 +1,6 @@ const { ethers } = require("hardhat") const { hexlify, randomBytes } = ethers.utils +const { AddressZero } = ethers.constants const { expect } = require("chai") const { exampleRequest } = require("./examples") const { hours, minutes } = require("./time") @@ -85,6 +86,16 @@ describe("Marketplace", function () { .withArgs(requestId(request), askToArray(request.ask)) }) + it("allows retrieval of request details", async function () { + await token.approve(marketplace.address, price(request)) + await marketplace.requestStorage(request) + const id = requestId(request) + const retrieved = await marketplace.getRequest(id) + expect(retrieved.client).to.equal(request.client) + expect(retrieved.expiry).to.equal(request.expiry) + expect(retrieved.nonce).to.equal(request.nonce) + }) + it("rejects request with invalid client address", async function () { let invalid = { ...request, client: host.address } await token.approve(marketplace.address, price(invalid)) @@ -126,6 +137,12 @@ describe("Marketplace", function () { .withArgs(slot.request, slot.index, slotId(slot)) }) + it("allows retrieval of host that filled slot", async function () { + expect(await marketplace.getHost(slotId(slot))).to.equal(AddressZero) + await marketplace.fillSlot(slot.request, slot.index, proof) + expect(await marketplace.getHost(slotId(slot))).to.equal(host.address) + }) + it("starts requiring storage proofs", async function () { await marketplace.fillSlot(slot.request, slot.index, proof) expect(await marketplace.proofEnd(slotId(slot))).to.be.gt(0) diff --git a/test/Storage.test.js b/test/Storage.test.js index ebd3a58..fdadfc0 100644 --- a/test/Storage.test.js +++ b/test/Storage.test.js @@ -2,7 +2,6 @@ const { expect } = require("chai") const { ethers, deployments } = require("hardhat") const { BigNumber } = ethers const { hexlify, randomBytes } = ethers.utils -const { AddressZero } = ethers.constants const { exampleRequest } = require("./examples") const { advanceTime, advanceTimeTo, currentTime, mine } = require("./evm") const { requestId, slotId } = require("./ids") @@ -59,20 +58,6 @@ describe("Storage", function () { await storage.deposit(collateralAmount) }) - it("can retrieve storage requests", async function () { - const id = requestId(request) - const retrieved = await storage.getRequest(id) - expect(retrieved.client).to.equal(request.client) - expect(retrieved.expiry).to.equal(request.expiry) - expect(retrieved.nonce).to.equal(request.nonce) - }) - - it("can retrieve host that filled slot", async function () { - expect(await storage.getHost(slotId(slot))).to.equal(AddressZero) - await storage.fillSlot(slot.request, slot.index, proof) - expect(await storage.getHost(slotId(slot))).to.equal(host.address) - }) - describe("ending the contract", function () { it("unlocks the host collateral", async function () { await storage.fillSlot(slot.request, slot.index, proof)