mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-01-05 23:13:09 +00:00
* checked exceptions in stores
* makes asynciter as much exception safe as it gets
* introduce "SafeAsyncIter" that uses Results and limits exceptions to cancellations
* adds {.push raises: [].} to errors
* uses SafeAsyncIter in "listBlocks" and in "getBlockExpirations"
* simplifies safeasynciter (magic of auto)
* gets rid of ugly casts
* tiny fix in hte way we create raising futures in tests of safeasynciter
* Removes two more casts caused by using checked exceptions
* adds an extended explanation of one more complex SafeAsyncIter test
* adds missing "finishOnErr" param in slice constructor of SafeAsyncIter
* better fix for "Error: Exception can raise an unlisted exception: Exception" error.
---------
Co-authored-by: Dmitriy Ryajov <dryajov@gmail.com>
69 lines
2.0 KiB
Nim
69 lines
2.0 KiB
Nim
import pkg/questionable/results
|
|
|
|
import pkg/codex/clock
|
|
import pkg/codex/contracts/requests
|
|
import pkg/codex/sales
|
|
import pkg/codex/sales/salesagent
|
|
import pkg/codex/sales/salescontext
|
|
import pkg/codex/sales/states/filled
|
|
import pkg/codex/sales/states/errored
|
|
import pkg/codex/sales/states/proving
|
|
|
|
import ../../../asynctest
|
|
import ../../helpers/mockmarket
|
|
import ../../examples
|
|
import ../../helpers
|
|
|
|
suite "sales state 'filled'":
|
|
let request = StorageRequest.example
|
|
let slotIndex = request.ask.slots div 2
|
|
|
|
var market: MockMarket
|
|
var slot: MockSlot
|
|
var agent: SalesAgent
|
|
var state: SaleFilled
|
|
var onExpiryUpdatePassedExpiry: SecondsSince1970
|
|
|
|
setup:
|
|
market = MockMarket.new()
|
|
slot = MockSlot(
|
|
requestId: request.id,
|
|
host: Address.example,
|
|
slotIndex: slotIndex,
|
|
proof: Groth16Proof.default,
|
|
)
|
|
|
|
market.requestEnds[request.id] = 321
|
|
onExpiryUpdatePassedExpiry = -1
|
|
let onExpiryUpdate = proc(
|
|
rootCid: Cid, expiry: SecondsSince1970
|
|
): Future[?!void] {.async: (raises: [CancelledError]).} =
|
|
onExpiryUpdatePassedExpiry = expiry
|
|
return success()
|
|
let context = SalesContext(market: market, onExpiryUpdate: some onExpiryUpdate)
|
|
|
|
agent = newSalesAgent(context, request.id, slotIndex, some request)
|
|
state = SaleFilled.new()
|
|
|
|
test "switches to proving state when slot is filled by me":
|
|
slot.host = await market.getSigner()
|
|
market.filled = @[slot]
|
|
let next = await state.run(agent)
|
|
check !next of SaleProving
|
|
|
|
test "calls onExpiryUpdate with request end":
|
|
slot.host = await market.getSigner()
|
|
market.filled = @[slot]
|
|
|
|
let expectedExpiry = 123
|
|
market.requestEnds[request.id] = expectedExpiry
|
|
let next = await state.run(agent)
|
|
check !next of SaleProving
|
|
check onExpiryUpdatePassedExpiry == expectedExpiry
|
|
|
|
test "switches to error state when slot is filled by another host":
|
|
slot.host = Address.example
|
|
market.filled = @[slot]
|
|
let next = await state.run(agent)
|
|
check !next of SaleErrored
|