2024-06-20 10:28:01 +00:00
|
|
|
import pkg/chronos
|
|
|
|
import pkg/codex/sales
|
|
|
|
import pkg/codex/stores
|
|
|
|
import pkg/questionable/results
|
|
|
|
|
|
|
|
type
|
|
|
|
MockReservations* = ref object of Reservations
|
|
|
|
createReservationThrowBytesOutOfBoundsError: bool
|
2024-10-04 06:16:11 +00:00
|
|
|
createReservationThrowError: ?(ref CatchableError)
|
2024-06-20 10:28:01 +00:00
|
|
|
|
|
|
|
proc new*(
|
|
|
|
T: type MockReservations,
|
|
|
|
repo: RepoStore
|
|
|
|
): MockReservations =
|
|
|
|
## Create a mock clock instance
|
|
|
|
MockReservations(availabilityLock: newAsyncLock(), repo: repo)
|
|
|
|
|
2024-10-04 06:16:11 +00:00
|
|
|
proc setCreateReservationThrowBytesOutOfBoundsError*(
|
|
|
|
self: MockReservations, flag: bool) =
|
|
|
|
|
2024-06-20 10:28:01 +00:00
|
|
|
self.createReservationThrowBytesOutOfBoundsError = flag
|
|
|
|
|
2024-10-04 06:16:11 +00:00
|
|
|
proc setCreateReservationThrowError*(
|
|
|
|
self: MockReservations, error: ?(ref CatchableError)) =
|
|
|
|
|
|
|
|
self.createReservationThrowError = error
|
|
|
|
|
2024-06-20 10:28:01 +00:00
|
|
|
method createReservation*(
|
|
|
|
self: MockReservations,
|
|
|
|
availabilityId: AvailabilityId,
|
|
|
|
slotSize: UInt256,
|
|
|
|
requestId: RequestId,
|
|
|
|
slotIndex: UInt256): Future[?!Reservation] {.async.} =
|
|
|
|
if self.createReservationThrowBytesOutOfBoundsError:
|
|
|
|
let error = newException(
|
|
|
|
BytesOutOfBoundsError,
|
|
|
|
"trying to reserve an amount of bytes that is greater than the total size of the Availability")
|
|
|
|
return failure(error)
|
|
|
|
|
2024-10-04 06:16:11 +00:00
|
|
|
elif error =? self.createReservationThrowError:
|
|
|
|
return failure(error)
|
|
|
|
|
2024-06-20 10:28:01 +00:00
|
|
|
return await procCall createReservation(Reservations(self), availabilityId, slotSize, requestId, slotIndex)
|
|
|
|
|