mirror of
https://github.com/status-im/codex-contracts-eth.git
synced 2025-03-03 17:40:48 +00:00
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(request.client == msg.sender, "Invalid client address");
|
||||||
require(requests[id].client == address(0), "Request already exists");
|
require(requests[id].client == address(0), "Request already exists");
|
||||||
requests[id] = request;
|
requests[id] = request;
|
||||||
|
_createLock(id, request.expiry);
|
||||||
transferFrom(msg.sender, request.maxPrice);
|
transferFrom(msg.sender, request.maxPrice);
|
||||||
funds.received += request.maxPrice;
|
funds.received += request.maxPrice;
|
||||||
funds.balance += request.maxPrice;
|
funds.balance += request.maxPrice;
|
||||||
@ -40,6 +41,7 @@ contract Marketplace is Collateral {
|
|||||||
require(offers[id].host == address(0), "Offer already exists");
|
require(offers[id].host == address(0), "Offer already exists");
|
||||||
require(offer.price <= request.maxPrice, "Price too high");
|
require(offer.price <= request.maxPrice, "Price too high");
|
||||||
offers[id] = offer;
|
offers[id] = offer;
|
||||||
|
_lock(msg.sender, offer.requestId);
|
||||||
emit StorageOffered(id, offer);
|
emit StorageOffered(id, offer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,6 +89,11 @@ describe("Marketplace", function () {
|
|||||||
.withArgs(offerId(offer), offerToArray(offer))
|
.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 () {
|
it("rejects offer with invalid host address", async function () {
|
||||||
let invalid = { ...offer, host: client.address }
|
let invalid = { ...offer, host: client.address }
|
||||||
await expect(marketplace.offerStorage(invalid)).to.be.revertedWith(
|
await expect(marketplace.offerStorage(invalid)).to.be.revertedWith(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user