2024-02-06 16:37:42 +00:00
|
|
|
{.used.}
|
|
|
|
|
|
|
|
import
|
2024-08-02 07:45:05 +00:00
|
|
|
std/[options, tables, sequtils, tempfiles, strutils],
|
2024-02-06 16:37:42 +00:00
|
|
|
stew/shims/net as stewNet,
|
|
|
|
testutils/unittests,
|
|
|
|
chronos,
|
|
|
|
chronicles,
|
2024-05-15 10:13:13 +00:00
|
|
|
std/strformat,
|
2024-02-06 16:37:42 +00:00
|
|
|
os,
|
|
|
|
libp2p/[peerstore, crypto/crypto]
|
|
|
|
|
|
|
|
import
|
2024-07-05 22:03:38 +00:00
|
|
|
waku/[
|
2024-02-06 16:37:42 +00:00
|
|
|
waku_core,
|
|
|
|
node/peer_manager,
|
|
|
|
node/waku_node,
|
|
|
|
waku_filter_v2,
|
|
|
|
waku_filter_v2/client,
|
|
|
|
waku_filter_v2/subscriptions,
|
|
|
|
waku_lightpush,
|
|
|
|
waku_lightpush/common,
|
|
|
|
waku_lightpush/client,
|
|
|
|
waku_lightpush/protocol_metrics,
|
2024-03-15 23:08:47 +00:00
|
|
|
waku_lightpush/rpc,
|
2024-07-05 22:03:38 +00:00
|
|
|
waku_rln_relay,
|
2024-02-06 16:37:42 +00:00
|
|
|
],
|
2024-05-15 10:13:13 +00:00
|
|
|
../testlib/[assertions, common, wakucore, wakunode, testasync, futures, testutils],
|
|
|
|
../resources/payloads
|
2024-02-06 16:37:42 +00:00
|
|
|
|
|
|
|
suite "Waku Lightpush - End To End":
|
|
|
|
var
|
|
|
|
handlerFuture {.threadvar.}: Future[(PubsubTopic, WakuMessage)]
|
|
|
|
handler {.threadvar.}: PushMessageHandler
|
|
|
|
|
|
|
|
server {.threadvar.}: WakuNode
|
|
|
|
client {.threadvar.}: WakuNode
|
|
|
|
|
|
|
|
serverRemotePeerInfo {.threadvar.}: RemotePeerInfo
|
|
|
|
pubsubTopic {.threadvar.}: PubsubTopic
|
|
|
|
contentTopic {.threadvar.}: ContentTopic
|
|
|
|
message {.threadvar.}: WakuMessage
|
|
|
|
|
|
|
|
asyncSetup:
|
|
|
|
handlerFuture = newPushHandlerFuture()
|
2024-03-15 23:08:47 +00:00
|
|
|
handler = proc(
|
2024-02-06 16:37:42 +00:00
|
|
|
peer: PeerId, pubsubTopic: PubsubTopic, message: WakuMessage
|
2024-03-15 23:08:47 +00:00
|
|
|
): Future[WakuLightPushResult[void]] {.async.} =
|
|
|
|
handlerFuture.complete((pubsubTopic, message))
|
|
|
|
return ok()
|
2024-02-06 16:37:42 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
serverKey = generateSecp256k1Key()
|
|
|
|
clientKey = generateSecp256k1Key()
|
|
|
|
|
|
|
|
server = newTestWakuNode(serverKey, ValidIpAddress.init("0.0.0.0"), Port(0))
|
|
|
|
client = newTestWakuNode(clientKey, ValidIpAddress.init("0.0.0.0"), Port(0))
|
|
|
|
|
|
|
|
await allFutures(server.start(), client.start())
|
|
|
|
await server.start()
|
|
|
|
|
2024-05-10 12:13:58 +00:00
|
|
|
await server.mountRelay()
|
2024-06-13 17:10:00 +00:00
|
|
|
await server.mountLightpush() # without rln-relay
|
2024-02-06 16:37:42 +00:00
|
|
|
client.mountLightpushClient()
|
|
|
|
|
|
|
|
serverRemotePeerInfo = server.peerInfo.toRemotePeerInfo()
|
|
|
|
pubsubTopic = DefaultPubsubTopic
|
|
|
|
contentTopic = DefaultContentTopic
|
|
|
|
message = fakeWakuMessage()
|
|
|
|
|
|
|
|
asyncTeardown:
|
|
|
|
await server.stop()
|
|
|
|
|
|
|
|
suite "Assessment of Message Relaying Mechanisms":
|
|
|
|
asyncTest "Via 11/WAKU2-RELAY from Relay/Full Node":
|
|
|
|
# Given a light lightpush client
|
2024-03-15 23:08:47 +00:00
|
|
|
let lightpushClient =
|
|
|
|
newTestWakuNode(generateSecp256k1Key(), ValidIpAddress.init("0.0.0.0"), Port(0))
|
2024-02-06 16:37:42 +00:00
|
|
|
lightpushClient.mountLightpushClient()
|
|
|
|
|
|
|
|
# When the client publishes a message
|
2024-03-15 23:08:47 +00:00
|
|
|
let publishResponse = await lightpushClient.lightpushPublish(
|
|
|
|
some(pubsubTopic), message, serverRemotePeerInfo
|
|
|
|
)
|
2024-02-06 16:37:42 +00:00
|
|
|
|
|
|
|
if not publishResponse.isOk():
|
|
|
|
echo "Publish failed: ", publishResponse.error()
|
|
|
|
|
2024-08-02 07:45:05 +00:00
|
|
|
# Then the message is not relayed but not due to RLN
|
|
|
|
assert publishResponse.isErr(), "We expect an error response"
|
2024-09-10 15:30:09 +00:00
|
|
|
|
|
|
|
assert (publishResponse.error == protocol_metrics.notPublishedAnyPeer),
|
|
|
|
"incorrect error response"
|
2024-05-15 10:13:13 +00:00
|
|
|
|
|
|
|
suite "Waku LightPush Validation Tests":
|
|
|
|
asyncTest "Validate message size exceeds limit":
|
2024-07-05 22:03:38 +00:00
|
|
|
let msgOverLimit = fakeWakuMessage(
|
|
|
|
contentTopic = contentTopic,
|
|
|
|
payload = getByteSequence(DefaultMaxWakuMessageSize + 64 * 1024),
|
|
|
|
)
|
|
|
|
|
2024-05-15 10:13:13 +00:00
|
|
|
# When the client publishes an over-limit message
|
|
|
|
let publishResponse = await client.lightpushPublish(
|
|
|
|
some(pubsubTopic), msgOverLimit, serverRemotePeerInfo
|
|
|
|
)
|
|
|
|
|
|
|
|
check:
|
|
|
|
publishResponse.isErr()
|
2024-07-05 22:03:38 +00:00
|
|
|
publishResponse.error ==
|
|
|
|
fmt"Message size exceeded maximum of {DefaultMaxWakuMessageSize} bytes"
|
2024-06-13 17:10:00 +00:00
|
|
|
|
|
|
|
suite "RLN Proofs as a Lightpush Service":
|
|
|
|
var
|
|
|
|
handlerFuture {.threadvar.}: Future[(PubsubTopic, WakuMessage)]
|
|
|
|
handler {.threadvar.}: PushMessageHandler
|
|
|
|
|
|
|
|
server {.threadvar.}: WakuNode
|
|
|
|
client {.threadvar.}: WakuNode
|
|
|
|
|
|
|
|
serverRemotePeerInfo {.threadvar.}: RemotePeerInfo
|
|
|
|
pubsubTopic {.threadvar.}: PubsubTopic
|
|
|
|
contentTopic {.threadvar.}: ContentTopic
|
|
|
|
message {.threadvar.}: WakuMessage
|
|
|
|
|
|
|
|
asyncSetup:
|
|
|
|
handlerFuture = newPushHandlerFuture()
|
|
|
|
handler = proc(
|
|
|
|
peer: PeerId, pubsubTopic: PubsubTopic, message: WakuMessage
|
|
|
|
): Future[WakuLightPushResult[void]] {.async.} =
|
|
|
|
handlerFuture.complete((pubsubTopic, message))
|
|
|
|
return ok()
|
|
|
|
|
|
|
|
let
|
|
|
|
serverKey = generateSecp256k1Key()
|
|
|
|
clientKey = generateSecp256k1Key()
|
|
|
|
|
|
|
|
server = newTestWakuNode(serverKey, ValidIpAddress.init("0.0.0.0"), Port(0))
|
|
|
|
client = newTestWakuNode(clientKey, ValidIpAddress.init("0.0.0.0"), Port(0))
|
|
|
|
|
|
|
|
# mount rln-relay
|
2024-06-20 09:35:21 +00:00
|
|
|
let wakuRlnConfig = WakuRlnConfig(
|
|
|
|
rlnRelayDynamic: false,
|
|
|
|
rlnRelayCredIndex: some(1.uint),
|
|
|
|
rlnRelayUserMessageLimit: 1,
|
|
|
|
rlnEpochSizeSec: 1,
|
|
|
|
rlnRelayTreePath: genTempPath("rln_tree", "wakunode"),
|
|
|
|
)
|
|
|
|
|
2024-06-13 17:10:00 +00:00
|
|
|
await allFutures(server.start(), client.start())
|
|
|
|
await server.start()
|
|
|
|
|
|
|
|
await server.mountRelay()
|
|
|
|
await server.mountRlnRelay(wakuRlnConfig)
|
|
|
|
await server.mountLightpush()
|
|
|
|
client.mountLightpushClient()
|
|
|
|
|
|
|
|
serverRemotePeerInfo = server.peerInfo.toRemotePeerInfo()
|
|
|
|
pubsubTopic = DefaultPubsubTopic
|
|
|
|
contentTopic = DefaultContentTopic
|
|
|
|
message = fakeWakuMessage()
|
|
|
|
|
|
|
|
asyncTeardown:
|
|
|
|
await server.stop()
|
|
|
|
|
|
|
|
suite "Lightpush attaching RLN proofs":
|
|
|
|
asyncTest "Message is published when RLN enabled":
|
|
|
|
# Given a light lightpush client
|
|
|
|
let lightpushClient =
|
|
|
|
newTestWakuNode(generateSecp256k1Key(), ValidIpAddress.init("0.0.0.0"), Port(0))
|
|
|
|
lightpushClient.mountLightpushClient()
|
|
|
|
|
|
|
|
# When the client publishes a message
|
|
|
|
let publishResponse = await lightpushClient.lightpushPublish(
|
|
|
|
some(pubsubTopic), message, serverRemotePeerInfo
|
|
|
|
)
|
|
|
|
|
|
|
|
if not publishResponse.isOk():
|
|
|
|
echo "Publish failed: ", publishResponse.error()
|
|
|
|
|
2024-08-02 07:45:05 +00:00
|
|
|
# Then the message is not relayed but not due to RLN
|
|
|
|
assert publishResponse.isErr(), "We expect an error response"
|
2024-09-10 15:30:09 +00:00
|
|
|
assert (publishResponse.error == protocol_metrics.notPublishedAnyPeer),
|
|
|
|
"incorrect error response"
|