mirror of https://github.com/waku-org/nwaku.git
59 lines
1.6 KiB
Nim
59 lines
1.6 KiB
Nim
{.used.}
|
|
|
|
import
|
|
std/[unittest, options, tables, sets],
|
|
chronos, chronicles,
|
|
libp2p/switch,
|
|
libp2p/protobuf/minprotobuf,
|
|
libp2p/stream/[bufferstream, connection],
|
|
libp2p/crypto/crypto,
|
|
libp2p/protocols/pubsub/rpc/message,
|
|
libp2p/multistream,
|
|
libp2p/transports/transport,
|
|
libp2p/transports/tcptransport,
|
|
../../waku/protocol/v2/[waku_store, message_notifier],
|
|
../../waku/node/v2/waku_types,
|
|
../test_helpers, ./utils
|
|
|
|
procSuite "Waku Store":
|
|
asyncTest "handle query":
|
|
let
|
|
key = PrivateKey.random(ECDSA, rng[]).get()
|
|
peer = PeerInfo.init(key)
|
|
msg = WakuMessage(payload: @[byte 1, 2, 3], contentTopic: "topic")
|
|
msg2 = WakuMessage(payload: @[byte 1, 2, 3], contentTopic: "topic2")
|
|
|
|
var dialSwitch = newStandardSwitch()
|
|
discard await dialSwitch.start()
|
|
|
|
var listenSwitch = newStandardSwitch(some(key))
|
|
discard await listenSwitch.start()
|
|
|
|
let
|
|
proto = WakuStore.init(dialSwitch, crypto.newRng())
|
|
subscription = proto.subscription()
|
|
rpc = HistoryQuery(topics: @["topic"])
|
|
|
|
proto.setPeer(listenSwitch.peerInfo)
|
|
|
|
var subscriptions = newTable[string, MessageNotificationSubscription]()
|
|
subscriptions["test"] = subscription
|
|
|
|
listenSwitch.mount(proto)
|
|
|
|
await subscriptions.notify("foo", msg)
|
|
await subscriptions.notify("foo", msg2)
|
|
|
|
var completionFut = newFuture[bool]()
|
|
|
|
proc handler(response: HistoryResponse) {.gcsafe, closure.} =
|
|
check:
|
|
response.messages.len() == 1
|
|
response.messages[0] == msg
|
|
completionFut.complete(true)
|
|
|
|
await proto.query(rpc, handler)
|
|
|
|
check:
|
|
(await completionFut.withTimeout(5.seconds)) == true
|