Feat/bump questionable (#627)

* Bumps questionable version to 0.10.12

* removes unnecessary questionnable bindings.

* Fixes tests

* unnecessary whitespaces
This commit is contained in:
Ben Bierens 2023-11-17 13:49:45 +01:00 committed by GitHub
parent 40d7714a67
commit bece1b88a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 38 additions and 72 deletions

View File

@ -20,7 +20,7 @@ requires "nimcrypto >= 0.4.1"
requires "nitro >= 0.5.1 & < 0.6.0" requires "nitro >= 0.5.1 & < 0.6.0"
requires "presto" requires "presto"
requires "protobuf_serialization >= 0.2.0 & < 0.3.0" requires "protobuf_serialization >= 0.2.0 & < 0.3.0"
requires "questionable >= 0.10.6 & < 0.11.0" requires "questionable >= 0.10.12 & < 0.11.0"
requires "secp256k1" requires "secp256k1"
requires "stew" requires "stew"
requires "upraises >= 0.1.0 & < 0.2.0" requires "upraises >= 0.1.0 & < 0.2.0"

View File

@ -181,7 +181,7 @@ proc getImpl(
self: Reservations, self: Reservations,
key: Key): Future[?!seq[byte]] {.async.} = key: Key): Future[?!seq[byte]] {.async.} =
if exists =? (await self.exists(key)) and not exists: if not await self.exists(key):
let err = newException(NotExistsError, "object with key " & $key & " does not exist") let err = newException(NotExistsError, "object with key " & $key & " does not exist")
return failure(err) return failure(err)
@ -226,7 +226,7 @@ proc delete(
trace "deleting object", key trace "deleting object", key
if exists =? (await self.exists(key)) and not exists: if not await self.exists(key):
return success() return success()
if err =? (await self.repo.metaDs.delete(key)).errorOption: if err =? (await self.repo.metaDs.delete(key)).errorOption:

View File

@ -20,19 +20,15 @@ method run*(state: SaleCancelled, machine: Machine): Future[?State] {.async.} =
without request =? data.request: without request =? data.request:
raiseAssert "no sale request" raiseAssert "no sale request"
without slotIndex =? data.slotIndex: let slot = Slot(request: request, slotIndex: data.slotIndex)
raiseAssert("no slot index assigned") debug "Collecting collateral and partial payout", requestId = $data.requestId, slotIndex = $data.slotIndex
let slot = Slot(request: request, slotIndex: slotIndex)
debug "Collecting collateral and partial payout", requestId = $data.requestId, slotIndex
await market.freeSlot(slot.id) await market.freeSlot(slot.id)
if onClear =? agent.context.onClear and if onClear =? agent.context.onClear and
request =? data.request and request =? data.request:
slotIndex =? data.slotIndex: onClear(request, data.slotIndex)
onClear(request, slotIndex)
if onCleanUp =? agent.onCleanUp: if onCleanUp =? agent.onCleanUp:
await onCleanUp() await onCleanUp()
warn "Sale cancelled due to timeout", requestId = $data.requestId, slotIndex warn "Sale cancelled due to timeout", requestId = $data.requestId, slotIndex = $data.slotIndex

View File

@ -42,15 +42,12 @@ method run*(state: SaleDownloading, machine: Machine): Future[?State] {.async.}
without request =? data.request: without request =? data.request:
raiseAssert "no sale request" raiseAssert "no sale request"
without slotIndex =? data.slotIndex:
raiseAssert("no slot index assigned")
without reservation =? data.reservation: without reservation =? data.reservation:
raiseAssert("no reservation") raiseAssert("no reservation")
logScope: logScope:
requestId = request.id requestId = request.id
slotIndex slotIndex = data.slotIndex
reservationId = reservation.id reservationId = reservation.id
availabilityId = reservation.availabilityId availabilityId = reservation.availabilityId
@ -72,7 +69,7 @@ method run*(state: SaleDownloading, machine: Machine): Future[?State] {.async.}
trace "Starting download" trace "Starting download"
if err =? (await onStore(request, if err =? (await onStore(request,
slotIndex, data.slotIndex,
onBatch)).errorOption: onBatch)).errorOption:
return some State(SaleErrored(error: err)) return some State(SaleErrored(error: err))

View File

@ -25,9 +25,8 @@ method run*(state: SaleErrored, machine: Machine): Future[?State] {.async.} =
error "Sale error", error=state.error.msgDetail, requestId = data.requestId, slotIndex = data.slotIndex error "Sale error", error=state.error.msgDetail, requestId = data.requestId, slotIndex = data.slotIndex
if onClear =? context.onClear and if onClear =? context.onClear and
request =? data.request and request =? data.request:
slotIndex =? data.slotIndex: onClear(request, data.slotIndex)
onClear(request, slotIndex)
if onCleanUp =? agent.onCleanUp: if onCleanUp =? agent.onCleanUp:
await onCleanUp() await onCleanUp()

View File

@ -20,11 +20,8 @@ method run*(state: SaleFailed, machine: Machine): Future[?State] {.async.} =
without request =? data.request: without request =? data.request:
raiseAssert "no sale request" raiseAssert "no sale request"
without slotIndex =? data.slotIndex: let slot = Slot(request: request, slotIndex: data.slotIndex)
raiseAssert("no slot index assigned") debug "Removing slot from mySlots", requestId = $data.requestId, slotIndex = $data.slotIndex
let slot = Slot(request: request, slotIndex: slotIndex)
debug "Removing slot from mySlots", requestId = $data.requestId, slotIndex
await market.freeSlot(slot.id) await market.freeSlot(slot.id)
let error = newException(SaleFailedError, "Sale failed") let error = newException(SaleFailedError, "Sale failed")

View File

@ -29,19 +29,17 @@ method run*(state: SaleFilled, machine: Machine): Future[?State] {.async.} =
let agent = SalesAgent(machine) let agent = SalesAgent(machine)
let data = agent.data let data = agent.data
let context = agent.context let context = agent.context
let market = context.market let market = context.market
let host = await market.getHost(data.requestId, data.slotIndex)
without slotIndex =? data.slotIndex:
raiseAssert("no slot index assigned")
let host = await market.getHost(data.requestId, slotIndex)
let me = await market.getSigner() let me = await market.getSigner()
if host == me.some:
info "Slot succesfully filled", requestId = $data.requestId, slotIndex
if request =? data.request and slotIndex =? data.slotIndex: if host == me.some:
info "Slot succesfully filled", requestId = $data.requestId, slotIndex = $data.slotIndex
if request =? data.request:
if onFilled =? agent.onFilled: if onFilled =? agent.onFilled:
onFilled(request, slotIndex) onFilled(request, data.slotIndex)
when codex_enable_proof_failures: when codex_enable_proof_failures:
if context.simulateProofFailures > 0: if context.simulateProofFailures > 0:

View File

@ -32,8 +32,5 @@ method run(state: SaleFilling, machine: Machine): Future[?State] {.async.} =
without (collateral =? data.request.?ask.?collateral): without (collateral =? data.request.?ask.?collateral):
raiseAssert "Request not set" raiseAssert "Request not set"
without slotIndex =? data.slotIndex: debug "Filling slot", requestId = $data.requestId, slotIndex = $data.slotIndex
raiseAssert("no slot index assigned") await market.fillSlot(data.requestId, data.slotIndex, state.proof, collateral)
debug "Filling slot", requestId = $data.requestId, slotIndex
await market.fillSlot(data.requestId, slotIndex, state.proof, collateral)

View File

@ -27,10 +27,7 @@ method run*(state: SaleFinished, machine: Machine): Future[?State] {.async.} =
without request =? data.request: without request =? data.request:
raiseAssert "no sale request" raiseAssert "no sale request"
without slotIndex =? data.slotIndex: info "Slot finished and paid out", requestId = $data.requestId, slotIndex = $data.slotIndex
raiseAssert("no slot index assigned")
info "Slot finished and paid out", requestId = $data.requestId, slotIndex
if onCleanUp =? agent.onCleanUp: if onCleanUp =? agent.onCleanUp:
await onCleanUp() await onCleanUp()

View File

@ -30,11 +30,8 @@ method run*(state: SaleInitialProving, machine: Machine): Future[?State] {.async
without onProve =? context.onProve: without onProve =? context.onProve:
raiseAssert "onProve callback not set" raiseAssert "onProve callback not set"
without slotIndex =? data.slotIndex:
raiseAssert("no slot index assigned")
debug "Generating initial proof", requestId = $data.requestId debug "Generating initial proof", requestId = $data.requestId
let proof = await onProve(Slot(request: request, slotIndex: slotIndex)) let proof = await onProve(Slot(request: request, slotIndex: data.slotIndex))
debug "Finished proof calculation", requestId = $data.requestId debug "Finished proof calculation", requestId = $data.requestId
return some State(SaleFilling(proof: proof)) return some State(SaleFilling(proof: proof))

View File

@ -28,11 +28,8 @@ method run(state: SalePayout, machine: Machine): Future[?State] {.async.} =
without request =? data.request: without request =? data.request:
raiseAssert "no sale request" raiseAssert "no sale request"
without slotIndex =? data.slotIndex: let slot = Slot(request: request, slotIndex: data.slotIndex)
raiseAssert("no slot index assigned") debug "Collecting finished slot's reward", requestId = $data.requestId, slotIndex = $data.slotIndex
let slot = Slot(request: request, slotIndex: slotIndex)
debug "Collecting finished slot's reward", requestId = $data.requestId, slotIndex
await market.freeSlot(slot.id) await market.freeSlot(slot.id)
return some State(SaleFinished()) return some State(SaleFinished())

View File

@ -112,18 +112,15 @@ method run*(state: SaleProving, machine: Machine): Future[?State] {.async.} =
without onProve =? context.onProve: without onProve =? context.onProve:
raiseAssert "onProve callback not set" raiseAssert "onProve callback not set"
without slotIndex =? data.slotIndex:
raiseAssert("no slot index assigned")
without market =? context.market: without market =? context.market:
raiseAssert("market not set") raiseAssert("market not set")
without clock =? context.clock: without clock =? context.clock:
raiseAssert("clock not set") raiseAssert("clock not set")
debug "Start proving", requestId = $data.requestId, slotIndex debug "Start proving", requestId = $data.requestId, slotIndex = $data.slotIndex
try: try:
let loop = state.proveLoop(market, clock, request, slotIndex, onProve) let loop = state.proveLoop(market, clock, request, data.slotIndex, onProve)
state.loop = loop state.loop = loop
await loop await loop
except CancelledError: except CancelledError:
@ -133,7 +130,7 @@ method run*(state: SaleProving, machine: Machine): Future[?State] {.async.} =
return some State(SaleErrored(error: e)) return some State(SaleErrored(error: e))
finally: finally:
# Cleanup of the proving loop # Cleanup of the proving loop
debug "Stopping proving.", requestId = $data.requestId, slotIndex debug "Stopping proving.", requestId = $data.requestId, slotIndex = $data.slotIndex
if not state.loop.isNil: if not state.loop.isNil:
if not state.loop.finished: if not state.loop.finished:

View File

@ -32,14 +32,8 @@ method run*(state: SaleUnknown, machine: Machine): Future[?State] {.async.} =
await agent.retrieveRequest() await agent.retrieveRequest()
await agent.subscribe() await agent.subscribe()
without slotIndex =? data.slotIndex: let slotId = slotId(data.requestId, data.slotIndex)
raiseAssert("no slot index assigned") let slotState = await market.slotState(slotId)
let slotId = slotId(data.requestId, slotIndex)
without slotState =? await market.slotState(slotId):
let error = newException(SaleUnknownError, "cannot retrieve slot state")
return some State(SaleErrored(error: error))
case slotState case slotState
of SlotState.Free: of SlotState.Free:

View File

@ -83,8 +83,7 @@ asyncchecksuite "Reservations module":
test "reserved availability exists": test "reserved availability exists":
let availability = createAvailability() let availability = createAvailability()
without exists =? await reservations.exists(availability.key.get): let exists = await reservations.exists(availability.key.get)
fail()
check exists check exists

View File

@ -88,5 +88,4 @@ proc restart*(node: NodeProcess) =
node.waitUntilStarted() node.waitUntilStarted()
proc removeDataDir*(node: NodeProcess) = proc removeDataDir*(node: NodeProcess) =
if dataDir =? node.dataDir: removeDir(node.dataDir)
removeDir(dataDir)

View File

@ -22,7 +22,9 @@ import ./twonodes
twonodessuite "Integration tests", debug1 = false, debug2 = false: twonodessuite "Integration tests", debug1 = false, debug2 = false:
proc purchaseStateIs(client: CodexClient, id: PurchaseId, state: string): bool = proc purchaseStateIs(client: CodexClient, id: PurchaseId, state: string): bool =
client.getPurchase(id).option.?state == some state without purchase =? client.getPurchase(id):
return false
return purchase.state == state
setup: setup:
# Our Hardhat configuration does use automine, which means that time tracked by `provider.currentTime()` is not # Our Hardhat configuration does use automine, which means that time tracked by `provider.currentTime()` is not

2
vendor/questionable vendored

@ -1 +1 @@
Subproject commit e56cf86c4a089c78a1b7c3005f13343bfbbe3b48 Subproject commit 2dd6b6b220f9f14a1231f6cafdf24f012bcc8414