logos-storage-nim/tests/codex/helpers/mockreservations.nim
Adam Uhlíř d2d8f64989
perf: contract storage optimizations (#1094)
* perf: contract storage optimizations

* Apply optimization changes

* Apply optimizing parameters sizing

* Update codex-contracts-eth

* bump latest changes in contracts branch

* Change requestDurationLimit to uint64

* fix tests

* fix tests

---------

Co-authored-by: Arnaud <arnaud@status.im>
Co-authored-by: Eric <5089238+emizzle@users.noreply.github.com>
2025-02-24 11:24:47 +01:00

51 lines
1.4 KiB
Nim

import pkg/chronos
import pkg/codex/sales
import pkg/codex/stores
import pkg/questionable/results
type MockReservations* = ref object of Reservations
createReservationThrowBytesOutOfBoundsError: bool
createReservationThrowError: ?(ref CatchableError)
proc new*(T: type MockReservations, repo: RepoStore): MockReservations =
## Create a mock clock instance
MockReservations(availabilityLock: newAsyncLock(), repo: repo)
proc setCreateReservationThrowBytesOutOfBoundsError*(
self: MockReservations, flag: bool
) =
self.createReservationThrowBytesOutOfBoundsError = flag
proc setCreateReservationThrowError*(
self: MockReservations, error: ?(ref CatchableError)
) =
self.createReservationThrowError = error
method createReservation*(
self: MockReservations,
availabilityId: AvailabilityId,
slotSize: uint64,
requestId: RequestId,
slotIndex: uint64,
collateralPerByte: UInt256,
duration: 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)
elif error =? self.createReservationThrowError:
return failure(error)
return await procCall createReservation(
Reservations(self),
availabilityId,
slotSize,
requestId,
slotIndex,
collateralPerByte,
duration,
)