From 807fc973c875b5bde8f517c71c818ba8f2f720dd Mon Sep 17 00:00:00 2001 From: Eric <5089238+emizzle@users.noreply.github.com> Date: Fri, 4 Oct 2024 13:28:39 +1000 Subject: [PATCH] feat(slot-reservations): Add `SlotReservationsFull` event (#183) `SlotReservationsFull` event is emitted once a slot has reached its capacity for slot reservations (3 reservations at this time). `SlotReservationsFull` event emists `requestId` and `slotIndex`. --- contracts/SlotReservations.sol | 6 ++++++ test/SlotReservations.test.js | 17 +++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/contracts/SlotReservations.sol b/contracts/SlotReservations.sol index 0327107..8584105 100644 --- a/contracts/SlotReservations.sol +++ b/contracts/SlotReservations.sol @@ -20,6 +20,10 @@ contract SlotReservations { SlotId slotId = Requests.slotId(requestId, slotIndex); _reservations[slotId].add(msg.sender); + + if (_reservations[slotId].length() == _config.maxReservations) { + emit SlotReservationsFull(requestId, slotIndex); + } } function canReserveSlot( @@ -33,4 +37,6 @@ contract SlotReservations { (_reservations[slotId].length() < _config.maxReservations) && (!_reservations[slotId].contains(host)); } + + event SlotReservationsFull(RequestId indexed requestId, uint256 slotIndex); } diff --git a/test/SlotReservations.test.js b/test/SlotReservations.test.js index 055c294..9db71e9 100644 --- a/test/SlotReservations.test.js +++ b/test/SlotReservations.test.js @@ -98,4 +98,21 @@ describe("SlotReservations", function () { switchAccount(provider) expect(await reservations.canReserveSlot(reqId, slotIndex)).to.be.false }) + + it("should emit an event when slot reservations are full", async function () { + await reservations.reserveSlot(reqId, slotIndex) + switchAccount(address1) + await reservations.reserveSlot(reqId, slotIndex) + switchAccount(address2) + await expect(reservations.reserveSlot(reqId, slotIndex)) + .to.emit(reservations, "SlotReservationsFull") + .withArgs(reqId, slotIndex) + }) + + it("should not emit an event when reservations are not full", async function () { + await expect(reservations.reserveSlot(reqId, slotIndex)).to.not.emit( + reservations, + "SlotReservationsFull" + ) + }) })