2021-04-23 06:56:04 +00:00
|
|
|
{.used.}
|
|
|
|
|
|
|
|
import
|
2022-08-02 23:47:42 +00:00
|
|
|
std/options,
|
|
|
|
testutils/unittests,
|
|
|
|
chronicles,
|
|
|
|
chronos,
|
2021-04-23 06:56:04 +00:00
|
|
|
libp2p/switch,
|
2022-08-02 23:47:42 +00:00
|
|
|
libp2p/crypto/crypto
|
|
|
|
import
|
2021-04-23 06:56:04 +00:00
|
|
|
../../waku/v2/node/peer_manager/peer_manager,
|
2022-08-02 23:47:42 +00:00
|
|
|
../../waku/v2/protocol/waku_message,
|
|
|
|
../../waku/v2/protocol/waku_lightpush,
|
|
|
|
../test_helpers
|
2021-04-23 06:56:04 +00:00
|
|
|
|
|
|
|
|
2022-08-02 23:47:42 +00:00
|
|
|
const
|
2022-08-01 16:21:11 +00:00
|
|
|
DefaultPubsubTopic = "/waku/2/default-waku/proto"
|
|
|
|
DefaultContentTopic = ContentTopic("/waku/2/default-content/proto")
|
2022-08-02 23:47:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
# TODO: Extend lightpush protocol test coverage
|
|
|
|
procSuite "Waku Lightpush":
|
2021-04-23 06:56:04 +00:00
|
|
|
|
2022-08-02 23:47:42 +00:00
|
|
|
asyncTest "handle light push request success":
|
|
|
|
# TODO: Move here the test case at test_wakunode: light push request success
|
|
|
|
discard
|
|
|
|
|
|
|
|
asyncTest "handle light push request fail":
|
2021-04-23 06:56:04 +00:00
|
|
|
let
|
|
|
|
key = PrivateKey.random(ECDSA, rng[]).get()
|
2022-08-02 23:47:42 +00:00
|
|
|
listenSwitch = newStandardSwitch(some(key))
|
|
|
|
await listenSwitch.start()
|
2021-04-23 06:56:04 +00:00
|
|
|
|
2022-08-02 23:47:42 +00:00
|
|
|
let dialSwitch = newStandardSwitch()
|
2022-01-14 09:25:01 +00:00
|
|
|
await dialSwitch.start()
|
2021-04-23 06:56:04 +00:00
|
|
|
|
|
|
|
|
2022-08-02 23:47:42 +00:00
|
|
|
proc requestHandler(requestId: string, msg: PushRequest) {.gcsafe, closure.} =
|
2021-04-23 06:56:04 +00:00
|
|
|
# TODO Success return here
|
|
|
|
debug "handle push req"
|
|
|
|
check:
|
|
|
|
1 == 0
|
|
|
|
|
|
|
|
# FIXME Unclear how we want to use subscriptions, if at all
|
|
|
|
let
|
2022-08-02 23:47:42 +00:00
|
|
|
peerManager = PeerManager.new(dialSwitch)
|
|
|
|
rng = crypto.newRng()
|
|
|
|
proto = WakuLightPush.init(peerManager, rng, requestHandler)
|
2021-04-23 06:56:04 +00:00
|
|
|
|
2021-10-06 12:29:08 +00:00
|
|
|
proto.setPeer(listenSwitch.peerInfo.toRemotePeerInfo())
|
2022-08-02 23:47:42 +00:00
|
|
|
dialSwitch.mount(proto)
|
2021-04-23 06:56:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
# TODO Can possibly get rid of this if it isn't dynamic
|
2022-08-02 23:47:42 +00:00
|
|
|
proc requestHandler2(requestId: string, msg: PushRequest) {.gcsafe, closure.} =
|
2021-04-23 06:56:04 +00:00
|
|
|
debug "push request handler"
|
|
|
|
# TODO: Also relay message
|
|
|
|
# TODO: Here we want to send back response with is_success true
|
|
|
|
discard
|
|
|
|
|
|
|
|
let
|
2022-08-02 23:47:42 +00:00
|
|
|
peerManager2 = PeerManager.new(listenSwitch)
|
|
|
|
rng2 = crypto.newRng()
|
|
|
|
proto2 = WakuLightPush.init(peerManager2, rng2, requestHandler2)
|
2021-04-23 06:56:04 +00:00
|
|
|
|
|
|
|
listenSwitch.mount(proto2)
|
|
|
|
|
|
|
|
|
2022-08-02 23:47:42 +00:00
|
|
|
## Given
|
|
|
|
let
|
2022-08-01 16:21:11 +00:00
|
|
|
msg = WakuMessage(payload: @[byte 1, 2, 3], contentTopic: DefaultContentTopic)
|
|
|
|
rpc = PushRequest(message: msg, pubSubTopic: DefaultPubsubTopic)
|
2022-08-02 23:47:42 +00:00
|
|
|
|
|
|
|
## When
|
|
|
|
let res = await proto.request(rpc)
|
2021-04-23 06:56:04 +00:00
|
|
|
|
2022-08-02 23:47:42 +00:00
|
|
|
## Then
|
|
|
|
check res.isOk()
|
|
|
|
let response = res.get()
|
2021-04-23 06:56:04 +00:00
|
|
|
check:
|
2022-08-02 23:47:42 +00:00
|
|
|
not response.isSuccess
|
|
|
|
|
|
|
|
## Cleanup
|
|
|
|
await allFutures(listenSwitch.stop(), dialSwitch.stop())
|