Lock collateral of host that offers storage

This commit is contained in:
Mark Spanbroek 2022-02-17 12:31:37 +01:00 committed by markspanbroek
parent 980e2343ed
commit cc57155792
2 changed files with 7 additions and 0 deletions

View File

@ -25,6 +25,7 @@ contract Marketplace is Collateral {
require(request.client == msg.sender, "Invalid client address");
require(requests[id].client == address(0), "Request already exists");
requests[id] = request;
_createLock(id, request.expiry);
transferFrom(msg.sender, request.maxPrice);
funds.received += request.maxPrice;
funds.balance += request.maxPrice;
@ -40,6 +41,7 @@ contract Marketplace is Collateral {
require(offers[id].host == address(0), "Offer already exists");
require(offer.price <= request.maxPrice, "Price too high");
offers[id] = offer;
_lock(msg.sender, offer.requestId);
emit StorageOffered(id, offer);
}

View File

@ -89,6 +89,11 @@ describe("Marketplace", function () {
.withArgs(offerId(offer), offerToArray(offer))
})
it("locks collateral of host", async function () {
await marketplace.offerStorage(offer)
await expect(marketplace.withdraw()).to.be.revertedWith("Account locked")
})
it("rejects offer with invalid host address", async function () {
let invalid = { ...offer, host: client.address }
await expect(marketplace.offerStorage(invalid)).to.be.revertedWith(