Lock collateral of host that offers storage
This commit is contained in:
parent
980e2343ed
commit
cc57155792
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in New Issue