diff --git a/codexcrawler/application.nim b/codexcrawler/application.nim index d3b34dd..889b054 100644 --- a/codexcrawler/application.nim +++ b/codexcrawler/application.nim @@ -18,7 +18,9 @@ type Application* = ref object state: State 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( status: ApplicationStatus.Running, config: config, diff --git a/codexcrawler/component.nim b/codexcrawler/component.nim index 623e757..9be452c 100644 --- a/codexcrawler/component.nim +++ b/codexcrawler/component.nim @@ -3,12 +3,16 @@ import pkg/questionable/results 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. # Use this method to subscribe/connect to other components. 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. # Is is guaranteed that all components have already successfulled handled 'awake'. # Use this method to begin the work of this component. diff --git a/codexcrawler/components/dhtmetrics.nim b/codexcrawler/components/dhtmetrics.nim index 54d4d33..847e1b2 100644 --- a/codexcrawler/components/dhtmetrics.nim +++ b/codexcrawler/components/dhtmetrics.nim @@ -38,7 +38,9 @@ proc handleCheckEvent( d.updateMetrics() 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: ?await d.ok.remove(nid) ?await d.nok.remove(nid) @@ -46,7 +48,9 @@ proc handleDeleteEvent(d: DhtMetrics, nids: seq[Nid]): Future[?!void] {.async: ( return success() 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) proc onDelete(nids: seq[Nid]): Future[?!void] {.async: (raises: [CancelledError]).} = diff --git a/codexcrawler/components/nodestore.nim b/codexcrawler/components/nodestore.nim index 7d68fbe..e502428 100644 --- a/codexcrawler/components/nodestore.nim +++ b/codexcrawler/components/nodestore.nim @@ -79,7 +79,9 @@ proc decode*(T: type NodeEntry, bytes: seq[byte]): ?!T = except ValueError as err: 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: error "failed to format key", err = err.msg return failure(err) @@ -94,7 +96,9 @@ proc storeNodeIsNew(s: NodeStore, nid: Nid): Future[?!bool] {.async: (raises: [C 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) proc fireNodesDeleted( @@ -102,7 +106,9 @@ proc fireNodesDeleted( ): Future[?!void] {.async: (raises: []).} = 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]() for nid in nids: without isNew =? (await s.storeNodeIsNew(nid)), err: @@ -145,7 +151,9 @@ proc processNodeCheck( ?await s.store.put(key, entry) 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: error "failed to format key", err = err.msg return failure(err) @@ -208,10 +216,14 @@ method deleteEntries*( method start*(s: NodeStore): Future[?!void] {.async: (raises: [CancelledError]).} = 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) - proc onCheck(event: DhtNodeCheckEventData): Future[?!void] {.async: (raises: [CancelledError]).} = + proc onCheck( + event: DhtNodeCheckEventData + ): Future[?!void] {.async: (raises: [CancelledError]).} = return await s.processNodeCheck(event) s.subFound = s.state.events.nodesFound.subscribe(onNodesFound) diff --git a/codexcrawler/components/todolist.nim b/codexcrawler/components/todolist.nim index 2d4093e..8e9beca 100644 --- a/codexcrawler/components/todolist.nim +++ b/codexcrawler/components/todolist.nim @@ -57,7 +57,9 @@ method pop*(t: TodoList): Future[?!Nid] {.async: (raises: []), base.} = method awake*(t: TodoList): Future[?!void] {.async: (raises: [CancelledError]).} = 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) return success() diff --git a/codexcrawler/installer.nim b/codexcrawler/installer.nim index e8a12f1..a29a836 100644 --- a/codexcrawler/installer.nim +++ b/codexcrawler/installer.nim @@ -18,7 +18,9 @@ import ./components/chainmetrics import ./components/chaincrawler 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]() let clock = createClock() diff --git a/codexcrawler/list.nim b/codexcrawler/list.nim index d19ebdf..8587dc4 100644 --- a/codexcrawler/list.nim +++ b/codexcrawler/list.nim @@ -35,7 +35,9 @@ proc decode(T: type Nid, bytes: seq[byte]): ?!T = except ValueError as err: 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: return failure(err) ?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 = 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): return success() @@ -72,7 +76,9 @@ method add*(this: List, nid: Nid): Future[?!void] {.async: (raises: [CancelledEr 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): return success() diff --git a/codexcrawler/services/dht.nim b/codexcrawler/services/dht.nim index 254f3a3..19d6661 100644 --- a/codexcrawler/services/dht.nim +++ b/codexcrawler/services/dht.nim @@ -75,7 +75,9 @@ method getNeighbors*( except CatchableError as exc: 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..." try: let node = await d.protocol.resolve(toNodeId(peerId)) diff --git a/codexcrawler/services/marketplace.nim b/codexcrawler/services/marketplace.nim index fd2c4f3..08819f8 100644 --- a/codexcrawler/services/marketplace.nim +++ b/codexcrawler/services/marketplace.nim @@ -109,7 +109,9 @@ method getRequestInfo*( else: notStarted() -method awake*(m: MarketplaceService): Future[?!void] {.async: (raises: [CancelledError]).} = +method awake*( + m: MarketplaceService +): Future[?!void] {.async: (raises: [CancelledError]).} = try: let provider = JsonRpcProvider.new(m.state.config.ethProvider) without marketplaceAddress =? Address.init(m.state.config.marketplaceAddress): diff --git a/codexcrawler/services/marketplace/market.nim b/codexcrawler/services/marketplace/market.nim index 4dfc501..f0a2f0b 100644 --- a/codexcrawler/services/marketplace/market.nim +++ b/codexcrawler/services/marketplace/market.nim @@ -123,7 +123,9 @@ proc config( return resolvedConfig -proc approveFunds(market: OnChainMarket, amount: UInt256) {.async: (raises: [CancelledError]).} = +proc approveFunds( + market: OnChainMarket, amount: UInt256 +) {.async: (raises: [CancelledError]).} = raiseAssert("Not available: approveFunds") proc getZkeyHash*( @@ -140,43 +142,59 @@ proc periodicity*( let period = config.proofs.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: let config = await market.config() 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: let config = await market.config() 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: let config = await market.config() return config.requestDurationLimit -proc proofDowntime*(market: OnChainMarket): Future[uint8] {.async: (raises: [CancelledError, MarketError]).} = +proc proofDowntime*( + market: OnChainMarket +): Future[uint8] {.async: (raises: [CancelledError, MarketError]).} = convertEthersError: let config = await market.config() 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: let overrides = CallOverrides(blockTag: some BlockTag.pending) 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: 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: let slots = await market.contract.mySlots() debug "Fetched my slots", numSlots = len(slots) return slots -proc requestStorage(market: OnChainMarket, request: StorageRequest) {.async: (raises: [CancelledError, MarketError]).} = +proc requestStorage( + market: OnChainMarket, request: StorageRequest +) {.async: (raises: [CancelledError, MarketError]).} = convertEthersError: debug "Requesting storage" await market.approveFunds(request.totalPrice()) @@ -204,16 +222,22 @@ proc requestState*( except Marketplace_UnknownRequest: 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: let overrides = CallOverrides(blockTag: some BlockTag.pending) 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: 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: return (await market.contract.requestExpiry(id)).uint64 @@ -234,7 +258,9 @@ proc currentCollateral*( convertEthersError: 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: try: return some await market.contract.getActiveSlot(slotId) @@ -258,14 +284,20 @@ proc fillSlot( discard await market.contract.fillSlot(requestId, slotIndex, proof).confirm(1) 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") -proc withdrawFunds(market: OnChainMarket, requestId: RequestId) {.async: (raises: [CancelledError, MarketError]).} = +proc withdrawFunds( + market: OnChainMarket, requestId: RequestId +) {.async: (raises: [CancelledError, MarketError]).} = convertEthersError: 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: try: let overrides = CallOverrides(blockTag: some BlockTag.pending) @@ -273,7 +305,9 @@ proc isProofRequired*(market: OnChainMarket, id: SlotId): Future[bool] {.async: except Marketplace_SlotIsFree: 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: try: let overrides = CallOverrides(blockTag: some BlockTag.pending) @@ -288,11 +322,15 @@ proc getChallenge*( let overrides = CallOverrides(blockTag: some BlockTag.pending) 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: 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: discard await market.contract.markProofAsMissing(id, period).confirm(1) @@ -499,11 +537,13 @@ proc subscribeProofSubmission*( let subscription = await market.contract.subscribe(ProofSubmitted, onEvent) return OnChainMarketSubscription(eventSubscription: subscription) -proc unsubscribe*(subscription: OnChainMarketSubscription) {.async: (raises: [CancelledError, MarketError]).} = +proc unsubscribe*( + subscription: OnChainMarketSubscription +) {.async: (raises: [CancelledError, MarketError]).} = try: await subscription.eventSubscription.unsubscribe() except ProviderError as err: - raiseMarketError(err.msg) + raiseMarketError(err.msg) proc queryPastSlotFilledEvents*( market: OnChainMarket, fromBlock: BlockTag diff --git a/codexcrawler/state.nim b/codexcrawler/state.nim index f29d6e1..d0d8056 100644 --- a/codexcrawler/state.nim +++ b/codexcrawler/state.nim @@ -33,7 +33,9 @@ type config*: Config 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) proc worker(): Future[void] {.async: (raises: [CancelledError]).} = @@ -45,7 +47,9 @@ proc delayedWorkerStart(s: State, step: OnStep, delay: Duration) {.async: (raise 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 # 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. diff --git a/codexcrawler/utils/asyncdataevent.nim b/codexcrawler/utils/asyncdataevent.nim index 823871f..8a47838 100644 --- a/codexcrawler/utils/asyncdataevent.nim +++ b/codexcrawler/utils/asyncdataevent.nim @@ -15,7 +15,8 @@ type queue: AsyncEventQueue[?T] 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] = AsyncDataEvent[T]( @@ -90,7 +91,9 @@ proc unsubscribe*[T]( else: 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 for subscription in all: await event.unsubscribe(subscription) diff --git a/tests/codexcrawler/components/testchainmetrics.nim b/tests/codexcrawler/components/testchainmetrics.nim index e1450b7..cbeec8c 100644 --- a/tests/codexcrawler/components/testchainmetrics.nim +++ b/tests/codexcrawler/components/testchainmetrics.nim @@ -39,7 +39,7 @@ suite "ChainMetrics": (await state.steppers[0]()).tryGet() except CatchableError: raiseAssert("CatchableError in onStep") - + test "start should start stepper for config.requestCheckDelay minutes": check: state.delays.len == 1 diff --git a/tests/codexcrawler/components/testdhtcrawler.nim b/tests/codexcrawler/components/testdhtcrawler.nim index 3b2616e..1c38697 100644 --- a/tests/codexcrawler/components/testdhtcrawler.nim +++ b/tests/codexcrawler/components/testdhtcrawler.nim @@ -40,7 +40,7 @@ suite "DhtCrawler": (await state.steppers[0]()).tryGet() except CatchableError: raiseAssert("CatchableError in onStep") - + proc responsive(nid: Nid): GetNeighborsResponse = GetNeighborsResponse(isResponsive: true, nodeIds: @[nid]) @@ -71,7 +71,9 @@ suite "DhtCrawler": test "nodes returned by getNeighbors are raised as nodesFound": 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 return success() @@ -89,7 +91,9 @@ suite "DhtCrawler": test "responsive result from getNeighbors raises the node as successful dhtNodeCheck": var checkEvent = DhtNodeCheckEventData() - proc onCheck(event: DhtNodeCheckEventData): Future[?!void] {.async: (raises: [CancelledError]).} = + proc onCheck( + event: DhtNodeCheckEventData + ): Future[?!void] {.async: (raises: [CancelledError]).} = checkEvent = event return success() @@ -108,7 +112,9 @@ suite "DhtCrawler": test "unresponsive result from getNeighbors raises the node as unsuccessful dhtNodeCheck": var checkEvent = DhtNodeCheckEventData() - proc onCheck(event: DhtNodeCheckEventData): Future[?!void] {.async: (raises: [CancelledError]).} = + proc onCheck( + event: DhtNodeCheckEventData + ): Future[?!void] {.async: (raises: [CancelledError]).} = checkEvent = event return success() diff --git a/tests/codexcrawler/components/testnodestore.nim b/tests/codexcrawler/components/testnodestore.nim index dc05e8a..29709fb 100644 --- a/tests/codexcrawler/components/testnodestore.nim +++ b/tests/codexcrawler/components/testnodestore.nim @@ -79,7 +79,9 @@ suite "Nodestore": test "nodesFound event should fire newNodesDiscovered": 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 return success() @@ -103,7 +105,9 @@ suite "Nodestore": var newNodes = newSeq[Nid]() count = 0 - proc onNewNodes(nids: seq[Nid]): Future[?!void] {.async: (raises: [CancelledError]).} = + proc onNewNodes( + nids: seq[Nid] + ): Future[?!void] {.async: (raises: [CancelledError]).} = newNodes = nids inc count return success() @@ -181,7 +185,9 @@ suite "Nodestore": test "deleteEntries fires nodesDeleted event": 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 return success() @@ -251,7 +257,9 @@ suite "Nodestore": test "dhtNodeCheck event for non-existing node should fire nodesDeleted": 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 return success() diff --git a/tests/codexcrawler/components/testtimetracker.nim b/tests/codexcrawler/components/testtimetracker.nim index 59c09eb..fa2421e 100644 --- a/tests/codexcrawler/components/testtimetracker.nim +++ b/tests/codexcrawler/components/testtimetracker.nim @@ -37,7 +37,9 @@ suite "TimeTracker": # Subscribe to nodesToRevisit event 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 return success() @@ -126,7 +128,9 @@ suite "TimeTracker": test "onStep raises routingTable nodes as nodesFound": 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 return success() diff --git a/tests/codexcrawler/mocks/mocklist.nim b/tests/codexcrawler/mocks/mocklist.nim index 5cee33e..721af59 100644 --- a/tests/codexcrawler/mocks/mocklist.nim +++ b/tests/codexcrawler/mocks/mocklist.nim @@ -16,13 +16,17 @@ method load*(this: MockList): Future[?!void] {.async: (raises: [CancelledError]) this.loadCalled = true 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) if this.addSuccess: return success() 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) if this.removeSuccess: return success() diff --git a/tests/codexcrawler/mocks/mockstate.nim b/tests/codexcrawler/mocks/mockstate.nim index cf2f151..ad92c7d 100644 --- a/tests/codexcrawler/mocks/mockstate.nim +++ b/tests/codexcrawler/mocks/mockstate.nim @@ -15,7 +15,9 @@ proc checkAllUnsubscribed*(s: MockState) = s.events.dhtNodeCheck.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.delays.add(delay) diff --git a/tests/codexcrawler/utils/testasyncdataevent.nim b/tests/codexcrawler/utils/testasyncdataevent.nim index ef24b1b..92ca859 100644 --- a/tests/codexcrawler/utils/testasyncdataevent.nim +++ b/tests/codexcrawler/utils/testasyncdataevent.nim @@ -20,7 +20,9 @@ suite "AsyncDataEvent": test "Successful event": var data = "" - proc eventHandler(e: ExampleData): Future[?!void] {.async: (raises: [CancelledError]).} = + proc eventHandler( + e: ExampleData + ): Future[?!void] {.async: (raises: [CancelledError]).} = data = e.s success() @@ -34,7 +36,9 @@ suite "AsyncDataEvent": test "Multiple events": var counter = 0 - proc eventHandler(e: ExampleData): Future[?!void] {.async: (raises: [CancelledError]).} = + proc eventHandler( + e: ExampleData + ): Future[?!void] {.async: (raises: [CancelledError]).} = inc counter success() @@ -54,15 +58,21 @@ suite "AsyncDataEvent": data1 = "" data2 = "" data3 = "" - proc eventHandler1(e: ExampleData): Future[?!void] {.async: (raises: [CancelledError]).} = + proc eventHandler1( + e: ExampleData + ): Future[?!void] {.async: (raises: [CancelledError]).} = data1 = e.s success() - proc eventHandler2(e: ExampleData): Future[?!void] {.async: (raises: [CancelledError]).} = + proc eventHandler2( + e: ExampleData + ): Future[?!void] {.async: (raises: [CancelledError]).} = data2 = e.s success() - proc eventHandler3(e: ExampleData): Future[?!void] {.async: (raises: [CancelledError]).} = + proc eventHandler3( + e: ExampleData + ): Future[?!void] {.async: (raises: [CancelledError]).} = data3 = e.s success() @@ -82,7 +92,9 @@ suite "AsyncDataEvent": await event.unsubscribe(sub3) 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) let s = event.subscribe(eventHandler) @@ -100,15 +112,21 @@ suite "AsyncDataEvent": data2 = "" data3 = "" - proc handler1(e: ExampleData): Future[?!void] {.async: (raises: [CancelledError]).} = + proc handler1( + e: ExampleData + ): Future[?!void] {.async: (raises: [CancelledError]).} = data1 = e.s success() - proc handler2(e: ExampleData): Future[?!void] {.async: (raises: [CancelledError]).} = + proc handler2( + e: ExampleData + ): Future[?!void] {.async: (raises: [CancelledError]).} = data2 = e.s success() - proc handler3(e: ExampleData): Future[?!void] {.async: (raises: [CancelledError]).} = + proc handler3( + e: ExampleData + ): Future[?!void] {.async: (raises: [CancelledError]).} = data3 = e.s success() @@ -139,7 +157,9 @@ suite "AsyncDataEvent": var callback = doNothing - proc eventHandler(e: ExampleData): Future[?!void] {.async: (raises: [CancelledError]).} = + proc eventHandler( + e: ExampleData + ): Future[?!void] {.async: (raises: [CancelledError]).} = await callback() success()