From de0595edb35f23cbf215c058c5ef081dd0955f8c Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Mon, 16 Jan 2023 14:28:42 +0100 Subject: [PATCH] [marketplace] rename state(id) -> requestState(id) --- contracts/Marketplace.sol | 19 ++++++++++--------- test/Marketplace.test.js | 16 ++++++++-------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/contracts/Marketplace.sol b/contracts/Marketplace.sol index 00f0f3f..c89b605 100644 --- a/contracts/Marketplace.sol +++ b/contracts/Marketplace.sol @@ -105,10 +105,10 @@ contract Marketplace is Collateral, Proofs, StateRetrieval { function freeSlot(SlotId slotId) public { Slot storage slot = _slot(slotId); require(slot.host == msg.sender, "Slot filled by other host"); - RequestState s = state(slot.requestId); - if (s == RequestState.Finished || s == RequestState.Cancelled) { + RequestState state = requestState(slot.requestId); + if (state == RequestState.Finished || state == RequestState.Cancelled) { payoutSlot(slot.requestId, slotId); - } else if (s == RequestState.Failed) { + } else if (state == RequestState.Failed) { removeFromMySlots(msg.sender, slotId); } else { _forciblyFreeSlot(slotId); @@ -179,10 +179,9 @@ contract Marketplace is Collateral, Proofs, StateRetrieval { RequestId requestId, SlotId slotId ) private marketplaceInvariant { - RequestState requestState = state(requestId); + RequestState state = requestState(requestId); require( - requestState == RequestState.Finished || - requestState == RequestState.Cancelled, + state == RequestState.Finished || state == RequestState.Cancelled, "Contract not ended" ); RequestContext storage context = _context(requestId); @@ -331,7 +330,9 @@ contract Marketplace is Collateral, Proofs, StateRetrieval { 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); if ( context.state == RequestState.New && @@ -361,8 +362,8 @@ contract Marketplace is Collateral, Proofs, StateRetrieval { function _requestAcceptsProofs( RequestId requestId ) internal view returns (bool) { - RequestState s = state(requestId); - return s == RequestState.New || s == RequestState.Started; + RequestState state = requestState(requestId); + return state == RequestState.New || state == RequestState.Started; } struct RequestContext { diff --git a/test/Marketplace.test.js b/test/Marketplace.test.js index 87a7b14..0152ed9 100644 --- a/test/Marketplace.test.js +++ b/test/Marketplace.test.js @@ -486,7 +486,7 @@ describe("Marketplace", function () { for (let i = 0; i <= lastSlot; i++) { 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 ) }) @@ -595,7 +595,7 @@ describe("Marketplace", 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 ) }) @@ -604,14 +604,14 @@ describe("Marketplace", function () { await waitUntilCancelled(request) switchAccount(client) 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 ) }) it("changes state to Started once all slots are filled", async function () { 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 ) }) @@ -619,7 +619,7 @@ describe("Marketplace", function () { it("state is Failed once too many slots are freed", async function () { await waitUntilStarted(marketplace, request, proof) await waitUntilFailed(marketplace, request) - await expect(await marketplace.state(slot.request)).to.equal( + await expect(await marketplace.requestState(slot.request)).to.equal( RequestState.Failed ) }) @@ -628,7 +628,7 @@ describe("Marketplace", function () { await waitUntilStarted(marketplace, request, proof) await waitUntilFinished(marketplace, requestId(request)) 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 ) }) @@ -641,14 +641,14 @@ describe("Marketplace", function () { let id = slotId(slot) await marketplace.forciblyFreeSlot(id) } - await expect(await marketplace.state(slot.request)).to.equal( + await expect(await marketplace.requestState(slot.request)).to.equal( RequestState.New ) }) it("changes state to Cancelled once request is cancelled", async function () { await waitUntilCancelled(request) - await expect(await marketplace.state(slot.request)).to.equal( + await expect(await marketplace.requestState(slot.request)).to.equal( RequestState.Cancelled ) })