-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(lightpush): Lightpush functional tests (#2269)
* Add ligthpush payload tests. * Add end to end lightpush tests. * updating vendor/nim-unittest2 to protect against core dump issue * Enable "Valid Payload Sizes" test again --------- Co-authored-by: Ivan FB <128452529+Ivansete-status@users.noreply.github.com>
- Loading branch information
1 parent
e4e147b
commit 817b2e0
Showing
18 changed files
with
1,081 additions
and
639 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import | ||
./test_wakunode_filter, | ||
./test_wakunode_lightpush, | ||
./test_wakunode_store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
{.used.} | ||
|
||
import | ||
std/[options, tables, sequtils], | ||
stew/shims/net as stewNet, | ||
testutils/unittests, | ||
chronos, | ||
chronicles, | ||
os, | ||
libp2p/[peerstore, crypto/crypto] | ||
|
||
import | ||
../../../waku/[ | ||
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, | ||
waku_lightpush/rpc | ||
], | ||
../testlib/[assertions, common, wakucore, wakunode, testasync, futures, testutils] | ||
|
||
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() | ||
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)) | ||
|
||
await allFutures(server.start(), client.start()) | ||
await server.start() | ||
|
||
waitFor server.mountRelay() | ||
waitFor server.mountLightpush() | ||
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 | ||
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() | ||
|
||
# Then the message is relayed to the server | ||
assertResultOk publishResponse |
Oops, something went wrong.