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`.
This commit is contained in:
Eric 2024-10-04 13:28:39 +10:00 committed by GitHub
parent 33010bd20c
commit 807fc973c8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 0 deletions

View File

@ -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);
}

View File

@ -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"
)
})
})