diff --git a/contracts/Marketplace.sol b/contracts/Marketplace.sol index 57b311e..57beff4 100644 --- a/contracts/Marketplace.sol +++ b/contracts/Marketplace.sol @@ -38,6 +38,8 @@ contract Marketplace is Collateral { Request storage request = requests[offer.requestId]; require(balanceOf(msg.sender) >= collateral, "Insufficient collateral"); require(request.client != address(0), "Unknown request"); + // solhint-disable-next-line not-rely-on-time + require(request.expiry > block.timestamp, "Request expired"); require(offer.host == msg.sender, "Invalid host address"); require(offers[id].host == address(0), "Offer already exists"); require(offer.price <= request.maxPrice, "Price too high"); diff --git a/test/Marketplace.test.js b/test/Marketplace.test.js index 43929ef..a95c52c 100644 --- a/test/Marketplace.test.js +++ b/test/Marketplace.test.js @@ -111,6 +111,18 @@ describe("Marketplace", function () { ) }) + it("rejects offer for expired request", async function () { + switchAccount(client) + let expired = { ...request, expiry: now() - hours(1) } + await token.approve(marketplace.address, request.maxPrice) + await marketplace.requestStorage(expired) + switchAccount(host) + let invalid = { ...offer, requestId: requestId(expired) } + await expect(marketplace.offerStorage(invalid)).to.be.revertedWith( + "Request 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(