## Nim-Dagger ## Copyright (c) 2022 Status Research & Development GmbH ## Licensed under either of ## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) ## * MIT license ([LICENSE-MIT](LICENSE-MIT)) ## at your option. ## This file may not be copied, modified, or distributed except according to ## those terms. import pkg/chronos import pkg/libp2p import pkg/questionable import pkg/questionable/results import pkg/stew/shims/net import pkg/dagger/discovery type MockDiscovery* = ref object of Discovery findBlockProvidersHandler*: proc(d: MockDiscovery, cid: Cid): seq[SignedPeerRecord] {.gcsafe.} publishProvideHandler*: proc(d: MockDiscovery, cid: Cid) {.gcsafe.} proc new*( T: type MockDiscovery, localInfo: PeerInfo, discoveryPort: Port, bootstrapNodes = newSeq[SignedPeerRecord](), ): T = T() proc findPeer*( d: Discovery, peerId: PeerID): Future[?PeerRecord] {.async.} = return none(PeerRecord) method findBlockProviders*( d: MockDiscovery, cid: Cid): Future[seq[SignedPeerRecord]] {.async.} = if isNil(d.findBlockProvidersHandler): return return d.findBlockProvidersHandler(d, cid) method provideBlock*(d: MockDiscovery, cid: Cid) {.async.} = if isNil(d.publishProvideHandler): return d.publishProvideHandler(d, cid) proc start*(d: Discovery) {.async.} = discard proc stop*(d: Discovery) {.async.} = discard