2024-06-20 12:28:01 +02: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 16:16:11 +10:00
|
|
|
createReservationThrowError: ?(ref CatchableError)
|
2024-06-20 12:28:01 +02:00
|
|
|
|
|
|
|
proc new*(T: type MockReservations, repo: RepoStore): MockReservations =
|
|
|
|
## Create a mock clock instance
|
|
|
|
MockReservations(availabilityLock: newAsyncLock(), repo: repo)
|
|
|
|
|
2024-10-04 16:16:11 +10:00
|
|
|
proc setCreateReservationThrowBytesOutOfBoundsError*(
|
|
|
|
self: MockReservations, flag: bool
|
|
|
|
) =
|
2024-06-20 12:28:01 +02:00
|
|
|
self.createReservationThrowBytesOutOfBoundsError = flag
|
|
|
|
|
2024-10-04 16:16:11 +10:00
|
|
|
proc setCreateReservationThrowError*(
|
|
|
|
self: MockReservations, error: ?(ref CatchableError)
|
|
|
|
) =
|
|
|
|
self.createReservationThrowError = error
|
|
|
|
|
2024-06-20 12:28:01 +02:00
|
|
|
method createReservation*(
|
|
|
|
self: MockReservations,
|
|
|
|
availabilityId: AvailabilityId,
|
|
|
|
slotSize: UInt256,
|
|
|
|
requestId: RequestId,
|
|
|
|
slotIndex: UInt256,
|
2025-01-24 18:18:00 +01:00
|
|
|
collateralPerByte: UInt256,
|
2024-06-20 12:28:01 +02:00
|
|
|
): 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 16:16:11 +10:00
|
|
|
elif error =? self.createReservationThrowError:
|
|
|
|
return failure(error)
|
2025-01-21 21:54:46 +01:00
|
|
|
|
2024-06-20 12:28:01 +02:00
|
|
|
return await procCall createReservation(
|
2025-01-24 18:18:00 +01:00
|
|
|
Reservations(self),
|
|
|
|
availabilityId,
|
|
|
|
slotSize,
|
|
|
|
requestId,
|
|
|
|
slotIndex,
|
|
|
|
collateralPerByte,
|
2024-06-20 12:28:01 +02:00
|
|
|
)
|