2022-06-10 11:30:51 +00:00
|
|
|
{.used.}
|
|
|
|
|
|
|
|
import
|
2023-09-01 13:03:59 +00:00
|
|
|
std/[sequtils,tempfiles],
|
2022-06-10 11:30:51 +00:00
|
|
|
stew/byteutils,
|
|
|
|
stew/shims/net,
|
|
|
|
testutils/unittests,
|
2022-10-28 09:51:46 +00:00
|
|
|
presto, presto/client as presto_client,
|
2023-02-10 14:17:50 +00:00
|
|
|
libp2p/crypto/crypto
|
2022-06-10 11:30:51 +00:00
|
|
|
import
|
2023-02-23 08:31:06 +00:00
|
|
|
../../waku/common/base64,
|
2023-08-09 17:11:50 +00:00
|
|
|
../../waku/waku_core,
|
|
|
|
../../waku/waku_node,
|
2023-09-26 11:33:52 +00:00
|
|
|
../../waku/waku_api/message_cache,
|
2023-09-22 13:36:46 +00:00
|
|
|
../../waku/waku_api/rest/server,
|
|
|
|
../../waku/waku_api/rest/client,
|
|
|
|
../../waku/waku_api/rest/responses,
|
|
|
|
../../waku/waku_api/rest/relay/types,
|
|
|
|
../../waku/waku_api/rest/relay/handlers as relay_api,
|
|
|
|
../../waku/waku_api/rest/relay/client as relay_api_client,
|
2023-08-09 17:11:50 +00:00
|
|
|
../../waku/waku_relay,
|
2023-09-11 06:32:31 +00:00
|
|
|
../../../waku/waku_rln_relay,
|
2023-04-05 14:01:51 +00:00
|
|
|
../testlib/wakucore,
|
|
|
|
../testlib/wakunode
|
2022-06-10 11:30:51 +00:00
|
|
|
|
2023-02-10 14:17:50 +00:00
|
|
|
proc testWakuNode(): WakuNode =
|
|
|
|
let
|
2023-02-13 10:43:49 +00:00
|
|
|
privkey = generateSecp256k1Key()
|
2022-06-10 11:30:51 +00:00
|
|
|
bindIp = ValidIpAddress.init("0.0.0.0")
|
|
|
|
extIp = ValidIpAddress.init("127.0.0.1")
|
2023-02-13 14:22:24 +00:00
|
|
|
port = Port(0)
|
2022-06-10 11:30:51 +00:00
|
|
|
|
2023-04-05 14:01:51 +00:00
|
|
|
newTestWakuNode(privkey, bindIp, port, some(extIp), some(port))
|
2022-06-10 11:30:51 +00:00
|
|
|
|
|
|
|
|
2023-02-13 14:22:24 +00:00
|
|
|
suite "Waku v2 Rest API - Relay":
|
2023-09-26 11:33:52 +00:00
|
|
|
asyncTest "Subscribe a node to an array of pubsub topics - POST /relay/v1/subscriptions":
|
2022-06-10 11:30:51 +00:00
|
|
|
# Given
|
|
|
|
let node = testWakuNode()
|
|
|
|
await node.start()
|
2022-09-07 15:31:27 +00:00
|
|
|
await node.mountRelay()
|
2022-06-10 11:30:51 +00:00
|
|
|
|
2023-02-13 14:22:24 +00:00
|
|
|
let restPort = Port(58011)
|
2022-06-10 11:30:51 +00:00
|
|
|
let restAddress = ValidIpAddress.init("0.0.0.0")
|
2022-06-28 10:22:59 +00:00
|
|
|
let restServer = RestServerRef.init(restAddress, restPort).tryGet()
|
2022-06-10 11:30:51 +00:00
|
|
|
|
2023-09-26 11:33:52 +00:00
|
|
|
let cache = MessageCache[string].init()
|
2022-06-10 11:30:51 +00:00
|
|
|
|
2023-09-26 11:33:52 +00:00
|
|
|
installRelayApiHandlers(restServer.router, node, cache)
|
2022-06-10 11:30:51 +00:00
|
|
|
restServer.start()
|
|
|
|
|
|
|
|
let pubSubTopics = @[
|
2022-11-09 14:00:11 +00:00
|
|
|
PubSubTopic("pubsub-topic-1"),
|
|
|
|
PubSubTopic("pubsub-topic-2"),
|
|
|
|
PubSubTopic("pubsub-topic-3")
|
2022-06-10 11:30:51 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
# When
|
|
|
|
let client = newRestHttpClient(initTAddress(restAddress, restPort))
|
2023-09-26 19:53:46 +00:00
|
|
|
let response = await client.relayPostSubscriptionsV1(pubSubTopics)
|
2022-06-10 11:30:51 +00:00
|
|
|
|
|
|
|
# Then
|
|
|
|
check:
|
|
|
|
response.status == 200
|
2022-10-28 09:51:46 +00:00
|
|
|
$response.contentType == $MIMETYPE_TEXT
|
2022-06-10 11:30:51 +00:00
|
|
|
response.data == "OK"
|
|
|
|
|
|
|
|
check:
|
2023-09-26 11:33:52 +00:00
|
|
|
cache.isSubscribed("pubsub-topic-1")
|
|
|
|
cache.isSubscribed("pubsub-topic-2")
|
|
|
|
cache.isSubscribed("pubsub-topic-3")
|
2022-06-10 11:30:51 +00:00
|
|
|
|
|
|
|
check:
|
2023-02-10 16:55:47 +00:00
|
|
|
toSeq(node.wakuRelay.subscribedTopics).len == pubSubTopics.len
|
2023-02-10 14:17:50 +00:00
|
|
|
|
2022-06-10 11:30:51 +00:00
|
|
|
await restServer.stop()
|
|
|
|
await restServer.closeWait()
|
|
|
|
await node.stop()
|
|
|
|
|
2023-09-26 11:33:52 +00:00
|
|
|
asyncTest "Unsubscribe a node from an array of pubsub topics - DELETE /relay/v1/subscriptions":
|
2022-06-10 11:30:51 +00:00
|
|
|
# Given
|
|
|
|
let node = testWakuNode()
|
|
|
|
await node.start()
|
2023-09-26 11:33:52 +00:00
|
|
|
await node.mountRelay(@[
|
|
|
|
"pubsub-topic-1",
|
|
|
|
"pubsub-topic-2",
|
|
|
|
"pubsub-topic-3",
|
|
|
|
"pubsub-topic-x",
|
|
|
|
])
|
2022-06-10 11:30:51 +00:00
|
|
|
|
2023-02-13 14:22:24 +00:00
|
|
|
let restPort = Port(58012)
|
2022-06-10 11:30:51 +00:00
|
|
|
let restAddress = ValidIpAddress.init("0.0.0.0")
|
2022-06-28 10:22:59 +00:00
|
|
|
let restServer = RestServerRef.init(restAddress, restPort).tryGet()
|
2022-06-10 11:30:51 +00:00
|
|
|
|
2023-09-26 11:33:52 +00:00
|
|
|
let cache = MessageCache[string].init()
|
|
|
|
cache.subscribe("pubsub-topic-1")
|
|
|
|
cache.subscribe("pubsub-topic-2")
|
|
|
|
cache.subscribe("pubsub-topic-3")
|
|
|
|
cache.subscribe("pubsub-topic-x")
|
2022-06-10 11:30:51 +00:00
|
|
|
|
2023-09-26 11:33:52 +00:00
|
|
|
installRelayApiHandlers(restServer.router, node, cache)
|
2022-06-10 11:30:51 +00:00
|
|
|
restServer.start()
|
|
|
|
|
|
|
|
let pubSubTopics = @[
|
2023-02-10 14:17:50 +00:00
|
|
|
PubSubTopic("pubsub-topic-1"),
|
2022-11-09 14:00:11 +00:00
|
|
|
PubSubTopic("pubsub-topic-2"),
|
|
|
|
PubSubTopic("pubsub-topic-3"),
|
|
|
|
PubSubTopic("pubsub-topic-y")
|
2022-06-10 11:30:51 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
# When
|
|
|
|
let client = newRestHttpClient(initTAddress(restAddress, restPort))
|
2023-09-26 19:53:46 +00:00
|
|
|
let response = await client.relayDeleteSubscriptionsV1(pubSubTopics)
|
2022-06-10 11:30:51 +00:00
|
|
|
|
|
|
|
# Then
|
|
|
|
check:
|
|
|
|
response.status == 200
|
2022-10-28 09:51:46 +00:00
|
|
|
$response.contentType == $MIMETYPE_TEXT
|
2022-06-10 11:30:51 +00:00
|
|
|
response.data == "OK"
|
|
|
|
|
|
|
|
check:
|
2023-09-26 11:33:52 +00:00
|
|
|
not cache.isSubscribed("pubsub-topic-1")
|
|
|
|
not node.wakuRelay.isSubscribed("pubsub-topic-1")
|
|
|
|
not cache.isSubscribed("pubsub-topic-2")
|
|
|
|
not node.wakuRelay.isSubscribed("pubsub-topic-2")
|
|
|
|
not cache.isSubscribed("pubsub-topic-3")
|
|
|
|
not node.wakuRelay.isSubscribed("pubsub-topic-3")
|
|
|
|
cache.isSubscribed("pubsub-topic-x")
|
|
|
|
node.wakuRelay.isSubscribed("pubsub-topic-x")
|
|
|
|
not cache.isSubscribed("pubsub-topic-y")
|
|
|
|
not node.wakuRelay.isSubscribed("pubsub-topic-y")
|
2022-06-10 11:30:51 +00:00
|
|
|
|
|
|
|
await restServer.stop()
|
|
|
|
await restServer.closeWait()
|
|
|
|
await node.stop()
|
|
|
|
|
2023-09-26 11:33:52 +00:00
|
|
|
asyncTest "Get the latest messages for a pubsub topic - GET /relay/v1/messages/{topic}":
|
2022-06-10 11:30:51 +00:00
|
|
|
# Given
|
|
|
|
let node = testWakuNode()
|
|
|
|
await node.start()
|
2022-09-07 15:31:27 +00:00
|
|
|
await node.mountRelay()
|
2022-06-10 11:30:51 +00:00
|
|
|
|
2023-02-13 14:22:24 +00:00
|
|
|
let restPort = Port(58013)
|
2022-06-10 11:30:51 +00:00
|
|
|
let restAddress = ValidIpAddress.init("0.0.0.0")
|
2022-06-28 10:22:59 +00:00
|
|
|
let restServer = RestServerRef.init(restAddress, restPort).tryGet()
|
2022-06-10 11:30:51 +00:00
|
|
|
|
|
|
|
let pubSubTopic = "/waku/2/default-waku/proto"
|
|
|
|
let messages = @[
|
|
|
|
fakeWakuMessage(contentTopic = "content-topic-x", payload = toBytes("TEST-1")),
|
|
|
|
fakeWakuMessage(contentTopic = "content-topic-x", payload = toBytes("TEST-1")),
|
|
|
|
fakeWakuMessage(contentTopic = "content-topic-x", payload = toBytes("TEST-1")),
|
|
|
|
]
|
|
|
|
|
2023-09-26 11:33:52 +00:00
|
|
|
let cache = MessageCache[string].init()
|
2022-06-10 11:30:51 +00:00
|
|
|
|
2023-09-26 11:33:52 +00:00
|
|
|
cache.subscribe(pubSubTopic)
|
2022-06-10 11:30:51 +00:00
|
|
|
for msg in messages:
|
2023-09-26 11:33:52 +00:00
|
|
|
cache.addMessage(pubSubTopic, msg)
|
2022-06-10 11:30:51 +00:00
|
|
|
|
2023-09-26 11:33:52 +00:00
|
|
|
installRelayApiHandlers(restServer.router, node, cache)
|
2022-06-10 11:30:51 +00:00
|
|
|
restServer.start()
|
|
|
|
|
|
|
|
# When
|
|
|
|
let client = newRestHttpClient(initTAddress(restAddress, restPort))
|
|
|
|
let response = await client.relayGetMessagesV1(pubSubTopic)
|
|
|
|
|
|
|
|
# Then
|
|
|
|
check:
|
|
|
|
response.status == 200
|
2022-10-28 09:51:46 +00:00
|
|
|
$response.contentType == $MIMETYPE_JSON
|
2022-06-10 11:30:51 +00:00
|
|
|
response.data.len == 3
|
2023-02-10 14:17:50 +00:00
|
|
|
response.data.all do (msg: RelayWakuMessage) -> bool:
|
2023-02-23 08:31:06 +00:00
|
|
|
msg.payload == base64.encode("TEST-1") and
|
2023-09-26 11:33:52 +00:00
|
|
|
msg.contentTopic.get() == "content-topic-x" and
|
2022-10-21 13:01:39 +00:00
|
|
|
msg.version.get() == 2 and
|
|
|
|
msg.timestamp.get() != Timestamp(0)
|
2022-06-10 11:30:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
check:
|
2023-09-26 11:33:52 +00:00
|
|
|
cache.isSubscribed(pubSubTopic)
|
|
|
|
cache.getMessages(pubSubTopic).tryGet().len == 0
|
2022-06-10 11:30:51 +00:00
|
|
|
|
|
|
|
await restServer.stop()
|
|
|
|
await restServer.closeWait()
|
|
|
|
await node.stop()
|
|
|
|
|
2023-09-26 11:33:52 +00:00
|
|
|
asyncTest "Post a message to a pubsub topic - POST /relay/v1/messages/{topic}":
|
2023-02-10 14:17:50 +00:00
|
|
|
## "Relay API: publish and subscribe/unsubscribe":
|
2022-06-10 11:30:51 +00:00
|
|
|
# Given
|
|
|
|
let node = testWakuNode()
|
|
|
|
await node.start()
|
2022-09-07 15:31:27 +00:00
|
|
|
await node.mountRelay()
|
2023-09-11 06:32:31 +00:00
|
|
|
await node.mountRlnRelay(WakuRlnConfig(rlnRelayDynamic: false,
|
|
|
|
rlnRelayCredIndex: some(1.uint),
|
|
|
|
rlnRelayTreePath: genTempPath("rln_tree", "wakunode_1")))
|
2022-06-10 11:30:51 +00:00
|
|
|
|
|
|
|
# RPC server setup
|
2023-02-13 14:22:24 +00:00
|
|
|
let restPort = Port(58014)
|
2022-06-10 11:30:51 +00:00
|
|
|
let restAddress = ValidIpAddress.init("0.0.0.0")
|
2022-06-28 10:22:59 +00:00
|
|
|
let restServer = RestServerRef.init(restAddress, restPort).tryGet()
|
2022-06-10 11:30:51 +00:00
|
|
|
|
2023-09-26 11:33:52 +00:00
|
|
|
let cache = MessageCache[string].init()
|
2022-06-10 11:30:51 +00:00
|
|
|
|
2023-09-26 11:33:52 +00:00
|
|
|
installRelayApiHandlers(restServer.router, node, cache)
|
2022-06-10 11:30:51 +00:00
|
|
|
restServer.start()
|
|
|
|
|
|
|
|
let client = newRestHttpClient(initTAddress(restAddress, restPort))
|
2023-02-10 14:17:50 +00:00
|
|
|
|
2023-09-26 11:33:52 +00:00
|
|
|
node.subscribe((kind: PubsubSub, topic: DefaultPubsubTopic))
|
2023-02-10 14:17:50 +00:00
|
|
|
require:
|
|
|
|
toSeq(node.wakuRelay.subscribedTopics).len == 1
|
|
|
|
|
2022-06-10 11:30:51 +00:00
|
|
|
# When
|
2022-11-09 08:55:47 +00:00
|
|
|
let response = await client.relayPostMessagesV1(DefaultPubsubTopic, RelayWakuMessage(
|
2023-02-23 08:31:06 +00:00
|
|
|
payload: base64.encode("TEST-PAYLOAD"),
|
2023-02-10 14:17:50 +00:00
|
|
|
contentTopic: some(DefaultContentTopic),
|
2022-06-10 11:30:51 +00:00
|
|
|
timestamp: some(int64(2022))
|
|
|
|
))
|
|
|
|
|
|
|
|
# Then
|
|
|
|
check:
|
|
|
|
response.status == 200
|
2022-10-28 09:51:46 +00:00
|
|
|
$response.contentType == $MIMETYPE_TEXT
|
2022-06-10 11:30:51 +00:00
|
|
|
response.data == "OK"
|
|
|
|
|
2023-09-26 11:33:52 +00:00
|
|
|
await restServer.stop()
|
|
|
|
await restServer.closeWait()
|
|
|
|
await node.stop()
|
|
|
|
|
|
|
|
# Autosharding API
|
|
|
|
|
|
|
|
asyncTest "Subscribe a node to an array of content topics - POST /relay/v1/auto/subscriptions":
|
|
|
|
# Given
|
|
|
|
let node = testWakuNode()
|
|
|
|
await node.start()
|
|
|
|
await node.mountRelay()
|
|
|
|
|
|
|
|
let restPort = Port(58011)
|
|
|
|
let restAddress = ValidIpAddress.init("0.0.0.0")
|
|
|
|
let restServer = RestServerRef.init(restAddress, restPort).tryGet()
|
|
|
|
|
|
|
|
let cache = MessageCache[string].init()
|
|
|
|
|
|
|
|
installRelayApiHandlers(restServer.router, node, cache)
|
|
|
|
restServer.start()
|
|
|
|
|
|
|
|
let contentTopics = @[
|
|
|
|
ContentTopic("/waku/2/default-content1/proto"),
|
|
|
|
ContentTopic("/waku/2/default-content2/proto"),
|
|
|
|
ContentTopic("/waku/2/default-content3/proto")
|
|
|
|
]
|
|
|
|
|
|
|
|
let shards = contentTopics.mapIt(getShard(it).expect("Valid Shard")).deduplicate()
|
|
|
|
|
|
|
|
# When
|
|
|
|
let client = newRestHttpClient(initTAddress(restAddress, restPort))
|
2023-09-26 19:53:46 +00:00
|
|
|
let response = await client.relayPostAutoSubscriptionsV1(contentTopics)
|
2023-09-26 11:33:52 +00:00
|
|
|
|
|
|
|
# Then
|
|
|
|
check:
|
|
|
|
response.status == 200
|
|
|
|
$response.contentType == $MIMETYPE_TEXT
|
|
|
|
response.data == "OK"
|
|
|
|
|
|
|
|
check:
|
|
|
|
cache.isSubscribed(contentTopics[0])
|
|
|
|
cache.isSubscribed(contentTopics[1])
|
|
|
|
cache.isSubscribed(contentTopics[2])
|
|
|
|
|
|
|
|
check:
|
|
|
|
# Node should be subscribed to all shards
|
|
|
|
toSeq(node.wakuRelay.subscribedTopics).len == shards.len
|
2022-06-10 11:30:51 +00:00
|
|
|
|
|
|
|
await restServer.stop()
|
|
|
|
await restServer.closeWait()
|
|
|
|
await node.stop()
|
2023-09-26 11:33:52 +00:00
|
|
|
|
|
|
|
asyncTest "Unsubscribe a node from an array of content topics - DELETE /relay/v1/auto/subscriptions":
|
|
|
|
# Given
|
|
|
|
let node = testWakuNode()
|
|
|
|
await node.start()
|
|
|
|
await node.mountRelay()
|
|
|
|
|
|
|
|
let restPort = Port(58012)
|
|
|
|
let restAddress = ValidIpAddress.init("0.0.0.0")
|
|
|
|
let restServer = RestServerRef.init(restAddress, restPort).tryGet()
|
|
|
|
|
|
|
|
let contentTopics = @[
|
|
|
|
ContentTopic("/waku/2/default-content1/proto"),
|
|
|
|
ContentTopic("/waku/2/default-content2/proto"),
|
|
|
|
ContentTopic("/waku/2/default-content3/proto"),
|
|
|
|
ContentTopic("/waku/2/default-contentX/proto")
|
|
|
|
]
|
|
|
|
|
|
|
|
let cache = MessageCache[string].init()
|
|
|
|
cache.subscribe(contentTopics[0])
|
|
|
|
cache.subscribe(contentTopics[1])
|
|
|
|
cache.subscribe(contentTopics[2])
|
|
|
|
cache.subscribe("/waku/2/default-contentY/proto")
|
|
|
|
|
|
|
|
installRelayApiHandlers(restServer.router, node, cache)
|
|
|
|
restServer.start()
|
|
|
|
|
|
|
|
# When
|
|
|
|
let client = newRestHttpClient(initTAddress(restAddress, restPort))
|
2023-09-26 19:53:46 +00:00
|
|
|
let response = await client.relayDeleteAutoSubscriptionsV1(contentTopics)
|
2023-09-26 11:33:52 +00:00
|
|
|
|
|
|
|
# Then
|
|
|
|
check:
|
|
|
|
response.status == 200
|
|
|
|
$response.contentType == $MIMETYPE_TEXT
|
|
|
|
response.data == "OK"
|
|
|
|
|
|
|
|
check:
|
|
|
|
not cache.isSubscribed(contentTopics[1])
|
|
|
|
not cache.isSubscribed(contentTopics[2])
|
|
|
|
not cache.isSubscribed(contentTopics[3])
|
|
|
|
cache.isSubscribed("/waku/2/default-contentY/proto")
|
|
|
|
|
|
|
|
await restServer.stop()
|
|
|
|
await restServer.closeWait()
|
|
|
|
await node.stop()
|
|
|
|
|
|
|
|
asyncTest "Get the latest messages for a content topic - GET /relay/v1/auto/messages/{topic}":
|
|
|
|
# Given
|
|
|
|
let node = testWakuNode()
|
|
|
|
await node.start()
|
|
|
|
await node.mountRelay()
|
|
|
|
|
|
|
|
let restPort = Port(58013)
|
|
|
|
let restAddress = ValidIpAddress.init("0.0.0.0")
|
|
|
|
let restServer = RestServerRef.init(restAddress, restPort).tryGet()
|
|
|
|
|
|
|
|
let contentTopic = DefaultContentTopic
|
|
|
|
let messages = @[
|
|
|
|
fakeWakuMessage(contentTopic = DefaultContentTopic, payload = toBytes("TEST-1")),
|
|
|
|
fakeWakuMessage(contentTopic = DefaultContentTopic, payload = toBytes("TEST-1")),
|
|
|
|
fakeWakuMessage(contentTopic = DefaultContentTopic, payload = toBytes("TEST-1")),
|
|
|
|
]
|
|
|
|
|
|
|
|
let cache = MessageCache[string].init()
|
|
|
|
|
|
|
|
cache.subscribe(contentTopic)
|
|
|
|
for msg in messages:
|
|
|
|
cache.addMessage(contentTopic, msg)
|
|
|
|
|
|
|
|
installRelayApiHandlers(restServer.router, node, cache)
|
|
|
|
restServer.start()
|
|
|
|
|
|
|
|
# When
|
|
|
|
let client = newRestHttpClient(initTAddress(restAddress, restPort))
|
|
|
|
let response = await client.relayGetAutoMessagesV1(contentTopic)
|
|
|
|
|
|
|
|
# Then
|
|
|
|
check:
|
|
|
|
response.status == 200
|
|
|
|
$response.contentType == $MIMETYPE_JSON
|
|
|
|
response.data.len == 3
|
|
|
|
response.data.all do (msg: RelayWakuMessage) -> bool:
|
|
|
|
msg.payload == base64.encode("TEST-1") and
|
|
|
|
msg.contentTopic.get() == DefaultContentTopic and
|
|
|
|
msg.version.get() == 2 and
|
|
|
|
msg.timestamp.get() != Timestamp(0)
|
|
|
|
|
|
|
|
check:
|
|
|
|
cache.isSubscribed(contentTopic)
|
|
|
|
cache.getMessages(contentTopic).tryGet().len == 0 # The cache is cleared when getMessage is called
|
|
|
|
|
|
|
|
await restServer.stop()
|
|
|
|
await restServer.closeWait()
|
|
|
|
await node.stop()
|
|
|
|
|
|
|
|
asyncTest "Post a message to a content topic - POST /relay/v1/auto/messages/{topic}":
|
|
|
|
## "Relay API: publish and subscribe/unsubscribe":
|
|
|
|
# Given
|
|
|
|
let node = testWakuNode()
|
|
|
|
await node.start()
|
|
|
|
await node.mountRelay()
|
|
|
|
await node.mountRlnRelay(WakuRlnConfig(rlnRelayDynamic: false,
|
|
|
|
rlnRelayCredIndex: some(1.uint),
|
|
|
|
rlnRelayTreePath: genTempPath("rln_tree", "wakunode_1")))
|
|
|
|
|
|
|
|
# RPC server setup
|
|
|
|
let restPort = Port(58014)
|
|
|
|
let restAddress = ValidIpAddress.init("0.0.0.0")
|
|
|
|
let restServer = RestServerRef.init(restAddress, restPort).tryGet()
|
|
|
|
|
|
|
|
let cache = MessageCache[string].init()
|
|
|
|
installRelayApiHandlers(restServer.router, node, cache)
|
|
|
|
restServer.start()
|
|
|
|
|
|
|
|
let client = newRestHttpClient(initTAddress(restAddress, restPort))
|
|
|
|
|
|
|
|
node.subscribe((kind: ContentSub, topic: DefaultContentTopic))
|
|
|
|
require:
|
|
|
|
toSeq(node.wakuRelay.subscribedTopics).len == 1
|
|
|
|
|
|
|
|
# When
|
2023-09-26 19:53:46 +00:00
|
|
|
let response = await client.relayPostAutoMessagesV1(RelayWakuMessage(
|
2023-09-26 11:33:52 +00:00
|
|
|
payload: base64.encode("TEST-PAYLOAD"),
|
|
|
|
contentTopic: some(DefaultContentTopic),
|
|
|
|
timestamp: some(int64(2022))
|
|
|
|
))
|
|
|
|
|
|
|
|
# Then
|
|
|
|
check:
|
|
|
|
response.status == 200
|
|
|
|
$response.contentType == $MIMETYPE_TEXT
|
|
|
|
response.data == "OK"
|
|
|
|
|
|
|
|
await restServer.stop()
|
|
|
|
await restServer.closeWait()
|
|
|
|
await node.stop()
|