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:
parent
ae92f63987
commit
18e667bf19
|
@ -23,8 +23,7 @@ contract Marketplace is Collateral {
|
||||||
{
|
{
|
||||||
bytes32 id = keccak256(abi.encode(request));
|
bytes32 id = keccak256(abi.encode(request));
|
||||||
require(request.client == msg.sender, "Invalid client address");
|
require(request.client == msg.sender, "Invalid client address");
|
||||||
require(request.size > 0, "Invalid size");
|
require(requests[id].client == address(0), "Request already exists");
|
||||||
require(requests[id].size == 0, "Request already exists");
|
|
||||||
requests[id] = request;
|
requests[id] = request;
|
||||||
transferFrom(msg.sender, request.maxPrice);
|
transferFrom(msg.sender, request.maxPrice);
|
||||||
funds.received += request.maxPrice;
|
funds.received += request.maxPrice;
|
||||||
|
@ -36,11 +35,9 @@ contract Marketplace is Collateral {
|
||||||
bytes32 id = keccak256(abi.encode(offer));
|
bytes32 id = keccak256(abi.encode(offer));
|
||||||
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.size != 0, "Unknown request");
|
require(request.client != address(0), "Unknown request");
|
||||||
require(offer.host == msg.sender, "Invalid host address");
|
require(offer.host == msg.sender, "Invalid host address");
|
||||||
require(offers[id].expiry == 0, "Offer already exists");
|
require(offers[id].host == address(0), "Offer already exists");
|
||||||
// solhint-disable-next-line not-rely-on-time
|
|
||||||
require(offer.expiry > block.timestamp, "Offer expired");
|
|
||||||
require(offer.price <= request.maxPrice, "Price too high");
|
require(offer.price <= request.maxPrice, "Price too high");
|
||||||
offers[id] = offer;
|
offers[id] = offer;
|
||||||
emit StorageOffered(id, offer);
|
emit StorageOffered(id, offer);
|
||||||
|
|
|
@ -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 () {
|
it("rejects resubmission of request", async function () {
|
||||||
await token.approve(marketplace.address, request.maxPrice * 2)
|
await token.approve(marketplace.address, request.maxPrice * 2)
|
||||||
await marketplace.requestStorage(request)
|
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 () {
|
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