Reject offer for expired request

This commit is contained in:
Mark Spanbroek 2022-02-21 12:16:27 +01:00 committed by markspanbroek
parent 85b212c703
commit 6e6cc1a230
2 changed files with 14 additions and 0 deletions

View File

@ -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");

View File

@ -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(