Use client/host address to check for duplicates

Removes the need for the extra correctness checks
on request size and offer expiry, since these are
no longer used to check for duplicates.
This commit is contained in:
Mark Spanbroek 2022-02-17 11:09:35 +01:00 committed by markspanbroek
parent ae92f63987
commit 18e667bf19
2 changed files with 3 additions and 21 deletions

View File

@ -23,8 +23,7 @@ contract Marketplace is Collateral {
{
bytes32 id = keccak256(abi.encode(request));
require(request.client == msg.sender, "Invalid client address");
require(request.size > 0, "Invalid size");
require(requests[id].size == 0, "Request already exists");
require(requests[id].client == address(0), "Request already exists");
requests[id] = request;
transferFrom(msg.sender, request.maxPrice);
funds.received += request.maxPrice;
@ -36,11 +35,9 @@ contract Marketplace is Collateral {
bytes32 id = keccak256(abi.encode(offer));
Request storage request = requests[offer.requestId];
require(balanceOf(msg.sender) >= collateral, "Insufficient collateral");
require(request.size != 0, "Unknown request");
require(request.client != address(0), "Unknown request");
require(offer.host == msg.sender, "Invalid host address");
require(offers[id].expiry == 0, "Offer already exists");
// solhint-disable-next-line not-rely-on-time
require(offer.expiry > block.timestamp, "Offer expired");
require(offers[id].host == address(0), "Offer already exists");
require(offer.price <= request.maxPrice, "Price too high");
offers[id] = offer;
emit StorageOffered(id, offer);

View File

@ -64,14 +64,6 @@ describe("Marketplace", function () {
)
})
it("rejects requests of size 0", async function () {
let invalid = { ...request, size: 0 }
await token.approve(marketplace.address, invalid.maxPrice)
await expect(marketplace.requestStorage(invalid)).to.be.revertedWith(
"Invalid size"
)
})
it("rejects resubmission of request", async function () {
await token.approve(marketplace.address, request.maxPrice * 2)
await marketplace.requestStorage(request)
@ -112,13 +104,6 @@ describe("Marketplace", function () {
)
})
it("rejects an expired offer", async function () {
let expired = { ...offer, expiry: now() - hours(1) }
await expect(marketplace.offerStorage(expired)).to.be.revertedWith(
"Offer expired"
)
})
it("rejects an offer that exceeds the maximum price", async function () {
let invalid = { ...offer, price: request.maxPrice + 1 }
await expect(marketplace.offerStorage(invalid)).to.be.revertedWith(