2020-08-31 03:32:41 +00:00
|
|
|
{.used.}
|
2020-08-27 02:44:09 +00:00
|
|
|
|
2020-08-31 03:32:41 +00:00
|
|
|
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,
|
2020-09-07 11:26:32 +00:00
|
|
|
../../waku/protocol/v2/[waku_store, message_notifier],
|
2020-09-16 02:59:10 +00:00
|
|
|
../../waku/node/v2/waku_types,
|
2020-08-31 03:32:41 +00:00
|
|
|
../test_helpers, ./utils
|
2020-08-27 02:44:09 +00:00
|
|
|
|
|
|
|
procSuite "Waku Store":
|
|
|
|
asyncTest "handle query":
|
|
|
|
let
|
2020-09-17 20:10:41 +00:00
|
|
|
key = PrivateKey.random(ECDSA, rng[]).get()
|
|
|
|
peer = PeerInfo.init(key)
|
2020-09-16 02:59:10 +00:00
|
|
|
msg = WakuMessage(payload: @[byte 1, 2, 3], contentTopic: "topic")
|
|
|
|
msg2 = WakuMessage(payload: @[byte 1, 2, 3], contentTopic: "topic2")
|
2020-08-27 02:44:09 +00:00
|
|
|
|
2020-09-17 20:10:41 +00:00
|
|
|
var dialSwitch = newStandardSwitch()
|
|
|
|
discard await dialSwitch.start()
|
2020-08-27 02:44:09 +00:00
|
|
|
|
2020-09-17 20:10:41 +00:00
|
|
|
var listenSwitch = newStandardSwitch(some(key))
|
|
|
|
discard await listenSwitch.start()
|
2020-08-27 02:44:09 +00:00
|
|
|
|
2020-09-24 02:16:25 +00:00
|
|
|
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)
|
|
|
|
|
2020-09-17 20:10:41 +00:00
|
|
|
await subscriptions.notify("foo", msg)
|
|
|
|
await subscriptions.notify("foo", msg2)
|
2020-08-27 02:44:09 +00:00
|
|
|
|
2020-09-24 02:16:25 +00:00
|
|
|
var completionFut = newFuture[bool]()
|
2020-08-27 02:44:09 +00:00
|
|
|
|
2020-09-24 02:16:25 +00:00
|
|
|
proc handler(response: HistoryResponse) {.gcsafe, closure.} =
|
|
|
|
check:
|
|
|
|
response.uuid == rpc.uuid
|
|
|
|
response.messages.len() == 1
|
|
|
|
response.messages[0] == msg
|
|
|
|
completionFut.complete(true)
|
2020-08-27 02:44:09 +00:00
|
|
|
|
2020-09-24 02:16:25 +00:00
|
|
|
await proto.query(rpc, handler)
|
2020-08-27 02:44:09 +00:00
|
|
|
|
|
|
|
check:
|
2020-09-24 02:16:25 +00:00
|
|
|
(await completionFut.withTimeout(5.seconds)) == true
|