[marketplace] slotIsNotFree() modifier
Replaces _slot getter
This commit is contained in:
parent
944e9c9da2
commit
8c6891f1e2
|
@ -102,8 +102,8 @@ contract Marketplace is Collateral, Proofs, StateRetrieval {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function freeSlot(SlotId slotId) public {
|
function freeSlot(SlotId slotId) public slotIsNotFree(slotId) {
|
||||||
Slot storage slot = _slot(slotId);
|
Slot storage slot = slots[slotId];
|
||||||
require(slot.host == msg.sender, "Slot filled by other host");
|
require(slot.host == msg.sender, "Slot filled by other host");
|
||||||
SlotState state = slotState(slotId);
|
SlotState state = slotState(slotId);
|
||||||
require(state != SlotState.Paid, "Already paid");
|
require(state != SlotState.Paid, "Already paid");
|
||||||
|
@ -133,7 +133,7 @@ contract Marketplace is Collateral, Proofs, StateRetrieval {
|
||||||
}
|
}
|
||||||
|
|
||||||
function _forciblyFreeSlot(SlotId slotId) internal marketplaceInvariant {
|
function _forciblyFreeSlot(SlotId slotId) internal marketplaceInvariant {
|
||||||
Slot storage slot = _slot(slotId);
|
Slot storage slot = slots[slotId];
|
||||||
RequestId requestId = slot.requestId;
|
RequestId requestId = slot.requestId;
|
||||||
RequestContext storage context = requestContexts[requestId];
|
RequestContext storage context = requestContexts[requestId];
|
||||||
|
|
||||||
|
@ -174,7 +174,7 @@ contract Marketplace is Collateral, Proofs, StateRetrieval {
|
||||||
Request storage request = requests[requestId];
|
Request storage request = requests[requestId];
|
||||||
context.state = RequestState.Finished;
|
context.state = RequestState.Finished;
|
||||||
removeFromMyRequests(request.client, requestId);
|
removeFromMyRequests(request.client, requestId);
|
||||||
Slot storage slot = _slot(slotId);
|
Slot storage slot = slots[slotId];
|
||||||
|
|
||||||
removeFromMySlots(slot.host, slotId);
|
removeFromMySlots(slot.host, slotId);
|
||||||
|
|
||||||
|
@ -226,10 +226,9 @@ contract Marketplace is Collateral, Proofs, StateRetrieval {
|
||||||
return requests[requestId];
|
return requests[requestId];
|
||||||
}
|
}
|
||||||
|
|
||||||
function _slot(SlotId slotId) internal view returns (Slot storage) {
|
modifier slotIsNotFree(SlotId slotId) {
|
||||||
Slot storage slot = slots[slotId];
|
require(slots[slotId].state != SlotState.Free, "Slot is free");
|
||||||
require(slot.state != SlotState.Free, "Slot empty");
|
_;
|
||||||
return slot;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function proofPeriod() public view returns (uint256) {
|
function proofPeriod() public view returns (uint256) {
|
||||||
|
|
|
@ -33,8 +33,4 @@ contract TestMarketplace is Marketplace {
|
||||||
function forciblyFreeSlot(SlotId slotId) public {
|
function forciblyFreeSlot(SlotId slotId) public {
|
||||||
_forciblyFreeSlot(slotId);
|
_forciblyFreeSlot(slotId);
|
||||||
}
|
}
|
||||||
|
|
||||||
function slot(SlotId slotId) public view returns (Slot memory) {
|
|
||||||
return _slot(slotId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -297,7 +297,7 @@ describe("Marketplace", function () {
|
||||||
slot.index = 5
|
slot.index = 5
|
||||||
let nonExistentId = slotId(slot)
|
let nonExistentId = slotId(slot)
|
||||||
await expect(marketplace.freeSlot(nonExistentId)).to.be.revertedWith(
|
await expect(marketplace.freeSlot(nonExistentId)).to.be.revertedWith(
|
||||||
"Slot empty"
|
"Slot is free"
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -320,12 +320,6 @@ describe("Marketplace", function () {
|
||||||
.to.emit(marketplace, "SlotFreed")
|
.to.emit(marketplace, "SlotFreed")
|
||||||
.withArgs(slot.request, id)
|
.withArgs(slot.request, id)
|
||||||
})
|
})
|
||||||
|
|
||||||
it("cannot get slot once freed", async function () {
|
|
||||||
await waitUntilStarted(marketplace, request, proof)
|
|
||||||
await marketplace.freeSlot(id)
|
|
||||||
await expect(marketplace.slot(id)).to.be.revertedWith("Slot empty")
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("paying out a slot", function () {
|
describe("paying out a slot", function () {
|
||||||
|
|
Loading…
Reference in New Issue