formatting

This commit is contained in:
thatben 2025-06-02 16:16:41 +02:00
parent 8b87f06ee2
commit 0228e7614f
No known key found for this signature in database
GPG Key ID: 62C543548433D43E
19 changed files with 194 additions and 67 deletions

View File

@ -18,7 +18,9 @@ type Application* = ref object
state: State state: State
components: seq[Component] components: seq[Component]
proc initializeApp(app: Application, config: Config): Future[?!void] {.async: (raises: [CancelledError]).} = proc initializeApp(
app: Application, config: Config
): Future[?!void] {.async: (raises: [CancelledError]).} =
app.state = State( app.state = State(
status: ApplicationStatus.Running, status: ApplicationStatus.Running,
config: config, config: config,

View File

@ -3,12 +3,16 @@ import pkg/questionable/results
type Component* = ref object of RootObj type Component* = ref object of RootObj
method awake*(c: Component): Future[?!void] {.async: (raises: [CancelledError]), base.} = method awake*(
c: Component
): Future[?!void] {.async: (raises: [CancelledError]), base.} =
# Awake is called on all components in an unspecified order. # Awake is called on all components in an unspecified order.
# Use this method to subscribe/connect to other components. # Use this method to subscribe/connect to other components.
return success() return success()
method start*(c: Component): Future[?!void] {.async: (raises: [CancelledError]), base.} = method start*(
c: Component
): Future[?!void] {.async: (raises: [CancelledError]), base.} =
# Start is called on all components in an unspecified order. # Start is called on all components in an unspecified order.
# Is is guaranteed that all components have already successfulled handled 'awake'. # Is is guaranteed that all components have already successfulled handled 'awake'.
# Use this method to begin the work of this component. # Use this method to begin the work of this component.

View File

@ -38,7 +38,9 @@ proc handleCheckEvent(
d.updateMetrics() d.updateMetrics()
return success() return success()
proc handleDeleteEvent(d: DhtMetrics, nids: seq[Nid]): Future[?!void] {.async: (raises: [CancelledError]).} = proc handleDeleteEvent(
d: DhtMetrics, nids: seq[Nid]
): Future[?!void] {.async: (raises: [CancelledError]).} =
for nid in nids: for nid in nids:
?await d.ok.remove(nid) ?await d.ok.remove(nid)
?await d.nok.remove(nid) ?await d.nok.remove(nid)
@ -46,7 +48,9 @@ proc handleDeleteEvent(d: DhtMetrics, nids: seq[Nid]): Future[?!void] {.async: (
return success() return success()
method awake*(d: DhtMetrics): Future[?!void] {.async: (raises: [CancelledError]).} = method awake*(d: DhtMetrics): Future[?!void] {.async: (raises: [CancelledError]).} =
proc onCheck(event: DhtNodeCheckEventData): Future[?!void] {.async: (raises: [CancelledError]).} = proc onCheck(
event: DhtNodeCheckEventData
): Future[?!void] {.async: (raises: [CancelledError]).} =
await d.handleCheckEvent(event) await d.handleCheckEvent(event)
proc onDelete(nids: seq[Nid]): Future[?!void] {.async: (raises: [CancelledError]).} = proc onDelete(nids: seq[Nid]): Future[?!void] {.async: (raises: [CancelledError]).} =

View File

@ -79,7 +79,9 @@ proc decode*(T: type NodeEntry, bytes: seq[byte]): ?!T =
except ValueError as err: except ValueError as err:
return failure(err.msg) return failure(err.msg)
proc storeNodeIsNew(s: NodeStore, nid: Nid): Future[?!bool] {.async: (raises: [CancelledError]).} = proc storeNodeIsNew(
s: NodeStore, nid: Nid
): Future[?!bool] {.async: (raises: [CancelledError]).} =
without key =? Key.init(nodestoreName / $nid), err: without key =? Key.init(nodestoreName / $nid), err:
error "failed to format key", err = err.msg error "failed to format key", err = err.msg
return failure(err) return failure(err)
@ -94,7 +96,9 @@ proc storeNodeIsNew(s: NodeStore, nid: Nid): Future[?!bool] {.async: (raises: [C
return success(not exists) return success(not exists)
proc fireNewNodesDiscovered(s: NodeStore, nids: seq[Nid]): Future[?!void] {.async: (raises: [CancelledError]).} = proc fireNewNodesDiscovered(
s: NodeStore, nids: seq[Nid]
): Future[?!void] {.async: (raises: [CancelledError]).} =
await s.state.events.newNodesDiscovered.fire(nids) await s.state.events.newNodesDiscovered.fire(nids)
proc fireNodesDeleted( proc fireNodesDeleted(
@ -102,7 +106,9 @@ proc fireNodesDeleted(
): Future[?!void] {.async: (raises: []).} = ): Future[?!void] {.async: (raises: []).} =
await s.state.events.nodesDeleted.fire(nids) await s.state.events.nodesDeleted.fire(nids)
proc processFoundNodes(s: NodeStore, nids: seq[Nid]): Future[?!void] {.async: (raises: [CancelledError]).} = proc processFoundNodes(
s: NodeStore, nids: seq[Nid]
): Future[?!void] {.async: (raises: [CancelledError]).} =
var newNodes = newSeq[Nid]() var newNodes = newSeq[Nid]()
for nid in nids: for nid in nids:
without isNew =? (await s.storeNodeIsNew(nid)), err: without isNew =? (await s.storeNodeIsNew(nid)), err:
@ -145,7 +151,9 @@ proc processNodeCheck(
?await s.store.put(key, entry) ?await s.store.put(key, entry)
return success() return success()
proc deleteEntry(s: NodeStore, nid: Nid): Future[?!bool] {.async: (raises: [CancelledError]).} = proc deleteEntry(
s: NodeStore, nid: Nid
): Future[?!bool] {.async: (raises: [CancelledError]).} =
without key =? Key.init(nodestoreName / $nid), err: without key =? Key.init(nodestoreName / $nid), err:
error "failed to format key", err = err.msg error "failed to format key", err = err.msg
return failure(err) return failure(err)
@ -208,10 +216,14 @@ method deleteEntries*(
method start*(s: NodeStore): Future[?!void] {.async: (raises: [CancelledError]).} = method start*(s: NodeStore): Future[?!void] {.async: (raises: [CancelledError]).} =
info "starting..." info "starting..."
proc onNodesFound(nids: seq[Nid]): Future[?!void] {.async: (raises: [CancelledError]).} = proc onNodesFound(
nids: seq[Nid]
): Future[?!void] {.async: (raises: [CancelledError]).} =
return await s.processFoundNodes(nids) return await s.processFoundNodes(nids)
proc onCheck(event: DhtNodeCheckEventData): Future[?!void] {.async: (raises: [CancelledError]).} = proc onCheck(
event: DhtNodeCheckEventData
): Future[?!void] {.async: (raises: [CancelledError]).} =
return await s.processNodeCheck(event) return await s.processNodeCheck(event)
s.subFound = s.state.events.nodesFound.subscribe(onNodesFound) s.subFound = s.state.events.nodesFound.subscribe(onNodesFound)

View File

@ -57,7 +57,9 @@ method pop*(t: TodoList): Future[?!Nid] {.async: (raises: []), base.} =
method awake*(t: TodoList): Future[?!void] {.async: (raises: [CancelledError]).} = method awake*(t: TodoList): Future[?!void] {.async: (raises: [CancelledError]).} =
info "initializing..." info "initializing..."
proc onNewNodes(nids: seq[Nid]): Future[?!void] {.async: (raises: [CancelledError]).} = proc onNewNodes(
nids: seq[Nid]
): Future[?!void] {.async: (raises: [CancelledError]).} =
t.addNodes(nids) t.addNodes(nids)
return success() return success()

View File

@ -18,7 +18,9 @@ import ./components/chainmetrics
import ./components/chaincrawler import ./components/chaincrawler
import ./components/requeststore import ./components/requeststore
proc createComponents*(state: State): Future[?!seq[Component]] {.async: (raises: [CancelledError]).} = proc createComponents*(
state: State
): Future[?!seq[Component]] {.async: (raises: [CancelledError]).} =
var components: seq[Component] = newSeq[Component]() var components: seq[Component] = newSeq[Component]()
let clock = createClock() let clock = createClock()

View File

@ -35,7 +35,9 @@ proc decode(T: type Nid, bytes: seq[byte]): ?!T =
except ValueError as err: except ValueError as err:
return failure(err.msg) return failure(err.msg)
proc saveItem(this: List, item: Nid): Future[?!void] {.async: (raises: [CancelledError]).} = proc saveItem(
this: List, item: Nid
): Future[?!void] {.async: (raises: [CancelledError]).} =
without itemKey =? Key.init(this.name / $item), err: without itemKey =? Key.init(this.name / $item), err:
return failure(err) return failure(err)
?await this.store.put(itemKey, item) ?await this.store.put(itemKey, item)
@ -61,7 +63,9 @@ method load*(this: List): Future[?!void] {.async: (raises: [CancelledError]), ba
proc contains*(this: List, nid: Nid): bool = proc contains*(this: List, nid: Nid): bool =
this.items.anyIt(it == nid) this.items.anyIt(it == nid)
method add*(this: List, nid: Nid): Future[?!void] {.async: (raises: [CancelledError]), base.} = method add*(
this: List, nid: Nid
): Future[?!void] {.async: (raises: [CancelledError]), base.} =
if this.contains(nid): if this.contains(nid):
return success() return success()
@ -72,7 +76,9 @@ method add*(this: List, nid: Nid): Future[?!void] {.async: (raises: [CancelledEr
return success() return success()
method remove*(this: List, nid: Nid): Future[?!void] {.async: (raises: [CancelledError]), base.} = method remove*(
this: List, nid: Nid
): Future[?!void] {.async: (raises: [CancelledError]), base.} =
if not this.contains(nid): if not this.contains(nid):
return success() return success()

View File

@ -75,7 +75,9 @@ method getNeighbors*(
except CatchableError as exc: except CatchableError as exc:
return failure(exc.msg) return failure(exc.msg)
proc findPeer*(d: Dht, peerId: PeerId): Future[?PeerRecord] {.async: (raises: [CancelledError]).} = proc findPeer*(
d: Dht, peerId: PeerId
): Future[?PeerRecord] {.async: (raises: [CancelledError]).} =
trace "protocol.resolve..." trace "protocol.resolve..."
try: try:
let node = await d.protocol.resolve(toNodeId(peerId)) let node = await d.protocol.resolve(toNodeId(peerId))

View File

@ -109,7 +109,9 @@ method getRequestInfo*(
else: else:
notStarted() notStarted()
method awake*(m: MarketplaceService): Future[?!void] {.async: (raises: [CancelledError]).} = method awake*(
m: MarketplaceService
): Future[?!void] {.async: (raises: [CancelledError]).} =
try: try:
let provider = JsonRpcProvider.new(m.state.config.ethProvider) let provider = JsonRpcProvider.new(m.state.config.ethProvider)
without marketplaceAddress =? Address.init(m.state.config.marketplaceAddress): without marketplaceAddress =? Address.init(m.state.config.marketplaceAddress):

View File

@ -123,7 +123,9 @@ proc config(
return resolvedConfig return resolvedConfig
proc approveFunds(market: OnChainMarket, amount: UInt256) {.async: (raises: [CancelledError]).} = proc approveFunds(
market: OnChainMarket, amount: UInt256
) {.async: (raises: [CancelledError]).} =
raiseAssert("Not available: approveFunds") raiseAssert("Not available: approveFunds")
proc getZkeyHash*( proc getZkeyHash*(
@ -140,43 +142,59 @@ proc periodicity*(
let period = config.proofs.period let period = config.proofs.period
return Periodicity(seconds: period) return Periodicity(seconds: period)
proc proofTimeout*(market: OnChainMarket): Future[uint64] {.async: (raises: [CancelledError, MarketError]).} = proc proofTimeout*(
market: OnChainMarket
): Future[uint64] {.async: (raises: [CancelledError, MarketError]).} =
convertEthersError: convertEthersError:
let config = await market.config() let config = await market.config()
return config.proofs.timeout return config.proofs.timeout
proc repairRewardPercentage*(market: OnChainMarket): Future[uint8] {.async: (raises: [CancelledError, MarketError]).} = proc repairRewardPercentage*(
market: OnChainMarket
): Future[uint8] {.async: (raises: [CancelledError, MarketError]).} =
convertEthersError: convertEthersError:
let config = await market.config() let config = await market.config()
return config.collateral.repairRewardPercentage return config.collateral.repairRewardPercentage
proc requestDurationLimit*(market: OnChainMarket): Future[uint64] {.async: (raises: [CancelledError, MarketError]).} = proc requestDurationLimit*(
market: OnChainMarket
): Future[uint64] {.async: (raises: [CancelledError, MarketError]).} =
convertEthersError: convertEthersError:
let config = await market.config() let config = await market.config()
return config.requestDurationLimit return config.requestDurationLimit
proc proofDowntime*(market: OnChainMarket): Future[uint8] {.async: (raises: [CancelledError, MarketError]).} = proc proofDowntime*(
market: OnChainMarket
): Future[uint8] {.async: (raises: [CancelledError, MarketError]).} =
convertEthersError: convertEthersError:
let config = await market.config() let config = await market.config()
return config.proofs.downtime return config.proofs.downtime
proc getPointer*(market: OnChainMarket, slotId: SlotId): Future[uint8] {.async: (raises: [CancelledError, MarketError]).} = proc getPointer*(
market: OnChainMarket, slotId: SlotId
): Future[uint8] {.async: (raises: [CancelledError, MarketError]).} =
convertEthersError: convertEthersError:
let overrides = CallOverrides(blockTag: some BlockTag.pending) let overrides = CallOverrides(blockTag: some BlockTag.pending)
return await market.contract.getPointer(slotId, overrides) return await market.contract.getPointer(slotId, overrides)
proc myRequests*(market: OnChainMarket): Future[seq[RequestId]] {.async: (raises: [CancelledError, MarketError]).} = proc myRequests*(
market: OnChainMarket
): Future[seq[RequestId]] {.async: (raises: [CancelledError, MarketError]).} =
convertEthersError: convertEthersError:
return await market.contract.myRequests return await market.contract.myRequests
proc mySlots*(market: OnChainMarket): Future[seq[SlotId]] {.async: (raises: [CancelledError, MarketError]).} = proc mySlots*(
market: OnChainMarket
): Future[seq[SlotId]] {.async: (raises: [CancelledError, MarketError]).} =
convertEthersError: convertEthersError:
let slots = await market.contract.mySlots() let slots = await market.contract.mySlots()
debug "Fetched my slots", numSlots = len(slots) debug "Fetched my slots", numSlots = len(slots)
return slots return slots
proc requestStorage(market: OnChainMarket, request: StorageRequest) {.async: (raises: [CancelledError, MarketError]).} = proc requestStorage(
market: OnChainMarket, request: StorageRequest
) {.async: (raises: [CancelledError, MarketError]).} =
convertEthersError: convertEthersError:
debug "Requesting storage" debug "Requesting storage"
await market.approveFunds(request.totalPrice()) await market.approveFunds(request.totalPrice())
@ -204,16 +222,22 @@ proc requestState*(
except Marketplace_UnknownRequest: except Marketplace_UnknownRequest:
return none RequestState return none RequestState
proc slotState*(market: OnChainMarket, slotId: SlotId): Future[SlotState] {.async: (raises: [CancelledError, MarketError]).} = proc slotState*(
market: OnChainMarket, slotId: SlotId
): Future[SlotState] {.async: (raises: [CancelledError, MarketError]).} =
convertEthersError: convertEthersError:
let overrides = CallOverrides(blockTag: some BlockTag.pending) let overrides = CallOverrides(blockTag: some BlockTag.pending)
return await market.contract.slotState(slotId, overrides) return await market.contract.slotState(slotId, overrides)
proc getRequestEnd*(market: OnChainMarket, id: RequestId): Future[uint64] {.async: (raises: [CancelledError, MarketError]).} = proc getRequestEnd*(
market: OnChainMarket, id: RequestId
): Future[uint64] {.async: (raises: [CancelledError, MarketError]).} =
convertEthersError: convertEthersError:
return (await market.contract.requestEnd(id)).uint64 return (await market.contract.requestEnd(id)).uint64
proc requestExpiresAt*(market: OnChainMarket, id: RequestId): Future[uint64] {.async: (raises: [CancelledError, MarketError]).} = proc requestExpiresAt*(
market: OnChainMarket, id: RequestId
): Future[uint64] {.async: (raises: [CancelledError, MarketError]).} =
convertEthersError: convertEthersError:
return (await market.contract.requestExpiry(id)).uint64 return (await market.contract.requestExpiry(id)).uint64
@ -234,7 +258,9 @@ proc currentCollateral*(
convertEthersError: convertEthersError:
return await market.contract.currentCollateral(slotId) return await market.contract.currentCollateral(slotId)
proc getActiveSlot*(market: OnChainMarket, slotId: SlotId): Future[?Slot] {.async: (raises: [CancelledError, MarketError]).} = proc getActiveSlot*(
market: OnChainMarket, slotId: SlotId
): Future[?Slot] {.async: (raises: [CancelledError, MarketError]).} =
convertEthersError: convertEthersError:
try: try:
return some await market.contract.getActiveSlot(slotId) return some await market.contract.getActiveSlot(slotId)
@ -258,14 +284,20 @@ proc fillSlot(
discard await market.contract.fillSlot(requestId, slotIndex, proof).confirm(1) discard await market.contract.fillSlot(requestId, slotIndex, proof).confirm(1)
trace "fillSlot transaction completed" trace "fillSlot transaction completed"
proc freeSlot*(market: OnChainMarket, slotId: SlotId) {.async: (raises: [CancelledError]).} = proc freeSlot*(
market: OnChainMarket, slotId: SlotId
) {.async: (raises: [CancelledError]).} =
raiseAssert("Not supported") raiseAssert("Not supported")
proc withdrawFunds(market: OnChainMarket, requestId: RequestId) {.async: (raises: [CancelledError, MarketError]).} = proc withdrawFunds(
market: OnChainMarket, requestId: RequestId
) {.async: (raises: [CancelledError, MarketError]).} =
convertEthersError: convertEthersError:
discard await market.contract.withdrawFunds(requestId).confirm(1) discard await market.contract.withdrawFunds(requestId).confirm(1)
proc isProofRequired*(market: OnChainMarket, id: SlotId): Future[bool] {.async: (raises: [CancelledError, MarketError]).} = proc isProofRequired*(
market: OnChainMarket, id: SlotId
): Future[bool] {.async: (raises: [CancelledError, MarketError]).} =
convertEthersError: convertEthersError:
try: try:
let overrides = CallOverrides(blockTag: some BlockTag.pending) let overrides = CallOverrides(blockTag: some BlockTag.pending)
@ -273,7 +305,9 @@ proc isProofRequired*(market: OnChainMarket, id: SlotId): Future[bool] {.async:
except Marketplace_SlotIsFree: except Marketplace_SlotIsFree:
return false return false
proc willProofBeRequired*(market: OnChainMarket, id: SlotId): Future[bool] {.async: (raises: [CancelledError, MarketError]).} = proc willProofBeRequired*(
market: OnChainMarket, id: SlotId
): Future[bool] {.async: (raises: [CancelledError, MarketError]).} =
convertEthersError: convertEthersError:
try: try:
let overrides = CallOverrides(blockTag: some BlockTag.pending) let overrides = CallOverrides(blockTag: some BlockTag.pending)
@ -288,11 +322,15 @@ proc getChallenge*(
let overrides = CallOverrides(blockTag: some BlockTag.pending) let overrides = CallOverrides(blockTag: some BlockTag.pending)
return await market.contract.getChallenge(id, overrides) return await market.contract.getChallenge(id, overrides)
proc submitProof*(market: OnChainMarket, id: SlotId, proof: Groth16Proof) {.async: (raises: [CancelledError, MarketError]).} = proc submitProof*(
market: OnChainMarket, id: SlotId, proof: Groth16Proof
) {.async: (raises: [CancelledError, MarketError]).} =
convertEthersError: convertEthersError:
discard await market.contract.submitProof(id, proof).confirm(1) discard await market.contract.submitProof(id, proof).confirm(1)
proc markProofAsMissing*(market: OnChainMarket, id: SlotId, period: Period) {.async: (raises: [CancelledError, MarketError]).} = proc markProofAsMissing*(
market: OnChainMarket, id: SlotId, period: Period
) {.async: (raises: [CancelledError, MarketError]).} =
convertEthersError: convertEthersError:
discard await market.contract.markProofAsMissing(id, period).confirm(1) discard await market.contract.markProofAsMissing(id, period).confirm(1)
@ -499,7 +537,9 @@ proc subscribeProofSubmission*(
let subscription = await market.contract.subscribe(ProofSubmitted, onEvent) let subscription = await market.contract.subscribe(ProofSubmitted, onEvent)
return OnChainMarketSubscription(eventSubscription: subscription) return OnChainMarketSubscription(eventSubscription: subscription)
proc unsubscribe*(subscription: OnChainMarketSubscription) {.async: (raises: [CancelledError, MarketError]).} = proc unsubscribe*(
subscription: OnChainMarketSubscription
) {.async: (raises: [CancelledError, MarketError]).} =
try: try:
await subscription.eventSubscription.unsubscribe() await subscription.eventSubscription.unsubscribe()
except ProviderError as err: except ProviderError as err:

View File

@ -33,7 +33,9 @@ type
config*: Config config*: Config
events*: Events events*: Events
proc delayedWorkerStart(s: State, step: OnStep, delay: Duration) {.async: (raises: [CancelledError]).} = proc delayedWorkerStart(
s: State, step: OnStep, delay: Duration
) {.async: (raises: [CancelledError]).} =
await sleepAsync(1.seconds) await sleepAsync(1.seconds)
proc worker(): Future[void] {.async: (raises: [CancelledError]).} = proc worker(): Future[void] {.async: (raises: [CancelledError]).} =
@ -45,7 +47,9 @@ proc delayedWorkerStart(s: State, step: OnStep, delay: Duration) {.async: (raise
asyncSpawn worker() asyncSpawn worker()
method whileRunning*(s: State, step: OnStep, delay: Duration) {.async: (raises: []), base.} = method whileRunning*(
s: State, step: OnStep, delay: Duration
) {.async: (raises: []), base.} =
# We use a small delay before starting the workers because 'whileRunning' is likely called from # We use a small delay before starting the workers because 'whileRunning' is likely called from
# component 'start' methods, which are executed sequentially in arbitrary order (to prevent temporal coupling). # component 'start' methods, which are executed sequentially in arbitrary order (to prevent temporal coupling).
# Worker steps might start raising events that other components haven't had time to subscribe to yet. # Worker steps might start raising events that other components haven't had time to subscribe to yet.

View File

@ -15,7 +15,8 @@ type
queue: AsyncEventQueue[?T] queue: AsyncEventQueue[?T]
subscriptions: seq[AsyncDataEventSubscription] subscriptions: seq[AsyncDataEventSubscription]
AsyncDataEventHandler*[T] = proc(data: T): Future[?!void] {.gcsafe, async: (raises: [CancelledError]).} AsyncDataEventHandler*[T] =
proc(data: T): Future[?!void] {.gcsafe, async: (raises: [CancelledError]).}
proc newAsyncDataEvent*[T](): AsyncDataEvent[T] = proc newAsyncDataEvent*[T](): AsyncDataEvent[T] =
AsyncDataEvent[T]( AsyncDataEvent[T](
@ -90,7 +91,9 @@ proc unsubscribe*[T](
else: else:
await event.performUnsubscribe(subscription) await event.performUnsubscribe(subscription)
proc unsubscribeAll*[T](event: AsyncDataEvent[T]) {.async: (raises: [CancelledError]).} = proc unsubscribeAll*[T](
event: AsyncDataEvent[T]
) {.async: (raises: [CancelledError]).} =
let all = event.subscriptions let all = event.subscriptions
for subscription in all: for subscription in all:
await event.unsubscribe(subscription) await event.unsubscribe(subscription)

View File

@ -71,7 +71,9 @@ suite "DhtCrawler":
test "nodes returned by getNeighbors are raised as nodesFound": test "nodes returned by getNeighbors are raised as nodesFound":
var nodesFound = newSeq[Nid]() var nodesFound = newSeq[Nid]()
proc onNodesFound(nids: seq[Nid]): Future[?!void] {.async: (raises: [CancelledError]).} = proc onNodesFound(
nids: seq[Nid]
): Future[?!void] {.async: (raises: [CancelledError]).} =
nodesFound = nids nodesFound = nids
return success() return success()
@ -89,7 +91,9 @@ suite "DhtCrawler":
test "responsive result from getNeighbors raises the node as successful dhtNodeCheck": test "responsive result from getNeighbors raises the node as successful dhtNodeCheck":
var checkEvent = DhtNodeCheckEventData() var checkEvent = DhtNodeCheckEventData()
proc onCheck(event: DhtNodeCheckEventData): Future[?!void] {.async: (raises: [CancelledError]).} = proc onCheck(
event: DhtNodeCheckEventData
): Future[?!void] {.async: (raises: [CancelledError]).} =
checkEvent = event checkEvent = event
return success() return success()
@ -108,7 +112,9 @@ suite "DhtCrawler":
test "unresponsive result from getNeighbors raises the node as unsuccessful dhtNodeCheck": test "unresponsive result from getNeighbors raises the node as unsuccessful dhtNodeCheck":
var checkEvent = DhtNodeCheckEventData() var checkEvent = DhtNodeCheckEventData()
proc onCheck(event: DhtNodeCheckEventData): Future[?!void] {.async: (raises: [CancelledError]).} = proc onCheck(
event: DhtNodeCheckEventData
): Future[?!void] {.async: (raises: [CancelledError]).} =
checkEvent = event checkEvent = event
return success() return success()

View File

@ -79,7 +79,9 @@ suite "Nodestore":
test "nodesFound event should fire newNodesDiscovered": test "nodesFound event should fire newNodesDiscovered":
var newNodes = newSeq[Nid]() var newNodes = newSeq[Nid]()
proc onNewNodes(nids: seq[Nid]): Future[?!void] {.async: (raises: [CancelledError]).} = proc onNewNodes(
nids: seq[Nid]
): Future[?!void] {.async: (raises: [CancelledError]).} =
newNodes = nids newNodes = nids
return success() return success()
@ -103,7 +105,9 @@ suite "Nodestore":
var var
newNodes = newSeq[Nid]() newNodes = newSeq[Nid]()
count = 0 count = 0
proc onNewNodes(nids: seq[Nid]): Future[?!void] {.async: (raises: [CancelledError]).} = proc onNewNodes(
nids: seq[Nid]
): Future[?!void] {.async: (raises: [CancelledError]).} =
newNodes = nids newNodes = nids
inc count inc count
return success() return success()
@ -181,7 +185,9 @@ suite "Nodestore":
test "deleteEntries fires nodesDeleted event": test "deleteEntries fires nodesDeleted event":
var deletedNodes = newSeq[Nid]() var deletedNodes = newSeq[Nid]()
proc onDeleted(nids: seq[Nid]): Future[?!void] {.async: (raises: [CancelledError]).} = proc onDeleted(
nids: seq[Nid]
): Future[?!void] {.async: (raises: [CancelledError]).} =
deletedNodes = nids deletedNodes = nids
return success() return success()
@ -251,7 +257,9 @@ suite "Nodestore":
test "dhtNodeCheck event for non-existing node should fire nodesDeleted": test "dhtNodeCheck event for non-existing node should fire nodesDeleted":
var deletedNodes = newSeq[Nid]() var deletedNodes = newSeq[Nid]()
proc onDeleted(nids: seq[Nid]): Future[?!void] {.async: (raises: [CancelledError]).} = proc onDeleted(
nids: seq[Nid]
): Future[?!void] {.async: (raises: [CancelledError]).} =
deletedNodes = nids deletedNodes = nids
return success() return success()

View File

@ -37,7 +37,9 @@ suite "TimeTracker":
# Subscribe to nodesToRevisit event # Subscribe to nodesToRevisit event
nodesToRevisitReceived = newSeq[Nid]() nodesToRevisitReceived = newSeq[Nid]()
proc onToRevisit(nids: seq[Nid]): Future[?!void] {.async: (raises: [CancelledError]).} = proc onToRevisit(
nids: seq[Nid]
): Future[?!void] {.async: (raises: [CancelledError]).} =
nodesToRevisitReceived = nids nodesToRevisitReceived = nids
return success() return success()
@ -126,7 +128,9 @@ suite "TimeTracker":
test "onStep raises routingTable nodes as nodesFound": test "onStep raises routingTable nodes as nodesFound":
var nodesFound = newSeq[Nid]() var nodesFound = newSeq[Nid]()
proc onNodesFound(nids: seq[Nid]): Future[?!void] {.async: (raises: [CancelledError]).} = proc onNodesFound(
nids: seq[Nid]
): Future[?!void] {.async: (raises: [CancelledError]).} =
nodesFound = nids nodesFound = nids
return success() return success()

View File

@ -16,13 +16,17 @@ method load*(this: MockList): Future[?!void] {.async: (raises: [CancelledError])
this.loadCalled = true this.loadCalled = true
return success() return success()
method add*(this: MockList, nid: Nid): Future[?!void] {.async: (raises: [CancelledError]).} = method add*(
this: MockList, nid: Nid
): Future[?!void] {.async: (raises: [CancelledError]).} =
this.added.add(nid) this.added.add(nid)
if this.addSuccess: if this.addSuccess:
return success() return success()
return failure("test failure") return failure("test failure")
method remove*(this: MockList, nid: Nid): Future[?!void] {.async: (raises: [CancelledError]).} = method remove*(
this: MockList, nid: Nid
): Future[?!void] {.async: (raises: [CancelledError]).} =
this.removed.add(nid) this.removed.add(nid)
if this.removeSuccess: if this.removeSuccess:
return success() return success()

View File

@ -15,7 +15,9 @@ proc checkAllUnsubscribed*(s: MockState) =
s.events.dhtNodeCheck.listeners == 0 s.events.dhtNodeCheck.listeners == 0
s.events.nodesToRevisit.listeners == 0 s.events.nodesToRevisit.listeners == 0
method whileRunning*(s: MockState, step: OnStep, delay: Duration) {.async: (raises: []).} = method whileRunning*(
s: MockState, step: OnStep, delay: Duration
) {.async: (raises: []).} =
s.steppers.add(step) s.steppers.add(step)
s.delays.add(delay) s.delays.add(delay)

View File

@ -20,7 +20,9 @@ suite "AsyncDataEvent":
test "Successful event": test "Successful event":
var data = "" var data = ""
proc eventHandler(e: ExampleData): Future[?!void] {.async: (raises: [CancelledError]).} = proc eventHandler(
e: ExampleData
): Future[?!void] {.async: (raises: [CancelledError]).} =
data = e.s data = e.s
success() success()
@ -34,7 +36,9 @@ suite "AsyncDataEvent":
test "Multiple events": test "Multiple events":
var counter = 0 var counter = 0
proc eventHandler(e: ExampleData): Future[?!void] {.async: (raises: [CancelledError]).} = proc eventHandler(
e: ExampleData
): Future[?!void] {.async: (raises: [CancelledError]).} =
inc counter inc counter
success() success()
@ -54,15 +58,21 @@ suite "AsyncDataEvent":
data1 = "" data1 = ""
data2 = "" data2 = ""
data3 = "" data3 = ""
proc eventHandler1(e: ExampleData): Future[?!void] {.async: (raises: [CancelledError]).} = proc eventHandler1(
e: ExampleData
): Future[?!void] {.async: (raises: [CancelledError]).} =
data1 = e.s data1 = e.s
success() success()
proc eventHandler2(e: ExampleData): Future[?!void] {.async: (raises: [CancelledError]).} = proc eventHandler2(
e: ExampleData
): Future[?!void] {.async: (raises: [CancelledError]).} =
data2 = e.s data2 = e.s
success() success()
proc eventHandler3(e: ExampleData): Future[?!void] {.async: (raises: [CancelledError]).} = proc eventHandler3(
e: ExampleData
): Future[?!void] {.async: (raises: [CancelledError]).} =
data3 = e.s data3 = e.s
success() success()
@ -82,7 +92,9 @@ suite "AsyncDataEvent":
await event.unsubscribe(sub3) await event.unsubscribe(sub3)
test "Failed event preserves error message": test "Failed event preserves error message":
proc eventHandler(e: ExampleData): Future[?!void] {.async: (raises: [CancelledError]).} = proc eventHandler(
e: ExampleData
): Future[?!void] {.async: (raises: [CancelledError]).} =
failure(msg) failure(msg)
let s = event.subscribe(eventHandler) let s = event.subscribe(eventHandler)
@ -100,15 +112,21 @@ suite "AsyncDataEvent":
data2 = "" data2 = ""
data3 = "" data3 = ""
proc handler1(e: ExampleData): Future[?!void] {.async: (raises: [CancelledError]).} = proc handler1(
e: ExampleData
): Future[?!void] {.async: (raises: [CancelledError]).} =
data1 = e.s data1 = e.s
success() success()
proc handler2(e: ExampleData): Future[?!void] {.async: (raises: [CancelledError]).} = proc handler2(
e: ExampleData
): Future[?!void] {.async: (raises: [CancelledError]).} =
data2 = e.s data2 = e.s
success() success()
proc handler3(e: ExampleData): Future[?!void] {.async: (raises: [CancelledError]).} = proc handler3(
e: ExampleData
): Future[?!void] {.async: (raises: [CancelledError]).} =
data3 = e.s data3 = e.s
success() success()
@ -139,7 +157,9 @@ suite "AsyncDataEvent":
var callback = doNothing var callback = doNothing
proc eventHandler(e: ExampleData): Future[?!void] {.async: (raises: [CancelledError]).} = proc eventHandler(
e: ExampleData
): Future[?!void] {.async: (raises: [CancelledError]).} =
await callback() await callback()
success() success()