diff --git a/contracts/Marketplace.sol b/contracts/Marketplace.sol index 4b1b9f3..eb576d9 100644 --- a/contracts/Marketplace.sol +++ b/contracts/Marketplace.sol @@ -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); } diff --git a/test/Marketplace.test.js b/test/Marketplace.test.js index cd804ce..31a38c5 100644 --- a/test/Marketplace.test.js +++ b/test/Marketplace.test.js @@ -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(