2022-06-10 13:30:51 +02:00
|
|
|
{.used.}
|
|
|
|
|
|
|
|
|
|
import
|
2025-09-10 16:18:51 +05:30
|
|
|
std/[sequtils, strformat, tempfiles, osproc],
|
2022-06-10 13:30:51 +02:00
|
|
|
stew/byteutils,
|
|
|
|
|
testutils/unittests,
|
2024-03-16 00:08:47 +01:00
|
|
|
presto,
|
|
|
|
|
presto/client as presto_client,
|
2023-02-10 15:17:50 +01:00
|
|
|
libp2p/crypto/crypto
|
2022-06-10 13:30:51 +02:00
|
|
|
import
|
2024-07-06 03:33:38 +05:30
|
|
|
waku/[
|
|
|
|
|
common/base64,
|
|
|
|
|
waku_core,
|
|
|
|
|
waku_node,
|
|
|
|
|
waku_api/message_cache,
|
|
|
|
|
waku_api/rest/server,
|
|
|
|
|
waku_api/rest/client,
|
|
|
|
|
waku_api/rest/responses,
|
|
|
|
|
waku_api/rest/relay/types,
|
|
|
|
|
waku_api/rest/relay/handlers as relay_api,
|
|
|
|
|
waku_api/rest/relay/client as relay_api_client,
|
|
|
|
|
waku_relay,
|
|
|
|
|
waku_rln_relay,
|
|
|
|
|
],
|
2023-04-05 16:01:51 +02:00
|
|
|
../testlib/wakucore,
|
2024-02-01 18:16:10 +01:00
|
|
|
../testlib/wakunode,
|
2025-09-10 16:18:51 +05:30
|
|
|
../resources/payloads,
|
|
|
|
|
../waku_rln_relay/[rln/waku_rln_relay_utils, utils_onchain]
|
2022-06-10 13:30:51 +02:00
|
|
|
|
2023-02-10 15:17:50 +01:00
|
|
|
proc testWakuNode(): WakuNode =
|
|
|
|
|
let
|
2023-02-13 11:43:49 +01:00
|
|
|
privkey = generateSecp256k1Key()
|
2023-12-14 07:16:39 +01:00
|
|
|
bindIp = parseIpAddress("0.0.0.0")
|
|
|
|
|
extIp = parseIpAddress("127.0.0.1")
|
2023-02-13 15:22:24 +01:00
|
|
|
port = Port(0)
|
2022-06-10 13:30:51 +02:00
|
|
|
|
2023-04-05 16:01:51 +02:00
|
|
|
newTestWakuNode(privkey, bindIp, port, some(extIp), some(port))
|
2022-06-10 13:30:51 +02:00
|
|
|
|
2023-02-13 15:22:24 +01:00
|
|
|
suite "Waku v2 Rest API - Relay":
|
2025-09-10 16:18:51 +05:30
|
|
|
var anvilProc {.threadVar.}: Process
|
|
|
|
|
var manager {.threadVar.}: OnchainGroupManager
|
|
|
|
|
|
|
|
|
|
setup:
|
|
|
|
|
anvilProc = runAnvil()
|
|
|
|
|
manager = waitFor setupOnchainGroupManager()
|
|
|
|
|
|
|
|
|
|
teardown:
|
|
|
|
|
stopAnvil(anvilProc)
|
|
|
|
|
|
2023-09-26 07:33:52 -04:00
|
|
|
asyncTest "Subscribe a node to an array of pubsub topics - POST /relay/v1/subscriptions":
|
2022-06-10 13:30:51 +02:00
|
|
|
# Given
|
|
|
|
|
let node = testWakuNode()
|
|
|
|
|
await node.start()
|
2025-05-05 22:57:20 +02:00
|
|
|
(await node.mountRelay()).isOkOr:
|
|
|
|
|
assert false, "Failed to mount relay"
|
2022-06-10 13:30:51 +02:00
|
|
|
|
2024-01-18 13:49:13 +01:00
|
|
|
var restPort = Port(0)
|
2025-09-09 14:04:10 +02:00
|
|
|
|
2023-12-14 07:16:39 +01:00
|
|
|
let restAddress = parseIpAddress("0.0.0.0")
|
2024-02-29 09:48:14 +01:00
|
|
|
let restServer = WakuRestServerRef.init(restAddress, restPort).tryGet()
|
2022-06-10 13:30:51 +02:00
|
|
|
|
2024-02-29 09:48:14 +01:00
|
|
|
restPort = restServer.httpServer.address.port # update with bound port for client use
|
2024-01-18 13:49:13 +01:00
|
|
|
|
2023-11-28 07:21:41 -05:00
|
|
|
let cache = MessageCache.init()
|
2022-06-10 13:30:51 +02:00
|
|
|
|
2023-09-26 07:33:52 -04:00
|
|
|
installRelayApiHandlers(restServer.router, node, cache)
|
2022-06-10 13:30:51 +02:00
|
|
|
restServer.start()
|
|
|
|
|
|
2024-09-10 15:07:12 -06:00
|
|
|
let
|
|
|
|
|
shard0 = RelayShard(clusterId: DefaultClusterId, shardId: 0)
|
|
|
|
|
shard1 = RelayShard(clusterId: DefaultClusterId, shardId: 1)
|
|
|
|
|
shard2 = RelayShard(clusterId: DefaultClusterId, shardId: 2)
|
|
|
|
|
|
|
|
|
|
let shards = @[$shard0, $shard1, $shard2]
|
2022-06-10 13:30:51 +02:00
|
|
|
|
2025-09-09 14:04:10 +02:00
|
|
|
let invalidTopic = "/test/2/this/is/a/content/topic/1"
|
|
|
|
|
|
|
|
|
|
var containsIncorrect = shards
|
|
|
|
|
containsIncorrect.add(invalidTopic)
|
|
|
|
|
|
|
|
|
|
# When contains incorrect pubsub topics, subscribe shall fail
|
2022-06-10 13:30:51 +02:00
|
|
|
let client = newRestHttpClient(initTAddress(restAddress, restPort))
|
2025-09-09 14:04:10 +02:00
|
|
|
let errorResponse = await client.relayPostSubscriptionsV1(containsIncorrect)
|
|
|
|
|
|
|
|
|
|
# Then
|
|
|
|
|
check:
|
|
|
|
|
errorResponse.status == 400
|
|
|
|
|
$errorResponse.contentType == $MIMETYPE_TEXT
|
|
|
|
|
errorResponse.data ==
|
|
|
|
|
"Invalid pubsub topic(s): @[\"/test/2/this/is/a/content/topic/1\"]"
|
|
|
|
|
|
|
|
|
|
# when all pubsub topics are correct, subscribe shall succeed
|
2024-09-10 15:07:12 -06:00
|
|
|
let response = await client.relayPostSubscriptionsV1(shards)
|
2022-06-10 13:30:51 +02:00
|
|
|
|
|
|
|
|
# Then
|
|
|
|
|
check:
|
|
|
|
|
response.status == 200
|
2022-10-28 12:51:46 +03:00
|
|
|
$response.contentType == $MIMETYPE_TEXT
|
2022-06-10 13:30:51 +02:00
|
|
|
response.data == "OK"
|
|
|
|
|
|
|
|
|
|
check:
|
2024-09-10 15:07:12 -06:00
|
|
|
cache.isPubsubSubscribed($shard0)
|
|
|
|
|
cache.isPubsubSubscribed($shard1)
|
|
|
|
|
cache.isPubsubSubscribed($shard2)
|
2022-06-10 13:30:51 +02:00
|
|
|
|
|
|
|
|
check:
|
2024-09-10 15:07:12 -06:00
|
|
|
toSeq(node.wakuRelay.subscribedTopics).len == shards.len
|
2023-02-10 15:17:50 +01:00
|
|
|
|
2022-06-10 13:30:51 +02:00
|
|
|
await restServer.stop()
|
|
|
|
|
await restServer.closeWait()
|
|
|
|
|
await node.stop()
|
|
|
|
|
|
2023-09-26 07:33:52 -04:00
|
|
|
asyncTest "Unsubscribe a node from an array of pubsub topics - DELETE /relay/v1/subscriptions":
|
2022-06-10 13:30:51 +02:00
|
|
|
# Given
|
|
|
|
|
let node = testWakuNode()
|
|
|
|
|
await node.start()
|
2024-09-10 15:07:12 -06:00
|
|
|
|
|
|
|
|
let
|
|
|
|
|
shard0 = RelayShard(clusterId: DefaultClusterId, shardId: 0)
|
|
|
|
|
shard1 = RelayShard(clusterId: DefaultClusterId, shardId: 1)
|
|
|
|
|
shard2 = RelayShard(clusterId: DefaultClusterId, shardId: 2)
|
|
|
|
|
shard3 = RelayShard(clusterId: DefaultClusterId, shardId: 3)
|
|
|
|
|
shard4 = RelayShard(clusterId: DefaultClusterId, shardId: 4)
|
|
|
|
|
|
2025-06-02 22:02:49 +02:00
|
|
|
(await node.mountRelay()).isOkOr:
|
2025-05-05 22:57:20 +02:00
|
|
|
assert false, "Failed to mount relay"
|
2022-06-10 13:30:51 +02:00
|
|
|
|
2025-06-02 22:02:49 +02:00
|
|
|
proc simpleHandler(
|
|
|
|
|
topic: PubsubTopic, msg: WakuMessage
|
|
|
|
|
): Future[void] {.async, gcsafe.} =
|
|
|
|
|
await sleepAsync(0.milliseconds)
|
|
|
|
|
|
|
|
|
|
for shard in @[$shard0, $shard1, $shard2, $shard3, $shard4]:
|
|
|
|
|
node.subscribe((kind: PubsubSub, topic: shard), simpleHandler).isOkOr:
|
|
|
|
|
assert false, "Failed to subscribe to pubsub topic: " & $error
|
|
|
|
|
|
2024-01-18 13:49:13 +01:00
|
|
|
var restPort = Port(0)
|
2023-12-14 07:16:39 +01:00
|
|
|
let restAddress = parseIpAddress("0.0.0.0")
|
2024-02-29 09:48:14 +01:00
|
|
|
let restServer = WakuRestServerRef.init(restAddress, restPort).tryGet()
|
2022-06-10 13:30:51 +02:00
|
|
|
|
2024-02-29 09:48:14 +01:00
|
|
|
restPort = restServer.httpServer.address.port # update with bound port for client use
|
2024-01-18 13:49:13 +01:00
|
|
|
|
2023-11-28 07:21:41 -05:00
|
|
|
let cache = MessageCache.init()
|
2024-09-10 15:07:12 -06:00
|
|
|
cache.pubsubSubscribe($shard0)
|
|
|
|
|
cache.pubsubSubscribe($shard1)
|
|
|
|
|
cache.pubsubSubscribe($shard2)
|
|
|
|
|
cache.pubsubSubscribe($shard3)
|
2022-06-10 13:30:51 +02:00
|
|
|
|
2023-09-26 07:33:52 -04:00
|
|
|
installRelayApiHandlers(restServer.router, node, cache)
|
2022-06-10 13:30:51 +02:00
|
|
|
restServer.start()
|
|
|
|
|
|
2024-09-10 15:07:12 -06:00
|
|
|
let shards = @[$shard0, $shard1, $shard2, $shard4]
|
2022-06-10 13:30:51 +02:00
|
|
|
|
|
|
|
|
# When
|
|
|
|
|
let client = newRestHttpClient(initTAddress(restAddress, restPort))
|
2024-09-10 15:07:12 -06:00
|
|
|
let response = await client.relayDeleteSubscriptionsV1(shards)
|
2022-06-10 13:30:51 +02:00
|
|
|
|
|
|
|
|
# Then
|
|
|
|
|
check:
|
|
|
|
|
response.status == 200
|
2022-10-28 12:51:46 +03:00
|
|
|
$response.contentType == $MIMETYPE_TEXT
|
2022-06-10 13:30:51 +02:00
|
|
|
response.data == "OK"
|
|
|
|
|
|
|
|
|
|
check:
|
2024-09-10 15:07:12 -06:00
|
|
|
not cache.isPubsubSubscribed($shard0)
|
|
|
|
|
not node.wakuRelay.isSubscribed($shard0)
|
|
|
|
|
not cache.isPubsubSubscribed($shard1)
|
|
|
|
|
not node.wakuRelay.isSubscribed($shard1)
|
|
|
|
|
not cache.isPubsubSubscribed($shard2)
|
|
|
|
|
not node.wakuRelay.isSubscribed($shard2)
|
|
|
|
|
cache.isPubsubSubscribed($shard3)
|
|
|
|
|
node.wakuRelay.isSubscribed($shard3)
|
|
|
|
|
not cache.isPubsubSubscribed($shard4)
|
|
|
|
|
not node.wakuRelay.isSubscribed($shard4)
|
2022-06-10 13:30:51 +02:00
|
|
|
|
|
|
|
|
await restServer.stop()
|
|
|
|
|
await restServer.closeWait()
|
|
|
|
|
await node.stop()
|
|
|
|
|
|
2023-09-26 07:33:52 -04:00
|
|
|
asyncTest "Get the latest messages for a pubsub topic - GET /relay/v1/messages/{topic}":
|
2022-06-10 13:30:51 +02:00
|
|
|
# Given
|
|
|
|
|
let node = testWakuNode()
|
|
|
|
|
await node.start()
|
2025-05-05 22:57:20 +02:00
|
|
|
(await node.mountRelay()).isOkOr:
|
|
|
|
|
assert false, "Failed to mount relay"
|
2022-06-10 13:30:51 +02:00
|
|
|
|
2024-01-18 13:49:13 +01:00
|
|
|
var restPort = Port(0)
|
2023-12-14 07:16:39 +01:00
|
|
|
let restAddress = parseIpAddress("0.0.0.0")
|
2024-02-29 09:48:14 +01:00
|
|
|
let restServer = WakuRestServerRef.init(restAddress, restPort).tryGet()
|
2022-06-10 13:30:51 +02:00
|
|
|
|
2024-02-29 09:48:14 +01:00
|
|
|
restPort = restServer.httpServer.address.port # update with bound port for client use
|
2024-01-18 13:49:13 +01:00
|
|
|
|
2024-07-09 18:36:12 +03:00
|
|
|
let pubSubTopic = "/waku/2/rs/0/0"
|
2024-02-29 09:48:14 +01:00
|
|
|
|
2024-03-16 00:08:47 +01:00
|
|
|
var messages =
|
|
|
|
|
@[
|
|
|
|
|
fakeWakuMessage(
|
|
|
|
|
contentTopic = "content-topic-x",
|
|
|
|
|
payload = toBytes("TEST-1"),
|
|
|
|
|
meta = toBytes("test-meta"),
|
|
|
|
|
ephemeral = true,
|
|
|
|
|
)
|
|
|
|
|
]
|
2022-06-10 13:30:51 +02:00
|
|
|
|
2023-11-28 07:21:41 -05:00
|
|
|
# Prevent duplicate messages
|
2024-03-16 00:08:47 +01:00
|
|
|
for i in 0 ..< 2:
|
|
|
|
|
var msg = fakeWakuMessage(
|
|
|
|
|
contentTopic = "content-topic-x",
|
|
|
|
|
payload = toBytes("TEST-1"),
|
|
|
|
|
meta = toBytes("test-meta"),
|
|
|
|
|
ephemeral = true,
|
|
|
|
|
)
|
2022-06-10 13:30:51 +02:00
|
|
|
|
2023-11-28 07:21:41 -05:00
|
|
|
while msg == messages[i]:
|
2024-03-16 00:08:47 +01:00
|
|
|
msg = fakeWakuMessage(
|
|
|
|
|
contentTopic = "content-topic-x",
|
|
|
|
|
payload = toBytes("TEST-1"),
|
|
|
|
|
meta = toBytes("test-meta"),
|
|
|
|
|
ephemeral = true,
|
|
|
|
|
)
|
2024-02-14 17:29:59 +02:00
|
|
|
|
2023-11-28 07:21:41 -05:00
|
|
|
messages.add(msg)
|
2024-02-29 09:48:14 +01:00
|
|
|
|
2023-11-28 07:21:41 -05:00
|
|
|
let cache = MessageCache.init()
|
|
|
|
|
|
|
|
|
|
cache.pubsubSubscribe(pubSubTopic)
|
2022-06-10 13:30:51 +02:00
|
|
|
for msg in messages:
|
2023-09-26 07:33:52 -04:00
|
|
|
cache.addMessage(pubSubTopic, msg)
|
2022-06-10 13:30:51 +02:00
|
|
|
|
2023-09-26 07:33:52 -04:00
|
|
|
installRelayApiHandlers(restServer.router, node, cache)
|
2022-06-10 13:30:51 +02:00
|
|
|
restServer.start()
|
|
|
|
|
|
|
|
|
|
# When
|
|
|
|
|
let client = newRestHttpClient(initTAddress(restAddress, restPort))
|
|
|
|
|
let response = await client.relayGetMessagesV1(pubSubTopic)
|
|
|
|
|
|
|
|
|
|
# Then
|
|
|
|
|
check:
|
|
|
|
|
response.status == 200
|
2022-10-28 12:51:46 +03:00
|
|
|
$response.contentType == $MIMETYPE_JSON
|
2022-06-10 13:30:51 +02:00
|
|
|
response.data.len == 3
|
2024-03-16 00:08:47 +01:00
|
|
|
response.data.all do(msg: RelayWakuMessage) -> bool:
|
2023-02-23 09:31:06 +01:00
|
|
|
msg.payload == base64.encode("TEST-1") and
|
2024-03-16 00:08:47 +01:00
|
|
|
msg.contentTopic.get() == "content-topic-x" and msg.version.get() == 2 and
|
|
|
|
|
msg.timestamp.get() != Timestamp(0) and
|
|
|
|
|
msg.meta.get() == base64.encode("test-meta") and msg.ephemeral.get() == true
|
2022-06-10 13:30:51 +02:00
|
|
|
|
|
|
|
|
check:
|
2023-11-28 07:21:41 -05:00
|
|
|
cache.isPubsubSubscribed(pubSubTopic)
|
2023-09-26 07:33:52 -04:00
|
|
|
cache.getMessages(pubSubTopic).tryGet().len == 0
|
2022-06-10 13:30:51 +02:00
|
|
|
|
|
|
|
|
await restServer.stop()
|
|
|
|
|
await restServer.closeWait()
|
|
|
|
|
await node.stop()
|
|
|
|
|
|
2023-09-26 07:33:52 -04:00
|
|
|
asyncTest "Post a message to a pubsub topic - POST /relay/v1/messages/{topic}":
|
2023-02-10 15:17:50 +01:00
|
|
|
## "Relay API: publish and subscribe/unsubscribe":
|
2022-06-10 13:30:51 +02:00
|
|
|
# Given
|
|
|
|
|
let node = testWakuNode()
|
2025-05-05 22:57:20 +02:00
|
|
|
(await node.mountRelay()).isOkOr:
|
|
|
|
|
assert false, "Failed to mount relay"
|
2025-09-26 14:47:15 +05:30
|
|
|
let wakuRlnConfig = getWakuRlnConfig(manager = manager, index = MembershipIndex(1))
|
2024-06-20 15:05:21 +05:30
|
|
|
|
2024-03-12 16:20:30 +05:30
|
|
|
await node.mountRlnRelay(wakuRlnConfig)
|
2025-09-10 16:18:51 +05:30
|
|
|
await node.start()
|
|
|
|
|
# Registration is mandatory before sending messages with rln-relay
|
|
|
|
|
let manager = cast[OnchainGroupManager](node.wakuRlnRelay.groupManager)
|
|
|
|
|
let idCredentials = generateCredentials(manager.rlnInstance)
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
waitFor manager.register(idCredentials, UserMessageLimit(20))
|
|
|
|
|
except Exception, CatchableError:
|
|
|
|
|
assert false,
|
|
|
|
|
"exception raised when calling register: " & getCurrentExceptionMsg()
|
|
|
|
|
|
|
|
|
|
let rootUpdated = waitFor manager.updateRoots()
|
2025-10-15 10:49:36 +02:00
|
|
|
info "Updated root for node", rootUpdated
|
2025-09-10 16:18:51 +05:30
|
|
|
|
|
|
|
|
let proofRes = waitFor manager.fetchMerkleProofElements()
|
|
|
|
|
if proofRes.isErr():
|
|
|
|
|
assert false, "failed to fetch merkle proof: " & proofRes.error
|
|
|
|
|
manager.merkleProofCache = proofRes.get()
|
2022-06-10 13:30:51 +02:00
|
|
|
|
|
|
|
|
# RPC server setup
|
2024-01-18 13:49:13 +01:00
|
|
|
var restPort = Port(0)
|
2023-12-14 07:16:39 +01:00
|
|
|
let restAddress = parseIpAddress("0.0.0.0")
|
2024-02-29 09:48:14 +01:00
|
|
|
let restServer = WakuRestServerRef.init(restAddress, restPort).tryGet()
|
2022-06-10 13:30:51 +02:00
|
|
|
|
2024-02-29 09:48:14 +01:00
|
|
|
restPort = restServer.httpServer.address.port # update with bound port for client use
|
2024-01-18 13:49:13 +01:00
|
|
|
|
2023-11-28 07:21:41 -05:00
|
|
|
let cache = MessageCache.init()
|
2022-06-10 13:30:51 +02:00
|
|
|
|
2023-09-26 07:33:52 -04:00
|
|
|
installRelayApiHandlers(restServer.router, node, cache)
|
2022-06-10 13:30:51 +02:00
|
|
|
restServer.start()
|
|
|
|
|
|
|
|
|
|
let client = newRestHttpClient(initTAddress(restAddress, restPort))
|
2023-02-10 15:17:50 +01:00
|
|
|
|
2025-06-02 22:02:49 +02:00
|
|
|
let simpleHandler = proc(
|
|
|
|
|
topic: PubsubTopic, msg: WakuMessage
|
|
|
|
|
): Future[void] {.async, gcsafe.} =
|
|
|
|
|
await sleepAsync(0.milliseconds)
|
|
|
|
|
|
|
|
|
|
node.subscribe((kind: PubsubSub, topic: DefaultPubsubTopic), simpleHandler).isOkOr:
|
2025-05-05 22:57:20 +02:00
|
|
|
assert false, "Failed to subscribe to pubsub topic"
|
2025-06-02 22:02:49 +02:00
|
|
|
|
2023-02-10 15:17:50 +01:00
|
|
|
require:
|
|
|
|
|
toSeq(node.wakuRelay.subscribedTopics).len == 1
|
|
|
|
|
|
2022-06-10 13:30:51 +02:00
|
|
|
# When
|
2024-03-16 00:08:47 +01:00
|
|
|
let response = await client.relayPostMessagesV1(
|
|
|
|
|
DefaultPubsubTopic,
|
|
|
|
|
RelayWakuMessage(
|
|
|
|
|
payload: base64.encode("TEST-PAYLOAD"),
|
|
|
|
|
contentTopic: some(DefaultContentTopic),
|
2025-05-26 17:56:29 +05:30
|
|
|
timestamp: some(now()),
|
2024-03-16 00:08:47 +01:00
|
|
|
),
|
|
|
|
|
)
|
2022-06-10 13:30:51 +02:00
|
|
|
|
|
|
|
|
# Then
|
|
|
|
|
check:
|
|
|
|
|
response.status == 200
|
2022-10-28 12:51:46 +03:00
|
|
|
$response.contentType == $MIMETYPE_TEXT
|
2022-06-10 13:30:51 +02:00
|
|
|
response.data == "OK"
|
|
|
|
|
|
2023-09-26 07:33:52 -04: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()
|
2025-05-05 22:57:20 +02:00
|
|
|
(await node.mountRelay()).isOkOr:
|
|
|
|
|
assert false, "Failed to mount relay"
|
2025-07-04 17:10:53 +10:00
|
|
|
require node.mountAutoSharding(1, 8).isOk
|
2023-09-26 07:33:52 -04:00
|
|
|
|
2024-01-18 13:49:13 +01:00
|
|
|
var restPort = Port(0)
|
2023-12-14 07:16:39 +01:00
|
|
|
let restAddress = parseIpAddress("0.0.0.0")
|
2024-02-29 09:48:14 +01:00
|
|
|
let restServer = WakuRestServerRef.init(restAddress, restPort).tryGet()
|
2023-09-26 07:33:52 -04:00
|
|
|
|
2024-02-29 09:48:14 +01:00
|
|
|
restPort = restServer.httpServer.address.port # update with bound port for client use
|
2024-01-18 13:49:13 +01:00
|
|
|
|
2023-11-28 07:21:41 -05:00
|
|
|
let cache = MessageCache.init()
|
2023-09-26 07:33:52 -04:00
|
|
|
|
|
|
|
|
installRelayApiHandlers(restServer.router, node, cache)
|
|
|
|
|
restServer.start()
|
|
|
|
|
|
2024-03-16 00:08:47 +01:00
|
|
|
let contentTopics =
|
|
|
|
|
@[
|
|
|
|
|
ContentTopic("/app-1/2/default-content/proto"),
|
|
|
|
|
ContentTopic("/app-2/2/default-content/proto"),
|
|
|
|
|
ContentTopic("/app-3/2/default-content/proto"),
|
|
|
|
|
]
|
2023-09-26 07:33:52 -04:00
|
|
|
|
|
|
|
|
# When
|
|
|
|
|
let client = newRestHttpClient(initTAddress(restAddress, restPort))
|
2023-09-26 15:53:46 -04:00
|
|
|
let response = await client.relayPostAutoSubscriptionsV1(contentTopics)
|
2023-09-26 07:33:52 -04:00
|
|
|
|
|
|
|
|
# Then
|
|
|
|
|
check:
|
|
|
|
|
response.status == 200
|
|
|
|
|
$response.contentType == $MIMETYPE_TEXT
|
|
|
|
|
response.data == "OK"
|
|
|
|
|
|
|
|
|
|
check:
|
2023-11-28 07:21:41 -05:00
|
|
|
cache.isContentSubscribed(contentTopics[0])
|
|
|
|
|
cache.isContentSubscribed(contentTopics[1])
|
|
|
|
|
cache.isContentSubscribed(contentTopics[2])
|
2023-09-26 07:33:52 -04:00
|
|
|
|
|
|
|
|
check:
|
|
|
|
|
# Node should be subscribed to all shards
|
2024-03-16 00:08:47 +01:00
|
|
|
node.wakuRelay.subscribedTopics ==
|
2025-05-26 21:58:02 +02:00
|
|
|
@["/waku/2/rs/1/5", "/waku/2/rs/1/7", "/waku/2/rs/1/2"]
|
2022-06-10 13:30:51 +02:00
|
|
|
|
|
|
|
|
await restServer.stop()
|
|
|
|
|
await restServer.closeWait()
|
|
|
|
|
await node.stop()
|
2023-09-26 07:33:52 -04:00
|
|
|
|
|
|
|
|
asyncTest "Unsubscribe a node from an array of content topics - DELETE /relay/v1/auto/subscriptions":
|
|
|
|
|
# Given
|
|
|
|
|
let node = testWakuNode()
|
|
|
|
|
await node.start()
|
2025-05-05 22:57:20 +02:00
|
|
|
(await node.mountRelay()).isOkOr:
|
|
|
|
|
assert false, "Failed to mount relay"
|
2025-07-04 17:10:53 +10:00
|
|
|
require node.mountAutoSharding(1, 8).isOk
|
2023-09-26 07:33:52 -04:00
|
|
|
|
2024-01-18 13:49:13 +01:00
|
|
|
var restPort = Port(0)
|
2023-12-14 07:16:39 +01:00
|
|
|
let restAddress = parseIpAddress("0.0.0.0")
|
2024-02-29 09:48:14 +01:00
|
|
|
let restServer = WakuRestServerRef.init(restAddress, restPort).tryGet()
|
2025-05-05 22:57:20 +02:00
|
|
|
restServer.start()
|
2023-09-26 07:33:52 -04:00
|
|
|
|
2024-02-29 09:48:14 +01:00
|
|
|
restPort = restServer.httpServer.address.port # update with bound port for client use
|
2024-01-18 13:49:13 +01:00
|
|
|
|
2024-03-16 00:08:47 +01:00
|
|
|
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"),
|
|
|
|
|
]
|
2023-09-26 07:33:52 -04:00
|
|
|
|
2023-11-28 07:21:41 -05:00
|
|
|
let cache = MessageCache.init()
|
|
|
|
|
cache.contentSubscribe(contentTopics[0])
|
|
|
|
|
cache.contentSubscribe(contentTopics[1])
|
|
|
|
|
cache.contentSubscribe(contentTopics[2])
|
|
|
|
|
cache.contentSubscribe("/waku/2/default-contentY/proto")
|
2023-09-26 07:33:52 -04:00
|
|
|
|
|
|
|
|
installRelayApiHandlers(restServer.router, node, cache)
|
|
|
|
|
|
|
|
|
|
# When
|
|
|
|
|
let client = newRestHttpClient(initTAddress(restAddress, restPort))
|
2025-05-05 22:57:20 +02:00
|
|
|
|
|
|
|
|
var response = await client.relayPostAutoSubscriptionsV1(contentTopics)
|
|
|
|
|
|
|
|
|
|
check:
|
|
|
|
|
response.status == 200
|
|
|
|
|
$response.contentType == $MIMETYPE_TEXT
|
|
|
|
|
response.data == "OK"
|
|
|
|
|
|
|
|
|
|
response = await client.relayDeleteAutoSubscriptionsV1(contentTopics)
|
2023-09-26 07:33:52 -04:00
|
|
|
|
|
|
|
|
# Then
|
|
|
|
|
check:
|
|
|
|
|
response.status == 200
|
|
|
|
|
$response.contentType == $MIMETYPE_TEXT
|
|
|
|
|
response.data == "OK"
|
|
|
|
|
|
|
|
|
|
check:
|
2023-11-28 07:21:41 -05:00
|
|
|
not cache.isContentSubscribed(contentTopics[1])
|
|
|
|
|
not cache.isContentSubscribed(contentTopics[2])
|
|
|
|
|
not cache.isContentSubscribed(contentTopics[3])
|
|
|
|
|
cache.isContentSubscribed("/waku/2/default-contentY/proto")
|
2023-09-26 07:33:52 -04:00
|
|
|
|
|
|
|
|
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()
|
2025-05-05 22:57:20 +02:00
|
|
|
(await node.mountRelay()).isOkOr:
|
|
|
|
|
assert false, "Failed to mount relay"
|
2025-07-04 17:10:53 +10:00
|
|
|
require node.mountAutoSharding(1, 8).isOk
|
2023-09-26 07:33:52 -04:00
|
|
|
|
2024-01-18 13:49:13 +01:00
|
|
|
var restPort = Port(0)
|
2023-12-14 07:16:39 +01:00
|
|
|
let restAddress = parseIpAddress("0.0.0.0")
|
2024-02-29 09:48:14 +01:00
|
|
|
let restServer = WakuRestServerRef.init(restAddress, restPort).tryGet()
|
2023-09-26 07:33:52 -04:00
|
|
|
|
2024-02-29 09:48:14 +01:00
|
|
|
restPort = restServer.httpServer.address.port # update with bound port for client use
|
2024-01-18 13:49:13 +01:00
|
|
|
|
2023-09-26 07:33:52 -04:00
|
|
|
let contentTopic = DefaultContentTopic
|
2023-11-28 07:21:41 -05:00
|
|
|
|
2024-03-16 00:08:47 +01:00
|
|
|
var messages =
|
|
|
|
|
@[
|
|
|
|
|
fakeWakuMessage(contentTopic = DefaultContentTopic, payload = toBytes("TEST-1"))
|
|
|
|
|
]
|
2023-09-26 07:33:52 -04:00
|
|
|
|
2023-11-28 07:21:41 -05:00
|
|
|
# Prevent duplicate messages
|
2024-03-16 00:08:47 +01:00
|
|
|
for i in 0 ..< 2:
|
|
|
|
|
var msg =
|
|
|
|
|
fakeWakuMessage(contentTopic = DefaultContentTopic, payload = toBytes("TEST-1"))
|
2023-11-28 07:21:41 -05:00
|
|
|
|
|
|
|
|
while msg == messages[i]:
|
2024-03-16 00:08:47 +01:00
|
|
|
msg = fakeWakuMessage(
|
|
|
|
|
contentTopic = DefaultContentTopic, payload = toBytes("TEST-1")
|
|
|
|
|
)
|
2024-02-29 09:48:14 +01:00
|
|
|
|
2023-11-28 07:21:41 -05:00
|
|
|
messages.add(msg)
|
2024-02-29 09:48:14 +01:00
|
|
|
|
2023-11-28 07:21:41 -05:00
|
|
|
let cache = MessageCache.init()
|
2023-09-26 07:33:52 -04:00
|
|
|
|
2023-11-28 07:21:41 -05:00
|
|
|
cache.contentSubscribe(contentTopic)
|
2023-09-26 07:33:52 -04:00
|
|
|
for msg in messages:
|
2023-11-28 07:21:41 -05:00
|
|
|
cache.addMessage(DefaultPubsubTopic, msg)
|
2023-09-26 07:33:52 -04:00
|
|
|
|
|
|
|
|
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
|
2024-03-16 00:08:47 +01:00
|
|
|
response.data.all do(msg: RelayWakuMessage) -> bool:
|
2023-09-26 07:33:52 -04:00
|
|
|
msg.payload == base64.encode("TEST-1") and
|
2024-03-16 00:08:47 +01:00
|
|
|
msg.contentTopic.get() == DefaultContentTopic and msg.version.get() == 2 and
|
|
|
|
|
msg.timestamp.get() != Timestamp(0)
|
2023-09-26 07:33:52 -04:00
|
|
|
|
|
|
|
|
check:
|
2023-11-28 07:21:41 -05:00
|
|
|
cache.isContentSubscribed(contentTopic)
|
2024-03-16 00:08:47 +01:00
|
|
|
cache.getAutoMessages(contentTopic).tryGet().len == 0
|
|
|
|
|
# The cache is cleared when getMessage is called
|
2023-09-26 07:33:52 -04:00
|
|
|
|
|
|
|
|
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()
|
2025-05-05 22:57:20 +02:00
|
|
|
(await node.mountRelay()).isOkOr:
|
|
|
|
|
assert false, "Failed to mount relay"
|
2025-07-04 17:10:53 +10:00
|
|
|
require node.mountAutoSharding(1, 8).isOk
|
|
|
|
|
|
2025-09-26 14:47:15 +05:30
|
|
|
let wakuRlnConfig = getWakuRlnConfig(manager = manager, index = MembershipIndex(1))
|
2024-06-20 15:05:21 +05:30
|
|
|
|
2024-03-12 16:20:30 +05:30
|
|
|
await node.mountRlnRelay(wakuRlnConfig)
|
2025-09-10 16:18:51 +05:30
|
|
|
await node.start()
|
|
|
|
|
# Registration is mandatory before sending messages with rln-relay
|
|
|
|
|
let manager = cast[OnchainGroupManager](node.wakuRlnRelay.groupManager)
|
|
|
|
|
let idCredentials = generateCredentials(manager.rlnInstance)
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
waitFor manager.register(idCredentials, UserMessageLimit(20))
|
|
|
|
|
except Exception, CatchableError:
|
|
|
|
|
assert false,
|
|
|
|
|
"exception raised when calling register: " & getCurrentExceptionMsg()
|
|
|
|
|
|
|
|
|
|
let rootUpdated = waitFor manager.updateRoots()
|
2025-10-15 10:49:36 +02:00
|
|
|
info "Updated root for node", rootUpdated
|
2025-09-10 16:18:51 +05:30
|
|
|
|
|
|
|
|
let proofRes = waitFor manager.fetchMerkleProofElements()
|
|
|
|
|
if proofRes.isErr():
|
|
|
|
|
assert false, "failed to fetch merkle proof: " & proofRes.error
|
|
|
|
|
manager.merkleProofCache = proofRes.get()
|
2023-09-26 07:33:52 -04:00
|
|
|
|
|
|
|
|
# RPC server setup
|
2024-01-18 13:49:13 +01:00
|
|
|
var restPort = Port(0)
|
2023-12-14 07:16:39 +01:00
|
|
|
let restAddress = parseIpAddress("0.0.0.0")
|
2024-02-29 09:48:14 +01:00
|
|
|
let restServer = WakuRestServerRef.init(restAddress, restPort).tryGet()
|
2023-09-26 07:33:52 -04:00
|
|
|
|
2024-02-29 09:48:14 +01:00
|
|
|
restPort = restServer.httpServer.address.port # update with bound port for client use
|
2024-01-18 13:49:13 +01:00
|
|
|
|
2023-11-28 07:21:41 -05:00
|
|
|
let cache = MessageCache.init()
|
2023-09-26 07:33:52 -04:00
|
|
|
installRelayApiHandlers(restServer.router, node, cache)
|
|
|
|
|
restServer.start()
|
|
|
|
|
|
|
|
|
|
let client = newRestHttpClient(initTAddress(restAddress, restPort))
|
|
|
|
|
|
2025-06-02 22:02:49 +02:00
|
|
|
let simpleHandler = proc(
|
|
|
|
|
topic: PubsubTopic, msg: WakuMessage
|
|
|
|
|
): Future[void] {.async, gcsafe.} =
|
|
|
|
|
await sleepAsync(0.milliseconds)
|
|
|
|
|
|
|
|
|
|
node.subscribe((kind: ContentSub, topic: DefaultContentTopic), simpleHandler).isOkOr:
|
2025-05-05 22:57:20 +02:00
|
|
|
assert false, "Failed to subscribe to content topic: " & $error
|
2023-09-26 07:33:52 -04:00
|
|
|
require:
|
|
|
|
|
toSeq(node.wakuRelay.subscribedTopics).len == 1
|
|
|
|
|
|
|
|
|
|
# When
|
2024-03-16 00:08:47 +01:00
|
|
|
let response = await client.relayPostAutoMessagesV1(
|
|
|
|
|
RelayWakuMessage(
|
|
|
|
|
payload: base64.encode("TEST-PAYLOAD"),
|
|
|
|
|
contentTopic: some(DefaultContentTopic),
|
2025-05-26 17:56:29 +05:30
|
|
|
timestamp: some(now()),
|
2024-03-16 00:08:47 +01:00
|
|
|
)
|
|
|
|
|
)
|
2023-09-26 07:33:52 -04:00
|
|
|
|
|
|
|
|
# Then
|
|
|
|
|
check:
|
|
|
|
|
response.status == 200
|
|
|
|
|
$response.contentType == $MIMETYPE_TEXT
|
|
|
|
|
response.data == "OK"
|
|
|
|
|
|
2024-01-18 13:49:13 +01:00
|
|
|
await restServer.stop()
|
|
|
|
|
await restServer.closeWait()
|
|
|
|
|
await node.stop()
|
|
|
|
|
|
|
|
|
|
asyncTest "Post a message to an invalid content topic - POST /relay/v1/auto/messages/{topic}":
|
|
|
|
|
## "Relay API: publish and subscribe/unsubscribe":
|
|
|
|
|
# Given
|
|
|
|
|
let node = testWakuNode()
|
2025-05-05 22:57:20 +02:00
|
|
|
(await node.mountRelay()).isOkOr:
|
|
|
|
|
assert false, "Failed to mount relay"
|
2025-07-04 17:10:53 +10:00
|
|
|
require node.mountAutoSharding(1, 8).isOk
|
|
|
|
|
|
2025-09-26 14:47:15 +05:30
|
|
|
let wakuRlnConfig = getWakuRlnConfig(manager = manager, index = MembershipIndex(1))
|
2024-03-12 16:20:30 +05:30
|
|
|
await node.mountRlnRelay(wakuRlnConfig)
|
2025-09-10 16:18:51 +05:30
|
|
|
await node.start()
|
|
|
|
|
|
|
|
|
|
# Registration is mandatory before sending messages with rln-relay
|
|
|
|
|
let manager = cast[OnchainGroupManager](node.wakuRlnRelay.groupManager)
|
|
|
|
|
let idCredentials = generateCredentials(manager.rlnInstance)
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
waitFor manager.register(idCredentials, UserMessageLimit(20))
|
|
|
|
|
except Exception, CatchableError:
|
|
|
|
|
assert false,
|
|
|
|
|
"exception raised when calling register: " & getCurrentExceptionMsg()
|
|
|
|
|
|
|
|
|
|
let rootUpdated = waitFor manager.updateRoots()
|
2025-10-15 10:49:36 +02:00
|
|
|
info "Updated root for node", rootUpdated
|
2025-09-10 16:18:51 +05:30
|
|
|
|
|
|
|
|
let proofRes = waitFor manager.fetchMerkleProofElements()
|
|
|
|
|
if proofRes.isErr():
|
|
|
|
|
assert false, "failed to fetch merkle proof: " & proofRes.error
|
|
|
|
|
manager.merkleProofCache = proofRes.get()
|
2024-01-18 13:49:13 +01:00
|
|
|
|
|
|
|
|
# RPC server setup
|
|
|
|
|
var restPort = Port(0)
|
|
|
|
|
let restAddress = parseIpAddress("0.0.0.0")
|
2024-02-29 09:48:14 +01:00
|
|
|
let restServer = WakuRestServerRef.init(restAddress, restPort).tryGet()
|
2024-01-18 13:49:13 +01:00
|
|
|
|
2024-02-29 09:48:14 +01:00
|
|
|
restPort = restServer.httpServer.address.port # update with bound port for client use
|
2024-01-18 13:49:13 +01:00
|
|
|
|
|
|
|
|
let cache = MessageCache.init()
|
|
|
|
|
installRelayApiHandlers(restServer.router, node, cache)
|
|
|
|
|
restServer.start()
|
|
|
|
|
|
|
|
|
|
let client = newRestHttpClient(initTAddress(restAddress, restPort))
|
|
|
|
|
|
2024-06-20 18:38:55 +05:30
|
|
|
let invalidContentTopic = "invalidContentTopic"
|
2024-01-18 13:49:13 +01:00
|
|
|
# When
|
2024-03-16 00:08:47 +01:00
|
|
|
let response = await client.relayPostAutoMessagesV1(
|
|
|
|
|
RelayWakuMessage(
|
|
|
|
|
payload: base64.encode("TEST-PAYLOAD"),
|
2024-06-20 18:38:55 +05:30
|
|
|
contentTopic: some(invalidContentTopic),
|
2024-03-16 00:08:47 +01:00
|
|
|
timestamp: some(int64(2022)),
|
|
|
|
|
)
|
|
|
|
|
)
|
2024-01-18 13:49:13 +01:00
|
|
|
|
|
|
|
|
# Then
|
|
|
|
|
check:
|
|
|
|
|
response.status == 400
|
|
|
|
|
$response.contentType == $MIMETYPE_TEXT
|
2024-03-16 00:08:47 +01:00
|
|
|
response.data ==
|
2024-06-20 18:38:55 +05:30
|
|
|
"Failed to publish. Autosharding error: invalid format: content-topic '" &
|
|
|
|
|
invalidContentTopic & "' must start with slash"
|
2024-01-18 13:49:13 +01:00
|
|
|
|
2024-02-01 18:16:10 +01:00
|
|
|
await restServer.stop()
|
|
|
|
|
await restServer.closeWait()
|
|
|
|
|
await node.stop()
|
|
|
|
|
|
|
|
|
|
asyncTest "Post a message larger than maximum size - POST /relay/v1/messages/{topic}":
|
|
|
|
|
# Given
|
|
|
|
|
let node = testWakuNode()
|
2025-05-05 22:57:20 +02:00
|
|
|
(await node.mountRelay()).isOkOr:
|
|
|
|
|
assert false, "Failed to mount relay"
|
2025-09-26 14:47:15 +05:30
|
|
|
let wakuRlnConfig = getWakuRlnConfig(manager = manager, index = MembershipIndex(1))
|
2024-03-12 16:20:30 +05:30
|
|
|
await node.mountRlnRelay(wakuRlnConfig)
|
2025-09-10 16:18:51 +05:30
|
|
|
await node.start()
|
|
|
|
|
|
|
|
|
|
# Registration is mandatory before sending messages with rln-relay
|
|
|
|
|
let manager = cast[OnchainGroupManager](node.wakuRlnRelay.groupManager)
|
|
|
|
|
let idCredentials = generateCredentials(manager.rlnInstance)
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
waitFor manager.register(idCredentials, UserMessageLimit(20))
|
|
|
|
|
except Exception, CatchableError:
|
|
|
|
|
assert false,
|
|
|
|
|
"exception raised when calling register: " & getCurrentExceptionMsg()
|
|
|
|
|
|
|
|
|
|
let rootUpdated = waitFor manager.updateRoots()
|
2025-10-15 10:49:36 +02:00
|
|
|
info "Updated root for node", rootUpdated
|
2025-09-10 16:18:51 +05:30
|
|
|
|
|
|
|
|
let proofRes = waitFor manager.fetchMerkleProofElements()
|
|
|
|
|
if proofRes.isErr():
|
|
|
|
|
assert false, "failed to fetch merkle proof: " & proofRes.error
|
|
|
|
|
manager.merkleProofCache = proofRes.get()
|
2024-02-01 18:16:10 +01:00
|
|
|
|
|
|
|
|
# RPC server setup
|
|
|
|
|
var restPort = Port(0)
|
|
|
|
|
let restAddress = parseIpAddress("0.0.0.0")
|
2024-02-29 09:48:14 +01:00
|
|
|
let restServer = WakuRestServerRef.init(restAddress, restPort).tryGet()
|
2024-02-01 18:16:10 +01:00
|
|
|
|
2024-02-29 09:48:14 +01:00
|
|
|
restPort = restServer.httpServer.address.port # update with bound port for client use
|
2024-02-01 18:16:10 +01:00
|
|
|
|
|
|
|
|
let cache = MessageCache.init()
|
|
|
|
|
|
|
|
|
|
installRelayApiHandlers(restServer.router, node, cache)
|
|
|
|
|
restServer.start()
|
|
|
|
|
|
|
|
|
|
let client = newRestHttpClient(initTAddress(restAddress, restPort))
|
|
|
|
|
|
2025-06-02 22:02:49 +02:00
|
|
|
let simpleHandler = proc(
|
|
|
|
|
topic: PubsubTopic, msg: WakuMessage
|
|
|
|
|
): Future[void] {.async, gcsafe.} =
|
|
|
|
|
await sleepAsync(0.milliseconds)
|
|
|
|
|
|
|
|
|
|
node.subscribe((kind: PubsubSub, topic: DefaultPubsubTopic), simpleHandler).isOkOr:
|
2025-05-05 22:57:20 +02:00
|
|
|
assert false, "Failed to subscribe to pubsub topic: " & $error
|
2024-02-01 18:16:10 +01:00
|
|
|
require:
|
|
|
|
|
toSeq(node.wakuRelay.subscribedTopics).len == 1
|
|
|
|
|
|
|
|
|
|
# When
|
2024-03-16 00:08:47 +01:00
|
|
|
let response = await client.relayPostMessagesV1(
|
|
|
|
|
DefaultPubsubTopic,
|
|
|
|
|
RelayWakuMessage(
|
2024-04-20 09:10:52 +05:30
|
|
|
payload: base64.encode(getByteSequence(DefaultMaxWakuMessageSize)),
|
2024-03-16 00:08:47 +01:00
|
|
|
# Message will be bigger than the max size
|
|
|
|
|
contentTopic: some(DefaultContentTopic),
|
|
|
|
|
timestamp: some(int64(2022)),
|
|
|
|
|
),
|
|
|
|
|
)
|
2024-02-29 09:48:14 +01:00
|
|
|
|
2024-02-05 09:24:54 +01:00
|
|
|
# Then
|
|
|
|
|
check:
|
|
|
|
|
response.status == 400
|
|
|
|
|
$response.contentType == $MIMETYPE_TEXT
|
2024-03-16 00:08:47 +01:00
|
|
|
response.data ==
|
2024-04-20 09:10:52 +05:30
|
|
|
fmt"Failed to publish: Message size exceeded maximum of {DefaultMaxWakuMessageSize} bytes"
|
2024-02-05 09:24:54 +01:00
|
|
|
|
|
|
|
|
await restServer.stop()
|
|
|
|
|
await restServer.closeWait()
|
|
|
|
|
await node.stop()
|
|
|
|
|
|
|
|
|
|
asyncTest "Post a message larger than maximum size - POST /relay/v1/auto/messages/{topic}":
|
|
|
|
|
# Given
|
|
|
|
|
let node = testWakuNode()
|
2025-05-05 22:57:20 +02:00
|
|
|
(await node.mountRelay()).isOkOr:
|
|
|
|
|
assert false, "Failed to mount relay"
|
2025-07-04 17:10:53 +10:00
|
|
|
require node.mountAutoSharding(1, 8).isOk
|
|
|
|
|
|
2025-09-26 14:47:15 +05:30
|
|
|
let wakuRlnConfig = getWakuRlnConfig(manager = manager, index = MembershipIndex(1))
|
2024-03-12 16:20:30 +05:30
|
|
|
await node.mountRlnRelay(wakuRlnConfig)
|
2025-09-10 16:18:51 +05:30
|
|
|
await node.start()
|
|
|
|
|
|
|
|
|
|
# Registration is mandatory before sending messages with rln-relay
|
|
|
|
|
let manager = cast[OnchainGroupManager](node.wakuRlnRelay.groupManager)
|
|
|
|
|
let idCredentials = generateCredentials(manager.rlnInstance)
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
waitFor manager.register(idCredentials, UserMessageLimit(20))
|
|
|
|
|
except Exception, CatchableError:
|
|
|
|
|
assert false,
|
|
|
|
|
"exception raised when calling register: " & getCurrentExceptionMsg()
|
|
|
|
|
|
|
|
|
|
let rootUpdated = waitFor manager.updateRoots()
|
2025-10-15 10:49:36 +02:00
|
|
|
info "Updated root for node", rootUpdated
|
2025-09-10 16:18:51 +05:30
|
|
|
|
|
|
|
|
let proofRes = waitFor manager.fetchMerkleProofElements()
|
|
|
|
|
if proofRes.isErr():
|
|
|
|
|
assert false, "failed to fetch merkle proof: " & proofRes.error
|
|
|
|
|
manager.merkleProofCache = proofRes.get()
|
2024-02-05 09:24:54 +01:00
|
|
|
|
|
|
|
|
# RPC server setup
|
|
|
|
|
var restPort = Port(0)
|
|
|
|
|
let restAddress = parseIpAddress("0.0.0.0")
|
2024-02-29 09:48:14 +01:00
|
|
|
let restServer = WakuRestServerRef.init(restAddress, restPort).tryGet()
|
2024-02-05 09:24:54 +01:00
|
|
|
|
2024-02-29 09:48:14 +01:00
|
|
|
restPort = restServer.httpServer.address.port # update with bound port for client use
|
2024-02-05 09:24:54 +01:00
|
|
|
|
|
|
|
|
let cache = MessageCache.init()
|
|
|
|
|
|
|
|
|
|
installRelayApiHandlers(restServer.router, node, cache)
|
|
|
|
|
restServer.start()
|
|
|
|
|
|
|
|
|
|
let client = newRestHttpClient(initTAddress(restAddress, restPort))
|
|
|
|
|
|
2025-06-02 22:02:49 +02:00
|
|
|
let simpleHandler = proc(
|
|
|
|
|
topic: PubsubTopic, msg: WakuMessage
|
|
|
|
|
): Future[void] {.async, gcsafe.} =
|
|
|
|
|
await sleepAsync(0.milliseconds)
|
|
|
|
|
|
|
|
|
|
node.subscribe((kind: PubsubSub, topic: DefaultPubsubTopic), simpleHandler).isOkOr:
|
2025-05-05 22:57:20 +02:00
|
|
|
assert false, "Failed to subscribe to pubsub topic: " & $error
|
2024-02-05 09:24:54 +01:00
|
|
|
require:
|
|
|
|
|
toSeq(node.wakuRelay.subscribedTopics).len == 1
|
|
|
|
|
|
|
|
|
|
# When
|
2024-03-16 00:08:47 +01:00
|
|
|
let response = await client.relayPostAutoMessagesV1(
|
|
|
|
|
RelayWakuMessage(
|
2024-04-20 09:10:52 +05:30
|
|
|
payload: base64.encode(getByteSequence(DefaultMaxWakuMessageSize)),
|
2024-03-16 00:08:47 +01:00
|
|
|
# Message will be bigger than the max size
|
|
|
|
|
contentTopic: some(DefaultContentTopic),
|
|
|
|
|
timestamp: some(int64(2022)),
|
|
|
|
|
)
|
|
|
|
|
)
|
2024-02-29 09:48:14 +01:00
|
|
|
|
2024-02-01 18:16:10 +01:00
|
|
|
# Then
|
|
|
|
|
check:
|
|
|
|
|
response.status == 400
|
|
|
|
|
$response.contentType == $MIMETYPE_TEXT
|
2024-03-16 00:08:47 +01:00
|
|
|
response.data ==
|
2024-04-20 09:10:52 +05:30
|
|
|
fmt"Failed to publish: Message size exceeded maximum of {DefaultMaxWakuMessageSize} bytes"
|
2024-02-01 18:16:10 +01:00
|
|
|
|
2023-09-26 07:33:52 -04:00
|
|
|
await restServer.stop()
|
|
|
|
|
await restServer.closeWait()
|
2024-02-29 09:48:14 +01:00
|
|
|
await node.stop()
|