2022-05-19 19:56:03 +00:00
|
|
|
## Nim-Codex
|
2022-04-13 16:32:35 +00:00
|
|
|
## 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
|
2022-05-19 19:56:03 +00:00
|
|
|
import pkg/codex/discovery
|
2022-05-26 02:29:31 +00:00
|
|
|
import pkg/contractabi/address as ca
|
2022-04-13 16:32:35 +00:00
|
|
|
|
|
|
|
type
|
2022-05-12 21:52:03 +00:00
|
|
|
MockDiscovery* = ref object of Discovery
|
2022-05-19 02:29:15 +00:00
|
|
|
findBlockProvidersHandler*: proc(d: MockDiscovery, cid: Cid):
|
|
|
|
Future[seq[SignedPeerRecord]] {.gcsafe.}
|
2022-05-26 02:29:31 +00:00
|
|
|
publishBlockProvideHandler*: proc(d: MockDiscovery, cid: Cid):
|
|
|
|
Future[void] {.gcsafe.}
|
|
|
|
findHostProvidersHandler*: proc(d: MockDiscovery, host: ca.Address):
|
|
|
|
Future[seq[SignedPeerRecord]] {.gcsafe.}
|
|
|
|
publishHostProvideHandler*: proc(d: MockDiscovery, host: ca.Address):
|
2022-05-19 02:29:15 +00:00
|
|
|
Future[void] {.gcsafe.}
|
2022-04-13 16:32:35 +00:00
|
|
|
|
2022-05-26 02:29:31 +00:00
|
|
|
proc new*(T: type MockDiscovery): T =
|
2022-04-13 16:32:35 +00:00
|
|
|
T()
|
|
|
|
|
|
|
|
proc findPeer*(
|
|
|
|
d: Discovery,
|
|
|
|
peerId: PeerID): Future[?PeerRecord] {.async.} =
|
|
|
|
return none(PeerRecord)
|
|
|
|
|
2022-05-26 02:29:31 +00:00
|
|
|
method find*(
|
2022-05-12 21:52:03 +00:00
|
|
|
d: MockDiscovery,
|
2022-04-13 16:32:35 +00:00
|
|
|
cid: Cid): Future[seq[SignedPeerRecord]] {.async.} =
|
2022-05-19 02:29:15 +00:00
|
|
|
if isNil(d.findBlockProvidersHandler):
|
|
|
|
return
|
2022-04-13 16:32:35 +00:00
|
|
|
|
2022-05-19 02:29:15 +00:00
|
|
|
return await d.findBlockProvidersHandler(d, cid)
|
2022-04-13 16:32:35 +00:00
|
|
|
|
2022-05-26 02:29:31 +00:00
|
|
|
method provide*(d: MockDiscovery, cid: Cid): Future[void] {.async.} =
|
|
|
|
if isNil(d.publishBlockProvideHandler):
|
|
|
|
return
|
|
|
|
|
|
|
|
await d.publishBlockProvideHandler(d, cid)
|
|
|
|
|
|
|
|
method find*(
|
|
|
|
d: MockDiscovery,
|
|
|
|
host: ca.Address): Future[seq[SignedPeerRecord]] {.async.} =
|
|
|
|
if isNil(d.findHostProvidersHandler):
|
2022-05-19 02:29:15 +00:00
|
|
|
return
|
|
|
|
|
2022-05-26 02:29:31 +00:00
|
|
|
return await d.findHostProvidersHandler(d, host)
|
2022-04-13 16:32:35 +00:00
|
|
|
|
2022-05-26 02:29:31 +00:00
|
|
|
method provide*(d: MockDiscovery, host: ca.Address): Future[void] {.async.} =
|
|
|
|
if isNil(d.publishHostProvideHandler):
|
|
|
|
return
|
2022-04-13 16:32:35 +00:00
|
|
|
|
2022-05-26 02:29:31 +00:00
|
|
|
await d.publishHostProvideHandler(d, host)
|