[marketplace] rename state(id) -> requestState(id)

This commit is contained in:
Mark Spanbroek 2023-01-16 14:28:42 +01:00 committed by markspanbroek
parent 10f88a62a7
commit de0595edb3
2 changed files with 18 additions and 17 deletions

View File

@ -105,10 +105,10 @@ contract Marketplace is Collateral, Proofs, StateRetrieval {
function freeSlot(SlotId slotId) public { function freeSlot(SlotId slotId) public {
Slot storage slot = _slot(slotId); Slot storage slot = _slot(slotId);
require(slot.host == msg.sender, "Slot filled by other host"); require(slot.host == msg.sender, "Slot filled by other host");
RequestState s = state(slot.requestId); RequestState state = requestState(slot.requestId);
if (s == RequestState.Finished || s == RequestState.Cancelled) { if (state == RequestState.Finished || state == RequestState.Cancelled) {
payoutSlot(slot.requestId, slotId); payoutSlot(slot.requestId, slotId);
} else if (s == RequestState.Failed) { } else if (state == RequestState.Failed) {
removeFromMySlots(msg.sender, slotId); removeFromMySlots(msg.sender, slotId);
} else { } else {
_forciblyFreeSlot(slotId); _forciblyFreeSlot(slotId);
@ -179,10 +179,9 @@ contract Marketplace is Collateral, Proofs, StateRetrieval {
RequestId requestId, RequestId requestId,
SlotId slotId SlotId slotId
) private marketplaceInvariant { ) private marketplaceInvariant {
RequestState requestState = state(requestId); RequestState state = requestState(requestId);
require( require(
requestState == RequestState.Finished || state == RequestState.Finished || state == RequestState.Cancelled,
requestState == RequestState.Cancelled,
"Contract not ended" "Contract not ended"
); );
RequestContext storage context = _context(requestId); RequestContext storage context = _context(requestId);
@ -331,7 +330,9 @@ contract Marketplace is Collateral, Proofs, StateRetrieval {
return request.ask.duration * request.ask.reward; return request.ask.duration * request.ask.reward;
} }
function state(RequestId requestId) public view returns (RequestState) { function requestState(
RequestId requestId
) public view returns (RequestState) {
RequestContext storage context = _context(requestId); RequestContext storage context = _context(requestId);
if ( if (
context.state == RequestState.New && context.state == RequestState.New &&
@ -361,8 +362,8 @@ contract Marketplace is Collateral, Proofs, StateRetrieval {
function _requestAcceptsProofs( function _requestAcceptsProofs(
RequestId requestId RequestId requestId
) internal view returns (bool) { ) internal view returns (bool) {
RequestState s = state(requestId); RequestState state = requestState(requestId);
return s == RequestState.New || s == RequestState.Started; return state == RequestState.New || state == RequestState.Started;
} }
struct RequestContext { struct RequestContext {

View File

@ -486,7 +486,7 @@ describe("Marketplace", function () {
for (let i = 0; i <= lastSlot; i++) { for (let i = 0; i <= lastSlot; i++) {
await marketplace.fillSlot(slot.request, i, proof) await marketplace.fillSlot(slot.request, i, proof)
} }
await expect(await marketplace.state(slot.request)).to.equal( await expect(await marketplace.requestState(slot.request)).to.equal(
RequestState.Started RequestState.Started
) )
}) })
@ -595,7 +595,7 @@ describe("Marketplace", function () {
}) })
it("changes state to Cancelled when client withdraws funds", async function () { it("changes state to Cancelled when client withdraws funds", async function () {
await expect(await marketplace.state(slot.request)).to.equal( await expect(await marketplace.requestState(slot.request)).to.equal(
RequestState.New RequestState.New
) )
}) })
@ -604,14 +604,14 @@ describe("Marketplace", function () {
await waitUntilCancelled(request) await waitUntilCancelled(request)
switchAccount(client) switchAccount(client)
await marketplace.withdrawFunds(slot.request) await marketplace.withdrawFunds(slot.request)
await expect(await marketplace.state(slot.request)).to.equal( await expect(await marketplace.requestState(slot.request)).to.equal(
RequestState.Cancelled RequestState.Cancelled
) )
}) })
it("changes state to Started once all slots are filled", async function () { it("changes state to Started once all slots are filled", async function () {
await waitUntilStarted(marketplace, request, proof) await waitUntilStarted(marketplace, request, proof)
await expect(await marketplace.state(slot.request)).to.equal( await expect(await marketplace.requestState(slot.request)).to.equal(
RequestState.Started RequestState.Started
) )
}) })
@ -619,7 +619,7 @@ describe("Marketplace", function () {
it("state is Failed once too many slots are freed", async function () { it("state is Failed once too many slots are freed", async function () {
await waitUntilStarted(marketplace, request, proof) await waitUntilStarted(marketplace, request, proof)
await waitUntilFailed(marketplace, request) await waitUntilFailed(marketplace, request)
await expect(await marketplace.state(slot.request)).to.equal( await expect(await marketplace.requestState(slot.request)).to.equal(
RequestState.Failed RequestState.Failed
) )
}) })
@ -628,7 +628,7 @@ describe("Marketplace", function () {
await waitUntilStarted(marketplace, request, proof) await waitUntilStarted(marketplace, request, proof)
await waitUntilFinished(marketplace, requestId(request)) await waitUntilFinished(marketplace, requestId(request))
await marketplace.freeSlot(slotId(slot)) await marketplace.freeSlot(slotId(slot))
await expect(await marketplace.state(slot.request)).to.equal( await expect(await marketplace.requestState(slot.request)).to.equal(
RequestState.Finished RequestState.Finished
) )
}) })
@ -641,14 +641,14 @@ describe("Marketplace", function () {
let id = slotId(slot) let id = slotId(slot)
await marketplace.forciblyFreeSlot(id) await marketplace.forciblyFreeSlot(id)
} }
await expect(await marketplace.state(slot.request)).to.equal( await expect(await marketplace.requestState(slot.request)).to.equal(
RequestState.New RequestState.New
) )
}) })
it("changes state to Cancelled once request is cancelled", async function () { it("changes state to Cancelled once request is cancelled", async function () {
await waitUntilCancelled(request) await waitUntilCancelled(request)
await expect(await marketplace.state(slot.request)).to.equal( await expect(await marketplace.requestState(slot.request)).to.equal(
RequestState.Cancelled RequestState.Cancelled
) )
}) })