mirror of
https://github.com/codex-storage/nim-codex.git
synced 2025-02-10 03:55:30 +00:00
* openAPI: StorageRequestCreation: reward => pricePerByte, collateral => collateralPerByte * purchasing: reward => pricePerByte, collateral => collateralPerByte * Updates availabilities and reservations to use totalCollateral, minPricePerByte, and maxCollateralPerByte * Uses correct div operator when operating on UInt256 * proposal updating totalCollateral in availability * makes sure that reading currentCollateral happens before freeing slot * Updates naming * fixes tests: unit and contracts * uses feat/price-per-byte branch for codex-contracts-eth * temporarily disables integration tests on CI * introduces high level <<totalCollateral>> property for a cleaner external interface * updates integration tests * Applies review comments * Updates description of totalCollateral in SalesAvailability * updates codex-contracts-eth (price-per-byte)
49 lines
1.4 KiB
Nim
49 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: UInt256,
|
|
requestId: RequestId,
|
|
slotIndex: UInt256,
|
|
collateralPerByte: 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,
|
|
)
|