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:
parent
33010bd20c
commit
807fc973c8
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
)
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue