Reject offer for expired request
This commit is contained in:
parent
85b212c703
commit
6e6cc1a230
|
@ -38,6 +38,8 @@ contract Marketplace is Collateral {
|
||||||
Request storage request = requests[offer.requestId];
|
Request storage request = requests[offer.requestId];
|
||||||
require(balanceOf(msg.sender) >= collateral, "Insufficient collateral");
|
require(balanceOf(msg.sender) >= collateral, "Insufficient collateral");
|
||||||
require(request.client != address(0), "Unknown request");
|
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(offer.host == msg.sender, "Invalid host address");
|
||||||
require(offers[id].host == address(0), "Offer already exists");
|
require(offers[id].host == address(0), "Offer already exists");
|
||||||
require(offer.price <= request.maxPrice, "Price too high");
|
require(offer.price <= request.maxPrice, "Price too high");
|
||||||
|
|
|
@ -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 () {
|
it("rejects an offer that exceeds the maximum price", async function () {
|
||||||
let invalid = { ...offer, price: request.maxPrice + 1 }
|
let invalid = { ...offer, price: request.maxPrice + 1 }
|
||||||
await expect(marketplace.offerStorage(invalid)).to.be.revertedWith(
|
await expect(marketplace.offerStorage(invalid)).to.be.revertedWith(
|
||||||
|
|
Loading…
Reference in New Issue