mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-01-02 13:33:10 +00:00
* Add availability enabled parameter * Return bytes to availability when finished * Add until parameter * Remove debug message * Clean up and fix tests * Update documentations and cleanup * Avoid swallowing CancelledError * Move until validation to reservations module * Call onAvailabilityAdded callabck when the availability is enabled in sales * Remove until validation in restapi when creating an availability * Add openapi documentation * Use results instead of stew/results (#1112) * feat: request duration limit (#1057) * feat: request duration limit * Fix tests and duration type * Add custom error * Remove merge issue * Update codex contracts eth * Update market config and fix test * Fix SlotReservationsConfig syntax * Update dependencies * test: remove doubled test * chore: update contracts repo --------- Co-authored-by: Arnaud <arnaud@status.im> * fix(statemachine): do not raise from state.run (#1115) * fix(statemachine): do not raise from state.run * fix rebase * fix exception handling in SaleProvingSimulated.prove - re-raise CancelledError - don't return State on CatchableError - expect the Proofs_InvalidProof custom error instead of checking a string * asyncSpawn salesagent.onCancelled This was swallowing a KeyError in one of the tests (fixed in the previous commit) * remove error handling states in asyncstatemachine * revert unneeded changes * formatting * PR feedback, logging updates * chore(integration): simplify block expiration integration test (#1100) * chore(integration): simplify block expiration integration test * clean up * fix after rebase * 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> * bump contracts to master (#1122) * Add availability enabled parameter * Return bytes to availability when finished * Add until parameter * Clean up and fix tests * Move until validation to reservations module * Apply suggestion changes: return the reservation module error * Apply suggestion changes for until dates * Apply suggestion changes: reorganize tests * Fix indent * Remove test related to timing issue * Add raises errors to async pragram and remove useless try except * Update open api documentation * Fix wording * Remove the httpClient restart statements * Use market.getRequestEnd to set validUntil * Remove returnBytes * Use clock.now in testing * Move the api validation file to the right file --------- Co-authored-by: Adam Uhlíř <adam@uhlir.dev> Co-authored-by: Eric <5089238+emizzle@users.noreply.github.com>
70 lines
2.2 KiB
Nim
70 lines
2.2 KiB
Nim
import pkg/chronos
|
|
import pkg/questionable
|
|
import pkg/codex/contracts/requests
|
|
import pkg/codex/sales/states/slotreserving
|
|
import pkg/codex/sales/states/downloading
|
|
import pkg/codex/sales/states/cancelled
|
|
import pkg/codex/sales/states/failed
|
|
import pkg/codex/sales/states/ignored
|
|
import pkg/codex/sales/states/errored
|
|
import pkg/codex/sales/salesagent
|
|
import pkg/codex/sales/salescontext
|
|
import pkg/codex/sales/reservations
|
|
import pkg/codex/stores/repostore
|
|
import ../../../asynctest
|
|
import ../../helpers
|
|
import ../../examples
|
|
import ../../helpers/mockmarket
|
|
import ../../helpers/mockclock
|
|
|
|
asyncchecksuite "sales state 'SlotReserving'":
|
|
let request = StorageRequest.example
|
|
let slotIndex = request.ask.slots div 2
|
|
var market: MockMarket
|
|
var clock: MockClock
|
|
var agent: SalesAgent
|
|
var state: SaleSlotReserving
|
|
var context: SalesContext
|
|
|
|
setup:
|
|
market = MockMarket.new()
|
|
clock = MockClock.new()
|
|
|
|
state = SaleSlotReserving.new()
|
|
context = SalesContext(market: market, clock: clock)
|
|
|
|
agent = newSalesAgent(context, request.id, slotIndex, request.some)
|
|
|
|
test "switches to cancelled state when request expires":
|
|
let next = state.onCancelled(request)
|
|
check !next of SaleCancelled
|
|
|
|
test "switches to failed state when request fails":
|
|
let next = state.onFailed(request)
|
|
check !next of SaleFailed
|
|
|
|
test "run switches to downloading when slot successfully reserved":
|
|
let next = await state.run(agent)
|
|
check !next of SaleDownloading
|
|
|
|
test "run switches to ignored when slot reservation not allowed":
|
|
market.setCanReserveSlot(false)
|
|
let next = await state.run(agent)
|
|
check !next of SaleIgnored
|
|
|
|
test "run switches to errored when slot reservation errors":
|
|
let error = newException(MarketError, "some error")
|
|
market.setErrorOnReserveSlot(error)
|
|
let next = !(await state.run(agent))
|
|
check next of SaleErrored
|
|
let errored = SaleErrored(next)
|
|
check errored.error == error
|
|
|
|
test "run switches to ignored when reservation is not allowed":
|
|
let error =
|
|
newException(SlotReservationNotAllowedError, "Reservation is not allowed")
|
|
market.setErrorOnReserveSlot(error)
|
|
let next = !(await state.run(agent))
|
|
check next of SaleIgnored
|
|
check SaleIgnored(next).reprocessSlot == false
|