Add host address to offers
This commit is contained in:
parent
51e2d65596
commit
ae92f63987
|
@ -37,6 +37,7 @@ 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.size != 0, "Unknown request");
|
require(request.size != 0, "Unknown request");
|
||||||
|
require(offer.host == msg.sender, "Invalid host address");
|
||||||
require(offers[id].expiry == 0, "Offer already exists");
|
require(offers[id].expiry == 0, "Offer already exists");
|
||||||
// solhint-disable-next-line not-rely-on-time
|
// solhint-disable-next-line not-rely-on-time
|
||||||
require(offer.expiry > block.timestamp, "Offer expired");
|
require(offer.expiry > block.timestamp, "Offer expired");
|
||||||
|
@ -57,6 +58,7 @@ contract Marketplace is Collateral {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Offer {
|
struct Offer {
|
||||||
|
address host;
|
||||||
bytes32 requestId;
|
bytes32 requestId;
|
||||||
uint256 price;
|
uint256 price;
|
||||||
uint256 expiry;
|
uint256 expiry;
|
||||||
|
|
|
@ -97,6 +97,13 @@ describe("Marketplace", function () {
|
||||||
.withArgs(offerId(offer), offerToArray(offer))
|
.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 () {
|
it("rejects offer for unknown request", async function () {
|
||||||
let unknown = exampleRequest()
|
let unknown = exampleRequest()
|
||||||
let invalid = { ...offer, requestId: requestId(unknown) }
|
let invalid = { ...offer, requestId: requestId(unknown) }
|
||||||
|
@ -159,7 +166,7 @@ function requestId(request) {
|
||||||
function offerId(offer) {
|
function offerId(offer) {
|
||||||
return keccak256(
|
return keccak256(
|
||||||
defaultAbiCoder.encode(
|
defaultAbiCoder.encode(
|
||||||
["bytes32", "uint256", "uint256"],
|
["address", "bytes32", "uint256", "uint256"],
|
||||||
offerToArray(offer)
|
offerToArray(offer)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -179,5 +186,5 @@ function requestToArray(request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function offerToArray(offer) {
|
function offerToArray(offer) {
|
||||||
return [offer.requestId, offer.price, offer.expiry]
|
return [offer.host, offer.requestId, offer.price, offer.expiry]
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ const exampleBid = () => ({
|
||||||
})
|
})
|
||||||
|
|
||||||
const exampleOffer = () => ({
|
const exampleOffer = () => ({
|
||||||
|
host: hexlify(randomBytes(20)),
|
||||||
price: 42,
|
price: 42,
|
||||||
expiry: now() + hours(1),
|
expiry: now() + hours(1),
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue