Add host address to offers

This commit is contained in:
Mark Spanbroek 2022-02-17 11:06:14 +01:00 committed by markspanbroek
parent 51e2d65596
commit ae92f63987
3 changed files with 12 additions and 2 deletions

View File

@ -37,6 +37,7 @@ contract Marketplace is Collateral {
Request storage request = requests[offer.requestId];
require(balanceOf(msg.sender) >= collateral, "Insufficient collateral");
require(request.size != 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");
@ -57,6 +58,7 @@ contract Marketplace is Collateral {
}
struct Offer {
address host;
bytes32 requestId;
uint256 price;
uint256 expiry;

View File

@ -97,6 +97,13 @@ describe("Marketplace", function () {
.withArgs(offerId(offer), offerToArray(offer))
})
it("rejects offer with invalid host address", async function () {
let invalid = { ...offer, host: client.address }
await expect(marketplace.offerStorage(invalid)).to.be.revertedWith(
"Invalid host address"
)
})
it("rejects offer for unknown request", async function () {
let unknown = exampleRequest()
let invalid = { ...offer, requestId: requestId(unknown) }
@ -159,7 +166,7 @@ function requestId(request) {
function offerId(offer) {
return keccak256(
defaultAbiCoder.encode(
["bytes32", "uint256", "uint256"],
["address", "bytes32", "uint256", "uint256"],
offerToArray(offer)
)
)
@ -179,5 +186,5 @@ function requestToArray(request) {
}
function offerToArray(offer) {
return [offer.requestId, offer.price, offer.expiry]
return [offer.host, offer.requestId, offer.price, offer.expiry]
}

View File

@ -19,6 +19,7 @@ const exampleBid = () => ({
})
const exampleOffer = () => ({
host: hexlify(randomBytes(20)),
price: 42,
expiry: now() + hours(1),
})