mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-01-06 16:03:08 +00:00
* changes * fix * changes * made the query function work * added rpc * whoops * Update wakurpc.nim * minor * fixes * update docs * fix * error handling * end-to-end waku node test * Update test_wakunode.nim * Update waku/node/v2/rpc/wakurpc.nim Co-authored-by: Oskar Thorén <ot@oskarthoren.com> * Update test_wakunode.nim * Update wakunode2.nim * fix * fix * shorter * rm echo * fix * added history peer Co-authored-by: Oskar Thorén <ot@oskarthoren.com>
60 lines
1.7 KiB
Nim
60 lines
1.7 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)
|
|
subscription = proto.subscription()
|
|
rpc = HistoryQuery(uuid: "1234", 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.uuid == rpc.uuid
|
|
response.messages.len() == 1
|
|
response.messages[0] == msg
|
|
completionFut.complete(true)
|
|
|
|
await proto.query(rpc, handler)
|
|
|
|
check:
|
|
(await completionFut.withTimeout(5.seconds)) == true
|